Skip to content

Commit

Permalink
Merge branch 'unique-node-name' of github.com:ChameleonCloud/blazar i…
Browse files Browse the repository at this point in the history
…nto unique-node-name-devstack-fixes

Change-Id: I60b452cc7cfbb435b82013f5b27bf02fb003b161
  • Loading branch information
AnishReddyRavula committed Mar 19, 2024
2 parents b8feea7 + 4761fa7 commit a066c0f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions blazar/db/sqlalchemy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,7 @@ def resource_properties_list(resource_type):
models.ExtraCapability.capability_name,
models.ExtraCapability.private,
resource_model.capability_value,
models.ExtraCapability.is_unique,
).join(resource_model), resource_model, deleted=False).distinct()

return query.all()
Expand Down
11 changes: 7 additions & 4 deletions blazar/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,19 @@ def to_dict(self):

@validates('capability_value')
def validate_capability_value(self, key, capability_value):
extra_capability = ExtraCapability.query.filter_by(id=self.capability_id).first()
from blazar.db.sqlalchemy import facade_wrapper
session = facade_wrapper.get_session()
extra_capability = session.query(ExtraCapability).filter_by(id=self.capability_id).first()
if extra_capability and extra_capability.is_unique:
existing_capability = (
self.query.filter_by(computehost_id=self.computehost_id,
session.query(ComputeHostExtraCapability).filter_by(computehost_id=self.computehost_id,
capability_id=self.capability_id).first()
)
if existing_capability:
raise ValueError(
f"{extra_capability.capability_name} is not unique "
f"for compute_host {self.computehost_id}"
f"{extra_capability.capability_name} must be unique. "
f"Please select unique {extra_capability.capability_name} for "
f"{self.computehost_id}"
)
return capability_value

Expand Down
10 changes: 7 additions & 3 deletions blazar/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,20 @@ def on_start(self, resource_id, lease=None):
def list_resource_properties(self, query):
detail = False if not query else query.get('detail', False)
resource_properties = collections.defaultdict(list)
is_property_unique = {}

for name, private, value in db_api.resource_properties_list(
for name, private, value, is_unique in db_api.resource_properties_list(
self.resource_type):

if not private:
resource_properties[name].append(value)
is_property_unique[name] = is_unique

if detail:
return [
dict(property=k, private=False, values=v)
dict(
property=k, private=False, values=v,
is_unique=is_property_unique[k]
)
for k, v in resource_properties.items()]
else:
return [dict(property=k) for k, v in resource_properties.items()]
Expand Down
2 changes: 1 addition & 1 deletion blazar/tests/db/sqlalchemy/test_sqlalchemy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def test_resource_properties_list(self):

result = db_api.resource_properties_list('physical:host')

self.assertListEqual(result, [('vgpu', False, '2')])
self.assertListEqual(result, [('vgpu', False, '2', False)])

def test_search_for_hosts_by_composed_queries(self):
"""Create one host and test composed queries."""
Expand Down
22 changes: 11 additions & 11 deletions blazar/tests/plugins/networks/test_network_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,11 @@ def test_list_resource_properties(self):

# Expecting a list of (Reservation, Allocation)
self.db_list_resource_properties.return_value = [
('prop1', False, 'aaa'),
('prop1', False, 'bbb'),
('prop2', False, 'aaa'),
('prop2', False, 'aaa'),
('prop3', True, 'aaa')
('prop1', False, 'aaa', False),
('prop1', False, 'bbb', False),
('prop2', False, 'aaa', False),
('prop2', False, 'aaa', False),
('prop3', True, 'aaa', False)
]

expected = [
Expand All @@ -1063,15 +1063,15 @@ def test_list_resource_properties_with_detail(self):

# Expecting a list of (Reservation, Allocation)
self.db_list_resource_properties.return_value = [
('prop1', False, 'aaa'),
('prop1', False, 'bbb'),
('prop2', False, 'ccc'),
('prop3', True, 'aaa')
('prop1', False, 'aaa', False),
('prop1', False, 'bbb', False),
('prop2', False, 'ccc', False),
('prop3', True, 'aaa', False)
]

expected = [
{'property': 'prop1', 'private': False, 'values': ['aaa', 'bbb']},
{'property': 'prop2', 'private': False, 'values': ['ccc']}
{'property': 'prop1', 'private': False, 'values': ['aaa', 'bbb'], 'is_unique': False},
{'property': 'prop2', 'private': False, 'values': ['ccc'], 'is_unique': False}
]

ret = self.fake_network_plugin.list_resource_properties(
Expand Down
26 changes: 13 additions & 13 deletions blazar/tests/plugins/oshosts/test_physical_host_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2549,16 +2549,16 @@ def test_list_resource_properties(self):

# Expecting a list of (Reservation, Allocation)
self.db_list_resource_properties.return_value = [
('prop1', False, 'aaa'),
('prop1', False, 'bbb'),
('prop2', False, 'aaa'),
('prop2', False, 'aaa'),
('prop3', True, 'aaa')
('prop1', False, 'aaa', False),
('prop1', False, 'bbb', False),
('prop2', False, 'aaa', False),
('prop2', False, 'aaa', False),
('prop3', True, 'aaa', False)
]

expected = [
{'property': 'prop1'},
{'property': 'prop2'}
{'property': 'prop1',},
{'property': 'prop2',}
]

ret = self.fake_phys_plugin.list_resource_properties(
Expand All @@ -2577,15 +2577,15 @@ def test_list_resource_properties_with_detail(self):

# Expecting a list of (Reservation, Allocation)
self.db_list_resource_properties.return_value = [
('prop1', False, 'aaa'),
('prop1', False, 'bbb'),
('prop2', False, 'ccc'),
('prop3', True, 'aaa')
('prop1', False, 'aaa', False),
('prop1', False, 'bbb', False),
('prop2', False, 'ccc', False),
('prop3', True, 'aaa', False)
]

expected = [
{'property': 'prop1', 'private': False, 'values': ['aaa', 'bbb']},
{'property': 'prop2', 'private': False, 'values': ['ccc']}
{'property': 'prop1', 'private': False, 'values': ['aaa', 'bbb'], 'is_unique': False},
{'property': 'prop2', 'private': False, 'values': ['ccc'], 'is_unique': False}
]

ret = self.fake_phys_plugin.list_resource_properties(
Expand Down

0 comments on commit a066c0f

Please sign in to comment.