Fix flavor matching for object-storage role

When assigning a node to the `object-storage` role, the correct flavor
will not be picked, because there is a mismatch between the role name
and the flavor name (swift-storage).

This patch adds some logic to pick the correct flavor for the object
storage role.

Change-Id: Id3d5738361f791a3e1120ad3b51d8867c27e4456
Closes-Bug: #1644756
This commit is contained in:
Florian Fuchs 2016-11-28 21:52:31 +01:00
parent 540a80a715
commit b6e9412628
2 changed files with 56 additions and 1 deletions

View File

@ -74,3 +74,50 @@ class ParametersTest(base.TestCase):
}
params = parameters.set_count_and_flavor_params('my-custom-role', 1, 1)
self.assertEqual(expected, params)
def test_swift_flavor_detected(self):
compute_client = mock.MagicMock()
# Mock for a compute_client.flavors.list result item and
# compute_client.flavors.get
flavor = mock.MagicMock()
flavor.id = 1
flavor.name = 'swift-storage'
# Mock result of <flavor instance>.get_keys()
flavor_keys = mock.MagicMock()
flavor_keys.get.side_effect = ('swift-storage', )
# Connecting the mock instances...
flavor.get_keys.side_effect = (flavor_keys, )
compute_client.flavors.list.side_effect = ((flavor, ),)
compute_client.flavors.get.side_effect = (flavor, )
# Calling `get_flavor` with an 'object-storage' role should return
# the 'swift-storage' flavor.
self.assertEqual(parameters.get_flavor('object-storage',
compute_client),
'swift-storage')
def test_compute_flavor_detected(self):
compute_client = mock.MagicMock()
# Mock for a compute_client.flavors.list result item and
# compute_client.flavors.get
flavor = mock.MagicMock()
flavor.id = 1
flavor.name = 'compute'
# Mock result of <flavor instance>.get_keys()
flavor_keys = mock.MagicMock()
flavor_keys.get.side_effect = ('compute', )
# Connecting the mock instances...
flavor.get_keys.side_effect = (flavor_keys, )
compute_client.flavors.list.side_effect = ((flavor, ),)
compute_client.flavors.get.side_effect = (flavor, )
# Calling `get_flavor` with a 'compute' role should return
# the 'compute' flavor.
self.assertEqual(parameters.get_flavor('compute', compute_client),
'compute')

View File

@ -17,6 +17,10 @@
from tripleo_common.utils import nodes
FLAVOR_ROLE_EXCEPTIONS = {
'object-storage': 'swift-storage'
}
PARAM_EXCEPTIONS = {
'control': {
'count': 'ControllerCount',
@ -43,7 +47,11 @@ def get_node_count(role, baremetal_client):
def get_flavor(role, compute_client):
for f in compute_client.flavors.list():
flavor = compute_client.flavors.get(f.id)
if flavor.get_keys().get('capabilities:profile') == role:
# The flavor's capabilities:profile and the role must match,
# unless the role has a different profile name (as defined in
# FLAVOR_ROLE_EXCEPTIONS).
if (flavor.get_keys().get('capabilities:profile') ==
FLAVOR_ROLE_EXCEPTIONS.get(role, role)):
return flavor.name
return 'baremetal'