Rename node --master -> node --leader

This commit is contained in:
Branden Rolston
2016-03-16 19:36:43 -07:00
parent ba8d7ef443
commit e28b9588fd
4 changed files with 54 additions and 37 deletions

View File

@@ -3,12 +3,12 @@ Manage DCOS nodes
Usage: Usage:
dcos node --info dcos node --info
dcos node [--json] dcos node [--json]
dcos node log [--follow --lines=N --master --slave=<slave-id>] dcos node log [--follow --lines=N --leader --master --slave=<slave-id>]
dcos node ssh [--option SSHOPT=VAL ...] dcos node ssh [--option SSHOPT=VAL ...]
[--config-file=<path>] [--config-file=<path>]
[--user=<user>] [--user=<user>]
[--master-proxy] [--master-proxy]
(--master | --slave=<slave-id>) (--leader | --master | --slave=<slave-id>)
Options: Options:
-h, --help Show this screen -h, --help Show this screen
@@ -16,7 +16,8 @@ Options:
--json Print json-formatted nodes --json Print json-formatted nodes
--follow Print data as the file grows --follow Print data as the file grows
--lines=N Print the last N lines [default: 10] --lines=N Print the last N lines [default: 10]
--master Access the leading master --leader Access the leading master
--master Deprecated. Please use --leader.
--master-proxy Proxy the SSH connection through a master node. This can be useful when --master-proxy Proxy the SSH connection through a master node. This can be useful when
accessing DCOS from a separate network. For example, in the default AWS accessing DCOS from a separate network. For example, in the default AWS
configuration, the private slaves are unreachable from the public configuration, the private slaves are unreachable from the public

View File

@@ -29,6 +29,11 @@ def _main():
_doc(), _doc(),
version="dcos-node version {}".format(dcoscli.version)) version="dcos-node version {}".format(dcoscli.version))
if args.get('--master'):
raise DCOSException(
'--master has been deprecated. Please use --leader.'
)
return cmds.execute(_cmds(), args) return cmds.execute(_cmds(), args)
@@ -55,12 +60,12 @@ def _cmds():
cmds.Command( cmds.Command(
hierarchy=['node', 'log'], hierarchy=['node', 'log'],
arg_keys=['--follow', '--lines', '--master', '--slave'], arg_keys=['--follow', '--lines', '--leader', '--slave'],
function=_log), function=_log),
cmds.Command( cmds.Command(
hierarchy=['node', 'ssh'], hierarchy=['node', 'ssh'],
arg_keys=['--master', '--slave', '--option', '--config-file', arg_keys=['--leader', '--slave', '--option', '--config-file',
'--user', '--master-proxy'], '--user', '--master-proxy'],
function=_ssh), function=_ssh),
@@ -105,38 +110,38 @@ def _list(json_):
emitter.publish(errors.DefaultError('No slaves found.')) emitter.publish(errors.DefaultError('No slaves found.'))
def _log(follow, lines, master, slave): def _log(follow, lines, leader, slave):
""" Prints the contents of master and slave logs. """ Prints the contents of leader and slave logs.
:param follow: same as unix tail's -f :param follow: same as unix tail's -f
:type follow: bool :type follow: bool
:param lines: number of lines to print :param lines: number of lines to print
:type lines: int :type lines: int
:param master: whether to print the master log :param leader: whether to print the leading master's log
:type master: bool :type leader: bool
:param slave: the slave ID to print :param slave: the slave ID to print
:type slave: str | None :type slave: str | None
:returns: process return code :returns: process return code
:rtype: int :rtype: int
""" """
if not (master or slave): if not (leader or slave):
raise DCOSException('You must choose one of --master or --slave.') raise DCOSException('You must choose one of --leader or --slave.')
lines = util.parse_int(lines) lines = util.parse_int(lines)
mesos_files = _mesos_files(master, slave) mesos_files = _mesos_files(leader, slave)
log.log_files(mesos_files, follow, lines) log.log_files(mesos_files, follow, lines)
return 0 return 0
def _mesos_files(master, slave_id): def _mesos_files(leader, slave_id):
"""Returns the MesosFile objects to log """Returns the MesosFile objects to log
:param master: whether to include the master log file :param leader: whether to include the leading master's log file
:type master: bool :type leader: bool
:param slave_id: the ID of a slave. used to include a slave's log :param slave_id: the ID of a slave. used to include a slave's log
file file
:type slave_id: str | None :type slave_id: str | None
@@ -145,7 +150,7 @@ def _mesos_files(master, slave_id):
""" """
files = [] files = []
if master: if leader:
files.append(mesos.MesosFile('/master/log')) files.append(mesos.MesosFile('/master/log'))
if slave_id: if slave_id:
slave = mesos.get_master().slave(slave_id) slave = mesos.get_master().slave(slave_id)
@@ -153,13 +158,13 @@ def _mesos_files(master, slave_id):
return files return files
def _ssh(master, slave, option, config_file, user, master_proxy): def _ssh(leader, slave, option, config_file, user, master_proxy):
"""SSH into a DCOS node using the IP addresses found in master's """SSH into a DCOS node using the IP addresses found in master's
state.json state.json
:param master: True if the user has opted to SSH into the leading :param leader: True if the user has opted to SSH into the leading
master master
:type master: bool | None :type leader: bool | None
:param slave: The slave ID if the user has opted to SSH into a slave :param slave: The slave ID if the user has opted to SSH into a slave
:type slave: str | None :type slave: str | None
:param option: SSH option :param option: SSH option
@@ -177,7 +182,7 @@ def _ssh(master, slave, option, config_file, user, master_proxy):
ssh_options = util.get_ssh_options(config_file, option) ssh_options = util.get_ssh_options(config_file, option)
dcos_client = mesos.DCOSClient() dcos_client = mesos.DCOSClient()
if master: if leader:
host = mesos.MesosDNSClient().hosts('leader.mesos.')[0]['ip'] host = mesos.MesosDNSClient().hosts('leader.mesos.')[0]['ip']
else: else:
summary = dcos_client.get_state_summary() summary = dcos_client.get_state_summary()

View File

@@ -3,12 +3,12 @@ Manage DCOS nodes
Usage: Usage:
dcos node --info dcos node --info
dcos node [--json] dcos node [--json]
dcos node log [--follow --lines=N --master --slave=<slave-id>] dcos node log [--follow --lines=N --leader --master --slave=<slave-id>]
dcos node ssh [--option SSHOPT=VAL ...] dcos node ssh [--option SSHOPT=VAL ...]
[--config-file=<path>] [--config-file=<path>]
[--user=<user>] [--user=<user>]
[--master-proxy] [--master-proxy]
(--master | --slave=<slave-id>) (--leader | --master | --slave=<slave-id>)
Options: Options:
-h, --help Show this screen -h, --help Show this screen
@@ -16,7 +16,8 @@ Options:
--json Print json-formatted nodes --json Print json-formatted nodes
--follow Print data as the file grows --follow Print data as the file grows
--lines=N Print the last N lines [default: 10] --lines=N Print the last N lines [default: 10]
--master Access the leading master --leader Access the leading master
--master Deprecated. Please use --leader.
--master-proxy Proxy the SSH connection through a master node. This can be useful when --master-proxy Proxy the SSH connection through a master node. This can be useful when
accessing DCOS from a separate network. For example, in the default AWS accessing DCOS from a separate network. For example, in the default AWS
configuration, the private slaves are unreachable from the public configuration, the private slaves are unreachable from the public

View File

@@ -43,12 +43,12 @@ def test_node_table():
def test_node_log_empty(): def test_node_log_empty():
stderr = b"You must choose one of --master or --slave.\n" stderr = b"You must choose one of --leader or --slave.\n"
assert_command(['dcos', 'node', 'log'], returncode=1, stderr=stderr) assert_command(['dcos', 'node', 'log'], returncode=1, stderr=stderr)
def test_node_log_master(): def test_node_log_leader():
assert_lines(['dcos', 'node', 'log', '--master'], 10) assert_lines(['dcos', 'node', 'log', '--leader'], 10)
def test_node_log_slave(): def test_node_log_slave():
@@ -65,11 +65,11 @@ def test_node_log_missing_slave():
assert stderr == b'No slave found with ID "bogus".\n' assert stderr == b'No slave found with ID "bogus".\n'
def test_node_log_master_slave(): def test_node_log_leader_slave():
slave_id = _node()[0]['id'] slave_id = _node()[0]['id']
returncode, stdout, stderr = exec_command( returncode, stdout, stderr = exec_command(
['dcos', 'node', 'log', '--master', '--slave={}'.format(slave_id)]) ['dcos', 'node', 'log', '--leader', '--slave={}'.format(slave_id)])
assert returncode == 0 assert returncode == 0
assert stderr == b'' assert stderr == b''
@@ -81,18 +81,18 @@ def test_node_log_master_slave():
def test_node_log_lines(): def test_node_log_lines():
assert_lines(['dcos', 'node', 'log', '--master', '--lines=4'], 4) assert_lines(['dcos', 'node', 'log', '--leader', '--lines=4'], 4)
def test_node_log_invalid_lines(): def test_node_log_invalid_lines():
assert_command(['dcos', 'node', 'log', '--master', '--lines=bogus'], assert_command(['dcos', 'node', 'log', '--leader', '--lines=bogus'],
stdout=b'', stdout=b'',
stderr=b'Error parsing string as int\n', stderr=b'Error parsing string as int\n',
returncode=1) returncode=1)
def test_node_ssh_master(): def test_node_ssh_leader():
_node_ssh(['--master']) _node_ssh(['--leader'])
def test_node_ssh_slave(): def test_node_ssh_slave():
@@ -102,21 +102,21 @@ def test_node_ssh_slave():
def test_node_ssh_option(): def test_node_ssh_option():
stdout, stderr, _ = _node_ssh_output( stdout, stderr, _ = _node_ssh_output(
['--master', '--option', 'Protocol=0']) ['--leader', '--option', 'Protocol=0'])
assert stdout == b'' assert stdout == b''
assert b'ignoring bad proto spec' in stderr assert b'ignoring bad proto spec' in stderr
def test_node_ssh_config_file(): def test_node_ssh_config_file():
stdout, stderr, _ = _node_ssh_output( stdout, stderr, _ = _node_ssh_output(
['--master', '--config-file', 'tests/data/node/ssh_config']) ['--leader', '--config-file', 'tests/data/node/ssh_config'])
assert stdout == b'' assert stdout == b''
assert b'ignoring bad proto spec' in stderr assert b'ignoring bad proto spec' in stderr
def test_node_ssh_user(): def test_node_ssh_user():
stdout, stderr, _ = _node_ssh_output( stdout, stderr, _ = _node_ssh_output(
['--master-proxy', '--master', '--user=bogus', '--option', ['--master-proxy', '--leader', '--user=bogus', '--option',
'PasswordAuthentication=no']) 'PasswordAuthentication=no'])
assert stdout == b'' assert stdout == b''
assert b'Permission denied' in stderr assert b'Permission denied' in stderr
@@ -131,14 +131,24 @@ def test_node_ssh_master_proxy_no_agent():
b"private key to hop between nodes in your cluster. Please " b"private key to hop between nodes in your cluster. Please "
b"run `ssh-agent`, then add your private key with `ssh-add`.\n") b"run `ssh-agent`, then add your private key with `ssh-add`.\n")
assert_command(['dcos', 'node', 'ssh', '--master-proxy', '--master'], assert_command(['dcos', 'node', 'ssh', '--master-proxy', '--leader'],
stderr=stderr, stderr=stderr,
returncode=1, returncode=1,
env=env) env=env)
def test_node_ssh_master_proxy(): def test_node_ssh_master_proxy():
_node_ssh(['--master', '--master-proxy']) _node_ssh(['--leader', '--master-proxy'])
def test_master_arg_deprecation_notice():
stderr = b"--master has been deprecated. Please use --leader.\n"
assert_command(['dcos', 'node', 'log', '--master'],
stderr=stderr,
returncode=1)
assert_command(['dcos', 'node', 'ssh', '--master'],
stderr=stderr,
returncode=1)
def _node_ssh_output(args): def _node_ssh_output(args):