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:
dcos node --info
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 ...]
[--config-file=<path>]
[--user=<user>]
[--master-proxy]
(--master | --slave=<slave-id>)
(--leader | --master | --slave=<slave-id>)
Options:
-h, --help Show this screen
@@ -16,7 +16,8 @@ Options:
--json Print json-formatted nodes
--follow Print data as the file grows
--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
accessing DCOS from a separate network. For example, in the default AWS
configuration, the private slaves are unreachable from the public

View File

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

View File

@@ -3,12 +3,12 @@ Manage DCOS nodes
Usage:
dcos node --info
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 ...]
[--config-file=<path>]
[--user=<user>]
[--master-proxy]
(--master | --slave=<slave-id>)
(--leader | --master | --slave=<slave-id>)
Options:
-h, --help Show this screen
@@ -16,7 +16,8 @@ Options:
--json Print json-formatted nodes
--follow Print data as the file grows
--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
accessing DCOS from a separate network. For example, in the default AWS
configuration, the private slaves are unreachable from the public

View File

@@ -43,12 +43,12 @@ def test_node_table():
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)
def test_node_log_master():
assert_lines(['dcos', 'node', 'log', '--master'], 10)
def test_node_log_leader():
assert_lines(['dcos', 'node', 'log', '--leader'], 10)
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'
def test_node_log_master_slave():
def test_node_log_leader_slave():
slave_id = _node()[0]['id']
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 stderr == b''
@@ -81,18 +81,18 @@ def test_node_log_master_slave():
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():
assert_command(['dcos', 'node', 'log', '--master', '--lines=bogus'],
assert_command(['dcos', 'node', 'log', '--leader', '--lines=bogus'],
stdout=b'',
stderr=b'Error parsing string as int\n',
returncode=1)
def test_node_ssh_master():
_node_ssh(['--master'])
def test_node_ssh_leader():
_node_ssh(['--leader'])
def test_node_ssh_slave():
@@ -102,21 +102,21 @@ def test_node_ssh_slave():
def test_node_ssh_option():
stdout, stderr, _ = _node_ssh_output(
['--master', '--option', 'Protocol=0'])
['--leader', '--option', 'Protocol=0'])
assert stdout == b''
assert b'ignoring bad proto spec' in stderr
def test_node_ssh_config_file():
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 b'ignoring bad proto spec' in stderr
def test_node_ssh_user():
stdout, stderr, _ = _node_ssh_output(
['--master-proxy', '--master', '--user=bogus', '--option',
['--master-proxy', '--leader', '--user=bogus', '--option',
'PasswordAuthentication=no'])
assert stdout == b''
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"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,
returncode=1,
env=env)
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):