Add Flake8 checks for bin/cfn-* to Gating

Fix the Pep8/hacking/pyflakes warnings in bin/cfn-*.

Change-Id: Ie21b3909c80d33adc712c2f3c9494d0fdbd90608
This commit is contained in:
Dirk Mueller 2013-06-13 09:34:11 +02:00
parent 971c165242
commit 87e08b0b4b
7 changed files with 137 additions and 138 deletions

View File

@ -26,11 +26,13 @@ def create_symlink(source_file, target_file, override=False):
if (override):
os.remove(target_file)
else:
print '%s already exists, will not replace with symlink' % target_file
print('%s already exists, will not replace with symlink'
% target_file)
return
print '%s -> %s' % (source_file, target_file)
os.symlink(source_file, target_file)
def check_dirs(source_dir, target_dir):
print '%s -> %s' % (source_dir, target_dir)
@ -42,10 +44,12 @@ def check_dirs(source_dir, target_dir):
try:
os.makedirs(target_dir)
except OSError as exc:
print 'Could not create target directory %s: %s' % (target_dir, exc)
print('Could not create target directory %s: %s'
% (target_dir, exc))
return False
return True
def create_symlinks(source_dir, target_dir, glob_pattern, override):
source_files = glob.glob(os.path.join(source_dir, glob_pattern))
for source_file in source_files:
@ -53,7 +57,7 @@ def create_symlinks(source_dir, target_dir, glob_pattern, override):
create_symlink(source_file, target_file, override=override)
if __name__ == '__main__':
description = 'Creates symlinks for the cfn-* scripts in this directory to /opt/aws/bin'
description = 'Creates symlinks for the cfn-* scripts to /opt/aws/bin'
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
'-t', '--target',
@ -64,14 +68,16 @@ if __name__ == '__main__':
parser.add_argument(
'-s', '--source',
dest="source_dir",
help="Source directory to create symlinks from. Defaults to the directory where this script is",
help="Source directory to create symlinks from. "
"Defaults to the directory where this script is",
default='/usr/bin',
required=False)
parser.add_argument(
'-f', '--force',
dest="force",
action='store_true',
help="If specified, will create symlinks even if there is already a target file",
help="If specified, will create symlinks even if "
"there is already a target file",
required=False)
args = parser.parse_args()

View File

@ -16,14 +16,10 @@
Implements cfn-get-metadata CloudFormation functionality
"""
import argparse
import io
import logging
import os
import os.path
import sys
from heat_cfntools.cfntools.cfn_helper import *
from heat_cfntools.cfntools import cfn_helper
description = " "
parser = argparse.ArgumentParser(description=description)
@ -78,7 +74,7 @@ file_handler = logging.FileHandler(log_file_name)
file_handler.setFormatter(logging.Formatter(log_format))
LOG.addHandler(file_handler)
metadata = Metadata(args.stack_name,
metadata = cfn_helper.Metadata(args.stack_name,
args.logical_resource_id,
access_key=args.access_key,
secret_key=args.secret_key,

View File

@ -16,14 +16,12 @@
Implements cfn-hup CloudFormation functionality
"""
import argparse
import io
import logging
import os
import os.path
import sys
from heat_cfntools.cfntools.cfn_helper import *
from heat_cfntools.cfntools import cfn_helper
description = " "
parser = argparse.ArgumentParser(description=description)
@ -90,7 +88,7 @@ if not config_files:
exit(1)
try:
mainconfig = HupConfig([main_config_file] + config_files)
mainconfig = cfn_helper.HupConfig([main_config_file] + config_files)
except Exception as ex:
LOG.error('Cannot load configuration: %s' % str(ex))
exit(1)
@ -103,7 +101,7 @@ if not mainconfig.unique_resources_get():
for r in mainconfig.unique_resources_get():
LOG.debug('Checking resource %s' % r)
metadata = Metadata(mainconfig.stack,
metadata = cfn_helper.Metadata(mainconfig.stack,
r,
credentials_file=mainconfig.credential_file,
region=mainconfig.region)

View File

@ -17,11 +17,9 @@ Implements cfn-init CloudFormation functionality
"""
import argparse
import logging
import os
import sys
from heat_cfntools.cfntools.cfn_helper import *
from heat_cfntools.cfntools import cfn_helper
description = " "
parser = argparse.ArgumentParser(description=description)
@ -60,7 +58,7 @@ file_handler = logging.FileHandler(log_file_name)
file_handler.setFormatter(logging.Formatter(log_format))
LOG.addHandler(file_handler)
metadata = Metadata(args.stack_name,
metadata = cfn_helper.Metadata(args.stack_name,
args.logical_resource_id,
access_key=args.access_key,
secret_key=args.secret_key,

View File

@ -19,13 +19,11 @@ import argparse
import logging
import os
import subprocess
import random
import sys
# Override BOTO_CONFIG, which makes boto look only at the specified
# config file, instead of the default locations
os.environ['BOTO_CONFIG'] = '/var/lib/heat-cfntools/cfn-boto-cfg'
from boto.ec2.cloudwatch import CloudWatchConnection
from boto.ec2 import cloudwatch
log_format = '%(levelname)s [%(asctime)s] %(message)s'
@ -41,7 +39,7 @@ except ImportError:
LOG.warn("psutil not available. If you want process and memory "
"statistics, you need to install it.")
from heat_cfntools.cfntools.cfn_helper import *
from heat_cfntools.cfntools import cfn_helper
KILO = 1024
MEGA = 1048576
@ -63,9 +61,11 @@ parser.add_argument('--service-failure', required=False, action="store_true",
parser.add_argument('--mem-util', required=False, action="store_true",
help='Reports memory utilization in percentages.')
parser.add_argument('--mem-used', required=False, action="store_true",
help='Reports memory used (excluding cache and buffers) in megabytes.')
help='Reports memory used (excluding cache/buffers) '
'in megabytes.')
parser.add_argument('--mem-avail', required=False, action="store_true",
help='Reports available memory (including cache and buffers) in megabytes.')
help='Reports available memory (including cache/buffers) '
'in megabytes.')
parser.add_argument('--swap-util', required=False, action="store_true",
help='Reports swap utilization in percentages.')
parser.add_argument('--swap-used', required=False, action="store_true",
@ -74,7 +74,7 @@ parser.add_argument('--disk-space-util', required=False, action="store_true",
help='Reports disk space utilization in percentages.')
parser.add_argument('--disk-space-used', required=False, action="store_true",
help='Reports allocated disk space in gigabytes.')
parser.add_argument('--disk-space-avail',required=False, action="store_true",
parser.add_argument('--disk-space-avail', required=False, action="store_true",
help='Reports available disk space in gigabytes.')
parser.add_argument('--memory-units', required=False, default='megabytes',
help='Specifies units for memory metrics.')
@ -103,7 +103,7 @@ args = parser.parse_args()
LOG.debug('cfn-push-stats called %s ' % (str(args)))
credentials = parse_creds_file(args.credential_file)
credentials = cfn_helper.parse_creds_file(args.credential_file)
namespace = 'system/linux'
data = {}
@ -185,6 +185,7 @@ if args.cpu_util:
'Value': cpu_percent,
'Units': 'Percent'}
# HAProxy
# =======
def parse_haproxy_unix_socket(res, latency_only=False):
@ -206,8 +207,8 @@ def parse_haproxy_unix_socket(res, latency_only=False):
stdin=echo.stdout,
stdout=subprocess.PIPE)
end_pipe = socat.stdout
raw = [l.strip('\n').split(',') for l in end_pipe
if l[0] != '#' and len(l) > 2]
raw = [l.strip('\n').split(',')
for l in end_pipe if l[0] != '#' and len(l) > 2]
latency = 0
up_count = 0
down_count = 0
@ -242,7 +243,7 @@ def send_stats(info):
# Create boto connection, need the hard-coded port/path as boto
# can't read these from config values in BOTO_CONFIG
# FIXME : currently only http due to is_secure=False
client = CloudWatchConnection(
client = cloudwatch.CloudWatchConnection(
aws_access_key_id=credentials['AWSAccessKeyId'],
aws_secret_access_key=credentials['AWSSecretKey'],
is_secure=False, port=8003, path="/v1", debug=0)

View File

@ -17,11 +17,10 @@ Implements cfn-signal CloudFormation functionality
"""
import argparse
import logging
import os
import sys
from heat_cfntools.cfntools.cfn_helper import *
from heat_cfntools.cfntools import cfn_helper
description = " "
@ -76,13 +75,13 @@ else:
status = 'SUCCESS'
body = {
"Status" : status,
"Reason" : args.reason,
"UniqueId" : args.unique_id,
"Data" : args.data
"Status": status,
"Reason": args.reason,
"UniqueId": args.unique_id,
"Data": args.data
}
cmd_str = "curl -X PUT -H \'Content-Type:\' --data-binary \'%s\' \"%s\"" % \
(json.dumps(body), args.url)
command = CommandRunner(cmd_str).run()
(cfn_helper.json.dumps(body), args.url)
command = cfn_helper.CommandRunner(cmd_str).run()
sys.exit(command.status)

View File

@ -15,6 +15,7 @@ downloadcache = ~/cache/pip
[testenv:pep8]
commands = flake8
flake8 --filename=cfn-* bin
[testenv:pylint]
setenv = VIRTUAL_ENV={envdir}