"""Remove given tenant from the volume type access list."""
volume_type_id = _volume_type_get_id_from_volume_type(context, type_id)
- count = _volume_type_access_query(context).\
- filter_by(volume_type_id=volume_type_id).\
- filter_by(project_id=project_id).\
- soft_delete(synchronize_session=False)
+ count = (_volume_type_access_query(context).
+ filter_by(volume_type_id=volume_type_id).
+ filter_by(project_id=project_id).
+ update({'deleted': True,
+ 'deleted_at': timeutils.utcnow(),
+ 'updated_at': literal_column('updated_at')}))
if count == 0:
raise exception.VolumeTypeAccessNotFound(
volume_type_id=type_id, project_id=project_id)
self.ctxt,
{'name': 'n2', 'id': vt['id']})
+ def test_volume_type_access_remove(self):
+ vt = db.volume_type_create(self.ctxt, {'name': 'n1'})
+ db.volume_type_access_add(self.ctxt, vt['id'], 'fake_project')
+ vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+ self.assertEqual(1, len(vtas))
+ db.volume_type_access_remove(self.ctxt, vt['id'], 'fake_project')
+ vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+ self.assertEqual(0, len(vtas))
+
+ def test_volume_type_access_remove_high_id(self):
+ vt = db.volume_type_create(self.ctxt, {'name': 'n1'})
+ vta = db.volume_type_access_add(self.ctxt, vt['id'], 'fake_project')
+ vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+ self.assertEqual(1, len(vtas))
+
+ # NOTE(dulek): Bug 1496747 uncovered problems when deleting accesses
+ # with id column higher than 128. This is regression test for that
+ # case.
+
+ session = sqlalchemy_api.get_session()
+ vta.id = 150
+ vta.save(session=session)
+ session.close()
+
+ db.volume_type_access_remove(self.ctxt, vt['id'], 'fake_project')
+ vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+ self.assertEqual(0, len(vtas))
+
def test_get_volume_type_extra_specs(self):
# Ensure that volume type extra specs can be accessed after
# the DB session is closed.