Merge pull request #467 from mesosphere/installer-fix

don't send CLUSTER_ID to segment for config subcommand and just 'dcos'
This commit is contained in:
tamarrow
2016-02-16 17:16:47 -08:00
2 changed files with 27 additions and 15 deletions

View File

@@ -247,6 +247,7 @@ def _base_properties(conf=None):
if not conf:
conf = util.get_config()
command = _command()
if len(sys.argv) > 1:
cmd = 'dcos ' + _command()
full_cmd = 'dcos ' + ' '.join(sys.argv[1:])
@@ -261,11 +262,14 @@ def _base_properties(conf=None):
logger.exception('Unable to find the hostname of the cluster.')
dcos_hostname = None
try:
cluster_id = mesos.DCOSClient().metadata().get('CLUSTER_ID')
except:
logger.exception('Unable to get the cluster_id of the cluster.')
cluster_id = None
cluster_id = None
if command and command != "config":
try:
cluster_id = mesos.DCOSClient().metadata().get('CLUSTER_ID')
except:
msg = 'Unable to get the cluster_id of the cluster.'
logger.debug(msg)
logger.exception(msg)
return {
'cmd': cmd,

View File

@@ -55,7 +55,23 @@ def test_config_set():
def test_cluster_id_sent():
'''Tests that cluster_id is sent to segment.io'''
args = [util.which('dcos')]
args = [util.which('dcos'), 'package', 'list']
version = 'release'
env = _env_reporting_with_url()
with patch('sys.argv', args), \
patch.dict(os.environ, env), \
patch('dcoscli.version', version):
props = _base_properties()
assert props.get('CLUSTER_ID')
@_mock
def test_cluster_id_not_sent():
'''Tests that cluster_id is sent to segment.io'''
args = [util.which('dcos'), 'config', 'show']
env = _env_reporting_with_url()
version = 'release'
@@ -65,15 +81,7 @@ def test_cluster_id_sent():
assert main() == 0
props = _base_properties()
# segment.io
data = {'userId': USER_ID,
'event': SEGMENT_IO_CLI_EVENT,
'properties': props}
assert props.get('CLUSTER_ID')
assert mock_called_some_args(http.post,
'{}/track'.format(SEGMENT_URL),
json=data,
timeout=(1, 1))
assert not props.get('CLUSTER_ID')
@_mock