DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 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 ONAPLibrary.RequestsHelper import RequestsHelper |
| 16 | from ONAPLibrary.TemplatingKeywords import TemplatingKeywords |
| 17 | from robot.api.deco import keyword |
| 18 | from robot.libraries.BuiltIn import BuiltIn |
| 19 | |
| 20 | |
DR695H | 303fda1 | 2019-09-19 12:24:38 -0400 | [diff] [blame^] | 21 | class CloudConfigSOKeywords(object): |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 22 | """SO is an ONAP testing library for Robot Framework that provides |
| 23 | functionality for interacting with the service orchestrator. """ |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 24 | |
| 25 | def __init__(self): |
| 26 | super(CloudConfigSOKeywords, self).__init__() |
| 27 | self.builtin = BuiltIn() |
| 28 | self.reqs = RequestsHelper() |
| 29 | self.templating = TemplatingKeywords() |
| 30 | |
| 31 | @keyword |
| 32 | def get_cloud_configuration(self, endpoint, data_path, site_name, auth=None): |
| 33 | """Gets cloud configuration in SO""" |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 34 | return self.reqs.get_request( |
| 35 | alias="so", |
| 36 | endpoint=endpoint, |
| 37 | data_path=data_path + "/" + site_name, |
| 38 | auth=auth) |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 39 | |
| 40 | @keyword |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 41 | def create_cloud_configuration(self, endpoint, data_path, templates_folder, |
| 42 | template, arguments, auth=None): |
| 43 | """Creates a cloud configuration in SO |
| 44 | so it knows how to talk to an openstack cloud""" |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 45 | self.templating.create_environment("so", templates_folder) |
| 46 | data = self.templating.apply_template("so", template, arguments) |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 47 | resp = self.reqs.post_request( |
| 48 | alias="so", |
| 49 | endpoint=endpoint, |
| 50 | data_path=data_path, |
| 51 | data=data, |
| 52 | auth=auth) |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 53 | self.builtin.should_match_regexp(str(resp.status_code), "^(201|200)$") |
| 54 | |
| 55 | @keyword |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 56 | def upsert_cloud_configuration(self, endpoint, data_path, templates_folder, |
| 57 | template, arguments, auth=None): |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 58 | """Creates a cloud configuration in SO, or if it exists updates it""" |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 59 | get_resp = self.get_cloud_configuration( |
| 60 | endpoint, data_path, arguments['site_name'], auth=auth) |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 61 | self.templating.create_environment("so", templates_folder) |
| 62 | data = self.templating.apply_template("so", template, arguments) |
| 63 | if get_resp.status_code == 404: |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 64 | resp = self.reqs.post_request( |
| 65 | alias="so", |
| 66 | endpoint=endpoint, |
| 67 | data_path=data_path, |
| 68 | data=data, |
| 69 | auth=auth) |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 70 | else: |
umry8364 | 12b24d7 | 2019-09-10 16:00:21 +0200 | [diff] [blame] | 71 | resp = self.reqs.put_request( |
| 72 | alias="so", |
| 73 | endpoint=endpoint, |
| 74 | data_path=data_path + "/" + arguments['site_name'], |
| 75 | data=data, |
| 76 | auth=auth) |
DR695H | 7145fe0 | 2019-07-24 16:37:01 -0400 | [diff] [blame] | 77 | self.builtin.should_match_regexp(str(resp.status_code), "^(201|200)$") |