Return master_id from get_resource_id for deleting SNMP resource

This commit modified the get_resource_id method in SysinvSyncThread.
The previous code only return community/ip_address which is for the
creat service operation. By this change, the get_resource_id method
in this class will return resource.master_id for deleting SNMP
community and trapdest.

Test:
  1 Add snmp trapdest and snmp community configuration from system
controller, with command:
    system snmp-comm-add -c test1
    system snmp-trapdest-add -c test1 -i 10.11.2.1
  2 Wait the snmp community and trapdest configured in subcloud in
subcloud controller:
    system snmp-comm-list
    system snmp-trapdest-list
  3 Delete the snmp community and trapdest in system controller:
    system snmp-trapdest-delete 10.11.2.1
    system snmp-comm-delete test1
  Expected: trapdest or community should be deleted from subcloud,
result can also be observed  in dcorch DB and /var/log/dcorch.log.

Change-Id: I8d3b40599f83263cade1799d5a1dae72d3bac2c5
Closes-Bug: 1863045
Signed-off-by: Yuxing Jiang <yuxing.jiang@windriver.com>
This commit is contained in:
Yuxing Jiang
2020-06-30 11:50:15 -04:00
parent 3a75a9d854
commit 4f5d0b4fca

View File

@@ -674,8 +674,11 @@ class SysinvSyncThread(SyncThread):
def get_resource_id(self, resource_type, resource):
if resource_type == consts.RESOURCE_TYPE_SYSINV_SNMP_COMM:
LOG.debug("get_resource_id for community {}".format(resource))
return resource.community
if hasattr(resource, 'community'):
LOG.debug("get_resource_id for community {}".format(resource))
return resource.community
elif hasattr(resource, 'master_id'):
return resource.master_id
elif resource_type == consts.RESOURCE_TYPE_SYSINV_SNMP_TRAPDEST:
if hasattr(resource, 'ip_address') and \
hasattr(resource, 'community'):
@@ -683,6 +686,8 @@ class SysinvSyncThread(SyncThread):
"community".format(resource),
extra=self.log_extra)
return resource.ip_address
elif hasattr(resource, 'master_id'):
return resource.master_id
elif resource_type == consts.RESOURCE_TYPE_SYSINV_CERTIFICATE:
if hasattr(resource, 'signature'):
LOG.debug("get_resource_id signature={}".format(