def update_device(self, dev_dict): """Sync the content from device dictionary to device object. The resource tracker updates the available devices periodically. To avoid meaningless syncs with the database, we update the device object only if a value changed. """ # Note(jprabh1x): added bus,slot,function into fields dict as # seperate fields. no_changes = ('status', 'instance_uuid', 'id', 'extra_info', 'workload') map(lambda x: dev_dict.pop(x, None), [key for key in no_changes]) # Note(jprabh1x): populating values for bus,slot,function from address in dev_dict. if dev_dict.has_key("address"): address = pci_utils.parse_address(dev_dict["address"]) dev_dict.update({'bus':str(address[1]), 'slot':str(address[2]), 'function':str(address[3])}) for k, v in dev_dict.items(): if k in self.fields.keys(): self[k] = v else: extra_info = self.extra_info extra_info.update({k: str(v)}) self.extra_info = extra_info
def test_parse_address(self): self.parse_result = pci_utils.parse_address("0000:04:12.6") self.assertEqual(self.parse_result, ('0000', '04', '12', '6'))
def test_parse_address(self): self.parse_result = pci_utils.parse_address("0000:04:12.6") self.assertEqual(self.parse_result, ('0000', '04', '12', '6'))