diff --git a/cyborg/api/controllers/v2/device_profiles.py b/cyborg/api/controllers/v2/device_profiles.py index 27bfcaf1..d2a76a06 100644 --- a/cyborg/api/controllers/v2/device_profiles.py +++ b/cyborg/api/controllers/v2/device_profiles.py @@ -93,8 +93,19 @@ class DeviceProfile(base.APIBase): ] return api_devprof + def get_device_profile(self, obj_devprof): + api_obj = {} + 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]) + api_obj['links'] = [ + link.Link.make_link_dict('device_profiles', api_obj['uuid']) + ] + return api_obj -class DeviceProfileCollection(base.APIBase): + +class DeviceProfileCollection(DeviceProfile): """API representation of a collection of device profiles.""" """A list containing device profile objects""" @@ -108,6 +119,12 @@ class DeviceProfileCollection(base.APIBase): for obj_devprof in obj_devprofs] return collection + def get_device_profiles(self, obj_devprofs): + api_obj_devprofs = [ + self.get_device_profile(obj_devprof) + for obj_devprof in obj_devprofs] + return api_obj_devprofs + class DeviceProfilesController(base.CyborgController, DeviceProfileCollection): @@ -238,11 +255,12 @@ class DeviceProfilesController(base.CyborgController, return ret @authorize_wsgi.authorize_wsgi("cyborg:device_profile", "get_one") - @expose.expose(DeviceProfile, wtypes.text) + @expose.expose('json', wtypes.text) def get_one(self, uuid): """Retrieve a single device profile by uuid.""" LOG.info('[device_profiles] get_one. uuid=%s', uuid) - api_obj_devprofs = self._get_device_profile_list(uuid=uuid) + obj_devprofs = self._get_device_profile_list(uuid=uuid) + api_obj_devprofs = self.get_device_profiles(obj_devprofs) if len(api_obj_devprofs) == 0: raise exception.ResourceNotFound( resource='Device profile', @@ -252,9 +270,11 @@ class DeviceProfilesController(base.CyborgController, if count != 1: # Should never happen because names are unique raise exception.ExpectedOneObject(obj='device profile', count=count) - ret = api_obj_devprofs[0] + ret = {"device_profile": api_obj_devprofs[0]} LOG.info('[device_profiles] get_one returned: %s', ret) - return DeviceProfile.convert_with_links(ret) + # TODO(Sundar) Replace this with convert_with_links() + return wsme.api.Response(ret, status_code=HTTPStatus.OK, + return_type=wsme.types.DictType) @authorize_wsgi.authorize_wsgi("cyborg:device_profile", "delete") @expose.expose(None, wtypes.text, status_code=HTTPStatus.NO_CONTENT) diff --git a/cyborg/tests/unit/api/controllers/v2/test_device_profiles.py b/cyborg/tests/unit/api/controllers/v2/test_device_profiles.py index e88e4311..cfde19ce 100644 --- a/cyborg/tests/unit/api/controllers/v2/test_device_profiles.py +++ b/cyborg/tests/unit/api/controllers/v2/test_device_profiles.py @@ -57,7 +57,8 @@ class TestDeviceProfileController(v2_test.APITestV2): url = self.DP_URL + '/%s' data = self.get_json(url % dp['uuid'], headers=self.headers) mock_dp.assert_called_once() - self._validate_dp(dp, data) + out_dp = data['device_profile'] + self._validate_dp(dp, out_dp) @mock.patch('cyborg.objects.DeviceProfile.list') def test_get_all(self, mock_dp):