diff options
Diffstat (limited to 'docker')
-rw-r--r-- | docker/dockerplugin/discovery.py | 12 | ||||
-rw-r--r-- | docker/dockerplugin/tasks.py | 47 | ||||
-rw-r--r-- | docker/dockerplugin/utils.py | 3 | ||||
-rw-r--r-- | docker/requirements.txt | 7 | ||||
-rw-r--r-- | docker/setup.py | 9 | ||||
-rw-r--r-- | docker/tox.ini | 9 |
6 files changed, 42 insertions, 45 deletions
diff --git a/docker/dockerplugin/discovery.py b/docker/dockerplugin/discovery.py index 8361c13..563693c 100644 --- a/docker/dockerplugin/discovery.py +++ b/docker/dockerplugin/discovery.py @@ -2,6 +2,7 @@ # org.onap.dcae # ================================================================================ # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. 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. @@ -187,7 +188,7 @@ def is_healthy(consul_host, instance): def add_to_entry(conn, key, add_name, add_value): """ - Find 'key' in consul. + Find 'key' in consul. Treat its value as a JSON string representing a dict. Extend the dict by adding an entry with key 'add_name' and value 'add_value'. Turn the resulting extended dict into a JSON string. @@ -223,12 +224,9 @@ def add_to_entry(conn, key, add_name, add_value): def _find_matching_services(services, name_search, tags): """Find matching services given search criteria""" - def is_match(service): - srv_name, srv_tags = service - return name_search in srv_name and \ - all(map(lambda tag: tag in srv_tags, tags)) - - return [ srv[0] for srv in services.items() if is_match(srv) ] + tags = set(tags) + return [srv_name for srv_name in services + if name_search in srv_name and tags <= set(services[srv_name])] def search_services(conn, name_search, tags): """Search for services that match criteria diff --git a/docker/dockerplugin/tasks.py b/docker/dockerplugin/tasks.py index 03eba62..8a15319 100644 --- a/docker/dockerplugin/tasks.py +++ b/docker/dockerplugin/tasks.py @@ -2,6 +2,7 @@ # org.onap.dcae # ================================================================================ # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. 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. @@ -136,32 +137,29 @@ def _parse_streams(**kwargs): """Parse streams and setup for DMaaP plugin""" # The DMaaP plugin requires this plugin to set the runtime properties # keyed by the node name. - def setup_publishes(s): - kwargs[s["name"]] = s + for stream in kwargs["streams_publishes"]: + kwargs[stream["name"]] = stream - map(setup_publishes, kwargs["streams_publishes"]) - - def setup_subscribes(s): - if s["type"] == "data_router": - # If username and password has been provided then generate it. The - # DMaaP plugin doesn't generate for subscribers. The generation code - # and length of username password has been lifted from the DMaaP + # NOTE: That the delivery url is constructed and setup in the start operation + for stream in kwargs["streams_subscribes"]: + if stream["type"] == "data_router": + # If either username or password is missing then generate it. The + # DMaaP plugin doesn't generate them for subscribers. + # The code and length of username/password are lifted from the DMaaP # plugin. # Don't want to mutate the source - s = copy.deepcopy(s) - if not s.get("username", None): - s["username"] = utils.random_string(8) - if not s.get("password", None): - s["password"] = utils.random_string(10) + stream = copy.deepcopy(stream) + if not stream.get("username", None): + stream["username"] = utils.random_string(8) + if not stream.get("password", None): + stream["password"] = utils.random_string(10) - kwargs[s["name"]] = s - - # NOTE: That the delivery url is constructed and setup in the start operation - map(setup_subscribes, kwargs["streams_subscribes"]) + kwargs[stream["name"]] = stream return kwargs + def _setup_for_discovery_streams(**kwargs): """Setup for discovery of streams @@ -182,18 +180,17 @@ def _setup_for_discovery_streams(**kwargs): v = { "location": dr_sub["location"], "delivery_url": None, "username": dr_sub["username"], "password": dr_sub["password"], "subscriber_id": None } - return dis.add_to_entry(conn, dmaap_kv_key, dr_sub["name"], v) != None + return dis.add_to_entry(conn, dmaap_kv_key, dr_sub["name"], v) try: - if all(map(add_feed, dr_subs)): - return kwargs + for dr_sub in dr_subs: + if add_feed(dr_sub) is None: + raise NonRecoverableError( + "Failure updating feed streams in Consul") except Exception as e: raise NonRecoverableError(e) - # You should never get here - raise NonRecoverableError("Failure updating feed streams in Consul") - else: - return kwargs + return kwargs @merge_inputs_for_create diff --git a/docker/dockerplugin/utils.py b/docker/dockerplugin/utils.py index c45af68..6475aaa 100644 --- a/docker/dockerplugin/utils.py +++ b/docker/dockerplugin/utils.py @@ -2,6 +2,7 @@ # org.onap.dcae # ================================================================================ # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. 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. @@ -34,7 +35,7 @@ def update_dict(d, u): Update dict d with dict u """ - for k, v in u.iteritems(): + for k, v in u.items(): if isinstance(v, collections.Mapping): r = update_dict(d.get(k, {}), v) d[k] = r diff --git a/docker/requirements.txt b/docker/requirements.txt index 35db24e..36602c8 100644 --- a/docker/requirements.txt +++ b/docker/requirements.txt @@ -1,2 +1,5 @@ -onap-dcae-dockering==1.4.0 -onap-dcae-dcaepolicy-lib>=2.4.1,<3.0.0 +python-consul>=0.6.0 +onap-dcae-dockering>=1.4.0 +onap-dcae-dcaepolicy-lib>=2.4.1 +cloudify-common>=5.0.0; python_version<"3" +cloudify-common @ git+https://github.com/cloudify-cosmo/cloudify-common@cy-1374-python3#egg=cloudify-common==5.0.0; python_version>="3" diff --git a/docker/setup.py b/docker/setup.py index d301c49..8cb99b6 100644 --- a/docker/setup.py +++ b/docker/setup.py @@ -2,6 +2,7 @@ # org.onap.dcae # ================================================================================ # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. 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. @@ -29,9 +30,9 @@ setup( packages=['dockerplugin'], zip_safe=False, install_requires=[ - "python-consul>=0.6.0,<1.0.0", - "onap-dcae-dockering>=1.0.0,<2.0.0", - "uuid==1.30", - "onap-dcae-dcaepolicy-lib>=2.4.1,<3.0.0" + 'python-consul>=0.6.0', + 'onap-dcae-dockering>=1.4.0', + 'onap-dcae-dcaepolicy-lib>=2.4.1', + 'cloudify-common>=5.0.0', ] ) diff --git a/docker/tox.ini b/docker/tox.ini index 9e3cfb2..c38918a 100644 --- a/docker/tox.ini +++ b/docker/tox.ini @@ -1,16 +1,13 @@ # content of: tox.ini , put in same dir as setup.py [tox] -envlist = py27 +envlist = py27,py36 [testenv] deps= -rrequirements.txt - cloudify-plugins-common==3.4 pytest coverage pytest-cov -setenv= - PYTHONPATH={toxinidir} commands= - pytest --junitxml xunit-results.xml --cov dockerplugin --cov-report xml - coverage xml + pytest --junitxml xunit-results.xml --cov dockerplugin --cov-report xml + coverage xml |