summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--robotframework-onap/ONAPLibrary/DNS.py26
-rw-r--r--robotframework-onap/ONAPLibrary/DNSKeywords.py23
-rw-r--r--robotframework-onap/eteutils/RequestsClientCert.py7
-rwxr-xr-xrobotframework-onap/vcpeutils/SoUtils.py92
4 files changed, 74 insertions, 74 deletions
diff --git a/robotframework-onap/ONAPLibrary/DNS.py b/robotframework-onap/ONAPLibrary/DNS.py
new file mode 100644
index 0000000..bc215ed
--- /dev/null
+++ b/robotframework-onap/ONAPLibrary/DNS.py
@@ -0,0 +1,26 @@
+# 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.robotlibcore import HybridCore
+from ONAPLibrary.DNSKeywords import DNSKeywords
+
+
+class DNS(HybridCore):
+ """ DNS Keywords are useful for DNS requests """
+
+ def __init__(self):
+ self.keyword_implementors = [
+ DNSKeywords()
+ ]
+ HybridCore.__init__(self, self.keyword_implementors)
diff --git a/robotframework-onap/ONAPLibrary/DNSKeywords.py b/robotframework-onap/ONAPLibrary/DNSKeywords.py
new file mode 100644
index 0000000..8f4e2f3
--- /dev/null
+++ b/robotframework-onap/ONAPLibrary/DNSKeywords.py
@@ -0,0 +1,23 @@
+import dns.message
+import dns.name
+import dns.query
+from robot.api.deco import keyword
+
+
+class DNSKeywords(object):
+ """ Utilities useful for DNS requests """
+
+ def __init__(self):
+ super(DNSKeywords, self).__init__()
+
+ @keyword
+ def dns_request(self, domain, ns):
+ """ return the ip address of the given domain name from the given nameserver """
+ request = dns.message.make_query(domain, dns.rdatatype.A)
+ request.flags |= dns.flags.AD
+ request.find_rrset(request.additional, dns.name.root, 65535, dns.rdatatype.OPT, create=True, force_unique=True)
+ response = dns.query.udp(request, ns)
+
+ for answer in response.answer:
+ for item in answer.items:
+ return item
diff --git a/robotframework-onap/eteutils/RequestsClientCert.py b/robotframework-onap/eteutils/RequestsClientCert.py
deleted file mode 100644
index e1fd66f..0000000
--- a/robotframework-onap/eteutils/RequestsClientCert.py
+++ /dev/null
@@ -1,7 +0,0 @@
-
-class RequestsClientCert:
- """RequestsClientCert allows adding a client cert to the Requests Robot Library."""
-
- def add_client_cert(self, session, cert):
- """Add Client Cert takes in a requests session object and a string path to the cert"""
- session.cert = cert \ No newline at end of file
diff --git a/robotframework-onap/vcpeutils/SoUtils.py b/robotframework-onap/vcpeutils/SoUtils.py
index 02b34e5..89210c1 100755
--- a/robotframework-onap/vcpeutils/SoUtils.py
+++ b/robotframework-onap/vcpeutils/SoUtils.py
@@ -6,6 +6,7 @@ from vcpeutils.preload import *
from vcpeutils.vcpecommon import *
from robot.api import logger
+from ONAPLibrary.RequestSOKeywords import RequestSOKeywords
class SoUtils:
@@ -17,72 +18,21 @@ class SoUtils:
self.vcpecommon = VcpeCommon()
self.api_version = 'v4'
self.service_req_api_url = self.vcpecommon.so_req_api_url[self.api_version]
-
- def submit_create_req(self, req_json, req_type, service_instance_id=None, vnf_instance_id=None):
- """
- POST {serverRoot}/serviceInstances/v4
- POST {serverRoot}/serviceInstances/v4/{serviceInstanceId}/vnfs
- POST {serverRoot}/serviceInstances/v4/{serviceInstanceId}/networks
- POST {serverRoot}/serviceInstances/v4/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules
- :param req_json:
- :param service_instance_id: this is required only for networks, vnfs, and vf modules
- :param req_type:
- :param vnf_instance_id:
- :return: req_id, instance_id
- """
- if req_type == 'service':
- url = self.service_req_api_url
- elif req_type == 'vnf':
- url = '/'.join([self.service_req_api_url, service_instance_id, 'vnfs'])
- elif req_type == 'network':
- url = '/'.join([self.service_req_api_url, service_instance_id, 'networks'])
- elif req_type == 'vfmodule':
- url = '/'.join([self.service_req_api_url, service_instance_id, 'vnfs', vnf_instance_id, 'vfModules'])
- else:
- self.logger.error('Invalid request type: {0}. Can only be service/vnf/network/vfmodule'.format(req_type))
- return None, None
-
- self.logger.info(url)
- r = requests.post(url, headers=self.vcpecommon.so_headers, auth=self.vcpecommon.so_userpass, json=req_json)
- self.logger.debug(r)
- response = r.json()
-
- self.logger.debug('---------------------------------------------------------------')
- self.logger.debug('------- Creation request submitted to SO, got response --------')
- self.logger.debug(json.dumps(response, indent=4, sort_keys=True))
- self.logger.debug('---------------------------------------------------------------')
- req_id = response.get('requestReferences', {}).get('requestId', '')
- instance_id = response.get('requestReferences', {}).get('instanceId', '')
-
- return req_id, instance_id
+ self.request_keywords = RequestSOKeywords()
def check_progress(self, req_id, interval=5):
if not req_id:
self.logger.error('Error when checking SO request progress, invalid request ID: ' + req_id)
return False
- duration = 0.0
- url = self.vcpecommon.so_check_progress_api_url + '/' + req_id
-
- while True:
- time.sleep(interval)
- r = requests.get(url, headers=self.vcpecommon.so_headers, auth=self.vcpecommon.so_userpass)
- response = r.json()
-
- duration += interval
-
- if response['request']['requestStatus']['requestState'] == 'IN_PROGRESS':
- self.logger.debug('------------------Request Status-------------------------------')
- self.logger.debug(json.dumps(response, indent=4, sort_keys=True))
- else:
- self.logger.debug('---------------------------------------------------------------')
- self.logger.debug('----------------- Creation Request Results --------------------')
- self.logger.debug(json.dumps(response, indent=4, sort_keys=True))
- self.logger.debug('---------------------------------------------------------------')
- flag = response['request']['requestStatus']['requestState'] == 'COMPLETE'
- if not flag:
- self.logger.error('Request failed.')
- self.logger.error(json.dumps(response, indent=4, sort_keys=True))
- return flag
+
+ response = self.request_keywords.run_polling_get_request(
+ self.vcpecommon.so_check_progress_api_url, '/' + req_id,
+ auth=self.vcpecommon.so_userpass, tries=500, interval=interval)
+ flag = response['request']['requestStatus']['requestState'] == 'COMPLETE'
+ if not flag:
+ self.logger.error('Request failed.')
+ self.logger.error(json.dumps(response, indent=4, sort_keys=True))
+ return flag
@staticmethod
def add_req_info(req_details, instance_name, product_family_id=None):
@@ -207,7 +157,8 @@ class SoUtils:
req = self.generate_custom_service_request(instance_name, parser.svc_model, brg_mac)
self.logger.info(json.dumps(req, indent=2, sort_keys=True))
self.logger.info('Creating custom service {0}.'.format(instance_name))
- req_id, svc_instance_id = self.submit_create_req(req, 'service')
+ req_id, svc_instance_id = self.request_keywords.run_create_request(
+ self.service_req_api_url, "/", req, auth=self.vcpecommon.so_userpass)
if not self.check_progress(req_id):
return False
return True
@@ -254,7 +205,8 @@ class SoUtils:
self.logger.info('Creating service instance: {0}.'.format(instance_name))
req = self.generate_service_request(instance_name, parser.svc_model)
self.logger.debug(json.dumps(req, indent=2, sort_keys=True))
- req_id, svc_instance_id = self.submit_create_req(req, 'service')
+ req_id, svc_instance_id = self.request_keywords.run_create_request(
+ self.service_req_api_url, "/", req, auth=self.vcpecommon.so_userpass)
if not self.check_progress(req_id, interval=5):
return None
@@ -269,7 +221,9 @@ class SoUtils:
self.logger.info('Creating network: ' + network_name)
req = self.generate_vnf_or_network_request(network_name, model, svc_instance_id, parser.svc_model)
self.logger.debug(json.dumps(req, indent=2, sort_keys=True))
- req_id, net_instance_id = self.submit_create_req(req, 'network', svc_instance_id)
+ req_id, net_instance_id = self.request_keywords.run_create_request(
+ self.service_req_api_url, '/'.join([svc_instance_id, 'networks']), req,
+ auth=self.vcpecommon.so_userpass)
if not self.check_progress(req_id):
return None
@@ -299,7 +253,9 @@ class SoUtils:
self.logger.info('Creating VNF: ' + vnf_instance_name)
req = self.generate_vnf_or_network_request(vnf_instance_name, vnf_model, svc_instance_id, parser.svc_model)
self.logger.debug(json.dumps(req, indent=2, sort_keys=True))
- req_id, vnf_instance_id = self.submit_create_req(req, 'vnf', svc_instance_id)
+ req_id, vnf_instance_id = self.request_keywords.run_create_request(
+ self.service_req_api_url, '/'.join([svc_instance_id, 'vnfs']), req,
+ auth=self.vcpecommon.so_userpass)
if not self.check_progress(req_id, interval=5):
self.logger.error('Failed to create VNF {0}.'.format(vnf_instance_name))
return False
@@ -332,9 +288,11 @@ class SoUtils:
req = self.generate_vfmodule_request(vfmodule_instance_name, model, svc_instance_id, parser.svc_model,
vnf_instance_id, vnf_model)
self.logger.debug(json.dumps(req, indent=2, sort_keys=True))
- req_id, vfmodule_instance_id = self.submit_create_req(req, 'vfmodule', svc_instance_id, vnf_instance_id)
+ req_id, vfmodule_instance_id = self.request_keywords.run_create_request(
+ self.service_req_api_url, '/'.join([svc_instance_id, 'vnfs', vnf_instance_id, 'vfModules']),
+ req, auth=self.vcpecommon.so_userpass)
if not self.check_progress(req_id, interval=50):
self.logger.error('Failed to create VF Module {0}.'.format(vfmodule_instance_name))
return None
- return svc_instance_id \ No newline at end of file
+ return svc_instance_id