diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-06-05 18:45:25 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-06-05 18:45:25 +0000 |
commit | 9a020a6ecf5d0ec1a49e8f52ce1c8908ae51e2b5 (patch) | |
tree | 87e4eef48efa5d35ba90d18bfc07f646ab709d42 | |
parent | 5a24235c22d259469e32febd58adb72c57880b2d (diff) | |
parent | 5b85997e33aa749ece94edebaaefefe71b899561 (diff) | |
download | nova-9a020a6ecf5d0ec1a49e8f52ce1c8908ae51e2b5.tar.gz nova-9a020a6ecf5d0ec1a49e8f52ce1c8908ae51e2b5.tar.xz nova-9a020a6ecf5d0ec1a49e8f52ce1c8908ae51e2b5.zip |
Merge "cleanup power state (partially implements bp task-management)"
-rw-r--r-- | nova/compute/manager.py | 3 | ||||
-rw-r--r-- | nova/compute/power_state.py | 25 | ||||
-rw-r--r-- | nova/scheduler/driver.py | 4 | ||||
-rw-r--r-- | nova/tests/baremetal/test_proxy_bare_metal.py | 14 | ||||
-rw-r--r-- | nova/tests/test_libvirt.py | 2 | ||||
-rw-r--r-- | nova/virt/libvirt/connection.py | 42 |
6 files changed, 61 insertions, 29 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 266e591c5..8c35d286b 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -308,7 +308,7 @@ class ComputeManager(manager.SchedulerDependentManager): try: return self.driver.get_info(instance)["state"] except exception.NotFound: - return power_state.FAILED + return power_state.NOSTATE def get_console_topic(self, context, **kwargs): """Retrieves the console host for a project on this host. @@ -2472,7 +2472,6 @@ class ComputeManager(manager.SchedulerDependentManager): continue if (vm_power_state in (power_state.NOSTATE, - power_state.SHUTOFF, power_state.SHUTDOWN, power_state.CRASHED) and db_instance['vm_state'] == vm_states.ACTIVE): diff --git a/nova/compute/power_state.py b/nova/compute/power_state.py index c468fe6b3..6d1c00b98 100644 --- a/nova/compute/power_state.py +++ b/nova/compute/power_state.py @@ -18,18 +18,26 @@ # License for the specific language governing permissions and limitations # under the License. -"""The various power states that a VM can be in.""" - -#NOTE(justinsb): These are the virDomainState values from libvirt +"""Power state is the state we get by calling virt driver on a particular +domain. The hypervisor is always considered the authority on the status +of a particular VM, and the power_state in the DB should be viewed as a +snapshot of the VMs's state in the (recent) past. It can be periodically +updated, and should also be updated at the end of a task if the task is +supposed to affect power_state. +""" + +# NOTE(maoy): These are *not* virDomainState values from libvirt. +# The hex value happens to match virDomainState for backward-compatibility +# reasons. NOSTATE = 0x00 RUNNING = 0x01 -BLOCKED = 0x02 PAUSED = 0x03 -SHUTDOWN = 0x04 -SHUTOFF = 0x05 +SHUTDOWN = 0x04 # the VM is powered off CRASHED = 0x06 SUSPENDED = 0x07 -FAILED = 0x08 + +# TODO(maoy): BUILDING state is only used in bare metal case and should +# eventually be removed/cleaned up. NOSTATE is probably enough. BUILDING = 0x09 # TODO(justinsb): Power state really needs to be a proper class, @@ -38,13 +46,10 @@ BUILDING = 0x09 _STATE_MAP = { NOSTATE: 'pending', RUNNING: 'running', - BLOCKED: 'blocked', PAUSED: 'paused', SHUTDOWN: 'shutdown', - SHUTOFF: 'shutdown', CRASHED: 'crashed', SUSPENDED: 'suspended', - FAILED: 'failed to spawn', BUILDING: 'building', } diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 87abfde11..a9b69c4bb 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -252,9 +252,7 @@ class Scheduler(object): """ # Checking instance is running. - if instance_ref['power_state'] != power_state.RUNNING and not ( - FLAGS.libvirt_type == 'xen' and - instance_ref['power_state'] == power_state.BLOCKED): + if instance_ref['power_state'] != power_state.RUNNING: raise exception.InstanceNotRunning( instance_id=instance_ref['uuid']) diff --git a/nova/tests/baremetal/test_proxy_bare_metal.py b/nova/tests/baremetal/test_proxy_bare_metal.py index 497debef9..74353ce3c 100644 --- a/nova/tests/baremetal/test_proxy_bare_metal.py +++ b/nova/tests/baremetal/test_proxy_bare_metal.py @@ -174,18 +174,14 @@ class BareMetalDomTestCase(test.TestCase): """Check to see that all entries in the domain list are removed except for the one that is in the running state""" - fake_file = StringIO.StringIO() - domains = [dict(node_id=1, name='i-00000001', status=power_state.NOSTATE), dict(node_id=2, name='i-00000002', status=power_state.RUNNING), - dict(node_id=3, name='i-00000003', status=power_state.BLOCKED), - dict(node_id=4, name='i-00000004', status=power_state.PAUSED), - dict(node_id=5, name='i-00000005', status=power_state.SHUTDOWN), - dict(node_id=6, name='i-00000006', status=power_state.SHUTOFF), - dict(node_id=7, name='i-00000007', status=power_state.CRASHED), - dict(node_id=8, name='i-00000008', status=power_state.SUSPENDED), - dict(node_id=9, name='i-00000009', status=power_state.FAILED)] + dict(node_id=3, name='i-00000003', status=power_state.PAUSED), + dict(node_id=5, name='i-00000004', status=power_state.SHUTDOWN), + dict(node_id=7, name='i-00000005', status=power_state.CRASHED), + dict(node_id=8, name='i-00000006', status=power_state.SUSPENDED), + dict(node_id=9, name='i-00000007', status=power_state.NOSTATE)] # Create the mock objects self.mox.StubOutWithMock(dom, 'read_domains') diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 596d6d1f1..dfceae4f3 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -2579,7 +2579,7 @@ class LibvirtDriverTestCase(test.TestCase): elif instance['name'] == "running": return {'state': power_state.RUNNING} else: - return {'state': power_state.SHUTOFF} + return {'state': power_state.SHUTDOWN} self.stubs.Set(self.libvirtconnection, 'get_info', fake_get_info) diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index d4d7b61aa..11c9841b3 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -46,7 +46,6 @@ import multiprocessing import os import shutil import sys -import time import uuid from eventlet import greenthread @@ -189,6 +188,34 @@ def patch_tpool_proxy(): patch_tpool_proxy() +VIR_DOMAIN_NOSTATE = 0 +VIR_DOMAIN_RUNNING = 1 +VIR_DOMAIN_BLOCKED = 2 +VIR_DOMAIN_PAUSED = 3 +VIR_DOMAIN_SHUTDOWN = 4 +VIR_DOMAIN_SHUTOFF = 5 +VIR_DOMAIN_CRASHED = 6 +VIR_DOMAIN_PMSUSPENDED = 7 + +LIBVIRT_POWER_STATE = { + VIR_DOMAIN_NOSTATE: power_state.NOSTATE, + VIR_DOMAIN_RUNNING: power_state.RUNNING, + # NOTE(maoy): The DOMAIN_BLOCKED state is only valid in Xen. + # It means that the VM is running and the vCPU is idle. So, + # we map it to RUNNING + VIR_DOMAIN_BLOCKED: power_state.RUNNING, + VIR_DOMAIN_PAUSED: power_state.PAUSED, + # NOTE(maoy): The libvirt API doc says that DOMAIN_SHUTDOWN + # means the domain is being shut down. So technically the domain + # is still running. SHUTOFF is the real powered off state. + # But we will map both to SHUTDOWN anyway. + # http://libvirt.org/html/libvirt-libvirt.html + VIR_DOMAIN_SHUTDOWN: power_state.SHUTDOWN, + VIR_DOMAIN_SHUTOFF: power_state.SHUTDOWN, + VIR_DOMAIN_CRASHED: power_state.CRASHED, + VIR_DOMAIN_PMSUSPENDED: power_state.SUSPENDED, +} + def _late_load_cheetah(): global Template @@ -347,6 +374,8 @@ class LibvirtDriver(driver.ComputeDriver): # puTime: the time used by the domain in nanoseconds (state, _max_mem, _mem, _num_cpu, _cpu_time) = domain.info() + state = LIBVIRT_POWER_STATE[state] + name = domain.name() return driver.InstanceInfo(name, state) @@ -389,7 +418,8 @@ class LibvirtDriver(driver.ComputeDriver): # Code=55 Error=Requested operation is not valid: # domain is not running (state, _max_mem, _mem, _cpus, _t) = virt_dom.info() - if state == power_state.SHUTOFF: + state = LIBVIRT_POWER_STATE[state] + if state == power_state.SHUTDOWN: is_okay = True if not is_okay: @@ -668,6 +698,8 @@ class LibvirtDriver(driver.ComputeDriver): snapshot_name = uuid.uuid4().hex (state, _max_mem, _mem, _cpus, _t) = virt_dom.info() + state = LIBVIRT_POWER_STATE[state] + if state == power_state.RUNNING: virt_dom.managedSave(0) # Make the snapshot @@ -719,6 +751,7 @@ class LibvirtDriver(driver.ComputeDriver): """ dom = self._lookup_by_name(instance.name) (state, _max_mem, _mem, _cpus, _t) = dom.info() + state = LIBVIRT_POWER_STATE[state] # NOTE(vish): This check allows us to reboot an instance that # is already shutdown. if state == power_state.RUNNING: @@ -728,8 +761,9 @@ class LibvirtDriver(driver.ComputeDriver): # call takes to return. for x in xrange(FLAGS.libvirt_wait_soft_reboot_seconds): (state, _max_mem, _mem, _cpus, _t) = dom.info() + state = LIBVIRT_POWER_STATE[state] + if state in [power_state.SHUTDOWN, - power_state.SHUTOFF, power_state.CRASHED]: LOG.info(_("Instance shutdown successfully."), instance=instance) @@ -1693,7 +1727,7 @@ class LibvirtDriver(driver.ComputeDriver): """ virt_dom = self._lookup_by_name(instance['name']) (state, max_mem, mem, num_cpu, cpu_time) = virt_dom.info() - return {'state': state, + return {'state': LIBVIRT_POWER_STATE[state], 'max_mem': max_mem, 'mem': mem, 'num_cpu': num_cpu, |