def test_run_attach_detach_volume(self): # Create one volume and one compute to test with instance_id = "storage-test" vol_size = "5" user_id = "fake" project_id = 'fake' mountpoint = "/dev/sdf" volume_id = self.volume.create_volume(vol_size, user_id, project_id) volume_obj = volume_service.get_volume(volume_id) volume_obj.start_attach(instance_id, mountpoint) rv = yield self.compute.attach_volume(volume_id, instance_id, mountpoint) self.assertEqual(volume_obj['status'], "in-use") self.assertEqual(volume_obj['attachStatus'], "attached") self.assertEqual(volume_obj['instance_id'], instance_id) self.assertEqual(volume_obj['mountpoint'], mountpoint) self.assertRaises(exception.Error, self.volume.delete_volume, volume_id) rv = yield self.volume.detach_volume(volume_id) volume_obj = volume_service.get_volume(volume_id) self.assertEqual(volume_obj['status'], "available") rv = self.volume.delete_volume(volume_id) self.assertRaises(exception.Error, volume_service.get_volume, volume_id)
def detach_volume(self, instance_id, volume_id): """ detach a volume from an instance """ # despite the documentation, virsh detach-disk just wants the device # name without the leading /dev/ volume = volume_service.get_volume(volume_id) target = volume['mountpoint'].rpartition('/dev/')[2] yield process.simple_execute( "sudo virsh detach-disk %s %s " % (instance_id, target)) volume.finish_detach() defer.returnValue(True)
def attach_volume(self, instance_id = None, volume_id = None, mountpoint = None): volume = volume_service.get_volume(volume_id) yield self._init_aoe() yield process.simple_execute( "sudo virsh attach-disk %s /dev/etherd/%s %s" % (instance_id, volume['aoe_device'], mountpoint.rpartition('/dev/')[2])) volume.finish_attach() defer.returnValue(True)
def test_run_create_volume(self): vol_size = '0' user_id = 'fake' project_id = 'fake' volume_id = self.volume.create_volume(vol_size, user_id, project_id) # TODO(termie): get_volume returns differently than create_volume self.assertEqual(volume_id, volume_service.get_volume(volume_id)['volume_id']) rv = self.volume.delete_volume(volume_id) self.assertRaises(exception.Error, volume_service.get_volume, volume_id)
def volumes(self): """ returns a list of all volumes """ for volume_id in datastore.Redis.instance().smembers("volumes"): volume = volume_service.get_volume(volume_id) yield volume
def _get_volume(self, context, volume_id): volume = volume_service.get_volume(volume_id) if context.user.is_admin() or volume['project_id'] == context.project.id: return volume raise exception.NotFound('Volume %s could not be found' % volume_id)