diff --git a/cyborg/api/controllers/v2/device_profiles.py b/cyborg/api/controllers/v2/device_profiles.py index 54401423..2fac34cd 100644 --- a/cyborg/api/controllers/v2/device_profiles.py +++ b/cyborg/api/controllers/v2/device_profiles.py @@ -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]) diff --git a/cyborg/objects/device_profile.py b/cyborg/objects/device_profile.py index 50d7506b..42002534 100644 --- a/cyborg/objects/device_profile.py +++ b/cyborg/objects/device_profile.py @@ -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']} diff --git a/cyborg/tests/unit/fake_device_profile.py b/cyborg/tests/unit/fake_device_profile.py index bfc86996..982d6115 100644 --- a/cyborg/tests/unit/fake_device_profile.py +++ b/cyborg/tests/unit/fake_device_profile.py @@ -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", diff --git a/cyborg/tests/unit/objects/test_device_profile.py b/cyborg/tests/unit/objects/test_device_profile.py index 439a7ad6..9ad136b1 100644 --- a/cyborg/tests/unit/objects/test_device_profile.py +++ b/cyborg/tests/unit/objects/test_device_profile.py @@ -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() diff --git a/cyborg/tests/unit/objects/test_ext_arq_job.py b/cyborg/tests/unit/objects/test_ext_arq_job.py index 2bd2bfcf..b2cf4b2c 100644 --- a/cyborg/tests/unit/objects/test_ext_arq_job.py +++ b/cyborg/tests/unit/objects/test_ext_arq_job.py @@ -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(), diff --git a/doc/api_samples/device_profiles/device_profiles-create-resp.json b/doc/api_samples/device_profiles/device_profiles-create-resp.json index a2f62f14..ae3d36f4 100644 --- a/doc/api_samples/device_profiles/device_profiles-create-resp.json +++ b/doc/api_samples/device_profiles/device_profiles-create-resp.json @@ -1,6 +1,7 @@ { "name":"afexample_3", "uuid":"1a939c88-0b01-408b-bab0-4c61d3a02d71", + "description": "", "groups":[ { "trait:CUSTOM_FUNCTION_ID_3AFB":"required", diff --git a/doc/api_samples/device_profiles/device_profiles-getone-resp.json b/doc/api_samples/device_profiles/device_profiles-getone-resp.json index 035e64ea..33cb648f 100644 --- a/doc/api_samples/device_profiles/device_profiles-getone-resp.json +++ b/doc/api_samples/device_profiles/device_profiles-getone-resp.json @@ -2,6 +2,7 @@ "device_profile":{ "name":"fpga-dp1", "uuid":"5518a925-1c2c-49a2-a8bf-0927d9456f3e", + "description": "", "groups":[ { "trait:CUSTOM_CHENKE_TRAITS":"required", diff --git a/doc/api_samples/device_profiles/device_profiles-list-resp.json b/doc/api_samples/device_profiles/device_profiles-list-resp.json index d4895ecc..2238408e 100644 --- a/doc/api_samples/device_profiles/device_profiles-list-resp.json +++ b/doc/api_samples/device_profiles/device_profiles-list-resp.json @@ -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", diff --git a/doc/api_samples/device_profiles/device_profiles-post-curl-with-bitstream.json b/doc/api_samples/device_profiles/device_profiles-post-curl-with-bitstream.json index db2e1e64..486c75df 100644 --- a/doc/api_samples/device_profiles/device_profiles-post-curl-with-bitstream.json +++ b/doc/api_samples/device_profiles/device_profiles-post-curl-with-bitstream.json @@ -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"}]}]' diff --git a/doc/api_samples/device_profiles/device_profiles-post-curl.json b/doc/api_samples/device_profiles/device_profiles-post-curl.json index bdb107e9..9134d855 100644 --- a/doc/api_samples/device_profiles/device_profiles-post-curl.json +++ b/doc/api_samples/device_profiles/device_profiles-post-curl.json @@ -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"}]}]' diff --git a/releasenotes/notes/add_description_to_device_profile-3c2efcbd54dac7b0.yaml b/releasenotes/notes/add_description_to_device_profile-3c2efcbd54dac7b0.yaml new file mode 100644 index 00000000..ad424835 --- /dev/null +++ b/releasenotes/notes/add_description_to_device_profile-3c2efcbd54dac7b0.yaml @@ -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.