Unblock nova-lxd gate
A recent change in nova[1] added an allocations argument to the compute driver spawn function. Include it in nova-lxd's implementation as well. Also allow deletion of instances that are in a rescued state. [1] https://review.openstack.org/#/c/511879/ Change-Id: Ie99ef6c7249b0b43cf21de6aaa883d04cdfafba2
This commit is contained in:
parent
aaa8b60215
commit
4e4bc6d0a7
|
@ -257,6 +257,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
image_meta = mock.Mock()
|
||||
injected_files = mock.Mock()
|
||||
admin_password = mock.Mock()
|
||||
allocations = mock.Mock()
|
||||
network_info = [_VIF]
|
||||
block_device_info = mock.Mock()
|
||||
virtapi = manager.ComputeVirtAPI(mock.MagicMock())
|
||||
|
@ -270,7 +271,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
|
||||
lxd_driver.spawn(
|
||||
ctx, instance, image_meta, injected_files, admin_password,
|
||||
network_info, block_device_info)
|
||||
allocations, network_info, block_device_info)
|
||||
|
||||
self.vif_driver.plug.assert_called_once_with(
|
||||
instance, network_info[0])
|
||||
|
@ -289,6 +290,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
image_meta = mock.Mock()
|
||||
injected_files = mock.Mock()
|
||||
admin_password = mock.Mock()
|
||||
allocations = mock.Mock()
|
||||
|
||||
lxd_driver = driver.LXDDriver(None)
|
||||
lxd_driver.init_host(None)
|
||||
|
@ -298,7 +300,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
|
||||
lxd_driver.spawn,
|
||||
ctx, instance, image_meta, injected_files, admin_password,
|
||||
None, None)
|
||||
allocations, None, None)
|
||||
|
||||
@mock.patch('nova.virt.configdrive.required_by')
|
||||
def test_spawn_with_configdrive(self, configdrive):
|
||||
|
@ -314,6 +316,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
image_meta = mock.Mock()
|
||||
injected_files = mock.Mock()
|
||||
admin_password = mock.Mock()
|
||||
allocations = mock.Mock()
|
||||
network_info = [_VIF]
|
||||
block_device_info = mock.Mock()
|
||||
virtapi = manager.ComputeVirtAPI(mock.MagicMock())
|
||||
|
@ -328,7 +331,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
|
||||
lxd_driver.spawn(
|
||||
ctx, instance, image_meta, injected_files, admin_password,
|
||||
network_info, block_device_info)
|
||||
allocations, network_info, block_device_info)
|
||||
|
||||
self.vif_driver.plug.assert_called_once_with(
|
||||
instance, network_info[0])
|
||||
|
@ -357,6 +360,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
image_meta = mock.Mock()
|
||||
injected_files = mock.Mock()
|
||||
admin_password = mock.Mock()
|
||||
allocations = mock.Mock()
|
||||
network_info = [_VIF]
|
||||
block_device_info = mock.Mock()
|
||||
virtapi = manager.ComputeVirtAPI(mock.MagicMock())
|
||||
|
@ -369,7 +373,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
lxdcore_exceptions.LXDAPIException,
|
||||
lxd_driver.spawn,
|
||||
ctx, instance, image_meta, injected_files, admin_password,
|
||||
network_info, block_device_info)
|
||||
allocations, network_info, block_device_info)
|
||||
lxd_driver.cleanup.assert_called_once_with(
|
||||
ctx, instance, network_info, block_device_info)
|
||||
|
||||
|
@ -390,6 +394,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
image_meta = mock.Mock()
|
||||
injected_files = mock.Mock()
|
||||
admin_password = mock.Mock()
|
||||
allocations = mock.Mock()
|
||||
network_info = [_VIF]
|
||||
block_device_info = mock.Mock()
|
||||
virtapi = manager.ComputeVirtAPI(mock.MagicMock())
|
||||
|
@ -402,7 +407,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
lxdcore_exceptions.LXDAPIException,
|
||||
lxd_driver.spawn,
|
||||
ctx, instance, image_meta, injected_files, admin_password,
|
||||
network_info, block_device_info)
|
||||
allocations, network_info, block_device_info)
|
||||
lxd_driver.cleanup.assert_called_once_with(
|
||||
ctx, instance, network_info, block_device_info)
|
||||
|
||||
|
@ -421,6 +426,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
image_meta = mock.Mock()
|
||||
injected_files = mock.Mock()
|
||||
admin_password = mock.Mock()
|
||||
allocations = mock.Mock()
|
||||
network_info = [_VIF]
|
||||
block_device_info = mock.Mock()
|
||||
virtapi = manager.ComputeVirtAPI(mock.MagicMock())
|
||||
|
@ -436,7 +442,7 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
lxdcore_exceptions.LXDAPIException,
|
||||
lxd_driver.spawn,
|
||||
ctx, instance, image_meta, injected_files, admin_password,
|
||||
network_info, block_device_info)
|
||||
allocations, network_info, block_device_info)
|
||||
lxd_driver.cleanup.assert_called_once_with(
|
||||
ctx, instance, network_info, block_device_info)
|
||||
|
||||
|
@ -483,13 +489,14 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
image_meta = mock.Mock()
|
||||
injected_files = mock.Mock()
|
||||
admin_password = mock.Mock()
|
||||
allocations = mock.Mock()
|
||||
network_info = [_VIF]
|
||||
block_device_info = mock.Mock()
|
||||
|
||||
drv.init_host(None)
|
||||
drv.spawn(
|
||||
ctx, instance, image_meta, injected_files, admin_password,
|
||||
network_info, block_device_info)
|
||||
allocations, network_info, block_device_info)
|
||||
|
||||
test_spawn()
|
||||
|
||||
|
|
|
@ -474,7 +474,8 @@ class LXDDriver(driver.ComputeDriver):
|
|||
return [c.name for c in self.client.containers.all()]
|
||||
|
||||
def spawn(self, context, instance, image_meta, injected_files,
|
||||
admin_password, network_info=None, block_device_info=None):
|
||||
admin_password, allocations, network_info=None,
|
||||
block_device_info=None):
|
||||
"""Create a new lxd container as a nova instance.
|
||||
|
||||
Creating a new container requires a number of steps. First, the
|
||||
|
@ -608,6 +609,10 @@ class LXDDriver(driver.ComputeDriver):
|
|||
if container.status != 'Stopped':
|
||||
container.stop(wait=True)
|
||||
container.delete(wait=True)
|
||||
if (instance.vm_state == vm_states.RESCUED):
|
||||
rescued_container = self.client.containers.get(
|
||||
'%s-rescue' % instance.name)
|
||||
rescued_container.delete(wait=True)
|
||||
except lxd_exceptions.LXDAPIException as e:
|
||||
if e.response.status_code == 404:
|
||||
LOG.warning('Failed to delete instance. '
|
||||
|
|
Loading…
Reference in New Issue