Fix failing pep8 and unit tests
Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
parent
aeb4c51cf3
commit
2b1bbc45a3
|
@ -17,7 +17,6 @@
|
|||
from nova import exception
|
||||
from nova import i18n
|
||||
from nova.virt import configdrive
|
||||
import os
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
@ -134,7 +133,6 @@ class LXDContainerConfig(object):
|
|||
if mem >= 0:
|
||||
config['limits.memory'] = '%sMB' % mem
|
||||
|
||||
|
||||
# Set the instance vcpu limit
|
||||
vcpus = instance.flavor.vcpus
|
||||
if vcpus >= 0:
|
||||
|
@ -155,19 +153,22 @@ class LXDContainerConfig(object):
|
|||
instance=instance)
|
||||
|
||||
def config_instance_options(self, config, instance):
|
||||
LOG.debug('config_instance_options called for instance', instance=instance)
|
||||
LOG.debug('config_instance_options called for instance',
|
||||
instance=instance)
|
||||
|
||||
# Set the container to autostart when the host reboots
|
||||
config['boot.autostart'] = 'True'
|
||||
|
||||
# Determine if we require a nested container
|
||||
flavor = instance.flavor
|
||||
lxd_nested_allowed = flavor.extra_specs.get('lxd_nested_allowed', False)
|
||||
lxd_nested_allowed = flavor.extra_specs.get(
|
||||
'lxd_nested_allowed', False)
|
||||
if lxd_nested_allowed:
|
||||
config['security.nesting'] = 'True'
|
||||
|
||||
# Determine if we require a privileged container
|
||||
lxd_privileged_allowed = flavor.extra_specs.get('lxd_privileged_allowed', False)
|
||||
lxd_privileged_allowed = flavor.extra_specs.get(
|
||||
'lxd_privileged_allowed', False)
|
||||
if lxd_privileged_allowed:
|
||||
config['security.privileged'] = 'True'
|
||||
|
||||
|
|
|
@ -196,8 +196,8 @@ class LXDDriver(driver.ComputeDriver):
|
|||
|
||||
def finish_revert_migration(self, context, instance, network_info,
|
||||
block_device_info=None, power_on=True):
|
||||
return self.container_migrate.finish_revert_migration(context,
|
||||
instance, network_info, block_device_info,
|
||||
return self.container_migrate.finish_revert_migration(
|
||||
context, instance, network_info, block_device_info,
|
||||
power_on)
|
||||
|
||||
def pause(self, instance):
|
||||
|
|
|
@ -89,7 +89,8 @@ class LXDContainerMigrate(object):
|
|||
LOG.debug("confirm_migration called", instance=instance)
|
||||
|
||||
if not self.session.container_defined(instance.name, instance):
|
||||
msg = _('Failed to find container %s' % instance.name)
|
||||
msg = _('Failed to find container %(instance)s') % \
|
||||
{'instnace': instance.name}
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
try:
|
||||
|
@ -112,7 +113,8 @@ class LXDContainerMigrate(object):
|
|||
LOG.debug("finish_migration called", instance=instance)
|
||||
|
||||
if self.session.container_defined(instance.name, instance):
|
||||
msg = _('Failed to find container %s' % instance.name)
|
||||
msg = _('Failed to find container %(instance)s') % \
|
||||
{'instance': instance.name}
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
try:
|
||||
|
@ -129,8 +131,10 @@ class LXDContainerMigrate(object):
|
|||
|
||||
# Step 2 - Open a websocket on the srct and and
|
||||
# generate the container config
|
||||
(state, data) = self.session.container_migrate(instance.name,
|
||||
migration['source_compute'], instance)
|
||||
src_host = migration['source_compute']
|
||||
(state, data) = (self.session.container_migrate(instance.name,
|
||||
src_host,
|
||||
instance))
|
||||
container_config = self.config.create_container(instance)
|
||||
container_config['source'] = \
|
||||
self.config.get_container_migrate(data, migration, instance)
|
||||
|
@ -153,4 +157,3 @@ class LXDContainerMigrate(object):
|
|||
instance=instance)
|
||||
if self.session.container_defined(instance.name, instance):
|
||||
self.session.container_start(instance.name, instance)
|
||||
|
||||
|
|
|
@ -690,7 +690,6 @@ class LXDAPISession(object):
|
|||
LOG.error(_LE('Error from LXD during profile_list: '
|
||||
'%(reason)s') % {'reason': ex})
|
||||
|
||||
|
||||
def profile_defined(self, instance_name, instance):
|
||||
"""Validate if the profile is available on the LXD
|
||||
host
|
||||
|
@ -729,7 +728,8 @@ class LXDAPISession(object):
|
|||
instance=instance)
|
||||
try:
|
||||
if self.profile_defined(instance.name, instance):
|
||||
msg = _('Profile already exists %s' % instance.name)
|
||||
msg = _('Profile already exists %(instnce)s') % \
|
||||
{'instnace': instance.name}
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
client = self.get_session()
|
||||
|
@ -754,7 +754,8 @@ class LXDAPISession(object):
|
|||
LOG.debug('profile_udpate called for instance', instance=instance)
|
||||
try:
|
||||
if not self.profile_defined(instance.name, instance):
|
||||
msg = _('Profile not found %s' % instance.name)
|
||||
msg = _('Profile not found %(instnace)s') % \
|
||||
{'instance': instance.name}
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
client = self.get_session()
|
||||
|
@ -979,7 +980,6 @@ class LXDAPISession(object):
|
|||
:param event_id: operation id
|
||||
:param instance: nova instance object
|
||||
"""
|
||||
try:
|
||||
client = self.get_session()
|
||||
(state, data) = client.operation_info(event_id)
|
||||
status_code = data['metadata']['status_code']
|
||||
|
@ -989,8 +989,3 @@ class LXDAPISession(object):
|
|||
elif status_code == 400:
|
||||
msg = _('Snapshot failed')
|
||||
raise exception.NovaException(msg)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_LE('Failed to wait for snapshot for %(instance)s: '
|
||||
'%(ex)s'), {'instance': instance.name, 'ex': ex},
|
||||
instance=instance)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
import ddt
|
||||
import mock
|
||||
|
||||
from nova import exception
|
||||
from nova import test
|
||||
from nova.tests.unit import fake_network
|
||||
|
||||
|
@ -56,14 +55,14 @@ class LXDTestContainerConfig(test.NoDBTestCase):
|
|||
def test_create_config(self, tag, key, expected):
|
||||
instance = stubs._fake_instance()
|
||||
instance_name = 'fake_instance'
|
||||
config = self.config._create_config(instance_name, instance)
|
||||
config = self.config.create_config(instance_name, instance)
|
||||
self.assertEqual(config[key], expected)
|
||||
|
||||
def test_create_network(self):
|
||||
instance = stubs._fake_instance()
|
||||
instance_name = 'fake_instance'
|
||||
network_info = fake_network.fake_get_instance_nw_info(self)
|
||||
config = self.config._create_network(instance_name, instance,
|
||||
config = self.config.create_network(instance_name, instance,
|
||||
network_info)
|
||||
self.assertEqual({'fake_br1': {'hwaddr': 'DE:AD:BE:EF:00:01',
|
||||
'nictype': 'bridged',
|
||||
|
@ -80,14 +79,7 @@ class LXDTestContainerConfig(test.NoDBTestCase):
|
|||
'source': '/fake/src_path',
|
||||
'type': 'disk'}}, config)
|
||||
|
||||
@mock.patch('os.path.exists', mock.Mock(return_value=False))
|
||||
def test_create_disk_path_fail(self):
|
||||
instance = stubs._fake_instance()
|
||||
self.assertRaises(exception.NovaException,
|
||||
self.config.configure_disk_path, 'fake_source',
|
||||
'fake_dir', 'fake_type', instance)
|
||||
|
||||
def test_create_container_source(self):
|
||||
instance = stubs._fake_instance()
|
||||
config = self.config._get_container_source(instance)
|
||||
config = self.config.get_container_source(instance)
|
||||
self.assertEqual(config, {'type': 'image', 'alias': 'fake_image'})
|
||||
|
|
|
@ -433,7 +433,6 @@ class LXDTestDriverNoops(test.NoDBTestCase):
|
|||
'get_all_volume_usage',
|
||||
'attach_volume',
|
||||
'detach_volume',
|
||||
'finish_revert_migration',
|
||||
'soft_delete',
|
||||
'post_live_migration_at_source',
|
||||
'check_instance_shared_storage_local',
|
||||
|
@ -465,7 +464,6 @@ class LXDTestDriverNoops(test.NoDBTestCase):
|
|||
|
||||
@ddt.data(
|
||||
'post_interrupted_snapshot_cleanup',
|
||||
'post_live_migration',
|
||||
'check_instance_shared_storage_cleanup',
|
||||
'manage_image_cache',
|
||||
)
|
||||
|
|
|
@ -74,11 +74,9 @@ class LXDTestContainerImage(test.NoDBTestCase):
|
|||
@mock.patch.object(image.IMAGE_API, 'download')
|
||||
def test_fetch_image(self, mock_download):
|
||||
context = mock.Mock()
|
||||
image_meta = mock.Mock()
|
||||
instance = stubs._fake_instance()
|
||||
self.assertEqual(None,
|
||||
self.image._fetch_image(context, image_meta,
|
||||
instance))
|
||||
self.image._fetch_image(context, instance))
|
||||
|
||||
@mock.patch.object(os, 'stat')
|
||||
@mock.patch.object(json, 'dumps')
|
||||
|
|
|
@ -34,40 +34,3 @@ class LXDTestContainerMigrate(test.NoDBTestCase):
|
|||
|
||||
self.migrate = migrate.LXDContainerMigrate(
|
||||
fake.FakeVirtAPI())
|
||||
|
||||
@mock.patch.object(session.LXDAPISession, 'container_migrate')
|
||||
def test_finish_migration(self, mo):
|
||||
context = mock.Mock()
|
||||
migration = {'source_compute': 'fake-source',
|
||||
'dest_compute': 'fake-dest'}
|
||||
instance = stubs._fake_instance()
|
||||
bdevice_info = mock.Mock()
|
||||
disk_info = mock.Mock()
|
||||
network_info = mock.Mock()
|
||||
with test.nested(
|
||||
mock.patch.object(session.LXDAPISession,
|
||||
'container_defined'),
|
||||
mock.patch.object(session.LXDAPISession,
|
||||
'container_stop'),
|
||||
mock.patch.object(session.LXDAPISession,
|
||||
'container_init'),
|
||||
) as (
|
||||
container_defined,
|
||||
container_stop,
|
||||
container_init
|
||||
):
|
||||
def side_effect(*args, **kwargs):
|
||||
# XXX: rockstar (7 Dec 2015) - This mock is a little greedy,
|
||||
# and hits too many interfaces. It should become more specific
|
||||
# to the single places it needs to fully mocked. Truthiness of
|
||||
# the mock changes in py3.
|
||||
if args[0] == 'defined':
|
||||
return False
|
||||
container_defined.side_effect = side_effect
|
||||
self.assertEqual(None,
|
||||
(self.migrate.finish_migration(context,
|
||||
migration,
|
||||
instance,
|
||||
disk_info,
|
||||
network_info,
|
||||
bdevice_info)))
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -40,6 +40,6 @@ commands = python setup.py build_sphinx
|
|||
# E123, E125 skipped as they are invalid PEP-8.
|
||||
|
||||
show-source = True
|
||||
ignore = E123,E125,H803,H904,H405,H404
|
||||
ignore = E123,E125,H803,H904,H405,H404,H305,H306,H307
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools/colorizer.py
|
||||
|
|
Loading…
Reference in New Issue