def test_flavor_manage_permissions(self): """Ensure that regular users can't create or delete flavors. """ ctx = context.get_admin_context() flav1 = {'flavor': rand_flavor()} # Ensure user can't create flavor resp = self.user_api.api_post('flavors', flav1, check_response_status=False) self.assertEqual(403, resp.status) # ... and that it didn't leak through self.assertRaises(ex.FlavorNotFound, db.flavor_get_by_flavor_id, ctx, flav1['flavor']['id']) # Create the flavor as the admin user self.api.api_post('flavors', flav1) # Ensure user can't delete flavors from our cloud resp = self.user_api.api_delete('flavors/%s' % flav1['flavor']['id'], check_response_status=False) self.assertEqual(403, resp.status) # ... and ensure that we didn't actually delete the flavor, # this will throw an exception if we did. db.flavor_get_by_flavor_id(ctx, flav1['flavor']['id'])
def test_instance_type_get_by_flavor_id_with_extra_specs(self): instance_type = db.flavor_get_by_flavor_id( self.context, 105) self.assertEqual(instance_type['extra_specs'], self.specs) instance_type = db.flavor_get_by_flavor_id( self.context, 2) self.assertEqual(instance_type['extra_specs'], {})
def test_flavor_manage_func(self): """Basic flavor creation lifecycle testing. - Creating a flavor - Ensure it's in the database - Ensure it's in the listing - Delete it - Ensure it's hidden in the database """ ctx = context.get_admin_context() flav1 = { 'flavor': rand_flavor(), } # Create flavor and ensure it made it to the database self.api.api_post('flavors', flav1) flav1db = db.flavor_get_by_flavor_id(ctx, flav1['flavor']['id']) self.assertFlavorDbEqual(flav1['flavor'], flav1db) # Ensure new flavor is seen in the listing resp = self.api.api_get('flavors') self.assertFlavorInList(flav1['flavor'], resp.body) # Delete flavor and ensure it was removed from the database self.api.api_delete('flavors/%s' % flav1['flavor']['id']) self.assertRaises(ex.FlavorNotFound, db.flavor_get_by_flavor_id, ctx, flav1['flavor']['id']) resp = self.api.api_delete('flavors/%s' % flav1['flavor']['id'], check_response_status=False) self.assertEqual(404, resp.status)
def get_by_flavor_id(cls, context, flavor_id, read_deleted=None): db_flavor = db.flavor_get_by_flavor_id(context, flavor_id, read_deleted) return cls._from_db_object(context, cls(context), db_flavor, expected_attrs=['extra_specs'])
def test_instance_type_get_by_flavor_id_with_extra_specs(self): instance_type = db.flavor_get_by_flavor_id(self.context, 105) self.assertEqual(instance_type['extra_specs'], self.specs) instance_type = db.flavor_get_by_flavor_id(self.context, 2) self.assertEqual(instance_type['extra_specs'], {})