Upload tox and fix pep8

Change-Id: I897b7dc1da11221f8a19459982aeae3edc41f643
This commit is contained in:
changzhi1990 2016-01-18 13:24:22 +08:00
parent 66b440e214
commit a4c4d2e094
11 changed files with 44 additions and 27 deletions

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import os
import sys
from SocketServer import ThreadingMixIn from SocketServer import ThreadingMixIn
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
from stetho.agent import api as agent_api from stetho.agent import api as agent_api

View File

@ -15,10 +15,8 @@
import os import os
import re import re
import time
import tempfile import tempfile
import signal import signal
import shlex
import subprocess import subprocess
import platform import platform
from threading import Timer from threading import Timer
@ -137,7 +135,7 @@ def get_interface(interface):
return format_centos_6_5(inf) return format_centos_6_5(inf)
elif not cmp(linux_dist, '7.0'): elif not cmp(linux_dist, '7.0'):
return format_centos_7_0(inf) return format_centos_7_0(inf)
except Exception as e: except Exception:
message = stdout.pop(0) message = stdout.pop(0)
return stdcode, message, None return stdcode, message, None

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import uuid
from stetho.agent.common import log from stetho.agent.common import log
from stetho.agent.common import utils from stetho.agent.common import utils
@ -46,7 +45,7 @@ class IPerfDriver(object):
parallel=None, bandwidth=None): parallel=None, bandwidth=None):
"""iperf -D -c host -t 60 """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'): if not (protocol, 'UDP'):
cmd.append('-u') cmd.append('-u')
if parallel: if parallel:

View File

@ -20,7 +20,6 @@ import sys
from cliff.command import Command from cliff.command import Command
from cliff.lister import Lister from cliff.lister import Lister
from json import JSONDecoder
LISTEN_PORT = 9698 LISTEN_PORT = 9698
SETUP_LINK_IP_PRE = "192.168.100." SETUP_LINK_IP_PRE = "192.168.100."
@ -63,13 +62,11 @@ def setup_server(agent):
log.debug('get agent:%s ip_address:%s' % ( log.debug('get agent:%s ip_address:%s' % (
agent, AGENT_INFOS[agent])) agent, AGENT_INFOS[agent]))
else: else:
log.error('Agent %s not configured. Please check it.' % ( log.error('Agent %s not configured. Please check it.' % (agent))
agent))
sys.exit() sys.exit()
log.debug('Begin create connection with http://%s:9698.' % ( log.debug('Begin create connection with http://%s:9698.' % (agent))
agent)) server = jsonrpclib.Server('http://%s:%s' %
server = jsonrpclib.Server('http://%s:%s' % ( (AGENT_INFOS[agent], LISTEN_PORT))
AGENT_INFOS[agent], LISTEN_PORT))
log.debug('Create connection with %s success.' % (agent)) log.debug('Create connection with %s success.' % (agent))
return server return server
@ -93,7 +90,7 @@ class TearDownLink(Command):
try: try:
res = server.teardown_link(parsed_args.interface) res = server.teardown_link(parsed_args.interface)
except Exception as e: 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): class SetUpLink(Lister):

View File

@ -31,5 +31,5 @@ cfg.CONF([], project='stetho',
AGENT_INFOS = {} AGENT_INFOS = {}
all_agents = cfg.CONF.network_agents_info + cfg.CONF.compute_agents_info all_agents = cfg.CONF.network_agents_info + cfg.CONF.compute_agents_info
for agent in all_agents: 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) AGENT_INFOS.update(item)

View File

@ -60,13 +60,11 @@ def setup_server(agent):
log.debug('get agent:%s ip_address:%s' % ( log.debug('get agent:%s ip_address:%s' % (
agent, AGENT_INFOS[agent])) agent, AGENT_INFOS[agent]))
else: else:
log.error('Agent %s not configured. Please check it.' % ( log.error('Agent %s not configured. Please check it.' % (agent))
agent))
sys.exit() sys.exit()
log.debug('Begin create connection with http://%s:9698.' % ( log.debug('Begin create connection with http://%s:9698.' % (agent))
agent)) server = jsonrpclib.Server('http://%s:%s' %
server = jsonrpclib.Server('http://%s:%s' % ( (AGENT_INFOS[agent], LISTEN_PORT))
AGENT_INFOS[agent], LISTEN_PORT))
log.debug('Create connection with %s success.' % (agent)) log.debug('Create connection with %s success.' % (agent))
return server return server

View File

@ -17,7 +17,6 @@ Command-line interface to Stetho APIs
""" """
import sys import sys
import logging
from cliff import app from cliff import app
from cliff import commandmanager from cliff import commandmanager

View File

@ -17,7 +17,6 @@ import mock
import unittest import unittest
from stetho.agent import api from stetho.agent import api
from stetho.agent.common import utils as agent_utils from stetho.agent.common import utils as agent_utils
from stetho.agent.drivers import iperf as iperf_driver
class TestApi(unittest.TestCase): class TestApi(unittest.TestCase):

View File

@ -74,7 +74,7 @@ class TestStethoClientMethods(unittest.TestCase):
self.assertEqual(self.server.check_ports_on_br.called, True) self.assertEqual(self.server.check_ports_on_br.called, True)
def test_check_iperf(self): 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 = { iperf_client_r = {
'message': '', 'message': '',
'code': 0, 'code': 0,
@ -85,11 +85,11 @@ class TestStethoClientMethods(unittest.TestCase):
'server_ip': 'localhost' '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.setup_iperf_server = mock.Mock(return_value=iperf_server_r)
self.server.start_iperf_client = mock.Mock(return_value=iperf_client_r) self.server.start_iperf_client = mock.Mock(return_value=iperf_client_r)
self.server.teardown_iperf_server = mock.Mock( 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']) shell.main(['check-iperf', 'agent-64', 'agent-64'])
self.assertEqual(self.server.setup_iperf_server.called, True) self.assertEqual(self.server.setup_iperf_server.called, True)
self.assertEqual(self.server.start_iperf_client.called, True) self.assertEqual(self.server.start_iperf_client.called, True)

View File

@ -1 +1,3 @@
mock mock
flake8
unittest

27
tox.ini Normal file
View File

@ -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/*