summaryrefslogtreecommitdiffstats
path: root/robotframework-onap/vcpeutils/SoUtils.py
diff options
context:
space:
mode:
authorDR695H <dr695h@att.com>2019-05-24 16:33:23 -0400
committerDR695H <dr695h@att.com>2019-05-24 16:35:40 -0400
commitdea8765ee75fb4b4c402d02afb1c53c8116e2176 (patch)
treef31cc6768d9760dc537b13e94fb2a653f2732d98 /robotframework-onap/vcpeutils/SoUtils.py
parentc9392aa6dc659ddc8940e98f3b5718e355d6c46b (diff)
not ready to submit my changes to soutils yet
Change-Id: I02122ad3fcf8d32efaed6976246943902f112e44 Issue-ID: TEST-158 Signed-off-by: DR695H <dr695h@att.com>
Diffstat (limited to 'robotframework-onap/vcpeutils/SoUtils.py')
-rwxr-xr-xrobotframework-onap/vcpeutils/SoUtils.py92
1 files changed, 67 insertions, 25 deletions
diff --git a/robotframework-onap/vcpeutils/SoUtils.py b/robotframework-onap/vcpeutils/SoUtils.py
index 89210c1..02b34e5 100755
--- a/robotframework-onap/vcpeutils/SoUtils.py
+++ b/robotframework-onap/vcpeutils/SoUtils.py
@@ -6,7 +6,6 @@ from vcpeutils.preload import *
from vcpeutils.vcpecommon import *
from robot.api import logger
-from ONAPLibrary.RequestSOKeywords import RequestSOKeywords
class SoUtils:
@@ -18,21 +17,72 @@ class SoUtils:
self.vcpecommon = VcpeCommon()
self.api_version = 'v4'
self.service_req_api_url = self.vcpecommon.so_req_api_url[self.api_version]
- self.request_keywords = RequestSOKeywords()
+
+ 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
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
-
- 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
+ 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
@staticmethod
def add_req_info(req_details, instance_name, product_family_id=None):
@@ -157,8 +207,7 @@ 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.request_keywords.run_create_request(
- self.service_req_api_url, "/", req, auth=self.vcpecommon.so_userpass)
+ req_id, svc_instance_id = self.submit_create_req(req, 'service')
if not self.check_progress(req_id):
return False
return True
@@ -205,8 +254,7 @@ 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.request_keywords.run_create_request(
- self.service_req_api_url, "/", req, auth=self.vcpecommon.so_userpass)
+ req_id, svc_instance_id = self.submit_create_req(req, 'service')
if not self.check_progress(req_id, interval=5):
return None
@@ -221,9 +269,7 @@ 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.request_keywords.run_create_request(
- self.service_req_api_url, '/'.join([svc_instance_id, 'networks']), req,
- auth=self.vcpecommon.so_userpass)
+ req_id, net_instance_id = self.submit_create_req(req, 'network', svc_instance_id)
if not self.check_progress(req_id):
return None
@@ -253,9 +299,7 @@ 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.request_keywords.run_create_request(
- self.service_req_api_url, '/'.join([svc_instance_id, 'vnfs']), req,
- auth=self.vcpecommon.so_userpass)
+ req_id, vnf_instance_id = self.submit_create_req(req, 'vnf', svc_instance_id)
if not self.check_progress(req_id, interval=5):
self.logger.error('Failed to create VNF {0}.'.format(vnf_instance_name))
return False
@@ -288,11 +332,9 @@ 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.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)
+ req_id, vfmodule_instance_id = self.submit_create_req(req, 'vfmodule', svc_instance_id, vnf_instance_id)
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
+ return svc_instance_id \ No newline at end of file