From 235f14b1f036fa5eb04d305a093a0a0d8f47c0f0 Mon Sep 17 00:00:00 2001 From: Michael Gummelt Date: Thu, 16 Apr 2015 11:00:30 -0700 Subject: [PATCH] remove segment.io --- cli/dcoscli/constants.py | 1 - cli/dcoscli/main.py | 60 ++-------------------- cli/setup.py | 1 - cli/tests/data/dcos/dcos_no_reporting.toml | 2 - cli/tests/integrations/cli/test_dcos.py | 59 ++------------------- cli/tox.ini | 1 - 6 files changed, 8 insertions(+), 116 deletions(-) delete mode 100644 cli/tests/data/dcos/dcos_no_reporting.toml diff --git a/cli/dcoscli/constants.py b/cli/dcoscli/constants.py index 86bcd40..e69de29 100644 --- a/cli/dcoscli/constants.py +++ b/cli/dcoscli/constants.py @@ -1 +0,0 @@ -SEGMENT_IO_WRITE_KEY = '51ybGTeFEFU1xo6u10XMDrr6kATFyRyh' diff --git a/cli/dcoscli/main.py b/cli/dcoscli/main.py index 8b69c6f..ab5d008 100644 --- a/cli/dcoscli/main.py +++ b/cli/dcoscli/main.py @@ -26,17 +26,13 @@ Environment Variables: to read about a specific subcommand. """ -import json -import os -import sys -from subprocess import PIPE, Popen -import analytics +import os +import subprocess + import dcoscli import docopt -import requests -from dcos.api import config, constants, emitting, subcommand, util -from dcoscli.constants import SEGMENT_IO_WRITE_KEY +from dcos.api import constants, emitting, subcommand, util emitter = emitting.FlatEmitter() @@ -58,10 +54,6 @@ def main(): emitter.publish(err) return 1 - # urllib3 is printing an SSL warning we want to silence. See - # DCOS-1007. - requests.packages.urllib3.disable_warnings() - command = args[''] if not command: @@ -72,49 +64,7 @@ def main(): emitter.publish(err) return 1 - subproc = Popen([executable, command] + args[''], - stderr=PIPE) - - analytics.write_key = SEGMENT_IO_WRITE_KEY - return wait_and_track(subproc) - - -def wait_and_track(subproc): - # capture and print stderr - err = '' - while subproc.poll() is None: - err_buff = subproc.stderr.read().decode('utf-8') - sys.stderr.write(err_buff) - err += err_buff - - exit_code = subproc.poll() - - conf = config.load_from_path( - os.environ[constants.DCOS_CONFIG_ENV]) - - if conf.get('core.report', True): - track(exit_code, err, conf) - - return exit_code - - -def track(exit_code, err, conf): - # segment.io analytics - try: - # We don't have user id's right now, but segment.io requires - # them, so we use a constant (1) - analytics.track('', 'dcos-cli', { - 'cmd': ' '.join(sys.argv), - 'exit_code': exit_code, - 'err': err or None, - 'dcoscli.version': dcoscli.version, - 'config': json.dumps(list(conf.property_items())) - }) - - analytics.flush() - except: - # ignore segment.io exceptions - pass + return subprocess.call([executable, command] + args['']) def _config_log_level_environ(log_level): diff --git a/cli/setup.py b/cli/setup.py index 5bc8a48..ac77710 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -67,7 +67,6 @@ setup( 'pkginfo', 'toml', 'virtualenv', - 'analytics-python', ], # If there are data files included in your packages that need to be diff --git a/cli/tests/data/dcos/dcos_no_reporting.toml b/cli/tests/data/dcos/dcos_no_reporting.toml deleted file mode 100644 index c463013..0000000 --- a/cli/tests/data/dcos/dcos_no_reporting.toml +++ /dev/null @@ -1,2 +0,0 @@ -[core] -report = false diff --git a/cli/tests/integrations/cli/test_dcos.py b/cli/tests/integrations/cli/test_dcos.py index e47d078..4405269 100644 --- a/cli/tests/integrations/cli/test_dcos.py +++ b/cli/tests/integrations/cli/test_dcos.py @@ -1,14 +1,8 @@ -import json import os -import analytics -import dcoscli -from dcos.api import config, constants, util -from dcoscli.main import main +from dcos.api import constants, util -import mock from common import exec_command -from mock import Mock, patch def test_default(): @@ -109,6 +103,7 @@ def test_log_level_flag(): assert returncode == 0 assert stdout == b"Get and set DCOS command line options\n" + assert stderr == b'' def test_capital_log_level_flag(): @@ -117,6 +112,7 @@ def test_capital_log_level_flag(): assert returncode == 0 assert stdout == b"Get and set DCOS command line options\n" + assert stderr == b'' def test_invalid_log_level_flag(): @@ -128,52 +124,3 @@ def test_invalid_log_level_flag(): b"values are ['debug', 'info', 'warning', 'error', " b"'critical']\n") assert stderr == b'' - - -def _mock_analytics_run(args): - with mock.patch('sys.argv', args): - analytics.track = Mock() - analytics.flush = Mock() - return main() - - -def _analytics_base_properties(args): - conf = config.load_from_path(os.environ[constants.DCOS_CONFIG_ENV]) - return {'cmd': ' '.join(args), - 'exit_code': 0, - 'err': None, - 'dcoscli.version': dcoscli.version, - 'config': json.dumps(list(conf.property_items()))} - - -def test_analytics_no_err(): - args = ['dcos'] - exit_code = _mock_analytics_run(args) - - props = _analytics_base_properties(args) - analytics.track.assert_called_with('', 'dcos-cli', props) - analytics.flush.assert_called_with() - assert exit_code == 0 - - -def test_analytics_err(): - args = ['dcos', 'marathon', 'task', 'show', 'asdf'] - exit_code = _mock_analytics_run(args) - - props = _analytics_base_properties(args) - props['exit_code'] = 1 - props['err'] = "Task 'asdf' does not exist\n" - analytics.track.assert_called_with('', 'dcos-cli', props) - analytics.flush.assert_called_with() - assert exit_code == 1 - - -def test_analytics_report_config(): - args = ['dcos'] - new_env = {constants.DCOS_CONFIG_ENV: - os.path.join('tests', 'data', 'dcos', 'dcos_no_reporting.toml')} - with patch.dict(os.environ, new_env): - exit_code = _mock_analytics_run(args) - assert analytics.track.call_count == 0 - assert analytics.flush.call_count == 0 - assert exit_code == 0 diff --git a/cli/tox.ini b/cli/tox.ini index 119c752..8a952fe 100644 --- a/cli/tox.ini +++ b/cli/tox.ini @@ -5,7 +5,6 @@ envlist = py{27,34}-integration, syntax deps = pytest pytest-cov - mock -e.. [testenv:syntax]