aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/vcpe/preload.py80
-rw-r--r--test/vcpe/preload_templates/template_aai_region_data.json11
-rwxr-xr-xtest/vcpe/vcpe.py3
-rwxr-xr-xtest/vcpe/vcpecommon.py10
4 files changed, 104 insertions, 0 deletions
diff --git a/test/vcpe/preload.py b/test/vcpe/preload.py
index f99d8dee1..5d86487ce 100755
--- a/test/vcpe/preload.py
+++ b/test/vcpe/preload.py
@@ -180,6 +180,86 @@ class Preload:
return None
return common_dict
+ def aai_region_query(self, req_method, json=None, verify=False):
+ """
+ Perform actual AAI API request for region
+ :param req_method: request method ({'get','put'})
+ :param json: Json payload
+ :param verify: SSL verify mode
+ :return:
+ """
+ url, headers, auth = (self.vcpecommon.aai_region_query_url,
+ self.vcpecommon.aai_headers,
+ self.vcpecommon.aai_userpass)
+ try:
+ if req_method == 'get':
+ request = requests.get(url, headers=headers, auth=auth,
+ verify=verify)
+ elif req_method == 'put':
+ request = requests.put(url, headers=headers, auth=auth,
+ verify=verify, json=json)
+ else:
+ raise requests.exceptions.RequestException
+ except requests.exceptions.RequestException as e:
+ self.logger.error("Error connecting to AAI API. Error details: " + str(e.message))
+ return False
+ try:
+ assert request.status_code == 200
+ except AssertionError:
+ self.logger.error('AAI request failed. API returned http code ' + str(request.status_code))
+ return False
+ try:
+ return request.json()
+ except ValueError as e:
+ if req_method == 'get':
+ self.logger.error('Unable to parse AAI response: ' + e.message)
+ return False
+ elif req_method == 'put':
+ return request.ok
+ else:
+ return False
+
+ def preload_aai_data(self, template_aai_region_data):
+ """
+ Update aai region data with identity-url
+ :param template_aai_region_data: path to region data template
+ :return:
+ """
+ request = self.aai_region_query('get')
+ if request:
+ # Check if identity-url already updated (for idempotency)
+ self.logger.debug("Regiond data acquired from AAI:\n" + json.dumps(request,indent=4))
+ try:
+ assert request['identity-url']
+ except KeyError:
+ pass
+ else:
+ self.logger.info('Identity-url already present in {0} data, not updating'.format(self.vcpecommon.cloud['--os-region-name']))
+ return
+
+ # Get resource_version and relationship_list from region data
+ resource_version = request['resource-version']
+ relationship_list = request['relationship-list']
+
+ replace_dict = {'${identity-url}': self.vcpecommon.cloud['--os-auth-url'],
+ '${identity_api_version}': self.vcpecommon.cloud['--os-identity-api-version'],
+ '${region_name}': self.vcpecommon.cloud['--os-region-name'],
+ '${resource_version}': resource_version
+ }
+ json_data = self.generate_json(template_aai_region_data, replace_dict)
+ json_data['relationship-list'] = relationship_list
+ self.logger.debug('Region update payload:\n' + json.dumps(json_data,indent=4))
+ else:
+ sys.exit(1)
+
+ # Update region data
+ request = self.aai_region_query('put', json_data)
+ if request:
+ self.logger.info('Successully updated identity-url in {0} '
+ 'region'.format(self.vcpecommon.cloud['--os-region-name']))
+ else:
+ sys.exit(1)
+
def test(self):
# this is for testing purpose
name_suffix = datetime.now().strftime('%Y%m%d%H%M')
diff --git a/test/vcpe/preload_templates/template_aai_region_data.json b/test/vcpe/preload_templates/template_aai_region_data.json
new file mode 100644
index 000000000..c574630f8
--- /dev/null
+++ b/test/vcpe/preload_templates/template_aai_region_data.json
@@ -0,0 +1,11 @@
+{
+ "cloud-owner": "CloudOwner",
+ "cloud-region-id": "${region_name}",
+ "cloud-type": "SharedNode",
+ "owner-defined-type": "OwnerType",
+ "cloud-region-version": "v1",
+ "identity-url": "${identity-url}/v${identity_api_version}",
+ "cloud-zone": "CloudZone",
+ "resource-version": "${resource_version}",
+ "relationship-list": ""
+}
diff --git a/test/vcpe/vcpe.py b/test/vcpe/vcpe.py
index bf6fcafbc..48190fe21 100755
--- a/test/vcpe/vcpe.py
+++ b/test/vcpe/vcpe.py
@@ -218,6 +218,9 @@ def init():
vcpecommon = VcpeCommon()
init_sdc(vcpecommon)
download_vcpe_service_templates(vcpecommon)
+ preloader = preload.Preload(vcpecommon)
+ template_aai_region_data = vcpecommon.find_file('aai_region_data', 'json', 'preload_templates')
+ preloader.preload_aai_data(template_aai_region_data)
def init_sdc(vcpecommon):
diff --git a/test/vcpe/vcpecommon.py b/test/vcpe/vcpecommon.py
index 545524e6f..ddbce4b24 100755
--- a/test/vcpe/vcpecommon.py
+++ b/test/vcpe/vcpecommon.py
@@ -223,6 +223,16 @@ class VcpeCommon:
self.mariadb_galera_endpoint_ip = self.get_k8s_service_endpoint_info('mariadb-galera','ip')
self.mariadb_galera_endpoint_port = self.get_k8s_service_endpoint_info('mariadb-galera','port')
+ #############################################################################################
+ # AAI urls
+ self.aai_region_query_url = 'https://' + self.oom_so_sdnc_aai_ip + ':' +\
+ self.aai_query_port +\
+ '/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/' +\
+ self.cloud['--os-region-name']
+ self.aai_headers = {'Accept': 'application/json',
+ 'Content-Type': 'application/json',
+ 'X-FromAppId': 'postman', 'X-TransactionId': '9999'}
+
def heatbridge(self, openstack_stack_name, svc_instance_uuid):
"""
Add vserver information to AAI