summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-04-12 18:06:35 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-04-12 19:03:01 +0000
commitb5af39bba53c907a2ad98916b3cfc529d6da1747 (patch)
tree2a573660b2408f58c54db874a4cf2069d1a627e2
parent6d750971fde9be564dafe6c4ca25fa8872bf44f3 (diff)
Make exposed methods clearer in xenapi.vmops
VMOps is only used by connection.py, but it's not always obvious which methods are intended to be public and which are used internally for implementation reasons. Prefix any internal methods with _ to make that clearer. Change-Id: I50244c18233d6d7463057cf5df42d5a5a3a6fab9
-rw-r--r--nova/tests/test_xenapi.py7
-rw-r--r--nova/tests/xenapi/stubs.py4
-rw-r--r--nova/virt/xenapi/vmops.py35
3 files changed, 22 insertions, 24 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 8d6780f67..da8091233 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -664,7 +664,7 @@ class XenAPIVMTestCase(test.TestCase):
def dummy(*args, **kwargs):
pass
- self.stubs.Set(vmops.VMOps, 'create_vifs', dummy)
+ self.stubs.Set(vmops.VMOps, '_create_vifs', dummy)
# Reset network table
xenapi_fake.reset_table('network')
# Instance id = 2 will use vlan network (see db/fakes.py)
@@ -703,6 +703,11 @@ class XenAPIVMTestCase(test.TestCase):
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
vm = vm_utils.VMHelper.lookup(session, instance.name)
vbd = xenapi_fake.create_vbd(vm, None)
+
+ def fake_spawn(self, context, inst, network_info, image_meta):
+ inst._rescue = False
+ self.stubs.Set(vmops.VMOps, 'spawn', fake_spawn)
+
conn = xenapi_conn.get_connection(False)
conn.rescue(self.context, instance, [], None)
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index b13d2b0e3..e97568f03 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -311,9 +311,6 @@ def stub_out_vm_methods(stubs):
def fake_release_bootlock(self, vm):
pass
- def fake_spawn_rescue(self, context, inst, network_info, image_meta):
- inst._rescue = False
-
@classmethod
def fake_generate_ephemeral(cls, *args):
pass
@@ -321,7 +318,6 @@ def stub_out_vm_methods(stubs):
stubs.Set(vmops.VMOps, "_shutdown", fake_shutdown)
stubs.Set(vmops.VMOps, "_acquire_bootlock", fake_acquire_bootlock)
stubs.Set(vmops.VMOps, "_release_bootlock", fake_release_bootlock)
- stubs.Set(vmops.VMOps, "spawn_rescue", fake_spawn_rescue)
stubs.Set(vm_utils.VMHelper, 'generate_ephemeral', fake_generate_ephemeral)
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index ee4a2956f..e95abf23c 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -357,10 +357,6 @@ class VMOps(object):
msg = _("Failed to spawn, rolling back")
undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
- def spawn_rescue(self, context, instance, image_meta, network_info):
- """Spawn a rescue instance."""
- self.spawn(context, instance, image_meta, network_info)
-
def _generate_hostname(self, instance):
"""Generate the instance's hostname."""
hostname = instance["hostname"]
@@ -422,7 +418,7 @@ class VMOps(object):
VMHelper.preconfigure_instance(self._session, instance,
first_vdi_ref, network_info)
- self.create_vifs(vm_ref, instance, network_info)
+ self._create_vifs(vm_ref, instance, network_info)
self.inject_network_info(instance, network_info, vm_ref)
hostname = self._generate_hostname(instance)
@@ -570,7 +566,7 @@ class VMOps(object):
# Update agent, if necessary
# This also waits until the agent starts
LOG.debug(_("Querying agent version"), instance=instance)
- version = self.get_agent_version(instance)
+ version = self._get_agent_version(instance)
if version:
LOG.info(_('Instance agent version: %s'), version,
instance=instance)
@@ -579,8 +575,8 @@ class VMOps(object):
cmp_version(version, agent_build['version']) < 0):
LOG.info(_('Updating Agent to %s'), agent_build['version'],
instance=instance)
- self.agent_update(instance, agent_build['url'],
- agent_build['md5hash'])
+ self._agent_update(instance, agent_build['url'],
+ agent_build['md5hash'])
# if the guest agent is not available, configure the
# instance, but skip the admin password configuration
@@ -909,7 +905,7 @@ class VMOps(object):
else:
self._session.call_xenapi('VM.clean_reboot', vm_ref)
- def get_agent_version(self, instance):
+ def _get_agent_version(self, instance):
"""Get the version of the agent running on the VM instance."""
# The agent can be slow to start for a variety of reasons. On Windows,
@@ -949,7 +945,7 @@ class VMOps(object):
return None
- def agent_update(self, instance, url, md5sum):
+ def _agent_update(self, instance, url, md5sum):
"""Update agent on the VM instance."""
# Send the encrypted password
@@ -1223,7 +1219,7 @@ class VMOps(object):
self._shutdown(instance, vm_ref)
self._acquire_bootlock(vm_ref)
instance._rescue = True
- self.spawn_rescue(context, instance, image_meta, network_info)
+ self.spawn(context, instance, image_meta, network_info)
rescue_vm_ref = VMHelper.lookup(self._session, instance.name)
vdi_ref = self._find_root_vdi_ref(vm_ref)
@@ -1467,14 +1463,15 @@ class VMOps(object):
for (network, info) in network_info:
location = 'vm-data/networking/%s' % info['mac'].replace(':', '')
- self.add_to_param_xenstore(vm_ref, location, json.dumps(info))
+ self._add_to_param_xenstore(vm_ref, location, json.dumps(info))
try:
- self.write_to_xenstore(instance, location, info, vm_ref=vm_ref)
+ self._write_to_xenstore(instance, location, info,
+ vm_ref=vm_ref)
except KeyError:
# catch KeyError for domid if instance isn't running
pass
- def create_vifs(self, vm_ref, instance, network_info):
+ def _create_vifs(self, vm_ref, instance, network_info):
"""Creates vifs for an instance."""
LOG.debug(_("Creating vifs"), instance=instance)
@@ -1515,9 +1512,9 @@ class VMOps(object):
hostname = hostname[:15]
LOG.debug(_("Injecting hostname to xenstore"), instance=instance)
- self.add_to_param_xenstore(vm_ref, 'vm-data/hostname', hostname)
+ self._add_to_param_xenstore(vm_ref, 'vm-data/hostname', hostname)
- def write_to_xenstore(self, instance, path, value, vm_ref=None):
+ def _write_to_xenstore(self, instance, path, value, vm_ref=None):
"""
Writes the passed value to the xenstore record for the given VM
at the specified location. A XenAPIPlugin.PluginError will be raised
@@ -1574,16 +1571,16 @@ class VMOps(object):
return {'returncode': 'error', 'message': err_msg}
return None
- def add_to_param_xenstore(self, vm_ref, key, val):
+ def _add_to_param_xenstore(self, vm_ref, key, val):
"""
Takes a key/value pair and adds it to the xenstore parameter
record for the given vm instance. If the key exists in xenstore,
it is overwritten
"""
- self.remove_from_param_xenstore(vm_ref, key)
+ self._remove_from_param_xenstore(vm_ref, key)
self._session.call_xenapi('VM.add_to_xenstore_data', vm_ref, key, val)
- def remove_from_param_xenstore(self, vm_ref, key):
+ def _remove_from_param_xenstore(self, vm_ref, key):
"""
Takes a single key and removes it from the xenstore parameter
record data for the given VM.