From 059940646802fb400c4e59b46d805f40ba61b70f Mon Sep 17 00:00:00 2001 From: Alessandro Pilotti Date: Sun, 9 Sep 2012 18:01:18 +0300 Subject: Adds get_available_resource to hyperv driver Fixes Bug #1048263 update_available_resource was changed to get_available_resource. This fix implements implements the method in the hyperv driver Change-Id: Id018877c563aab7f75618ada318b6422ab06c7b7 --- ...est_get_available_resource_multiprocessing.p.gz | Bin 0 -> 270 bytes ...estCase.test_get_available_resource_shutil.p.gz | Bin 0 -> 298 bytes ...PITestCase.test_get_available_resource_wmi.p.gz | Bin 0 -> 1013 bytes nova/tests/test_hypervapi.py | 6 ++++ nova/virt/hyperv/driver.py | 4 +-- nova/virt/hyperv/vmops.py | 34 +++++++-------------- 6 files changed, 19 insertions(+), 25 deletions(-) create mode 100644 nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz create mode 100644 nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz create mode 100644 nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz new file mode 100644 index 000000000..3f50a76e0 Binary files /dev/null and b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz differ diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz new file mode 100644 index 000000000..35126ad4b Binary files /dev/null and b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz differ diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz new file mode 100644 index 000000000..1a34569d1 Binary files /dev/null and b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz differ diff --git a/nova/tests/test_hypervapi.py b/nova/tests/test_hypervapi.py index 49a411862..0ae65feaf 100644 --- a/nova/tests/test_hypervapi.py +++ b/nova/tests/test_hypervapi.py @@ -19,6 +19,7 @@ Test suite for the Hyper-V driver and related APIs. """ import os +import platform import shutil import sys import uuid @@ -151,6 +152,11 @@ class HyperVAPITestCase(basetestcase.BaseTestCase): finally: super(HyperVAPITestCase, self).tearDown() + def test_get_available_resource(self): + dic = self._conn.get_available_resource() + + self.assertEquals(dic['hypervisor_hostname'], platform.node()) + def test_list_instances(self): num_vms = self._hypervutils.get_vm_count() instances = self._conn.list_instances() diff --git a/nova/virt/hyperv/driver.py b/nova/virt/hyperv/driver.py index c8a2e299e..f385640f5 100644 --- a/nova/virt/hyperv/driver.py +++ b/nova/virt/hyperv/driver.py @@ -120,8 +120,8 @@ class HyperVDriver(driver.ComputeDriver): def poll_rescued_instances(self, timeout): pass - def update_available_resource(self, context, host): - self._vmops.update_available_resource(context, host) + def get_available_resource(self): + return self._vmops.get_available_resource() def update_host_status(self): """See xenapi_conn.py implementation.""" diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py index aa8d34e12..bb0e294c0 100644 --- a/nova/virt/hyperv/vmops.py +++ b/nova/virt/hyperv/vmops.py @@ -20,6 +20,7 @@ Management class for basic VM operations. """ import multiprocessing import os +import platform import uuid from nova import db @@ -555,23 +556,17 @@ class VMOps(baseops.BaseOps): LOG.info(_('Windows version: %s ') % version) return version - def update_available_resource(self, context, host): - """Updates compute manager resource info on ComputeNode table. + def get_available_resource(self): + """Retrieve resource info. - This method is called as an periodic tasks and is used only - in live migration currently. + This method is called when nova-compute launches, and + as part of a periodic task. - :param ctxt: security context - :param host: hostname that compute manager is currently running + :returns: dictionary describing resources """ + LOG.info(_('get_available_resource called')) - try: - service_ref = db.service_get_all_compute_by_host(context, host)[0] - except exception.NotFound: - raise exception.ComputeServiceUnavailable(host=host) - - # Updating host information # TODO(alexpilotti) implemented cpu_info dic = {'vcpus': self._get_vcpu_total(), 'memory_mb': self._get_memory_mb_total(), @@ -581,17 +576,10 @@ class VMOps(baseops.BaseOps): 'local_gb_used': self._get_local_gb_used(), 'hypervisor_type': "hyperv", 'hypervisor_version': self._get_hypervisor_version(), - 'cpu_info': "unknown", - 'service_id': service_ref['id'], - 'disk_available_least': 1} - - compute_node_ref = service_ref['compute_node'] - if not compute_node_ref: - LOG.info(_('Compute_service record created for %s ') % host) - db.compute_node_create(context, dic) - else: - LOG.info(_('Compute_service record updated for %s ') % host) - db.compute_node_update(context, compute_node_ref[0]['id'], dic) + 'hypervisor_hostname': platform.node(), + 'cpu_info': 'unknown'} + + return dic def _cache_image(self, fn, target, fname, cow=False, Size=None, *args, **kwargs): -- cgit