aboutsummaryrefslogtreecommitdiffstats
path: root/app/app
diff options
context:
space:
mode:
Diffstat (limited to 'app/app')
-rw-r--r--app/app/MANIFEST.in1
-rw-r--r--app/app/__init__.py0
-rw-r--r--app/app/config_binding_service/__init__.py8
-rw-r--r--app/app/config_binding_service/openapi.yaml112
-rwxr-xr-xapp/app/main.py14
-rw-r--r--app/app/pom.xml6
-rw-r--r--app/app/setup.py11
-rw-r--r--app/app/swagger.yaml100
-rw-r--r--app/app/tests/test_api.py103
-rw-r--r--app/app/tests/test_client.py38
-rw-r--r--app/app/tests/test_controller.py120
-rw-r--r--app/app/tox.ini2
12 files changed, 276 insertions, 239 deletions
diff --git a/app/app/MANIFEST.in b/app/app/MANIFEST.in
deleted file mode 100644
index 3d5afa6..0000000
--- a/app/app/MANIFEST.in
+++ /dev/null
@@ -1 +0,0 @@
-include swagger.yaml
diff --git a/app/app/__init__.py b/app/app/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/app/app/__init__.py
+++ /dev/null
diff --git a/app/app/config_binding_service/__init__.py b/app/app/config_binding_service/__init__.py
index 5a6b081..306a762 100644
--- a/app/app/config_binding_service/__init__.py
+++ b/app/app/config_binding_service/__init__.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
import os
+import connexion
class BadEnviornmentENVNotFound(Exception):
@@ -38,3 +39,8 @@ def get_consul_uri():
return "http://{0}:{1}".format(os.environ["CONSUL_HOST"], 8500)
else:
raise BadEnviornmentENVNotFound("CONSUL_HOST")
+
+
+# this has to be here due to circular dependency
+app = connexion.App(__name__, specification_dir='.')
+app.add_api('openapi.yaml', arguments={'title': 'Config Binding Service'})
diff --git a/app/app/config_binding_service/openapi.yaml b/app/app/config_binding_service/openapi.yaml
new file mode 100644
index 0000000..bc4dd49
--- /dev/null
+++ b/app/app/config_binding_service/openapi.yaml
@@ -0,0 +1,112 @@
+openapi: 3.0.0
+info:
+ version: 2.3.0
+ title: Config Binding Service
+paths:
+ '/service_component/{service_component_name}':
+ parameters:
+ - name: service_component_name
+ in: path
+ description: >-
+ Service Component Name. service_component_name must be a key in
+ consul.
+ required: true
+ schema:
+ type: string
+ get:
+ description: >-
+ Binds the configuration for service_component_name and returns the bound
+ configuration as a JSON
+ operationId: config_binding_service.controller.bind_config_for_scn
+ responses:
+ '200':
+ description: OK; the bound config is returned as an object
+ content:
+ '*/*':
+ schema:
+ type: object
+ '404':
+ description: there is no configuration in Consul for this component
+ '/service_component_all/{service_component_name}':
+ parameters:
+ - name: service_component_name
+ in: path
+ description: >-
+ Service Component Name. service_component_name must be a key in
+ consul.
+ required: true
+ schema:
+ type: string
+ get:
+ description: >-
+ Binds the configuration for service_component_name and returns the bound
+ configuration, policies, and any other keys that are in Consul
+ operationId: config_binding_service.controller.bind_all
+ responses:
+ '200':
+ description: >-
+ OK; returns {config : ..., policies : ....., k : ...} for all other
+ k in Consul
+ content:
+ '*/*':
+ schema:
+ type: object
+ '404':
+ description: there is no configuration in Consul for this component
+ '/{key}/{service_component_name}':
+ parameters:
+ - name: key
+ in: path
+ description: >-
+ this endpoint tries to pull service_component_name:key; key is the key
+ after the colon
+ required: true
+ schema:
+ type: string
+ - name: service_component_name
+ in: path
+ description: Service Component Name.
+ required: true
+ schema:
+ type: string
+ get:
+ description: >-
+ this is an endpoint that fetches a generic service_component_name:key
+ out of Consul. The idea is that we don't want to tie components to
+ Consul directly in case we swap out the backend some day, so the CBS
+ abstracts Consul from clients. The structuring and weird collision of
+ this new API with the above is unfortunate but due to legacy concerns.
+ operationId: config_binding_service.controller.get_key
+ responses:
+ '200':
+ description: 'OK; returns service_component_name:key'
+ content:
+ '*/*':
+ schema:
+ type: object
+ '400':
+ description: >-
+ bad request. Currently this is only returned on :policies, which is
+ a complex object, and should be gotten through service_component_all
+ content:
+ '*/*':
+ schema:
+ type: string
+ '404':
+ description: key does not exist
+ content:
+ '*/*':
+ schema:
+ type: string
+ /healthcheck:
+ get:
+ description: >-
+ This is the health check endpoint. If this returns a 200, the server is
+ alive and consul can be reached. If not a 200, either dead, or no
+ connection to consul
+ operationId: config_binding_service.controller.healthcheck
+ responses:
+ '200':
+ description: Successful response
+ '503':
+ description: the config binding service cannot reach Consul
diff --git a/app/app/main.py b/app/app/main.py
index dd71ccf..c7adaaf 100755
--- a/app/app/main.py
+++ b/app/app/main.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,16 +17,12 @@
# ============LICENSE_END=========================================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
-import connexion
from config_binding_service.logging import create_loggers
-
-# Entrypoint When in uwsgi
-# This create logger call used to be in the main block, but when moving to NGINX+uwsgi, this had to change. See https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/
-create_loggers()
-app = connexion.App(__name__, specification_dir='.')
-app.add_api('swagger.yaml', arguments={'title': 'Config Binding Service'})
+from config_binding_service import app
if __name__ == "__main__":
# Only for debugging while developing
app.run(host='0.0.0.0', port=10000, debug=True)
+else:
+ # Entrypoint in UWSGI
+ create_loggers()
diff --git a/app/app/pom.xml b/app/app/pom.xml
index 7887201..3b634a6 100644
--- a/app/app/pom.xml
+++ b/app/app/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
================================================================================
-Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -24,13 +24,13 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
<parent>
<groupId>org.onap.dcaegen2.platform.configbinding</groupId>
<artifactId>app</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.3.0-SNAPSHOT</version>
</parent>
<!--- CHANGE THE FOLLOWING 3 OBJECTS for your own repo -->
<groupId>org.onap.dcaegen2.platform.configbinding</groupId>
<artifactId>app-app</artifactId>
<name>dcaegen2-platform-configbinding-app-app</name>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.3.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/app/app/setup.py b/app/app/setup.py
index 65ff0b6..38929c9 100644
--- a/app/app/setup.py
+++ b/app/app/setup.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -20,12 +20,15 @@ from setuptools import setup, find_packages
setup(
name='config_binding_service',
- version='2.2.5',
+ version='2.3.0',
packages=find_packages(exclude=["tests.*", "tests"]),
author="Tommy Carpenter",
author_email="tommy@research.att.com",
description='Service to fetch and bind configurations',
url="https://gerrit.onap.org/r/#/admin/projects/dcaegen2/platform/configbinding",
- install_requires=["requests", "Flask", "connexion", "six"],
- include_package_data=True
+ install_requires=["requests",
+ "Flask",
+ "six",
+ "connexion[swagger-ui]"],
+ package_data={'config_binding_service': ['openapi.yaml']}
)
diff --git a/app/app/swagger.yaml b/app/app/swagger.yaml
deleted file mode 100644
index 49627c0..0000000
--- a/app/app/swagger.yaml
+++ /dev/null
@@ -1,100 +0,0 @@
-# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
-# ================================================================================
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
-
----
-swagger: "2.0"
-info:
- version: "2.2.5"
- title: "Config Binding Service"
-paths:
- /service_component/{service_component_name}:
- parameters:
- - name: "service_component_name"
- in: "path"
- description: "Service Component Name. service_component_name must be a key in consul."
- required: true
- type: "string"
- get:
- description: "Binds the configuration for service_component_name and returns the bound configuration as a JSON"
- operationId: "config_binding_service.controller.bind_config_for_scn"
- responses:
- 200:
- description: OK; the bound config is returned as an object
- schema:
- type: object
- 404:
- description: there is no configuration in Consul for this component
-
- /service_component_all/{service_component_name}:
- parameters:
- - name: "service_component_name"
- in: "path"
- description: "Service Component Name. service_component_name must be a key in consul."
- required: true
- type: "string"
- get:
- description: "Binds the configuration for service_component_name and returns the bound configuration, policies, and any other keys that are in Consul"
- operationId: "config_binding_service.controller.bind_all"
- responses:
- 200:
- description: "OK; returns {config : ..., policies : ....., k : ...} for all other k in Consul"
- schema:
- type: object
- 404:
- description: there is no configuration in Consul for this component
-
- /{key}/{service_component_name}:
- parameters:
- - name: "key"
- in: "path"
- description: "this endpoint tries to pull service_component_name:key; key is the key after the colon"
- required: true
- type: "string"
- - name: "service_component_name"
- in: "path"
- description: "Service Component Name."
- required: true
- type: "string"
- get:
- description: "this is an endpoint that fetches a generic service_component_name:key out of Consul. The idea is that we don't want to tie components to Consul directly in case we swap out the backend some day, so the CBS abstracts Consul from clients. The structuring and weird collision of this new API with the above is unfortunate but due to legacy concerns."
- operationId: "config_binding_service.controller.get_key"
- responses:
- 200:
- description: "OK; returns service_component_name:key"
- schema:
- type: object
- 404:
- description: "key does not exist"
- schema:
- type: string
- 400:
- description: "bad request. Currently this is only returned on :policies, which is a complex object, and should be gotten through service_component_all"
- schema:
- type: string
-
- /healthcheck:
- get:
- description: "This is the health check endpoint. If this returns a 200, the server is alive and consul can be reached. If not a 200, either dead, or no connection to consul"
- operationId: "config_binding_service.controller.healthcheck"
- parameters: []
- responses:
- 200:
- description: Successful response
- 503:
- description: the config binding service cannot reach Consul
diff --git a/app/app/tests/test_api.py b/app/app/tests/test_api.py
new file mode 100644
index 0000000..118a2a0
--- /dev/null
+++ b/app/app/tests/test_api.py
@@ -0,0 +1,103 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import json
+import pytest
+import os
+import tempfile
+from config_binding_service import app
+
+
+TEST_NAME = "test_service_component_name.unknown.unknown.unknown.dcae.onap.org"
+
+
+# http://flask.pocoo.org/docs/1.0/testing/
+@pytest.fixture
+def cbsclient():
+ db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
+ app.app.config['TESTING'] = True
+ testclient = app.app.test_client()
+
+ yield testclient
+
+ os.close(db_fd)
+ os.unlink(app.app.config['DATABASE'])
+
+
+def test_get(monkeypatch, cbsclient, monkeyed_requests_put):
+ monkeypatch.setattr('requests.put', monkeyed_requests_put)
+
+ res = cbsclient.get('/service_component/scn_exists',
+ headers={"x-onap-requestid": 123456789})
+ assert(json.loads(res.data) == {"foo3": "bar3"})
+ assert(res.status_code == 200)
+ assert(res.headers["x-onap-requestid"] == "123456789")
+
+ res = cbsclient.get('/service_component/scn_NOTexists',
+ headers={"x-onap-requestid": 123456789})
+ assert(res.status_code == 404)
+ assert(res.headers["x-onap-requestid"] == "123456789")
+
+ res = cbsclient.get('/service_component/asdfasdf',
+ headers={"x-onap-requestid": 123456789})
+ assert(res.status_code == 500)
+ assert(res.headers["x-onap-requestid"] == "123456789")
+
+
+def test_generic(monkeypatch, cbsclient, monkeyed_requests_get, monkeyed_requests_put):
+ monkeypatch.setattr('requests.put', monkeyed_requests_put)
+ monkeypatch.setattr('requests.get', monkeyed_requests_get)
+
+ res = cbsclient.get('/dti/{0}'.format(TEST_NAME))
+ assert json.loads(res.data) == {"my": "dti"}
+ assert res.json == {"my": "dti"}
+ assert res.status_code == 200
+ assert "x-onap-requestid" in res.headers
+
+ res = cbsclient.get('/nokeyforyou/{0}'.format(TEST_NAME))
+ assert res.status_code == 404
+ assert "x-onap-requestid" in res.headers
+
+ res = cbsclient.get('/policies/{0}'.format(TEST_NAME))
+ assert res.status_code == 400
+ assert "x-onap-requestid" in res.headers
+
+
+def test_resolve_all(monkeypatch, cbsclient, monkeyed_requests_put, monkeyed_get_connection_info_from_consul, expected_config):
+ monkeypatch.setattr('requests.put', monkeyed_requests_put)
+ monkeypatch.setattr('config_binding_service.client._get_connection_info_from_consul', monkeyed_get_connection_info_from_consul)
+ withstuff = {'config': {'my': 'amazing config'},
+ 'dti': {'my': 'dti'},
+ 'policies': {'items': [{'policyName': 'DCAE_alex.Config_MS_alex_microservice.132.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'policyScope': 'alex_policy_scope', 'configName': 'alex_config_name', 'description': 'test DCAE policy-handler', 'service': 'alex_service', 'policyName': 'alex_policy_name', 'riskLevel': '3', 'key1': 'value1', 'policy_hello': 'world!', 'content': {'foo': 'microservice3', 'foo_updated': '2018-01-30T13:25:33.222Z'}, 'riskType': '1712_ETE', 'guard': 'False', 'version': '0.0.1', 'location': 'Central', 'policy_updated_ts': '2018-02-19T15:09:55.217Z', 'updated_policy_id': 'DCAE_alex.Config_MS_alex_microservice', 'policy_updated_to_ver': '132', 'priority': '4', 'policy_updated_from_ver': '131', 'templateVersion': '2', 'uuid': '5e87d7c5-0daf-4b6b-ab92-5365cf5db1ef'}, 'property': None, 'type': 'JSON', 'policyVersion': '132'}, {'policyName': 'DCAE_alex.Config_db_client_policy_id_value.133.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'db_client_ts': '2017-11-21T12:12:13.696Z', 'db_client': 'ipsum', 'policy_hello': 'world!', 'policy_updated_from_ver': '132', 'updated_policy_id': 'DCAE_alex.Config_db_client_policy_id_value', 'policy_updated_ts': '2018-02-19T15:09:55.812Z', 'policy_updated_to_ver': '133'}, 'property': None, 'type': 'JSON', 'policyVersion': '133'}], 'event': {'action': 'gathered', 'timestamp': '2018-02-19 15:36:44.877380', 'update_id': 'bb73c20a-5ff8-450f-8223-da6720ade267', 'policies_count': 2}}}
+
+ assert cbsclient.get('service_component_all/{0}'.format(TEST_NAME)).json == withstuff
+
+ assert cbsclient.get('service_component_all/test_resolve_scn').json == {"config": expected_config}
+
+ res = cbsclient.get('/service_component_all/{0}'.format(TEST_NAME))
+ assert json.loads(res.data) == withstuff
+ assert res.json == withstuff
+ assert res.status_code == 200
+ assert "x-onap-requestid" in res.headers
+
+ res = cbsclient.get('/service_component_all/test_resolve_scn')
+ assert res.status_code == 200
+ assert res.json == {"config": expected_config}
+
+ res = cbsclient.get('/service_component_all/scn_NOTexists')
+ assert res.status_code == 404
+ assert "x-onap-requestid" in res.headers
diff --git a/app/app/tests/test_client.py b/app/app/tests/test_client.py
index cd3287c..96c3467 100644
--- a/app/app/tests/test_client.py
+++ b/app/app/tests/test_client.py
@@ -1,4 +1,22 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+
from config_binding_service import client
+import pytest
# pytest doesnt support objects in conftest
@@ -10,6 +28,15 @@ class FakeReq(object):
self.remote_addr = "6.6.6.6"
+# pytest doesnt support objects in conftest
+class FakeConnexion(object):
+ def __init__(self, headers, path, host, remote_addr):
+ self.headers = headers
+ self.path = path
+ self.host = host
+ self.remote_addr = remote_addr
+
+
def test_consul_get_all_as_transaction(monkeypatch, monkeyed_requests_put):
"""tests _consul_get_all_as_transaction"""
monkeypatch.setattr('requests.put', monkeyed_requests_put)
@@ -166,3 +193,14 @@ def test_both(monkeypatch, monkeyed_get_connection_info_from_consul, expected_co
"doubledeep": {"sodeep": {"hello": "<<WHO?>>"}}}
test_bind_1 = client.resolve_override(config, test_rels, test_dmaap)
assert(test_bind_1 == expected_config)
+
+
+def test_failures(monkeypatch, monkeyed_requests_put, monkeyed_requests_get):
+ monkeypatch.setattr('requests.put', monkeyed_requests_put)
+ monkeypatch.setattr('requests.get', monkeyed_requests_get)
+ monkeypatch.setattr('connexion.request', FakeConnexion({"x-onap-requestid": 123456789}, "/service_component", "mytestingmachine", "myremoteclient"))
+ assert(client.resolve("scn_exists", FakeReq(), "unit test xer") == {"foo3": "bar3"})
+ with pytest.raises(client.CantGetConfig):
+ client.resolve("scn_NOTexists", FakeReq(), "unit test xer")
+ with pytest.raises(client.CantGetConfig):
+ client.get_key("nokeyforyou", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org", FakeReq(), "unit test xer")
diff --git a/app/app/tests/test_controller.py b/app/app/tests/test_controller.py
deleted file mode 100644
index 0650a38..0000000
--- a/app/app/tests/test_controller.py
+++ /dev/null
@@ -1,120 +0,0 @@
-# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
-# ================================================================================
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
-import json
-import pytest
-from config_binding_service import client, controller
-
-
-# pytest doesnt support objects in conftest
-class FakeConnexion(object):
- def __init__(self, headers, path, host, remote_addr):
- self.headers = headers
- self.path = path
- self.host = host
- self.remote_addr = remote_addr
-
-
-# pytest doesnt support objects in conftest
-class FakeReq(object):
- """used to fake the logging params"""
- def __init__(self):
- self.path = "/unittest in {0}".format(__name__)
- self.host = "localhost"
- self.remote_addr = "6.6.6.6"
-
-
-def test_bind_config_for_scn(monkeypatch, monkeyed_requests_put):
- monkeypatch.setattr('requests.put', monkeyed_requests_put)
- monkeypatch.setattr('connexion.request', FakeConnexion({"x-onap-requestid": 123456789}, "/service_component", "mytestingmachine", "myremoteclient"))
-
- assert(client.resolve("scn_exists", FakeReq(), "unit test xer") == {"foo3": "bar3"})
- with pytest.raises(client.CantGetConfig):
- client.resolve("scn_NOTexists", FakeReq(), "unit test xer")
-
- R = controller.bind_config_for_scn("scn_exists")
- assert(json.loads(R.data) == {"foo3": "bar3"})
- assert(R.status_code == 200)
- assert(R.headers["x-onap-requestid"] == "123456789")
-
- R = controller.bind_config_for_scn("scn_NOTexists")
- assert(R.status_code == 404)
- assert(R.headers["x-onap-requestid"] == "123456789")
-
- R = controller.bind_config_for_scn("asdfasdf")
- assert(R.status_code == 500)
- assert(R.headers["x-onap-requestid"] == "123456789")
-
-
-def test_generic(monkeypatch, monkeyed_requests_get, monkeyed_requests_put):
- monkeypatch.setattr('requests.put', monkeyed_requests_put)
- monkeypatch.setattr('requests.get', monkeyed_requests_get)
- assert client.get_key("dti", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org", FakeReq(), "unit test xer") == json.loads('{"my": "dti"}')
- with pytest.raises(client.CantGetConfig):
- client.get_key("nokeyforyou", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org", FakeReq(), "unit test xer")
-
- monkeypatch.setattr('connexion.request', FakeConnexion({}, "/get_key", "mytestingmachine", "myremoteclient"))
-
- R = controller.get_key(
- "dti", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org")
- assert(json.loads(R.data) == {"my": "dti"})
- assert(R.status_code == 200)
- assert "x-onap-requestid" in R.headers
-
- R = controller.get_key(
- "nokeyforyou", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org")
- assert(R.status_code == 404)
- assert "x-onap-requestid" in R.headers
-
- R = controller.get_key(
- "policies", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org")
- assert(R.status_code == 400)
- assert "x-onap-requestid" in R.headers
-
-
-def test_resolve_all(monkeypatch, monkeyed_requests_put, monkeyed_get_connection_info_from_consul, expected_config):
- monkeypatch.setattr('requests.put', monkeyed_requests_put)
- allk = client.resolve_all("test_service_component_name.unknown.unknown.unknown.dcae.onap.org", FakeReq(), "unit test xer")
- withstuff = {'config': {'my': 'amazing config'},
- 'dti': {'my': 'dti'},
- 'policies': {'items': [{'policyName': 'DCAE_alex.Config_MS_alex_microservice.132.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'policyScope': 'alex_policy_scope', 'configName': 'alex_config_name', 'description': 'test DCAE policy-handler', 'service': 'alex_service', 'policyName': 'alex_policy_name', 'riskLevel': '3', 'key1': 'value1', 'policy_hello': 'world!', 'content': {'foo': 'microservice3', 'foo_updated': '2018-01-30T13:25:33.222Z'}, 'riskType': '1712_ETE', 'guard': 'False', 'version': '0.0.1', 'location': 'Central', 'policy_updated_ts': '2018-02-19T15:09:55.217Z', 'updated_policy_id': 'DCAE_alex.Config_MS_alex_microservice', 'policy_updated_to_ver': '132', 'priority': '4', 'policy_updated_from_ver': '131', 'templateVersion': '2', 'uuid': '5e87d7c5-0daf-4b6b-ab92-5365cf5db1ef'}, 'property': None, 'type': 'JSON', 'policyVersion': '132'}, {'policyName': 'DCAE_alex.Config_db_client_policy_id_value.133.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'db_client_ts': '2017-11-21T12:12:13.696Z', 'db_client': 'ipsum', 'policy_hello': 'world!', 'policy_updated_from_ver': '132', 'updated_policy_id': 'DCAE_alex.Config_db_client_policy_id_value', 'policy_updated_ts': '2018-02-19T15:09:55.812Z', 'policy_updated_to_ver': '133'}, 'property': None, 'type': 'JSON', 'policyVersion': '133'}], 'event': {'action': 'gathered', 'timestamp': '2018-02-19 15:36:44.877380', 'update_id': 'bb73c20a-5ff8-450f-8223-da6720ade267', 'policies_count': 2}}}
- assert allk == withstuff
-
- monkeypatch.setattr('config_binding_service.client._get_connection_info_from_consul',
- monkeyed_get_connection_info_from_consul)
- allk = client.resolve_all("test_resolve_scn", FakeReq(), "unit test xer")
- assert allk == {"config": expected_config}
-
- monkeypatch.setattr('connexion.request', FakeConnexion({}, "/service_component_all", "mytestingmachine", "myremoteclient"))
-
- R = controller.bind_all(
- "test_service_component_name.unknown.unknown.unknown.dcae.onap.org")
- assert(json.loads(R.data) == withstuff)
- assert(R.status_code == 200)
- assert "x-onap-requestid" in R.headers
-
- R = controller.bind_all("test_resolve_scn")
- assert(json.loads(R.data) == {"config": expected_config})
- assert(R.status_code == 200)
-
- R = controller.bind_all("scn_NOTexists")
- assert(R.status_code == 404)
- assert "x-onap-requestid" in R.headers
-
- R = controller.bind_all("asdfasdf")
- assert(R.status_code == 500)
diff --git a/app/app/tox.ini b/app/app/tox.ini
index 34fb22d..40fa3b3 100644
--- a/app/app/tox.ini
+++ b/app/app/tox.ini
@@ -12,7 +12,7 @@ setenv =
HOSTNAME = config_binding_service
PYTHONPATH={toxinidir}
commands=
- pytest --junitxml xunit-results.xml --cov config_binding_service --cov-report xml --cov-report term
+ pytest --junitxml xunit-results.xml --cov config_binding_service --cov-report xml --cov-report term --cov-fail-under=70
coverage xml -i
[testenv:flake8]