diff options
Diffstat (limited to 'docker')
-rw-r--r-- | docker/tests/test_decorators.py | 36 | ||||
-rw-r--r-- | docker/tests/test_discovery.py | 16 | ||||
-rw-r--r-- | docker/tests/test_tasks.py | 63 | ||||
-rw-r--r-- | docker/tests/test_utils.py | 32 | ||||
-rw-r--r-- | docker/tox.ini | 2 |
5 files changed, 145 insertions, 4 deletions
diff --git a/docker/tests/test_decorators.py b/docker/tests/test_decorators.py new file mode 100644 index 0000000..403e39f --- /dev/null +++ b/docker/tests/test_decorators.py @@ -0,0 +1,36 @@ +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# 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. + +from dockerplugin import decorators as dec + + +def test_wrapper_merge_inputs(): + properties = { "app_config": {"nested": { "a": 123, "b": 456 }, "foo": "duh"}, + "image": "some-docker-image" } + kwargs = { "app_config": {"nested": {"a": 789, "c": "zyx"}} } + + def task_func(**inputs): + return inputs + + expected = { "app_config": {"nested": { "a": 789, "b": 456, "c": "zyx" }, + "foo": "duh"}, "image": "some-docker-image" } + + assert expected == dec._wrapper_merge_inputs(task_func, properties, **kwargs) + diff --git a/docker/tests/test_discovery.py b/docker/tests/test_discovery.py index cee75b1..f3aed66 100644 --- a/docker/tests/test_discovery.py +++ b/docker/tests/test_discovery.py @@ -1,7 +1,7 @@ # ============LICENSE_START======================================================= # org.onap.dcae # ================================================================================ -# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# 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. @@ -40,6 +40,12 @@ def test_wrap_consul_call(): wrapped_foo("a", "b", "c") +def test_generate_service_component_name(): + component_type = "some-component-type" + name = dis.generate_service_component_name(component_type) + assert name.split("_")[1] == component_type + + def test_find_matching_services(): services = { "component_dockerhost_1": ["foo", "bar"], "platform_dockerhost": [], "component_dockerhost_2": ["baz"] } @@ -53,3 +59,11 @@ def test_find_matching_services(): "component_dockerhost", ["foo"]) assert [] == dis._find_matching_services(services, "unknown", ["foo"]) + + +def test_is_healthy_pure(): + def fake_is_healthy(name): + return 0, [{ "Checks": [{"Status": "passing"}] }] + + assert True == dis._is_healthy_pure(fake_is_healthy, "some-component") + diff --git a/docker/tests/test_tasks.py b/docker/tests/test_tasks.py index 6661532..c58d02c 100644 --- a/docker/tests/test_tasks.py +++ b/docker/tests/test_tasks.py @@ -1,7 +1,7 @@ # ============LICENSE_START======================================================= # org.onap.dcae # ================================================================================ -# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# 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. @@ -20,9 +20,10 @@ import copy import pytest -from cloudify.exceptions import NonRecoverableError +from cloudify.exceptions import NonRecoverableError, RecoverableError import dockerplugin from dockerplugin import tasks +from dockerplugin.exceptions import DockerPluginDeploymentError def test_generate_component_name(): @@ -89,6 +90,28 @@ def test_parse_streams(monkeypatch): assert expected == tasks._parse_streams(**test_input) +def test_setup_for_discovery(monkeypatch): + test_input = { "name": "some-name", + "application_config": { "one": "a", "two": "b" } } + + def fake_push_config(conn, name, application_config): + return + + monkeypatch.setattr(dockerplugin.discovery, "push_service_component_config", + fake_push_config) + + assert test_input == tasks._setup_for_discovery(**test_input) + + def fake_push_config_connection_error(conn, name, application_config): + raise dockerplugin.discovery.DiscoveryConnectionError("Boom") + + monkeypatch.setattr(dockerplugin.discovery, "push_service_component_config", + fake_push_config_connection_error) + + with pytest.raises(RecoverableError): + tasks._setup_for_discovery(**test_input) + + def test_setup_for_discovery_streams(monkeypatch): test_input = {'feed01': {'type': 'data_router', 'name': 'feed01', 'username': 'hero', 'password': '123456', 'location': 'Bedminster'}, @@ -147,6 +170,37 @@ def test_setup_for_discovery_streams(monkeypatch): tasks._setup_for_discovery_streams(**test_input) +def test_lookup_service(monkeypatch): + def fake_lookup(conn, scn): + return [{"ServiceAddress": "192.168.1.1", "ServicePort": "80"}] + + monkeypatch.setattr(dockerplugin.discovery, "lookup_service", + fake_lookup) + + assert "192.168.1.1" == tasks._lookup_service("some-component") + assert "192.168.1.1:80" == tasks._lookup_service("some-component", + with_port=True) + + +def test_verify_container(monkeypatch): + def fake_is_healthy_success(ch, scn): + return True + + monkeypatch.setattr(dockerplugin.discovery, "is_healthy", + fake_is_healthy_success) + + assert tasks._verify_container("some-name", 3) + + def fake_is_healthy_never_good(ch, scn): + return False + + monkeypatch.setattr(dockerplugin.discovery, "is_healthy", + fake_is_healthy_never_good) + + with pytest.raises(DockerPluginDeploymentError): + tasks._verify_container("some-name", 2) + + def test_update_delivery_url(monkeypatch): test_input = {'feed01': {'type': 'data_router', 'name': 'feed01', 'username': 'hero', 'password': '123456', 'location': 'Bedminster', @@ -216,3 +270,8 @@ def test_enhance_docker_params(): actual = tasks._enhance_docker_params(**test_kwargs) assert actual["envs"] == {"SERVICE_TAGS": "abc,zed"} + + +def test_notify_container(): + test_input = { "docker_config": { "trigger_type": "unknown" } } + assert test_input == tasks._notify_container(**test_input) diff --git a/docker/tests/test_utils.py b/docker/tests/test_utils.py new file mode 100644 index 0000000..4578dae --- /dev/null +++ b/docker/tests/test_utils.py @@ -0,0 +1,32 @@ +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# 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. + +from dockerplugin import utils + + +def test_random_string(): + target_length = 10 + assert len(utils.random_string(target_length)) == target_length + + +def test_update_dict(): + d = { "a": 1, "b": 2 } + u = { "a": 2, "b": 3 } + assert utils.update_dict(d, u) == u diff --git a/docker/tox.ini b/docker/tox.ini index 9a4b7f8..91f7dc6 100644 --- a/docker/tox.ini +++ b/docker/tox.ini @@ -8,4 +8,4 @@ deps= pytest coverage pytest-cov -commands=pytest --junitxml xunit-results.xml --cov {envsitepackagesdir}/dockerplugin --cov-report=xml +commands=pytest --junitxml xunit-results.xml --cov {envsitepackagesdir}/dockerplugin |