Merge "Remove the unused, but well tested, function "check_nodes_count""
This commit is contained in:
commit
ee25a7bb01
@ -191,119 +191,6 @@ class TestWaitForStackUtil(TestCase):
|
||||
self.assertRaises(ValueError, utils.file_checksum, '/dev/zero')
|
||||
|
||||
|
||||
class TestCheckNodesCountCreate(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.baremetal = mock.Mock()
|
||||
self.defaults = {
|
||||
'ControllerCount': 1,
|
||||
'ComputeCount': 1,
|
||||
'ObjectStorageCount': 0,
|
||||
'BlockStorageCount': 0,
|
||||
'CephStorageCount': 0,
|
||||
}
|
||||
self.stack = None
|
||||
|
||||
def ironic_node_list(*args, **kwargs):
|
||||
if kwargs.get('associated') is True:
|
||||
nodes = range(2)
|
||||
elif kwargs.get('maintenance') is False:
|
||||
nodes = range(1)
|
||||
return nodes
|
||||
self.baremetal.node.list.side_effect = ironic_node_list
|
||||
|
||||
def test_check_nodes_count_deploy_enough_nodes(self):
|
||||
user_params = {'ControllerCount': 2}
|
||||
self.assertEqual((True, 3, 3),
|
||||
utils.check_nodes_count(self.baremetal, None,
|
||||
user_params, self.defaults))
|
||||
|
||||
def test_check_nodes_count_deploy_too_much(self):
|
||||
user_params = {'ControllerCount': 3}
|
||||
self.assertEqual((False, 4, 3),
|
||||
utils.check_nodes_count(self.baremetal, None,
|
||||
user_params, self.defaults))
|
||||
|
||||
def test_check_nodes_count_scale_enough_nodes(self):
|
||||
user_params = {'ControllerCount': 2}
|
||||
self.assertEqual((True, 3, 3),
|
||||
utils.check_nodes_count(self.baremetal, self.stack,
|
||||
user_params, self.defaults))
|
||||
|
||||
def test_check_nodes_count_scale_too_much(self):
|
||||
user_params = {'ControllerCount': 3}
|
||||
self.assertEqual((False, 4, 3),
|
||||
utils.check_nodes_count(self.baremetal, self.stack,
|
||||
user_params, self.defaults))
|
||||
|
||||
|
||||
class TestCheckNodesCountUpdate(TestCheckNodesCountCreate):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCheckNodesCountUpdate, self).setUp()
|
||||
self.stack = mock.Mock(parameters=self.defaults)
|
||||
|
||||
def test_check_default_param_not_in_stack(self):
|
||||
user_params = {'ControllerCount': 3}
|
||||
missing_param = 'CephStorageCount'
|
||||
self.stack.parameters = self.defaults.copy()
|
||||
del self.stack.parameters[missing_param]
|
||||
|
||||
self.assertEqual((False, 4, 3),
|
||||
utils.check_nodes_count(self.baremetal, self.stack,
|
||||
user_params, self.defaults))
|
||||
|
||||
|
||||
class TestCheckNodesCountCustomRolesCreate(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.baremetal = mock.Mock()
|
||||
self.custom_roles_defaults = {
|
||||
'ControllerApiCount': 3,
|
||||
'ControllerPacemakerCount': 3,
|
||||
'ComputeDvrCount': 3
|
||||
}
|
||||
self.stack = None
|
||||
|
||||
def ironic_node_list(*args, **kwargs):
|
||||
if kwargs.get('associated') is True:
|
||||
nodes = range(2)
|
||||
elif kwargs.get('maintenance') is False:
|
||||
nodes = range(9)
|
||||
return nodes
|
||||
self.baremetal.node.list.side_effect = ironic_node_list
|
||||
|
||||
def test_check_nodes_count_custom_roles_scale_enough_nodes(self):
|
||||
user_params = {
|
||||
'ControllerApiCount': 3,
|
||||
'ControllerPacemakerCount': 3,
|
||||
'ComputeDvrCount': 3
|
||||
}
|
||||
self.assertEqual((True, 9, 11),
|
||||
utils.check_nodes_count(self.baremetal, self.stack,
|
||||
user_params,
|
||||
self.custom_roles_defaults))
|
||||
|
||||
def test_check_nodes_count_custom_roles_scale_too_much(self):
|
||||
user_params = {
|
||||
'ControllerApiCount': 3,
|
||||
'ControllerPacemakerCount': 3,
|
||||
'ComputeDvrCount': 6
|
||||
}
|
||||
self.assertEqual((False, 12, 11),
|
||||
utils.check_nodes_count(self.baremetal, self.stack,
|
||||
user_params,
|
||||
self.custom_roles_defaults))
|
||||
|
||||
|
||||
class TestCheckNodesCountCustomRolesUpdate(
|
||||
TestCheckNodesCountCustomRolesCreate):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCheckNodesCountCustomRolesUpdate, self).setUp()
|
||||
self.stack = mock.Mock(parameters=self.custom_roles_defaults)
|
||||
|
||||
|
||||
class TestEnsureRunAsNormalUser(TestCase):
|
||||
|
||||
@mock.patch('os.geteuid')
|
||||
|
@ -607,7 +607,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.check_nodes_count', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
'_deploy_postconfig', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
@ -617,9 +616,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
@mock.patch('shutil.copytree', autospec=True)
|
||||
def test_environment_dirs(self, mock_copy, mock_deploy_heat,
|
||||
mock_update_parameters, mock_post_config,
|
||||
mock_utils_check_nodes, mock_utils_endpoint,
|
||||
mock_utils_createrc, mock_utils_tempest,
|
||||
mock_tarball):
|
||||
mock_utils_endpoint, mock_utils_createrc,
|
||||
mock_utils_tempest, mock_tarball):
|
||||
|
||||
clients = self.app.client_manager
|
||||
workflow_client = clients.workflow_engine
|
||||
@ -669,7 +667,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.get_stack', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.check_nodes_count', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
'_deploy_postconfig', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
@ -679,9 +676,9 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
@mock.patch('shutil.copytree', autospec=True)
|
||||
def test_environment_dirs_env(self, mock_copy, mock_deploy_heat,
|
||||
mock_update_parameters, mock_post_config,
|
||||
mock_utils_check_nodes, mock_utils_get_stack,
|
||||
mock_utils_endpoint, mock_utils_createrc,
|
||||
mock_utils_tempest, mock_tarball):
|
||||
mock_utils_get_stack, mock_utils_endpoint,
|
||||
mock_utils_createrc, mock_utils_tempest,
|
||||
mock_tarball):
|
||||
|
||||
clients = self.app.client_manager
|
||||
workflow_client = clients.workflow_engine
|
||||
@ -728,7 +725,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.check_nodes_count', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
'_deploy_postconfig', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
@ -740,7 +736,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
mock_deploy_heat,
|
||||
mock_update_parameters,
|
||||
mock_post_config,
|
||||
mock_utils_check_nodes,
|
||||
mock_utils_endpoint,
|
||||
mock_utils_createrc,
|
||||
mock_utils_tempest,
|
||||
@ -998,8 +993,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
|
||||
@mock.patch('tripleoclient.workflows.plan_management.tarball',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.utils.check_nodes_count',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.utils.create_tempest_deployer_input',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
|
||||
@ -1014,7 +1007,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
mock_oc_endpoint,
|
||||
mock_create_ocrc,
|
||||
mock_create_tempest_deployer_input,
|
||||
mock_check_nodes_count, mock_tarball):
|
||||
mock_tarball):
|
||||
clients = self.app.client_manager
|
||||
|
||||
workflow_client = clients.workflow_engine
|
||||
|
@ -387,38 +387,6 @@ def file_checksum(filepath):
|
||||
return checksum.hexdigest()
|
||||
|
||||
|
||||
def check_nodes_count(baremetal_client, stack, parameters, defaults):
|
||||
"""Check if there are enough available nodes for creating/scaling stack"""
|
||||
count = 0
|
||||
|
||||
for param, default in defaults.items():
|
||||
if stack:
|
||||
try:
|
||||
current = int(stack.parameters[param])
|
||||
except KeyError:
|
||||
# We could be adding a new role on stack-update, so there's no
|
||||
# assumption the parameter exists in the stack.
|
||||
current = parameters.get(param, default)
|
||||
count += parameters.get(param, current)
|
||||
else:
|
||||
count += parameters.get(param, default)
|
||||
|
||||
# We get number of nodes usable for the stack by getting already
|
||||
# used (associated) nodes and number of nodes which can be used
|
||||
# (not in maintenance mode).
|
||||
# Assumption is that associated nodes are part of the stack (only
|
||||
# one overcloud is supported).
|
||||
associated = len(baremetal_client.node.list(associated=True))
|
||||
available = len(baremetal_client.node.list(associated=False,
|
||||
maintenance=False))
|
||||
ironic_nodes_count = associated + available
|
||||
|
||||
if count > ironic_nodes_count:
|
||||
return False, count, ironic_nodes_count
|
||||
else:
|
||||
return True, count, ironic_nodes_count
|
||||
|
||||
|
||||
def ensure_run_as_normal_user():
|
||||
"""Check if the command runs under normal user (EUID!=0)"""
|
||||
if os.geteuid() == 0:
|
||||
|
Loading…
Reference in New Issue
Block a user