Fix parameter update for custom roles
When updating parameters for roles, a fixed set of parameters based on the standard roles (Compute, Control, Ceph-Storage, ...) was used to name the count and flavor params. This didn't account for custom roles. This patch changes this to derive the parameter names based on convention, so updating count/flavor params for custom roles doesn't break. Change-Id: Iee172782ed8faa1eb077f43132083e5c6af67250 Closes-Bug: #1643882
This commit is contained in:
parent
618bf6fae8
commit
10ee43e413
76
tripleo_common/tests/utils/test_parameters.py
Normal file
76
tripleo_common/tests/utils/test_parameters.py
Normal file
@ -0,0 +1,76 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from tripleo_common.tests import base
|
||||
from tripleo_common.utils import parameters
|
||||
|
||||
|
||||
class ParametersTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.utils.parameters.get_node_count')
|
||||
@mock.patch('tripleo_common.utils.parameters.get_flavor')
|
||||
def test_set_count_and_flavor_params_for_controller(self,
|
||||
mock_get_flavor,
|
||||
mock_get_node_count):
|
||||
mock_get_node_count.return_value = 1
|
||||
mock_get_flavor.return_value = 'control'
|
||||
expected = {
|
||||
'ControllerCount': 1,
|
||||
'OvercloudControlFlavor': 'control'
|
||||
}
|
||||
params = parameters.set_count_and_flavor_params('control', 1, 1)
|
||||
self.assertEqual(expected, params)
|
||||
|
||||
@mock.patch('tripleo_common.utils.parameters.get_node_count')
|
||||
@mock.patch('tripleo_common.utils.parameters.get_flavor')
|
||||
def test_set_count_and_flavor_params_for_swift(self,
|
||||
mock_get_flavor,
|
||||
mock_get_node_count):
|
||||
mock_get_node_count.return_value = 1
|
||||
mock_get_flavor.return_value = 'swift-storage'
|
||||
expected = {
|
||||
'ObjectStorageCount': 1,
|
||||
'OvercloudSwiftStorageFlavor': 'swift-storage'
|
||||
}
|
||||
params = parameters.set_count_and_flavor_params('object-storage', 1, 1)
|
||||
self.assertEqual(expected, params)
|
||||
|
||||
@mock.patch('tripleo_common.utils.parameters.get_node_count')
|
||||
@mock.patch('tripleo_common.utils.parameters.get_flavor')
|
||||
def test_set_count_and_flavor_params_for_role(self,
|
||||
mock_get_flavor,
|
||||
mock_get_node_count):
|
||||
mock_get_node_count.return_value = 1
|
||||
mock_get_flavor.return_value = 'ceph-storage'
|
||||
expected = {
|
||||
'CephStorageCount': 1,
|
||||
'OvercloudCephStorageFlavor': 'ceph-storage'
|
||||
}
|
||||
params = parameters.set_count_and_flavor_params('ceph-storage', 1, 1)
|
||||
self.assertEqual(expected, params)
|
||||
|
||||
@mock.patch('tripleo_common.utils.parameters.get_node_count')
|
||||
@mock.patch('tripleo_common.utils.parameters.get_flavor')
|
||||
def test_set_count_and_flavor_params_for_custom_role(self,
|
||||
mock_get_flavor,
|
||||
mock_get_node_count):
|
||||
mock_get_node_count.return_value = 1
|
||||
mock_get_flavor.return_value = 'custom-role'
|
||||
expected = {
|
||||
'MyCustomRoleCount': 1,
|
||||
'OvercloudMyCustomRoleFlavor': 'custom-role'
|
||||
}
|
||||
params = parameters.set_count_and_flavor_params('my-custom-role', 1, 1)
|
||||
self.assertEqual(expected, params)
|
@ -16,26 +16,15 @@
|
||||
|
||||
from tripleo_common.utils import nodes
|
||||
|
||||
PARAMS = {
|
||||
|
||||
PARAM_EXCEPTIONS = {
|
||||
'control': {
|
||||
'count': 'ControllerCount',
|
||||
'flavor': 'OvercloudControlFlavor'
|
||||
},
|
||||
'compute': {
|
||||
'count': 'ComputeCount',
|
||||
'flavor': 'OvercloudComputeFlavor'
|
||||
},
|
||||
'block-storage': {
|
||||
'count': 'BlockStorageCount',
|
||||
'flavor': 'OvercloudBlockStorageFlavor'
|
||||
},
|
||||
'object-storage': {
|
||||
'count': 'ObjectStorageCount',
|
||||
'flavor': 'OvercloudSwiftStorageFlavor'
|
||||
},
|
||||
'ceph-storage': {
|
||||
'count': 'CephStorageCount',
|
||||
'flavor': 'OvercloudCephStorageFlavor'
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +48,25 @@ def get_flavor(role, compute_client):
|
||||
return 'baremetal'
|
||||
|
||||
|
||||
def _get_count_key(role):
|
||||
return '%sCount' % role.title().replace('-', '')
|
||||
|
||||
|
||||
def _get_flavor_key(role):
|
||||
return 'Overcloud%sFlavor' % role.title().replace('-', '')
|
||||
|
||||
|
||||
def set_count_and_flavor_params(role, baremetal_client, compute_client):
|
||||
"""Returns the parameters for role count and flavor.
|
||||
|
||||
The parameter names are derived from the role name:
|
||||
|
||||
<camel case role name, no hyphens>Count
|
||||
Overcloud<camel case role name, no hyphens>Flavor
|
||||
|
||||
Exceptions from this rule (the control and object-storage roles) are
|
||||
defined in the PARAM_EXCEPTIONS dict.
|
||||
"""
|
||||
node_count = get_node_count(role, baremetal_client)
|
||||
|
||||
if node_count == 0:
|
||||
@ -67,7 +74,12 @@ def set_count_and_flavor_params(role, baremetal_client, compute_client):
|
||||
else:
|
||||
flavor = get_flavor(role, compute_client)
|
||||
|
||||
if role in PARAM_EXCEPTIONS:
|
||||
return {
|
||||
PARAM_EXCEPTIONS[role]['count']: node_count,
|
||||
PARAM_EXCEPTIONS[role]['flavor']: flavor
|
||||
}
|
||||
return {
|
||||
PARAMS[role]['count']: node_count,
|
||||
PARAMS[role]['flavor']: flavor
|
||||
_get_count_key(role): node_count,
|
||||
_get_flavor_key(role): flavor
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user