From 6358aa3444fe90a12040c288ba750dc9f6b4f19d Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Wed, 30 Oct 2019 13:46:43 +0100 Subject: [PATCH] Add identity-url to region data in AAI This change automates the process of updating region data with identity-url Change-Id: Ibda9ac8d1bbe1a489d496a5f293aafdebb73d416 Signed-off-by: Bartek Grzybowski Issue-ID: SO-2308 --- docs/docs_vCPE.rst | 33 ++------- test/vcpe/preload.py | 80 ++++++++++++++++++++++ .../template_aai_region_data.json | 11 +++ test/vcpe/vcpe.py | 3 + test/vcpe/vcpecommon.py | 10 +++ 5 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 test/vcpe/preload_templates/template_aai_region_data.json diff --git a/docs/docs_vCPE.rst b/docs/docs_vCPE.rst index a64a660b5..82bca3030 100644 --- a/docs/docs_vCPE.rst +++ b/docs/docs_vCPE.rst @@ -31,42 +31,21 @@ Here are the main steps to run the use case in Integration lab environment, wher 2. Add customer SDN-ETHERNET-INTERNET (see the use case tutorial wiki page for detail) -3. Add identity-url to RegionOne data in A&AI. First use POSTMAN to GET cloud-region RegionOne data, then add identity-url and PUT back to A&AI - -:: - - GET https://{{aai}}:{{port}}/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne - -:: - - PUT https://{{aai}}:{{port}}/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne - { - "cloud-owner": "CloudOwner", - "cloud-region-id": "RegionOne", - "cloud-type": "SharedNode", - "owner-defined-type": "OwnerType", - "cloud-region-version": "v1", - "identity-url": "http://10.12.25.2:5000/v2.0", - "cloud-zone": "CloudZone", - "resource-version": "1559336510793", - "relationship-list": { - ... ... - -4. Add route on sdnc cluster VM node, which is the cluster VM node where pod sdnc-sdnc-0 is running on. This will allow ONAP SDNC to configure BRG later on. +3. Add route on sdnc cluster VM node, which is the cluster VM node where pod sdnc-sdnc-0 is running on. This will allow ONAP SDNC to configure BRG later on. :: ip route add 10.3.0.0/24 via 10.0.101.10 dev ens3 -5. Install Python and other Python libraries +4. Install Python and other Python libraries :: integration/test/vcpe/bin/setup.sh -6. Change the Openstack env parameters and one customer service related parameter in vcpecommon.py +5. Change the Openstack env parameters and one customer service related parameter in vcpecommon.py :: @@ -94,19 +73,19 @@ Here are the main steps to run the use case in Integration lab environment, wher # CHANGEME: vgw_VfModuleModelInvariantUuid is in rescust service csar, open service template with filename like service-VcpesvcRescust1118-template.yml and look for vfModuleModelInvariantUUID under groups vgw module metadata. self.vgw_VfModuleModelInvariantUuid = 'xxxxxxxxxxxxxxx' -7. Initialize vcpe +6. Initialize vcpe :: vcpe.py init -8. Run a command from Rancher node to insert vcpe customer service workflow entry in SO catalogdb. You should be able to see a sql command printed out from the above step output at the end, and use that sql command to replace the sample sql command below (inside the double quote) and run it from Rancher node: +7. Run a command from Rancher node to insert vcpe customer service workflow entry in SO catalogdb. You should be able to see a sql command printed out from the above step output at the end, and use that sql command to replace the sample sql command below (inside the double quote) and run it from Rancher node: :: kubectl exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword catalogdb -e "INSERT INTO service_recipe (ACTION, VERSION_STR, DESCRIPTION, ORCHESTRATION_URI, SERVICE_PARAM_XSD, RECIPE_TIMEOUT, SERVICE_TIMEOUT_INTERIM, CREATION_TIMESTAMP, SERVICE_MODEL_UUID) VALUES ('createInstance','1','vCPEResCust 2019-06-03 _04ba','/mso/async/services/CreateVcpeResCustService',NULL,181,NULL, NOW(),'6c4a469d-ca2c-4b02-8cf1-bd02e9c5a7ce')" -9. Run Robot to create and distribute for vCPE customer service. This step assumes step 1 has successfully distributed all vcpe models except customer service model +8. Run Robot to create and distribute for vCPE customer service. This step assumes step 1 has successfully distributed all vcpe models except customer service model :: 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 -- 2.16.6