def cleanup(self, context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None, destroy_vifs=True): """Clean up the filesystem around the container. See `nova.virt.driver.ComputeDriver.cleanup` for more information. """ if destroy_vifs: self.unplug_vifs(instance, network_info) self.firewall_driver.unfilter_instance(instance, network_info) lxd_config = self.client.host_info storage.detach_ephemeral(block_device_info, lxd_config, instance) name = pwd.getpwuid(os.getuid()).pw_name container_dir = common.InstanceAttributes(instance).instance_dir if os.path.exists(container_dir): utils.execute( 'chown', '-R', '{}:{}'.format(name, name), container_dir, run_as_root=True) shutil.rmtree(container_dir) try: self.client.profiles.get(instance.name).delete() except lxd_exceptions.LXDAPIException as e: if e.response.status_code == 404: LOG.warning('Failed to delete instance. ' 'Profile does not exist for %(instance)s.', {'instance': instance.name}) else: raise
def test_remove_ephemeral_with_zfs(self, block_device_info_get_ephemerals, execute): block_device_info_get_ephemerals.return_value = [{ 'virtual_name': 'ephemerals0' }] ctx = context.get_admin_context() instance = fake_instance.fake_instance_obj(ctx, name='test', memory_mb=0) block_device_info = mock.Mock() lxd_config = { 'environment': { 'storage': 'zfs' }, 'config': { 'storage.zfs_pool_name': 'zfs' } } client = mock.Mock() storage.detach_ephemeral(client, block_device_info, lxd_config, instance) block_device_info_get_ephemerals.assert_called_once_with( block_device_info) expected_calls = [ mock.call('zfs', 'destroy', 'zfs/instance-00000001-ephemeral', run_as_root=True) ] self.assertEqual(expected_calls, execute.call_args_list)
def test_remove_ephemeral_with_lvm( self, block_device_info_get_ephemerals, execute): block_device_info_get_ephemerals.return_value = [ {'virtual_name': 'ephemerals0'}] ctx = context.get_admin_context() instance = fake_instance.fake_instance_obj( ctx, name='test', memory_mb=0) block_device_info = mock.Mock() lxd_config = {'environment': {'storage': 'lvm'}, 'config': {'storage.lvm_vg_name': 'lxd'}} client = mock.Mock() storage.detach_ephemeral( client, block_device_info, lxd_config, instance) block_device_info_get_ephemerals.assert_called_once_with( block_device_info) expected_calls = [ mock.call( 'umount', '/dev/lxd/instance-00000001-ephemerals0', run_as_root=True), mock.call('lvremove', '-f', '/dev/lxd/instance-00000001-ephemerals0', run_as_root=True) ] self.assertEqual(expected_calls, execute.call_args_list)
def test_remove_ephemeral_with_lvm(self, block_device_info_get_ephemerals, execute): block_device_info_get_ephemerals.return_value = [{ 'virtual_name': 'ephemerals0' }] ctx = context.get_admin_context() instance = fake_instance.fake_instance_obj(ctx, name='test', memory_mb=0) block_device_info = mock.Mock() lxd_config = { 'environment': { 'storage': 'lvm' }, 'config': { 'storage.lvm_vg_name': 'lxd' } } storage.detach_ephemeral(block_device_info, lxd_config, instance) block_device_info_get_ephemerals.assert_called_once_with( block_device_info) expected_calls = [ mock.call('umount', '/dev/lxd/instance-00000001-ephemerals0', run_as_root=True), mock.call('lvremove', '-f', '/dev/lxd/instance-00000001-ephemerals0', run_as_root=True) ] self.assertEqual(expected_calls, execute.call_args_list)