def test_create(self, mock_from_db_obj): db_extarq = self.fake_db_extarqs[0] mock_from_db_obj.return_value = self.fake_obj_extarqs[0] with mock.patch.object(self.dbapi, 'extarq_create', autospec=True) as mock_extarq_create: mock_extarq_create.return_value = db_extarq extarq = objects.ExtARQ(self.context, **db_extarq) extarq.arq = objects.ARQ(self.context, **db_extarq) extarq.create(self.context) mock_extarq_create.assert_called_once()
def post(self, req): """Create one or more ARQs for a single device profile. Request body: { 'device_profile_name': <string> } Future: { 'device_profile_name': <string> # required 'device_profile_group_id': <integer>, # opt, default=0 'image_uuid': <glance-image-UUID>, #optional, for future } :param req: request body. """ LOG.info("[arq] post req = (%s)", req) context = pecan.request.context dp_name = req.get('device_profile_name') if dp_name is not None: try: devprof = objects.DeviceProfile.get_by_name(context, dp_name) except exception.ResourceNotFound: raise exception.ResourceNotFound(resource='Device Profile', msg='with name=%s' % dp_name) except Exception as e: raise e else: raise exception.DeviceProfileNameNeeded() LOG.info('[arqs] post. device profile name=%s', dp_name) extarq_list = [] for group_id, group in enumerate(devprof.groups): accel_resources = [ int(val) for key, val in group.items() if key.startswith('resources') ] # If/when we introduce non-accelerator resources, like # device-local memory, the key search above needs to be # made specific to accelerator resources only. num_accels = sum(accel_resources) arq_fields = { 'device_profile_name': devprof.name, 'device_profile_group_id': group_id, } for i in range(num_accels): obj_arq = objects.ARQ(context, **arq_fields) extarq_fields = {'arq': obj_arq} obj_extarq = objects.ExtARQ(context, **extarq_fields) new_extarq = pecan.request.conductor_api.arq_create( context, obj_extarq, devprof.id) extarq_list.append(new_extarq) ret = ARQCollection.convert_with_links( [extarq.arq for extarq in extarq_list]) LOG.info('[arqs] post returned: %s', ret) return ret