Exemplo n.º 1
0
    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'])
Exemplo n.º 2
0
    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'], {})
Exemplo n.º 4
0
 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'], {})
Exemplo n.º 5
0
    def test_instance_type_get_by_flavor_id_with_extra_specs(self):
        instance_type = db.flavor_get_by_flavor_id(self.context, 105)
        self.assertEquals(
            instance_type['extra_specs'],
            dict(cpu_arch="x86_64",
                 cpu_model="Nehalem",
                 xpu_arch="fermi",
                 xpus="2",
                 xpu_model="Tesla 2050"))

        instance_type = db.flavor_get_by_flavor_id(self.context, 2)
        self.assertEquals(instance_type['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.assertEquals(instance_type['extra_specs'],
                          dict(cpu_arch="x86_64",
                               cpu_model="Nehalem",
                               xpu_arch="fermi",
                               xpus="2",
                               xpu_model="Tesla 2050"))

        instance_type = db.flavor_get_by_flavor_id(
                            self.context,
                            2)
        self.assertEquals(instance_type['extra_specs'], {})
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 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'])
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
Arquivo: flavor.py Projeto: sapcc/nova
 def get_by_flavor_id(cls, context, flavor_id, read_deleted=None):
     try:
         db_flavor = cls._flavor_get_by_flavor_id_from_db(context,
                                                          flavor_id)
     except exception.FlavorNotFound:
         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'])
Exemplo n.º 11
0
def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
    """Retrieve flavor by flavorid.

    :raises: FlavorNotFound
    """
    if ctxt is None:
        ctxt = context.get_admin_context(read_deleted=read_deleted)

    return db.flavor_get_by_flavor_id(ctxt, flavorid, read_deleted)
Exemplo n.º 12
0
def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
    """Retrieve flavor by flavorid.

    :raises: FlavorNotFound
    """
    if ctxt is None:
        ctxt = context.get_admin_context(read_deleted=read_deleted)

    return db.flavor_get_by_flavor_id(ctxt, flavorid, read_deleted)
Exemplo n.º 13
0
 def get_by_flavor_id(cls, context, flavor_id, read_deleted=None):
     try:
         db_flavor = cls._flavor_get_by_flavor_id_from_db(context,
                                                          flavor_id)
     except exception.FlavorNotFound:
         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'])
Exemplo n.º 14
0
def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
    """Retrieve flavor by flavorid.

    :raises: FlavorNotFound
    """
    if ctxt is None:
        ctxt = context.get_admin_context(read_deleted=read_deleted)

    # NOTE(melwitt): return a copy temporarily until conversion to object
    return dict(db.flavor_get_by_flavor_id(ctxt, flavorid, read_deleted))
Exemplo n.º 15
0
def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
    """Retrieve flavor by flavorid.

    :raises: FlavorNotFound
    """
    if ctxt is None:
        ctxt = context.get_admin_context(read_deleted=read_deleted)

    # NOTE(melwitt): return a copy temporarily until conversion to object
    return dict(db.flavor_get_by_flavor_id(ctxt, flavorid, read_deleted))
Exemplo n.º 16
0
    def test_flavor_manage_func(self):
        ctx = context.get_admin_context()
        flav1 = {
            'flavor': rand_flavor(),
        }

        # Create flavor and ensure it made it to the database
        resp = self.api.api_post('flavors', flav1)

        flav1db = db.flavor_get_by_flavor_id(ctx, flav1['flavor']['id'])
        self.assertFlavorDbEqual(flav1['flavor'], flav1db)

        # Delete flavor and ensure it was removed from the database
        resp = self.api.api_request('flavors/%s' % flav1['flavor']['id'],
                                    method='DELETE')
        self.assertRaises(ex.FlavorNotFound, db.flavor_get_by_flavor_id, ctx,
                          flav1['flavor']['id'])

        resp = self.api.api_request('flavors/%s' % flav1['flavor']['id'],
                                    method='DELETE')
        self.assertEqual(404, resp.status_code)
Exemplo n.º 17
0
 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(), db_flavor,
                                expected_attrs=['extra_specs'])