def _get_vol_creation_request(self, num_vols, drive_ix, size=0): volume_params = [] for i in range(num_vols): name = 'name_' + str(i) try: volume_types.create(self.context.elevated(), name, extra_specs={'type': 'vsa_drive', 'drive_name': name, 'drive_type': 'type_' + str(drive_ix), 'drive_size': 1 + 100 * (drive_ix)}) self.created_types_lst.append(name) except exception.VolumeTypeExists: # type is already created pass volume_type = volume_types.get_volume_type_by_name(self.context, name) volume = {'size': size, 'snapshot_id': None, 'name': 'vol_' + str(i), 'description': None, 'volume_type_id': volume_type['id']} volume_params.append(volume) return {'num_volumes': len(volume_params), 'vsa_id': 123, 'volumes': volume_params}
def create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.context'] if not body or body == "": raise exc.HTTPUnprocessableEntity() vol_type = body.get('volume_type', None) if vol_type is None or vol_type == "": raise exc.HTTPUnprocessableEntity() name = vol_type.get('name', None) specs = vol_type.get('extra_specs', {}) if name is None or name == "": raise exc.HTTPUnprocessableEntity() try: volume_types.create(context, name, specs) vol_type = volume_types.get_volume_type_by_name(context, name) except exception.QuotaError as error: self._handle_quota_error(error) except exception.NotFound: raise exc.HTTPNotFound() return {'volume_type': vol_type}
def test_vsa_sched_create_single_volume(self): global scheduled_volume scheduled_volume = {} self._set_service_states(host_num=10, drive_type_start_ix=0, drive_type_num=5, init_num_drives=10, exclude_host_list=['host_0', 'host_1']) prev = self._generate_default_service_states() global global_volume global_volume = {} drive_ix = 2 name = 'name_' + str(drive_ix) volume_types.create(self.context.elevated(), name, extra_specs={'type': 'vsa_drive', 'drive_name': name, 'drive_type': 'type_' + str(drive_ix), 'drive_size': 1 + 100 * (drive_ix)}) self.created_types_lst.append(name) volume_type = volume_types.get_volume_type_by_name(self.context, name) global_volume['volume_type_id'] = volume_type['id'] global_volume['size'] = 0 self.driver.schedule_create_volume(self.context, 123, availability_zone=None) self.assertEqual(scheduled_volume['id'], 123) self.assertEqual(scheduled_volume['host'], 'host_9')
def _create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.context'] authorize(context) if not body or body == "": raise webob.exc.HTTPUnprocessableEntity() vol_type = body.get('volume_type', None) if vol_type is None or vol_type == "": raise webob.exc.HTTPUnprocessableEntity() name = vol_type.get('name', None) specs = vol_type.get('extra_specs', {}) if name is None or name == "": raise webob.exc.HTTPUnprocessableEntity() try: volume_types.create(context, name, specs) vol_type = volume_types.get_volume_type_by_name(context, name) except exception.VolumeTypeExists as err: raise webob.exc.HTTPConflict(explanation=str(err)) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, vol_type)
def setUp(self): super(VsaTestCase, self).setUp() self.stubs = stubout.StubOutForTesting() self.vsa_api = vsa.API() self.flags(quota_volumes=100, quota_gigabytes=10000) self.context = context.get_admin_context() volume_types.create(self.context, 'SATA_500_7200', extra_specs={'type': 'vsa_drive', 'drive_name': 'SATA_500_7200', 'drive_type': 'SATA', 'drive_size': '500', 'drive_rpm': '7200'}) def fake_show_by_name(meh, context, name): if name == 'wrong_image_name': LOG.debug(_("Test: Emulate wrong VSA name. Raise")) raise exception.ImageNotFound return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} self.stubs.Set(nova.image.fake._FakeImageService, 'show_by_name', fake_show_by_name)
def test_volume_type_create_then_purge(self): """Ensure volume types can be created and deleted""" prev_all_vtypes = volume_types.get_all_types(self.ctxt, inactive=1) volume_types.create(self.ctxt, self.vol_type1_name, self.vol_type1_specs) new = volume_types.get_volume_type_by_name(self.ctxt, self.vol_type1_name) for k, v in self.vol_type1_specs.iteritems(): self.assertEqual(v, new['extra_specs'][k], 'one of fields doesnt match') new_all_vtypes = volume_types.get_all_types(self.ctxt, inactive=1) self.assertEqual(len(prev_all_vtypes) + 1, len(new_all_vtypes), 'drive type was not created') volume_types.destroy(self.ctxt, self.vol_type1_name) new_all_vtypes2 = volume_types.get_all_types(self.ctxt, inactive=1) self.assertEqual(len(new_all_vtypes), len(new_all_vtypes2), 'drive type was incorrectly deleted') volume_types.purge(self.ctxt, self.vol_type1_name) new_all_vtypes2 = volume_types.get_all_types(self.ctxt, inactive=1) self.assertEqual(len(new_all_vtypes) - 1, len(new_all_vtypes2), 'drive type was not purged')
def test_volume_type_get_by_id_and_name(self): """Ensure volume types get returns same entry""" volume_types.create(self.ctxt, self.vol_type1_name, self.vol_type1_specs) new = volume_types.get_volume_type_by_name(self.ctxt, self.vol_type1_name) new2 = volume_types.get_volume_type(self.ctxt, new["id"]) self.assertEqual(new, new2)
def test_volume_type_create_then_destroy(self): """Ensure volume types can be created and deleted""" prev_all_vtypes = volume_types.get_all_types(self.ctxt) volume_types.create(self.ctxt, self.vol_type1_name, self.vol_type1_specs) new = volume_types.get_volume_type_by_name(self.ctxt, self.vol_type1_name) LOG.info(_("Given data: %s"), self.vol_type1_specs) LOG.info(_("Result data: %s"), new) for k, v in self.vol_type1_specs.iteritems(): self.assertEqual(v, new['extra_specs'][k], 'one of fields doesnt match') new_all_vtypes = volume_types.get_all_types(self.ctxt) self.assertEqual(len(prev_all_vtypes) + 1, len(new_all_vtypes), 'drive type was not created') volume_types.destroy(self.ctxt, self.vol_type1_name) new_all_vtypes = volume_types.get_all_types(self.ctxt) self.assertEqual(prev_all_vtypes, new_all_vtypes, 'drive type was not deleted')
def test_repeated_vol_types_should_raise_api_error(self): """Ensures that volume duplicates raises ApiError""" new_name = self.vol_type1_name + "dup" volume_types.create(self.ctxt, new_name) volume_types.destroy(self.ctxt, new_name) self.assertRaises( exception.ApiError, volume_types.create, self.ctxt, new_name)
def get_vsa_volume_type(self, context): name = FLAGS.vsa_volume_type_name try: vol_type = volume_types.get_volume_type_by_name(context, name) except exception.NotFound: volume_types.create(context, name, extra_specs=dict(type="vsa_volume")) vol_type = volume_types.get_volume_type_by_name(context, name) return vol_type
def test_volume_type_search_by_extra_spec(self): """Ensure volume types get by extra spec returns correct type""" volume_types.create(self.ctxt, "type1", {"key1": "val1", "key2": "val2"}) volume_types.create(self.ctxt, "type2", {"key2": "val2", "key3": "val3"}) volume_types.create(self.ctxt, "type3", {"key3": "another_value", "key4": "val4"}) vol_types = volume_types.get_all_types(self.ctxt, search_opts={'extra_specs': {"key1": "val1"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 1) self.assertTrue("type1" in vol_types.keys()) self.assertEqual(vol_types['type1']['extra_specs'], {"key1": "val1", "key2": "val2"}) vol_types = volume_types.get_all_types(self.ctxt, search_opts={'extra_specs': {"key2": "val2"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 2) self.assertTrue("type1" in vol_types.keys()) self.assertTrue("type2" in vol_types.keys()) vol_types = volume_types.get_all_types(self.ctxt, search_opts={'extra_specs': {"key3": "val3"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 1) self.assertTrue("type2" in vol_types.keys())
def create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.context'] authorize(context) if not self.is_valid_body(body, 'volume_type'): raise exc.HTTPUnprocessableEntity() vol_type = body['volume_type'] name = vol_type.get('name', None) specs = vol_type.get('extra_specs', {}) if name is None or name == "": raise exc.HTTPUnprocessableEntity() try: volume_types.create(context, name, specs) vol_type = volume_types.get_volume_type_by_name(context, name) except exception.NotFound: raise exc.HTTPNotFound() return {'volume_type': vol_type}
def test_volume_type_search_by_extra_spec_multiple(self): """Ensure volume types get by extra spec returns correct type""" volume_types.create(self.ctxt, "type1", {"key1": "val1", "key2": "val2", "key3": "val3"}) volume_types.create(self.ctxt, "type2", {"key2": "val2", "key3": "val3"}) volume_types.create(self.ctxt, "type3", {"key1": "val1", "key3": "val3", "key4": "val4"}) vol_types = volume_types.get_all_types(self.ctxt, search_opts={"extra_specs": {"key1": "val1", "key3": "val3"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 2) self.assertTrue("type1" in vol_types.keys()) self.assertTrue("type3" in vol_types.keys()) self.assertEqual(vol_types["type1"]["extra_specs"], {"key1": "val1", "key2": "val2", "key3": "val3"}) self.assertEqual(vol_types["type3"]["extra_specs"], {"key1": "val1", "key3": "val3", "key4": "val4"})
def test_volume_type_search_by_extra_spec(self): """Ensure volume types get by extra spec returns correct type""" volume_types.create(self.ctxt, "type1", { "key1": "val1", "key2": "val2" }) volume_types.create(self.ctxt, "type2", { "key2": "val2", "key3": "val3" }) volume_types.create(self.ctxt, "type3", { "key3": "another_value", "key4": "val4" }) vol_types = volume_types.get_all_types( self.ctxt, search_opts={'extra_specs': { "key1": "val1" }}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 1) self.assertTrue("type1" in vol_types.keys()) self.assertEqual(vol_types['type1']['extra_specs'], { "key1": "val1", "key2": "val2" }) vol_types = volume_types.get_all_types( self.ctxt, search_opts={'extra_specs': { "key2": "val2" }}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 2) self.assertTrue("type1" in vol_types.keys()) self.assertTrue("type2" in vol_types.keys()) vol_types = volume_types.get_all_types( self.ctxt, search_opts={'extra_specs': { "key3": "val3" }}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 1) self.assertTrue("type2" in vol_types.keys())
def test_repeated_vol_types_shouldnt_raise(self): """Ensures that volume duplicates don't raise""" new_name = self.vol_type1_name + "dup" volume_types.create(self.ctxt, new_name) volume_types.destroy(self.ctxt, new_name) volume_types.create(self.ctxt, new_name)