Пример #1
0
    def start_fixture(self):
        super(NonSharedStorageFixture, self).start_fixture()
        self.context = context.get_admin_context()

        cn1_uuid = uuidutils.generate_uuid()
        cn2_uuid = uuidutils.generate_uuid()
        aggA_uuid = uuidutils.generate_uuid()
        aggB_uuid = uuidutils.generate_uuid()
        aggC_uuid = uuidutils.generate_uuid()
        os.environ['CN1_UUID'] = cn1_uuid
        os.environ['CN2_UUID'] = cn2_uuid
        os.environ['AGGA_UUID'] = aggA_uuid
        os.environ['AGGB_UUID'] = aggB_uuid
        os.environ['AGGC_UUID'] = aggC_uuid

        cn1 = rp_obj.ResourceProvider(self.context, name='cn1', uuid=cn1_uuid)
        cn1.create()

        cn2 = rp_obj.ResourceProvider(self.context, name='cn2', uuid=cn2_uuid)
        cn2.create()

        # Populate compute node inventory for VCPU and RAM
        for cn in (cn1, cn2):
            vcpu_inv = rp_obj.Inventory(self.context,
                                        resource_provider=cn,
                                        resource_class='VCPU',
                                        total=24,
                                        reserved=0,
                                        max_unit=24,
                                        min_unit=1,
                                        step_size=1,
                                        allocation_ratio=16.0)
            vcpu_inv.obj_set_defaults()
            ram_inv = rp_obj.Inventory(self.context,
                                       resource_provider=cn,
                                       resource_class='MEMORY_MB',
                                       total=128 * 1024,
                                       reserved=0,
                                       max_unit=128 * 1024,
                                       min_unit=256,
                                       step_size=256,
                                       allocation_ratio=1.5)
            ram_inv.obj_set_defaults()
            disk_inv = rp_obj.Inventory(self.context,
                                        resource_provider=cn,
                                        resource_class='DISK_GB',
                                        total=2000,
                                        reserved=100,
                                        max_unit=2000,
                                        min_unit=10,
                                        step_size=10,
                                        allocation_ratio=1.0)
            disk_inv.obj_set_defaults()
            inv_list = rp_obj.InventoryList(
                objects=[vcpu_inv, ram_inv, disk_inv])
            cn.set_inventory(inv_list)
Пример #2
0
 def test_create_in_db_with_parent_provider_uuid(self):
     parent = resource_provider.ResourceProvider(
         self.context, uuid=uuids.parent, name="parent")
     parent.create()
     child = resource_provider.ResourceProvider(
         self.context, uuid=uuids.child, name="child",
         parent_provider_uuid=uuids.parent)
     child.create()
     self.assertEqual(uuids.child, child.uuid)
     self.assertEqual(uuids.parent, child.parent_provider_uuid)
     self.assertEqual(uuids.parent, child.root_provider_uuid)
Пример #3
0
    def test_destroy_with_traits(self):
        """Test deleting a resource provider that has a trait successfully.
        """
        rp = resource_provider.ResourceProvider(self.context,
                                                uuid=uuids.rp,
                                                name='fake_rp1')
        rp.create()
        custom_trait = resource_provider.Trait(self.context,
                                               uuid=uuids.trait,
                                               name='CUSTOM_TRAIT_1')
        custom_trait.create()
        rp.set_traits([custom_trait])

        trl = resource_provider.TraitList.get_all_by_resource_provider(
            self.context, rp)
        self.assertEqual(1, len(trl))

        # Delete a resource provider that has a trait assosiation.
        rp.destroy()

        # Assert the record has been deleted
        # in 'resource_provider_traits' table
        # after Resource Provider object has been destroyed.
        trl = resource_provider.TraitList.get_all_by_resource_provider(
            self.context, rp)
        self.assertEqual(0, len(trl))
        # Assert that NotFound exception is raised.
        self.assertRaises(exception.NotFound,
                          resource_provider.ResourceProvider.get_by_uuid,
                          self.context, uuids.rp)
Пример #4
0
 def test_create_with_id_fails(self):
     rp = resource_provider.ResourceProvider(context=self.context,
                                             uuid=_RESOURCE_PROVIDER_UUID,
                                             name=_RESOURCE_PROVIDER_NAME)
     rp.create()
     inv = resource_provider.Inventory(context=self.context,
                                       resource_provider=rp,
                                       resource_class=_RESOURCE_CLASS_NAME,
                                       total=16,
                                       reserved=2,
                                       min_unit=1,
                                       max_unit=8,
                                       step_size=1,
                                       allocation_ratio=1.0)
     inv_list = resource_provider.InventoryList(context=self.context,
                                                objects=[inv])
     rp.set_inventory(inv_list)
     obj = resource_provider.Allocation(context=self.context,
                                        id=99,
                                        resource_provider=rp,
                                        resource_class=_RESOURCE_CLASS_NAME,
                                        consumer_id=uuids.fake_instance,
                                        used=8)
     alloc_list = resource_provider.AllocationList(self.context,
                                                   objects=[obj])
     self.assertRaises(exception.ObjectActionError, alloc_list.create_all)
Пример #5
0
    def test_find(self):
        rp = resource_provider.ResourceProvider(uuid=uuids.rp_uuid)
        inv_list = resource_provider.InventoryList(objects=[
            resource_provider.Inventory(
                resource_provider=rp,
                resource_class=fields.ResourceClass.VCPU,
                total=24),
            resource_provider.Inventory(
                resource_provider=rp,
                resource_class=fields.ResourceClass.MEMORY_MB,
                total=10240),
        ])

        found = inv_list.find(fields.ResourceClass.MEMORY_MB)
        self.assertIsNotNone(found)
        self.assertEqual(10240, found.total)

        found = inv_list.find(fields.ResourceClass.VCPU)
        self.assertIsNotNone(found)
        self.assertEqual(24, found.total)

        found = inv_list.find(fields.ResourceClass.DISK_GB)
        self.assertIsNone(found)

        # Try an integer resource class identifier...
        self.assertRaises(ValueError, inv_list.find, VCPU_ID)

        # Use an invalid string...
        self.assertIsNone(inv_list.find('HOUSE'))
Пример #6
0
    def test_create(self, mock_ensure_cache):
        rp = resource_provider.ResourceProvider(context=self.context,
                                                uuid=_RESOURCE_PROVIDER_UUID,
                                                name=_RESOURCE_PROVIDER_NAME)
        rp.create()
        inv = resource_provider.Inventory(context=self.context,
                                          resource_provider=rp,
                                          resource_class=_RESOURCE_CLASS_NAME,
                                          total=16,
                                          reserved=2,
                                          min_unit=1,
                                          max_unit=8,
                                          step_size=1,
                                          allocation_ratio=1.0)
        inv_list = resource_provider.InventoryList(context=self.context,
                                                   objects=[inv])
        rp.set_inventory(inv_list)
        obj = resource_provider.Allocation(context=self.context,
                                           resource_provider=rp,
                                           resource_class=_RESOURCE_CLASS_NAME,
                                           consumer_id=uuids.fake_instance,
                                           used=8)
        alloc_list = resource_provider.AllocationList(self.context,
                                                      objects=[obj])
        alloc_list.create_all()

        rp_al = resource_provider.AllocationList
        saved_allocations = rp_al.get_all_by_resource_provider(
            self.context, rp)
        self.assertEqual(1, len(saved_allocations))
        self.assertEqual(obj.used, saved_allocations[0].used)
Пример #7
0
 def setUp(self):
     super(TestPlacementURLs, self).setUp()
     self.resource_provider = rp_obj.ResourceProvider(
         name=uuidsentinel.rp_name,
         uuid=uuidsentinel.rp_uuid)
     self.resource_class = rp_obj.ResourceClass(
         name='CUSTOM_BAREMETAL_GOLD',
         id=1000)
Пример #8
0
    def test_set_traits_resets_changes(self, mock_set_traits, mock_reset):
        trait = resource_provider.Trait(name="HW_CPU_X86_AVX2")
        traits = resource_provider.TraitList(objects=[trait])

        rp = resource_provider.ResourceProvider(self.context, name='cn1',
            uuid=uuids.cn1)
        rp.set_traits(traits)
        mock_set_traits.assert_called_once_with(self.context, rp, traits)
        mock_reset.assert_called_once_with()
Пример #9
0
def create_resource_provider(req):
    """POST to create a resource provider.

    On success return a 201 response with an empty body
    (microversions 1.0 - 1.19) or a 200 response with a
    payload representing the newly created resource provider
    (microversions 1.20 - latest), and a location header
    pointing to the resource provider.
    """
    context = req.environ['placement.context']
    context.can(policies.CREATE)
    schema = rp_schema.POST_RESOURCE_PROVIDER_SCHEMA
    want_version = req.environ[microversion.MICROVERSION_ENVIRON]
    if want_version.matches((1, 14)):
        schema = rp_schema.POST_RP_SCHEMA_V1_14
    data = util.extract_json(req.body, schema)

    try:
        if data.get('uuid'):
            # Normalize UUID with no proper dashes into dashed one
            # with format {8}-{4}-{4}-{4}-{12}
            data['uuid'] = str(uuidlib.UUID(data['uuid']))
        else:
            data['uuid'] = uuidutils.generate_uuid()

        resource_provider = rp_obj.ResourceProvider(context, **data)
        resource_provider.create()
    except db_exc.DBDuplicateEntry as exc:
        # Whether exc.columns has one or two entries (in the event
        # of both fields being duplicates) appears to be database
        # dependent, so going with the complete solution here.
        duplicate = ', '.join(['%s: %s' % (column, data[column])
                          for column in exc.columns])
        raise webob.exc.HTTPConflict(
            _('Conflicting resource provider %(duplicate)s already exists.') %
            {'duplicate': duplicate},
            comment=errors.DUPLICATE_NAME)
    except exception.ObjectActionError as exc:
        raise webob.exc.HTTPBadRequest(
            _('Unable to create resource provider "%(name)s", %(rp_uuid)s: '
              '%(error)s') %
            {'name': data['name'], 'rp_uuid': data['uuid'], 'error': exc})

    req.response.location = util.resource_provider_url(
        req.environ, resource_provider)
    if want_version.matches(min_version=(1, 20)):
        req.response.body = encodeutils.to_utf8(jsonutils.dumps(
            _serialize_provider(req.environ, resource_provider, want_version)))
        req.response.content_type = 'application/json'
        modified = util.pick_last_modified(None, resource_provider)
        req.response.last_modified = modified
        req.response.cache_control = 'no-cache'
    else:
        req.response.status = 201
        req.response.content_type = None
    return req.response
Пример #10
0
 def test_create_no_parent(self):
     rp = resource_provider.ResourceProvider(self.context,
                                             uuid=_RESOURCE_PROVIDER_UUID,
                                             name=_RESOURCE_PROVIDER_NAME)
     rp.create()
     self.assertIsInstance(rp.id, int)
     self.assertEqual(_RESOURCE_PROVIDER_UUID, rp.uuid)
     self.assertEqual(_RESOURCE_PROVIDER_NAME, rp.name)
     self.assertEqual(_RESOURCE_PROVIDER_UUID, rp.root_provider_uuid)
     self.assertIsNone(rp.parent_provider_uuid)
Пример #11
0
    def test_create_with_root_provider_uuid_fail(self):
        obj = resource_provider.ResourceProvider(
            context=self.context,
            uuid=_RESOURCE_PROVIDER_UUID,
            name=_RESOURCE_PROVIDER_NAME,
            root_provider_uuid=_RESOURCE_PROVIDER_UUID,
        )

        exc = self.assertRaises(exception.ObjectActionError, obj.create)
        self.assertIn('root provider UUID cannot be manually set', str(exc))
Пример #12
0
 def test_concurrent_exception_causes_409(self):
     rp = resource_provider.ResourceProvider()
     expected_message = ('Update conflict: Another thread concurrently '
                         'updated the data')
     with mock.patch.object(rp,
                            "set_aggregates",
                            side_effect=exception.ConcurrentUpdateDetected):
         exc = self.assertRaises(webob.exc.HTTPConflict,
                                 aggregate._set_aggregates, rp, [])
     self.assertIn(expected_message, six.text_type(exc))
Пример #13
0
 def _create_resource_provider(self, inventory):
     """Helper method to create a resource provider with inventory"""
     ctxt = context.get_admin_context()
     rp_uuid = uuidutils.generate_uuid()
     rp = rp_obj.ResourceProvider(context=ctxt, name=rp_uuid, uuid=rp_uuid)
     rp.create()
     inv = rp_obj.Inventory(context=ctxt, resource_provider=rp, **inventory)
     inv_list = rp_obj.InventoryList(objects=[inv])
     rp.set_inventory(inv_list)
     return rp
Пример #14
0
 def test_get_by_uuid_from_db(self):
     rp = resource_provider.ResourceProvider(context=self.context,
                                             uuid=_RESOURCE_PROVIDER_UUID,
                                             name=_RESOURCE_PROVIDER_NAME)
     rp.create()
     retrieved_rp = resource_provider.ResourceProvider.get_by_uuid(
         self.context, _RESOURCE_PROVIDER_UUID)
     self.assertEqual(rp.uuid, retrieved_rp.uuid)
     self.assertEqual(rp.name, retrieved_rp.name)
     self.assertEqual(rp.root_provider_uuid,
                      retrieved_rp.root_provider_uuid)
Пример #15
0
 def test_save_immutable(self):
     fields = {
         'id': 1,
         'uuid': _RESOURCE_PROVIDER_UUID,
         'generation': 1,
         'root_provider_uuid': _RESOURCE_PROVIDER_UUID,
     }
     for field in fields:
         rp = resource_provider.ResourceProvider(context=self.context)
         setattr(rp, field, fields[field])
         self.assertRaises(exception.ObjectActionError, rp.save)
Пример #16
0
 def _create_provider(self, name, *aggs, **kwargs):
     # TODO(efried): Common with test_allocation_candidates.ProviderDBBase
     parent = kwargs.get('parent')
     rp = rp_obj.ResourceProvider(self.ctx, name=name,
                                  uuid=getattr(uuids, name))
     if parent:
         rp.parent_provider_uuid = parent
     rp.create()
     if aggs:
         rp.set_aggregates(aggs)
     return rp
Пример #17
0
    def test_get_allocations(self, mock_get_allocations_from_db,
                             mock_ensure_cache):
        rp = resource_provider.ResourceProvider(id=_RESOURCE_PROVIDER_ID,
                                                uuid=uuids.resource_provider)
        rp_alloc_list = resource_provider.AllocationList
        allocations = rp_alloc_list.get_all_by_resource_provider(
            self.context, rp)

        self.assertEqual(1, len(allocations))
        mock_get_allocations_from_db.assert_called_once_with(
            self.context, rp.id)
        self.assertEqual(_ALLOCATION_DB['used'], allocations[0].used)
Пример #18
0
def create_provider(context, name, *aggs, **kwargs):
    parent = kwargs.get('parent')
    root = kwargs.get('root')
    uuid = kwargs.get('uuid', getattr(uuids, name))
    rp = rp_obj.ResourceProvider(context, name=name, uuid=uuid)
    if parent:
        rp.parent_provider_uuid = parent
    if root:
        rp.root_provider_uuid = root
    rp.create()
    if aggs:
        rp.set_aggregates(aggs)
    return rp
Пример #19
0
 def _create_provider(self, name, *aggs, **kwargs):
     parent = kwargs.get('parent')
     root = kwargs.get('root')
     uuid = kwargs.get('uuid', getattr(uuids, name))
     rp = rp_obj.ResourceProvider(self.ctx, name=name, uuid=uuid)
     if parent:
         rp.parent_provider_uuid = parent
     if root:
         rp.root_provider_uuid = root
     rp.create()
     if aggs:
         rp.set_aggregates(aggs)
     self.rp_uuid_to_name[rp.uuid] = name
     return rp
Пример #20
0
    def test_set_defaults(self):
        rp = resource_provider.ResourceProvider(id=_RESOURCE_PROVIDER_ID,
                                                uuid=_RESOURCE_PROVIDER_UUID)
        kwargs = dict(resource_provider=rp,
                      resource_class=_RESOURCE_CLASS_NAME,
                      total=16)
        inv = resource_provider.Inventory(self.context, **kwargs)

        inv.obj_set_defaults()
        self.assertEqual(0, inv.reserved)
        self.assertEqual(1, inv.min_unit)
        self.assertEqual(1, inv.max_unit)
        self.assertEqual(1, inv.step_size)
        self.assertEqual(1.0, inv.allocation_ratio)
Пример #21
0
 def test_non_negative_handling(self):
     # NOTE(cdent): Just checking, useless to be actually
     # comprehensive here.
     rp = resource_provider.ResourceProvider(id=_RESOURCE_PROVIDER_ID,
                                             uuid=_RESOURCE_PROVIDER_UUID)
     kwargs = dict(resource_provider=rp,
                   resource_class=_RESOURCE_CLASS_NAME,
                   total=16,
                   reserved=2,
                   min_unit=1,
                   max_unit=-8,
                   step_size=1,
                   allocation_ratio=1.0)
     self.assertRaises(ValueError, resource_provider.Inventory, **kwargs)
Пример #22
0
    def test_create_incomplete_consumers(self):
        """Test the online data migration that creates incomplete consumer
        records along with the incomplete consumer project/user records.
        """
        self._create_incomplete_allocations(self.ctx)
        # We do a "really online" online data migration for incomplete
        # consumers when calling AllocationList.get_all_by_consumer_id() and
        # AllocationList.get_all_by_resource_provider() and there are still
        # incomplete consumer records. So, to simulate a situation where the
        # operator has yet to run the nova-manage online_data_migration CLI
        # tool completely, we first call
        # consumer_obj.create_incomplete_consumers() with a batch size of 1.
        # This should mean there will be two allocation records still remaining
        # with a missing consumer record (since we create 3 total to begin
        # with). We then query the allocations table directly to grab that
        # consumer UUID in the allocations table that doesn't refer to a
        # consumer table record and call
        # AllocationList.get_all_by_consumer_id() with that consumer UUID. This
        # should create the remaining missing consumer record "inline" in the
        # AllocationList.get_all_by_consumer_id() method.
        # After that happens, there should still be a single allocation record
        # that is missing a relation to the consumers table. We call the
        # AllocationList.get_all_by_resource_provider() method and verify that
        # method cleans up the remaining incomplete consumers relationship.
        res = consumer_obj.create_incomplete_consumers(self.ctx, 1)
        self.assertEqual((1, 1), res)

        # Grab the consumer UUID for the allocation record with a
        # still-incomplete consumer record.
        res = _get_allocs_with_no_consumer_relationship(self.ctx)
        self.assertEqual(2, len(res))
        still_missing = res[0][0]
        rp_obj.AllocationList.get_all_by_consumer_id(self.ctx, still_missing)

        # There should still be a single missing consumer relationship. Let's
        # grab that and call AllocationList.get_all_by_resource_provider()
        # which should clean that last one up for us.
        res = _get_allocs_with_no_consumer_relationship(self.ctx)
        self.assertEqual(1, len(res))
        still_missing = res[0][0]
        rp1 = rp_obj.ResourceProvider(self.ctx, id=1)
        rp_obj.AllocationList.get_all_by_resource_provider(self.ctx, rp1)

        # get_all_by_resource_provider() should have auto-completed the still
        # missing consumer record and _check_incomplete_consumers() should
        # assert correctly that there are no more incomplete consumer records.
        self._check_incomplete_consumers(self.ctx)
        res = consumer_obj.create_incomplete_consumers(self.ctx, 10)
        self.assertEqual((0, 0), res)
Пример #23
0
    def test_capacity(self):
        rp = resource_provider.ResourceProvider(id=_RESOURCE_PROVIDER_ID,
                                                uuid=_RESOURCE_PROVIDER_UUID)
        kwargs = dict(resource_provider=rp,
                      resource_class=_RESOURCE_CLASS_NAME,
                      total=16,
                      reserved=16)
        inv = resource_provider.Inventory(self.context, **kwargs)
        inv.obj_set_defaults()

        self.assertEqual(0, inv.capacity)
        inv.reserved = 15
        self.assertEqual(1, inv.capacity)
        inv.allocation_ratio = 2.0
        self.assertEqual(2, inv.capacity)
Пример #24
0
 def test_get_all_by_resource_provider(self, mock_get, mock_ensure_cache):
     expected = [dict(_INVENTORY_DB,
                      resource_provider_id=_RESOURCE_PROVIDER_ID),
                 dict(_INVENTORY_DB,
                      id=_INVENTORY_DB['id'] + 1,
                      resource_provider_id=_RESOURCE_PROVIDER_ID)]
     mock_get.return_value = expected
     rp = resource_provider.ResourceProvider(id=_RESOURCE_PROVIDER_ID,
                                             uuid=_RESOURCE_PROVIDER_UUID)
     objs = resource_provider.InventoryList.get_all_by_resource_provider(
         self.context, rp)
     self.assertEqual(2, len(objs))
     self.assertEqual(_INVENTORY_DB['id'], objs[0].id)
     self.assertEqual(_INVENTORY_DB['id'] + 1, objs[1].id)
     self.assertEqual(_RESOURCE_PROVIDER_ID, objs[0].resource_provider.id)
Пример #25
0
 def test_create_incomplete_consumers_multiple_allocs_per_consumer(self):
     """Tests that missing consumer records are created when listing
     allocations against a resource provider or running the online data
     migration routine when the consumers have multiple allocations on the
     same provider.
     """
     self._create_incomplete_allocations(self.ctx, num_of_consumer_allocs=2)
     # Run the online data migration to migrate one consumer. The batch size
     # needs to be large enough to hit more than one consumer for this test
     # where each consumer has two allocations.
     res = consumer_obj.create_incomplete_consumers(self.ctx, 2)
     self.assertEqual((2, 2), res)
     # Migrate the rest by listing allocations on the resource provider.
     rp1 = rp_obj.ResourceProvider(self.ctx, id=1)
     rp_obj.AllocationList.get_all_by_resource_provider(self.ctx, rp1)
     self._check_incomplete_consumers(self.ctx)
     res = consumer_obj.create_incomplete_consumers(self.ctx, 10)
     self.assertEqual((0, 0), res)
Пример #26
0
 def test_create_with_id_fails(self, mock_rc_cache):
     rp = resource_provider.ResourceProvider(context=self.context,
                                             uuid=_RESOURCE_PROVIDER_UUID,
                                             name=_RESOURCE_PROVIDER_NAME)
     self.project = project_obj.Project(self.context,
                                        external_id='fake-project')
     self.user = user_obj.User(self.context, external_id='fake-user')
     self.consumer = consumer_obj.Consumer(self.context,
                                           uuid=uuids.fake_instance,
                                           project=self.project,
                                           user=self.user)
     obj = resource_provider.Allocation(context=self.context,
                                        id=99,
                                        resource_provider=rp,
                                        resource_class=_RESOURCE_CLASS_NAME,
                                        consumer=self.consumer,
                                        used=8)
     alloc_list = resource_provider.AllocationList(self.context,
                                                   objects=[obj])
     self.assertRaises(exception.ObjectActionError, alloc_list.create_all)
Пример #27
0
def create_resource_provider(req):
    """POST to create a resource provider.

    On success return a 201 response with an empty body and a location
    header pointing to the newly created resource provider.
    """
    context = req.environ['placement.context']
    schema = rp_schema.POST_RESOURCE_PROVIDER_SCHEMA
    want_version = req.environ[microversion.MICROVERSION_ENVIRON]
    if want_version.matches((1, 14)):
        schema = rp_schema.POST_RP_SCHEMA_V1_14
    data = util.extract_json(req.body, schema)

    try:
        uuid = data.setdefault('uuid', uuidutils.generate_uuid())
        resource_provider = rp_obj.ResourceProvider(context, **data)
        resource_provider.create()
    except db_exc.DBDuplicateEntry as exc:
        # Whether exc.columns has one or two entries (in the event
        # of both fields being duplicates) appears to be database
        # dependent, so going with the complete solution here.
        duplicate = ', '.join(
            ['%s: %s' % (column, data[column]) for column in exc.columns])
        raise webob.exc.HTTPConflict(
            _('Conflicting resource provider %(duplicate)s already exists.') %
            {'duplicate': duplicate})
    except exception.ObjectActionError as exc:
        raise webob.exc.HTTPBadRequest(
            _('Unable to create resource provider "%(name)s", %(rp_uuid)s: '
              '%(error)s') % {
                  'name': data['name'],
                  'rp_uuid': uuid,
                  'error': exc
              })

    req.response.location = util.resource_provider_url(req.environ,
                                                       resource_provider)
    req.response.status = 201
    req.response.content_type = None
    return req.response
Пример #28
0
    def test_destroy(self):
        def emulate_rp_mysql_delete(func):
            def wrapped(context, _id):
                rp = context.session.query(
                    models.ResourceProvider).\
                    filter(
                        models.ResourceProvider.id == _id).first()
                self.assertIsNone(rp.root_provider_id)
                return func(context, _id)

            return wrapped

        emulated = emulate_rp_mysql_delete(resource_provider._delete_rp_record)

        rp = resource_provider.ResourceProvider(self.context,
                                                uuid=_RESOURCE_PROVIDER_UUID,
                                                name=_RESOURCE_PROVIDER_NAME)
        rp.create()

        with mock.patch.object(resource_provider, '_delete_rp_record',
                               emulated):
            rp.destroy()
Пример #29
0
    def start_fixture(self):
        super(AllocationFixture, self).start_fixture()
        self.context = context.get_admin_context()

        # For use creating and querying allocations/usages
        os.environ['ALT_USER_ID'] = uuidutils.generate_uuid()
        project_id = os.environ['PROJECT_ID']
        user_id = os.environ['USER_ID']
        alt_user_id = os.environ['ALT_USER_ID']

        user = user_obj.User(self.context, external_id=user_id)
        user.create()
        alt_user = user_obj.User(self.context, external_id=alt_user_id)
        alt_user.create()
        project = project_obj.Project(self.context, external_id=project_id)
        project.create()

        # Stealing from the super
        rp_name = os.environ['RP_NAME']
        rp_uuid = os.environ['RP_UUID']
        rp = rp_obj.ResourceProvider(self.context, name=rp_name, uuid=rp_uuid)
        rp.create()

        # Create a first consumer for the DISK_GB
        consumer_id = uuidutils.generate_uuid()
        consumer = consumer_obj.Consumer(self.context,
                                         uuid=consumer_id,
                                         user=user,
                                         project=project)
        consumer.create()

        # Create some DISK_GB inventory and allocations.
        inventory = rp_obj.Inventory(self.context,
                                     resource_provider=rp,
                                     resource_class='DISK_GB',
                                     total=2048,
                                     step_size=10,
                                     min_unit=10,
                                     max_unit=600)
        inventory.obj_set_defaults()
        rp.add_inventory(inventory)
        alloc1 = rp_obj.Allocation(self.context,
                                   resource_provider=rp,
                                   resource_class='DISK_GB',
                                   consumer=consumer,
                                   used=500)
        alloc2 = rp_obj.Allocation(self.context,
                                   resource_provider=rp,
                                   resource_class='DISK_GB',
                                   consumer=consumer,
                                   used=500)
        alloc_list = rp_obj.AllocationList(self.context,
                                           objects=[alloc1, alloc2])
        alloc_list.create_all()

        # Create a second consumer for the VCPU
        consumer_id = uuidutils.generate_uuid()
        consumer = consumer_obj.Consumer(self.context,
                                         uuid=consumer_id,
                                         user=user,
                                         project=project)
        consumer.create()
        # This consumer is referenced from the gabbits
        os.environ['CONSUMER_ID'] = consumer_id

        # Create some VCPU inventory and allocations.
        inventory = rp_obj.Inventory(self.context,
                                     resource_provider=rp,
                                     resource_class='VCPU',
                                     total=10,
                                     max_unit=4)
        inventory.obj_set_defaults()
        rp.add_inventory(inventory)
        alloc1 = rp_obj.Allocation(self.context,
                                   resource_provider=rp,
                                   resource_class='VCPU',
                                   consumer=consumer,
                                   used=2)
        alloc2 = rp_obj.Allocation(self.context,
                                   resource_provider=rp,
                                   resource_class='VCPU',
                                   consumer=consumer,
                                   used=4)
        alloc_list = rp_obj.AllocationList(self.context,
                                           objects=[alloc1, alloc2])
        alloc_list.create_all()

        # Create a consumer object for a different user
        alt_consumer_id = uuidutils.generate_uuid()
        alt_consumer = consumer_obj.Consumer(self.context,
                                             uuid=alt_consumer_id,
                                             user=alt_user,
                                             project=project)
        alt_consumer.create()
        os.environ['ALT_CONSUMER_ID'] = alt_consumer_id

        # Create a couple of allocations for a different user.
        alloc1 = rp_obj.Allocation(self.context,
                                   resource_provider=rp,
                                   resource_class='DISK_GB',
                                   consumer=alt_consumer,
                                   used=20)
        alloc2 = rp_obj.Allocation(self.context,
                                   resource_provider=rp,
                                   resource_class='VCPU',
                                   consumer=alt_consumer,
                                   used=1)
        alloc_list = rp_obj.AllocationList(self.context,
                                           objects=[alloc1, alloc2])
        alloc_list.create_all()

        # The ALT_RP_XXX variables are for a resource provider that has
        # not been created in the Allocation fixture
        os.environ['ALT_RP_UUID'] = uuidutils.generate_uuid()
        os.environ['ALT_RP_NAME'] = uuidutils.generate_uuid()
Пример #30
0
    def start_fixture(self):
        super(SharedStorageFixture, self).start_fixture()
        self.context = context.get_admin_context()

        cn1_uuid = uuidutils.generate_uuid()
        cn2_uuid = uuidutils.generate_uuid()
        ss_uuid = uuidutils.generate_uuid()
        agg_uuid = uuidutils.generate_uuid()
        os.environ['CN1_UUID'] = cn1_uuid
        os.environ['CN2_UUID'] = cn2_uuid
        os.environ['SS_UUID'] = ss_uuid
        os.environ['AGG_UUID'] = agg_uuid

        cn1 = rp_obj.ResourceProvider(
            self.context,
            name='cn1',
            uuid=cn1_uuid)
        cn1.create()

        cn2 = rp_obj.ResourceProvider(
            self.context,
            name='cn2',
            uuid=cn2_uuid)
        cn2.create()

        ss = rp_obj.ResourceProvider(
            self.context,
            name='ss',
            uuid=ss_uuid)
        ss.create()

        # Populate compute node inventory for VCPU and RAM
        for cn in (cn1, cn2):
            vcpu_inv = rp_obj.Inventory(
                self.context,
                resource_provider=cn,
                resource_class='VCPU',
                total=24,
                reserved=0,
                max_unit=24,
                min_unit=1,
                step_size=1,
                allocation_ratio=16.0)
            vcpu_inv.obj_set_defaults()
            ram_inv = rp_obj.Inventory(
                self.context,
                resource_provider=cn,
                resource_class='MEMORY_MB',
                total=128 * 1024,
                reserved=0,
                max_unit=128 * 1024,
                min_unit=256,
                step_size=256,
                allocation_ratio=1.5)
            ram_inv.obj_set_defaults()
            inv_list = rp_obj.InventoryList(objects=[vcpu_inv, ram_inv])
            cn.set_inventory(inv_list)

        t_avx_sse = rp_obj.Trait.get_by_name(self.context, "HW_CPU_X86_SSE")
        t_avx_sse2 = rp_obj.Trait.get_by_name(self.context, "HW_CPU_X86_SSE2")
        cn1.set_traits(rp_obj.TraitList(objects=[t_avx_sse, t_avx_sse2]))

        # Populate shared storage provider with DISK_GB inventory
        disk_inv = rp_obj.Inventory(
            self.context,
            resource_provider=ss,
            resource_class='DISK_GB',
            total=2000,
            reserved=100,
            max_unit=2000,
            min_unit=10,
            step_size=10,
            allocation_ratio=1.0)
        disk_inv.obj_set_defaults()
        inv_list = rp_obj.InventoryList(objects=[disk_inv])
        ss.set_inventory(inv_list)

        # Mark the shared storage pool as having inventory shared among any
        # provider associated via aggregate
        t = rp_obj.Trait.get_by_name(
            self.context,
            "MISC_SHARES_VIA_AGGREGATE",
        )
        ss.set_traits(rp_obj.TraitList(objects=[t]))

        # Now associate the shared storage pool and both compute nodes with the
        # same aggregate
        cn1.set_aggregates([agg_uuid])
        cn2.set_aggregates([agg_uuid])
        ss.set_aggregates([agg_uuid])