summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorAndy Southgate <andy.southgate@citrix.com>2011-01-24 19:04:25 +0000
committerAndy Southgate <andy.southgate@citrix.com>2011-01-24 19:04:25 +0000
commitcd346a2cda13833f976b9e838d67cf17c52f327e (patch)
tree4b639be009632abd5404d5a3b3cef232b6694f5c /nova
parentc97618e1eaff4091f01381073a298d0f67050126 (diff)
OS-55: PEP8 fixes
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/db/fakes.py17
-rw-r--r--nova/tests/test_xenapi.py19
-rw-r--r--nova/tests/xenapi/stubs.py10
-rw-r--r--nova/virt/conn_common.py3
-rw-r--r--nova/virt/disk.py2
-rw-r--r--nova/virt/xenapi/fake.py9
-rw-r--r--nova/virt/xenapi/vm_utils.py80
-rw-r--r--nova/virt/xenapi/vmops.py6
8 files changed, 77 insertions, 69 deletions
diff --git a/nova/tests/db/fakes.py b/nova/tests/db/fakes.py
index 4a0d1cc3c..c47fba5f3 100644
--- a/nova/tests/db/fakes.py
+++ b/nova/tests/db/fakes.py
@@ -23,6 +23,7 @@ from nova import db
from nova import utils
from nova.compute import instance_types
+
class FakeModel(object):
""" Stubs out for model """
def __init__(self, values):
@@ -37,6 +38,7 @@ class FakeModel(object):
else:
raise NotImplementedError()
+
def stub_out_db_instance_api(stubs):
""" Stubs out the db API for creating Instances """
@@ -67,12 +69,12 @@ def stub_out_db_instance_api(stubs):
stubs.Set(db, 'instance_create', fake_instance_create)
-def stub_out_db_network_api(stubs, injected = False):
+
+def stub_out_db_network_api(stubs, injected=False):
"""Stubs out the db API for retrieving networks"""
network_fields = {
- 'bridge': 'xenbr0',
- 'injected': injected
- }
+ 'bridge': 'xenbr0',
+ 'injected': injected}
if injected:
network_fields.update({
@@ -80,8 +82,7 @@ def stub_out_db_network_api(stubs, injected = False):
'gateway': '10.0.0.1',
'broadcast': '10.0.0.255',
'dns': '10.0.0.2',
- 'ra_server': None
- })
+ 'ra_server': None})
def fake_network_get_by_instance(context, instance_id):
return FakeModel(network_fields)
@@ -90,5 +91,5 @@ def stub_out_db_network_api(stubs, injected = False):
return '10.0.0.3'
stubs.Set(db, 'network_get_by_instance', fake_network_get_by_instance)
- stubs.Set(db, 'instance_get_fixed_address', fake_instance_get_fixed_address)
-
+ stubs.Set(db, 'instance_get_fixed_address',
+ fake_instance_get_fixed_address)
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index c94aeefd1..f7f7102a8 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -213,7 +213,7 @@ class XenAPIVMTestCase(test.TestCase):
check()
- def check_vm_record(self, conn, check_injection = False):
+ def check_vm_record(self, conn, check_injection=False):
instances = conn.list_instances()
self.assertEquals(instances, [1])
@@ -244,13 +244,13 @@ class XenAPIVMTestCase(test.TestCase):
# Check that the VM is running according to XenAPI.
self.assertEquals(vm['power_state'], 'Running')
-
+
if check_injection:
xenstore_data = xenapi_fake.VM_get_xenstore_data(vm_ref)
key_prefix = 'vm-data/vif/22_33_2A_B3_CC_DD/tcpip/'
tcpip_data = dict([(k.replace(key_prefix, ''), v)
for k, v in xenstore_data.iteritems()
- if k.startswith(key_prefix) ])
+ if k.startswith(key_prefix)])
self.assertEquals(tcpip_data, {
'BroadcastAddress/data/0': '10.0.0.255',
@@ -270,11 +270,10 @@ class XenAPIVMTestCase(test.TestCase):
'NameServer/type': 'string',
'SubnetMask/data/0': '255.255.255.0',
'SubnetMask/name': 'SubnetMask',
- 'SubnetMask/type': 'multi_sz'
- })
+ 'SubnetMask/type': 'multi_sz'})
def _test_spawn(self, image_id, kernel_id, ramdisk_id,
- check_injection = False):
+ check_injection=False):
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
values = {'name': 1,
'id': 1,
@@ -289,7 +288,7 @@ class XenAPIVMTestCase(test.TestCase):
conn = xenapi_conn.get_connection(False)
instance = db.instance_create(values)
conn.spawn(instance)
- self.check_vm_record(conn, check_injection = check_injection)
+ self.check_vm_record(conn, check_injection=check_injection)
def test_spawn_raw_objectstore(self):
FLAGS.xenapi_image_service = 'objectstore'
@@ -309,9 +308,9 @@ class XenAPIVMTestCase(test.TestCase):
def test_spawn_netinject(self):
FLAGS.xenapi_image_service = 'glance'
- db_fakes.stub_out_db_network_api(self.stubs, injected = True)
- self._test_spawn(1, 2, 3, check_injection = True)
-
+ db_fakes.stub_out_db_network_api(self.stubs, injected=True)
+ self._test_spawn(1, 2, 3, check_injection=True)
+
def tearDown(self):
super(XenAPIVMTestCase, self).tearDown()
self.manager.delete_project(self.project)
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 3cfc8e5f9..027855592 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -173,20 +173,20 @@ class FakeSessionForVMTests(fake.SessionBase):
def VM_get_VIFs(self, session_ref, vm_ref):
return (['0', '1', '2'])
-
+
def VIF_get_device(self, session_ref, vif_ref):
return ('1', '0', '2')[int(vif_ref)]
-
+
def VIF_get_MAC(self, session_ref, vif_ref):
return (
'11:22:2a:b3:CC:dd',
'22:33:2a:b3:CC:dd',
- '44:44:2a:b3:CC:dd'
- )[int(vif_ref)]
-
+ '44:44:2a:b3:CC:dd')[int(vif_ref)]
+
def VM_add_to_xenstore_data(self, session_ref, vm_ref, key, value):
fake.VM_add_to_xenstore_data(vm_ref, key, value)
+
class FakeSessionForVolumeTests(fake.SessionBase):
""" Stubs out a XenAPISession for Volume tests """
def __init__(self, uri):
diff --git a/nova/virt/conn_common.py b/nova/virt/conn_common.py
index bd9ed7794..5550b50c1 100644
--- a/nova/virt/conn_common.py
+++ b/nova/virt/conn_common.py
@@ -27,7 +27,8 @@ FLAGS = flags.FLAGS
flags.DEFINE_string('injected_network_template',
utils.abspath('virt/interfaces.template'),
'Template file for injected network')
-
+
+
def get_injectables(inst):
key = str(inst['key_data'])
net = None
diff --git a/nova/virt/disk.py b/nova/virt/disk.py
index 88b05f0c0..21bb53369 100644
--- a/nova/virt/disk.py
+++ b/nova/virt/disk.py
@@ -154,6 +154,7 @@ def _allocate_device():
def _free_device(device):
_DEVICES.append(device)
+
def inject_data_into_fs(fs, key, net, execute):
"""Injects data into a filesystem already mounted by the caller.
Virt connections can call this directly if they mount their fs
@@ -164,6 +165,7 @@ def inject_data_into_fs(fs, key, net, execute):
if net:
_inject_net_into_fs(net, fs, execute=execute)
+
def _inject_key_into_fs(key, fs, execute=None):
"""Add the given public ssh key to root's authorized_keys.
diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py
index f9ae8766a..561e47911 100644
--- a/nova/virt/xenapi/fake.py
+++ b/nova/virt/xenapi/fake.py
@@ -148,15 +148,18 @@ def create_vbd(vm_ref, vdi_ref):
after_VBD_create(vbd_ref, vbd_rec)
return vbd_ref
+
def VM_get_xenstore_data(vm_ref):
return _db_content['VM'][vm_ref].get('xenstore_data', '')
-
+
+
def VM_add_to_xenstore_data(vm_ref, key, value):
db_ref = _db_content['VM'][vm_ref]
if not 'xenstore_data' in db_ref:
db_ref['xenstore_data'] = {}
db_ref['xenstore_data'][key] = value
-
+
+
def after_VBD_create(vbd_ref, vbd_rec):
"""Create read-only fields and backref from VM to VBD when VBD is
created."""
@@ -169,11 +172,13 @@ def after_VBD_create(vbd_ref, vbd_rec):
vm_name_label = _db_content['VM'][vm_ref]['name_label']
vbd_rec['vm_name_label'] = vm_name_label
+
def after_VM_create(vm_ref, vm_rec):
"""Create read-only fields in the VM record."""
if 'is_control_domain' not in vm_rec:
vm_rec['is_control_domain'] = False
+
def create_pbd(config, host_ref, sr_ref, attached):
return _create_object('PBD', {
'device-config': config,
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index 68946a2bb..fa60c44c3 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -448,7 +448,7 @@ class VMHelper(HelperBase):
def preconfigure_instance(cls, session, instance, vdi_ref):
"""Makes alterations to the image before launching as part of spawn.
"""
-
+
# As mounting the image VDI is expensive, we only want do do it once,
# if at all, so determine whether it's required first, and then do
# everything
@@ -456,12 +456,13 @@ class VMHelper(HelperBase):
key, net = conn_common.get_injectables(instance)
if key is not None or net is not None:
mount_required = True
-
+
if mount_required:
+
def _mounted_processing(device):
"""Callback which runs with the image VDI attached"""
-
- dev_path = '/dev/'+device+'1' # NB: Partition 1 hardcoded
+
+ dev_path = '/dev/' + device + '1' # NB: Partition 1 hardcoded
tmpdir = tempfile.mkdtemp()
try:
# Mount only Linux filesystems, to avoid disturbing
@@ -478,9 +479,9 @@ class VMHelper(HelperBase):
else:
try:
# This try block ensures that the umount occurs
-
- xe_update_networking_filename = os.path.join(tmpdir,
- 'usr', 'sbin', 'xe-update-networking')
+
+ xe_update_networking_filename = os.path.join(
+ tmpdir, 'usr', 'sbin', 'xe-update-networking')
if os.path.isfile(xe_update_networking_filename):
# The presence of the xe-update-networking
# file indicates that this guest agent can
@@ -489,14 +490,15 @@ class VMHelper(HelperBase):
# required
LOG.info(_('XenServer tools installed in this '
'image are capable of network injection. '
- 'Networking files will not be manipulated'))
+ 'Networking files will not be'
+ 'manipulated'))
else:
- xe_daemon_filename = os.path.join(tmpdir, 'usr',
- 'sbin', 'xe-daemon')
+ xe_daemon_filename = os.path.join(tmpdir,
+ 'usr', 'sbin', 'xe-daemon')
if os.path.isfile(xe_daemon_filename):
- LOG.info(_('XenServer tools are present in '
- 'this image but are not capable of '
- 'network injection'))
+ LOG.info(_('XenServer tools are present '
+ 'in this image but are not capable '
+ 'of network injection'))
else:
LOG.info(_('XenServer tools are not '
'installed in this image'))
@@ -510,24 +512,23 @@ class VMHelper(HelperBase):
# remove temporary directory
os.rmdir(tmpdir)
- with_vdi_attached_here(session, vdi_ref, False, _mounted_processing)
-
-
+ with_vdi_attached_here(session, vdi_ref, False,
+ _mounted_processing)
+
@classmethod
def preconfigure_xenstore(cls, session, instance, vm_ref):
"""Sets xenstore values to modify the image behaviour after
VM start.
"""
-
+
xenstore_types = {
- 'BroadcastAddress' : 'multi_sz',
- 'DefaultGateway' : 'multi_sz',
- 'EnableDhcp' : 'dword',
- 'IPAddress' : 'multi_sz',
- 'NameServer' : 'string',
- 'SubnetMask' : 'multi_sz'
- }
-
+ 'BroadcastAddress': 'multi_sz',
+ 'DefaultGateway': 'multi_sz',
+ 'EnableDhcp': 'dword',
+ 'IPAddress': 'multi_sz',
+ 'NameServer': 'string',
+ 'SubnetMask': 'multi_sz'}
+
# Network setup
network_ref = db.network_get_by_instance(
context.get_admin_context(), instance['id'])
@@ -535,8 +536,8 @@ class VMHelper(HelperBase):
admin_context = context.get_admin_context()
address = db.instance_get_fixed_address(admin_context,
instance['id'])
-
- xenstore_data = {
+
+ xenstore_data = {
# NB: Setting broadcast address is not supported by
# Windows or the Windows guest agent, and will be ignored
# on that platform
@@ -545,30 +546,29 @@ class VMHelper(HelperBase):
'IPAddress': address,
'SubnetMask': network_ref['netmask'],
'DefaultGateway': network_ref['gateway'],
- 'NameServer': network_ref['dns']
- }
-
- device_to_configure = 0 # Configure network device 0 in the VM
-
+ 'NameServer': network_ref['dns']}
+
+ device_to_configure = 0 # Configure network device 0 in the VM
+
vif_refs = session.call_xenapi('VM.get_VIFs', vm_ref)
mac_addr = None
-
+
for vif_ref in vif_refs:
device = session.call_xenapi('VIF.get_device', vif_ref)
if str(device) == str(device_to_configure):
mac_addr = session.call_xenapi('VIF.get_MAC', vif_ref)
break
-
+
if mac_addr is None:
raise exception.NotFound(_('Networking device %s not found '
'in VM'))
-
+
# MAC address must be upper case in the xenstore key,
# with colons replaced by underscores
underscore_mac_addr = mac_addr.replace(':', '_')
xenstore_prefix = ('vm-data/vif/' +
underscore_mac_addr.upper() + '/tcpip/')
-
+
for xenstore_key, xenstore_value in xenstore_data.iteritems():
# NB: The xenstore_key part of the instance_key isn't used but
# must be unique. We set it to xenstore_key as a convenient
@@ -578,15 +578,15 @@ class VMHelper(HelperBase):
key_type = xenstore_types[xenstore_key]
session.call_xenapi('VM.add_to_xenstore_data', vm_ref,
- instance_key+'/name', xenstore_key)
+ instance_key + '/name', xenstore_key)
session.call_xenapi('VM.add_to_xenstore_data', vm_ref,
- instance_key+'/type', key_type)
+ instance_key + '/type', key_type)
if key_type == 'multi_sz':
session.call_xenapi('VM.add_to_xenstore_data', vm_ref,
- instance_key+'/data/0', xenstore_value)
+ instance_key + '/data/0', xenstore_value)
else:
session.call_xenapi('VM.add_to_xenstore_data', vm_ref,
- instance_key+'/data', xenstore_value)
+ instance_key + '/data', xenstore_value)
@classmethod
def compile_info(cls, record):
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index df282807a..9eea19c42 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -105,14 +105,14 @@ class VMOps(object):
if network_ref:
VMHelper.create_vif(self._session, vm_ref,
network_ref, instance.mac_address)
-
+
# Alter the image before VM start for, e.g. network injection
VMHelper.preconfigure_instance(self._session, instance, vdi_ref)
-
+
# Configure the VM's xenstore data before start for,
# e.g. network configuration
VMHelper.preconfigure_xenstore(self._session, instance, vm_ref)
-
+
LOG.debug(_('Starting VM %s...'), vm_ref)
self._session.call_xenapi('VM.start', vm_ref, False, False)
instance_name = instance.name