diff options
author | Sudipta Biswas <sbiswas7@in.ibm.com> | 2015-07-11 00:12:13 +0530 |
---|---|---|
committer | Sudipta Biswas <sbiswas7@in.ibm.com> | 2015-07-21 23:30:34 +0530 |
commit | e464267085ca45129ef9b092db41112697ddf3ca (patch) | |
tree | 0a63785748402cc0ddf40516e0d0dd5ccdaa016b /nova/pci | |
parent | 4442979e71bb09ff9b71604c0dddd37c2bede04d (diff) | |
download | nova-e464267085ca45129ef9b092db41112697ddf3ca.tar.gz |
cleanup NovaObjectDictCompat subclassing from pci_device
cleanup subclassing on NovaObjectDictCompat and fix subsequent
Unit tests and code associated with nova/objects/pci_device.py
Due to the exhaustive nature of changes, the cleanup is done
one object at a time.
This is the first patch of the series.
There shall be more patches to follow for other objects.
Related to blueprint liberty-objects
Change-Id: Idb764632e9a4f926bc1f159333de6a8366abcfab
Diffstat (limited to 'nova/pci')
-rw-r--r-- | nova/pci/device.py | 2 | ||||
-rw-r--r-- | nova/pci/manager.py | 24 | ||||
-rw-r--r-- | nova/pci/stats.py | 2 |
3 files changed, 14 insertions, 14 deletions
diff --git a/nova/pci/device.py b/nova/pci/device.py index a7cb201cfd..8f4e8d079b 100644 --- a/nova/pci/device.py +++ b/nova/pci/device.py @@ -28,7 +28,7 @@ def check_device_status(dev_status=None): def outer(f): @functools.wraps(f) def inner(devobj, instance=None): - if devobj['status'] not in dev_status: + if devobj.status not in dev_status: raise exception.PciDeviceInvalidStatus( compute_node_id=devobj.compute_node_id, address=devobj.address, status=devobj.status, diff --git a/nova/pci/manager.py b/nova/pci/manager.py index 04719f4f50..dfb161c2f5 100644 --- a/nova/pci/manager.py +++ b/nova/pci/manager.py @@ -65,12 +65,12 @@ class PciDevTracker(object): self.allocations = collections.defaultdict(list) self.claims = collections.defaultdict(list) for dev in self.pci_devs: - uuid = dev['instance_uuid'] - if dev['status'] == 'claimed': + uuid = dev.instance_uuid + if dev.status == 'claimed': self.claims[uuid].append(dev) - elif dev['status'] == 'allocated': + elif dev.status == 'allocated': self.allocations[uuid].append(dev) - elif dev['status'] == 'available': + elif dev.status == 'available': self.stats.add_device(dev) @property @@ -84,7 +84,7 @@ class PciDevTracker(object): dev.save() self.pci_devs = [dev for dev in self.pci_devs - if dev['status'] != 'deleted'] + if dev.status != 'deleted'] @property def pci_stats(self): @@ -103,11 +103,11 @@ class PciDevTracker(object): or removed while assigned. """ - exist_addrs = set([dev['address'] for dev in self.pci_devs]) + exist_addrs = set([dev.address for dev in self.pci_devs]) new_addrs = set([dev['address'] for dev in devices]) for existed in self.pci_devs: - if existed['address'] in exist_addrs - new_addrs: + if existed.address in exist_addrs - new_addrs: try: device.remove(existed) except exception.PciDeviceInvalidStatus as e: @@ -126,9 +126,9 @@ class PciDevTracker(object): self.stats.remove_device(existed) else: new_value = next((dev for dev in devices if - dev['address'] == existed['address'])) + dev['address'] == existed.address)) new_value['compute_node_id'] = self.node_id - if existed['status'] in ('claimed', 'allocated'): + if existed.status in ('claimed', 'allocated'): # Pci properties may change while assigned because of # hotplug or config changes. Although normally this should # not happen. @@ -183,7 +183,7 @@ class PciDevTracker(object): def _free_device(self, dev, instance=None): device.free(dev, instance) - stale = self.stale.pop(dev['address'], None) + stale = self.stale.pop(dev.address, None) if stale: dev.update_device(stale) self.stats.add_device(dev) @@ -195,8 +195,8 @@ class PciDevTracker(object): # information, not the claimed one. So we can't use # instance['pci_devices'] to check the devices to be freed. for dev in self.pci_devs: - if (dev['status'] in ('claimed', 'allocated') and - dev['instance_uuid'] == instance['uuid']): + if (dev.status in ('claimed', 'allocated') and + dev.instance_uuid == instance['uuid']): self._free_device(dev) def update_pci_for_instance(self, context, instance): diff --git a/nova/pci/stats.py b/nova/pci/stats.py index 46bdc2a652..d5becef55e 100644 --- a/nova/pci/stats.py +++ b/nova/pci/stats.py @@ -88,7 +88,7 @@ class PciDeviceStats(object): if not devspec: return tags = devspec.get_tags() - pool = {k: dev.get(k) for k in self.pool_keys} + pool = {k: getattr(dev, k) for k in self.pool_keys} if tags: pool.update(tags) return pool |