Exemple #1
0
    def test_instance_type_create_then_delete(self):
        # Ensure instance types can be created.
        name = "Small Flavor"
        flavorid = "flavor1"

        original_list = flavors.get_all_types()

        # create new type and make sure values stick
        inst_type = flavors.create(name, 256, 1, 120, 100, flavorid)
        inst_type_id = inst_type["id"]
        self.assertEqual(inst_type["flavorid"], flavorid)
        self.assertEqual(inst_type["name"], name)
        self.assertEqual(inst_type["memory_mb"], 256)
        self.assertEqual(inst_type["vcpus"], 1)
        self.assertEqual(inst_type["root_gb"], 120)
        self.assertEqual(inst_type["ephemeral_gb"], 100)
        self.assertEqual(inst_type["swap"], 0)
        self.assertEqual(inst_type["rxtx_factor"], 1.0)

        # make sure new type shows up in list
        new_list = flavors.get_all_types()
        self.assertNotEqual(len(original_list), len(new_list), "instance type was not created")

        flavors.destroy(name)
        self.assertRaises(exception.InstanceTypeNotFound, flavors.get_instance_type, inst_type_id)

        # deleted instance should not be in list anymoer
        new_list = flavors.get_all_types()
        self.assertEqual(original_list, new_list)
    def _delete(self, req, id):
        context = req.environ["nova.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"])
Exemple #3
0
    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 _delete(self, req, id):
        context = req.environ['nova.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'])
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    def test_get_inactive_flavors_with_same_name(self):
        flav1 = flavors.create('flavor', 256, 1, 120)
        flavors.destroy('flavor')
        flav2 = flavors.create('flavor', 512, 4, 250)

        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)
Exemple #8
0
    def _delete(self, req, id):
        context = req.environ['nova.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'])

        return webob.Response(status_int=202)
Exemple #9
0
    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)
Exemple #10
0
    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)
Exemple #11
0
    def test_get_inactive_flavors_with_same_name(self):
        flav1 = flavors.create('flavor', 256, 1, 120)
        flavors.destroy('flavor')
        flav2 = flavors.create('flavor', 512, 4, 250)

        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)
Exemple #12
0
    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)
Exemple #13
0
    def test_get_inactive_flavors_with_same_name(self):
        flavors.create('flavor1', 256, 1, 120, 100, "test_id1")
        flavors.destroy('flavor1')
        flavors.create('flavor1', 512, 4, 250, 100, "test_id2")

        returned_flavors_ids = flavors.get_all_flavors().keys()
        self.assertNotIn('test_id1', returned_flavors_ids)
        self.assertIn('test_id2', returned_flavors_ids)

        returned_flavors_ids = flavors.get_all_flavors(inactive=True).keys()
        self.assertIn('test_id1', returned_flavors_ids)
        self.assertIn('test_id2', returned_flavors_ids)
Exemple #14
0
    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)
Exemple #15
0
    def _delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)

        try:
            flavor = flavors.get_instance_type_by_flavor_id(
                    id, read_deleted="no")
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        flavors.destroy(flavor['name'])

        return webob.Response(status_int=202)
Exemple #16
0
    def test_can_read_deleted_types_using_flavor_id(self):
        # Ensure deleted instance types 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_instance_type_by_flavor_id() is set to use read_deleted by
        # default.
        flavors.destroy(inst_type["name"])
        deleted_inst_type = flavors.get_instance_type_by_flavor_id(inst_type_flavor_id)
        self.assertEqual(inst_type_name, deleted_inst_type["name"])
Exemple #17
0
 def delete(self, name):
     """Marks instance types / flavors as deleted."""
     try:
         flavors.destroy(name)
     except exception.InstanceTypeNotFound:
         print _("Valid instance type name is required")
         return 1
     except db_exc.DBError as e:
         print _("DB Error: %s") % e
         return 2
     except Exception:
         return 3
     else:
         print _("%s deleted") % name
Exemple #18
0
    def test_create_then_delete(self):
        original_list = flavors.get_all_types()

        flavor = flavors.create("flavor", 64, 1, 120)

        # Ensure new type shows up in list
        new_list = flavors.get_all_types()
        self.assertNotEqual(len(original_list), len(new_list), "instance type was not created")

        flavors.destroy("flavor")
        self.assertRaises(exception.InstanceTypeNotFound, flavors.get_instance_type, flavor["id"])

        # Deleted instance should not be in list anymore
        new_list = flavors.get_all_types()
        self.assertEqual(original_list, new_list)
Exemple #19
0
    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 _delete(self, req, id):
        context = req.environ['nova.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'])

        # NOTE(oomichi): Return 202 for backwards compatibility but should be
        # 204 as this operation complete the deletion of aggregate resource and
        # return no response body.
        return webob.Response(status_int=202)
Exemple #21
0
    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(original_list, new_list)
Exemple #22
0
    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.InstanceTypeNotFound,
                          flavors.get_flavor, flavor['id'])

        # Deleted instance should not be in list anymore
        new_list = flavors.get_all_flavors()
        self.assertEqual(original_list, new_list)
Exemple #23
0
    def _delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)

        # NOTE(alex_xu): back-compatible with db layer hard-code admin
        # permission checks.
        nova_context.require_admin_context(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'])

        return webob.Response(status_int=202)
Exemple #24
0
    def _delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)

        # NOTE(alex_xu): back-compatible with db layer hard-code admin
        # permission checks.
        nova_context.require_admin_context(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'])

        return webob.Response(status_int=202)
Exemple #25
0
    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)
Exemple #26
0
    def test_create_then_delete(self):
        ctxt = context.get_admin_context()
        original_list = objects.FlavorList.get_all(ctxt)

        flavor = flavors.create('flavor', 64, 1, 120)

        # Ensure new type shows up in list
        new_list = objects.FlavorList.get_all(ctxt)
        self.assertNotEqual(len(original_list), len(new_list),
                            'instance type was not created')

        flavors.destroy('flavor')
        self.assertRaises(exception.FlavorNotFound, objects.Flavor.get_by_id,
                          ctxt, flavor.id)

        # Deleted instance should not be in list anymore
        new_list = objects.FlavorList.get_all(ctxt)
        self.assertEqual(len(original_list), len(new_list))
        for i, f in enumerate(original_list):
            self.assertIsInstance(f, objects.Flavor)
            self.assertEqual(f.flavorid, new_list[i].flavorid)
Exemple #27
0
    def test_create_then_delete(self):
        ctxt = context.get_admin_context()
        original_list = objects.FlavorList.get_all(ctxt)

        flavor = flavors.create('flavor', 64, 1, 120)

        # Ensure new type shows up in list
        new_list = objects.FlavorList.get_all(ctxt)
        self.assertNotEqual(len(original_list), len(new_list),
                            'instance type was not created')

        flavors.destroy('flavor')
        self.assertRaises(exception.FlavorNotFound,
                          objects.Flavor.get_by_id, ctxt, flavor.id)

        # Deleted instance should not be in list anymore
        new_list = objects.FlavorList.get_all(ctxt)
        self.assertEqual(len(original_list), len(new_list))
        for i, f in enumerate(original_list):
            self.assertIsInstance(f, objects.Flavor)
            self.assertEqual(f.flavorid, new_list[i].flavorid)
Exemple #28
0
    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)
Exemple #29
0
class FlavorManageController(wsgi.Controller):
    """
    The Flavor Lifecycle API controller for the OpenStack API.
    """
    _view_builder_class = flavors_view.ViewBuilder

    def __init__(self):
        super(FlavorManageController, self).__init__()

    @wsgi.action("delete")
    def _delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)

        try:
            flavor = flavors.get_instance_type_by_flavor_id(id,
                                                            read_deleted="no")
        except exception.NotFound, e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        flavors.destroy(flavor['name'])

        return webob.Response(status_int=202)