remove segment.io
This commit is contained in:
@@ -1 +0,0 @@
|
||||
SEGMENT_IO_WRITE_KEY = '51ybGTeFEFU1xo6u10XMDrr6kATFyRyh'
|
||||
|
||||
@@ -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['<command>']
|
||||
|
||||
if not command:
|
||||
@@ -72,49 +64,7 @@ def main():
|
||||
emitter.publish(err)
|
||||
return 1
|
||||
|
||||
subproc = Popen([executable, command] + args['<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-user>', '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['<args>'])
|
||||
|
||||
|
||||
def _config_log_level_environ(log_level):
|
||||
|
||||
@@ -67,7 +67,6 @@ setup(
|
||||
'pkginfo',
|
||||
'toml',
|
||||
'virtualenv',
|
||||
'analytics-python',
|
||||
],
|
||||
|
||||
# If there are data files included in your packages that need to be
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
[core]
|
||||
report = false
|
||||
@@ -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-user>', '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-user>', '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
|
||||
|
||||
@@ -5,7 +5,6 @@ envlist = py{27,34}-integration, syntax
|
||||
deps =
|
||||
pytest
|
||||
pytest-cov
|
||||
mock
|
||||
-e..
|
||||
|
||||
[testenv:syntax]
|
||||
|
||||
Reference in New Issue
Block a user