def _delete(self, req, id): context = req.environ['patron.context'] authorize(context) try: flavor = flavors.get_flavor_by_flavor_id( id, ctxt=context, read_deleted="no") except exception.FlavorNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) flavors.destroy(flavor['name'])
def _delete(self, req, id): context = req.environ['patron.context'] authorize(context) try: flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context, read_deleted="no") except exception.FlavorNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) flavors.destroy(flavor['name'])
def test_get_inactive_flavors_with_same_flavorid(self): flav1 = flavors.create('flavor', 256, 1, 120, 100, "flavid") flavors.destroy('flavor') flav2 = flavors.create('flavor', 512, 4, 250, 100, "flavid") returned_flavors_ids = flavors.get_all_flavors().keys() self.assertNotIn(flav1.id, returned_flavors_ids) self.assertIn(flav2.id, returned_flavors_ids) returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys() self.assertIn(flav1.id, returned_flavors_ids) self.assertIn(flav2.id, returned_flavors_ids)
def test_get_inactive_flavors(self): flav1 = flavors.create('flavor1', 256, 1, 120) flav2 = flavors.create('flavor2', 512, 4, 250) flavors.destroy('flavor1') returned_flavors_ids = flavors.get_all_flavors().keys() self.assertNotIn(flav1.id, returned_flavors_ids) self.assertIn(flav2.id, returned_flavors_ids) returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys() self.assertIn(flav1.id, returned_flavors_ids) self.assertIn(flav2.id, returned_flavors_ids)
def test_read_deleted_false_converting_flavorid(self): """Ensure deleted flavors are not returned when not needed (for example when creating a server and attempting to translate from flavorid to instance_type_id. """ flavors.create("instance_type1", 256, 1, 120, 100, "test1") flavors.destroy("instance_type1") flavors.create("instance_type1_redo", 256, 1, 120, 100, "test1") instance_type = flavors.get_flavor_by_flavor_id( "test1", read_deleted="no") self.assertEqual("instance_type1_redo", instance_type.name)
def test_can_read_deleted_types_using_flavor_id(self): # Ensure deleted flavors can be read when querying flavor_id. inst_type_name = "test" inst_type_flavor_id = "test1" inst_type = flavors.create(inst_type_name, 256, 1, 120, 100, inst_type_flavor_id) self.assertEqual(inst_type_name, inst_type.name) # NOTE(jk0): The deleted flavor will show up here because the context # in get_flavor_by_flavor_id() is set to use read_deleted by # default. flavors.destroy(inst_type.name) deleted_inst_type = flavors.get_flavor_by_flavor_id( inst_type_flavor_id) self.assertEqual(inst_type_name, deleted_inst_type.name)
def test_create_then_delete(self): original_list = flavors.get_all_flavors() flavor = flavors.create('flavor', 64, 1, 120) # Ensure new type shows up in list new_list = flavors.get_all_flavors() self.assertNotEqual(len(original_list), len(new_list), 'instance type was not created') flavors.destroy('flavor') self.assertRaises(exception.FlavorNotFound, flavors.get_flavor, flavor.id) # Deleted instance should not be in list anymore new_list = flavors.get_all_flavors() self.assertEqual(len(original_list), len(new_list)) for k in original_list.keys(): f = original_list[k] self.assertIsInstance(f, objects.Flavor) self.assertEqual(f.flavorid, new_list[k].flavorid)