diff options
| author | Daniel P. Berrange <berrange@redhat.com> | 2013-02-15 15:36:57 +0000 |
|---|---|---|
| committer | Daniel P. Berrange <berrange@redhat.com> | 2013-02-16 10:39:35 +0000 |
| commit | 5ec38e6a576e0102a951e45d6ee2753450bcd3f4 (patch) | |
| tree | be84720ae3531c6982c88a19bf87607d70fef077 | |
| parent | dc5a994e333c743f8ae8970ce0a2d8ca8c48d9f3 (diff) | |
| download | nova-5ec38e6a576e0102a951e45d6ee2753450bcd3f4.tar.gz nova-5ec38e6a576e0102a951e45d6ee2753450bcd3f4.tar.xz nova-5ec38e6a576e0102a951e45d6ee2753450bcd3f4.zip | |
Ensure there is only one instance of LibvirtDriver
The HostState() class in libvirt creates a second instance of
the LibvirtDriver() class, which cause duplicate initialization
of various things. This is pointless, since it was a method on
the original LibvirtDriver() which created the HostState()
instance, and thus it could easily pass in the original object.
Blueprint: compute-driver-events
Change-Id: I0734bfcc1b014406ffe64ef7abb14a533998dea2
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
| -rw-r--r-- | nova/tests/test_libvirt.py | 8 | ||||
| -rwxr-xr-x | nova/virt/libvirt/driver.py | 10 |
2 files changed, 4 insertions, 14 deletions
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index c93bb0168..d2cd5a757 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -3393,13 +3393,7 @@ class HostStateTestCase(test.TestCase): return HostStateTestCase.instance_caps def test_update_status(self): - virtapi = fake.FakeVirtAPI() - self.mox.StubOutWithMock(libvirt_driver, 'LibvirtDriver') - libvirt_driver.LibvirtDriver(virtapi, True).AndReturn( - self.FakeConnection()) - - self.mox.ReplayAll() - hs = libvirt_driver.HostState(virtapi, True) + hs = libvirt_driver.HostState(self.FakeConnection()) stats = hs._stats self.assertEquals(stats["vcpus"], 1) self.assertEquals(stats["vcpus_used"], 0) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 4e2fb9d39..8ce03f13a 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -319,7 +319,7 @@ class LibvirtDriver(driver.ComputeDriver): @property def host_state(self): if not self._host_state: - self._host_state = HostState(self.virtapi, self.read_only) + self._host_state = HostState(self) return self._host_state def has_min_version(self, lv_ver=None, hv_ver=None, hv_type=None): @@ -3306,12 +3306,10 @@ class LibvirtDriver(driver.ComputeDriver): class HostState(object): """Manages information about the compute node through libvirt.""" - def __init__(self, virtapi, read_only): + def __init__(self, connection): super(HostState, self).__init__() - self.read_only = read_only self._stats = {} - self.connection = None - self.virtapi = virtapi + self.connection = connection self.update_status() def get_host_stats(self, refresh=False): @@ -3325,8 +3323,6 @@ class HostState(object): def update_status(self): """Retrieve status info from libvirt.""" LOG.debug(_("Updating host stats")) - if self.connection is None: - self.connection = LibvirtDriver(self.virtapi, self.read_only) data = {} data["vcpus"] = self.connection.get_vcpu_total() data["vcpus_used"] = self.connection.get_vcpu_used() |
