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