示例#1
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)
示例#2
0
    def test_get_by_filter_with_attributes(self):
        db_device = self.fake_device
        device = objects.Device(context=self.context, **db_device)
        device.create(self.context)
        device_get = objects.Device.get(self.context, device.uuid)
        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.device_id = device_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.device_id = device_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.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 = {"num_accelerators": 4, "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)
示例#3
0
    def test_get_by_host(self):
        dep1 = self.fake_deployable
        dep2 = self.fake_deployable2
        fake_hostname = 'host_name'
        dep_obj1 = objects.Deployable(context=self.context, **dep1)
        dep_obj2 = objects.Deployable(context=self.context, **dep2)
        dep_obj1.create(self.context)
        dep_obj2.create(self.context)

        dep_obj1.save(self.context)
        dep_obj2.save(self.context)
        dep_objs = objects.Deployable.get_by_host(self.context, fake_hostname)
        self.assertEqual(dep_objs[0].host, fake_hostname)
        self.assertEqual(dep_objs[1].host, fake_hostname)
示例#4
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)
示例#5
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)
示例#6
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')
示例#7
0
    def test_create(self, mock_create):
        mock_create.return_value = self.fake_deployable
        dpl = objects.Deployable(context=self.context,
                                 **mock_create.return_value)
        dpl.create(self.context)

        self.assertEqual(self.fake_deployable['id'], dpl.id)
示例#8
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)
示例#9
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")
示例#10
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)
示例#11
0
文件: utils.py 项目: tobyxdd/cyborg
def get_test_deployable(ctxt, **kw):
    """Return an Deployable 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_dp = db_utils.get_test_deployable(**kw)
    return objects.Deployable(ctxt, **test_dp)
示例#12
0
 def create_deployable(fpgas, bdf, parent_uuid=None):
     fpga = fpgas[bdf]
     dep = self._gen_deployable_from_host_dev(fpga)
     # if parent_uuid:
     dep["parent_uuid"] = parent_uuid
     obj_dep = objects.Deployable(context, **dep)
     new_dep = self.conductor_api.deployable_create(context, obj_dep)
     return new_dep
示例#13
0
 def test_destroy(self, mock_destroy):
     mock_destroy.return_value = self.fake_deployable
     dpl = objects.Deployable(context=self.context,
                              **mock_destroy.return_value)
     dpl.create(self.context)
     self.assertEqual(self.fake_deployable['id'], dpl.id)
     dpl.destroy(self.context)
     self.assertRaises(exception.DeployableNotFound, objects.Deployable.get,
                       self.context, dpl['uuid'])
示例#14
0
 def test_save(self, mock_save):
     mock_save.return_value = self.fake_deployable
     dpl = objects.Deployable(context=self.context,
                              **mock_save.return_value)
     dpl.create(self.context)
     dpl.host = 'test_save'
     dpl.save(self.context)
     dpl_get = objects.Deployable.get(self.context, dpl['uuid'])
     self.assertEqual(dpl_get.host, 'test_save')
示例#15
0
 def post(self, dep):
     """Create a new deployable.
     :param dep: a deployable within the request body.
     """
     context = pecan.request.context
     obj_dep = objects.Deployable(context, **dep)
     new_dep = pecan.request.conductor_api.deployable_create(
         context, obj_dep)
     # Set the HTTP Location Header
     pecan.response.location = link.build_url('deployables', new_dep.uuid)
     return Deployable.convert_with_links(new_dep)
示例#16
0
    def test_get(self):
        db_device = self.fake_device
        device = objects.Device(context=self.context, **db_device)
        device.create(self.context)
        device_get = objects.Device.get(self.context, device.uuid)
        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.device_id = device_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)
        self.assertEqual(dpl_get.uuid, dpl.uuid)
示例#17
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)
示例#18
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)
示例#19
0
    def test_get_by_filter(self):
        db_device = self.fake_device
        device = objects.Device(context=self.context, **db_device)
        device.create(self.context)
        device_get = objects.Device.get(self.context, device.uuid)
        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.device_id = device_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)
示例#20
0
    def test_destroy(self):
        db_device = self.fake_device
        device = objects.Device(context=self.context, **db_device)
        device.create(self.context)
        device_get = objects.Device.get(self.context, device.uuid)
        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.device_id = device_get.id
        dpl.create(self.context)
        self.assertEqual(db_dpl['uuid'], dpl.uuid)
        dpl.destroy(self.context)
        self.assertRaises(exception.ResourceNotFound, objects.Deployable.get,
                          self.context, dpl.uuid)
示例#21
0
    def test_delete_attribute(self):
        db_device = self.fake_device
        device = objects.Device(context=self.context, **db_device)
        device.create(self.context)
        device_get = objects.Device.get(self.context, device.uuid)
        db_dpl = self.fake_deployable
        dpl = objects.Deployable(context=self.context, **db_dpl)

        dpl.device_id = device_get.id
        dpl.create(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl.uuid)
        db_attr = self.fake_attribute
        dpl_get.add_attribute(self.context, db_attr['key'], db_attr['value'])
        dpl_get.save(self.context)
        dpl_get = objects.Deployable.get(self.context, dpl_get.uuid)
        self.assertEqual(len(dpl_get.attributes_list), 1)

        dpl_get.delete_attribute(self.context, dpl_get.attributes_list[0])
        self.assertEqual(len(dpl_get.attributes_list), 0)
示例#22
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)
示例#23
0
    def update_gpu_usage(self, context):
        """Update the gpu resource usage and stats after a change in an
        instance, for the original update_usage specified update fpga, define a
        new func update gpu here.
        """
        def create_deployable(gpus, bdf, parent_uuid=None):
            gpu = gpus[bdf]
            dep = self._gen_deployable_from_host_dev(gpu)
            # if parent_uuid:
            dep["parent_uuid"] = parent_uuid
            obj_dep = objects.Deployable(context, **dep)
            new_dep = self.conductor_api.deployable_create(context, obj_dep)
            return new_dep
        gpus = self._get_gpu_devices()
        deployables = self.conductor_api.deployable_get_by_host(
            context, self.host)

        accls = dict([(v["pcie_address"], v) for v in deployables
                      if v["type"] == "GPU"])
        all_gpus = dict([(v["devices"], v) for v in gpus])

        # Add
        new = set(all_gpus.keys()) - set(accls.keys())
        new_gpus = [all_gpus[n] for n in new]
        for n in new_gpus:
            dep = self._gen_deployable_from_host_dev(n)
            # if parent_uuid:
            dep["parent_uuid"] = None
            obj_dep = objects.Deployable(context, **dep)
            self.conductor_api.deployable_create(context, obj_dep)

        # Delete
        not_exists = set(accls.keys()) - set(all_gpus.keys())
        for obsolete in not_exists:
            try:
                self.conductor_api.deployable_delete(context, accls[obsolete])
            except RemoteError as e:
                LOG.error(e)
            del accls[obsolete]
示例#24
0
 def test_get(self, mock_get):
     mock_get.return_value = self.fake_deployable
     dpl = objects.Deployable(context=self.context, **mock_get.return_value)
     dpl.create(self.context)
     dpl_get = objects.Deployable.get(self.context, dpl['uuid'])
     self.assertEqual(dpl_get.uuid, dpl.uuid)
示例#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)