Make pep8 tests run against the library directory as well, and associated tweaks (mostly to indentation) in the library
directory.
This commit is contained in:
parent
72faf8eb0a
commit
477ca2ed1a
13 changed files with 128 additions and 133 deletions
3
Makefile
3
Makefile
|
@ -71,7 +71,8 @@ pep8:
|
|||
@echo "#############################################"
|
||||
@echo "# Running PEP8 Compliance Tests"
|
||||
@echo "#############################################"
|
||||
pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261 lib/ bin/
|
||||
-pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261 lib/ bin/
|
||||
-pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261 --filename "*" library/
|
||||
|
||||
pyflakes:
|
||||
pyflakes lib/ansible/*.py bin/*
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
import traceback
|
||||
# added to stave off future warnings about apt api
|
||||
import warnings;
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore', "apt API not stable yet", FutureWarning)
|
||||
|
||||
# APT related constants
|
||||
|
@ -30,8 +30,7 @@ APT = "DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical %s" % APT_PATH
|
|||
|
||||
def run_apt(command):
|
||||
try:
|
||||
cmd = subprocess.Popen(command, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
cmd = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = cmd.communicate()
|
||||
except (OSError, IOError), e:
|
||||
rc = 1
|
||||
|
@ -131,7 +130,8 @@ def main():
|
|||
)
|
||||
|
||||
try:
|
||||
import apt, apt_pkg
|
||||
import apt
|
||||
import apt_pkg
|
||||
except:
|
||||
module.fail_json("Could not import python modules: apt, apt_pkg. Please install python-apt package.")
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ def main():
|
|||
module_fail_json(ansible_job_id=jid, results_file=log_path,
|
||||
msg="Could not parse job output: %s" % data)
|
||||
|
||||
if not data.has_key("started"):
|
||||
if not 'started' in data:
|
||||
data['finished'] = 1
|
||||
data['ansible_job_id'] = jid
|
||||
module.exit_json(**data)
|
||||
|
|
|
@ -54,9 +54,9 @@ def main():
|
|||
delta = endd - startd
|
||||
|
||||
if out is None:
|
||||
out = ''
|
||||
out = ''
|
||||
if err is None:
|
||||
err = ''
|
||||
err = ''
|
||||
|
||||
module.exit_json(
|
||||
cmd = args,
|
||||
|
|
|
@ -26,22 +26,22 @@
|
|||
import subprocess
|
||||
|
||||
def get_facter_data():
|
||||
p = subprocess.Popen(["/usr/bin/env", "facter", "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(out, err) = p.communicate()
|
||||
rc = p.returncode
|
||||
return rc, out, err
|
||||
p = subprocess.Popen(["/usr/bin/env", "facter", "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(out, err) = p.communicate()
|
||||
rc = p.returncode
|
||||
return rc, out, err
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict()
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict()
|
||||
)
|
||||
|
||||
rc, out, err = get_facter_data()
|
||||
if rc != 0:
|
||||
module.fail_json(msg=err)
|
||||
else:
|
||||
module.exit_json(**json.loads(out))
|
||||
rc, out, err = get_facter_data()
|
||||
if rc != 0:
|
||||
module.fail_json(msg=err)
|
||||
else:
|
||||
module.exit_json(**json.loads(out))
|
||||
|
||||
# this is magic, see lib/ansible/module_common.py
|
||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||
|
|
107
library/file
107
library/file
|
@ -112,13 +112,6 @@ def selinux_context(path):
|
|||
context = ret[1].split(':')
|
||||
return context
|
||||
|
||||
# ===========================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ===========================================
|
||||
# support functions
|
||||
|
||||
|
@ -157,64 +150,64 @@ def set_context_if_different(path, context, changed):
|
|||
return changed
|
||||
|
||||
def set_owner_if_different(path, owner, changed):
|
||||
if owner is None:
|
||||
return changed
|
||||
user, group = user_and_group(path)
|
||||
if owner != user:
|
||||
try:
|
||||
uid = pwd.getpwnam(owner).pw_uid
|
||||
except KeyError:
|
||||
module_fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
|
||||
try:
|
||||
os.chown(path, uid, -1)
|
||||
except OSError:
|
||||
module_fail_json(path=path, msg='chown failed')
|
||||
return True
|
||||
if owner is None:
|
||||
return changed
|
||||
user, group = user_and_group(path)
|
||||
if owner != user:
|
||||
try:
|
||||
uid = pwd.getpwnam(owner).pw_uid
|
||||
except KeyError:
|
||||
module_fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
|
||||
try:
|
||||
os.chown(path, uid, -1)
|
||||
except OSError:
|
||||
module_fail_json(path=path, msg='chown failed')
|
||||
return True
|
||||
|
||||
return changed
|
||||
return changed
|
||||
|
||||
def set_group_if_different(path, group, changed):
|
||||
if group is None:
|
||||
return changed
|
||||
old_user, old_group = user_and_group(path)
|
||||
if old_group != group:
|
||||
try:
|
||||
gid = grp.getgrnam(group).gr_gid
|
||||
except KeyError:
|
||||
module_fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
|
||||
try:
|
||||
os.chown(path, -1, gid)
|
||||
except OSError:
|
||||
module_fail_json(path=path, msg='chgrp failed')
|
||||
return True
|
||||
return changed
|
||||
if group is None:
|
||||
return changed
|
||||
old_user, old_group = user_and_group(path)
|
||||
if old_group != group:
|
||||
try:
|
||||
gid = grp.getgrnam(group).gr_gid
|
||||
except KeyError:
|
||||
module_fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
|
||||
try:
|
||||
os.chown(path, -1, gid)
|
||||
except OSError:
|
||||
module_fail_json(path=path, msg='chgrp failed')
|
||||
return True
|
||||
return changed
|
||||
|
||||
def set_mode_if_different(path, mode, changed):
|
||||
if mode is None:
|
||||
return changed
|
||||
try:
|
||||
# FIXME: support English modes
|
||||
mode = int(mode, 8)
|
||||
except Exception, e:
|
||||
module_fail_json(path=path, msg='mode needs to be something octalish', details=str(e))
|
||||
if mode is None:
|
||||
return changed
|
||||
try:
|
||||
# FIXME: support English modes
|
||||
mode = int(mode, 8)
|
||||
except Exception, e:
|
||||
module_fail_json(path=path, msg='mode needs to be something octalish', details=str(e))
|
||||
|
||||
st = os.stat(path)
|
||||
prev_mode = stat.S_IMODE(st[stat.ST_MODE])
|
||||
st = os.stat(path)
|
||||
prev_mode = stat.S_IMODE(st[stat.ST_MODE])
|
||||
|
||||
if prev_mode != mode:
|
||||
# FIXME: comparison against string above will cause this to be executed
|
||||
# every time
|
||||
try:
|
||||
os.chmod(path, mode)
|
||||
except Exception, e:
|
||||
if prev_mode != mode:
|
||||
# FIXME: comparison against string above will cause this to be executed
|
||||
# every time
|
||||
try:
|
||||
os.chmod(path, mode)
|
||||
except Exception, e:
|
||||
module_fail_json(path=path, msg='chmod failed', details=str(e))
|
||||
|
||||
st = os.stat(path)
|
||||
new_mode = stat.S_IMODE(st[stat.ST_MODE])
|
||||
|
||||
st = os.stat(path)
|
||||
new_mode = stat.S_IMODE(st[stat.ST_MODE])
|
||||
|
||||
if new_mode != prev_mode:
|
||||
return True
|
||||
return changed
|
||||
if new_mode != prev_mode:
|
||||
return True
|
||||
return changed
|
||||
|
||||
|
||||
def rmtree_error(func, path, exc_info):
|
||||
|
@ -222,7 +215,9 @@ def rmtree_error(func, path, exc_info):
|
|||
|
||||
def main():
|
||||
|
||||
# FIXME: pass this around, should not use global
|
||||
global module
|
||||
|
||||
module = AnsibleModule(
|
||||
check_invalid_arguments = False,
|
||||
argument_spec = dict(
|
||||
|
|
|
@ -59,8 +59,8 @@ def set_mount(**kwargs):
|
|||
changed = False
|
||||
for line in open(args['fstab'], 'r').readlines():
|
||||
if not line.strip():
|
||||
to_write.append(line)
|
||||
continue
|
||||
to_write.append(line)
|
||||
continue
|
||||
if line.strip().startswith('#'):
|
||||
to_write.append(line)
|
||||
continue
|
||||
|
@ -85,9 +85,9 @@ def set_mount(**kwargs):
|
|||
ld[t] = args[t]
|
||||
|
||||
if changed:
|
||||
to_write.append(new_line % ld)
|
||||
to_write.append(new_line % ld)
|
||||
else:
|
||||
to_write.append(line)
|
||||
to_write.append(line)
|
||||
|
||||
if not exists:
|
||||
to_write.append(new_line % args)
|
||||
|
@ -115,8 +115,8 @@ def unset_mount(**kwargs):
|
|||
changed = False
|
||||
for line in open(args['fstab'], 'r').readlines():
|
||||
if not line.strip():
|
||||
to_write.append(line)
|
||||
continue
|
||||
to_write.append(line)
|
||||
continue
|
||||
if line.strip().startswith('#'):
|
||||
to_write.append(line)
|
||||
continue
|
||||
|
@ -147,9 +147,9 @@ def mount(**kwargs):
|
|||
|
||||
name = kwargs['name']
|
||||
if os.path.ismount(name):
|
||||
cmd = ['/bin/mount', '-o', 'remount', name]
|
||||
cmd = [ '/bin/mount', '-o', 'remount', name ]
|
||||
else:
|
||||
cmd = ['/bin/mount', name ]
|
||||
cmd = [ '/bin/mount', name ]
|
||||
|
||||
call = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = call.communicate()
|
||||
|
|
|
@ -31,9 +31,9 @@ def main():
|
|||
)
|
||||
rc, out, err = get_ohai_data()
|
||||
if rc != 0:
|
||||
module.fail_json(msg=err)
|
||||
module.fail_json(msg=err)
|
||||
else:
|
||||
module.exit_json(**json.loads(out))
|
||||
module.exit_json(**json.loads(out))
|
||||
|
||||
# this is magic, see lib/ansible/module_common.py
|
||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||
|
|
|
@ -207,11 +207,9 @@ def main():
|
|||
if state:
|
||||
result['state'] = state
|
||||
rc, stdout, stderr = _run("%s %s status" % (SERVICE, name))
|
||||
module.exit_json(**result);
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
# this is magic, see lib/ansible/module_common.py
|
||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||
|
||||
main()
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ class Facts(object):
|
|||
self.facts['selinux']['policyvers'] = 'unknown'
|
||||
try:
|
||||
(rc, configmode) = selinux.selinux_getenforcemode()
|
||||
if rc == 0 and Facts.SELINUX_MODE_DICT.has_key(configmode):
|
||||
if rc == 0 and configmode in Facts.SELINUX_MODE_DICT:
|
||||
self.facts['selinux']['config_mode'] = Facts.SELINUX_MODE_DICT[configmode]
|
||||
else:
|
||||
self.facts['selinux']['config_mode'] = 'unknown'
|
||||
|
@ -138,7 +138,7 @@ class Facts(object):
|
|||
self.facts['selinux']['config_mode'] = 'unknown'
|
||||
try:
|
||||
mode = selinux.security_getenforce()
|
||||
if Facts.SELINUX_MODE_DICT.has_key(mode):
|
||||
if mode in Facts.SELINUX_MODE_DICT:
|
||||
self.facts['selinux']['mode'] = Facts.SELINUX_MODE_DICT[mode]
|
||||
else:
|
||||
self.facts['selinux']['mode'] = 'unknown'
|
||||
|
@ -196,19 +196,21 @@ class LinuxHardware(Hardware):
|
|||
|
||||
In addition, it also defines number of DMI facts.
|
||||
"""
|
||||
|
||||
platform = 'Linux'
|
||||
MEMORY_FACTS = ['MemTotal', 'SwapTotal', 'MemFree', 'SwapFree']
|
||||
# DMI bits
|
||||
DMI_DICT = { 'form_factor': '/sys/devices/virtual/dmi/id/chassis_type',
|
||||
'product_name': '/sys/devices/virtual/dmi/id/product_name',
|
||||
'product_serial': '/sys/devices/virtual/dmi/id/product_serial',
|
||||
'product_uuid': '/sys/devices/virtual/dmi/id/product_uuid',
|
||||
'product_version': '/sys/devices/virtual/dmi/id/product_version',
|
||||
'system_vendor': '/sys/devices/virtual/dmi/id/sys_vendor',
|
||||
'bios_date': '/sys/devices/virtual/dmi/id/bios_date',
|
||||
'bios_version': '/sys/devices/virtual/dmi/id/bios_version' }
|
||||
# From smolt and DMI spec
|
||||
# See http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.0.pdf
|
||||
DMI_DICT = dict(
|
||||
form_factor = '/sys/devices/virtual/dmi/id/chassis_type',
|
||||
product_name = '/sys/devices/virtual/dmi/id/product_name',
|
||||
product_serial = '/sys/devices/virtual/dmi/id/product_serial',
|
||||
product_uuid = '/sys/devices/virtual/dmi/id/product_uuid',
|
||||
product_version = '/sys/devices/virtual/dmi/id/product_version',
|
||||
system_vendor = '/sys/devices/virtual/dmi/id/sys_vendor',
|
||||
bios_date = '/sys/devices/virtual/dmi/id/bios_date',
|
||||
bios_version = '/sys/devices/virtual/dmi/id/bios_version'
|
||||
)
|
||||
# DMI SPEC -- http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.0.pdf
|
||||
FORM_FACTOR = [ "Unknown", "Other", "Unknown", "Desktop",
|
||||
"Low Profile Desktop", "Pizza Box", "Mini Tower", "Tower",
|
||||
"Portable", "Laptop", "Notebook", "Hand Held", "Docking Station",
|
||||
|
@ -634,36 +636,36 @@ def run_setup(module):
|
|||
# ruby-json is ALSO installed, include facter data in the JSON
|
||||
|
||||
if os.path.exists("/usr/bin/facter"):
|
||||
cmd = subprocess.Popen("/usr/bin/facter --json", shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = cmd.communicate()
|
||||
facter = True
|
||||
try:
|
||||
facter_ds = json.loads(out)
|
||||
except:
|
||||
facter = False
|
||||
if facter:
|
||||
for (k,v) in facter_ds.items():
|
||||
setup_options["facter_%s" % k] = v
|
||||
cmd = subprocess.Popen("/usr/bin/facter --json", shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = cmd.communicate()
|
||||
facter = True
|
||||
try:
|
||||
facter_ds = json.loads(out)
|
||||
except:
|
||||
facter = False
|
||||
if facter:
|
||||
for (k,v) in facter_ds.items():
|
||||
setup_options["facter_%s" % k] = v
|
||||
|
||||
# ditto for ohai, but just top level string keys
|
||||
# because it contains a lot of nested stuff we can't use for
|
||||
# templating w/o making a nicer key for it (TODO)
|
||||
|
||||
if os.path.exists("/usr/bin/ohai"):
|
||||
cmd = subprocess.Popen("/usr/bin/ohai", shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = cmd.communicate()
|
||||
ohai = True
|
||||
try:
|
||||
ohai_ds = json.loads(out)
|
||||
except:
|
||||
ohai = False
|
||||
if ohai:
|
||||
for (k,v) in ohai_ds.items():
|
||||
if type(v) == str or type(v) == unicode:
|
||||
k2 = "ohai_%s" % k
|
||||
setup_options[k2] = v
|
||||
cmd = subprocess.Popen("/usr/bin/ohai", shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = cmd.communicate()
|
||||
ohai = True
|
||||
try:
|
||||
ohai_ds = json.loads(out)
|
||||
except:
|
||||
ohai = False
|
||||
if ohai:
|
||||
for (k,v) in ohai_ds.items():
|
||||
if type(v) == str or type(v) == unicode:
|
||||
k2 = "ohai_%s" % k
|
||||
setup_options[k2] = v
|
||||
|
||||
setup_result = {}
|
||||
setup_result['ansible_facts'] = setup_options
|
||||
|
@ -683,4 +685,3 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||
main()
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ def user_mod(module, user, **kwargs):
|
|||
cmd.append('-a')
|
||||
groups_need_mod = True
|
||||
else:
|
||||
groups_need_mod = True
|
||||
groups_need_mod = True
|
||||
|
||||
if groups_need_mod:
|
||||
cmd.append('-G')
|
||||
|
|
|
@ -183,7 +183,7 @@ class Virt(object):
|
|||
"nrVirtCpu" : data[3],
|
||||
"cpuTime" : str(data[4]),
|
||||
}
|
||||
info[vm]["autostart"] = self.conn.get_autostart(vm)
|
||||
info[vm]["autostart"] = self.conn.get_autostart(vm)
|
||||
|
||||
return info
|
||||
|
||||
|
|
10
library/yum
10
library/yum
|
@ -130,9 +130,9 @@ def run(command):
|
|||
out = ''
|
||||
|
||||
if out is None:
|
||||
out = ''
|
||||
out = ''
|
||||
if err is None:
|
||||
err = ''
|
||||
err = ''
|
||||
else:
|
||||
rc = cmd.returncode
|
||||
|
||||
|
@ -144,7 +144,7 @@ def install_no_repoq(module, items, yum_basecmd, latest=False):
|
|||
to_install = []
|
||||
if not latest:
|
||||
for item in items:
|
||||
rc, out, err = run([rpmbin, "-q", "--whatprovides", item])
|
||||
rc, out, err = run([rpmbin, "-q", "--whatprovides", item])
|
||||
if rc != 0:
|
||||
to_install.append(item)
|
||||
if len(to_install) > 0:
|
||||
|
@ -163,7 +163,7 @@ def install_no_repoq(module, items, yum_basecmd, latest=False):
|
|||
if rc != 0:
|
||||
module.fail_json(msg=err)
|
||||
for item in to_install:
|
||||
rc, out, err = run([rpmbin, "-q", "--whatprovides", item])
|
||||
rc, out, err = run([rpmbin, "-q", "--whatprovides", item])
|
||||
if rc != 0:
|
||||
module.fail_json(msg="%s could not be installed" % item)
|
||||
|
||||
|
@ -174,7 +174,7 @@ def remove_no_repoq(module, items, yum_basecmd):
|
|||
|
||||
to_remove = []
|
||||
for item in items:
|
||||
rc, out, err = run([rpmbin, "-q", "--whatprovides", "--qf", "%{NAME}\n", item])
|
||||
rc, out, err = run([rpmbin, "-q", "--whatprovides", "--qf", "%{NAME}\n", item])
|
||||
if rc == 0:
|
||||
to_remove.append(out.strip())
|
||||
if len(to_remove) > 0:
|
||||
|
|
Loading…
Reference in a new issue