Example #1
0
    def start_fixture(self):
        super(AllocationFixture, self).start_fixture()

        # 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, uuid=user_id)
        user.create()
        alt_user = user_obj.User(self.context, uuid=alt_user_id)
        alt_user.create()
        project = project_obj.Project(self.context, uuid=project_id)
        project.create()

        # Stealing from the super
        rp_name = os.environ['RP_NAME']
        rp_uuid = os.environ['RP_UUID']
        # Create the rp with VCPU and DISK_GB inventory
        rp = tb.create_provider(self.context, rp_name, uuid=rp_uuid)
        tb.add_inventory(rp,
                         'DISK_GB',
                         2048,
                         step_size=10,
                         min_unit=10,
                         max_unit=1000)
        tb.add_inventory(rp, 'VCPU', 10, max_unit=10)

        # Create a first consumer for the DISK_GB allocations

        consumer1 = tb.ensure_consumer(self.context, user, project)
        tb.set_allocation(self.context, rp, consumer1, {'DISK_GB': 1000})
        os.environ['CONSUMER_0'] = consumer1.uuid

        # Create a second consumer for the VCPU allocations
        consumer2 = tb.ensure_consumer(self.context, user, project)
        tb.set_allocation(self.context, rp, consumer2, {'VCPU': 6})
        os.environ['CONSUMER_ID'] = consumer2.uuid

        # Create a consumer object for a different user
        alt_consumer = tb.ensure_consumer(self.context, alt_user, project)
        os.environ['ALT_CONSUMER_ID'] = alt_consumer.uuid

        # Create a couple of allocations for a different user.
        tb.set_allocation(self.context, rp, alt_consumer, {
            'DISK_GB': 20,
            'VCPU': 1
        })

        # 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()
Example #2
0
    def make_entities(self):
        aggA_uuid = uuidutils.generate_uuid()
        os.environ['AGGA_UUID'] = aggA_uuid

        ss1 = tb.create_provider(self.context, 'ss1', aggA_uuid)
        tb.set_traits(ss1, ot.MISC_SHARES_VIA_AGGREGATE)
        tb.add_inventory(ss1, orc.DISK_GB, 2000)
        os.environ['SS1_UUID'] = ss1.uuid

        # CN1
        if not self.cn1:
            self.cn1 = tb.create_provider(self.context, 'cn1', aggA_uuid)
        self.cn1.set_aggregates([aggA_uuid])
        tb.set_traits(self.cn1, ot.COMPUTE_VOLUME_MULTI_ATTACH)
        os.environ['CN1_UUID'] = self.cn1.uuid

        numas = []
        for i in (0, 1):
            numa = tb.create_provider(
                self.context, 'numa%d' % i, parent=self.cn1.uuid)
            traits = [ot.HW_NUMA_ROOT]
            if i == 1:
                traits.append('CUSTOM_FOO')
            tb.set_traits(numa, *traits)
            tb.add_inventory(numa, orc.VCPU, 4)
            numas.append(numa)
            os.environ['NUMA%d_UUID' % i] = numa.uuid
        tb.add_inventory(
            numas[0], orc.MEMORY_MB, 2048, min_unit=512, step_size=256)
        tb.add_inventory(
            numas[1], orc.MEMORY_MB, 2048, min_unit=256, max_unit=1024)
        user, proj = tb.create_user_and_project(self.context, prefix='numafx')
        consumer = tb.ensure_consumer(self.context, user, proj)
        tb.set_allocation(self.context, numas[0], consumer, {orc.VCPU: 2})

        fpga = tb.create_provider(self.context, 'fpga0', parent=numas[0].uuid)
        # TODO(efried): Use standard FPGA resource class
        tb.add_inventory(fpga, 'CUSTOM_FPGA', 1)
        os.environ['FPGA0_UUID'] = fpga.uuid

        pgpu = tb.create_provider(self.context, 'pgpu0', parent=numas[0].uuid)
        tb.add_inventory(pgpu, orc.VGPU, 8)
        os.environ['PGPU0_UUID'] = pgpu.uuid

        for i in (0, 1):
            fpga = tb.create_provider(
                self.context, 'fpga1_%d' % i, parent=numas[1].uuid)
            # TODO(efried): Use standard FPGA resource class
            tb.add_inventory(fpga, 'CUSTOM_FPGA', 1)
            os.environ['FPGA1_%d_UUID' % i] = fpga.uuid

        agent = tb.create_provider(
            self.context, 'sriov_agent', parent=self.cn1.uuid)
        tb.set_traits(agent, 'CUSTOM_VNIC_TYPE_DIRECT')
        os.environ['SRIOV_AGENT_UUID'] = agent.uuid

        for i in (1, 2):
            dev = tb.create_provider(
                self.context, 'esn%d' % i, parent=agent.uuid)
            tb.set_traits(dev, 'CUSTOM_PHYSNET%d' % i)
            tb.add_inventory(dev, orc.NET_BW_EGR_KILOBIT_PER_SEC, 10000 * i)
            os.environ['ESN%d_UUID' % i] = dev.uuid

        agent = tb.create_provider(
            self.context, 'ovs_agent', parent=self.cn1.uuid)
        tb.set_traits(agent, 'CUSTOM_VNIC_TYPE_NORMAL')
        os.environ['OVS_AGENT_UUID'] = agent.uuid

        dev = tb.create_provider(self.context, 'br_int', parent=agent.uuid)
        tb.set_traits(dev, 'CUSTOM_PHYSNET0')
        tb.add_inventory(dev, orc.NET_BW_EGR_KILOBIT_PER_SEC, 1000)
        os.environ['BR_INT_UUID'] = dev.uuid

        # CN2
        if not self.cn2:
            self.cn2 = tb.create_provider(self.context, 'cn2')

        self.cn2.set_aggregates([aggA_uuid])
        tb.add_inventory(self.cn2, orc.VCPU, 8)
        # Get a new consumer
        consumer = tb.ensure_consumer(self.context, user, proj)
        tb.set_allocation(self.context, self.cn2, consumer, {orc.VCPU: 3})
        tb.add_inventory(
            self.cn2, orc.MEMORY_MB, 2048, min_unit=1024, step_size=128)
        tb.add_inventory(self.cn2, orc.DISK_GB, 1000)
        tb.set_traits(self.cn2, 'CUSTOM_FOO')
        os.environ['CN2_UUID'] = self.cn2.uuid

        nics = []
        for i in (1, 2, 3):
            nic = tb.create_provider(
                self.context, 'nic%d' % i, parent=self.cn2.uuid)
            # TODO(efried): Use standard HW_NIC_ROOT trait
            tb.set_traits(nic, 'CUSTOM_HW_NIC_ROOT')
            nics.append(nic)
            os.environ['NIC%s_UUID' % i] = nic.uuid
        # PFs for NIC1
        for i in (1, 2):
            suf = '1_%d' % i
            pf = tb.create_provider(
                self.context, 'pf%s' % suf, parent=nics[0].uuid)
            tb.set_traits(pf, 'CUSTOM_PHYSNET%d' % i)
            # TODO(efried): Use standard generic VF resource class?
            tb.add_inventory(pf, 'CUSTOM_VF', 4)
            os.environ['PF%s_UUID' % suf] = pf.uuid
        # PFs for NIC2
        for i in (0, 1, 2, 3):
            suf = '2_%d' % (i + 1)
            pf = tb.create_provider(
                self.context, 'pf%s' % suf, parent=nics[1].uuid)
            tb.set_traits(pf, 'CUSTOM_PHYSNET%d' % ((i % 2) + 1))
            # TODO(efried): Use standard generic VF resource class?
            tb.add_inventory(pf, 'CUSTOM_VF', 2)
            os.environ['PF%s_UUID' % suf] = pf.uuid
        # PF for NIC3
        suf = '3_1'
        pf = tb.create_provider(
            self.context, 'pf%s' % suf, parent=nics[2].uuid)
        tb.set_traits(pf, 'CUSTOM_PHYSNET1')
        # TODO(efried): Use standard generic VF resource class?
        tb.add_inventory(pf, 'CUSTOM_VF', 8)
        os.environ['PF%s_UUID' % suf] = pf.uuid