diff options
author | 2017-09-06 17:46:45 -0400 | |
---|---|---|
committer | 2017-09-06 17:50:51 -0400 | |
commit | da9cdd6a23d2fa2748795a6c83b14cc4d3fa3d13 (patch) | |
tree | a9e7a8580b992ebec517edb67b8e2e612dd4ecec /docker/tests | |
parent | fcb0bb5252f8e90ce065e7e6f9034f9d1a4ef8ce (diff) |
Enhance to query Consul for target docker host
* `SelectedDockerHost` actually queries by a name stem and location
* Shorten name
* Tag components with deployment id
Change-Id: I715f1de25fa047ce70eb26a5cc7615cfd3b408e7
Issue-ID: DCAEGEN2-91
Signed-off-by: Michael Hwang <mhwang@research.att.com>
Diffstat (limited to 'docker/tests')
-rw-r--r-- | docker/tests/test_discovery.py | 15 | ||||
-rw-r--r-- | docker/tests/test_tasks.py | 36 |
2 files changed, 43 insertions, 8 deletions
diff --git a/docker/tests/test_discovery.py b/docker/tests/test_discovery.py index 9a18519..cee75b1 100644 --- a/docker/tests/test_discovery.py +++ b/docker/tests/test_discovery.py @@ -38,3 +38,18 @@ def test_wrap_consul_call(): wrapped_foo = partial(dis._wrap_consul_call, foo_connection_error) with pytest.raises(dis.DiscoveryConnectionError): wrapped_foo("a", "b", "c") + + +def test_find_matching_services(): + services = { "component_dockerhost_1": ["foo", "bar"], + "platform_dockerhost": [], "component_dockerhost_2": ["baz"] } + assert sorted(["component_dockerhost_1", "component_dockerhost_2"]) \ + == sorted(dis._find_matching_services(services, "component_dockerhost", [])) + + assert ["component_dockerhost_1"] == dis._find_matching_services(services, \ + "component_dockerhost", ["foo", "bar"]) + + assert ["component_dockerhost_1"] == dis._find_matching_services(services, \ + "component_dockerhost", ["foo"]) + + assert [] == dis._find_matching_services(services, "unknown", ["foo"]) diff --git a/docker/tests/test_tasks.py b/docker/tests/test_tasks.py index 74482c6..6661532 100644 --- a/docker/tests/test_tasks.py +++ b/docker/tests/test_tasks.py @@ -25,6 +25,17 @@ import dockerplugin from dockerplugin import tasks +def test_generate_component_name(): + kwargs = { "service_component_type": "doodle", + "service_component_name_override": None } + + assert "doodle" in tasks._generate_component_name(**kwargs)["name"] + + kwargs["service_component_name_override"] = "yankee" + + assert "yankee" == tasks._generate_component_name(**kwargs)["name"] + + def test_parse_streams(monkeypatch): # Good case for streams_publishes test_input = { "streams_publishes": [{"name": "topic00", "type": "message_router"}, @@ -166,33 +177,42 @@ def test_update_delivery_url(monkeypatch): def test_enhance_docker_params(): # Good - Test empty docker config - test_kwargs = { "docker_config": {} } + test_kwargs = { "docker_config": {}, "service_id": None } actual = tasks._enhance_docker_params(**test_kwargs) - assert actual == {'envs': {}, 'docker_config': {}} + assert actual == {'envs': {"SERVICE_TAGS": ""}, 'docker_config': {}, "service_id": None } # Good - Test just docker config ports and volumes test_kwargs = { "docker_config": { "ports": ["1:1", "2:2"], - "volumes": [{"container": "somewhere", "host": "somewhere else"}] } } + "volumes": [{"container": "somewhere", "host": "somewhere else"}] }, + "service_id": None } actual = tasks._enhance_docker_params(**test_kwargs) - assert actual == {'envs': {}, 'docker_config': {'ports': ['1:1', '2:2'], + assert actual == {'envs': {"SERVICE_TAGS": ""}, 'docker_config': {'ports': ['1:1', '2:2'], 'volumes': [{'host': 'somewhere else', 'container': 'somewhere'}]}, 'ports': ['1:1', '2:2'], 'volumes': [{'host': 'somewhere else', - 'container': 'somewhere'}]} + 'container': 'somewhere'}], "service_id": None} # Good - Test just docker config ports and volumes with overrrides test_kwargs = { "docker_config": { "ports": ["1:1", "2:2"], "volumes": [{"container": "somewhere", "host": "somewhere else"}] }, "ports": ["3:3", "4:4"], "volumes": [{"container": "nowhere", "host": - "nowhere else"}]} + "nowhere else"}], + "service_id": None } actual = tasks._enhance_docker_params(**test_kwargs) - assert actual == {'envs': {}, 'docker_config': {'ports': ['1:1', '2:2'], + assert actual == {'envs': {"SERVICE_TAGS": ""}, 'docker_config': {'ports': ['1:1', '2:2'], 'volumes': [{'host': 'somewhere else', 'container': 'somewhere'}]}, 'ports': ['1:1', '2:2', '3:3', '4:4'], 'volumes': [{'host': 'somewhere else', 'container': 'somewhere'}, {'host': 'nowhere else', 'container': - 'nowhere'}]} + 'nowhere'}], "service_id": None} + + # Good + + test_kwargs = { "docker_config": {}, "service_id": "zed", + "deployment_id": "abc" } + actual = tasks._enhance_docker_params(**test_kwargs) + assert actual["envs"] == {"SERVICE_TAGS": "abc,zed"} |