1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 from RequestsLibrary import RequestsLibrary
15 from robot.api import logger
16 from robot.api.deco import keyword
17 from robot.libraries.BuiltIn import BuiltIn
19 from ONAPLibrary.RequestsHelper import RequestsHelper
20 from ONAPLibrary.TemplatingKeywords import TemplatingKeywords
21 from ONAPLibrary.Base64Keywords import Base64Keywords
24 class SNIROKeywords(object):
25 """OOF is an ONAP testing library for Robot Framework that provides functionality for interacting with the
26 optimiztion framework. """
29 super(SNIROKeywords, self).__init__()
30 self.reqs = RequestsHelper()
31 self.templating = TemplatingKeywords()
32 self.base64 = Base64Keywords()
33 self.builtin = BuiltIn()
36 def run_sniro_get_request(self, endpoint, data_path, accept="application/json", auth=None):
37 """Runs OOF-SNIRO Get request"""
38 resp = self.get_request(endpoint, data_path, accept, auth)
39 self.builtin.should_be_equal_as_strings(resp.status_code, "200")
43 def reset_sniro(self, endpoint):
44 logger.debug('Clearing SNIRO data')
45 resp = self.post_request(endpoint, '/reset', None)
46 self.builtin.should_be_equal_as_strings(resp.status_code, "200", 'Clearing SNIRO date failed.')
49 def preload_sniro(self, endpoint, template_directory, template_sniro_data, template_sniro_request,
50 tunnelxconn_ar_name, vgw_name, vbrg_ar_name, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
51 self.templating.create_environment("sniro", template_directory)
52 logger.info('Preloading SNIRO for homing service')
53 replace_dict = {'tunnelxconn_ar_name': tunnelxconn_ar_name,
55 'brg_ar_name': vbrg_ar_name,
56 'vgmux_svc_instance_uuid': vgmux_svc_instance_uuid,
57 'vbrg_svc_instance_uuid': vbrg_svc_instance_uuid
59 sniro_data = self.templating.apply_template("sniro", template_sniro_data, replace_dict)
60 base64_sniro_data = self.base64.base64_encode(sniro_data)
61 replace_dict = {'base64_sniro_data': base64_sniro_data}
62 sniro_request = self.templating.apply_template("sniro", template_sniro_request, replace_dict)
63 resp = self.post_request(endpoint, '/', sniro_request)
64 self.builtin.should_be_equal_as_strings(resp.status_code, "200", 'SNIRO preloading failed.')
67 def post_request(self, endpoint, data_path, data, accept="application/json", auth=None):
68 """Runs an SNIRO post request"""
69 logger.info("Creating session" + endpoint)
70 RequestsLibrary().create_session("so", endpoint, auth=auth)
71 headers = self.reqs.create_headers(accept=accept)
72 resp = RequestsLibrary().post_request("so", data_path, data=data, headers=headers)
73 logger.info("Received response from so " + resp.text)
76 def get_request(self, endpoint, data_path, accept="application/json", auth=None):
77 """Runs an SNIRO get request"""
78 logger.info("Creating session" + endpoint)
79 RequestsLibrary().create_session("sniro", endpoint, auth=auth)
80 resp = RequestsLibrary().get_request("sniro", data_path, headers=self.reqs.create_headers(accept=accept))
81 logger.info("Received response from OOF-SNIRO " + resp.text)