Merge "flake8 everything"

This commit is contained in:
Jenkins 2016-09-17 02:56:37 +00:00 committed by Gerrit Code Review
commit 1bcef6a78b
6 changed files with 101 additions and 91 deletions

View File

@ -30,7 +30,7 @@ def per(percent, value):
def remaining(avail, total): def remaining(avail, total):
return "(%dMB/%dMB)" % (avail/1024, total/1024) return "(%dMB/%dMB)" % (avail / 1024, total / 1024)
def interpret_output_df(output): def interpret_output_df(output):
@ -67,9 +67,11 @@ def interpret_output_df(output):
if used + avail != total: if used + avail != total:
return (1, '[WARN] Used + Avail. != Total space') return (1, '[WARN] Used + Avail. != Total space')
elif avail < per(crit_percent, total): elif avail < per(crit_percent, total):
return (2, "[ERR] Ceph df avail. critical %s" % remaining(avail, total)) return (2, "[ERR] Ceph df avail. critical %s" %
remaining(avail, total))
elif avail < per(warn_percent, total): elif avail < per(warn_percent, total):
return (1, "[WARN] Ceph df avail. waring %s" % remaining(avail, total)) return (1, "[WARN] Ceph df avail. waring %s" %
remaining(avail, total))
else: else:
return (0, "[OK] Ceph df avail. seems good %s" % return (0, "[OK] Ceph df avail. seems good %s" %
remaining(avail, total)) remaining(avail, total))

View File

@ -106,11 +106,11 @@ class Novautils(object):
endpoint_url = urlparse.urlparse(url) endpoint_url = urlparse.urlparse(url)
except Exception as e: except Exception as e:
utils.unknown("you must provide an endpoint_url in the form" utils.unknown("you must provide an endpoint_url in the form"
+ "<scheme>://<url>/ (%s)" % e) "<scheme>://<url>/ (%s)" % e)
scheme = endpoint_url.scheme scheme = endpoint_url.scheme
if scheme is None: if scheme is None:
utils.unknown("you must provide an endpoint_url in the form" utils.unknown("you must provide an endpoint_url in the form"
+ "<scheme>://<url>/ (%s)" % e) "<scheme>://<url>/ (%s)" % e)
catalog_url = None catalog_url = None
try: try:
catalog_url = urlparse.urlparse( catalog_url = urlparse.urlparse(
@ -147,10 +147,10 @@ class Novautils(object):
self.notifications.append("Found '%s' present %d time(s)" self.notifications.append("Found '%s' present %d time(s)"
% (volume_name, count)) % (volume_name, count))
else: else:
self.msgs.append("Found '%s' present %d time(s). " self.msgs.append("Found '%s' present %d time(s). " %
% (volume_name, count) (volume_name, count) +
+ "Won't create test volume. " "Won't create test volume. "
+ "Please check and delete.") "Please check and delete.")
def create_volume(self, volume_name, size, availability_zone, volume_type): def create_volume(self, volume_name, size, availability_zone, volume_type):
if not self.msgs: if not self.msgs:
@ -179,7 +179,7 @@ class Novautils(object):
self.volume.get() self.volume.get()
except Exception as e: except Exception as e:
self.msgs.append("Problem getting the status of " self.msgs.append("Problem getting the status of "
+ "the volume: %s" % e) "the volume: %s" % e)
break break
def delete_volume(self): def delete_volume(self):
@ -195,8 +195,8 @@ class Novautils(object):
while not deleted and not self.msgs: while not deleted and not self.msgs:
time.sleep(1) time.sleep(1)
if timer >= timeout: if timer >= timeout:
self.msgs.append("Could not delete the volume within" self.msgs.append("Could not delete the volume within "
+ "%d seconds" % timer) "%d seconds" % timer)
break break
timer += 1 timer += 1
try: try:
@ -232,13 +232,14 @@ def _check_cinder_volume():
parser.add_argument('--endpoint_type', metavar='endpoint_type', type=str, parser.add_argument('--endpoint_type', metavar='endpoint_type', type=str,
default="publicURL", default="publicURL",
help='Endpoint type in the catalog request. ' help="""Endpoint type in the catalog request. """
+ 'Public by default.') """Public by default.""")
parser.add_argument('--force_delete', action='store_true', parser.add_argument('--force_delete', action='store_true',
help='If matching volumes are found, delete them and ' help="""If matching volumes are found, delete """
+ 'add a notification in the message instead of ' """them and add a notification in the """
+ 'getting out in critical state.') """message instead of getting out in """
"""critical state.""")
parser.add_argument('--api_version', metavar='api_version', type=str, parser.add_argument('--api_version', metavar='api_version', type=str,
default='1', default='1',
@ -246,13 +247,13 @@ def _check_cinder_volume():
parser.add_argument('--timeout', metavar='timeout', type=int, parser.add_argument('--timeout', metavar='timeout', type=int,
default=120, default=120,
help='Max number of second to create/delete a volume ' help="""Max number of second to create/delete a """
+ '(120 by default).') """volume (120 by default).""")
parser.add_argument('--volume_name', metavar='volume_name', type=str, parser.add_argument('--volume_name', metavar='volume_name', type=str,
default="monitoring_test", default="monitoring_test",
help='Name of the volume to create ' help="""Name of the volume to create """
+ '(monitoring_test by default)') """(monitoring_test by default)""")
parser.add_argument('--volume_size', metavar='volume_size', type=int, parser.add_argument('--volume_size', metavar='volume_size', type=int,
default=1, default=1,

View File

@ -69,11 +69,11 @@ def mangle_url(orig_url, url):
endpoint_url = urlparse.urlparse(url) endpoint_url = urlparse.urlparse(url)
except Exception as e: except Exception as e:
utils.unknown("you must provide an endpoint_url in the form" utils.unknown("you must provide an endpoint_url in the form"
+ "<scheme>://<url>/ (%s)\n" % e) "<scheme>://<url>/ (%s)\n" % e)
scheme = endpoint_url.scheme scheme = endpoint_url.scheme
if scheme is None: if scheme is None:
utils.unknown("you must provide an endpoint_url in the form" utils.unknown("you must provide an endpoint_url in the form"
+ "<scheme>://<url>/ (%s)\n" % e) "<scheme>://<url>/ (%s)\n" % e)
catalog_url = urlparse.urlparse(orig_url) catalog_url = urlparse.urlparse(orig_url)
port = endpoint_url.port port = endpoint_url.port
@ -114,8 +114,8 @@ class Novautils(object):
dt = datetime.datetime.utcnow() dt = datetime.datetime.utcnow()
td = dt - epoch td = dt - epoch
# return td.total_seconds() # return td.total_seconds()
return int((td.microseconds + (td.seconds + td.days * 24 * 3600) return int((td.microseconds +
* 10**6) / 1e6) (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6)
def check_connection(self, force=False): def check_connection(self, force=False):
if not self.connection_done or force: if not self.connection_done or force:
@ -149,14 +149,14 @@ class Novautils(object):
count += 1 count += 1
if count > 0: if count > 0:
if delete: if delete:
self.notifications.append("Found %d ip(s): %s" self.notifications.append("Found %d ip(s): %s" %
% (count, '{' + ', '.join( (count, '{' + ', '.join(
found_ips) + '}')) found_ips) + '}'))
else: else:
self.msgs.append("Found %d ip(s): %s. " self.msgs.append("Found %d ip(s): %s. " %
% (count, ', '.join(found_ips)) (count, ', '.join(found_ips)) +
+ "Won't create test floating ip. " "Won't create test floating ip. "
+ "Please check and delete.") "Please check and delete.")
def get_network_id(self, router_name): def get_network_id(self, router_name):
if not self.msgs: if not self.msgs:
@ -197,10 +197,10 @@ def fip_type(string):
def _check_neutron_floating_ip(): def _check_neutron_floating_ip():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Check an Floating ip creation. Note that it is able ' description="""Check an Floating ip creation. Note that it is """
+ 'to delete *all* floating ips from a account, so ' """able to delete *all* floating ips from a account, """
+ 'ensure that nothing important is running on the ' """so ensure that nothing important is running on """
+ 'specified account.') """the specified account.""")
parser.add_argument('--auth_url', metavar='URL', type=str, parser.add_argument('--auth_url', metavar='URL', type=str,
default=os.getenv('OS_AUTH_URL'), default=os.getenv('OS_AUTH_URL'),
help='Keystone URL') help='Keystone URL')
@ -222,26 +222,28 @@ def _check_neutron_floating_ip():
parser.add_argument('--endpoint_type', metavar='endpoint_type', type=str, parser.add_argument('--endpoint_type', metavar='endpoint_type', type=str,
default="publicURL", default="publicURL",
help='Endpoint type in the catalog request. ' help="""Endpoint type in the catalog request. """
+ 'Public by default.') """Public by default.""")
parser.add_argument('--force_delete', action='store_true', parser.add_argument('--force_delete', action='store_true',
help='If matching floating ip are found, delete them ' help="""If matching floating ip are found, delete """
+ 'and add a notification in the message instead of ' """them and add a notification in the message"""
+ 'getting out in critical state.') """ instead of getting out in critical """
"""state.""")
parser.add_argument('--timeout', metavar='timeout', type=int, parser.add_argument('--timeout', metavar='timeout', type=int,
default=120, default=120,
help='Max number of second to create/delete a ' help="""Max number of second to create/delete a """
+ 'floating ip (120 by default).') """floating ip (120 by default).""")
parser.add_argument('--floating_ip', metavar='floating_ip', type=fip_type, parser.add_argument('--floating_ip', metavar='floating_ip', type=fip_type,
default=None, default=None,
help='Regex of IP(s) to check for existance. ' help="""Regex of IP(s) to check for existance. """
+ 'This value can be "all" for conveniance (match ' """This value can be "all" for conveniance """
+ 'all ip). This permit to avoid certain floating ' """(match all ip). This permit to avoid """
+ 'ip to be kept. Its default value prevents the ' """certain floating ip to be kept. Its """
+ 'removal of any existing floating ip') """default value prevents the removal of """
"""any existing floating ip""")
parser.add_argument('--ext_router_name', metavar='ext_router_name', parser.add_argument('--ext_router_name', metavar='ext_router_name',
type=str, default='public', type=str, default='public',

View File

@ -88,8 +88,8 @@ class Novautils(object):
dt = datetime.datetime.utcnow() dt = datetime.datetime.utcnow()
td = dt - epoch td = dt - epoch
# return td.total_seconds() # return td.total_seconds()
return int((td.microseconds + (td.seconds + td.days * 24 * 3600) return int((td.microseconds +
* 10**6) / 1e6) (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6)
def check_connection(self, force=False): def check_connection(self, force=False):
if not self.connection_done or force: if not self.connection_done or force:
@ -109,11 +109,11 @@ class Novautils(object):
endpoint_url = urllib.parse.urlparse(url) endpoint_url = urllib.parse.urlparse(url)
except Exception as e: except Exception as e:
utils.unknown("you must provide an endpoint_url in the form" utils.unknown("you must provide an endpoint_url in the form"
+ "<scheme>://<url>/ (%s)\n" % e) "<scheme>://<url>/ (%s)\n" % e)
scheme = endpoint_url.scheme scheme = endpoint_url.scheme
if scheme is None: if scheme is None:
utils.unknown("you must provide an endpoint_url in the form" utils.unknown("you must provide an endpoint_url in the form"
+ "<scheme>://<url>/ (%s)\n" % e) "<scheme>://<url>/ (%s)\n" % e)
catalog_url = None catalog_url = None
try: try:
catalog_url = urllib.parse.urlparse( catalog_url = urllib.parse.urlparse(
@ -153,9 +153,10 @@ class Novautils(object):
% (instance_name, count)) % (instance_name, count))
else: else:
self.msgs.append( self.msgs.append(
"Found '%s' present %d time(s). " % (instance_name, count) "Found '%s' present %d time(s). " %
+ "Won't create test instance. " (instance_name, count) +
+ "Please check and delete.") "Won't create test instance. "
"Please check and delete.")
def get_image(self, image_name): def get_image(self, image_name):
if not self.msgs: if not self.msgs:
@ -246,10 +247,9 @@ class Novautils(object):
time.sleep(1) time.sleep(1)
if timer >= timeout: if timer >= timeout:
self.msgs.append( self.msgs.append(
"Could not delete the vm %s within %d seconds " "Could not delete the vm %s within %d seconds " %
% (instance.name, timer) (instance.name, timer) + "(created at %s)" %
+ "(created at %s)" instance.created)
% instance.created)
break break
timer += 1 timer += 1
try: try:
@ -268,35 +268,39 @@ class Novautils(object):
def _check_nova_instance(): def _check_nova_instance():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Check an OpenStack Keystone server.',conflict_handler='resolve') description='Check an OpenStack Keystone server.',
conflict_handler='resolve')
parser.add_argument('--auth_url','--os-auth-url', metavar='URL', type=str, parser.add_argument('--auth_url', '--os-auth-url', metavar='URL',
default=os.getenv('OS_AUTH_URL'), type=str, default=os.getenv('OS_AUTH_URL'),
help='url to use for authetication (Deprecated)') help='url to use for authetication (Deprecated)')
parser.add_argument('--os-auth-url', dest='auth_url', type=str, parser.add_argument('--os-auth-url', dest='auth_url', type=str,
default=os.getenv('OS_AUTH_URL'), default=os.getenv('OS_AUTH_URL'),
help='url to use for authetication') help='url to use for authetication')
parser.add_argument('--username','--os-username', metavar='username', type=str, parser.add_argument('--username', '--os-username', metavar='username',
default=os.getenv('OS_USERNAME'), type=str, default=os.getenv('OS_USERNAME'),
help='username to use for authentication (Deprecated)') help="""username to use for authentication"""
""" (Deprecated)""")
parser.add_argument('--os-username',dest='username' ,type=str, parser.add_argument('--os-username', dest='username', type=str,
default=os.getenv('OS_USERNAME'), default=os.getenv('OS_USERNAME'),
help='username to use for authentication') help='username to use for authentication')
parser.add_argument('--password','--os-password', metavar='password', type=str, parser.add_argument('--password', '--os-password', metavar='password',
default=os.getenv('OS_PASSWORD'), type=str, default=os.getenv('OS_PASSWORD'),
help='password to use for authentication (Deprecated)') help="""password to use for authentication"""
""" (Deprecated)""")
parser.add_argument('--os-password', dest='password', type=str, parser.add_argument('--os-password', dest='password', type=str,
default=os.getenv('OS_PASSWORD'), default=os.getenv('OS_PASSWORD'),
help='password to use for authentication') help='password to use for authentication')
parser.add_argument('--tenant','--os-tenant-name', metavar='tenant', type=str, parser.add_argument('--tenant', '--os-tenant-name', metavar='tenant',
default=os.getenv('OS_TENANT_NAME'), type=str, default=os.getenv('OS_TENANT_NAME'),
help='tenant name to use for authentication (Deprecated)') help="""tenant name to use for authentication"""
""" (Deprecated)""")
parser.add_argument('--os-tenant-name', dest='tenant', type=str, parser.add_argument('--os-tenant-name', dest='tenant', type=str,
default=os.getenv('OS_TENANT_NAME'), default=os.getenv('OS_TENANT_NAME'),
@ -305,15 +309,16 @@ def _check_nova_instance():
parser.add_argument('--endpoint_url', metavar='endpoint_url', type=str, parser.add_argument('--endpoint_url', metavar='endpoint_url', type=str,
help='Override the catalog endpoint.') help='Override the catalog endpoint.')
parser.add_argument('--endpoint_type','--os-endpoint-type', metavar='endpoint_type', type=str, parser.add_argument('--endpoint_type', '--os-endpoint-type',
metavar='endpoint_type', type=str,
default="publicURL", default="publicURL",
help='Endpoint type in the catalog request. ' help="""Endpoint type in the catalog request. """
+ 'Public by default. (Deprecated)') """Public by default. (Deprecated)""")
parser.add_argument('--os-endpoint-type', dest='endpoint_type', type=str, parser.add_argument('--os-endpoint-type', dest='endpoint_type', type=str,
default="publicURL", default="publicURL",
help='Endpoint type in the catalog request. ' help="""Endpoint type in the catalog request. """
+ 'Public by default.') """Public by default.""")
parser.add_argument('--image_name', metavar='image_name', type=str, parser.add_argument('--image_name', metavar='image_name', type=str,
default=default_image_name, default=default_image_name,
@ -331,9 +336,9 @@ def _check_nova_instance():
% default_instance_name) % default_instance_name)
parser.add_argument('--force_delete', action='store_true', parser.add_argument('--force_delete', action='store_true',
help='If matching instances are found delete them and ' help="""If matching instances are found delete """
+ 'add a notification in the message instead of ' """them and add a notification in the message"""
+ 'getting out in critical state.') """ instead of getting out in critical state.""")
parser.add_argument('--api_version', metavar='api_version', type=str, parser.add_argument('--api_version', metavar='api_version', type=str,
default='2', default='2',
@ -341,13 +346,13 @@ def _check_nova_instance():
parser.add_argument('--timeout', metavar='timeout', type=int, parser.add_argument('--timeout', metavar='timeout', type=int,
default=120, default=120,
help='Max number of second to create a instance' help="""Max number of second to create a instance"""
+ '(120 by default)') """ (120 by default)""")
parser.add_argument('--timeout_delete', metavar='timeout_delete', type=int, parser.add_argument('--timeout_delete', metavar='timeout_delete',
default=45, type=int, default=45,
help='Max number of second to delete an existing ' help="""Max number of second to delete an existing """
+ 'instance (45 by default).') """instance (45 by default).""")
parser.add_argument('--insecure', action='store_true', parser.add_argument('--insecure', action='store_true',
help="The server's cert will not be verified") help="The server's cert will not be verified")

View File

@ -74,10 +74,10 @@ def check_process_exists_and_amqp_connected(name):
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
continue continue
found_amqp = ( found_amqp = (
len(list(itertools.takewhile(lambda c: len(c.remote_address) <= 1 len(list(itertools.takewhile(lambda c:
or c.remote_address[1] len(c.remote_address) <= 1 or
!= AMQP_PORT, connections))) c.remote_address[1] != AMQP_PORT,
!= len(connections)) connections))) != len(connections))
if found_amqp: if found_amqp:
ok("%s is working." % name) ok("%s is working." % name)
critical("%s is not connected to AMQP" % name) critical("%s is not connected to AMQP" % name)
@ -256,7 +256,6 @@ class Keystone(object):
self.shell.stderr = StringIO() self.shell.stderr = StringIO()
self.help = False self.help = False
def run(self): def run(self):
command = ['token', 'issue'] command = ['token', 'issue']
vformat = ['-f', 'value', '-c', 'id'] vformat = ['-f', 'value', '-c', 'id']

View File

@ -32,5 +32,6 @@ commands = flake8
commands = {posargs} commands = {posargs}
[flake8] [flake8]
IGNORE= H105,H405
exclude = .tox,doc exclude = .tox,doc
show-source = true show-source = true