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.
15 from ONAPLibrary.RequestsHelper import RequestsHelper
16 from ONAPLibrary.TemplatingKeywords import TemplatingKeywords
17 from robot.api.deco import keyword
18 from robot.libraries.BuiltIn import BuiltIn
21 class CloudConfigSOKeywords(object):
22 """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce
26 super(CloudConfigSOKeywords, self).__init__()
27 self.builtin = BuiltIn()
28 self.reqs = RequestsHelper()
29 self.templating = TemplatingKeywords()
32 def get_cloud_configuration(self, endpoint, data_path, site_name, auth=None):
33 """Gets cloud configuration in SO"""
34 return self.reqs.get_request("so", endpoint, data_path + "/" + site_name, auth=auth)
37 def create_cloud_configuration(self, endpoint, data_path, templates_folder, template, arguments, auth=None):
38 """Creates a cloud configuration in SO, so it knows how to talk to an openstack cloud"""
39 self.templating.create_environment("so", templates_folder)
40 data = self.templating.apply_template("so", template, arguments)
41 resp = self.reqs.post_request("so", endpoint, data_path, data, auth=auth)
42 self.builtin.should_match_regexp(str(resp.status_code), "^(201|200)$")
45 def upsert_cloud_configuration(self, endpoint, data_path, templates_folder, template, arguments, auth=None):
46 """Creates a cloud configuration in SO, or if it exists updates it"""
47 get_resp = self.get_cloud_configuration(endpoint, data_path, arguments['site_name'])
48 self.templating.create_environment("so", templates_folder)
49 data = self.templating.apply_template("so", template, arguments)
50 if get_resp.status_code == 404:
51 resp = self.reqs.post_request("so", endpoint, data_path, data, auth=auth)
53 resp = self.reqs.put_request("so", endpoint, data_path, data, auth=auth)
54 self.builtin.should_match_regexp(str(resp.status_code), "^(201|200)$")