From a4c4d2e094fcfcfb76f4a988ce521e3e6c0dba9d Mon Sep 17 00:00:00 2001 From: changzhi1990 Date: Mon, 18 Jan 2016 13:24:22 +0800 Subject: [PATCH] Upload tox and fix pep8 Change-Id: I897b7dc1da11221f8a19459982aeae3edc41f643 --- stetho/agent/agent.py | 2 -- stetho/agent/common/utils.py | 4 +-- stetho/agent/drivers/iperf.py | 3 +-- stetho/stethoclient/agent_api.py | 13 ++++----- stetho/stethoclient/constants.py | 2 +- stetho/stethoclient/drivers/iperf_api.py | 10 +++---- stetho/stethoclient/shell.py | 1 - stetho/tests/unit/agent/test_api.py | 1 - .../unit/stethoclient/test_stethoclient.py | 6 ++--- test-requirements.txt | 2 ++ tox.ini | 27 +++++++++++++++++++ 11 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 tox.ini diff --git a/stetho/agent/agent.py b/stetho/agent/agent.py index cf35ca1..262ff8d 100644 --- a/stetho/agent/agent.py +++ b/stetho/agent/agent.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import os -import sys from SocketServer import ThreadingMixIn from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer from stetho.agent import api as agent_api diff --git a/stetho/agent/common/utils.py b/stetho/agent/common/utils.py index 8afb26f..e9d6552 100644 --- a/stetho/agent/common/utils.py +++ b/stetho/agent/common/utils.py @@ -15,10 +15,8 @@ import os import re -import time import tempfile import signal -import shlex import subprocess import platform from threading import Timer @@ -137,7 +135,7 @@ def get_interface(interface): return format_centos_6_5(inf) elif not cmp(linux_dist, '7.0'): return format_centos_7_0(inf) - except Exception as e: + except Exception: message = stdout.pop(0) return stdcode, message, None diff --git a/stetho/agent/drivers/iperf.py b/stetho/agent/drivers/iperf.py index 55c27d7..69aea5e 100644 --- a/stetho/agent/drivers/iperf.py +++ b/stetho/agent/drivers/iperf.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid from stetho.agent.common import log from stetho.agent.common import utils @@ -46,7 +45,7 @@ class IPerfDriver(object): parallel=None, bandwidth=None): """iperf -D -c host -t 60 """ - cmd = ['iperf', '-c', host, '-p', str(port), '-t', str(timeout)] + cmd = ['iperf', '-c', host, '-p', str(port), '-t', str(timeout)] if not (protocol, 'UDP'): cmd.append('-u') if parallel: diff --git a/stetho/stethoclient/agent_api.py b/stetho/stethoclient/agent_api.py index 78903a5..e728baa 100644 --- a/stetho/stethoclient/agent_api.py +++ b/stetho/stethoclient/agent_api.py @@ -20,7 +20,6 @@ import sys from cliff.command import Command from cliff.lister import Lister -from json import JSONDecoder LISTEN_PORT = 9698 SETUP_LINK_IP_PRE = "192.168.100." @@ -63,13 +62,11 @@ def setup_server(agent): log.debug('get agent:%s ip_address:%s' % ( agent, AGENT_INFOS[agent])) else: - log.error('Agent %s not configured. Please check it.' % ( - agent)) + log.error('Agent %s not configured. Please check it.' % (agent)) sys.exit() - log.debug('Begin create connection with http://%s:9698.' % ( - agent)) - server = jsonrpclib.Server('http://%s:%s' % ( - AGENT_INFOS[agent], LISTEN_PORT)) + log.debug('Begin create connection with http://%s:9698.' % (agent)) + server = jsonrpclib.Server('http://%s:%s' % + (AGENT_INFOS[agent], LISTEN_PORT)) log.debug('Create connection with %s success.' % (agent)) return server @@ -93,7 +90,7 @@ class TearDownLink(Command): try: res = server.teardown_link(parsed_args.interface) except Exception as e: - self.log.error('Error %s has occured.' % res) + self.log.error('Error %s has occured because: ' % (res, e)) class SetUpLink(Lister): diff --git a/stetho/stethoclient/constants.py b/stetho/stethoclient/constants.py index ee36ff3..dabd384 100644 --- a/stetho/stethoclient/constants.py +++ b/stetho/stethoclient/constants.py @@ -31,5 +31,5 @@ cfg.CONF([], project='stetho', AGENT_INFOS = {} all_agents = cfg.CONF.network_agents_info + cfg.CONF.compute_agents_info for agent in all_agents: - item = {'agent-'+agent: cfg.CONF.managed_network_prefix+agent} + item = {'agent-' + agent: cfg.CONF.managed_network_prefix + agent} AGENT_INFOS.update(item) diff --git a/stetho/stethoclient/drivers/iperf_api.py b/stetho/stethoclient/drivers/iperf_api.py index 558b523..4a916d1 100644 --- a/stetho/stethoclient/drivers/iperf_api.py +++ b/stetho/stethoclient/drivers/iperf_api.py @@ -60,13 +60,11 @@ def setup_server(agent): log.debug('get agent:%s ip_address:%s' % ( agent, AGENT_INFOS[agent])) else: - log.error('Agent %s not configured. Please check it.' % ( - agent)) + log.error('Agent %s not configured. Please check it.' % (agent)) sys.exit() - log.debug('Begin create connection with http://%s:9698.' % ( - agent)) - server = jsonrpclib.Server('http://%s:%s' % ( - AGENT_INFOS[agent], LISTEN_PORT)) + log.debug('Begin create connection with http://%s:9698.' % (agent)) + server = jsonrpclib.Server('http://%s:%s' % + (AGENT_INFOS[agent], LISTEN_PORT)) log.debug('Create connection with %s success.' % (agent)) return server diff --git a/stetho/stethoclient/shell.py b/stetho/stethoclient/shell.py index 1ec60c2..7b5a7ae 100644 --- a/stetho/stethoclient/shell.py +++ b/stetho/stethoclient/shell.py @@ -17,7 +17,6 @@ Command-line interface to Stetho APIs """ import sys -import logging from cliff import app from cliff import commandmanager diff --git a/stetho/tests/unit/agent/test_api.py b/stetho/tests/unit/agent/test_api.py index c1feb14..c371b44 100644 --- a/stetho/tests/unit/agent/test_api.py +++ b/stetho/tests/unit/agent/test_api.py @@ -17,7 +17,6 @@ import mock import unittest from stetho.agent import api from stetho.agent.common import utils as agent_utils -from stetho.agent.drivers import iperf as iperf_driver class TestApi(unittest.TestCase): diff --git a/stetho/tests/unit/stethoclient/test_stethoclient.py b/stetho/tests/unit/stethoclient/test_stethoclient.py index 5e02590..aee4ea0 100644 --- a/stetho/tests/unit/stethoclient/test_stethoclient.py +++ b/stetho/tests/unit/stethoclient/test_stethoclient.py @@ -74,7 +74,7 @@ class TestStethoClientMethods(unittest.TestCase): self.assertEqual(self.server.check_ports_on_br.called, True) def test_check_iperf(self): - iperf_server_r = {u'message': u'', u'code': 0, u'data': {u'pid': 1234}} + iperf_server_r = {'message': '', u'code': 0, 'data': {'pid': 1234}} iperf_client_r = { 'message': '', 'code': 0, @@ -85,11 +85,11 @@ class TestStethoClientMethods(unittest.TestCase): 'server_ip': 'localhost' } } - teardown_iperf_r = {u'message': u'', u'code': 0, u'data': {}} + teardown_iperf_r = {'message': '', 'code': 0, 'data': {}} self.server.setup_iperf_server = mock.Mock(return_value=iperf_server_r) self.server.start_iperf_client = mock.Mock(return_value=iperf_client_r) self.server.teardown_iperf_server = mock.Mock( - return_value=teardown_iperf_r) + return_value=teardown_iperf_r) shell.main(['check-iperf', 'agent-64', 'agent-64']) self.assertEqual(self.server.setup_iperf_server.called, True) self.assertEqual(self.server.start_iperf_client.called, True) diff --git a/test-requirements.txt b/test-requirements.txt index 932a895..cac7939 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,3 @@ mock +flake8 +unittest diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..a73a93b --- /dev/null +++ b/tox.ini @@ -0,0 +1,27 @@ +[tox] +envlist = py26,py27,pep8 + +[testenv] +setenv = VIRTUAL_ENV={envdir} + NOSE_WITH_OPENSTACK=1 + NOSE_OPENSTACK_COLOR=1 + NOSE_OPENSTACK_RED=0.05 + NOSE_OPENSTACK_YELLOW=0.025 + NOSE_OPENSTACK_SHOW_ELAPSED=1 + NOSE_OPENSTACK_STDOUT=1 +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = + /usr/bin/find . -type f -name "*.pyc" -delete + python setup.py testr --slowest --testr-args='{posargs}' + nosetests {posargs} +whitelist_externals = * + +[testenv:pep8] +commands = flake8 +distribute = false + +[flake8] +ignore = H703,H102,E265,E262,H233 +show-source = true +exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build,setup.py,tests/ci/*,scripts/*