diff --git a/cli/dcoscli/analytics.py b/cli/dcoscli/analytics.py index 031d08e..9f05717 100644 --- a/cli/dcoscli/analytics.py +++ b/cli/dcoscli/analytics.py @@ -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, diff --git a/cli/tests/integrations/test_analytics.py b/cli/tests/integrations/test_analytics.py index 2dd0321..fa07e57 100644 --- a/cli/tests/integrations/test_analytics.py +++ b/cli/tests/integrations/test_analytics.py @@ -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