summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-23 00:21:57 +0000
committerGerrit Code Review <review@openstack.org>2012-02-23 00:21:57 +0000
commit6166b73a50270c617d1dc7e36cfe095d0eeeef3f (patch)
tree7a01e335d9ba3a890c90bb0493898171cfb111c4
parent08fa534a0d28fa1be48aef927584161becb936c7 (diff)
parent112dd3c1b824097acf5f89cd3afa8785623e4f9e (diff)
downloadnova-6166b73a50270c617d1dc7e36cfe095d0eeeef3f.tar.gz
nova-6166b73a50270c617d1dc7e36cfe095d0eeeef3f.tar.xz
nova-6166b73a50270c617d1dc7e36cfe095d0eeeef3f.zip
Merge "Move get_info to taking an instance."
-rw-r--r--nova/compute/manager.py12
-rw-r--r--nova/tests/baremetal/test_proxy_bare_metal.py3
-rw-r--r--nova/tests/test_libvirt.py15
-rw-r--r--nova/tests/test_virt_drivers.py5
-rw-r--r--nova/tests/test_vmwareapi.py32
-rw-r--r--nova/tests/test_xenapi.py2
-rw-r--r--nova/virt/baremetal/proxy.py4
-rw-r--r--nova/virt/driver.py2
-rw-r--r--nova/virt/fake.py8
-rw-r--r--nova/virt/libvirt/connection.py38
-rw-r--r--nova/virt/vmwareapi/vmops.py6
-rw-r--r--nova/virt/vmwareapi_conn.py4
-rw-r--r--nova/virt/xenapi/vmops.py7
-rw-r--r--nova/virt/xenapi_conn.py4
14 files changed, 68 insertions, 74 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 77452ee94..3066cb3a6 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -258,7 +258,7 @@ class ComputeManager(manager.SchedulerDependentManager):
"""Retrieve the power state for the given instance."""
LOG.debug(_('Checking state'), instance=instance)
try:
- return self.driver.get_info(instance['name'])["state"]
+ return self.driver.get_info(instance)["state"]
except exception.NotFound:
return power_state.FAILED
@@ -2229,16 +2229,14 @@ class ComputeManager(manager.SchedulerDependentManager):
for db_instance in db_instances:
# Allow other periodic tasks to do some work...
greenthread.sleep(0)
- name = db_instance["name"]
db_power_state = db_instance['power_state']
try:
- vm_instance = self.driver.get_info(name)
+ vm_instance = self.driver.get_info(db_instance)
vm_power_state = vm_instance.state
except exception.InstanceNotFound:
- msg = _("Instance %(name)s found in database but "
- "not known by hypervisor. Setting power "
- "state to NOSTATE") % locals()
- LOG.warn(msg)
+ LOG.warn(_("Instance found in database but not known by "
+ "hypervisor. Setting power state to NOSTATE"),
+ locals(), instance=db_instance)
vm_power_state = power_state.NOSTATE
if vm_power_state == db_power_state:
diff --git a/nova/tests/baremetal/test_proxy_bare_metal.py b/nova/tests/baremetal/test_proxy_bare_metal.py
index 0ea746227..d1768d151 100644
--- a/nova/tests/baremetal/test_proxy_bare_metal.py
+++ b/nova/tests/baremetal/test_proxy_bare_metal.py
@@ -282,7 +282,8 @@ class ProxyBareMetalTestCase(test.TestCase):
# Code under test
conn = proxy.get_connection(True)
- info = conn.get_info('instance-00000001')
+ # TODO: this is not a very good fake instance
+ info = conn.get_info({'name': 'instance-00000001'})
# Expected values
self.assertEquals(info['mem'], 16777216)
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 75c3f4eb6..3044cd136 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -2208,10 +2208,10 @@ class LibvirtConnectionTestCase(test.TestCase):
"""Test for nova.virt.libvirt.connection.LivirtConnection
._wait_for_running. """
- def fake_get_info(instance_name):
- if instance_name == "not_found":
+ def fake_get_info(instance):
+ if instance['name'] == "not_found":
raise exception.NotFound
- elif instance_name == "running":
+ elif instance['name'] == "running":
return {'state': power_state.RUNNING}
else:
return {'state': power_state.SHUTOFF}
@@ -2222,15 +2222,18 @@ class LibvirtConnectionTestCase(test.TestCase):
""" instance not found case """
self.assertRaises(utils.LoopingCallDone,
self.libvirtconnection._wait_for_running,
- "not_found")
+ {'name': 'not_found',
+ 'uuid': 'not_found_uuid'})
""" instance is running case """
self.assertRaises(utils.LoopingCallDone,
self.libvirtconnection._wait_for_running,
- "running")
+ {'name': 'running',
+ 'uuid': 'running_uuid'})
""" else case """
- self.libvirtconnection._wait_for_running("else")
+ self.libvirtconnection._wait_for_running({'name': 'else',
+ 'uuid': 'other_uuid'})
def test_finish_migration(self):
"""Test for nova.virt.libvirt.connection.LivirtConnection
diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py
index 70d54db9a..5b5b7d42e 100644
--- a/nova/tests/test_virt_drivers.py
+++ b/nova/tests/test_virt_drivers.py
@@ -245,7 +245,7 @@ class _VirtDriverTestCase(test.TestCase):
@catch_notimplementederror
def test_get_info(self):
instance_ref, network_info = self._get_running_instance()
- info = self.connection.get_info(instance_ref['name'])
+ info = self.connection.get_info(instance_ref)
self.assertIn('state', info)
self.assertIn('max_mem', info)
self.assertIn('mem', info)
@@ -255,7 +255,8 @@ class _VirtDriverTestCase(test.TestCase):
@catch_notimplementederror
def test_get_info_for_unknown_instance(self):
self.assertRaises(exception.NotFound,
- self.connection.get_info, 'I just made this name up')
+ self.connection.get_info,
+ {'name': 'I just made this name up'})
@catch_notimplementederror
def test_get_diagnostics(self):
diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py
index bf8bcbe2f..49584eeb3 100644
--- a/nova/tests/test_vmwareapi.py
+++ b/nova/tests/test_vmwareapi.py
@@ -114,7 +114,7 @@ class VMWareAPIVMTestCase(test.TestCase):
self.assertEquals(len(instances), 1)
# Get Nova record for VM
- vm_info = self.conn.get_info(1)
+ vm_info = self.conn.get_info({'name': 1})
# Get record for VM
vms = vmwareapi_fake._get_objects("VirtualMachine")
@@ -157,15 +157,15 @@ class VMWareAPIVMTestCase(test.TestCase):
def test_spawn(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
def test_snapshot(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
self.conn.snapshot(self.context, self.instance, "Test-Snapshot")
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
def test_snapshot_non_existent(self):
@@ -175,11 +175,11 @@ class VMWareAPIVMTestCase(test.TestCase):
def test_reboot(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
reboot_type = "SOFT"
self.conn.reboot(self.instance, self.network_info, reboot_type)
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
def test_reboot_non_existent(self):
@@ -188,19 +188,19 @@ class VMWareAPIVMTestCase(test.TestCase):
def test_reboot_not_poweredon(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
self.conn.suspend(self.instance)
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.PAUSED)
self.assertRaises(Exception, self.conn.reboot, self.instance)
def test_suspend(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
self.conn.suspend(self.instance)
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.PAUSED)
def test_suspend_non_existent(self):
@@ -209,13 +209,13 @@ class VMWareAPIVMTestCase(test.TestCase):
def test_resume(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
self.conn.suspend(self.instance)
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.PAUSED)
self.conn.resume(self.instance)
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
def test_resume_non_existent(self):
@@ -224,18 +224,18 @@ class VMWareAPIVMTestCase(test.TestCase):
def test_resume_not_suspended(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
self.assertRaises(Exception, self.conn.resume, self.instance)
def test_get_info(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
def test_destroy(self):
self._create_vm()
- info = self.conn.get_info(1)
+ info = self.conn.get_info({'name': 1})
self._check_vm_info(info, power_state.RUNNING)
instances = self.conn.list_instances()
self.assertEquals(len(instances), 1)
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 312aaea37..fc8e535e7 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -332,7 +332,7 @@ class XenAPIVMTestCase(test.TestCase):
self.assertEquals(instances, [str(instance_id)])
# Get Nova record for VM
- vm_info = conn.get_info(instance_id)
+ vm_info = conn.get_info({'name': instance_id})
# Get XenAPI record for VM
vms = [rec for ref, rec
in xenapi_fake.get_all_records('VM').iteritems()
diff --git a/nova/virt/baremetal/proxy.py b/nova/virt/baremetal/proxy.py
index b651ee2c4..cd2427a6d 100644
--- a/nova/virt/baremetal/proxy.py
+++ b/nova/virt/baremetal/proxy.py
@@ -531,7 +531,7 @@ class ProxyConnection(driver.ComputeDriver):
LOG.debug(_('instance %s: finished toXML method'), instance['name'])
return xml_info
- def get_info(self, instance_name):
+ def get_info(self, instance):
"""Retrieve information from baremetal for a specific instance name.
If a baremetal error is encountered during lookup, we might raise a
@@ -539,7 +539,7 @@ class ProxyConnection(driver.ComputeDriver):
baremetal error is.
"""
- _domain_info = self._conn.get_domain_info(instance_name)
+ _domain_info = self._conn.get_domain_info(instance['name'])
state, max_mem, mem, num_cpu, cpu_time = _domain_info
return {'state': state,
'max_mem': max_mem,
diff --git a/nova/virt/driver.py b/nova/virt/driver.py
index 92e0d53dd..8779699ac 100644
--- a/nova/virt/driver.py
+++ b/nova/virt/driver.py
@@ -108,7 +108,7 @@ class ComputeDriver(object):
# TODO(Vek): Need to pass context in for access to auth_token
raise NotImplementedError()
- def get_info(self, instance_name):
+ def get_info(self, instance):
"""Get the current status of an instance, by name (not ID!)
Returns a dict containing:
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index ba2d6dae7..bbb8e05be 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -188,10 +188,10 @@ class FakeConnection(driver.ComputeDriver):
pass
return True
- def get_info(self, instance_name):
- if instance_name not in self.instances:
- raise exception.InstanceNotFound(instance_id=instance_name)
- i = self.instances[instance_name]
+ def get_info(self, instance):
+ if instance['name'] not in self.instances:
+ raise exception.InstanceNotFound(instance_id=instance['name'])
+ i = self.instances[instance['name']]
return {'state': i.state,
'max_mem': 0,
'mem': 0,
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
index 634acdeca..ce723de55 100644
--- a/nova/virt/libvirt/connection.py
+++ b/nova/virt/libvirt/connection.py
@@ -339,10 +339,8 @@ class LibvirtConnection(driver.ComputeDriver):
def _destroy(self, instance, network_info, block_device_info=None,
cleanup=True):
- instance_name = instance['name']
-
try:
- virt_dom = self._lookup_by_name(instance_name)
+ virt_dom = self._lookup_by_name(instance['name'])
except exception.NotFound:
virt_dom = None
@@ -395,10 +393,8 @@ class LibvirtConnection(driver.ComputeDriver):
def _wait_for_destroy():
"""Called at an interval until the VM is gone."""
- instance_name = instance['name']
-
try:
- state = self.get_info(instance_name)['state']
+ state = self.get_info(instance)['state']
except exception.NotFound:
LOG.info(_("Instance destroyed successfully."),
instance=instance)
@@ -672,10 +668,8 @@ class LibvirtConnection(driver.ComputeDriver):
def _wait_for_reboot():
"""Called at an interval until the VM is running again."""
- instance_name = instance['name']
-
try:
- state = self.get_info(instance_name)['state']
+ state = self.get_info(instance)['state']
except exception.NotFound:
LOG.error(_("During reboot, instance disappeared."),
instance=instance)
@@ -816,10 +810,8 @@ class LibvirtConnection(driver.ComputeDriver):
def _wait_for_boot():
"""Called at an interval until the VM is running."""
- instance_name = instance['name']
-
try:
- state = self.get_info(instance_name)['state']
+ state = self.get_info(instance)['state']
except exception.NotFound:
LOG.error(_("During reboot, instance disappeared."),
instance=instance)
@@ -1375,7 +1367,7 @@ class LibvirtConnection(driver.ComputeDriver):
"[Error Code %(error_code)s] %(ex)s") % locals()
raise exception.Error(msg)
- def get_info(self, instance_name):
+ def get_info(self, instance):
"""Retrieve information from libvirt for a specific instance name.
If a libvirt error is encountered during lookup, we might raise a
@@ -1383,7 +1375,7 @@ class LibvirtConnection(driver.ComputeDriver):
libvirt error is.
"""
- virt_dom = self._lookup_by_name(instance_name)
+ virt_dom = self._lookup_by_name(instance['name'])
(state, max_mem, mem, num_cpu, cpu_time) = virt_dom.info()
return {'state': state,
'max_mem': max_mem,
@@ -1891,7 +1883,7 @@ class LibvirtConnection(driver.ComputeDriver):
def wait_for_live_migration():
"""waiting for live migration completion"""
try:
- self.get_info(instance_ref.name)['state']
+ self.get_info(instance_ref)['state']
except exception.NotFound:
timer.stop()
post_method(ctxt, instance_ref, dest, block_migration)
@@ -2178,17 +2170,17 @@ class LibvirtConnection(driver.ComputeDriver):
return disk_info_text
- def _wait_for_running(self, instance_name):
+ def _wait_for_running(self, instance):
try:
- state = self.get_info(instance_name)['state']
+ state = self.get_info(instance)['state']
except exception.NotFound:
- msg = _("During wait running, %s disappeared.") % instance_name
- LOG.error(msg)
+ LOG.error(_("During wait running, instance disappeared."),
+ instance=instance)
raise utils.LoopingCallDone
if state == power_state.RUNNING:
- msg = _("Instance %s running successfully.") % instance_name
- LOG.info(msg)
+ LOG.info(_("Instance running successfully."),
+ instance=instance)
raise utils.LoopingCallDone
@exception.wrap_exception()
@@ -2230,7 +2222,7 @@ class LibvirtConnection(driver.ComputeDriver):
self.firewall_driver.apply_instance_filter(instance, network_info)
- timer = utils.LoopingCall(self._wait_for_running, instance['name'])
+ timer = utils.LoopingCall(self._wait_for_running, instance)
return timer.start(interval=0.5, now=True)
@exception.wrap_exception()
@@ -2252,7 +2244,7 @@ class LibvirtConnection(driver.ComputeDriver):
domain = self._create_new_domain(xml)
self.firewall_driver.apply_instance_filter(instance, network_info)
- timer = utils.LoopingCall(self._wait_for_running, instance['name'])
+ timer = utils.LoopingCall(self._wait_for_running, instance)
return timer.start(interval=0.5, now=True)
def confirm_migration(self, migration, instance, network_info):
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index d613d7e02..4574dafdb 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -661,11 +661,11 @@ class VMWareVMOps(object):
reason = _("instance is not in a suspended state")
raise exception.InstanceResumeFailure(reason=reason)
- def get_info(self, instance_name):
+ def get_info(self, instance):
"""Return data about the VM instance."""
- vm_ref = self._get_vm_ref_from_the_name(instance_name)
+ vm_ref = self._get_vm_ref_from_the_name(instance['name'])
if vm_ref is None:
- raise exception.InstanceNotFound(instance_id=instance_name)
+ raise exception.InstanceNotFound(instance_id=instance['name'])
lst_properties = ["summary.config.numCpu",
"summary.config.memorySizeMB",
diff --git a/nova/virt/vmwareapi_conn.py b/nova/virt/vmwareapi_conn.py
index 16b1f8ac6..614b25cff 100644
--- a/nova/virt/vmwareapi_conn.py
+++ b/nova/virt/vmwareapi_conn.py
@@ -162,9 +162,9 @@ class VMWareESXConnection(driver.ComputeDriver):
"""Resume the suspended VM instance."""
self._vmops.resume(instance)
- def get_info(self, instance_name):
+ def get_info(self, instance):
"""Return info about the VM instance."""
- return self._vmops.get_info(instance_name)
+ return self._vmops.get_info(instance)
def get_diagnostics(self, instance):
"""Return data about VM diagnostics."""
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 78177920c..19370f7e6 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -477,7 +477,6 @@ class VMOps(object):
"""Spawn a new instance."""
LOG.debug(_('Starting VM %s...'), vm_ref)
self._start(instance, vm_ref)
- instance_name = instance.name
instance_uuid = instance.uuid
LOG.info(_('Spawning VM %(instance_uuid)s created %(vm_ref)s.')
% locals())
@@ -499,7 +498,7 @@ class VMOps(object):
LOG.debug(_('Instance %s: waiting for running'), instance_uuid)
expiration = time.time() + FLAGS.xenapi_running_timeout
while time.time() < expiration:
- state = self.get_info(instance_name)['state']
+ state = self.get_info(instance)['state']
if state == power_state.RUNNING:
break
@@ -1021,7 +1020,7 @@ class VMOps(object):
def _shutdown(self, instance, vm_ref, hard=True):
"""Shutdown an instance."""
instance_uuid = instance.uuid
- state = self.get_info(instance['name'])['state']
+ state = self.get_info(instance)['state']
if state == power_state.SHUTDOWN:
LOG.warn(_("VM %(instance_uuid)s already halted,"
"skipping shutdown...") % locals())
@@ -1393,7 +1392,7 @@ class VMOps(object):
def get_info(self, instance):
"""Return data about VM instance."""
- vm_ref = self._get_vm_opaque_ref(instance)
+ vm_ref = self._get_vm_opaque_ref(instance['name'])
vm_rec = self._session.call_xenapi("VM.get_record", vm_ref)
return VMHelper.compile_info(vm_rec)
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index 77efb34e3..1f308e5a5 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -314,9 +314,9 @@ class XenAPIConnection(driver.ComputeDriver):
"""Unplug VIFs from networks."""
self._vmops.unplug_vifs(instance_ref, network_info)
- def get_info(self, instance_name):
+ def get_info(self, instance):
"""Return data about VM instance"""
- return self._vmops.get_info(instance_name)
+ return self._vmops.get_info(instance)
def get_diagnostics(self, instance):
"""Return data about VM diagnostics"""