def test_run_attach_detach_volume(self): """Make sure volume can be attached and detached from instance.""" inst = {} inst['image_id'] = 1 inst['reservation_id'] = 'r-fakeres' inst['launch_time'] = '10' inst['user_id'] = 'fake' inst['project_id'] = 'fake' inst['instance_type_id'] = '2' # m1.tiny inst['ami_launch_index'] = 0 instance = db.instance_create(self.context, {}) instance_id = instance['id'] instance_uuid = instance['uuid'] mountpoint = "/dev/sdf" volume = self._create_volume() volume_id = volume['id'] self.volume.create_volume(self.context, volume_id) if FLAGS.fake_tests: db.volume_attached(self.context, volume_id, instance_uuid, mountpoint) else: self.compute.attach_volume(self.context, instance_uuid, volume_id, mountpoint) vol = db.volume_get(context.get_admin_context(), volume_id) self.assertEqual(vol['status'], "in-use") self.assertEqual(vol['attach_status'], "attached") self.assertEqual(vol['mountpoint'], mountpoint) self.assertEqual(vol['instance_uuid'], instance_uuid) self.assertNotEqual(vol['attach_time'], None) self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, volume_id) if FLAGS.fake_tests: db.volume_detached(self.context, volume_id) else: self.compute.detach_volume(self.context, instance_uuid, volume_id) vol = db.volume_get(self.context, volume_id) self.assertEqual(vol['status'], "available") self.assertEqual(vol['attach_time'], None) self.volume.delete_volume(self.context, volume_id) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, volume_id) db.instance_destroy(self.context, instance_uuid)
def test_live_migration_raises_exception(self): """Confirms recover method is called when exceptions are raised.""" # Skip if non-libvirt environment if not self.lazy_load_library_exists(): return # Preparing data self.compute = utils.import_object(FLAGS.compute_manager) instance_dict = { 'host': 'fake', 'state': power_state.RUNNING, 'state_description': 'running' } instance_ref = db.instance_create(self.context, self.test_instance) instance_ref = db.instance_update(self.context, instance_ref['id'], instance_dict) vol_dict = {'status': 'migrating', 'size': 1} volume_ref = db.volume_create(self.context, vol_dict) db.volume_attached(self.context, volume_ref['id'], instance_ref['id'], '/dev/fake') # Preparing mocks vdmock = self.mox.CreateMock(libvirt.virDomain) self.mox.StubOutWithMock(vdmock, "migrateToURI") vdmock.migrateToURI(FLAGS.live_migration_uri % 'dest', mox.IgnoreArg(), None, FLAGS.live_migration_bandwidth).\ AndRaise(libvirt.libvirtError('ERR')) def fake_lookup(instance_name): if instance_name == instance_ref.name: return vdmock self.create_fake_libvirt_mock(lookupByName=fake_lookup) # Start test self.mox.ReplayAll() conn = libvirt_conn.LibvirtConnection(False) self.assertRaises(libvirt.libvirtError, conn._live_migration, self.context, instance_ref, 'dest', '', self.compute.recover_live_migration) instance_ref = db.instance_get(self.context, instance_ref['id']) self.assertTrue(instance_ref['state_description'] == 'running') self.assertTrue(instance_ref['state'] == power_state.RUNNING) volume_ref = db.volume_get(self.context, volume_ref['id']) self.assertTrue(volume_ref['status'] == 'in-use') db.volume_destroy(self.context, volume_ref['id']) db.instance_destroy(self.context, instance_ref['id'])
def test_run_attach_detach_volume(self): """Make sure volume can be attached and detached from instance.""" inst = {} inst['image_id'] = 1 inst['reservation_id'] = 'r-fakeres' inst['launch_time'] = '10' inst['user_id'] = 'fake' inst['project_id'] = 'fake' inst['instance_type'] = 'm1.tiny' inst['mac_address'] = utils.generate_mac() inst['ami_launch_index'] = 0 instance_id = db.instance_create(self.context, inst)['id'] mountpoint = "/dev/sdf" volume_id = self._create_volume() self.volume.create_volume(self.context, volume_id) if FLAGS.fake_tests: db.volume_attached(self.context, volume_id, instance_id, mountpoint) else: self.compute.attach_volume(self.context, instance_id, volume_id, mountpoint) vol = db.volume_get(context.get_admin_context(), volume_id) self.assertEqual(vol['status'], "in-use") self.assertEqual(vol['attach_status'], "attached") self.assertEqual(vol['mountpoint'], mountpoint) instance_ref = db.volume_get_instance(self.context, volume_id) self.assertEqual(instance_ref['id'], instance_id) self.assertRaises(exception.Error, self.volume.delete_volume, self.context, volume_id) if FLAGS.fake_tests: db.volume_detached(self.context, volume_id) else: self.compute.detach_volume(self.context, instance_id, volume_id) vol = db.volume_get(self.context, volume_id) self.assertEqual(vol['status'], "available") self.volume.delete_volume(self.context, volume_id) self.assertRaises(exception.Error, db.volume_get, self.context, volume_id) db.instance_destroy(self.context, instance_id)
def test_live_migration_raises_exception(self): """Confirms recover method is called when exceptions are raised.""" # Skip if non-libvirt environment if not self.lazy_load_library_exists(): return # Preparing data self.compute = utils.import_object(FLAGS.compute_manager) instance_dict = {'host': 'fake', 'state': power_state.RUNNING, 'state_description': 'running'} instance_ref = db.instance_create(self.context, self.test_instance) instance_ref = db.instance_update(self.context, instance_ref['id'], instance_dict) vol_dict = {'status': 'migrating', 'size': 1} volume_ref = db.volume_create(self.context, vol_dict) db.volume_attached(self.context, volume_ref['id'], instance_ref['id'], '/dev/fake') # Preparing mocks vdmock = self.mox.CreateMock(libvirt.virDomain) self.mox.StubOutWithMock(vdmock, "migrateToURI") vdmock.migrateToURI(FLAGS.live_migration_uri % 'dest', mox.IgnoreArg(), None, FLAGS.live_migration_bandwidth).\ AndRaise(libvirt.libvirtError('ERR')) def fake_lookup(instance_name): if instance_name == instance_ref.name: return vdmock self.create_fake_libvirt_mock(lookupByName=fake_lookup) # Start test self.mox.ReplayAll() conn = libvirt_conn.LibvirtConnection(False) self.assertRaises(libvirt.libvirtError, conn._live_migration, self.context, instance_ref, 'dest', '', self.compute.recover_live_migration) instance_ref = db.instance_get(self.context, instance_ref['id']) self.assertTrue(instance_ref['state_description'] == 'running') self.assertTrue(instance_ref['state'] == power_state.RUNNING) volume_ref = db.volume_get(self.context, volume_ref['id']) self.assertTrue(volume_ref['status'] == 'in-use') db.volume_destroy(self.context, volume_ref['id']) db.instance_destroy(self.context, instance_ref['id'])
def _attach_volume(self): """Attach volumes to an instance. """ volume_id_list = [] for index in xrange(3): vol = {} vol["size"] = 0 vol_ref = db.volume_create(self.context, vol) self.volume.create_volume(self.context, vol_ref["id"]) vol_ref = db.volume_get(self.context, vol_ref["id"]) # each volume has a different mountpoint mountpoint = "/dev/sd" + chr((ord("b") + index)) db.volume_attached(self.context, vol_ref["id"], self.instance_uuid, mountpoint) volume_id_list.append(vol_ref["id"]) return volume_id_list
def _attach_volume(self): """Attach volumes to an instance. """ volume_id_list = [] for index in xrange(3): vol = {} vol['size'] = 0 vol_ref = db.volume_create(self.context, vol) self.volume.create_volume(self.context, vol_ref['id']) vol_ref = db.volume_get(self.context, vol_ref['id']) # each volume has a different mountpoint mountpoint = "/dev/sd" + chr((ord('b') + index)) db.volume_attached(self.context, vol_ref['id'], self.instance_uuid, mountpoint) volume_id_list.append(vol_ref['id']) return volume_id_list
def _attach_volume(self): """Attach volumes to an instance. This function also sets a fake log message.""" volume_id_list = [] for index in xrange(3): vol = {} vol['size'] = 0 vol_ref = db.volume_create(self.context, vol) self.volume.create_volume(self.context, vol_ref['id']) vol_ref = db.volume_get(self.context, vol_ref['id']) # each volume has a different mountpoint mountpoint = "/dev/sd" + chr((ord('b') + index)) db.volume_attached(self.context, vol_ref['id'], self.instance_id, mountpoint) volume_id_list.append(vol_ref['id']) return volume_id_list
def test_create_snapshot_force(self): """Test snapshot in use can be created forcibly.""" def fake_cast(ctxt, topic, msg): pass self.stubs.Set(rpc, 'cast', fake_cast) volume_id = self._create_volume() self.volume.create_volume(self.context, volume_id) db.volume_attached(self.context, volume_id, self.instance_id, '/dev/sda1') volume_api = volume.api.API() self.assertRaises(exception.ApiError, volume_api.create_snapshot, self.context, volume_id, 'fake_name', 'fake_description') snapshot_ref = volume_api.create_snapshot_force( self.context, volume_id, 'fake_name', 'fake_description') db.snapshot_destroy(self.context, snapshot_ref['id']) db.volume_destroy(self.context, volume_id)
def test_create_snapshot_force(self): """Test snapshot in use can be created forcibly.""" def fake_cast(ctxt, topic, msg): pass self.stubs.Set(rpc, "cast", fake_cast) volume = self._create_volume() self.volume.create_volume(self.context, volume["id"]) db.volume_attached(self.context, volume["id"], self.instance_uuid, "/dev/sda1") volume_api = nova.volume.api.API() volume = volume_api.get(self.context, volume["id"]) self.assertRaises( exception.InvalidVolume, volume_api.create_snapshot, self.context, volume, "fake_name", "fake_description" ) snapshot_ref = volume_api.create_snapshot_force(self.context, volume, "fake_name", "fake_description") db.snapshot_destroy(self.context, snapshot_ref["id"]) db.volume_destroy(self.context, volume["id"])
def test_run_attach_detach_volume(self): """Make sure volume can be attached and detached from instance.""" inst = {} inst["image_id"] = 1 inst["reservation_id"] = "r-fakeres" inst["launch_time"] = "10" inst["user_id"] = "fake" inst["project_id"] = "fake" inst["instance_type_id"] = "2" # m1.tiny inst["ami_launch_index"] = 0 instance = db.instance_create(self.context, {}) instance_id = instance["id"] instance_uuid = instance["uuid"] mountpoint = "/dev/sdf" volume = self._create_volume() volume_id = volume["id"] self.volume.create_volume(self.context, volume_id) if FLAGS.fake_tests: db.volume_attached(self.context, volume_id, instance_uuid, mountpoint) else: self.compute.attach_volume(self.context, instance_uuid, volume_id, mountpoint) vol = db.volume_get(context.get_admin_context(), volume_id) self.assertEqual(vol["status"], "in-use") self.assertEqual(vol["attach_status"], "attached") self.assertEqual(vol["mountpoint"], mountpoint) self.assertEqual(vol["instance_uuid"], instance_uuid) self.assertRaises(exception.NovaException, self.volume.delete_volume, self.context, volume_id) if FLAGS.fake_tests: db.volume_detached(self.context, volume_id) else: self.compute.detach_volume(self.context, instance_uuid, volume_id) vol = db.volume_get(self.context, volume_id) self.assertEqual(vol["status"], "available") self.volume.delete_volume(self.context, volume_id) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, volume_id) db.instance_destroy(self.context, instance_id)
def test_create_snapshot_force(self): """Test snapshot in use can be created forcibly.""" def fake_cast(ctxt, topic, msg): pass self.stubs.Set(rpc, 'cast', fake_cast) volume_id = self._create_volume() self.volume.create_volume(self.context, volume_id) db.volume_attached(self.context, volume_id, self.instance_id, '/dev/sda1') volume_api = volume.api.API() self.assertRaises(exception.ApiError, volume_api.create_snapshot, self.context, volume_id, 'fake_name', 'fake_description') snapshot_ref = volume_api.create_snapshot_force(self.context, volume_id, 'fake_name', 'fake_description') db.snapshot_destroy(self.context, snapshot_ref['id']) db.volume_destroy(self.context, volume_id)
def _attach_volume(self): """Attach volumes to an instance. This function also sets a fake log message.""" volume_id_list = [] for index in xrange(3): vol = {} vol['size'] = 0 volume_id = db.volume_create(self.context, vol)['id'] self.volume.create_volume(self.context, volume_id) # each volume has a different mountpoint mountpoint = "/dev/sd" + chr((ord('b') + index)) db.volume_attached(self.context, volume_id, self.instance_id, mountpoint) (shelf_id, blade_id) = db.volume_get_shelf_and_blade(self.context, volume_id) self.output += "%s %s eth0 /dev/nova-volumes/vol-foo auto run\n" \ % (shelf_id, blade_id) volume_id_list.append(volume_id) return volume_id_list