summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordongwenjuan <dong.wenjuan@zte.com.cn>2017-12-21 16:11:31 +0800
committerdongwenjuan <dong.wenjuan@zte.com.cn>2018-01-09 09:37:39 +0800
commit754b94bba6df6e7aafd5f1ffb8432a40cb815649 (patch)
tree4bbe2f725e5b378bbd8f1b12cbbbb173afb203b2
parentbdbd22904733af311225a3315555bb39ea12ed55 (diff)
support pep8 check
Change-Id: I3c4358694c57d27a207ae60712c44f717c8895f7 Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
-rw-r--r--.gitignore1
-rw-r--r--doctor_tests/alarm.py2
-rw-r--r--doctor_tests/common/__init__.py2
-rw-r--r--doctor_tests/common/utils.py3
-rw-r--r--doctor_tests/consumer/base.py2
-rw-r--r--doctor_tests/consumer/sample.py2
-rw-r--r--doctor_tests/identity_auth.py4
-rw-r--r--doctor_tests/image.py12
-rw-r--r--doctor_tests/inspector/base.py2
-rw-r--r--doctor_tests/inspector/congress.py20
-rw-r--r--doctor_tests/inspector/sample.py24
-rw-r--r--doctor_tests/installer/apex.py50
-rw-r--r--doctor_tests/installer/base.py1
-rw-r--r--doctor_tests/installer/common/congress.py12
-rw-r--r--doctor_tests/installer/common/set_ceilometer.py3
-rw-r--r--doctor_tests/installer/common/vitrage.py11
-rw-r--r--doctor_tests/installer/local.py12
-rw-r--r--doctor_tests/instance.py6
-rw-r--r--doctor_tests/main.py33
-rw-r--r--doctor_tests/monitor/__init__.py1
-rw-r--r--doctor_tests/monitor/collectd.py56
-rw-r--r--doctor_tests/monitor/collectd_plugin.py78
-rw-r--r--doctor_tests/monitor/sample.py10
-rw-r--r--doctor_tests/network.py3
-rw-r--r--doctor_tests/profiler_poc.py5
-rw-r--r--doctor_tests/scenario/network_failure.py35
-rw-r--r--doctor_tests/user.py24
-rw-r--r--requirements.txt1
-rw-r--r--tox.ini18
29 files changed, 273 insertions, 160 deletions
diff --git a/.gitignore b/.gitignore
index 7e893869..6fc25628 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
**.log
*.pyc
/*.egg-info/
+.eggs/
/build/
/docs_build/
/docs_output/
diff --git a/doctor_tests/alarm.py b/doctor_tests/alarm.py
index 3b1aaf3f..df49bab3 100644
--- a/doctor_tests/alarm.py
+++ b/doctor_tests/alarm.py
@@ -52,7 +52,7 @@ class Alarm(object):
for i in range(0, self.conf.instance_count):
alarm_name = self.alarm_names[i]
if alarm_name in alarms:
- continue;
+ continue
vm_name = '%s%d' % (self.conf.instance_basename, i)
vm_id = getattr(servers[vm_name], 'id')
alarm_request = dict(
diff --git a/doctor_tests/common/__init__.py b/doctor_tests/common/__init__.py
index e68a3070..48893ae6 100644
--- a/doctor_tests/common/__init__.py
+++ b/doctor_tests/common/__init__.py
@@ -5,4 +5,4 @@
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-############################################################################## \ No newline at end of file
+##############################################################################
diff --git a/doctor_tests/common/utils.py b/doctor_tests/common/utils.py
index d2962a8a..0e2c8752 100644
--- a/doctor_tests/common/utils.py
+++ b/doctor_tests/common/utils.py
@@ -78,7 +78,8 @@ class SSHClient(object):
output.append(line.decode('utf-8'))
if ret:
if self.log:
- self.log.info("*** FAILED to run command %s (%s)" % (command, ret))
+ self.log.info("*** FAILED to run command %s (%s)"
+ % (command, ret))
raise Exception(
"Unable to run \ncommand: %s\nret: %s"
% (command, ret))
diff --git a/doctor_tests/consumer/base.py b/doctor_tests/consumer/base.py
index 35170748..b6c4b34e 100644
--- a/doctor_tests/consumer/base.py
+++ b/doctor_tests/consumer/base.py
@@ -23,4 +23,4 @@ class BaseConsumer(object):
@abc.abstractmethod
def stop(self):
- pass \ No newline at end of file
+ pass
diff --git a/doctor_tests/consumer/sample.py b/doctor_tests/consumer/sample.py
index d76a764b..eaf5fabd 100644
--- a/doctor_tests/consumer/sample.py
+++ b/doctor_tests/consumer/sample.py
@@ -55,8 +55,8 @@ class ConsumerApp(Thread):
@app.route('/failure', methods=['POST'])
def event_posted():
self.log.info('doctor consumer notified at %s' % time.time())
- self.log.info('sample consumer received data = %s' % request.data)
data = json.loads(request.data.decode('utf8'))
+ self.log.info('sample consumer received data = %s' % data)
return 'OK'
@app.route('/shutdown', methods=['POST'])
diff --git a/doctor_tests/identity_auth.py b/doctor_tests/identity_auth.py
index eb046986..0d429597 100644
--- a/doctor_tests/identity_auth.py
+++ b/doctor_tests/identity_auth.py
@@ -18,8 +18,8 @@ def get_identity_auth(username=None, password=None, project=None):
password = password or os.environ['OS_PASSWORD']
user_domain_name = os.environ.get('OS_USER_DOMAIN_NAME') or 'Default'
user_domain_id = os.environ.get('OS_USER_DOMAIN_ID') or 'default'
- project_name = project or os.environ.get('OS_PROJECT_NAME') \
- or os.environ.get('OS_TENANT_NAME')
+ project_name = (project or os.environ.get('OS_PROJECT_NAME') or
+ os.environ.get('OS_TENANT_NAME'))
project_domain_name = os.environ.get('OS_PROJECT_DOMAIN_NAME') or 'Default'
project_domain_id = os.environ.get('OS_PROJECT_DOMAIN_ID') or 'default'
diff --git a/doctor_tests/image.py b/doctor_tests/image.py
index 2e313e12..9961b22d 100644
--- a/doctor_tests/image.py
+++ b/doctor_tests/image.py
@@ -28,7 +28,7 @@ OPTS = [
help='the name of image file',
required=True),
cfg.StrOpt('image_download_url',
- default='https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img',
+ default='https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img', # noqa
help='the url where to get the image',
required=True),
]
@@ -53,10 +53,12 @@ class Image(object):
resp = urllib.request.urlopen(self.conf.image_download_url)
with open(self.conf.image_filename, "wb") as file:
file.write(resp.read())
- self.image = self.glance.images.create(name=self.conf.image_name,
- disk_format=self.conf.image_format,
- container_format="bare",
- visibility="public")
+ self.image = \
+ self.glance.images.create(
+ name=self.conf.image_name,
+ disk_format=self.conf.image_format,
+ container_format="bare",
+ visibility="public")
self.glance.images.upload(self.image['id'],
open(self.conf.image_filename, 'rb'))
else:
diff --git a/doctor_tests/inspector/base.py b/doctor_tests/inspector/base.py
index 854f0695..a6eae451 100644
--- a/doctor_tests/inspector/base.py
+++ b/doctor_tests/inspector/base.py
@@ -27,4 +27,4 @@ class BaseInspector(object):
@abc.abstractmethod
def stop(self):
- pass \ No newline at end of file
+ pass
diff --git a/doctor_tests/inspector/congress.py b/doctor_tests/inspector/congress.py
index c89a41bd..fb747ec5 100644
--- a/doctor_tests/inspector/congress.py
+++ b/doctor_tests/inspector/congress.py
@@ -20,13 +20,13 @@ class CongressInspector(BaseInspector):
policy = 'classification'
rules = {
'host_down':
- 'host_down(host) :- doctor:events(hostname=host, type="compute.host.down", status="down")',
+ 'host_down(host) :- doctor:events(hostname=host, type="compute.host.down", status="down")', # noqa
'active_instance_in_host':
- 'active_instance_in_host(vmid, host) :- nova:servers(id=vmid, host_name=host, status="ACTIVE")',
+ 'active_instance_in_host(vmid, host) :- nova:servers(id=vmid, host_name=host, status="ACTIVE")', # noqa
'host_force_down':
- 'execute[nova:services.force_down(host, "nova-compute", "True")] :- host_down(host)',
+ 'execute[nova:services.force_down(host, "nova-compute", "True")] :- host_down(host)', # noqa
'error_vm_states':
- 'execute[nova:servers.reset_state(vmid, "error")] :- host_down(host), active_instance_in_host(vmid, host)'
+ 'execute[nova:servers.reset_state(vmid, "error")] :- host_down(host), active_instance_in_host(vmid, host)' # noqa
}
def __init__(self, conf, log):
@@ -38,12 +38,14 @@ class CongressInspector(BaseInspector):
def _init_driver_and_ds(self):
datasources = \
- {ds['name']: ds for ds in self.congress.list_datasources()['results']}
+ {ds['name']: ds for ds in
+ self.congress.list_datasources()['results']}
# check nova_api version
nova_api_version = datasources['nova']['config'].get('api_version')
if nova_api_version and nova_api_version < self.nova_api_min_version:
- raise Exception('Congress Nova datasource API version < nova_api_min_version(%s)'
+ raise Exception('Congress Nova datasource API '
+ 'version < nova_api_min_version(%s)'
% self.nova_api_min_version)
# create doctor datasource if it's not exist
@@ -54,7 +56,8 @@ class CongressInspector(BaseInspector):
# check whether doctor driver exist
drivers = \
- {driver['id']: driver for driver in self.congress.list_drivers()['results']}
+ {driver['id']: driver for driver in
+ self.congress.list_drivers()['results']}
if self.doctor_driver not in drivers:
raise Exception('Do not support doctor driver in congress')
@@ -66,7 +69,8 @@ class CongressInspector(BaseInspector):
ds = self.congress.list_datasources()['results']
doctor_ds = next((item for item in ds if item['driver'] == 'doctor'),
None)
- congress_endpoint = self.congress.httpclient.get_endpoint(auth=self.auth)
+ congress_endpoint = \
+ self.congress.httpclient.get_endpoint(auth=self.auth)
return ('%s/v1/data-sources/%s/tables/events/rows' %
(congress_endpoint, doctor_ds['id']))
diff --git a/doctor_tests/inspector/sample.py b/doctor_tests/inspector/sample.py
index fe67a903..fadfd3d4 100644
--- a/doctor_tests/inspector/sample.py
+++ b/doctor_tests/inspector/sample.py
@@ -58,12 +58,15 @@ class SampleInspector(BaseInspector):
try:
host = server.__dict__.get('OS-EXT-SRV-ATTR:host')
self.servers[host].append(server)
- self.log.debug('get hostname=%s from server=%s' % (host, server))
+ self.log.debug('get hostname=%s from server=%s'
+ % (host, server))
except Exception as e:
- self.log.info('can not get hostname from server=%s' % server)
+ self.log.info('can not get hostname from server=%s, error=%s'
+ % (server, e))
def get_inspector_url(self):
- return 'http://%s:%s/events' % (self.conf.inspector.ip, self.conf.inspector.port)
+ return 'http://%s:%s/events' % (self.conf.inspector.ip,
+ self.conf.inspector.port)
def start(self):
self.log.info('sample inspector start......')
@@ -105,7 +108,8 @@ class SampleInspector(BaseInspector):
@utils.run_async
def _disable_compute_host(self, hostname):
self.nova.services.force_down(hostname, 'nova-compute', True)
- self.log.info('doctor mark host(%s) down at %s' % (hostname, time.time()))
+ self.log.info('doctor mark host(%s) down at %s'
+ % (hostname, time.time()))
@utils.run_async
def _vms_reset_state(self, state, hostname):
@@ -113,7 +117,8 @@ class SampleInspector(BaseInspector):
@utils.run_async
def _vm_reset_state(nova, server, state):
nova.servers.reset_state(server, state)
- self.log.info('doctor mark vm(%s) error at %s' % (server, time.time()))
+ self.log.info('doctor mark vm(%s) error at %s'
+ % (server, time.time()))
thrs = []
for nova, server in zip(self.novaclients, self.servers[hostname]):
@@ -129,7 +134,8 @@ class SampleInspector(BaseInspector):
@utils.run_async
def _set_port_data_plane_status(port_id):
self.neutron.update_port(port_id, body)
- self.log.info('doctor set data plane status %s on port %s' % (status, port_id))
+ self.log.info('doctor set data plane status %s on port %s'
+ % (status, port_id))
thrs = []
params = {'binding:host_id': hostname}
@@ -153,9 +159,11 @@ class InspectorApp(Thread):
@app.route('/events', methods=['PUT'])
def event_posted():
- self.log.info('event posted in sample inspector at %s' % time.time())
+ self.log.info('event posted in sample inspector at %s'
+ % time.time())
self.log.info('sample inspector = %s' % self.inspector)
- self.log.info('sample inspector received data = %s' % request.data)
+ self.log.info('sample inspector received data = %s'
+ % request.data)
events = json.loads(request.data.decode('utf8'))
self.inspector.handle_events(events)
return "OK"
diff --git a/doctor_tests/installer/apex.py b/doctor_tests/installer/apex.py
index 16f0376e..aaacb385 100644
--- a/doctor_tests/installer/apex.py
+++ b/doctor_tests/installer/apex.py
@@ -72,9 +72,11 @@ class ApexInstaller(BaseInstaller):
"| sed -e 's/^.*ctlplane=//' |awk '{print $1}'"
ret, controllers = self.client.ssh(command)
if ret:
- raise Exception('Exec command to get controller ips in Apex installer failed'
- 'ret=%s, output=%s' % (ret, controllers))
- self.log.info('Get controller_ips:%s from Apex installer' % controllers)
+ raise Exception('Exec command to get controller ips'
+ 'in Apex installer failed, ret=%s, output=%s'
+ % (ret, controllers))
+ self.log.info('Get controller_ips:%s from Apex installer'
+ % controllers)
self.controllers = controllers
def get_host_ip_from_hostname(self, hostname):
@@ -82,20 +84,31 @@ class ApexInstaller(BaseInstaller):
hostname_in_undercloud = hostname.split('.')[0]
- command = "source stackrc; nova show %s | awk '/ ctlplane network /{print $5}'" % (hostname_in_undercloud)
+ command = "source stackrc; nova show %s | awk '/ ctlplane network /{print $5}'" % (hostname_in_undercloud) # noqa
ret, host_ip = self.client.ssh(command)
if ret:
- raise Exception('Exec command to get host ip from hostname(%s) in Apex installer failed'
- 'ret=%s, output=%s' % (hostname, ret, host_ip))
- self.log.info('Get host_ip:%s from host_name:%s in Apex installer' % (host_ip, hostname))
+ raise Exception('Exec command to get host ip from hostname(%s)'
+ 'in Apex installer failed, ret=%s, output=%s'
+ % (hostname, ret, host_ip))
+ self.log.info('Get host_ip:%s from host_name:%s in Apex installer'
+ % (host_ip, hostname))
return host_ip[0]
def setup_stunnel(self):
- self.log.info('Setup ssh stunnel in controller nodes in Apex installer......')
+ self.log.info('Setup ssh stunnel in controller nodes'
+ ' in Apex installer......')
for node_ip in self.controllers:
- cmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i %s %s@%s -R %s:localhost:%s sleep 600 > ssh_tunnel.%s.log 2>&1 < /dev/null &" \
- % (self.key_file, self.node_user_name, node_ip,
- self.conf.consumer.port, self.conf.consumer.port, node_ip)
+ cmd = ("ssh -o UserKnownHostsFile=/dev/null"
+ "-o StrictHostKeyChecking=no"
+ "-i %s %s@%s -R %s:localhost:%s"
+ "sleep 600 > ssh_tunnel.%s.log"
+ "2>&1 < /dev/null &"
+ % (self.key_file,
+ self.node_user_name,
+ node_ip,
+ self.conf.consumer.port,
+ self.conf.consumer.port,
+ node_ip))
server = subprocess.Popen(cmd, shell=True)
self.servers.append(server)
server.communicate()
@@ -104,7 +117,8 @@ class ApexInstaller(BaseInstaller):
self.log.info('Set apply patches start......')
for node_ip in self.controllers:
- client = SSHClient(node_ip, self.node_user_name, key_filename=self.key_file)
+ client = SSHClient(node_ip, self.node_user_name,
+ key_filename=self.key_file)
self.controller_clients.append(client)
self._ceilometer_apply_patches(client, self.cm_set_script)
@@ -116,13 +130,15 @@ class ApexInstaller(BaseInstaller):
def _ceilometer_apply_patches(self, ssh_client, script_name):
installer_dir = os.path.dirname(os.path.realpath(__file__))
- script_abs_path = '{0}/{1}/{2}'.format(installer_dir, 'common', script_name)
+ script_abs_path = '{0}/{1}/{2}'.format(installer_dir,
+ 'common', script_name)
ssh_client.scp(script_abs_path, script_name)
cmd = 'sudo python %s' % script_name
ret, output = ssh_client.ssh(cmd)
if ret:
- raise Exception('Do the ceilometer command in controller node failed....'
- 'ret=%s, cmd=%s, output=%s' % (ret, cmd, output))
- ssh_client.ssh('sudo systemctl restart openstack-ceilometer-notification.service')
-
+ raise Exception('Do the ceilometer command in controller'
+ ' node failed, ret=%s, cmd=%s, output=%s'
+ % (ret, cmd, output))
+ ssh_client.ssh('sudo systemctl restart '
+ 'openstack-ceilometer-notification.service')
diff --git a/doctor_tests/installer/base.py b/doctor_tests/installer/base.py
index fa39816a..dcb5b1d8 100644
--- a/doctor_tests/installer/base.py
+++ b/doctor_tests/installer/base.py
@@ -9,6 +9,7 @@
import abc
import six
+
@six.add_metaclass(abc.ABCMeta)
class BaseInstaller(object):
def __init__(self, conf, log):
diff --git a/doctor_tests/installer/common/congress.py b/doctor_tests/installer/common/congress.py
index db882de2..cc58c390 100644
--- a/doctor_tests/installer/common/congress.py
+++ b/doctor_tests/installer/common/congress.py
@@ -6,6 +6,8 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+
def set_doctor_driver_conf(ssh_client, restart_cmd):
cg_set_cmd = '''#!/bin/bash
co_conf=/etc/congress/congress.conf
@@ -23,8 +25,9 @@ fi
ret, output = ssh_client.ssh(cg_set_cmd)
if ret:
- raise Exception('Do the congress command in controller node failed....'
- 'ret=%s, cmd=%s, output=%s' % (ret, cg_set_cmd, output))
+ raise Exception('Do the congress command in controller node failed...'
+ 'ret=%s, cmd=%s, output=%s'
+ % (ret, cg_set_cmd, output))
def restore_doctor_driver_conf(ssh_client, restart_cmd):
@@ -43,5 +46,6 @@ fi
ret, output = ssh_client.ssh(cg_restore_cmd)
if ret:
- raise Exception('Do the congress command in controller node failed....'
- 'ret=%s, cmd=%s, output=%s' % (ret, cg_restore_cmd, output))
+ raise Exception('Do the congress command in controller node failed...'
+ 'ret=%s, cmd=%s, output=%s'
+ % (ret, cg_restore_cmd, output))
diff --git a/doctor_tests/installer/common/set_ceilometer.py b/doctor_tests/installer/common/set_ceilometer.py
index f5946cb2..4050aaef 100644
--- a/doctor_tests/installer/common/set_ceilometer.py
+++ b/doctor_tests/installer/common/set_ceilometer.py
@@ -33,7 +33,8 @@ def set_notifier_topic():
publishers.append(event_notifier_topic)
config_modified = True
else:
- print('NOTE: event notifier is configured in ceilometer as we needed')
+ print('NOTE: event notifier is configured'
+ 'in ceilometer as we needed')
if config_modified:
shutil.copyfile(ep_file, ep_file_bak)
diff --git a/doctor_tests/installer/common/vitrage.py b/doctor_tests/installer/common/vitrage.py
index 9ea32271..30a73f5d 100644
--- a/doctor_tests/installer/common/vitrage.py
+++ b/doctor_tests/installer/common/vitrage.py
@@ -9,7 +9,8 @@
import os
-vitrage_template_file = '/etc/vitrage/templates/vitrage_host_down_scenarios.yaml'
+vitrage_template_file = \
+ '/etc/vitrage/templates/vitrage_host_down_scenarios.yaml'
template = """
metadata:
@@ -86,13 +87,15 @@ scenarios:
action_type: mark_down
action_target:
target: instance
-"""
+""" # noqa
def set_vitrage_host_down_template():
if os.path.isfile(vitrage_template_file):
- print('Vitrage host_down template file: %s already exists.' % vitrage_template_file)
+ print('Vitrage host_down template file: %s already exists.'
+ % vitrage_template_file)
else:
- print('Create Vitrage host_down template file:%s.' % vitrage_template_file)
+ print('Create Vitrage host_down template file:%s.'
+ % vitrage_template_file)
with open(vitrage_template_file, 'w') as file:
file.write(template)
diff --git a/doctor_tests/installer/local.py b/doctor_tests/installer/local.py
index 453755c2..fee14f33 100644
--- a/doctor_tests/installer/local.py
+++ b/doctor_tests/installer/local.py
@@ -11,7 +11,8 @@ import shutil
import subprocess
from doctor_tests.installer.base import BaseInstaller
-from doctor_tests.installer.common.vitrage import set_vitrage_host_down_template
+from doctor_tests.installer.common.vitrage import \
+ set_vitrage_host_down_template
from doctor_tests.common.constants import Inspector
from doctor_tests.common.utils import load_json_file
from doctor_tests.common.utils import write_json_file
@@ -36,7 +37,8 @@ class LocalInstaller(BaseInstaller):
self.restore_apply_patches()
def get_ssh_key_from_installer(self):
- self.log.info('Assuming SSH keys already exchanged with computer for local installer type')
+ self.log.info('Assuming SSH keys already exchanged with computer'
+ 'for local installer type')
return None
def get_host_ip_from_hostname(self, hostname):
@@ -47,7 +49,8 @@ class LocalInstaller(BaseInstaller):
stdout, stderr = server.communicate()
host_ip = stdout.strip().decode("utf-8")
- self.log.info('Get host_ip:%s from host_name:%s in local installer' % (host_ip, hostname))
+ self.log.info('Get host_ip:%s from host_name:%s in local installer'
+ % (host_ip, hostname))
return host_ip
def set_apply_patches(self):
@@ -103,7 +106,8 @@ class LocalInstaller(BaseInstaller):
def _restore_nova_policy(self):
if self.policy_modified:
- shutil.copyfile(self.nova_policy_file_backup, self.nova_policy_file)
+ shutil.copyfile(self.nova_policy_file_backup,
+ self.nova_policy_file)
os.remove(self.nova_policy_file_backup)
elif self.add_policy_file:
os.remove(self.nova_policy_file)
diff --git a/doctor_tests/instance.py b/doctor_tests/instance.py
index 27f412e2..960e7057 100644
--- a/doctor_tests/instance.py
+++ b/doctor_tests/instance.py
@@ -54,14 +54,15 @@ class Instance(object):
flavors = {flavor.name: flavor for flavor in self.nova.flavors.list()}
flavor = flavors.get(self.conf.flavor)
image = self.nova.glance.find_image(self.conf.image_name)
- network = self.neutron.list_networks(name=self.conf.net_name)['networks'][0]
+ network = \
+ self.neutron.list_networks(name=self.conf.net_name)['networks'][0]
nics = {'net-id': network['id']}
self.servers = \
{getattr(server, 'name'): server
for server in self.nova.servers.list()}
for i in range(0, self.conf.instance_count):
- vm_name = "%s%d"%(self.conf.instance_basename, i)
+ vm_name = "%s%d" % (self.conf.instance_basename, i)
self.vm_names.append(vm_name)
if vm_name not in self.servers:
server = self.nova.servers.create(vm_name, image,
@@ -111,4 +112,3 @@ class Instance(object):
count += 1
time.sleep(2)
raise Exception('time out for vm launch')
-
diff --git a/doctor_tests/main.py b/doctor_tests/main.py
index b9a34430..3f346356 100644
--- a/doctor_tests/main.py
+++ b/doctor_tests/main.py
@@ -95,7 +95,8 @@ class DoctorTest(object):
self.setup()
# wait for aodh alarms are updated in caches for event evaluator,
- # sleep time should be larger than event_alarm_cache_ttl(default 60)
+ # sleep time should be larger than event_alarm_cache_ttl
+ # (default 60)
time.sleep(60)
# injecting host failure...
@@ -110,9 +111,11 @@ class DoctorTest(object):
notification_time = calculate_notification_time(LogFile)
if notification_time < 1 and notification_time > 0:
- LOG.info('doctor test successfully, notification_time=%s' % notification_time)
+ LOG.info('doctor test successfully, notification_time=%s'
+ % notification_time)
else:
- LOG.error('doctor test failed, notification_time=%s' % notification_time)
+ LOG.error('doctor test failed, notification_time=%s'
+ % notification_time)
sys.exit(1)
if self.conf.profiler_type:
@@ -144,13 +147,15 @@ class DoctorTest(object):
return Host(host_name, host_ip)
def check_host_status(self, hostname, state):
- service = self.nova.services.list(host=hostname, binary='nova-compute')
+ service = self.nova.services.list(host=hostname,
+ binary='nova-compute')
host_state = service[0].__dict__.get('state')
assert host_state == state
def unset_forced_down_hosts(self):
if self.down_host:
- self.nova.services.force_down(self.down_host.name, 'nova-compute', False)
+ self.nova.services.force_down(self.down_host.name,
+ 'nova-compute', False)
time.sleep(2)
self.check_host_status(self.down_host.name, 'up')
@@ -178,11 +183,16 @@ class DoctorTest(object):
# TODO(yujunz) check the actual delay to verify time sync status
# expected ~1s delay from $trigger to $linkdown
relative_start = linkdown
- os.environ['DOCTOR_PROFILER_T00'] = str(int((linkdown - relative_start)*1000))
- os.environ['DOCTOR_PROFILER_T01'] = str(int((detected - relative_start) * 1000))
- os.environ['DOCTOR_PROFILER_T03'] = str(int((vmdown - relative_start) * 1000))
- os.environ['DOCTOR_PROFILER_T04'] = str(int((hostdown - relative_start) * 1000))
- os.environ['DOCTOR_PROFILER_T09'] = str(int((notified - relative_start) * 1000))
+ os.environ['DOCTOR_PROFILER_T00'] = \
+ str(int((linkdown - relative_start) * 1000))
+ os.environ['DOCTOR_PROFILER_T01'] = \
+ str(int((detected - relative_start) * 1000))
+ os.environ['DOCTOR_PROFILER_T03'] = \
+ str(int((vmdown - relative_start) * 1000))
+ os.environ['DOCTOR_PROFILER_T04'] = \
+ str(int((hostdown - relative_start) * 1000))
+ os.environ['DOCTOR_PROFILER_T09'] = \
+ str(int((notified - relative_start) * 1000))
profiler_main(log=LOG)
@@ -206,7 +216,8 @@ def main():
doctor_root_dir = os.path.dirname(test_dir)
config_file_dir = '{0}/{1}'.format(doctor_root_dir, 'etc/')
- config_files = [join(config_file_dir, f) for f in os.listdir(config_file_dir)
+ config_files = [join(config_file_dir, f)
+ for f in os.listdir(config_file_dir)
if isfile(join(config_file_dir, f))]
conf = config.prepare_conf(args=sys.argv[1:],
diff --git a/doctor_tests/monitor/__init__.py b/doctor_tests/monitor/__init__.py
index 7e30c9f8..76839720 100644
--- a/doctor_tests/monitor/__init__.py
+++ b/doctor_tests/monitor/__init__.py
@@ -23,6 +23,7 @@ _monitor_name_class_mapping = {
'collectd': 'doctor_tests.monitor.collectd.CollectdMonitor'
}
+
def get_monitor(conf, inspector_url, log):
monitor_class = _monitor_name_class_mapping.get(conf.monitor.type)
return importutils.import_object(monitor_class, conf,
diff --git a/doctor_tests/monitor/collectd.py b/doctor_tests/monitor/collectd.py
index 4e9329c2..60150b12 100644
--- a/doctor_tests/monitor/collectd.py
+++ b/doctor_tests/monitor/collectd.py
@@ -9,7 +9,6 @@
import os
import socket
import getpass
-import sys
from doctor_tests.monitor.base import BaseMonitor
@@ -22,11 +21,11 @@ class CollectdMonitor(BaseMonitor):
tmp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
tmp_sock.connect(("8.8.8.8", 80))
- ## control_ip is the IP of primary interface of control node i.e.
- ## eth0, eno1. It is used by collectd monitor to communicate with
- ## sample inspector.
- ## TODO (umar) see if mgmt IP of control is a better option. Also
- ## primary interface may not be the right option
+ # control_ip is the IP of primary interface of control node i.e.
+ # eth0, eno1. It is used by collectd monitor to communicate with
+ # sample inspector.
+ # TODO (umar) see if mgmt IP of control is a better option. Also
+ # primary interface may not be the right option
self.control_ip = tmp_sock.getsockname()[0]
self.compute_user = getpass.getuser()
self.interface_name = os.environ.get('INTERFACE_NAME') or ''
@@ -35,18 +34,21 @@ class CollectdMonitor(BaseMonitor):
self.username = os.environ.get('OS_USERNAME')
self.password = os.environ.get('OS_PASSWORD')
self.project_name = os.environ.get('OS_PROJECT_NAME')
- self.user_domain_name = os.environ.get('OS_USER_DOMAIN_NAME') or 'default'
+ self.user_domain_name = \
+ os.environ.get('OS_USER_DOMAIN_NAME') or 'default'
self.user_domain_id = os.environ.get('OS_USER_DOMAIN_ID')
- self.project_domain_name = os.environ.get('OS_PROJECT_DOMAIN_NAME') or 'default'
+ self.project_domain_name = \
+ os.environ.get('OS_PROJECT_DOMAIN_NAME') or 'default'
self.project_domain_id = os.environ.get('OS_PROJECT_DOMAIN_ID')
- self.ssh_opts_cpu = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
+ self.ssh_opts_cpu = \
+ '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
def start(self, host):
self.log.info("Collectd monitor start.........")
self.compute_host = host.name
self.compute_ip = host.ip
f = open("%s/collectd.conf" % self.top_dir, 'w')
- collectd_conf_file = """
+ collectd_conf_file = """
Hostname %s
FQDNLookup false
Interval 1
@@ -93,16 +95,21 @@ LoadPlugin logfile
SendNotification true
DispatchValues false
</Plugin>
- """ % (self.compute_host, self.compute_user, self.control_ip, self.compute_ip, self.compute_host, self.compute_user,
- self.inspector_type, self.auth_url, self.username, self.password, self.project_name, self.user_domain_name,
- self.user_domain_id, self.project_domain_name, self.project_domain_id)
+ """ % (self.compute_host, self.compute_user, self.control_ip,
+ self.compute_ip, self.compute_host, self.compute_user,
+ self.inspector_type, self.auth_url, self.username,
+ self.password, self.project_name, self.user_domain_name,
+ self.user_domain_id, self.project_domain_name,
+ self.project_domain_id)
f.write(collectd_conf_file)
f.close()
- os.system(" scp %s %s/collectd.conf %s@%s: " % (self.ssh_opts_cpu, self.top_dir, self.compute_user, self.compute_ip))
+ os.system("scp %s %s/collectd.conf %s@%s: "
+ % (self.ssh_opts_cpu, self.top_dir,
+ self.compute_user, self.compute_ip))
self.log.info("after first scp")
- ## @TODO (umar) Always assuming that the interface is assigned an IP if
- ## interface name is not provided. See if there is a better approach
+ # @TODO (umar) Always assuming that the interface is assigned an IP if
+ # interface name is not provided. See if there is a better approach
os.system(""" ssh %s %s@%s \"if [ -n \"%s\" ]; then
dev=%s
else
@@ -115,15 +122,24 @@ LoadPlugin logfile
else
sudo touch \${collectd_conf}-doctor-created
fi
- sudo mv collectd.conf /opt/collectd/etc/collectd.conf\" """ % (self.ssh_opts_cpu, self.compute_user, self.compute_ip, self.interface_name, self.interface_name, self.compute_ip))
+ sudo mv collectd.conf /opt/collectd/etc/collectd.conf\" """
+ % (self.ssh_opts_cpu, self.compute_user,
+ self.compute_ip, self.interface_name,
+ self.interface_name, self.compute_ip))
self.log.info("after first ssh")
- os.system(" scp %s %s/monitor/collectd_plugin.py %s@%s:collectd_plugin.py " % (self.ssh_opts_cpu, self.top_dir, self.compute_user, self.compute_ip))
+ os.system("scp %s %s/monitor/collectd_plugin.py"
+ "%s@%s:collectd_plugin.py"
+ % (self.ssh_opts_cpu, self.top_dir,
+ self.compute_user, self.compute_ip))
self.log.info("after sec scp")
- os.system(" ssh %s %s@%s \"sudo pkill collectd; sudo /opt/collectd/sbin/collectd\" " % (self.ssh_opts_cpu, self.compute_user, self.compute_ip))
+ os.system("ssh %s %s@%s \"sudo pkill collectd;"
+ "sudo /opt/collectd/sbin/collectd\" "
+ % (self.ssh_opts_cpu, self.compute_user, self.compute_ip))
self.log.info("after sec ssh")
def stop(self):
- os.system(" ssh %s %s@%s \"sudo pkill collectd\" " % (self.ssh_opts_cpu, self.compute_user, self.compute_ip))
+ os.system(" ssh %s %s@%s \"sudo pkill collectd\" "
+ % (self.ssh_opts_cpu, self.compute_user, self.compute_ip))
def cleanup(self):
os.system(""" ssh %s %s@%s \"
diff --git a/doctor_tests/monitor/collectd_plugin.py b/doctor_tests/monitor/collectd_plugin.py
index 57105f33..f4341020 100644
--- a/doctor_tests/monitor/collectd_plugin.py
+++ b/doctor_tests/monitor/collectd_plugin.py
@@ -23,7 +23,7 @@ from congressclient.v1 import client
def write_debug(str_write, write_type, compute_user):
file_name = ('/home/%s/monitor.log' % compute_user)
file_tmp = open(file_name, write_type)
- file_tmp.write( "%s" % str_write)
+ file_tmp.write("%s" % str_write)
file_tmp.close()
@@ -84,48 +84,51 @@ class DoctorMonitorCollectd(object):
collectd.info('Unknown config key "%s"' % key)
def init_collectd(self):
- write_debug("Compute node collectd monitor start at %s\n\n" % datetime.now().isoformat(), "w", self.compute_user)
+ write_debug("Compute node collectd monitor start at %s\n\n"
+ % datetime.now().isoformat(), "w", self.compute_user)
if self.inspector_type == 'sample':
self.inspector_url = ('http://%s:12345/events' % self.control_ip)
elif self.inspector_type == 'congress':
loader = loading.get_plugin_loader('password')
- self.auth = loader.load_from_options(auth_url=self.os_auth_url,
- username=self.os_username,
- password=self.os_password,
- project_name=self.os_project_name,
- user_domain_name=self.os_user_domain_name,
- user_domain_id=self.os_user_domain_id,
- project_domain_name=self.os_project_domain_name,
- project_domain_id=self.os_project_domain_id)
- self.sess=session.Session(auth=self.auth)
+ self.auth = loader.load_from_options(
+ auth_url=self.os_auth_url,
+ username=self.os_username,
+ password=self.os_password,
+ project_name=self.os_project_name,
+ user_domain_name=self.os_user_domain_name,
+ user_domain_id=self.os_user_domain_id,
+ project_domain_name=self.os_project_domain_name,
+ project_domain_id=self.os_project_domain_id)
+ self.sess = session.Session(auth=self.auth)
congress = client.Client(session=self.sess, service_type='policy')
ds = congress.list_datasources()['results']
- doctor_ds = next((item for item in ds if item['driver'] == 'doctor'),
- None)
+ doctor_ds = next(
+ (item for item in ds if item['driver'] == 'doctor'), None)
- congress_endpoint = congress.httpclient.get_endpoint(auth=self.auth)
- self.inspector_url = ('%s/v1/data-sources/%s/tables/events/rows' %
- (congress_endpoint, doctor_ds['id']))
+ congress_endpoint = \
+ congress.httpclient.get_endpoint(auth=self.auth)
+ self.inspector_url = ('%s/v1/data-sources/%s/tables/events/rows'
+ % (congress_endpoint, doctor_ds['id']))
else:
sys.exit()
self.start_notifications = 1
-
def notify_inspector(self):
event_type = "compute.host.down"
payload = [
{
- 'id': ("monitor_%s_id1" % self.monitor_type),
- 'time': datetime.now().isoformat(),
- 'type': event_type,
- 'details': {
- 'hostname': self.host_name,
- 'status': 'down',
- 'monitor': ("monitor_%s" % self.monitor_type),
- 'monitor_event_id': ("monitor_%s_event1" % self.monitor_type)
- },
- },
+ 'id': ("monitor_%s_id1" % self.monitor_type),
+ 'time': datetime.now().isoformat(),
+ 'type': event_type,
+ 'details': {
+ 'hostname': self.host_name,
+ 'status': 'down',
+ 'monitor': ("monitor_%s" % self.monitor_type),
+ 'monitor_event_id':
+ ("monitor_%s_event1" % self.monitor_type)
+ },
+ },
]
data = json.dumps(payload)
self.inspector_notified = 1
@@ -135,7 +138,7 @@ class DoctorMonitorCollectd(object):
try:
requests.post(self.inspector_url, data=data, headers=headers)
except ConnectionError as err:
- print err
+ print(err)
elif self.inspector_type == 'congress':
# TODO(umar) enhance for token expiry case
headers = {
@@ -145,22 +148,25 @@ class DoctorMonitorCollectd(object):
}
requests.put(self.inspector_url, data=data, headers=headers)
-
- def handle_notif(self, notification, data=None):
- if (notification.severity == collectd.NOTIF_FAILURE or
- notification.severity == collectd.NOTIF_WARNING):
- if (self.start_notifications == 1 and self.inspector_notified == 0):
- write_debug("Received down notification: doctor monitor detected at %s\n" % time.time(), "a", self.compute_user)
+ def handle_notify(self, notification, data=None):
+ if (notification.seerity == collectd.NOTIF_FAILURE or
+ notification.severity == collectd.NOTIF_WARNING):
+ if (self.start_notifications == 1 and
+ self.inspector_notified == 0):
+ write_debug("Received down notification:"
+ "doctor monitor detected at %s\n"
+ % time.time(), "a", self.compute_user)
self.notify_inspector()
elif notification.severity == collectd.NOTIF_OKAY:
collectd.info("Interface status: UP again %s\n" % time.time())
else:
- collectd.info("Unknown notification severity %s\n" % notification.severity)
+ collectd.info("Unknown notification severity %s\n"
+ % notification.severity)
monitor = DoctorMonitorCollectd()
collectd.register_config(monitor.config_func)
collectd.register_init(monitor.init_collectd)
-collectd.register_notification(monitor.handle_notif)
+collectd.register_notification(monitor.handle_notify)
diff --git a/doctor_tests/monitor/sample.py b/doctor_tests/monitor/sample.py
index 4dc5e603..c207cd9f 100644
--- a/doctor_tests/monitor/sample.py
+++ b/doctor_tests/monitor/sample.py
@@ -51,16 +51,20 @@ class SampleMonitor(BaseMonitor):
}
auth_token = self.session.get_token() if \
- self.conf.inspector.type != 'sample' else None
+ self.conf.inspector.type != 'sample' else None
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Auth-Token': auth_token,
}
if self.conf.inspector.type != Inspector.VITRAGE:
- requests.put(self.inspector_url, data=json.dumps([data]), headers=headers)
+ requests.put(self.inspector_url,
+ data=json.dumps([data]),
+ headers=headers)
else:
- requests.post(self.inspector_url, data=json.dumps(data), headers=headers)
+ requests.post(self.inspector_url,
+ data=json.dumps(data),
+ headers=headers)
class Pinger(Thread):
diff --git a/doctor_tests/network.py b/doctor_tests/network.py
index ee153e66..0965e01f 100644
--- a/doctor_tests/network.py
+++ b/doctor_tests/network.py
@@ -47,7 +47,8 @@ class Network(object):
self.log.info('network create end.......')
self.log.info('subnet create start.......')
- subnets = self.neutron.list_subnets(network_id=self.net['id'])['subnets']
+ subnets = \
+ self.neutron.list_subnets(network_id=self.net['id'])['subnets']
subnet_param = {'name': net_name, 'network_id': self.net['id'],
'cidr': self.conf.net_cidr, 'ip_version': 4,
'enable_dhcp': False}
diff --git a/doctor_tests/profiler_poc.py b/doctor_tests/profiler_poc.py
index ea36eaeb..9f1df33a 100644
--- a/doctor_tests/profiler_poc.py
+++ b/doctor_tests/profiler_poc.py
@@ -12,7 +12,8 @@ PoC of performance profiler for OPNFV doctor project
Usage:
-Export environment variables to set timestamp at each checkpoint in millisecond.
+Export environment variables to set timestamp at each
+checkpoint in millisecond.
Valid check points are: DOCTOR_PROFILER_T{00-09}
See also: https://goo.gl/98Osig
@@ -53,7 +54,7 @@ link down:{T00}| | | | | | | | |
evaluated event:{T07}| |
fired alarm:{T08}|
received alarm:{T09}
-"""
+""" # noqa
def main(log=None):
diff --git a/doctor_tests/scenario/network_failure.py b/doctor_tests/scenario/network_failure.py
index b2309435..b55440ed 100644
--- a/doctor_tests/scenario/network_failure.py
+++ b/doctor_tests/scenario/network_failure.py
@@ -47,18 +47,24 @@ class NetworkFault(object):
def get_disable_network_log(self):
if self.GetLog:
- self.log.info('Already get the disable_netork.log from down_host......')
+ self.log.info('Already get the disable_netork.log '
+ 'from down_host......')
return self.disable_network_log
if self.host is not None:
- client = SSHClient(self.host.ip,
- self.installer.node_user_name,
- key_filename=self.installer.get_ssh_key_from_installer(),
- look_for_keys=True,
- log=self.log)
+ client = SSHClient(
+ self.host.ip,
+ self.installer.node_user_name,
+ key_filename=self.installer.get_ssh_key_from_installer(),
+ look_for_keys=True,
+ log=self.log)
- self.disable_network_log = '{0}/{1}'.format(self.test_dir, 'disable_network.log')
- client.scp('disable_network.log', self.disable_network_log, method='get')
- self.log.info('Get the disable_netork.log from down_host(host_name:%s, host_ip:%s)'
+ self.disable_network_log = '{0}/{1}'.format(self.test_dir,
+ 'disable_network.log')
+ client.scp('disable_network.log',
+ self.disable_network_log,
+ method='get')
+ self.log.info('Get the disable_netork.log from'
+ 'down_host(host_name:%s, host_ip:%s)'
% (self.host.name, self.host.ip))
self.GetLog = True
return self.disable_network_log
@@ -67,11 +73,12 @@ class NetworkFault(object):
file_name = '{0}/{1}'.format(self.test_dir, 'disable_network.sh')
with open(file_name, 'w') as file:
file.write(LINK_DOWN_SCRIPT.format(compute_ip=compute_ip))
- client = SSHClient(compute_ip,
- self.installer.node_user_name,
- key_filename=self.installer.get_ssh_key_from_installer(),
- look_for_keys=True,
- log=self.log)
+ client = SSHClient(
+ compute_ip,
+ self.installer.node_user_name,
+ key_filename=self.installer.get_ssh_key_from_installer(),
+ look_for_keys=True,
+ log=self.log)
client.scp(file_name, 'disable_network.sh')
command = 'bash disable_network.sh > disable_network.log 2>&1 &'
client.ssh(command)
diff --git a/doctor_tests/user.py b/doctor_tests/user.py
index 5598a2d5..b5637d93 100644
--- a/doctor_tests/user.py
+++ b/doctor_tests/user.py
@@ -88,12 +88,13 @@ class User(object):
self.conf.doctor_domain_id)
self.projects[test_project.name] = test_project
else:
- self.log.info('project %s already created......' % self.conf.doctor_project)
- self.log.info('test project %s' % str(self.projects[self.conf.doctor_project]))
+ self.log.info('project %s already created......'
+ % self.conf.doctor_project)
+ self.log.info('test project %s'
+ % str(self.projects[self.conf.doctor_project]))
def _create_user(self):
"""create test user"""
- project = self.projects.get(self.conf.doctor_project)
self.users = {user.name: user for user in
self.keystone.users.list(
domain=self.conf.doctor_domain_id)}
@@ -105,8 +106,10 @@ class User(object):
domain=self.conf.doctor_domain_id)
self.users[test_user.name] = test_user
else:
- self.log.info('user %s already created......' % self.conf.doctor_user)
- self.log.info('test user %s' % str(self.users[self.conf.doctor_user]))
+ self.log.info('user %s already created......'
+ % self.conf.doctor_user)
+ self.log.info('test user %s'
+ % str(self.users[self.conf.doctor_user]))
def _create_role(self):
"""create test role"""
@@ -119,7 +122,8 @@ class User(object):
self.roles[test_role.name] = test_role
else:
self.use_exist_role = True
- self.log.info('role %s already created......' % self.conf.doctor_role)
+ self.log.info('role %s already created......'
+ % self.conf.doctor_role)
self.log.info('test role %s' % str(self.roles[self.conf.doctor_role]))
def _add_user_role_in_project(self, is_admin=False):
@@ -178,9 +182,10 @@ class User(object):
self.quota = self.nova.quotas.get(project.id,
user_id=user.id)
if self.conf.quota_instances > self.quota.instances:
- self.nova.quotas.update(project.id,
- instances=self.conf.quota_instances,
- user_id=user.id)
+ self.nova.quotas.update(
+ project.id,
+ instances=self.conf.quota_instances,
+ user_id=user.id)
if self.conf.quota_cores > self.quota.cores:
self.nova.quotas.update(project.id,
cores=self.conf.quota_cores,
@@ -188,4 +193,3 @@ class User(object):
self.log.info('user quota update end......')
else:
raise Exception('No project or role for update quota')
-
diff --git a/requirements.txt b/requirements.txt
index 0f4e88be..9a355184 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -16,3 +16,4 @@ python-congressclient<2000,>=1.3.0 # Apache-2.0
python-glanceclient>=2.8.0 # Apache-2.0
python-vitrageclient>=1.2.0 # Apache-2.0
virtualenv>=13.1.0 # MIT
+flake8<2.6.0,>=2.5.4 # MIT
diff --git a/tox.ini b/tox.ini
index e9a14077..2eaadacd 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
[tox]
minversion = 2.3.1
-envlist = py35
+envlist = py35, pep8
skipsdist = True
[testenv]
@@ -30,3 +30,19 @@ passenv =
PROFILER_TYPE
changedir = {toxinidir}/doctor_tests
commands = doctor-test
+
+[testenv:pep8]
+changedir = {toxinidir}
+commands = flake8
+
+[flake8]
+# E123, E125 skipped as they are invalid PEP-8.
+# H106: Don’t put vim configuration in source files
+# H203: Use assertIs(Not)None to check for None
+
+show-source = True
+ignore = E123,E125
+enable-extensions=H106,H203
+builtins = _
+filename = *.py,app.wsgi
+exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tests