def test_create(self): chassis = objects.Chassis(self.context, **self.fake_chassis) with mock.patch.object(self.dbapi, 'create_chassis', autospec=True) as mock_create_chassis: mock_create_chassis.return_value = db_utils.get_test_chassis() chassis.create() args, _kwargs = mock_create_chassis.call_args self.assertEqual(objects.Chassis.VERSION, args[0]['version'])
def post(self, chassis): """Create a new chassis. :param chassis: a chassis within the request body. """ new_chassis = objects.Chassis(pecan.request.context, **chassis.as_dict()) new_chassis.create() # Set the HTTP Location Header pecan.response.location = link.build_url('chassis', new_chassis.uuid) return Chassis.convert_with_links(new_chassis)
def get_test_chassis(ctxt, **kw): """Return a Chassis object with appropriate attributes. NOTE: The object leaves the attributes marked as changed, such that a create() could be used to commit it to the DB. """ db_chassis = db_utils.get_test_chassis(**kw) chassis = objects.Chassis(ctxt) for key in db_chassis: setattr(chassis, key, db_chassis[key]) return chassis
def get_test_chassis(ctxt, **kw): """Return a Chassis object with appropriate attributes. NOTE: The object leaves the attributes marked as changed, such that a create() could be used to commit it to the DB. """ db_chassis = db_utils.get_test_chassis(**kw) # Let DB generate ID if it isn't specified explicitly if 'id' not in kw: del db_chassis['id'] chassis = objects.Chassis(ctxt) for key in db_chassis: setattr(chassis, key, db_chassis[key]) return chassis
def post(self, chassis): """Create a new chassis. :param chassis: a chassis within the request body. """ cdict = pecan.request.context.to_dict() policy.authorize('baremetal:chassis:create', cdict, cdict) new_chassis = objects.Chassis(pecan.request.context, **chassis.as_dict()) new_chassis.create() # Set the HTTP Location Header pecan.response.location = link.build_url('chassis', new_chassis.uuid) return Chassis.convert_with_links(new_chassis)
def post(self, chassis): """Create a new chassis. :param chassis: a chassis within the request body. """ context = api.request.context api_utils.check_policy('baremetal:chassis:create') # NOTE(yuriyz): UUID is mandatory for notifications payload if not chassis.get('uuid'): chassis['uuid'] = uuidutils.generate_uuid() new_chassis = objects.Chassis(context, **chassis) notify.emit_start_notification(context, new_chassis, 'create') with notify.handle_error_notification(context, new_chassis, 'create'): new_chassis.create() notify.emit_end_notification(context, new_chassis, 'create') # Set the HTTP Location Header api.response.location = link.build_url('chassis', new_chassis.uuid) return convert_with_links(new_chassis)
def post(self, chassis): """Create a new chassis. :param chassis: a chassis within the request body. """ context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:chassis:create', cdict, cdict) # NOTE(yuriyz): UUID is mandatory for notifications payload if not chassis.uuid: chassis.uuid = uuidutils.generate_uuid() new_chassis = objects.Chassis(context, **chassis.as_dict()) notify.emit_start_notification(context, new_chassis, 'create') with notify.handle_error_notification(context, new_chassis, 'create'): new_chassis.create() notify.emit_end_notification(context, new_chassis, 'create') # Set the HTTP Location Header api.response.location = link.build_url('chassis', new_chassis.uuid) return Chassis.convert_with_links(new_chassis)