Merge "Remove old flavor_access_get_by_flavor_id db api method"
This commit is contained in:
commit
7d33930ff5
|
@ -1572,17 +1572,6 @@ def flavor_extra_specs_delete(context, flavor_id, key):
|
||||||
"""Delete the given extra specs item."""
|
"""Delete the given extra specs item."""
|
||||||
IMPL.flavor_extra_specs_delete(context, flavor_id, key)
|
IMPL.flavor_extra_specs_delete(context, flavor_id, key)
|
||||||
|
|
||||||
|
|
||||||
def flavor_extra_specs_update_or_create(context, flavor_id,
|
|
||||||
extra_specs):
|
|
||||||
"""Create or update instance type extra specs.
|
|
||||||
|
|
||||||
This adds or modifies the key/value pairs specified in the
|
|
||||||
extra specs dict argument
|
|
||||||
"""
|
|
||||||
IMPL.flavor_extra_specs_update_or_create(context, flavor_id,
|
|
||||||
extra_specs)
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4847,47 +4847,6 @@ def flavor_extra_specs_delete(context, flavor_id, key):
|
||||||
extra_specs_key=key, flavor_id=flavor_id)
|
extra_specs_key=key, flavor_id=flavor_id)
|
||||||
|
|
||||||
|
|
||||||
@require_context
|
|
||||||
@pick_context_manager_writer
|
|
||||||
def flavor_extra_specs_update_or_create(context, flavor_id, specs,
|
|
||||||
max_retries=10):
|
|
||||||
for attempt in range(max_retries):
|
|
||||||
try:
|
|
||||||
instance_type_id = _flavor_get_id_from_flavor(context, flavor_id)
|
|
||||||
|
|
||||||
spec_refs = model_query(context, models.InstanceTypeExtraSpecs,
|
|
||||||
read_deleted="no").\
|
|
||||||
filter_by(instance_type_id=instance_type_id).\
|
|
||||||
filter(models.InstanceTypeExtraSpecs.key.in_(specs.keys())).\
|
|
||||||
all()
|
|
||||||
|
|
||||||
existing_keys = set()
|
|
||||||
for spec_ref in spec_refs:
|
|
||||||
key = spec_ref["key"]
|
|
||||||
existing_keys.add(key)
|
|
||||||
with get_context_manager(context).writer.savepoint.using(
|
|
||||||
context):
|
|
||||||
spec_ref.update({"value": specs[key]})
|
|
||||||
|
|
||||||
for key, value in specs.items():
|
|
||||||
if key in existing_keys:
|
|
||||||
continue
|
|
||||||
spec_ref = models.InstanceTypeExtraSpecs()
|
|
||||||
with get_context_manager(context).writer.savepoint.using(
|
|
||||||
context):
|
|
||||||
spec_ref.update({"key": key, "value": value,
|
|
||||||
"instance_type_id": instance_type_id})
|
|
||||||
context.session.add(spec_ref)
|
|
||||||
|
|
||||||
return specs
|
|
||||||
except db_exc.DBDuplicateEntry:
|
|
||||||
# a concurrent transaction has been committed,
|
|
||||||
# try again unless this was the last attempt
|
|
||||||
if attempt == max_retries - 1:
|
|
||||||
raise exception.FlavorExtraSpecUpdateCreateFailed(
|
|
||||||
id=flavor_id, retries=max_retries)
|
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4109,16 +4109,6 @@ class InstanceTypeTestCase(BaseInstanceTypeTestCase):
|
||||||
ignored_keys)
|
ignored_keys)
|
||||||
self._assertEqualObjects(extra_specs, flavor['extra_specs'])
|
self._assertEqualObjects(extra_specs, flavor['extra_specs'])
|
||||||
|
|
||||||
@mock.patch('sqlalchemy.orm.query.Query.all', return_value=[])
|
|
||||||
def test_flavor_create_with_extra_specs_duplicate(self, mock_all):
|
|
||||||
extra_specs = dict(key='value')
|
|
||||||
flavorid = 'flavorid'
|
|
||||||
self._create_flavor({'flavorid': flavorid, 'extra_specs': extra_specs})
|
|
||||||
|
|
||||||
self.assertRaises(exception.FlavorExtraSpecUpdateCreateFailed,
|
|
||||||
db.flavor_extra_specs_update_or_create,
|
|
||||||
self.ctxt, flavorid, extra_specs)
|
|
||||||
|
|
||||||
def test_flavor_get_all(self):
|
def test_flavor_get_all(self):
|
||||||
# NOTE(boris-42): Remove base instance types
|
# NOTE(boris-42): Remove base instance types
|
||||||
for it in db.flavor_get_all(self.ctxt):
|
for it in db.flavor_get_all(self.ctxt):
|
||||||
|
@ -4404,37 +4394,6 @@ class InstanceTypeExtraSpecsTestCase(BaseInstanceTypeTestCase):
|
||||||
db.flavor_extra_specs_delete,
|
db.flavor_extra_specs_delete,
|
||||||
self.ctxt, it['flavorid'], 'dummy')
|
self.ctxt, it['flavorid'], 'dummy')
|
||||||
|
|
||||||
def test_flavor_extra_specs_update_or_create(self):
|
|
||||||
for it in self.flavors:
|
|
||||||
current_specs = it['extra_specs']
|
|
||||||
current_specs.update(dict(b='b1', c='c1', d='d1', e='e1'))
|
|
||||||
params = (self.ctxt, it['flavorid'], current_specs)
|
|
||||||
db.flavor_extra_specs_update_or_create(*params)
|
|
||||||
real_specs = db.flavor_extra_specs_get(self.ctxt, it['flavorid'])
|
|
||||||
self._assertEqualObjects(current_specs, real_specs)
|
|
||||||
|
|
||||||
def test_flavor_extra_specs_update_or_create_flavor_not_found(self):
|
|
||||||
self.assertRaises(exception.FlavorNotFound,
|
|
||||||
db.flavor_extra_specs_update_or_create,
|
|
||||||
self.ctxt, 'nonexists', {})
|
|
||||||
|
|
||||||
def test_flavor_extra_specs_update_or_create_retry(self):
|
|
||||||
|
|
||||||
def counted():
|
|
||||||
def get_id(context, flavorid):
|
|
||||||
get_id.counter += 1
|
|
||||||
raise db_exc.DBDuplicateEntry
|
|
||||||
get_id.counter = 0
|
|
||||||
return get_id
|
|
||||||
|
|
||||||
get_id = counted()
|
|
||||||
self.stub_out('nova.db.sqlalchemy.api._flavor_get_id_from_flavor',
|
|
||||||
get_id)
|
|
||||||
self.assertRaises(exception.FlavorExtraSpecUpdateCreateFailed,
|
|
||||||
sqlalchemy_api.flavor_extra_specs_update_or_create,
|
|
||||||
self.ctxt, 1, {}, 5)
|
|
||||||
self.assertEqual(get_id.counter, 5)
|
|
||||||
|
|
||||||
|
|
||||||
class InstanceTypeAccessTestCase(BaseInstanceTypeTestCase):
|
class InstanceTypeAccessTestCase(BaseInstanceTypeTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue