Add 'description' field to the device profile object
Add the DeviceProfile objects version 1.1, and add 'description' field to the DeviceProfile's fields. And 'description' also will expose to end users from the GET/POST response body. Story: 2007397 Partial-Implements: blueprint add-description-field-to-device-profiles Change-Id: I15fd9a430d09b20b55375b374fd7fd96542c6358
This commit is contained in:
parent
fc7a85d8cb
commit
002e31a129
@ -62,8 +62,7 @@ class DeviceProfile(base.APIBase):
|
||||
@classmethod
|
||||
def get_api_obj(cls, obj_devprof):
|
||||
api_obj = {}
|
||||
# TODO(Sundar) add description field in db, objects and here
|
||||
for field in ['name', 'uuid', 'groups']:
|
||||
for field in ['name', 'description', 'uuid', 'groups']:
|
||||
api_obj[field] = obj_devprof[field]
|
||||
for field in ['created_at', 'updated_at']:
|
||||
api_obj[field] = str(obj_devprof[field])
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import versionutils
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from cyborg.common import exception
|
||||
@ -29,7 +30,8 @@ LOG = logging.getLogger(__name__)
|
||||
@base.CyborgObjectRegistry.register
|
||||
class DeviceProfile(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
# Version 1.1: Added description field.
|
||||
VERSION = '1.1'
|
||||
|
||||
dbapi = dbapi.get_instance()
|
||||
|
||||
@ -38,8 +40,16 @@ class DeviceProfile(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
'uuid': object_fields.StringField(nullable=False),
|
||||
'name': object_fields.StringField(nullable=False),
|
||||
'groups': object_fields.ListOfDictOfNullableStringsField(),
|
||||
'description': object_fields.StringField(nullable=True),
|
||||
}
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
super(DeviceProfile, self).obj_make_compatible(
|
||||
primitive, target_version)
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 1) and 'description' in primitive:
|
||||
del primitive['description']
|
||||
|
||||
def _to_profile_json(self, obj_changes):
|
||||
if 'groups' in obj_changes: # Convert to profile_json string
|
||||
d = {"groups": obj_changes['groups']}
|
||||
|
@ -37,6 +37,7 @@ def _get_device_profiles_as_dict():
|
||||
"id": 1,
|
||||
"uuid": u"a95e10ae-b3e3-4eab-a513-1afae6f17c51",
|
||||
"name": u'afaas_example_1',
|
||||
"description": "fake-afaas_example_1-desc",
|
||||
"created_at": date1,
|
||||
"updated_at": None,
|
||||
"groups": [
|
||||
@ -52,9 +53,10 @@ def _get_device_profiles_as_dict():
|
||||
dp2 = {
|
||||
"id": 2,
|
||||
"uuid": u"199c46b7-63a7-431b-aa40-35da4b9420b1",
|
||||
"name": u'daas_example_1',
|
||||
"name": u'daas_example_2',
|
||||
"created_at": date2,
|
||||
"updated_at": None,
|
||||
"description": "fake-daas_example_2-desc",
|
||||
"groups": [
|
||||
{"resources:ACCELERATOR_FPGA": "1",
|
||||
"trait:CUSTOM_REGION_ID_3ACD": "required",
|
||||
|
@ -36,6 +36,7 @@ class TestDeviceProfileObject(base.DbTestCase):
|
||||
mock_db_devprof_get.assert_called_once_with(self.context, name)
|
||||
self.assertEqual(self.context, obj_devprof._context)
|
||||
self.assertEqual(name, obj_devprof.name)
|
||||
self.assertIn('description', obj_devprof)
|
||||
|
||||
def test_get_by_uuid(self):
|
||||
uuid = self.fake_device_profile['uuid']
|
||||
@ -46,6 +47,7 @@ class TestDeviceProfileObject(base.DbTestCase):
|
||||
mock_db_devprof_get.assert_called_once_with(self.context, uuid)
|
||||
self.assertEqual(self.context, obj_devprof._context)
|
||||
self.assertEqual(uuid, obj_devprof.uuid)
|
||||
self.assertIn('description', obj_devprof)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.dbapi, 'device_profile_list',
|
||||
@ -58,6 +60,8 @@ class TestDeviceProfileObject(base.DbTestCase):
|
||||
self.assertEqual(self.context, obj_devprofs[0]._context)
|
||||
self.assertEqual(self.fake_device_profile['name'],
|
||||
obj_devprofs[0].name)
|
||||
self.assertEqual(self.fake_device_profile['description'],
|
||||
obj_devprofs[0].description)
|
||||
|
||||
def test_create(self):
|
||||
api_devprofs = fake_device_profile.get_api_devprofs()
|
||||
|
@ -67,6 +67,7 @@ class TestExtARQJobMixin(base.DbTestCase):
|
||||
"id": self.fake_db_extarqs[0]['device_profile_id'],
|
||||
"uuid": uuid,
|
||||
"name": self.fake_db_extarqs[0]['device_profile_name'],
|
||||
"description": "fake-device_profile_desc",
|
||||
"profile_json": jsonutils.dumps({"groups": groups}),
|
||||
"created_at": timeutils.utcnow().isoformat(),
|
||||
"updated_at": timeutils.utcnow().isoformat(),
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"name":"afexample_3",
|
||||
"uuid":"1a939c88-0b01-408b-bab0-4c61d3a02d71",
|
||||
"description": "",
|
||||
"groups":[
|
||||
{
|
||||
"trait:CUSTOM_FUNCTION_ID_3AFB":"required",
|
||||
|
@ -2,6 +2,7 @@
|
||||
"device_profile":{
|
||||
"name":"fpga-dp1",
|
||||
"uuid":"5518a925-1c2c-49a2-a8bf-0927d9456f3e",
|
||||
"description": "",
|
||||
"groups":[
|
||||
{
|
||||
"trait:CUSTOM_CHENKE_TRAITS":"required",
|
||||
|
@ -3,6 +3,7 @@
|
||||
{
|
||||
"name":"bym-1",
|
||||
"uuid":"3d03fa5b-507c-4810-a344-759e9ef4337a",
|
||||
"description": "",
|
||||
"groups":[
|
||||
{
|
||||
"resources:FPGA":"1",
|
||||
@ -21,6 +22,7 @@
|
||||
{
|
||||
"name":"fpga-dp1",
|
||||
"uuid":"5518a925-1c2c-49a2-a8bf-0927d9456f3e",
|
||||
"description": "",
|
||||
"groups":[
|
||||
{
|
||||
"trait:CUSTOM_CHENKE_TRAITS":"required",
|
||||
|
@ -1,10 +1,11 @@
|
||||
curl -g -i -X POST $cyborg_endpoint_url/device_profiles \
|
||||
-H "Accept: application/json" -H "Content-Type: application/json" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "User-Agent:None" \
|
||||
-H "X-Auth-Token: yourtoken" \
|
||||
-d '[
|
||||
{"name": "afexample_3",
|
||||
"groups": [{"resources:CUSTOM_ACCELERATOR_FPGA": "1",
|
||||
"trait:CUSTOM_FPGA_1": "required",
|
||||
"trait:CUSTOM_FUNCTION_ID_3AFB": "required",
|
||||
"accel:bitstream_id": "a6a12670-7014-4cff-a563-cea949b57fb3"}]}]'
|
||||
-d '[{"name": "afexample_3",
|
||||
"description": "device profile description",
|
||||
"groups": [{"resources:CUSTOM_ACCELERATOR_FPGA": "1",
|
||||
"trait:CUSTOM_FPGA_1": "required",
|
||||
"trait:CUSTOM_FUNCTION_ID_3AFB": "required",
|
||||
"accel:bitstream_id": "a6a12670-7014-4cff-a563-cea949b57fb3"}]}]'
|
||||
|
@ -1,9 +1,10 @@
|
||||
curl -g -i -X POST $cyborg_endpoint_url/device_profiles \
|
||||
-H "Accept: application/json" -H "Content-Type: application/json" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "User-Agent:None" \
|
||||
-H "X-Auth-Token: yourtoken" \
|
||||
-d '[
|
||||
{"name": "afexample_3",
|
||||
"groups": [{"resources:CUSTOM_ACCELERATOR_FPGA": "1",
|
||||
"trait:CUSTOM_FPGA_1": "required",
|
||||
"trait:CUSTOM_FUNCTION_ID_3AFB": "required"}]}]'
|
||||
-d '[{"name": "afexample_3",
|
||||
"description": "device profile description",
|
||||
"groups": [{"resources:CUSTOM_ACCELERATOR_FPGA": "1",
|
||||
"trait:CUSTOM_FPGA_1": "required",
|
||||
"trait:CUSTOM_FUNCTION_ID_3AFB": "required"}]}]'
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``description`` as a column of the ``device_profiles`` table
|
||||
in the device profile to allow end users to set some descriptions
|
||||
for the device profile when creating a device profile.
|
Loading…
x
Reference in New Issue
Block a user