Add function for checking sanity of nodes to upgrade
Move sanity checks logic for upgrading node into separate function. Change-Id: Ifa46753f0bed18a0e25887c2a07445145011dad4 Related-bug: 1583063
This commit is contained in:
parent
99f06d545e
commit
86a7e912a3
|
@ -26,15 +26,10 @@ from octane.util import patch
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def upgrade_node(env_id, node_ids, isolated=False, network_template=None,
|
||||
provision=True, roles=None, live_migration=True):
|
||||
# From check_deployment_status
|
||||
env = environment_obj.Environment(env_id)
|
||||
nodes = [node_obj.Node(node_id) for node_id in node_ids]
|
||||
|
||||
# Sanity check
|
||||
def check_sanity(env_id, nodes):
|
||||
one_orig_id = None
|
||||
for node in nodes:
|
||||
node_id = node.data['id']
|
||||
orig_id = node.data['cluster']
|
||||
if orig_id == env_id:
|
||||
raise Exception(
|
||||
|
@ -48,14 +43,16 @@ def upgrade_node(env_id, node_ids, isolated=False, network_template=None,
|
|||
orig_id, one_orig_id,
|
||||
)
|
||||
one_orig_id = orig_id
|
||||
# NOTE(ogelbukh): Another sanity check: we can't upgrade single controller
|
||||
# except the first one, otherwise deployment fails
|
||||
# TODO(ogelbukh): Investigate and solve the root cause of the issue that
|
||||
# prevents upgrade of a single controller
|
||||
if not isolated and len(nodes) == 1 and \
|
||||
'controller' in nodes[0].data['roles']:
|
||||
raise Exception("Cannot upgrade single non-isolated controller {0}"
|
||||
.format(nodes[0].data['id']))
|
||||
|
||||
|
||||
def upgrade_node(env_id, node_ids, isolated=False, network_template=None,
|
||||
provision=True, roles=None, live_migration=True):
|
||||
# From check_deployment_status
|
||||
env = environment_obj.Environment(env_id)
|
||||
nodes = [node_obj.Node(node_id) for node_id in node_ids]
|
||||
|
||||
check_sanity(env_id, nodes)
|
||||
|
||||
# NOTE(ogelbukh): patches and scripts copied to nailgun container
|
||||
# for later use
|
||||
copy_patches_folder_to_nailgun()
|
||||
|
|
|
@ -89,3 +89,39 @@ def test_upgrade_node(mocker, node_ids, isolated, network_template,
|
|||
mock_deploy_nodes.assert_called_once()
|
||||
else:
|
||||
mock_deploy_changes.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('node_data,expected_error', [
|
||||
([{
|
||||
'id': 'test-node',
|
||||
'cluster': None,
|
||||
}], None),
|
||||
([{
|
||||
'id': 'test-node',
|
||||
'cluster': 'test-env',
|
||||
}], Exception),
|
||||
([{
|
||||
'id': 'test-node',
|
||||
'cluster': 'test-env-1',
|
||||
}, {
|
||||
'id': 'another-test-node',
|
||||
'cluster': 'test-env-2'
|
||||
}], Exception),
|
||||
])
|
||||
def test_check_sanity(mocker, node, node_data, expected_error):
|
||||
test_env_id = "test-env"
|
||||
mock_nodes = []
|
||||
for data in node_data:
|
||||
mock_node = mocker.Mock(data=data)
|
||||
mock_nodes.append(mock_node)
|
||||
if expected_error:
|
||||
with pytest.raises(expected_error) as exc_info:
|
||||
upgrade_node.check_sanity(test_env_id, mock_nodes)
|
||||
if len(mock_nodes) == 1:
|
||||
assert "Cannot upgrade node with ID %s:" \
|
||||
in exc_info.value.args[0]
|
||||
else:
|
||||
assert "Not upgrading nodes from different clusters" \
|
||||
in exc_info.value.args[0]
|
||||
else:
|
||||
assert upgrade_node.check_sanity(test_env_id, mock_nodes) is None
|
||||
|
|
Loading…
Reference in New Issue