def post(self, req_devprof_list): """Create one or more device_profiles. NOTE: Only one device profile supported in Train. :param devprof: a list of device_profiles. [{ "name": <string>, "groups": [ {"key1: "value1", "key2": "value2"} ] "uuid": <uuid> # optional }] :returns: The list of created device profiles """ # TODO(Sundar) Support more than one devprof per request, if needed LOG.info("[device_profiles] POST request = (%s)", req_devprof_list) if len(req_devprof_list) != 1: raise exception.InvalidParameterValue( err="Only one device profile allowed " "per POST request for now.") req_devprof = req_devprof_list[0] self._validate_post_request(req_devprof) context = pecan.request.context obj_devprof = objects.DeviceProfile(context, **req_devprof) new_devprof = pecan.request.conductor_api.device_profile_create( context, obj_devprof) ret = DeviceProfile.get_api_obj(new_devprof) return wsme.api.Response(ret, status_code=http_client.CREATED, return_type=wsme.types.DictType)
def post(self, req_devprof_list): """Create one or more device_profiles. NOTE: Only one device profile supported in Train. :param devprof: a list of device_profiles. [{ "name": <string>, "groups": [ {"key1: "value1", "key2": "value2"} ] "uuid": <uuid> # optional "description": <description> # optional }] :returns: The list of created device profiles """ # TODO(Sundar) Support more than one devprof per request, if needed LOG.info("[device_profiles] POST request = (%s)", req_devprof_list) if len(req_devprof_list) != 1: raise exception.InvalidParameterValue( err="Only one device profile allowed " "per POST request for now.") req_devprof = req_devprof_list[0] self._validate_post_request(req_devprof) context = pecan.request.context obj_devprof = objects.DeviceProfile(context, **req_devprof) new_devprof = pecan.request.conductor_api.device_profile_create( context, obj_devprof) return DeviceProfile.convert_with_links(new_devprof)
def test_create(self): with mock.patch.object(self.dbapi, 'device_profile_create', autospec=True) as mock_device_profile_create: mock_device_profile_create.return_value = self.fake_device_profile device_profile = objects.DeviceProfile(self.context, **self.fake_device_profile) device_profile.create(self.context) mock_device_profile_create.assert_called_once_with( self.context, self.fake_device_profile) self.assertEqual(self.context, device_profile._context)
def test_create(self): api_devprofs = fake_device_profile.get_api_devprofs() api_devprof = api_devprofs[0] db_devprofs = fake_device_profile.get_db_devprofs() db_devprof = db_devprofs[0] with mock.patch.object(self.dbapi, 'device_profile_create', autospec=True) as mock_db_devprof_create: mock_db_devprof_create.return_value = self.fake_device_profile obj_devprof = objects.DeviceProfile(**api_devprof) obj_devprof.create(self.context) mock_db_devprof_create.assert_called_once_with( self.context, db_devprof)