initial redo of the requests keywords for client certs
[testsuite/python-testing-utils.git] / robotframework-onap / ONAPLibrary / SNIROKeywords.py
1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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
15 from robot.api import logger
16 from robot.api.deco import keyword
17 from robot.libraries.BuiltIn import BuiltIn
18
19 from ONAPLibrary.RequestsHelper import RequestsHelper
20 from ONAPLibrary.TemplatingKeywords import TemplatingKeywords
21 from ONAPLibrary.Base64Keywords import Base64Keywords
22
23
24 class SNIROKeywords(object):
25     """OOF is an ONAP testing library for Robot Framework that provides functionality for interacting with the
26     optimiztion framework. """
27
28     def __init__(self):
29         super(SNIROKeywords, self).__init__()
30         self.reqs = RequestsHelper()
31         self.templating = TemplatingKeywords()
32         self.base64 = Base64Keywords()
33         self.builtin = BuiltIn()
34
35     @keyword
36     def run_sniro_get_request(self, endpoint, data_path, accept="application/json", auth=None):
37         """Runs OOF-SNIRO Get request"""
38         resp = self.reqs.get_request(alias="oof-sniro", endpoint=endpoint, data_path=data_path, accept=accept,
39                                      auth=auth)
40         self.builtin.should_be_equal_as_strings(resp.status_code, "200")
41         return resp
42
43     @keyword
44     def reset_sniro(self, endpoint):
45         logger.debug('Clearing SNIRO data')
46         resp = self.reqs.post_request(alias="oof-sniro", endpoint=endpoint, data_path='/reset')
47         self.builtin.should_be_equal_as_strings(resp.status_code, "200", 'Clearing SNIRO date failed.')
48
49     @keyword
50     def preload_sniro(self, endpoint, template_directory, template_sniro_data, template_sniro_request,
51                       tunnelxconn_ar_name, vgw_name, vbrg_ar_name, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
52         self.templating.create_environment("sniro", template_directory)
53         logger.info('Preloading SNIRO for homing service')
54         replace_dict = {'tunnelxconn_ar_name': tunnelxconn_ar_name,
55                         'vgw_name': vgw_name,
56                         'brg_ar_name': vbrg_ar_name,
57                         'vgmux_svc_instance_uuid': vgmux_svc_instance_uuid,
58                         'vbrg_svc_instance_uuid': vbrg_svc_instance_uuid
59                         }
60         sniro_data = self.templating.apply_template("sniro", template_sniro_data, replace_dict)
61         base64_sniro_data = self.base64.base64_encode(sniro_data)
62         replace_dict = {'base64_sniro_data': base64_sniro_data}
63         sniro_request = self.templating.apply_template("sniro", template_sniro_request, replace_dict)
64         resp = self.reqs.post_request(alias="oof-sniro", endpoint=endpoint, data_path='/', data=sniro_request)
65         self.builtin.should_be_equal_as_strings(resp.status_code, "200", 'SNIRO preloading failed.')
66         return True