Example #1
0
    def test_create_exists(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context,
                                  **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context,
                                 **db_dpl)

        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_attr = self.fake_attribute
        attr = objects.Attribute(context=self.context,
                                 **db_attr)
        attr.deployable_id = dpl_get.id
        attr.create(self.context)
        attr2 = objects.Attribute(context=self.context,
                                  **db_attr)
        attr2.deployable_id = dpl_get.id
        self.assertRaises(exception.AttributeAlreadyExists,
                          attr2.create, self.context)
Example #2
0
    def test_destroy(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context,
                                  **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context,
                                 **db_dpl)

        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_attr = self.fake_attribute
        attr = objects.Attribute(context=self.context,
                                 **db_attr)
        attr.deployable_id = dpl_get.id
        attr.create(self.context)
        self.assertEqual(db_attr['uuid'], attr.uuid)

        attr.destroy(self.context)
        self.assertRaises(exception.AttributeNotFound,
                          objects.Attribute.get, self.context,
                          attr.uuid)
Example #3
0
    def test_add_attribute(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)
        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_attr = self.fake_attribute

        dpl.add_attribute(self.context, db_attr['key'], db_attr['value'])
        dpl.save(self.context)

        dpl_get = objects.Deployable.get(self.context, dpl.uuid)
        self.assertEqual(len(dpl_get.attributes_list), 1)
        self.assertEqual(dpl_get.attributes_list[0].key, db_attr['key'])
        self.assertEqual(dpl_get.attributes_list[0].value, db_attr['value'])

        dpl.add_attribute(self.context, db_attr['key'], 'change_value')
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)
        self.assertEqual(len(dpl_get.attributes_list), 1)
        self.assertEqual(dpl_get.attributes_list[0].key, db_attr['key'])
        self.assertEqual(dpl_get.attributes_list[0].value, 'change_value')
Example #4
0
    def test_save(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context,
                                  **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context,
                                 **db_dpl)

        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_attr = self.fake_attribute
        attr = objects.Attribute(context=self.context,
                                 **db_attr)
        attr.deployable_id = dpl_get.id
        attr.create(self.context)
        attr_get = objects.Attribute.get(self.context, attr.uuid)
        attr_get.set_key_value_pair("test_key", "test_val")
        attr_get.save(self.context)
        attr_get_2 = objects.Attribute.get(self.context, attr_get.uuid)
        self.assertEqual(attr_get_2.key, "test_key")
        self.assertEqual(attr_get_2.value, "test_val")
Example #5
0
    def test_get_by_filter(self):
        db_acc = self.fake_accelerator
        db_pf = self.fake_physical_function
        db_vf = self.fake_virtual_function
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)
        pf = objects.PhysicalFunction(context=self.context, **db_pf)

        pf.accelerator_id = acc_get.id
        pf.create(self.context)
        pf_get = objects.PhysicalFunction.get(self.context, pf.uuid)
        vf = objects.VirtualFunction(context=self.context, **db_vf)
        vf.accelerator_id = pf_get.accelerator_id
        vf.create(self.context)
        vf_get = objects.VirtualFunction.get(self.context, vf.uuid)
        pf_get.add_vf(vf_get)
        pf_get.save(self.context)

        query = {"vendor": pf_get['vendor']}
        vf_get_list = objects.VirtualFunction.get_by_filter(
            self.context, query)

        self.assertEqual(len(vf_get_list), 1)
        self.assertEqual(vf_get_list[0].uuid, vf.uuid)
        self.assertEqual(objects.VirtualFunction, type(vf_get_list[0]))
        self.assertEqual(1, 1)
Example #6
0
    def _gen_accelerator_for_deployable(self,
                                        context,
                                        name,
                                        vendor,
                                        productor,
                                        desc="",
                                        dev_type="pf",
                                        acc_type="FPGA",
                                        acc_cap="",
                                        remotable=0):
        """
        The type of the accelerator device, e.g GPU, FPGA, ...
        acc_type defines the usage of the accelerator, e.g Crypto
        acc_capability defines the specific capability, e.g AES
        """
        db_acc = {
            'deleted': False,
            'uuid': uuidutils.generate_uuid(),
            'name': name,
            'description': desc,
            'project_id': pecan.request.context.project_id,
            'user_id': pecan.request.context.user_id,
            'device_type': dev_type,
            'acc_type': acc_type,
            'acc_capability': acc_cap,
            'vendor_id': vendor,
            'product_id': productor,
            'remotable': remotable
        }

        acc = objects.Accelerator(context, **db_acc)
        acc = self.conductor_api.accelerator_create(context, acc)
        return acc
Example #7
0
 def test_get(self, mock_get):
     mock_get.return_value = self.fake_accelerator
     acc = objects.Accelerator(context=self.context,
                               **mock_get.return_value)
     acc.create(self.context)
     acc_get = objects.Accelerator.get(self.context, acc['uuid'])
     self.assertEqual(acc_get.uuid, acc.uuid)
Example #8
0
    def test_create(self, mock_create):
        mock_create.return_value = self.fake_accelerator
        acc = objects.Accelerator(context=self.context,
                                  **mock_create.return_value)
        acc.create(self.context)

        self.assertEqual(self.fake_accelerator['id'], acc.id)
Example #9
0
    def test_delete_attribute(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)
        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)
        db_attr = self.fake_attribute
        attr = objects.Attribute(context=self.context, **db_attr)
        attr.deployable_id = dpl_get.id
        attr.create(self.context)
        dpl_get.add_attribute(attr)
        dpl_get.save(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl_get.uuid)
        self.assertEqual(len(dpl_get.attributes_list), 1)
        self.assertEqual(dpl_get.attributes_list[0].id, attr.id)

        dpl_get.delete_attribute(self.context, dpl_get.attributes_list[0])
        self.assertEqual(len(dpl_get.attributes_list), 0)
        self.assertRaises(exception.AttributeNotFound, objects.Attribute.get,
                          self.context, attr.uuid)
Example #10
0
    def test_get_by_filter2(self):
        db_acc = self.fake_accelerator

        db_pf = self.fake_physical_function
        db_vf = self.fake_virtual_function

        db_pf2 = self.fake_physical_function
        db_vf2 = self.fake_virtual_function
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)
        pf = objects.PhysicalFunction(context=self.context, **db_pf)

        pf.accelerator_id = acc_get.id
        pf.create(self.context)
        pf_get = objects.PhysicalFunction.get(self.context, pf.uuid)
        pf2 = objects.PhysicalFunction(context=self.context, **db_pf2)

        pf2.accelerator_id = acc_get.id
        pf2.create(self.context)
        pf_get2 = objects.PhysicalFunction.get(self.context, pf2.uuid)
        query = {"uuid": pf2.uuid}

        pf_get_list = objects.PhysicalFunction.get_by_filter(
            self.context, query)
        self.assertEqual(1, 1)
Example #11
0
    def test_get_by_filter(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_attr = self.fake_attribute
        attr = objects.Attribute(context=self.context, **db_attr)
        attr.deployable_id = dpl_get.id
        attr.create(self.context)
        attr_filter = {"key": "attr_key", "value": "attr_val"}
        attr_get = objects.Attribute.get_by_filter(self.context,
                                                   attr_filter)[0]

        self.assertEqual(db_attr['uuid'], attr_get.uuid)

        attr_filter = {"key": "attr_key", "value": "attr_val2"}
        attr_get_list = objects.Attribute.get_by_filter(
            self.context, attr_filter)
        self.assertEqual(len(attr_get_list), 0)
Example #12
0
def get_test_accelerator(ctxt, **kw):
    """Return an Accelerator object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    test_acc = db_utils.get_test_accelerator(**kw)
    obj_acc = objects.Accelerator(ctxt, **test_acc)
    return obj_acc
Example #13
0
 def test_destroy(self, mock_destroy):
     mock_destroy.return_value = self.fake_accelerator
     acc = objects.Accelerator(context=self.context,
                               **mock_destroy.return_value)
     acc.create(self.context)
     self.assertEqual(self.fake_accelerator['id'], acc.id)
     acc.destroy(self.context)
     self.assertRaises(exception.AcceleratorNotFound,
                       objects.Accelerator.get, self.context, acc['uuid'])
Example #14
0
 def test_save(self, mock_save):
     mock_save.return_value = self.fake_accelerator
     acc = objects.Accelerator(context=self.context,
                               **mock_save.return_value)
     acc.create(self.context)
     acc.name = 'test_save'
     acc.save(self.context)
     acc_get = objects.Accelerator.get(self.context, acc['uuid'])
     self.assertEqual(acc_get.name, 'test_save')
Example #15
0
 def test_get(self):
     db_pf = self.fake_physical_function
     db_acc = self.fake_accelerator
     acc = objects.Accelerator(context=self.context, **db_acc)
     acc.create(self.context)
     acc_get = objects.Accelerator.get(self.context, acc.uuid)
     pf = objects.PhysicalFunction(context=self.context, **db_pf)
     pf.accelerator_id = acc_get.id
     pf.create(self.context)
     pf_get = objects.PhysicalFunction.get(self.context, pf.uuid)
     self.assertEqual(pf_get.uuid, pf.uuid)
Example #16
0
    def test_get_by_filter_with_attributes(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)
        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_dpl2 = self.fake_deployable2
        dpl2 = objects.Deployable(context=self.context, **db_dpl2)
        dpl2.accelerator_id = acc_get.id
        dpl2.create(self.context)
        dpl2_get = objects.Deployable.get(self.context, dpl2.uuid)

        db_attr = self.fake_attribute

        db_attr2 = self.fake_attribute2

        db_attr3 = self.fake_attribute3

        dpl.add_attribute(self.context, 'attr_key', 'attr_val')
        dpl.save(self.context)

        dpl2.add_attribute(self.context, 'test_key', 'test_val')
        dpl2.save(self.context)

        dpl2.add_attribute(self.context, 'test_key3', 'test_val3')
        dpl2.save(self.context)

        query = {"attr_key": "attr_val"}

        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 1)
        self.assertEqual(dpl_get_list[0].uuid, dpl.uuid)

        query = {"test_key": "test_val"}
        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 1)
        self.assertEqual(dpl_get_list[0].uuid, dpl2.uuid)

        query = {"test_key": "test_val", "test_key3": "test_val3"}
        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 1)
        self.assertEqual(dpl_get_list[0].uuid, dpl2.uuid)

        query = {"host": "host_name", "test_key3": "test_val3"}
        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 1)
        self.assertEqual(dpl_get_list[0].uuid, dpl2.uuid)
Example #17
0
    def test_get(self):
        db_vf = self.fake_virtual_function
        db_acc = self.fake_accelerator

        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)
        vf = objects.VirtualFunction(context=self.context, **db_vf)
        vf.accelerator_id = acc_get.id
        vf.create(self.context)
        vf_get = objects.VirtualFunction.get(self.context, vf.uuid)
        self.assertEqual(vf_get.uuid, vf.uuid)
Example #18
0
    def test_get(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)
        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)
        self.assertEqual(dpl_get.uuid, dpl.uuid)
Example #19
0
    def post(self, accelerator):
        """Create a new accelerator.

        :param accelerator: an accelerator within the request body.
        """
        context = pecan.request.context
        rpc_acc = objects.Accelerator(context, **accelerator)
        new_acc = pecan.request.conductor_api.accelerator_create(
            context, rpc_acc)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('accelerators', new_acc.uuid)
        return Accelerator.convert_with_links(new_acc)
Example #20
0
    def test_get_by_filter(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)
        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        query = {"uuid": dpl['uuid']}
        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)

        self.assertEqual(dpl_get_list[0].uuid, dpl.uuid)
Example #21
0
 def test_destroy(self):
     db_pf = self.fake_physical_function
     db_acc = self.fake_accelerator
     acc = objects.Accelerator(context=self.context, **db_acc)
     acc.create(self.context)
     acc_get = objects.Accelerator.get(self.context, acc.uuid)
     pf = objects.PhysicalFunction(context=self.context, **db_pf)
     pf.accelerator_id = acc_get.id
     pf.create(self.context)
     pf_get = objects.PhysicalFunction.get(self.context, pf.uuid)
     self.assertEqual(db_pf['uuid'], pf_get.uuid)
     pf_get.destroy(self.context)
     self.assertRaises(exception.DeployableNotFound,
                       objects.PhysicalFunction.get, self.context,
                       pf_get['uuid'])
Example #22
0
    def test_destroy(self):
        db_vf = self.fake_virtual_function
        db_acc = self.fake_accelerator

        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)
        vf = objects.VirtualFunction(context=self.context, **db_vf)
        vf.accelerator_id = acc_get.id
        vf.create(self.context)
        vf_get = objects.VirtualFunction.get(self.context, vf.uuid)
        self.assertEqual(db_vf['uuid'], vf_get.uuid)
        vf_get.destroy(self.context)
        self.assertRaises(exception.DeployableNotFound,
                          objects.VirtualFunction.get, self.context,
                          vf_get['uuid'])
Example #23
0
    def test_get_by_deployable_uuid(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_attr = self.fake_attribute
        attr = objects.Attribute(context=self.context, **db_attr)
        attr.deployable_id = dpl_get.id
        attr.create(self.context)
        attr_get = objects.Attribute.get_by_deployable_id(
            self.context, dpl_get.id)[0]

        self.assertEqual(db_attr['uuid'], attr_get.uuid)
Example #24
0
    def test_add_vf(self):
        db_pf = self.fake_physical_function
        db_vf = self.fake_virtual_function
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)
        pf = objects.PhysicalFunction(context=self.context, **db_pf)
        pf.accelerator_id = acc_get.id
        pf.create(self.context)
        pf_get = objects.PhysicalFunction.get(self.context, pf.uuid)

        vf = objects.VirtualFunction(context=self.context, **db_vf)
        vf.accelerator_id = pf_get.accelerator_id
        vf.create(self.context)
        vf_get = objects.VirtualFunction.get(self.context, vf.uuid)

        pf_get.add_vf(vf_get)

        pf_get.save(self.context)
        pf_get_2 = objects.PhysicalFunction.get(self.context, pf.uuid)

        self.assertEqual(db_vf['uuid'], pf_get_2.virtual_function_list[0].uuid)
Example #25
0
    def test_get_by_filter_with_attributes(self):
        db_acc = self.fake_accelerator
        acc = objects.Accelerator(context=self.context, **db_acc)
        acc.create(self.context)
        acc_get = objects.Accelerator.get(self.context, acc.uuid)

        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)
        dpl.accelerator_id = acc_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)

        db_dpl2 = self.fake_deployable2
        dpl2 = objects.Deployable(context=self.context, **db_dpl2)
        dpl2.accelerator_id = acc_get.id
        dpl2.create(self.context)
        dpl2_get = objects.Deployable.get(self.context, dpl2.uuid)

        db_attr = self.fake_attribute
        attr = objects.Attribute(context=self.context, **db_attr)
        attr.deployable_id = dpl_get.id
        attr.create(self.context)

        db_attr2 = self.fake_attribute2
        attr2 = objects.Attribute(context=self.context, **db_attr2)
        attr2.deployable_id = dpl2_get.id
        attr2.create(self.context)

        db_attr3 = self.fake_attribute3
        attr3 = objects.Attribute(context=self.context, **db_attr3)
        attr3.deployable_id = dpl2_get.id
        attr3.create(self.context)

        dpl.add_attribute(attr)
        dpl.save(self.context)

        dpl2.add_attribute(attr2)
        dpl2.save(self.context)

        dpl2.add_attribute(attr3)
        dpl2.save(self.context)

        query = {"attr_key": "attr_val"}

        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 2)
        self.assertEqual(dpl_get_list[0].uuid, dpl.uuid)

        attr2.set_key_value_pair("test_key", "test_val")
        attr2.save(self.context)

        attr3.set_key_value_pair("test_key3", "test_val3")
        attr3.save(self.context)

        query = {"test_key": "test_val"}
        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 1)
        self.assertEqual(dpl_get_list[0].uuid, dpl2.uuid)

        query = {"test_key": "test_val", "test_key3": "test_val3"}
        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 1)
        self.assertEqual(dpl_get_list[0].uuid, dpl2.uuid)

        query = {"host": "host_name", "test_key3": "test_val3"}
        dpl_get_list = objects.Deployable.get_by_filter(self.context, query)
        self.assertEqual(len(dpl_get_list), 1)
        self.assertEqual(dpl_get_list[0].uuid, dpl2.uuid)