blob: 3a181dd44790c928a3a68fa6d968c257d460d541 [file] [log] [blame]
DR695H205db3c2019-07-01 13:58:49 -04001# 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.
DR695H335a1c82019-07-11 11:57:29 -040014
DR695H205db3c2019-07-01 13:58:49 -040015from robot.api import logger
16from robot.api.deco import keyword
17from robot.libraries.BuiltIn import BuiltIn
18
DR695H1afa01d2019-07-11 11:02:06 -040019from ONAPLibrary.RequestsHelper import RequestsHelper
DR695H205db3c2019-07-01 13:58:49 -040020from ONAPLibrary.TemplatingKeywords import TemplatingKeywords
21from ONAPLibrary.Base64Keywords import Base64Keywords
22
23
24class 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__()
DR695H1afa01d2019-07-11 11:02:06 -040030 self.reqs = RequestsHelper()
DR695H205db3c2019-07-01 13:58:49 -040031 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"""
DR695Hafd52372019-08-12 18:17:19 -040038 resp = self.reqs.get_request(alias="oof-sniro", endpoint=endpoint, data_path=data_path, accept=accept,
39 auth=auth)
DR695H205db3c2019-07-01 13:58:49 -040040 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')
DR695Hafd52372019-08-12 18:17:19 -040046 resp = self.reqs.post_request(alias="oof-sniro", endpoint=endpoint, data_path='/reset')
DR695H205db3c2019-07-01 13:58:49 -040047 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)
DR695Hafd52372019-08-12 18:17:19 -040064 resp = self.reqs.post_request(alias="oof-sniro", endpoint=endpoint, data_path='/', data=sniro_request)
DR695H205db3c2019-07-01 13:58:49 -040065 self.builtin.should_be_equal_as_strings(resp.status_code, "200", 'SNIRO preloading failed.')
66 return True