Update INFO.yaml with new PTL
[testsuite/python-testing-utils.git] / robotframework-onap / ONAPLibrary / RequestSOKeywords.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 ONAPLibrary.RequestsHelper import RequestsHelper
16 from robot.api import logger
17 from robot.api.deco import keyword
18 from robot.libraries.BuiltIn import BuiltIn
19
20
21 class RequestSOKeywords(object):
22     """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce
23     orchestrator. """
24
25     def __init__(self):
26         super(RequestSOKeywords, self).__init__()
27         self.builtin = BuiltIn()
28         self.reqs = RequestsHelper()
29
30     @keyword
31     def run_polling_get_request(self, endpoint, data_path, complete_states=None, fail_states=None, tries=20,
32                                 interval=15, auth=None):
33         """Runs an SO get request until a certain state is received."""
34         if fail_states is None:
35             fail_states = ["FAILED"]
36         if complete_states is None:
37             complete_states = ["COMPLETE"]
38         # do this until it is done
39         for i in range(tries):
40             resp = self.reqs.get_request(alias="so", endpoint=endpoint, data_path=data_path, auth=auth)
41             logger.info(resp.json()['request']['requestStatus']['requestState'])
42             if resp.json()['request']['requestStatus']['requestState'] in fail_states:
43                 self.builtin.fail("Received failure response from so " + resp.text)
44             if resp.json()['request']['requestStatus']['requestState'] in complete_states:
45                 logger.info("Received complete response from so " + resp.text)
46                 return True, resp
47             else:
48                 self.builtin.sleep(interval, "Response from SO is not in requested status")
49         return False, None
50
51     @keyword
52     def run_create_request(self, endpoint, data_path, data, auth=None):
53         """Runs an SO create request and returns the request id and instance id."""
54         response = self.reqs.post_request(alias="so", endpoint=endpoint, data_path=data_path, data=data, auth=auth)
55         logger.info("Creation request submitted to SO, got response")
56
57         req_id = response.get('requestReferences', {}).get('requestId', '')
58         instance_id = response.get('requestReferences', {}).get('instanceId', '')
59
60         return req_id, instance_id