From 3db5715fbfa519dfabb2dab95630b294e7fd2857 Mon Sep 17 00:00:00 2001 From: DR695H Date: Wed, 31 Jul 2019 17:42:10 -0400 Subject: pull global vars from robot trial Issue-ID: TEST-184 Change-Id: I008c9cfbc1ae65c7735fcab2b474a0cbf7ec2ca9 Signed-off-by: DR695H --- robotframework-onap/ONAPLibrary/BaseAAIKeywords.py | 18 ++++++--- robotframework-onap/ONAPLibrary/Utilities.py | 4 +- robotframework-onap/ONAPLibrary/VariableHelper.py | 43 -------------------- .../ONAPLibrary/VariableKeywords.py | 46 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 50 deletions(-) delete mode 100644 robotframework-onap/ONAPLibrary/VariableHelper.py create mode 100644 robotframework-onap/ONAPLibrary/VariableKeywords.py (limited to 'robotframework-onap/ONAPLibrary') diff --git a/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py b/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py index 2804e23..a512203 100644 --- a/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py +++ b/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py @@ -19,6 +19,7 @@ import time from ONAPLibrary.RequestsHelper import RequestsHelper from ONAPLibrary.HTTPKeywords import HTTPKeywords +from ONAPLibrary.VariableKeywords import VariableKeywords class BaseAAIKeywords(object): @@ -30,6 +31,11 @@ class BaseAAIKeywords(object): self.reqs = RequestsHelper() self.builtin = BuiltIn() self.http = HTTPKeywords() + self.vars = VariableKeywords() + aai_ip_addr = self.vars.get_globally_injected_parameters()['GLOBAL_INJECTED_AAI_IP_ADDR'] + aai_server_protocol = self.vars.get_global_parameters()['GLOBAL_AAI_SERVER_PROTOCOL'] + aai_server_port = self.vars.get_global_parameters()['GLOBAL_AAI_SERVER_PORT'] + self.aai_endpoint = aai_server_protocol + '://' + aai_ip_addr + ':' + aai_server_port @keyword def run_get_request(self, endpoint, data_path, accept="application/json", auth=None): @@ -54,15 +60,15 @@ class BaseAAIKeywords(object): def run_delete_request(self, endpoint, data_path, resource_version, accept="application/json", auth=None): """Runs an AAI delete request""" self.http.disable_warnings() - return self.reqs.delete_request("aai", endpoint, data_path + '?resource-version=' + resource_version, data=None, - sdc_user=None, accept=accept, auth=auth) + return self.reqs.delete_request("aai", endpoint, data_path + '?resource-version=' + resource_version, + data=None, sdc_user=None, accept=accept, auth=auth) @keyword - def wait_for_node_to_exist(self, endpoint, search_node_type, key, uuid, auth=None): + def wait_for_node_to_exist(self, search_node_type, key, uuid, auth=None): logger.info('Waiting for AAI traversal to complete...') for i in range(30): time.sleep(1) - result = self.find_node(endpoint, search_node_type, key, uuid, auth=auth) + result = self.find_node(search_node_type, key, uuid, auth=auth) if result: return result @@ -72,10 +78,10 @@ class BaseAAIKeywords(object): self.builtin.fail(error_message) @keyword - def find_node(self, endpoint, search_node_type, key, node_uuid, auth=None): + def find_node(self, search_node_type, key, node_uuid, auth=None): data_path = '/aai/v11/search/nodes-query?search-node-type={0}&filter={1}:EQUALS:{2}'.format( search_node_type, key, node_uuid) self.http.disable_warnings() - resp = self.reqs.get_request("aai", endpoint, data_path, accept="application/json", auth=auth) + resp = self.reqs.get_request("aai", self.aai_endpoint, data_path, accept="application/json", auth=auth) response = resp.json() return 'result-data' in response diff --git a/robotframework-onap/ONAPLibrary/Utilities.py b/robotframework-onap/ONAPLibrary/Utilities.py index 5751e21..4773432 100644 --- a/robotframework-onap/ONAPLibrary/Utilities.py +++ b/robotframework-onap/ONAPLibrary/Utilities.py @@ -18,6 +18,7 @@ from ONAPLibrary.SocketKeywords import SocketKeywords from ONAPLibrary.UUIDKeywords import UUIDKeywords from ONAPLibrary.HTTPKeywords import HTTPKeywords from ONAPLibrary.Base64Keywords import Base64Keywords +from ONAPLibrary.VariableKeywords import VariableKeywords class Utilities(HybridCore): @@ -31,6 +32,7 @@ class Utilities(HybridCore): SocketKeywords(), UUIDKeywords(), HTTPKeywords(), - Base64Keywords() + Base64Keywords(), + VariableKeywords() ] HybridCore.__init__(self, self.keyword_implementors) diff --git a/robotframework-onap/ONAPLibrary/VariableHelper.py b/robotframework-onap/ONAPLibrary/VariableHelper.py deleted file mode 100644 index 4a0b819..0000000 --- a/robotframework-onap/ONAPLibrary/VariableHelper.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 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. - -from robot.libraries.BuiltIn import BuiltIn - - -class VariableHelper(object): - """ Non keyword class for useful for working with varaibles """ - - def __init__(self): - super(VariableHelper, self).__init__() - self.builtin = BuiltIn() - - def get_globally_injected_parameters(self): - dictionary = self.builtin.get_variables(no_decoration=True) - return self.filter_variables_by_key_prefix(dictionary, "GLOBAL_INJECTED_") - - def get_global_parameters(self): - dictionary = self.builtin.get_variables(no_decoration=True) - global_variables = self.filter_variables_by_key_prefix(dictionary, "GLOBAL_") - # strip out global injected (get those above) - for key in self.get_globally_injected_parameters(): - del global_variables[key] - return global_variables - - @staticmethod - def filter_variables_by_key_prefix(dictionary, partial): - matches = dict() - for key, val in dictionary.items(): - if key.startswith(partial): - matches[key] = val - return matches diff --git a/robotframework-onap/ONAPLibrary/VariableKeywords.py b/robotframework-onap/ONAPLibrary/VariableKeywords.py new file mode 100644 index 0000000..6338aa2 --- /dev/null +++ b/robotframework-onap/ONAPLibrary/VariableKeywords.py @@ -0,0 +1,46 @@ +# Copyright 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. + +from robot.libraries.BuiltIn import BuiltIn +from robot.api.deco import keyword + + +class VariableKeywords(object): + """ keyword class for useful keywords for working with varaibles """ + + def __init__(self): + super(VariableKeywords, self).__init__() + self.builtin = BuiltIn() + + @keyword + def get_globally_injected_parameters(self): + dictionary = self.builtin.get_variables(no_decoration=True) + return self._filter_variables_by_key_prefix(dictionary, "GLOBAL_INJECTED_") + + @keyword + def get_global_parameters(self): + dictionary = self.builtin.get_variables(no_decoration=True) + global_variables = self._filter_variables_by_key_prefix(dictionary, "GLOBAL_") + # strip out global injected (get those above) + for key in self.get_globally_injected_parameters(): + del global_variables[key] + return global_variables + + @staticmethod + def _filter_variables_by_key_prefix(dictionary, partial): + matches = dict() + for key, val in dictionary.items(): + if key.startswith(partial): + matches[key] = val + return matches -- cgit 1.2.3-korg