diff options
-rw-r--r-- | onap-dcae-dcaepolicy-lib/README.md | 2 | ||||
-rw-r--r-- | onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py | 20 | ||||
-rw-r--r-- | onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/policies_output.py | 13 | ||||
-rw-r--r-- | onap-dcae-dcaepolicy-lib/pom.xml | 4 | ||||
-rw-r--r-- | onap-dcae-dcaepolicy-lib/setup.py | 4 | ||||
-rw-r--r-- | onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py | 32 |
6 files changed, 39 insertions, 36 deletions
diff --git a/onap-dcae-dcaepolicy-lib/README.md b/onap-dcae-dcaepolicy-lib/README.md index 0273b7b..b279a23 100644 --- a/onap-dcae-dcaepolicy-lib/README.md +++ b/onap-dcae-dcaepolicy-lib/README.md @@ -15,7 +15,7 @@ python setup.py sdist upload ### **requirements.txt** ```python -onap-dcae-dcaepolicy-lib==2.4.1 +onap-dcae-dcaepolicy-lib==2.5.0 ``` ### **tasks.py** diff --git a/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py b/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py index a8d8d70..68a9858 100644 --- a/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py +++ b/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py @@ -1,5 +1,5 @@ # ================================================================================ -# 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. @@ -126,7 +126,7 @@ class Policies(object): property_policy_filter = target.node.properties.get(POLICY_FILTER) if property_policy_filter: policy_filter = deepcopy(dict( - (k, v) for (k, v) in dict(property_policy_filter).iteritems() + (k, v) for (k, v) in dict(property_policy_filter).items() if v or isinstance(v, (int, float)) )) Policies._fix_policy_filter(policy_filter) @@ -140,7 +140,7 @@ class Policies(object): filtered_policies = target.instance.runtime_properties.get(POLICIES_FILTERED) if not filtered_policies or not isinstance(filtered_policies, dict): return True - for (policy_id, policy) in filtered_policies.iteritems(): + for (policy_id, policy) in filtered_policies.items(): Policies._add_policy(policy_id, policy, False, policies) return True @@ -150,9 +150,8 @@ class Policies(object): if not policies: return {} - return dict((policy_id, policy.get(POLICY_BODY)) - for policy_id, policy in policies.iteritems() if policy.get(POLICY_BODY) - ) + return {policy_id: policy.get(POLICY_BODY) + for policy_id, policy in policies.items() if policy.get(POLICY_BODY)} @staticmethod def gather_policies_to_node(): @@ -238,11 +237,12 @@ class Policies(object): new_policies = dict((policy_id, policy) for policy_filter_id in policy_filters for (policy_id, policy) in added_policies.get(policy_filter_id, {}) - .get(POLICIES, {}).iteritems()) + .get(POLICIES, {}).items()) ctx.logger.info("new_policies: {0}".format(json.dumps(new_policies))) - for (policy_id, policy) in new_policies.iteritems(): + for policy_id in new_policies: + policy = new_policies.get(policy_id) deployed_policy = policies.get(policy_id) if not deployed_policy: policies[policy_id] = policy @@ -363,8 +363,8 @@ class Policies(object): """returns the list of policy_body objects if policy_body exists""" if isinstance(selected_policies, dict): return deepcopy([policy.get(POLICY_BODY) - for policy in selected_policies.values() if policy.get(POLICY_BODY)]) + for policy in selected_policies.itervalues() if policy.get(POLICY_BODY)]) policies = ctx.instance.runtime_properties.get(POLICIES, {}) return deepcopy([policy.get(POLICY_BODY) - for policy in policies.values() if policy.get(POLICY_BODY)]) + for policy in policies.itervalues() if policy.get(POLICY_BODY)]) diff --git a/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/policies_output.py b/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/policies_output.py index d8125c0..0034b9c 100644 --- a/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/policies_output.py +++ b/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/policies_output.py @@ -1,5 +1,5 @@ # ================================================================================ -# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 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,7 +20,10 @@ import base64 import json -import urllib +try: + from urllib.parse import quote +except ImportError: + from urllib import quote import uuid from datetime import datetime @@ -51,7 +54,7 @@ class PoliciesOutput(object): def _gen_txn_operation(verb, service_component_name, key=None, value=None): """returns the properly formatted operation to be used inside transaction""" key = PoliciesOutput.POLICIES_FOLDER_MASK.format( - service_component_name, urllib.quote(key or "") + service_component_name, quote(key or "") ) if value: return {"KV": {"Verb": verb, "Key": key, "Value": base64.b64encode(value)}} @@ -108,7 +111,7 @@ class PoliciesOutput(object): store_policies = [ PoliciesOutput._gen_txn_operation(PoliciesOutput.OPERATION_SET, service_component_name, "items/" + policy_id, json.dumps(policy_body)) - for policy_id, policy_body in policy_bodies.iteritems() + for policy_id, policy_body in policy_bodies.items() ] txn = [ PoliciesOutput._gen_txn_operation( @@ -117,7 +120,7 @@ class PoliciesOutput(object): PoliciesOutput.OPERATION_SET, service_component_name, "event", json.dumps(event)) ] idx_step = PoliciesOutput.MAX_OPS_PER_TXN - len(txn) - for idx in xrange(0, len(store_policies), idx_step): + for idx in range(0, len(store_policies), idx_step): txn += store_policies[idx : idx + idx_step] if not PoliciesOutput._run_transaction("store_policies", txn): return False diff --git a/onap-dcae-dcaepolicy-lib/pom.xml b/onap-dcae-dcaepolicy-lib/pom.xml index ecbbea7..3bc3719 100644 --- a/onap-dcae-dcaepolicy-lib/pom.xml +++ b/onap-dcae-dcaepolicy-lib/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0"?> <!-- ================================================================================ -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. @@ -27,7 +27,7 @@ limitations under the License. <groupId>org.onap.dcaegen2.utils</groupId> <artifactId>onap-dcae-dcaepolicy-lib</artifactId> <name>dcaegen2-utils-onap-dcae-dcaepolicy-lib</name> - <version>2.4.1-SNAPSHOT</version> + <version>2.5.0-SNAPSHOT</version> <url>http://maven.apache.org</url> <properties> diff --git a/onap-dcae-dcaepolicy-lib/setup.py b/onap-dcae-dcaepolicy-lib/setup.py index b68247d..ea443c7 100644 --- a/onap-dcae-dcaepolicy-lib/setup.py +++ b/onap-dcae-dcaepolicy-lib/setup.py @@ -1,5 +1,5 @@ # ================================================================================ -# 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. @@ -23,7 +23,7 @@ from setuptools import setup, find_packages setup( name='onap-dcae-dcaepolicy-lib', description='lib of policy decorators to be used by cloudify plugins of dcae controller', - version="2.4.1", + version="2.5.0", author='Alex Shatov', author_email="alexs@att.com", license='Apache 2', diff --git a/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py b/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py index 4b3e39c..7281757 100644 --- a/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py +++ b/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.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. @@ -132,18 +132,18 @@ class MonkeyedPolicyBody(object): """check whether both policy_body objects are the same""" if not isinstance(policy_body_1, dict) or not isinstance(policy_body_2, dict): return False - for key in policy_body_1.keys(): + for key in policy_body_1: if key not in policy_body_2: return False val_1 = policy_body_1[key] val_2 = policy_body_2[key] + if (val_1 is None) != (val_2 is None): + return False if isinstance(val_1, dict) \ and not MonkeyedPolicyBody.is_the_same_dict(val_1, val_2): return False - if (val_1 is None and val_2 is not None) \ - or (val_1 is not None and val_2 is None) \ - or (val_1 != val_2): + if val_1 != val_2: return False return True @@ -592,7 +592,7 @@ def test_update_policies(): ctx.logger.info("policy[{0}]: not yet in policies".format(MONKEYED_POLICY_ID_M_2)) assert MONKEYED_POLICY_ID_M_2 not in policies - policy_filter_ids = runtime_properties.get(dcae_policy.POLICY_FILTERS, {}).keys() or ["--"] + policy_filter_ids = list(runtime_properties.get(dcae_policy.POLICY_FILTERS) or ["--"]) policy_update(updated_policies=[updated_policy], added_policies={ @@ -653,7 +653,7 @@ def test_update_not_only_config(): ctx.logger.info("policy[{0}]: not yet in policies".format(MONKEYED_POLICY_ID_M_2)) assert MONKEYED_POLICY_ID_M_2 not in policies - policy_filter_ids = runtime_properties.get(dcae_policy.POLICY_FILTERS, {}).keys() or ["--"] + policy_filter_ids = list(runtime_properties.get(dcae_policy.POLICY_FILTERS) or ["--"]) policy_update_not_only_config(updated_policies=[updated_policy], added_policies={ @@ -728,7 +728,7 @@ def test_update_policies_not(): assert unexpected_removed_policy_id not in policies assert junk_policy_filter_id not in runtime_properties.get(dcae_policy.POLICY_FILTERS, {}) - policy_filter_ids = runtime_properties.get(dcae_policy.POLICY_FILTERS, {}).keys() or ["--"] + policy_filter_ids = list(runtime_properties.get(dcae_policy.POLICY_FILTERS) or ["--"]) policy_update(updated_policies=[existing_policy, damaged_policy, updated_policy], added_policies={ @@ -770,7 +770,7 @@ def test_update_many_calcs(): ctx.logger.info("policy[{0}]: not yet in policies".format(MONKEYED_POLICY_ID_M_2)) assert MONKEYED_POLICY_ID_M_2 not in policies - policy_filter_ids = runtime_properties.get(dcae_policy.POLICY_FILTERS, {}).keys() or ["--"] + policy_filter_ids = list(runtime_properties.get(dcae_policy.POLICY_FILTERS) or ["--"]) policy_update_many_calcs(updated_policies=[updated_policy], added_policies={ @@ -823,7 +823,7 @@ def test_remove_all_policies(): policies = runtime_properties[dcae_policy.POLICIES] ctx.logger.info("policies: {0}".format(json.dumps(policies))) - remove_policy_ids = policies.keys() + remove_policy_ids = list(policies) policy_update(updated_policies=None, added_policies=None, removed_policies=remove_policy_ids) @@ -853,7 +853,7 @@ def test_remove_all_policies_twice(): policies = runtime_properties[dcae_policy.POLICIES] ctx.logger.info("policies: {0}".format(json.dumps(policies))) - remove_policy_ids = policies.keys() + remove_policy_ids = list(policies) policy_update(updated_policies=None, added_policies=None, removed_policies=remove_policy_ids) policy_update(updated_policies=None, added_policies=None, removed_policies=remove_policy_ids) @@ -884,7 +884,7 @@ def test_remove_then_update(): policies = runtime_properties[dcae_policy.POLICIES] ctx.logger.info("policies: {0}".format(json.dumps(policies))) - remove_policy_ids = policies.keys() + remove_policy_ids = list(policies) policy_update(updated_policies=None, added_policies=None, removed_policies=remove_policy_ids) updated_policy = MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID_2, 2, priority="aa20") @@ -895,7 +895,7 @@ def test_remove_then_update(): ctx.logger.info("policy[{0}]: not yet in policies".format(MONKEYED_POLICY_ID_M_2)) assert MONKEYED_POLICY_ID_M_2 not in policies - policy_filter_ids = runtime_properties.get(dcae_policy.POLICY_FILTERS, {}).keys() or ["--"] + policy_filter_ids = list(runtime_properties.get(dcae_policy.POLICY_FILTERS) or ["--"]) policy_update(updated_policies=[updated_policy], added_policies={ @@ -935,7 +935,7 @@ def test_remove_update_many_calcs(): policies = runtime_properties[dcae_policy.POLICIES] ctx.logger.info("policies: {0}".format(json.dumps(policies))) - remove_policy_ids = policies.keys() + remove_policy_ids = list(policies) policy_update_many_calcs(updated_policies=None, added_policies=None, removed_policies=remove_policy_ids) @@ -952,7 +952,7 @@ def test_remove_update_many_calcs(): ctx.logger.info("policy[{0}]: not yet in policies".format(MONKEYED_POLICY_ID_M_2)) assert MONKEYED_POLICY_ID_M_2 not in policies - policy_filter_ids = runtime_properties.get(dcae_policy.POLICY_FILTERS, {}).keys() or ["--"] + policy_filter_ids = list(runtime_properties.get(dcae_policy.POLICY_FILTERS) or ["--"]) policy_update_many_calcs(updated_policies=[updated_policy], added_policies={ @@ -1004,7 +1004,7 @@ def test_bad_update_many_calcs(): ctx.logger.info("policy[{0}]: not yet in policies".format(MONKEYED_POLICY_ID_M_2)) assert MONKEYED_POLICY_ID_M_2 not in policies - policy_filter_ids = runtime_properties.get(dcae_policy.POLICY_FILTERS, {}).keys() or ["--"] + policy_filter_ids = list(runtime_properties.get(dcae_policy.POLICY_FILTERS) or ["--"]) policy_update_many_calcs(updated_policies=[damaged_policy], added_policies={ |