summaryrefslogtreecommitdiffstats
path: root/robotframework-onap/vcpeutils/preload.py
diff options
context:
space:
mode:
authorDR695H <dr695h@att.com>2019-07-01 13:58:49 -0400
committerDR695H <dr695h@att.com>2019-07-01 13:58:49 -0400
commit205db3c1a955f9e96776019deb2922fd208557a7 (patch)
tree07927a1dd809e65c24ee57b7b86b5fb58fb72c14 /robotframework-onap/vcpeutils/preload.py
parent96707b207ca00d80e622a0351b4566ebc87ace61 (diff)
adding in new keywords for base64, oof and sniro
Issue-ID: TEST-171 Change-Id: Ib305d17ca4847bf1e5740bd1983ca1f66b75bbd8 Signed-off-by: DR695H <dr695h@att.com>
Diffstat (limited to 'robotframework-onap/vcpeutils/preload.py')
-rwxr-xr-xrobotframework-onap/vcpeutils/preload.py129
1 files changed, 11 insertions, 118 deletions
diff --git a/robotframework-onap/vcpeutils/preload.py b/robotframework-onap/vcpeutils/preload.py
index 642b5e7..793e70d 100755
--- a/robotframework-onap/vcpeutils/preload.py
+++ b/robotframework-onap/vcpeutils/preload.py
@@ -1,23 +1,20 @@
#! /usr/bin/python
-from datetime import datetime
-from vcpeutils.vcpecommon import *
from vcpeutils.csar_parser import *
from robot.api import logger
from past import builtins
-import base64
+import requests
class Preload:
def __init__(self, vcpecommon):
- self.logger = logger
self.vcpecommon = vcpecommon
def replace(self, sz, replace_dict):
for old_string, new_string in list(replace_dict.items()):
sz = sz.replace(old_string, new_string)
if self.vcpecommon.template_variable_symbol in sz:
- self.logger.error('Error! Cannot find a value to replace ' + sz)
+ logger.error('Error! Cannot find a value to replace ' + sz)
return sz
def generate_json(self, template_file, replace_dict):
@@ -35,48 +32,9 @@ class Preload:
if self.vcpecommon.template_variable_symbol in v:
data[k] = self.replace(v, replace_dict)
else:
- self.logger.warn('Unexpected line in template: {}. Look for value {}'.format(template_file, v))
+ logger.warn('Unexpected line in template: {}. Look for value {}'.format(template_file, v))
return json_data
- def reset_sniro(self):
- self.logger.debug('Clearing SNIRO data')
- r = requests.post(self.vcpecommon.sniro_url + '/reset', headers=self.vcpecommon.sniro_headers)
- if 2 != r.status_code / 100:
- self.logger.debug(r.content)
- self.logger.error('Clearing SNIRO date failed.')
- sys.exit()
-
- def preload_sniro(self, template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, vbrg_ar_name,
- vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
- self.reset_sniro()
- self.logger.info('Preloading SNIRO for homing service')
- replace_dict = {'${tunnelxconn_ar_name}': tunnelxconn_ar_name,
- '${vgw_name}': vgw_name,
- '${brg_ar_name}': vbrg_ar_name,
- '${vgmux_svc_instance_uuid}': vgmux_svc_instance_uuid,
- '${vbrg_svc_instance_uuid}': vbrg_svc_instance_uuid
- }
- sniro_data = self.generate_json(template_sniro_data, replace_dict)
- self.logger.debug('SNIRO data:')
- self.logger.debug(json.dumps(sniro_data, indent=4, sort_keys=True))
-
- base64_sniro_data = base64.b64encode(json.dumps(sniro_data))
- self.logger.debug('SNIRO data: 64')
- self.logger.debug(base64_sniro_data)
- replace_dict = {'${base64_sniro_data}': base64_sniro_data, '${sniro_ip}': self.vcpecommon.hosts['robot']}
- sniro_request = self.generate_json(template_sniro_request, replace_dict)
- self.logger.debug('SNIRO request:')
- self.logger.debug(json.dumps(sniro_request, indent=4, sort_keys=True))
-
- r = requests.post(self.vcpecommon.sniro_url, headers=self.vcpecommon.sniro_headers, json=sniro_request)
- if 2 != r.status_code / 100:
- response = r.json()
- self.logger.debug(json.dumps(response, indent=4, sort_keys=True))
- self.logger.error('SNIRO preloading failed.')
- sys.exit()
-
- return True
-
def preload_network(self, template_file, network_role, subnet_start_ip, subnet_gateway, common_dict, name_suffix):
"""
:param template_file:
@@ -98,18 +56,18 @@ class Preload:
'${subnet_start_ip}': subnet_start_ip,
'${subnet_gateway}': subnet_gateway
}
- self.logger.info('Preloading network ' + network_role)
+ logger.info('Preloading network ' + network_role)
return self.preload(template_file, replace_dict, self.vcpecommon.sdnc_preload_network_url)
def preload(self, template_file, replace_dict, url):
- self.logger.debug(json.dumps(replace_dict, indent=4, sort_keys=True))
+ logger.debug(json.dumps(replace_dict, indent=4, sort_keys=True))
json_data = self.generate_json(template_file, replace_dict)
- self.logger.debug(json.dumps(json_data, indent=4, sort_keys=True))
+ logger.debug(json.dumps(json_data, indent=4, sort_keys=True))
r = requests.post(url, headers=self.vcpecommon.sdnc_headers, auth=self.vcpecommon.sdnc_userpass, json=json_data)
response = r.json()
if int(response.get('output', {}).get('response-code', 0)) != 200:
- self.logger.debug(json.dumps(response, indent=4, sort_keys=True))
- self.logger.error('Preloading failed.')
+ logger.debug(json.dumps(response, indent=4, sort_keys=True))
+ logger.error('Preloading failed.')
return False
return True
@@ -118,7 +76,7 @@ class Preload:
'${suffix}': name_suffix
}
replace_dict.update(commont_dict)
- self.logger.info('Preloading vGW')
+ logger.info('Preloading vGW')
return self.preload(template_file, replace_dict, self.vcpecommon.sdnc_preload_vnf_url)
def preload_vgw_gra(self, template_file, brg_mac, commont_dict, name_suffix, vgw_vfmod_name_index):
@@ -127,7 +85,7 @@ class Preload:
'${vgw_vfmod_name_index}': vgw_vfmod_name_index
}
replace_dict.update(commont_dict)
- self.logger.info('Preloading vGW-GRA')
+ logger.info('Preloading vGW-GRA')
return self.preload(template_file, replace_dict, self.vcpecommon.sdnc_preload_gra_url)
def preload_vfmodule(self, template_file, service_instance_id, vnf_model, vfmodule_model, common_dict, name_suffix):
@@ -159,70 +117,5 @@ class Preload:
'${sdnc_oam_ip}': self.vcpecommon.sdnc_oam_ip,
'${suffix}': name_suffix}
replace_dict.update(common_dict)
- self.logger.info('Preloading VF Module ' + vfmodule_name)
+ logger.info('Preloading VF Module ' + vfmodule_name)
return self.preload(template_file, replace_dict, self.vcpecommon.sdnc_preload_vnf_url)
-
- def preload_all_networks(self, template_file, name_suffix):
- common_dict = {'${' + k + '}': v for k, v in list(self.vcpecommon.common_preload_config.items())}
- for network, v in list(self.vcpecommon.preload_network_config.items()):
- subnet_start_ip, subnet_gateway_ip = v
- if not self.preload_network(template_file, network, subnet_start_ip, subnet_gateway_ip,
- common_dict, name_suffix):
- return None
- return common_dict
-
- def test(self):
- # this is for testing purpose
- name_suffix = datetime.now().strftime('%Y%m%d%H%M')
- vcpecommon = VcpeCommon()
- preloader = Preload(vcpecommon)
-
- network_dict = {'${' + k + '}': v for k, v in list(self.vcpecommon.common_preload_config.items())}
- template_file = 'preload_templates/template.network.json'
- for k, v in list(self.vcpecommon.preload_network_config.items()):
- if not preloader.preload_network(template_file, k, v[0], v[1], network_dict, name_suffix):
- break
-
- print('---------------------------------------------------------------')
- print('Network related replacement dictionary:')
- print(json.dumps(network_dict, indent=4, sort_keys=True))
- print('---------------------------------------------------------------')
-
- keys = ['infra', 'bng', 'gmux', 'brg']
- for key in keys:
- csar_file = self.vcpecommon.find_file(key, 'csar', 'csar')
- template_file = self.vcpecommon.find_file(key, 'json', 'preload_templates')
- if csar_file and template_file:
- parser = CsarParser()
- parser.parse_csar(csar_file)
- service_instance_id = 'test112233'
- preloader.preload_vfmodule(template_file, service_instance_id, parser.vnf_models[0],
- parser.vfmodule_models[0], network_dict, name_suffix)
-
- def test_sniro(self):
- template_sniro_data = self.vcpecommon.find_file('sniro_data', 'json', 'preload_templates')
- template_sniro_request = self.vcpecommon.find_file('sniro_request', 'json', 'preload_templates')
-
- vcperescust_csar = self.vcpecommon.find_file('rescust', 'csar', 'csar')
- parser = CsarParser()
- parser.parse_csar(vcperescust_csar)
- tunnelxconn_ar_name = None
- brg_ar_name = None
- vgw_name = None
- for model in parser.vnf_models:
- if 'tunnel' in model['modelCustomizationName']:
- tunnelxconn_ar_name = model['modelCustomizationName']
- elif 'brg' in model['modelCustomizationName']:
- brg_ar_name = model['modelCustomizationName']
- elif 'vgw' in model['modelCustomizationName']:
- vgw_name = model['modelCustomizationName']
-
- if not (tunnelxconn_ar_name and brg_ar_name and vgw_name):
- self.logger.error('Cannot find all names from %s.', vcperescust_csar)
- sys.exit()
-
- vgmux_svc_instance_uuid = '88888888888888'
- vbrg_svc_instance_uuid = '999999999999999'
-
- self.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name,
- vgmux_svc_instance_uuid, vbrg_svc_instance_uuid)