Fix servernotification metadata issue

In LCM operation, vnfcResourceInfo[].metadata.server_notification
value was not stored. as the result, servernotification unregistration
was not executed. This patch fixes this problem.

Closes-Bug: #2004097
Change-Id: I06ea7ced6d9a33c067be3e24ab2c4163bef3574c
This commit is contained in:
Koji Shimizu 2023-01-29 15:31:12 +09:00
parent 5c851b34ba
commit 9c49c3b9cc
8 changed files with 95 additions and 41 deletions

View File

@ -146,7 +146,7 @@ with vnflcm show command. For example:
| | .... |
| | "metadata": { |
| | "ServerNotifierUri": "http://localhost:9990/server_notification", |
| | "ServerNotifierFaultID": "1234" |
| | "ServerNotifierFaultID": ["1111", "1234"] |
| | } |
| | .... |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+

View File

@ -73,16 +73,17 @@ class ServerNotification(mon_base.MonitoringPlugin):
'vnfcInfo')):
raise sol_ex.ServerNotificationValidationError(
detail="access info not found in the vnf instance.")
if fault_id != vnf_instance.instantiatedVnfInfo.metadata.get(
'ServerNotifierFaultID'):
if fault_id not in vnf_instance.instantiatedVnfInfo.metadata.get(
'ServerNotifierFaultID', []):
raise sol_ex.ServerNotificationValidationError(
detail="fault_id does not match.")
# Get the list of instantiatedVnfInfo.vnfcInfo[x].id where
# vnfcInfo[x].vnfcResourceInfoId == vnfcResourceInfo[y].id and
# vnfcResourceInfo[y].metadata.alarmId == alarm_id
# vnfcInfo[x].vnfcResourceInfoId = vnfcResourceInfo[y].id and
# vnfcResourceInfo[y].metadata.server_notification.alarmId = alarm_id
rsc_info = filter(lambda x: ('metadata' in x and
alarm_id == x['metadata'].get('alarmId')),
alarm_id == x['metadata'].get(
'server_notification', {}).get('alarmId')),
vnf_instance.instantiatedVnfInfo.vnfcResourceInfo)
rsc_ids = list(map(lambda x: x['id'], rsc_info))
vnfc_info = filter(lambda x:

View File

@ -975,7 +975,7 @@ class Openstack(object):
return metadata
def _update_vnfc_metadata(self, vnfc_res_infos, storage_infos,
heat_client, nfv_dict):
heat_client, nfv_dict, inst):
for vnfc_res_info in vnfc_res_infos:
metadata = vnfc_res_info.metadata
if 'parent_stack_id' in metadata:
@ -998,6 +998,25 @@ class Openstack(object):
for vdu_name, image in images.items():
metadata[f'image-{vdu_name}'] = image
self._add_extra_metadata_from_inst(metadata, vnfc_res_info.id,
inst)
def _add_extra_metadata_from_inst(self, metadata, vnfc_res_id, inst):
if (not inst.obj_attr_is_set('instantiatedVnfInfo') or
not inst.instantiatedVnfInfo.obj_attr_is_set(
'vnfcResourceInfo')):
return
# NOTE: it is irregular to add vnfcResourceInfo.metadata by
# outside of infra_driver. should not do anymore
extra_keys = ['server_notification']
for vnfc_res_info in inst.instantiatedVnfInfo.vnfcResourceInfo:
if vnfc_res_info.id == vnfc_res_id and vnfc_res_info.metadata:
for key in extra_keys:
if key in vnfc_res_info.metadata:
metadata[key] = vnfc_res_info.metadata[key]
return
def _make_instantiated_vnf_info(self, req, inst, grant_req, grant, vnfd,
heat_client, is_rollback=False, stack_id=None):
# get heat resources
@ -1079,7 +1098,7 @@ class Openstack(object):
vnfc_res_info.vnfcCpInfo = cp_infos
self._update_vnfc_metadata(vnfc_res_infos, storage_infos,
heat_client, nfv_dict)
heat_client, nfv_dict, inst)
vnf_vl_res_infos = [
objects.VnfVirtualLinkResourceInfoV2(

View File

@ -78,11 +78,11 @@ class ServerNotificationMgmtDriver(object):
res_ids = vnfc_res_ids if vnfc_res_ids else []
for rsc in self.inst['instantiatedVnfInfo']['vnfcResourceInfo']:
if ('metadata' in rsc and
'alarmId' in rsc['metadata'] and (isall or
'server_notification' in rsc['metadata'] and (isall or
rsc['computeResource']['resourceId'] in res_ids)):
found = True
alarm_id = rsc['metadata']['alarmId']
del rsc['metadata']['alarmId']
alarm_id = rsc['metadata']['server_notification']['alarmId']
del rsc['metadata']['server_notification']
server_id = rsc['computeResource']['resourceId']
self._request_unregister(
server_notifier_uri, tenant, server_id, alarm_id)
@ -91,11 +91,13 @@ class ServerNotificationMgmtDriver(object):
def request_register_cancel(self, rsc_list):
server_notifier_uri, _, tenant = self.get_params()
for rsc in rsc_list:
alarm_id = rsc['metadata']['alarmId']
del rsc['metadata']['alarmId']
server_id = rsc['computeResource']['resourceId']
self._request_unregister(
server_notifier_uri, tenant, server_id, alarm_id)
if ('metadata' in rsc and
'server_notification' in rsc['metadata']):
alarm_id = rsc['metadata']['server_notification']['alarmId']
del rsc['metadata']['server_notification']
server_id = rsc['computeResource']['resourceId']
self._request_unregister(
server_notifier_uri, tenant, server_id, alarm_id)
def _request_register(self, vnfc_resource):
server_id = vnfc_resource['computeResource']['resourceId']
@ -118,7 +120,8 @@ class ServerNotificationMgmtDriver(object):
raise common_ex.MgmtDriverOtherError(error_message=msg)
if 'metadata' not in vnfc_resource:
vnfc_resource['metadata'] = {}
vnfc_resource['metadata']['alarmId'] = res_body['alarm_id']
vnfc_resource['metadata']['server_notification'] = {
'alarmId': res_body['alarm_id']}
LOG.debug(
"server_notification registration is processed: %d. "
"alarm_id: %s", resp.status_code, res_body['alarm_id'])
@ -128,7 +131,7 @@ class ServerNotificationMgmtDriver(object):
rsc_list = []
for rsc in self.inst['instantiatedVnfInfo']['vnfcResourceInfo']:
if ('metadata' not in rsc or
'alarmId' not in rsc['metadata']):
'server_notification' not in rsc['metadata']):
try:
self._request_register(rsc)
rsc_list.append(rsc)

View File

@ -179,7 +179,7 @@ class ServerNotificationTest(test_vnflcm_basic_common.CommonVnfLcmTest):
instantiate_req = paramgen.instantiate_vnf_min()
instantiate_req['additionalParams'] = {
'ServerNotifierUri': server_notification_uri,
'ServerNotifierFaultID': '1234'
'ServerNotifierFaultID': ['1111', '1234']
}
resp, body = self.instantiate_vnf_instance(inst_id, instantiate_req)
@ -243,7 +243,11 @@ class ServerNotificationTest(test_vnflcm_basic_common.CommonVnfLcmTest):
(stack['resource_name'] == 'VDU2')][0]
heal_req = paramgen.heal_vnf_all_min()
resp, body = self.heal_vnf_instance(inst_id, heal_req)
while True:
resp, body = self.heal_vnf_instance(inst_id, heal_req)
if 409 != resp.status_code:
break
time.sleep(3)
self.assertEqual(202, resp.status_code)
self.check_resp_headers_in_operation_task(resp)
lcmocc_id = os.path.basename(resp.headers['Location'])
@ -309,7 +313,11 @@ class ServerNotificationTest(test_vnflcm_basic_common.CommonVnfLcmTest):
self.assertIsNotNone(vnfc_id)
heal_req = paramgen.heal_vnf_vnfc_min(vnfc_id)
resp, body = self.heal_vnf_instance(inst_id, heal_req)
while True:
resp, body = self.heal_vnf_instance(inst_id, heal_req)
if 409 != resp.status_code:
break
time.sleep(3)
self.assertEqual(202, resp.status_code)
self.check_resp_headers_in_operation_task(resp)
lcmocc_id = os.path.basename(resp.headers['Location'])
@ -349,7 +357,11 @@ class ServerNotificationTest(test_vnflcm_basic_common.CommonVnfLcmTest):
nested_stacks = self.heat_client.get_resources(stack_name)
count_before_scaleout = len(nested_stacks)
scaleout_req = paramgen.scaleout_vnf_min()
resp, body = self.scale_vnf_instance(inst_id, scaleout_req)
while True:
resp, body = self.scale_vnf_instance(inst_id, scaleout_req)
if 409 != resp.status_code:
break
time.sleep(3)
self.assertEqual(202, resp.status_code)
self.check_resp_headers_in_operation_task(resp)
lcmocc_id = os.path.basename(resp.headers['Location'])
@ -379,7 +391,11 @@ class ServerNotificationTest(test_vnflcm_basic_common.CommonVnfLcmTest):
# 6. LCM-Scale (SCALE_IN)
scalein_req = paramgen.scalein_vnf_min()
resp, body = self.scale_vnf_instance(inst_id, scalein_req)
while True:
resp, body = self.scale_vnf_instance(inst_id, scalein_req)
if 409 != resp.status_code:
break
time.sleep(3)
self.assertEqual(202, resp.status_code)
self.check_resp_headers_in_operation_task(resp)
lcmocc_id = os.path.basename(resp.headers['Location'])
@ -394,7 +410,11 @@ class ServerNotificationTest(test_vnflcm_basic_common.CommonVnfLcmTest):
# 7. LCM-Terminate
terminate_req = paramgen.terminate_vnf_min()
resp, body = self.terminate_vnf_instance(inst_id, terminate_req)
while True:
resp, body = self.terminate_vnf_instance(inst_id, terminate_req)
if 409 != resp.status_code:
break
time.sleep(3)
self.assertEqual(202, resp.status_code)
self.check_resp_headers_in_operation_task(resp)

View File

@ -78,11 +78,11 @@ class ServerNotificationMgmtDriver(object):
res_ids = vnfc_res_ids if vnfc_res_ids else []
for rsc in self.inst['instantiatedVnfInfo']['vnfcResourceInfo']:
if ('metadata' in rsc and
'alarmId' in rsc['metadata'] and (isall or
'server_notification' in rsc['metadata'] and (isall or
rsc['computeResource']['resourceId'] in res_ids)):
found = True
alarm_id = rsc['metadata']['alarmId']
del rsc['metadata']['alarmId']
alarm_id = rsc['metadata']['server_notification']['alarmId']
del rsc['metadata']['server_notification']
server_id = rsc['computeResource']['resourceId']
self._request_unregister(
server_notifier_uri, tenant, server_id, alarm_id)
@ -91,11 +91,13 @@ class ServerNotificationMgmtDriver(object):
def request_register_cancel(self, rsc_list):
server_notifier_uri, _, tenant = self.get_params()
for rsc in rsc_list:
alarm_id = rsc['metadata']['alarmId']
del rsc['metadata']['alarmId']
server_id = rsc['computeResource']['resourceId']
self._request_unregister(
server_notifier_uri, tenant, server_id, alarm_id)
if ('metadata' in rsc and
'server_notification' in rsc['metadata']):
alarm_id = rsc['metadata']['server_notification']['alarmId']
del rsc['metadata']['server_notification']
server_id = rsc['computeResource']['resourceId']
self._request_unregister(
server_notifier_uri, tenant, server_id, alarm_id)
def _request_register(self, vnfc_resource):
server_id = vnfc_resource['computeResource']['resourceId']
@ -118,7 +120,8 @@ class ServerNotificationMgmtDriver(object):
raise common_ex.MgmtDriverOtherError(error_message=msg)
if 'metadata' not in vnfc_resource:
vnfc_resource['metadata'] = {}
vnfc_resource['metadata']['alarmId'] = res_body['alarm_id']
vnfc_resource['metadata']['server_notification'] = {
'alarmId': res_body['alarm_id']}
LOG.debug(
"server_notification registration is processed: %d. "
"alarm_id: %s", resp.status_code, res_body['alarm_id'])
@ -128,7 +131,7 @@ class ServerNotificationMgmtDriver(object):
rsc_list = []
for rsc in self.inst['instantiatedVnfInfo']['vnfcResourceInfo']:
if ('metadata' not in rsc or
'alarmId' not in rsc['metadata']):
'server_notification' not in rsc['metadata']):
try:
self._request_register(rsc)
rsc_list.append(rsc)

View File

@ -40,14 +40,18 @@ _inst1 = {
'vduId': 'vduId',
'computeResource': {},
'metadata': {
"alarmId": "alarm_id"
"server_notification": {
"alarmId": "alarm_id"
}
}
}, {
'id': 'vnfc_resource_id2',
'vduId': 'vduId2',
'computeResource': {},
'metadata': {
"alarmId": "alarm_id2"
"server_notification": {
"alarmId": "alarm_id2"
}
}
}
],
@ -59,7 +63,7 @@ _inst1 = {
}],
'metadata': {
'ServerNotifierUri': 'ServerNotifierUri',
'ServerNotifierFaultID': '1234'
'ServerNotifierFaultID': ['1111', '1234']
}
}
}

View File

@ -42,14 +42,18 @@ _inst1 = {
'vduId': 'vduId',
'computeResource': {},
'metadata': {
"alarmId": "alarm_id"
"server_notification": {
"alarmId": "alarm_id"
}
}
}, {
'id': 'vnfc_resource_id2',
'vduId': 'vduId2',
'computeResource': {},
'metadata': {
"alarmId": "alarm_id2"
"server_notification": {
"alarmId": "alarm_id2"
}
}
}
],
@ -61,7 +65,7 @@ _inst1 = {
}],
'metadata': {
'ServerNotifierUri': 'ServerNotifierUri',
'ServerNotifierFaultID': '1234'
'ServerNotifierFaultID': ['1111', '1234']
}
},
}
@ -174,7 +178,7 @@ class TestServerNotification(base.TestCase):
group='server_notification', server_notification=True)
_inst = copy.deepcopy(_inst1)
metadata = _inst['instantiatedVnfInfo']['metadata']
metadata['ServerNotifierFaultID'] = '0000'
metadata['ServerNotifierFaultID'] = ['0000']
mock_inst.return_value = objects.VnfInstanceV2.from_dict(_inst)
self.assertRaises(