blob: 671a306b0c309f100bc3fb5f365519e89d65eeac [file] [log] [blame]
DR695H45b0fbf2019-05-24 14:28:57 -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
15from ONAPLibrary.RequestsHelper import RequestsHelper
DR695H45b0fbf2019-05-24 14:28:57 -040016from robot.api import logger
17from robot.api.deco import keyword
18from robot.libraries.BuiltIn import BuiltIn
19
DR695H45b0fbf2019-05-24 14:28:57 -040020
21class 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__()
DR695H45b0fbf2019-05-24 14:28:57 -040027 self.builtin = BuiltIn()
DR695H335a1c82019-07-11 11:57:29 -040028 self.reqs = RequestsHelper()
DR695H45b0fbf2019-05-24 14:28:57 -040029
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):
DR695Hafd52372019-08-12 18:17:19 -040040 resp = self.reqs.get_request(alias="so", endpoint=endpoint, data_path=data_path, auth=auth)
DR695H45b0fbf2019-05-24 14:28:57 -040041 logger.info(resp.json()['request']['requestStatus']['requestState'])
DR695He74c39b2019-07-29 14:50:13 -040042 if resp.json()['request']['requestStatus']['requestState'] in fail_states:
43 self.builtin.fail("Received failure response from so " + resp.text)
DR695H45b0fbf2019-05-24 14:28:57 -040044 if resp.json()['request']['requestStatus']['requestState'] in complete_states:
DR695He74c39b2019-07-29 14:50:13 -040045 logger.info("Received complete response from so " + resp.text)
DR695H843119f2019-07-09 18:10:15 -040046 return True, resp
DR695H45b0fbf2019-05-24 14:28:57 -040047 else:
48 self.builtin.sleep(interval, "Response from SO is not in requested status")
DR695H843119f2019-07-09 18:10:15 -040049 return False, None
DR695H45b0fbf2019-05-24 14:28:57 -040050
51 @keyword
DR695H843119f2019-07-09 18:10:15 -040052 def run_create_request(self, endpoint, data_path, data, auth=None):
DR695H45b0fbf2019-05-24 14:28:57 -040053 """Runs an SO create request and returns the request id and instance id."""
DR695Hafd52372019-08-12 18:17:19 -040054 response = self.reqs.post_request(alias="so", endpoint=endpoint, data_path=data_path, data=data, auth=auth)
DR695H45b0fbf2019-05-24 14:28:57 -040055 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