create so keywords for use in robot framework 88/88488/2
authorDR695H <dr695h@att.com>
Fri, 24 May 2019 18:28:57 +0000 (14:28 -0400)
committerDR695H <dr695h@att.com>
Fri, 24 May 2019 18:33:55 +0000 (14:33 -0400)
recreates all of SO_Interface into a python component

Change-Id: I2a1347cb6614979692244156cefe2849b7894709
Issue-ID: TEST-158
Signed-off-by: DR695H <dr695h@att.com>
robotframework-onap/ONAPLibrary/BaseSOKeywords.py [new file with mode: 0644]
robotframework-onap/ONAPLibrary/RequestSOKeywords.py [new file with mode: 0644]
robotframework-onap/ONAPLibrary/SO.py [new file with mode: 0644]
robotframework-onap/setup.py

diff --git a/robotframework-onap/ONAPLibrary/BaseSOKeywords.py b/robotframework-onap/ONAPLibrary/BaseSOKeywords.py
new file mode 100644 (file)
index 0000000..1c9f6f3
--- /dev/null
@@ -0,0 +1,90 @@
+# Copyright 2019 AT&T Intellectual Property. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from RequestsLibrary import RequestsLibrary
+from robot.api import logger
+from robot.api.deco import keyword
+from robot.libraries.BuiltIn import BuiltIn
+
+from eteutils.UUID import UUID
+
+
+class BaseSOKeywords(object):
+    """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce
+    orchestrator. """
+
+    def __init__(self):
+        super(BaseSOKeywords, self).__init__()
+        self.application_id = "robot-ete"
+        self.uuid = UUID()
+        self.builtin = BuiltIn()
+
+    @keyword
+    def run_get_request(self, endpoint, data_path, accept="application/json", auth=None):
+        """Runs an SO get request"""
+        resp = self.get_request(endpoint, data_path, accept, auth)
+        self.builtin.should_be_equal_as_strings(resp.status_code, "200")
+        return resp
+
+    @keyword
+    def run_post_request(self, endpoint, data_path, data, accept="application/json", auth=None):
+        """Runs an SO post request"""
+        return self.post_request(endpoint, data_path, data, accept, auth)
+
+    @keyword
+    def run_put_request(self, endpoint, data_path, data, accept="application/json", auth=None):
+        """Runs an SO post request"""
+        return self.put_request(endpoint, data_path, data, accept, auth)
+
+    def get_request(self, endpoint, data_path, accept="application/json", auth=None):
+        """Runs an SO get request"""
+        logger.info("Creating session" + endpoint)
+        RequestsLibrary().create_session("so", endpoint, auth=auth)
+        resp = RequestsLibrary().get_request("so", data_path, headers=self.create_headers(accept))
+        logger.info("Received response from so " + resp.text)
+        return resp
+
+    def create_headers(self, accept="application/json"):
+        """Create the headers that are used by so"""
+        uuid = self.uuid.generate_UUID()
+        headers = {
+            "Accept": accept,
+            "Content-Type": "application/json",
+            "X-TransactionId": self.application_id + "-" + uuid,
+            "X-FromAppId": self.application_id
+        }
+        return headers
+
+    def post_request(self, endpoint, data_path, data, accept="application/json", auth=None):
+        """Runs an SO post request"""
+        logger.info("Creating session" + endpoint)
+        RequestsLibrary().create_session("so", endpoint, auth=auth)
+        resp = RequestsLibrary().post_request("so", data_path, data=data, headers=self.create_headers(accept))
+        logger.info("Received response from so " + resp.text)
+        return resp
+
+    def put_request(self, endpoint, data_path, data, accept="application/json", auth=None):
+        """Runs an SO post request"""
+        logger.info("Creating session" + endpoint)
+        RequestsLibrary().create_session("so", endpoint, auth=auth)
+        resp = RequestsLibrary().put_request("so", data_path, data=data, headers=self.create_headers(accept))
+        logger.info("Received response from so " + resp.text)
+        return resp
+
+    def delete_request(self, endpoint, data_path, data, accept="application/json", auth=None):
+        """Runs an SO post request"""
+        logger.info("Creating session" + endpoint)
+        RequestsLibrary().create_session("so", endpoint, auth=auth)
+        resp = RequestsLibrary().delete_request("so", data_path, data=data, headers=self.create_headers(accept))
+        logger.info("Received response from so " + resp.text)
+        return resp
diff --git a/robotframework-onap/ONAPLibrary/RequestSOKeywords.py b/robotframework-onap/ONAPLibrary/RequestSOKeywords.py
new file mode 100644 (file)
index 0000000..275cb68
--- /dev/null
@@ -0,0 +1,61 @@
+# Copyright 2019 AT&T Intellectual Property. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from BaseSOKeywords import BaseSOKeywords
+from robot.api import logger
+from robot.api.deco import keyword
+from robot.libraries.BuiltIn import BuiltIn
+
+from eteutils.UUID import UUID
+
+
+class RequestSOKeywords(object):
+    """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce
+    orchestrator. """
+
+    def __init__(self):
+        super(RequestSOKeywords, self).__init__()
+        self.application_id = "robot-ete"
+        self.uuid = UUID()
+        self.builtin = BuiltIn()
+        self.base_keywords = BaseSOKeywords()
+
+    @keyword
+    def run_polling_get_request(self, endpoint, data_path, complete_states=None, fail_states=None, tries=20,
+                                interval=15, auth=None):
+        """Runs an SO get request until a certain state is received."""
+        if fail_states is None:
+            fail_states = ["FAILED"]
+        if complete_states is None:
+            complete_states = ["COMPLETE"]
+        # do this until it is done
+        for i in range(tries):
+            resp = self.base_keywords.get_request(endpoint, data_path, auth=auth)
+            self.builtin.should_not_contain_any(resp.text, fail_states)
+            logger.info(resp.json()['request']['requestStatus']['requestState'])
+            if resp.json()['request']['requestStatus']['requestState'] in complete_states:
+                logger.info("Received response from so " + resp.text)
+                return resp
+            else:
+                self.builtin.sleep(interval, "Response from SO is not in requested status")
+
+    @keyword
+    def run_create_request(self, endpoint, data_path, data, auth):
+        """Runs an SO create request and returns the request id and instance id."""
+        response = self.base_keywords.post_request(endpoint, data_path, data, auth=auth)
+        logger.info("Creation request submitted to SO, got response")
+
+        req_id = response.get('requestReferences', {}).get('requestId', '')
+        instance_id = response.get('requestReferences', {}).get('instanceId', '')
+
+        return req_id, instance_id
diff --git a/robotframework-onap/ONAPLibrary/SO.py b/robotframework-onap/ONAPLibrary/SO.py
new file mode 100644 (file)
index 0000000..b01c14f
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright 2019 AT&T Intellectual Property. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from ONAPLibrary.RequestSOKeywords import RequestSOKeywords
+from ONAPLibrary.robotlibcore import HybridCore
+from ONAPLibrary.BaseSOKeywords import BaseSOKeywords
+
+
+class SO(HybridCore):
+    """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce
+    orchestrator. """
+
+    def __init__(self):
+        self.keyword_implementors = [
+            BaseSOKeywords(),
+            RequestSOKeywords()
+        ]
+        HybridCore.__init__(self, self.keyword_implementors)
index 31168e5..53cdbc0 100644 (file)
@@ -37,7 +37,8 @@ setup(
         # narrow range of urlib3. if for some reason we remove requests, readd this back in
         'six',
         'requests',
-        'future'
+        'future',
+        'robotframework-requests'
     ],  # what we need
     packages=['eteutils', 'loadtest', 'vcpeutils', 'ONAPLibrary'],       # The name of your scripts package
     package_dir={