Remove the last remnants of LXDSession use
_container_init just changed to _migrate, and was dramatically simplified because pylxd handles most of the work for us now. Change-Id: I60e513e0ea5967a7f579918085b27b0c17aea802
This commit is contained in:
parent
473dfb629e
commit
e6a584ea28
|
@ -36,8 +36,8 @@ class LXDTestLiveMigrate(test.NoDBTestCase):
|
||||||
self.driver.config = mock.MagicMock()
|
self.driver.config = mock.MagicMock()
|
||||||
self.driver.operations = mock.MagicMock()
|
self.driver.operations = mock.MagicMock()
|
||||||
|
|
||||||
@mock.patch.object(driver.LXDDriver, '_container_init')
|
@mock.patch.object(driver.LXDDriver, '_migrate')
|
||||||
def test_live_migration(self, mock_container_init):
|
def test_live_migration(self, mock_migrate):
|
||||||
"""Verify that the correct live migration calls
|
"""Verify that the correct live migration calls
|
||||||
are made.
|
are made.
|
||||||
"""
|
"""
|
||||||
|
@ -48,19 +48,19 @@ class LXDTestLiveMigrate(test.NoDBTestCase):
|
||||||
mock.sentinel.dest, mock_post_method,
|
mock.sentinel.dest, mock_post_method,
|
||||||
mock.sentinel.recover_method, mock.sentinel.block_migration,
|
mock.sentinel.recover_method, mock.sentinel.block_migration,
|
||||||
mock.sentinel.migrate_data)
|
mock.sentinel.migrate_data)
|
||||||
mock_container_init.assert_called_once_with(mock.sentinel.dest,
|
mock_migrate.assert_called_once_with(mock.sentinel.dest,
|
||||||
mock.sentinel.instance)
|
mock.sentinel.instance)
|
||||||
mock_post_method.assert_called_once_with(
|
mock_post_method.assert_called_once_with(
|
||||||
mock.sentinel.context, mock.sentinel.instance, mock.sentinel.dest,
|
mock.sentinel.context, mock.sentinel.instance, mock.sentinel.dest,
|
||||||
mock.sentinel.block_migration)
|
mock.sentinel.block_migration)
|
||||||
|
|
||||||
@mock.patch.object(driver.LXDDriver, '_container_init')
|
@mock.patch.object(driver.LXDDriver, '_migrate')
|
||||||
def test_live_migration_failed(self, mock_container_init):
|
def test_live_migration_failed(self, mock_migrate):
|
||||||
"""Verify that an exception is raised when live-migration
|
"""Verify that an exception is raised when live-migration
|
||||||
fails.
|
fails.
|
||||||
"""
|
"""
|
||||||
self.flags(my_ip='fakeip')
|
self.flags(my_ip='fakeip')
|
||||||
mock_container_init.side_effect = \
|
mock_migrate.side_effect = \
|
||||||
lxd_exceptions.APIError(500, 'Fake')
|
lxd_exceptions.APIError(500, 'Fake')
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
lxd_exceptions.APIError,
|
lxd_exceptions.APIError,
|
||||||
|
|
|
@ -46,7 +46,6 @@ from pylxd import exceptions as lxd_exceptions
|
||||||
from nova.virt.lxd import vif as lxd_vif
|
from nova.virt.lxd import vif as lxd_vif
|
||||||
from nova.virt.lxd import common
|
from nova.virt.lxd import common
|
||||||
from nova.virt.lxd import flavor
|
from nova.virt.lxd import flavor
|
||||||
from nova.virt.lxd import session
|
|
||||||
from nova.virt.lxd import storage
|
from nova.virt.lxd import storage
|
||||||
|
|
||||||
from nova.api.metadata import base as instance_metadata
|
from nova.api.metadata import base as instance_metadata
|
||||||
|
@ -267,11 +266,6 @@ class LXDDriver(driver.ComputeDriver):
|
||||||
device_scan_attempts=CONF.libvirt.num_iscsi_scan_tries,
|
device_scan_attempts=CONF.libvirt.num_iscsi_scan_tries,
|
||||||
transport='default')
|
transport='default')
|
||||||
|
|
||||||
# XXX: rockstar (5 Jul 2016) - These attributes are temporary. We
|
|
||||||
# will know our cleanup of nova-lxd is complete when these
|
|
||||||
# attributes are no longer needed.
|
|
||||||
self.session = session.LXDAPISession()
|
|
||||||
|
|
||||||
def init_host(self, host):
|
def init_host(self, host):
|
||||||
"""Initialize the driver on the host.
|
"""Initialize the driver on the host.
|
||||||
|
|
||||||
|
@ -928,7 +922,7 @@ class LXDDriver(driver.ComputeDriver):
|
||||||
|
|
||||||
# Step 2 - Open a websocket on the srct and and
|
# Step 2 - Open a websocket on the srct and and
|
||||||
# generate the container config
|
# generate the container config
|
||||||
self._container_init(migration['source_compute'], instance)
|
self._migrate(migration['source_compute'], instance)
|
||||||
|
|
||||||
# Step 3 - Start the network and container
|
# Step 3 - Start the network and container
|
||||||
self.plug_vifs(instance, network_info)
|
self.plug_vifs(instance, network_info)
|
||||||
|
@ -960,7 +954,7 @@ class LXDDriver(driver.ComputeDriver):
|
||||||
def live_migration(self, context, instance, dest,
|
def live_migration(self, context, instance, dest,
|
||||||
post_method, recover_method, block_migration=False,
|
post_method, recover_method, block_migration=False,
|
||||||
migrate_data=None):
|
migrate_data=None):
|
||||||
self._container_init(dest, instance)
|
self._migrate(dest, instance)
|
||||||
post_method(context, instance, dest, block_migration)
|
post_method(context, instance, dest, block_migration)
|
||||||
|
|
||||||
def post_live_migration(self, context, instance, block_device_info,
|
def post_live_migration(self, context, instance, block_device_info,
|
||||||
|
@ -1067,40 +1061,6 @@ class LXDDriver(driver.ComputeDriver):
|
||||||
|
|
||||||
return configdrive_dir
|
return configdrive_dir
|
||||||
|
|
||||||
def get_container_migrate(self, container_migrate, host, instance):
|
|
||||||
"""Create the image source for a migrating container
|
|
||||||
|
|
||||||
:container_migrate: the container websocket information
|
|
||||||
:host: the source host
|
|
||||||
:instance: nova instance object
|
|
||||||
return dictionary of the image source
|
|
||||||
"""
|
|
||||||
LOG.debug('get_container_migrate called for instance',
|
|
||||||
instance=instance)
|
|
||||||
try:
|
|
||||||
# Generate the container config
|
|
||||||
container_metadata = container_migrate['metadata']
|
|
||||||
|
|
||||||
container_url = 'https://%s:8443%s' \
|
|
||||||
% (CONF.my_ip, container_migrate.get('operation'))
|
|
||||||
|
|
||||||
lxd_config = self.client.host_info['environment']
|
|
||||||
|
|
||||||
return {
|
|
||||||
'base_image': '',
|
|
||||||
'mode': 'pull',
|
|
||||||
'certificate': lxd_config['certificate'],
|
|
||||||
'operation': container_url,
|
|
||||||
'secrets': container_metadata['metadata'],
|
|
||||||
'type': 'migration'
|
|
||||||
}
|
|
||||||
except Exception as ex:
|
|
||||||
with excutils.save_and_reraise_exception():
|
|
||||||
LOG.error(_LE('Failed to configure migation source '
|
|
||||||
'%(instance)s: %(ex)s'),
|
|
||||||
{'instance': instance.name, 'ex': ex},
|
|
||||||
instance=instance)
|
|
||||||
|
|
||||||
def _after_reboot(self):
|
def _after_reboot(self):
|
||||||
"""Perform sync operation after host reboot."""
|
"""Perform sync operation after host reboot."""
|
||||||
context = nova.context.get_admin_context()
|
context = nova.context.get_admin_context()
|
||||||
|
@ -1122,14 +1082,11 @@ class LXDDriver(driver.ComputeDriver):
|
||||||
instance, network_info)
|
instance, network_info)
|
||||||
self.firewall_driver.apply_instance_filter(instance, network_info)
|
self.firewall_driver.apply_instance_filter(instance, network_info)
|
||||||
|
|
||||||
def _container_init(self, host, instance):
|
def _migrate(self, source_host, instance):
|
||||||
(state, data) = (self.session.container_migrate(instance.name,
|
"""Migrate an instance from source."""
|
||||||
CONF.my_ip,
|
source_client = pylxd.Client(
|
||||||
instance))
|
endpoint='https://{}'.format(source_host), verify=False)
|
||||||
container_config = {
|
container = source_client.containers.get(instance.name)
|
||||||
'name': instance.name,
|
data = container.generate_migration_data()
|
||||||
'profiles': [instance.name],
|
|
||||||
'source': self.get_container_migrate(
|
self.containers.create(data, wait=True)
|
||||||
data, host, instance)
|
|
||||||
}
|
|
||||||
self.session.container_init(container_config, instance, host)
|
|
||||||
|
|
Loading…
Reference in New Issue