aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2020-06-15 17:01:09 +0200
committerMorgan Richomme <morgan.richomme@orange.com>2020-06-15 19:19:28 +0000
commit360ebc15448f4d4720d80ea7339f92d4d3eafa55 (patch)
tree9d26a092fce35fc519b4927c96a82ad0c0283b1e
parentb5058f79afaa0f93758c9cdc45e6bd8384a61836 (diff)
Fix for missing VNFC rel information
This patch adds workaround for missing VNFC-VSERVER relation when VSERVER info is created by SO heatbridge (instead robot) Change-Id: I4d54f4bd1ac17193f5b1037bedbf1d00af9d0ac9 Issue-ID: SO-2983 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> (cherry picked from commit 573cb9b667f82307df881d356441c2d99b91bf2a)
-rwxr-xr-xtutorials/vFWDT/playbooks/configure_ansible.sh8
-rwxr-xr-xtutorials/vFWDT/workflow/workflow.py95
2 files changed, 88 insertions, 15 deletions
diff --git a/tutorials/vFWDT/playbooks/configure_ansible.sh b/tutorials/vFWDT/playbooks/configure_ansible.sh
index e5a42d04..3b6f2b0f 100755
--- a/tutorials/vFWDT/playbooks/configure_ansible.sh
+++ b/tutorials/vFWDT/playbooks/configure_ansible.sh
@@ -78,8 +78,8 @@ APPC_SECRET=`kubectl get secrets | grep appc-db-root-pass`
APPC_PWD=`./get_secret.sh $APPC_SECRET`
echo "SECRET: $APPC_PWD"
-kubectl exec -n onap $APPCDB -- mysql -u root -p$APPC_PWD sdnctl -e'SELECT * FROM DEVICE_AUTHENTICATION WHERE PROTOCOL LIKE "ANSIBLE";'
-kubectl exec -n onap $APPCDB -- mysql -u root -p$APPC_PWD sdnctl -e'UPDATE DEVICE_AUTHENTICATION SET URL = "http://appc-ansible-server:8000/Dispatch" WHERE PROTOCOL LIKE "ANSIBLE" AND PASSWORD IS NULL;'
-kubectl exec -n onap $APPCDB -- mysql -u root -p$APPC_PWD sdnctl -e'UPDATE DEVICE_AUTHENTICATION SET PASSWORD = "admin" WHERE PROTOCOL LIKE "ANSIBLE" AND PASSWORD IS NULL;'
-kubectl exec -n onap $APPCDB -- mysql -u root -p$APPC_PWD sdnctl -e'SELECT * FROM DEVICE_AUTHENTICATION WHERE PROTOCOL LIKE "ANSIBLE";'
+kubectl exec -n onap $APPCDB -- mysql -u root -p"$APPC_PWD" sdnctl -e'SELECT * FROM DEVICE_AUTHENTICATION WHERE PROTOCOL LIKE "ANSIBLE";'
+kubectl exec -n onap $APPCDB -- mysql -u root -p"$APPC_PWD" sdnctl -e'UPDATE DEVICE_AUTHENTICATION SET URL = "http://appc-ansible-server:8000/Dispatch" WHERE PROTOCOL LIKE "ANSIBLE" AND PASSWORD IS NULL;'
+kubectl exec -n onap $APPCDB -- mysql -u root -p"$APPC_PWD" sdnctl -e'UPDATE DEVICE_AUTHENTICATION SET PASSWORD = "admin" WHERE PROTOCOL LIKE "ANSIBLE" AND PASSWORD IS NULL;'
+kubectl exec -n onap $APPCDB -- mysql -u root -p"$APPC_PWD" sdnctl -e'SELECT * FROM DEVICE_AUTHENTICATION WHERE PROTOCOL LIKE "ANSIBLE";'
echo "APPC database configured for LCM commands"
diff --git a/tutorials/vFWDT/workflow/workflow.py b/tutorials/vFWDT/workflow/workflow.py
index 6d34eaf1..66218316 100755
--- a/tutorials/vFWDT/workflow/workflow.py
+++ b/tutorials/vFWDT/workflow/workflow.py
@@ -165,6 +165,9 @@ def _get_aai_rel_link_data(data, related_to, search_key=None, match_dict=None):
dval = None
matched = False
link = rel.get("related-link")
+ property = ""
+ if rel.get("related-to-property") is not None:
+ property = rel.get("related-to-property")[0]['property-value']
r_data = rel.get(rdata, [])
if search_key:
for rd in r_data:
@@ -172,7 +175,7 @@ def _get_aai_rel_link_data(data, related_to, search_key=None, match_dict=None):
dval = rd.get(rval)
if not match_dict: # return first match
response.append(
- {"link": link, "d_value": dval}
+ {"link": link, "property": property, "d_value": dval}
)
break # go to next relation
if rd.get(rkey) == m_key \
@@ -180,17 +183,17 @@ def _get_aai_rel_link_data(data, related_to, search_key=None, match_dict=None):
matched = True
if match_dict and matched: # if matching required
response.append(
- {"link": link, "d_value": dval}
+ {"link": link, "property": property, "d_value": dval}
)
# matched, return search value corresponding
# to the matched r_data group
else: # no search key; just return the link
response.append(
- {"link": link, "d_value": dval}
+ {"link": link, "property": property, "d_value": dval}
)
if response:
response.append(
- {"link": None, "d_value": None}
+ {"link": None, "property": None, "d_value": None}
)
return response
@@ -198,7 +201,9 @@ def _get_aai_rel_link_data(data, related_to, search_key=None, match_dict=None):
class AAIApiResource(Resource):
actions = {
'generic_vnf': {'method': 'GET', 'url': 'network/generic-vnfs/generic-vnf/{}'},
+ 'vf_module': {'method': 'GET', 'url': 'network/generic-vnfs/generic-vnf/{}/vf-modules/vf-module/{}'},
'vnfc': {'method': 'GET', 'url': 'network/vnfcs/vnfc/{}'},
+ 'vnfc_put': {'method': 'PUT', 'url': 'network/vnfcs/vnfc/{}'},
'vnfc_patch': {'method': 'PATCH', 'url': 'network/vnfcs/vnfc/{}'},
'link': {'method': 'GET', 'url': '{}'},
'service_instance': {'method': 'GET',
@@ -526,18 +531,86 @@ def _extract_has_appc_identifiers(has_result, demand, onap_ip):
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'])
+ _verify_vnfc_data(api, onap_ip, config)
return config
-def _verify_vnfc_data(aai_api, onap_ip, vnfc_name, oam_ip):
+def _verify_vnfc_data(aai_api, onap_ip, config, root=None):
+ vnfc_name = config['vserver-name']
+ oam_ip = config['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')
+ #print(json.dumps(response.body))
+ if "ipaddress-v4-oam-vip" not in response.body and oam_ip != "":
+ print("VNFC IP information update for {}".format(vnfc_name))
+ api = _init_python_aai_api(onap_ip, 'application/merge-patch+json')
+ with _no_ssl_verification():
response = api.aai.vnfc_patch(vnfc_name, body={"ipaddress-v4-oam-vip": oam_ip, "vnfc-name": vnfc_name}, params=None, headers={})
+ if "relationship-list" not in response.body:
+ print("VNFC REL information update for {}".format(vnfc_name))
+ vserver_info = {
+ "link": "",
+ "owner": "",
+ "region": "",
+ "tenant": "",
+ "id": ""
+ }
+ with _no_ssl_verification():
+ vf_module = aai_api.aai.vf_module(config['vnf-id'], config['vf-module-id'], body=None, params={'depth': 2}, headers={}).body
+ related_to = "vserver"
+ search_key = "cloud-region.cloud-owner"
+ rl_data_list = _get_aai_rel_link_data(data=vf_module, related_to=related_to, search_key=search_key)
+ vserver_info["owner"] = rl_data_list[0]['d_value']
+
+ search_key = "cloud-region.cloud-region-id"
+ rl_data_list = _get_aai_rel_link_data(data=vf_module, related_to=related_to, search_key=search_key)
+ vserver_info["region"] = rl_data_list[0]['d_value']
+
+ search_key = "tenant.tenant-id"
+ rl_data_list = _get_aai_rel_link_data(data=vf_module, related_to=related_to, search_key=search_key)
+ vserver_info["tenant"] = rl_data_list[0]['d_value']
+
+ search_key = "vserver.vserver-id"
+ rl_data_list = _get_aai_rel_link_data(data=vf_module, related_to=related_to, search_key=search_key)
+ for relation in rl_data_list:
+ vserver_info["id"] = relation['d_value']
+ vserver_info["link"] = relation['link']
+
+ rel_data = {
+ "related-to": "vserver",
+ "related-link": vserver_info["link"],
+ "relationship-data": [
+ {
+ "relationship-key": "cloud-region.cloud-owner",
+ "relationship-value": vserver_info["owner"]
+ },
+ {
+ "relationship-key": "cloud-region.cloud-region-id",
+ "relationship-value": vserver_info["region"]
+ },
+ {
+ "relationship-key": "tenant.tenant-id",
+ "relationship-value": vserver_info["tenant"]
+ },
+ {
+ "relationship-key": "vserver.vserver-id",
+ "relationship-value": vserver_info["id"]
+ }
+ ]
+ }
+ #print(json.dumps(rel_data, indent=4))
+ if config['vserver-id'] == relation['d_value']:
+ with _no_ssl_verification():
+ response = aai_api.aai.vnfc_put("{}/relationship-list/relationship".format(vnfc_name), body=rel_data, params=None, headers={})
+ elif root is None and relation['d_value'] is not None:
+ new_config = copy.deepcopy(config)
+ new_config['vserver-name'] = relation['property']
+ new_config['vserver-id'] = relation['d_value']
+ new_config['ip'] = ""
+ _verify_vnfc_data(aai_api, onap_ip, new_config, vnfc_name)
+ with _no_ssl_verification():
+ response = aai_api.aai.vnfc(vnfc_name, body=None, params=None, headers={})
+ #print(json.dumps(response.body))
def _extract_osdf_appc_identifiers(has_result, demand, onap_ip):
@@ -577,7 +650,7 @@ def _extract_osdf_appc_identifiers(has_result, demand, onap_ip):
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'])
+ _verify_vnfc_data(api, onap_ip, config)
return config