def save(self, context=None): """Save updates to this Container. Updates will be made column by column based on the result of self.what_changed(). :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object, e.g.: Container(context) """ updates = self.obj_get_changes() cpuset_obj = updates.pop('cpuset', None) if cpuset_obj is not None: updates['cpuset'] = cpuset_obj._to_dict() annotations = updates.pop('annotations', None) if annotations is not None: updates['annotations'] = self.fields['annotations'].to_primitive( self, 'annotations', self.annotations) cni_metadata = updates.pop('cni_metadata', None) if cni_metadata is not None: updates['cni_metadata'] = self.fields['cni_metadata'].to_primitive( self, 'cni_metadata', self.cni_metadata) dbapi.update_container(context, self.container_type, self.uuid, updates) self.obj_reset_changes()
def test_update_container(self, mock_update, mock_write, mock_read): mock_read.side_effect = etcd.EtcdKeyNotFound container = utils.create_test_container(context=self.context) new_image = 'new-image' mock_read.side_effect = lambda *args: FakeEtcdResult(container.as_dict( )) dbapi.update_container(self.context, container.uuid, {'image': new_image}) self.assertEqual( new_image, json.loads(mock_update.call_args_list[0][0][0].value)['image'])
def test_update_container_with_the_same_name(self): container1 = utils.create_test_container( name='container-one', uuid=uuidutils.generate_uuid(), context=self.context) container2 = utils.create_test_container( name='container-two', uuid=uuidutils.generate_uuid(), context=self.context) new_name = 'new_name' dbapi.update_container(self.context, container1.id, {'name': new_name}) self.assertRaises(exception.ContainerAlreadyExists, dbapi.update_container, self.context, container2.id, {'name': new_name})
def test_update_container_with_the_same_name(self): CONF.set_override("unique_container_name_scope", "project", group="compute") container1 = utils.create_test_container( name='container-one', uuid=uuidutils.generate_uuid(), context=self.context) container2 = utils.create_test_container( name='container-two', uuid=uuidutils.generate_uuid(), context=self.context) new_name = 'new_name' dbapi.update_container(self.context, container1.id, {'name': new_name}) self.assertRaises(exception.ContainerAlreadyExists, dbapi.update_container, self.context, container2.id, {'name': new_name})
def save(self, context=None): """Save updates to this Container. Updates will be made column by column based on the result of self.what_changed(). :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object, e.g.: Container(context) """ updates = self.obj_get_changes() dbapi.update_container(context, self.uuid, updates) self.obj_reset_changes()
def test_update_container(self): container = utils.create_test_container(context=self.context) old_image = container.image new_image = 'new-image' self.assertNotEqual(old_image, new_image) res = dbapi.update_container(self.context, container.container_type, container.id, {'image': new_image}) self.assertEqual(new_image, res.image)
def test_update_container_with_the_same_name(self): CONF.set_override("unique_container_name_scope", "project", group="compute") container1 = utils.create_test_container( name='container-one', uuid=uuidutils.generate_uuid(), context=self.context) container2 = utils.create_test_container( name='container-two', uuid=uuidutils.generate_uuid(), context=self.context) new_name = 'new_name' dbapi.update_container(self.context, container1.container_type, container1.id, {'name': new_name}) self.assertRaises(exception.ContainerAlreadyExists, dbapi.update_container, self.context, container2.container_type, container2.id, {'name': new_name})
def save(self, context=None): """Save updates to this Container. Updates will be made column by column based on the result of self.what_changed(). :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object, e.g.: Container(context) """ updates = self.obj_get_changes() cpuset_obj = updates.pop('cpuset', None) if cpuset_obj is not None: updates['cpuset'] = cpuset_obj._to_dict() dbapi.update_container(context, self.container_type, self.uuid, updates) self.obj_reset_changes()