Merge "Allow update host API to add new extra capabilities"

This commit is contained in:
Jenkins 2017-08-21 04:43:25 +00:00 committed by Gerrit Code Review
commit a47dfb107f
3 changed files with 37 additions and 8 deletions

View File

@ -302,8 +302,6 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
return None
def update_computehost(self, host_id, values):
# NOTE (sbauza): Only update existing extra capabilites, don't create
# other ones
if values:
cant_update_extra_capability = []
for value in values:
@ -311,17 +309,29 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
host_id,
value,
)
for raw_capability in capabilities:
capability = {
if capabilities:
for raw_capability in capabilities:
capability = {
'capability_name': value,
'capability_value': values[value],
}
try:
db_api.host_extra_capability_update(
raw_capability['id'], capability)
except (db_ex.BlazarDBException, RuntimeError):
cant_update_extra_capability.append(
raw_capability['capability_name'])
else:
new_capability = {
'computehost_id': host_id,
'capability_name': value,
'capability_value': values[value],
}
try:
db_api.host_extra_capability_update(
raw_capability['id'], capability)
except RuntimeError:
db_api.host_extra_capability_create(new_capability)
except (db_ex.BlazarDBException, RuntimeError):
cant_update_extra_capability.append(
raw_capability['capability_name'])
new_capability['capability_name'])
if cant_update_extra_capability:
raise manager_ex.CantAddExtraCapability(
host=host_id,

View File

@ -267,6 +267,18 @@ class PhysicalHostPluginTestCase(tests.TestCase):
self.fake_phys_plugin.update_computehost,
self.fake_host_id, host_values)
def test_update_host_with_new_extra_capability(self):
host_values = {'buzz': 'word'}
self.db_host_extra_capability_get_all_per_name.return_value = []
self.fake_phys_plugin.update_computehost(self.fake_host_id,
host_values)
self.db_host_extra_capability_create.assert_called_once_with({
'computehost_id': '1',
'capability_name': 'buzz',
'capability_value': 'word'
})
def test_delete_host(self):
self.fake_phys_plugin.delete_computehost(self.fake_host_id)

View File

@ -0,0 +1,7 @@
---
features:
- |
The update host API now allows new extra capabilities to be created on
existing hosts, in addition to allowing values of existing keys to be
modified. However, extra capabilities cannot yet be removed due to lack of
API support. As a workaround, operators can delete hosts and recreate them.