vFWDT tutorial fixes after integration tests 51/106651/2
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Sun, 26 Apr 2020 21:49:55 +0000 (23:49 +0200)
committerLukasz Rajewski <lukasz.rajewski@orange.com>
Mon, 27 Apr 2020 10:49:11 +0000 (12:49 +0200)
Modification in test files, including configuration
and workflow files.

Change-Id: I6d9eaf4355a151fa20f1b5d4ea8a025cbcb3d70f
Issue-ID: INT-1465
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
tutorials/vFWDT/playbooks/vfw-sink/latest/ansible/distributetrafficcheck/site.yml
tutorials/vFWDT/playbooks/vfw-sink/latest/ansible/upgradepostcheck/site.yml
tutorials/vFWDT/playbooks/vfw-sink/latest/ansible/upgradeprecheck/site.yml
tutorials/vFWDT/playbooks/vpgn/latest/ansible/distributetraffic/site.yml
tutorials/vFWDT/playbooks/vpgn/latest/ansible/distributetrafficcheck/site.yml
tutorials/vFWDT/workflow/templates/cdt-templates/vfw-sink/traffic.json
tutorials/vFWDT/workflow/templates/cdt-templates/vfw-sink/upgrade.json
tutorials/vFWDT/workflow/templates/cdt-templates/vpgn/traffic.json
tutorials/vFWDT/workflow/templates/hasRequest.json
tutorials/vFWDT/workflow/workflow.py

index 2ad56da..daa7da8 100755 (executable)
@@ -1,5 +1,5 @@
 ---
-- hosts: vfw-sink
+- hosts: vFWDT
   gather_facts: no
   remote_user: ubuntu
   tasks:
@@ -7,9 +7,23 @@
     failed_when: new_software_version is not defined
   - debug: var="existing_software_version"
     failed_when: existing_software_version is not defined
+  - name: Check if version is known
+    stat:
+      path: /opt/config/version.txt
+    register: version_file
+  - name: Default version
+    shell: echo '{{existing_software_version}}' >> /opt/config/version.txt
+    when: version_file.stat.exists == false
+    become: true
   - name: Read OLD Software Version
     shell: cat /opt/config/version.txt
     register: old_version
     become: true
-  - debug: var=old_version.stdout
+  - name: Check existing version
+    debug:
+      msg: "{{old_version.stdout}} == {{existing_software_version}}"
+    failed_when: old_version.stdout != existing_software_version
+  - name: Check if upgrade is needed
+    debug:
+      msg: "{{old_version.stdout}} -> {{new_software_version}}"
     failed_when: old_version.stdout == new_software_version
index b249032..473f44f 100755 (executable)
@@ -1,13 +1,13 @@
 {
     "InventoryNames": "VM",
-    "PlaybookName": "${()=(book_name)}",
+    "PlaybookName": "${book_name}",
     "AutoNodeList": true,
     "EnvParameters": {
         "ConfigFileName": "../traffic_distribution_config.json",
         "vnf_instance": "vfwdt"
     },
     "FileParameters": {
-        "traffic_distribution_config.json": "${()=(file_parameter_content)}"
+        "traffic_distribution_config.json": "${file_parameter_content}"
     },
     "Timeout": 3600
 }
index c875f28..453db34 100755 (executable)
@@ -1,15 +1,15 @@
 {
     "InventoryNames": "VM",
-    "PlaybookName": "${()=(book_name)}",
+    "PlaybookName": "${book_name}",
     "AutoNodeList": true,
     "EnvParameters": {
         "ConfigFileName": "../config.json",
         "vnf_instance": "vfwdt",
-        "new_software_version": "${()=(new-software-version)}",
-        "existing_software_version": "${()=(existing-software-version)}"
+        "new_software_version": "${new-software-version}",
+        "existing_software_version": "${existing-software-version}"
     },
     "FileParameters": {
-        "config.json": "${()=(file_parameter_content)}"
+        "config.json": "${file_parameter_content}"
     },
     "Timeout": 3600
 }
index b249032..473f44f 100755 (executable)
@@ -1,13 +1,13 @@
 {
     "InventoryNames": "VM",
-    "PlaybookName": "${()=(book_name)}",
+    "PlaybookName": "${book_name}",
     "AutoNodeList": true,
     "EnvParameters": {
         "ConfigFileName": "../traffic_distribution_config.json",
         "vnf_instance": "vfwdt"
     },
     "FileParameters": {
-        "traffic_distribution_config.json": "${()=(file_parameter_content)}"
+        "traffic_distribution_config.json": "${file_parameter_content}"
     },
     "Timeout": 3600
 }
index a0c678b..fd3dcf4 100644 (file)
@@ -37,7 +37,7 @@
         "demands": {
             "vFW-SINK": [
                 {
-                    "attributes": {
+                    "filtering_attributes": {
                         "global-customer-id": {
                             "get_param": "chosen_customer_id"
                         },
                         },
                         "model-version-id": "202d2fd8-a045-4c9a-b767-2a1639c10291",
                         "orchestration-status": [
-                            "active"
+                            "Active"
                         ],
                         "model-invariant-id": "6f3fd439-fd5f-4a2d-95bc-b6bf8787001a",
                         "service_instance_id": {
                             "get_param": "service_id"
-                        },
-                        "prov-status": "ACTIVE"
+                        }
                     },
                     "inventory_provider": "aai",
                     "service_resource_id": "vFW-SINK-XX",
@@ -78,7 +77,7 @@
             ],
             "vPGN": [
                 {
-                    "attributes": {
+                    "filtering_attributes": {
                         "global-customer-id": {
                             "get_param": "chosen_customer_id"
                         },
                         },
                         "model-version-id": "6bfe954e-bb00-4111-be3c-33eed9d20a8c",
                         "orchestration-status": [
-                            "active"
+                            "Active"
                         ],
                         "model-invariant-id": "3f356335-7b36-41ee-8f74-72d0a2ec3ebf",
                         "service_instance_id": {
                             "get_param": "service_id"
-                        },
-                        "prov-status": "ACTIVE"
+                        }
                     },
                     "inventory_provider": "aai",
                     "service_resource_id": "vPGN-XX",
index dd15e81..dce32b3 100755 (executable)
@@ -199,6 +199,7 @@ class AAIApiResource(Resource):
     actions = {
         'generic_vnf': {'method': 'GET', 'url': 'network/generic-vnfs/generic-vnf/{}'},
         'vnfc': {'method': 'GET', 'url': 'network/vnfcs/vnfc/{}'},
+        'vnfc_patch': {'method': 'PATCH', 'url': 'network/vnfcs/vnfc/{}'},
         'link': {'method': 'GET', 'url': '{}'},
         'service_instance': {'method': 'GET',
                              'url': 'business/customers/customer/{}/service-subscriptions/service-subscription/{}/service-instances/service-instance/{}'}
@@ -232,7 +233,7 @@ class APPCLcmApiResource(Resource):
     }
 
 
-def _init_python_aai_api(onap_ip):
+def _init_python_aai_api(onap_ip, content_type='application/json'):
     api = API(
         api_root_url="https://{}:30233/aai/v14/".format(onap_ip),
         params={},
@@ -240,7 +241,7 @@ def _init_python_aai_api(onap_ip):
             'Authorization': encode("AAI", "AAI"),
             'X-FromAppId': 'SCRIPT',
             'Accept': 'application/json',
-            'Content-Type': 'application/json',
+            'Content-Type': content_type,
             'X-TransactionId': str(uuid.uuid4()),
         },
         timeout=30,
@@ -449,8 +450,8 @@ def _has_request(onap_ip, aai_data, exclude, use_oof_cache):
     node['chosen_customer_id'] = aai_data['service-info']['global-customer-id']
     node['service_id'] = aai_data['service-info']['service-instance-id']
     node = template['template']['demands']['vFW-SINK'][0]
-    node['attributes']['model-invariant-id'] = aai_data['vfw-model-info']['model-invariant-id']
-    node['attributes']['model-version-id'] = aai_data['vfw-model-info']['model-version-id']
+    node['filtering_attributes']['model-invariant-id'] = aai_data['vfw-model-info']['model-invariant-id']
+    node['filtering_attributes']['model-version-id'] = aai_data['vfw-model-info']['model-version-id']
     if exclude:
         node['excluded_candidates'][0]['candidate_id'][0] = aai_data['vf-module-id']
         del node['required_candidates']
@@ -458,8 +459,8 @@ def _has_request(onap_ip, aai_data, exclude, use_oof_cache):
         node['required_candidates'][0]['candidate_id'][0] = aai_data['vf-module-id']
         del node['excluded_candidates']
     node = template['template']['demands']['vPGN'][0]
-    node['attributes']['model-invariant-id'] = aai_data['vpgn-model-info']['model-invariant-id']
-    node['attributes']['model-version-id'] = aai_data['vpgn-model-info']['model-version-id']
+    node['filtering_attributes']['model-invariant-id'] = aai_data['vpgn-model-info']['model-invariant-id']
+    node['filtering_attributes']['model-version-id'] = aai_data['vpgn-model-info']['model-version-id']
 
     #print(json.dumps(template, indent=4))
 
@@ -524,9 +525,21 @@ def _extract_has_appc_identifiers(has_result, demand, onap_ip):
     if demand.lower() not in ansible_inventory:
         ansible_inventory[demand.lower()] = {}
     ansible_inventory[demand.lower()][config['vserver-name']] = ansible_inventory_entry
+
+    _verify_vnfc_data(api, onap_ip, config['vserver-name'], config['ip'])
     return config
 
 
+def _verify_vnfc_data(aai_api, onap_ip, vnfc_name, oam_ip):
+    with _no_ssl_verification():
+        response = aai_api.aai.vnfc(vnfc_name, body=None, params=None, headers={})
+        #print(json.dumps(response.body))
+        if "ipaddress-v4-oam-vip" not in response.body:
+            print("VNFC information update for {}".format(vnfc_name))
+            api = _init_python_aai_api(onap_ip, 'application/merge-patch+json')
+            response = api.aai.vnfc_patch(vnfc_name, body={"ipaddress-v4-oam-vip": oam_ip, "vnfc-name": vnfc_name}, params=None, headers={})
+
+
 def _extract_osdf_appc_identifiers(has_result, demand, onap_ip):
     if demand == 'vPGN':
         v_server = has_result[demand]['vservers'][0]
@@ -804,10 +817,10 @@ def build_appc_lcms_requests_body(rancher_ip, onap_ip, aai_data, use_oof_cache,
     #print(json.dumps(migrate_to, indent=4))
     req_id = str(uuid.uuid4())
     result = list()
-    old_version = 2.0
+    old_version = "2.0"
     if_dt_only = new_version is None
     if new_version is not None and new_version != "1.0":
-        old_version = 1.0
+        old_version = "1.0"
 
     requests = list()
     include_lock = True
@@ -883,7 +896,7 @@ def build_appc_lcms_requests_body(rancher_ip, onap_ip, aai_data, use_oof_cache,
 
 @timing("> Execute APPC REQ")
 def appc_lcm_request(onap_ip, req):
-    print(req)
+    #print(req)
     api = _init_python_appc_lcm_api(onap_ip)
     with _no_ssl_verification():
     #print(json.dumps(req, indent=4))
@@ -939,7 +952,7 @@ def appc_lcm_status_request(onap_ip, req):
     api = _init_python_appc_lcm_api(onap_ip)
     status_body = _build_appc_lcm_status_body(req)
     _set_appc_lcm_timestamp(status_body)
-    print("CHECK STATUS")
+    #print("CHECK STATUS")
     with _no_ssl_verification():
         result = api.lcm.action_status(body=status_body, params={}, headers={})
 
@@ -981,7 +994,7 @@ def _execute_lcm_requests(workflow, onap_ip, check_result):
         _set_appc_lcm_timestamp(req)
         conf_result = False
         result = appc_lcm_request(onap_ip, req)
-        print("Result {}".format(result))
+        #print("Result {}".format(result))
 
         if result == 100:
             conf_result = confirm_appc_lcm_action(onap_ip, req, check_result)
@@ -1042,8 +1055,9 @@ def _set_artifact_payload(vnf_type, vnfc_type, action, artifact):
             template_file = template_file.format(vnfc_type, 'upgrade.json')
         else:
             template_file = template_file.format(vnfc_type, 'traffic.json')
-
-        artifact_contents = json.dumps(json.loads(open(template_file).read()))
+        #print("Template for action {} in {}".format(action, template_file))
+        #print(json.dumps(json.loads(open(template_file).read()), indent=4))
+        artifact_contents = json.dumps(json.loads(open(template_file).read()), indent=4).replace("\n", "\r\n")
     elif artifact['type'] == 'parameter_definitions':
         file = 'templates/cdt-templates/templates/{}'
         if sw_upgrade:
@@ -1067,7 +1081,7 @@ def _set_artifact_payload(vnf_type, vnfc_type, action, artifact):
     payload['action'] = action
 
     if artifact['type'] == 'config_template':
-        artifact['artifact-contents'] = artifact_contents
+        payload['artifact-contents'] = artifact_contents
     artifact['payload'] = payload