From cf8b2a2026cf8606de0f9474bd2e1563d662b4ab Mon Sep 17 00:00:00 2001 From: Renuka Apte Date: Mon, 30 Jul 2012 14:56:24 -0700 Subject: xenapi: Tag nova volumes during attach_volume 1. Set other_config:'osvol':'True' on VBD during attach. 2. Use this (instead of nodestroys list) to determine which volumes should not be destroyed on instance terminate. 3. Ensure that the SRs for the attached volumes are forgotten when instance is terminated. In the virt/xenapi layer, there is no way to determine which of the VDIs are nova volumes. This information is required when terminating and instance, to ensure the volumes are kept intact, as well as other operations like migrate. Fixes bug 1030143. Change-Id: Id1717e64bc29092ce9ffe13b7c254a3867fe8342 --- nova/tests/compute/test_compute.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index b6d775bd2..079547a74 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -365,6 +365,41 @@ class ComputeTestCase(BaseTestCase): LOG.info(_("After terminating instances: %s"), instances) self.assertEqual(len(instances), 0) + def test_run_terminate_with_vol_attached(self): + """Make sure it is possible to run and terminate instance with volume + attached + """ + instance = jsonutils.to_primitive(self._create_fake_instance()) + + self.compute.run_instance(self.context, instance=instance) + + instances = db.instance_get_all(context.get_admin_context()) + LOG.info(_("Running instances: %s"), instances) + self.assertEqual(len(instances), 1) + + def fake_check_attach(*args, **kwargs): + pass + + def fake_reserve_volume(*args, **kwargs): + pass + + def fake_volume_get(self, context, volume_id): + return {'id': volume_id} + + self.stubs.Set(nova.volume.api.API, 'get', fake_volume_get) + self.stubs.Set(nova.volume.api.API, 'check_attach', fake_check_attach) + self.stubs.Set(nova.volume.api.API, 'reserve_volume', + fake_reserve_volume) + + self.compute_api.attach_volume(self.context, instance, 1, + '/dev/vdc') + + self.compute.terminate_instance(self.context, instance=instance) + + instances = db.instance_get_all(context.get_admin_context()) + LOG.info(_("After terminating instances: %s"), instances) + self.assertEqual(len(instances), 0) + def test_terminate_no_network(self): # This is as reported in LP bug 1008875 instance = jsonutils.to_primitive(self._create_fake_instance()) -- cgit