Move a set of nodes at once

Before this patch octane made separate calls to move nodes one by one.

Change-Id: I999a98d57b3184d35972e4862fcb4f284a066e9e
Related-Bug: #1616925
This commit is contained in:
Ilya Kharin 2016-09-03 01:04:10 +03:00
parent 21ab16ccfc
commit 9a4817174e
3 changed files with 19 additions and 10 deletions

View File

@ -25,12 +25,14 @@ class EnvMoveNode(env_commands.EnvMixIn, base.BaseCommand):
parser.add_argument('--roles', nargs='?',
help="Assign the given roles to the node (a comma "
"separated list of roles).")
parser.add_argument('node_id',
type=int,
help='ID of the node to upgrade.')
parser.add_argument('env_id',
type=str,
help='ID of the environment.')
parser.add_argument('nodes_ids',
type=int,
metavar='node-id',
nargs='+',
help='IDs of the nodes to upgrade.')
return parser
def take_action(self, parsed_args):
@ -38,7 +40,7 @@ class EnvMoveNode(env_commands.EnvMixIn, base.BaseCommand):
# fuelclient.objects.Environment the connection
# will be called directly.
data = {
'node_id': parsed_args.node_id,
'nodes_ids': parsed_args.nodes_ids,
'reprovision': parsed_args.provision,
}
if parsed_args.roles:
@ -47,9 +49,9 @@ class EnvMoveNode(env_commands.EnvMixIn, base.BaseCommand):
"clusters/{0}/upgrade/assign".format(parsed_args.env_id),
data,
)
msg = ('Node {node_id} successfully relocated to the environment'
msg = ('Nodes {nodes_ids} successfully relocated to the environment'
' {env_id}.\n'.format(
node_id=parsed_args.node_id,
nodes_ids=parsed_args.nodes_ids,
env_id=parsed_args.env_id,
))
self.app.stdout.write(msg)

View File

@ -232,7 +232,7 @@ def test_incompatible_provision_method(mocker,
@pytest.mark.parametrize("provision,compat", [
(True, True,),
(True, True),
(False, True),
])
def test_move_nodes(mocker, mock_subprocess, provision, compat):
@ -242,9 +242,11 @@ def test_move_nodes(mocker, mock_subprocess, provision, compat):
}
nodes = [mock.Mock(), mock.Mock()]
for idx, node in enumerate(nodes):
for idx, node in enumerate(nodes, 1):
node.data = {'id': str(idx)}
mock_move_nodes = mocker.patch(
"octane.util.env.fuel2_env_call")
mock_create_configdrive = mocker.patch(
"octane.util.disk.create_configdrive_partition")
mock_wait_for = mocker.patch(
@ -257,7 +259,11 @@ def test_move_nodes(mocker, mock_subprocess, provision, compat):
assert mock_create_configdrive.call_args_list == \
[mock.call(node) for node in nodes]
mock_wait_for.assert_called_once_with(nodes, 'provisioned')
mock_move_nodes.assert_called_once_with(
["move", "node", "test-id", "1", "2"])
else:
mock_move_nodes.assert_called_once_with(
["move", "node", "--no-provision", "test-id", "1", "2"])
assert mock_create_configdrive.call_args_list == []
assert mock_wait_for.call_args_list == []

View File

@ -181,12 +181,13 @@ def move_nodes(env, nodes, provision=True, roles=None):
cmd += ['--no-provision']
if roles:
cmd += ['--roles', ','.join(roles)]
cmd.append(str(env_id))
for node in nodes:
node_id = node.data['id']
cmd_move_node = cmd + [str(node_id), str(env_id)]
cmd.append(str(node_id))
if provision and incompatible_provision_method(env):
disk.create_configdrive_partition(node)
fuel2_env_call(cmd_move_node)
fuel2_env_call(cmd)
if provision:
LOG.info("Nodes provision started. Please wait...")
wait_for_nodes(nodes, "provisioned")