From d2ca484d6bd07c3d7b36a9da8b59f4c1c523445d Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Wed, 16 Apr 2014 12:13:50 -0500 Subject: Reporting: Log to debug to prevent spam in logs Signed-off-by: Sol Jerome --- src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index e2e565b1d..2530d2b2b 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -372,8 +372,8 @@ class DjangoORM(StorageBase): self.logger.error("Failed to import interaction: %s" % traceback.format_exc().splitlines()[-1]) finally: - self.logger.info("%s: Closing database connection" % - self.__class__.__name__) + self.logger.debug("%s: Closing database connection" % + self.__class__.__name__) db.close_connection() -- cgit v1.2.3-1-g7c22 From 2454dddb3a5a0afdcfc2f875edfdcc7b5a85d4ba Mon Sep 17 00:00:00 2001 From: John Morris Date: Sun, 20 Apr 2014 17:06:54 -0500 Subject: Enable bcfg2-yum-helper to depsolve for arches incompatible with server By default, the yum dependency resolver uses the host's architecture to filter compatible packages. This prevents dependency resolution when the bcfg2 client's architecture is incompatible with the server's. This workaround checks the element for each of the client's yum sources, and if they are all identical, passes that architecture to bcfg2-yum-helper to override the default. The rpmUtils.arch module may only be configured for a single architecture. If multiple architectures are configured in yum sources, we don't know which one to pick, so use the default behavior instead. --- src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 29 ++++++++++++++++++++++++---- src/sbin/bcfg2-yum-helper | 9 +++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index 67ff05ca1..6139a28b5 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -429,6 +429,25 @@ class YumCollection(Collection): yumconf.write(open(self.cfgfile, 'w')) + def get_arch(self): + """ If 'arch' for each source is the same, return that arch, otherwise + None. + + This helps bcfg2-yum-helper when the client arch is + incompatible with the bcfg2 server's arch. + + In case multiple arches are found, punt back to the default behavior. + """ + arches = set() + for source in self: + for url_map in source.url_map: + if url_map['arch'] in self.metadata.groups: + arches.add(url_map['arch']) + if len(arches) == 1: + return arches.pop() + else: + return None + def get_config(self, raw=False): # pylint: disable=W0221 """ Get the yum configuration for this collection. @@ -886,10 +905,12 @@ class YumCollection(Collection): if packagelist: try: - result = self.call_helper( - "complete", - dict(packages=list(packagelist), - groups=list(self.get_relevant_groups()))) + helper_dict = dict(packages=list(packagelist), + groups=list(self.get_relevant_groups())) + arch = self.get_arch() + if arch is not None: + helper_dict['arch'] = arch + result = self.call_helper("complete", helper_dict) except ValueError: # error reported by call_helper() return set(), packagelist diff --git a/src/sbin/bcfg2-yum-helper b/src/sbin/bcfg2-yum-helper index 227d977de..dc6a6cc0b 100755 --- a/src/sbin/bcfg2-yum-helper +++ b/src/sbin/bcfg2-yum-helper @@ -62,6 +62,10 @@ class YumHelper(object): # pylint: enable=E1121,W0212 self.logger = logging.getLogger(self.__class__.__name__) + def setarch(self, arch): + """ Configure an arch other than the bcfg2 server arch for dep + resolution. """ + self.yumbase.arch.setup_arch(arch=arch) class DepSolver(YumHelper): """ Yum dependency solver. This is used for operations that only @@ -326,6 +330,11 @@ def main(): sys.exc_info()[1]) rv = 2 try: + # if provided, set client arch for dependency resolution + arch = data.get('arch', None) + if arch is not None: + depsolver.setarch(arch) + depsolver.groups = data['groups'] (packages, unknown) = depsolver.complete( [pkg_to_tuple(p) for p in data['packages']]) -- cgit v1.2.3-1-g7c22 From 5888be3f06738f6a93cd6afab930369bdd2eb023 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 25 Apr 2014 07:52:35 -0400 Subject: reduce logging from failed decryption with decrypt=lax --- .../Server/Plugins/Cfg/CfgEncryptedGenerator.py | 21 +++++++++++---------- .../Server/Plugins/Cfg/CfgPrivateKeyCreator.py | 14 ++++++-------- src/lib/Bcfg2/Server/Plugins/Properties.py | 20 ++++++++------------ 3 files changed, 25 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py index cf7eae75b..0a30a070a 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py @@ -1,12 +1,11 @@ """ CfgEncryptedGenerator lets you encrypt your plaintext :ref:`server-plugins-generators-cfg` files on the server. """ -import Bcfg2.Server.Plugins.Cfg from Bcfg2.Server.Plugin import PluginExecutionError -from Bcfg2.Server.Plugins.Cfg import CfgGenerator +from Bcfg2.Server.Plugins.Cfg import CfgGenerator, SETUP try: from Bcfg2.Encryption import bruteforce_decrypt, EVPError, \ - get_algorithm + get_algorithm, CFG_SECTION HAS_CRYPTO = True except ImportError: HAS_CRYPTO = False @@ -27,7 +26,6 @@ class CfgEncryptedGenerator(CfgGenerator): CfgGenerator.__init__(self, fname, spec, encoding) if not HAS_CRYPTO: raise PluginExecutionError("M2Crypto is not available") - __init__.__doc__ = CfgGenerator.__init__.__doc__ def handle_event(self, event): CfgGenerator.handle_event(self, event) @@ -36,15 +34,18 @@ class CfgEncryptedGenerator(CfgGenerator): # todo: let the user specify a passphrase by name try: self.data = bruteforce_decrypt( - self.data, - setup=Bcfg2.Server.Plugins.Cfg.SETUP, - algorithm=get_algorithm(Bcfg2.Server.Plugins.Cfg.SETUP)) + self.data, setup=SETUP, + algorithm=get_algorithm(SETUP)) except EVPError: - raise PluginExecutionError("Failed to decrypt %s" % self.name) - handle_event.__doc__ = CfgGenerator.handle_event.__doc__ + strict = SETUP.cfp.get(CFG_SECTION, "decrypt", + default="strict") + msg = "Cfg: Failed to decrypt %s" % self.name + if strict: + raise PluginExecutionError(msg) + else: + self.logger.debug(msg) def get_data(self, entry, metadata): if self.data is None: raise PluginExecutionError("Failed to decrypt %s" % self.name) return CfgGenerator.get_data(self, entry, metadata) - get_data.__doc__ = CfgGenerator.get_data.__doc__ diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py index e890fdecb..ac031461a 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py @@ -31,7 +31,6 @@ class CfgPrivateKeyCreator(CfgCreator, StructFile): pubkey_path = os.path.dirname(self.name) + ".pub" pubkey_name = os.path.join(pubkey_path, os.path.basename(pubkey_path)) self.pubkey_creator = CfgPublicKeyCreator(pubkey_name) - __init__.__doc__ = CfgCreator.__init__.__doc__ @property def category(self): @@ -55,7 +54,6 @@ class CfgPrivateKeyCreator(CfgCreator, StructFile): def handle_event(self, event): CfgCreator.handle_event(self, event) StructFile.HandleEvent(self, event) - handle_event.__doc__ = CfgCreator.handle_event.__doc__ def _gen_keypair(self, metadata, spec=None): """ Generate a keypair according to the given client medata @@ -201,10 +199,6 @@ class CfgPrivateKeyCreator(CfgCreator, StructFile): def Index(self): StructFile.Index(self) if HAS_CRYPTO: - strict = self.xdata.get( - "decrypt", - SETUP.cfp.get(Bcfg2.Encryption.CFG_SECTION, "decrypt", - default="strict")) == "strict" for el in self.xdata.xpath("//*[@encrypted]"): try: el.text = self._decrypt(el).encode('ascii', @@ -213,13 +207,17 @@ class CfgPrivateKeyCreator(CfgCreator, StructFile): self.logger.info("Cfg: Decrypted %s to gibberish, skipping" % el.tag) except Bcfg2.Encryption.EVPError: + default_strict = SETUP.cfp.get( + Bcfg2.Encryption.CFG_SECTION, "decrypt", + default="strict") + strict = self.xdata.get("decrypt", + default_strict) == "strict" msg = "Cfg: Failed to decrypt %s element in %s" % \ (el.tag, self.name) if strict: raise PluginExecutionError(msg) else: - self.logger.info(msg) - Index.__doc__ = StructFile.Index.__doc__ + self.logger.debug(msg) def _decrypt(self, element): """ Decrypt a single encrypted element """ diff --git a/src/lib/Bcfg2/Server/Plugins/Properties.py b/src/lib/Bcfg2/Server/Plugins/Properties.py index 8c6cf799a..ac0cc884a 100644 --- a/src/lib/Bcfg2/Server/Plugins/Properties.py +++ b/src/lib/Bcfg2/Server/Plugins/Properties.py @@ -172,7 +172,6 @@ class XMLPropertyFile(Bcfg2.Server.Plugin.StructFile, PropertyFile): Bcfg2.Server.Plugin.StructFile.__init__(self, name, fam=fam, should_monitor=should_monitor) PropertyFile.__init__(self, name) - __init__.__doc__ = Bcfg2.Server.Plugin.StructFile.__init__.__doc__ def _write(self): open(self.name, "wb").write( @@ -180,7 +179,6 @@ class XMLPropertyFile(Bcfg2.Server.Plugin.StructFile, PropertyFile): xml_declaration=False, pretty_print=True).decode('UTF-8')) return True - _write.__doc__ = PropertyFile._write.__doc__ def validate_data(self): """ ensure that the data in this object validates against the @@ -203,30 +201,28 @@ class XMLPropertyFile(Bcfg2.Server.Plugin.StructFile, PropertyFile): self.name) else: return True - validate_data.__doc__ = PropertyFile.validate_data.__doc__ def Index(self): Bcfg2.Server.Plugin.StructFile.Index(self) if HAS_CRYPTO: - strict = self.xdata.get( - "decrypt", - SETUP.cfp.get(Bcfg2.Encryption.CFG_SECTION, "decrypt", - default="strict")) == "strict" for el in self.xdata.xpath("//*[@encrypted]"): try: el.text = self._decrypt(el).encode('ascii', 'xmlcharrefreplace') except UnicodeDecodeError: - LOGGER.info("Properties: Decrypted %s to gibberish, " - "skipping" % el.tag) + self.logger.info("Properties: Decrypted %s to gibberish, " + "skipping" % el.tag) except Bcfg2.Encryption.EVPError: + strict = self.xdata.get( + "decrypt", + SETUP.cfp.get(Bcfg2.Encryption.CFG_SECTION, "decrypt", + default="strict")) == "strict" msg = "Properties: Failed to decrypt %s element in %s" % \ - (el.tag, self.name) + (el.tag, self.name) if strict: raise PluginExecutionError(msg) else: - LOGGER.info(msg) - Index.__doc__ = Bcfg2.Server.Plugin.StructFile.Index.__doc__ + self.logger.debug(msg) def _decrypt(self, element): """ Decrypt a single encrypted properties file element """ -- cgit v1.2.3-1-g7c22 From a88ce57202d778d0a4d95ef45d3d9361471c4525 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 25 Apr 2014 07:53:36 -0400 Subject: do not bruteforce Properties decrypts with unknown passphrase this greatly decreases startup time with lots of data encrypted with missing passphrases --- src/lib/Bcfg2/Server/Plugins/Properties.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Server/Plugins/Properties.py b/src/lib/Bcfg2/Server/Plugins/Properties.py index ac0cc884a..6f054fd33 100644 --- a/src/lib/Bcfg2/Server/Plugins/Properties.py +++ b/src/lib/Bcfg2/Server/Plugins/Properties.py @@ -231,19 +231,12 @@ class XMLPropertyFile(Bcfg2.Server.Plugin.StructFile, PropertyFile): passes = Bcfg2.Encryption.get_passphrases(SETUP) try: passphrase = passes[element.get("encrypted")] - try: - return Bcfg2.Encryption.ssl_decrypt( - element.text, passphrase, - algorithm=Bcfg2.Encryption.get_algorithm(SETUP)) - except Bcfg2.Encryption.EVPError: - # error is raised below - pass - except KeyError: - # bruteforce_decrypt raises an EVPError with a sensible - # error message, so we just let it propagate up the stack - return Bcfg2.Encryption.bruteforce_decrypt( - element.text, passphrases=passes.values(), + return Bcfg2.Encryption.ssl_decrypt( + element.text, passphrase, algorithm=Bcfg2.Encryption.get_algorithm(SETUP)) + except KeyError: + raise Bcfg2.Encryption.EVPError("No passphrase named '%s'" % + element.get("encrypted")) raise Bcfg2.Encryption.EVPError("Failed to decrypt") def get_additional_data(self, metadata): -- cgit v1.2.3-1-g7c22 From 14c6cfde0761e910b6c3c1924d51cf915ba96e9d Mon Sep 17 00:00:00 2001 From: Chris Brinker Date: Thu, 24 Apr 2014 14:58:15 -0700 Subject: Default to only (En|De)crypt vars that need it For both Encrypting and Decrypting of Properties files, we should by default only attempt to execute on elements that have an "encrypted" attribute defined. The code will already attempt to encrypt every element if nothing in the current document matches this xpath, which catches the case of a user trying to fully encrypt a completely new properties file. Conflicts: src/lib/Bcfg2/Server/Encryption.py --- src/sbin/bcfg2-crypt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/sbin/bcfg2-crypt b/src/sbin/bcfg2-crypt index 5641732cd..2212c2360 100755 --- a/src/sbin/bcfg2-crypt +++ b/src/sbin/bcfg2-crypt @@ -200,7 +200,7 @@ class CfgDecryptor(Decryptor): class PropertiesCryptoMixin(object): """ Mixin to provide some common methods for Properties crypto """ - default_xpath = '//*' + default_xpath = '//*[@encrypted]' def _get_elements(self, xdata): """ Get the list of elements to encrypt or decrypt """ @@ -288,7 +288,6 @@ class PropertiesEncryptor(Encryptor, PropertiesCryptoMixin): class PropertiesDecryptor(Decryptor, PropertiesCryptoMixin): """ decryptor class for Properties files """ - default_xpath = '//*[@encrypted]' def decrypt(self): decrypted_any = False -- cgit v1.2.3-1-g7c22 From 148239de876a0c8d2fb53fd644ffaabc70540370 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 25 Apr 2014 08:46:59 -0400 Subject: fixed pylint/pep-8 tests --- src/lib/Bcfg2/Client/Client.py | 2 +- src/lib/Bcfg2/Client/Tools/APK.py | 8 ++++---- src/lib/Bcfg2/Client/Tools/FreeBSDPackage.py | 2 +- src/lib/Bcfg2/Client/Tools/IPS.py | 2 +- src/lib/Bcfg2/Client/Tools/MacPorts.py | 10 +++++----- src/lib/Bcfg2/Client/Tools/Pacman.py | 11 +++++------ src/lib/Bcfg2/Client/Tools/Portage.py | 12 ++++++------ src/lib/Bcfg2/Client/Tools/SMF.py | 2 +- src/lib/Bcfg2/Client/Tools/YUM.py | 2 +- src/lib/Bcfg2/Server/Admin/Minestruct.py | 4 ++-- src/lib/Bcfg2/Server/Admin/Pull.py | 8 ++++---- src/lib/Bcfg2/Server/Admin/Viz.py | 20 ++++++++++---------- src/lib/Bcfg2/Server/Core.py | 2 +- src/lib/Bcfg2/settings.py | 4 ++-- src/sbin/bcfg2-info | 3 +-- src/sbin/bcfg2-lint | 4 +--- src/sbin/bcfg2-yum-helper | 1 + 17 files changed, 47 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Client/Client.py b/src/lib/Bcfg2/Client/Client.py index 1676ee717..14fe6768a 100644 --- a/src/lib/Bcfg2/Client/Client.py +++ b/src/lib/Bcfg2/Client/Client.py @@ -294,7 +294,7 @@ class Client(object): self.setup['dryrun']) if not self.setup['omit_lock_check']: - #check lock here + # check lock here try: lockfile = open(self.setup['lockfile'], 'w') if locked(lockfile.fileno()): diff --git a/src/lib/Bcfg2/Client/Tools/APK.py b/src/lib/Bcfg2/Client/Tools/APK.py index 58641ed37..eb70fa676 100644 --- a/src/lib/Bcfg2/Client/Tools/APK.py +++ b/src/lib/Bcfg2/Client/Tools/APK.py @@ -30,7 +30,7 @@ class APK(Bcfg2.Client.Tools.PkgTool): def VerifyPackage(self, entry, _): """Verify Package status for entry.""" - if not 'version' in entry.attrib: + if 'version' not in entry.attrib: self.logger.info("Cannot verify unversioned package %s" % entry.attrib['name']) return False @@ -38,9 +38,9 @@ class APK(Bcfg2.Client.Tools.PkgTool): if entry.attrib['name'] in self.installed: if entry.attrib['version'] in \ ['auto', self.installed[entry.attrib['name']]]: - #if not self.setup['quick'] and \ - # entry.get('verify', 'true') == 'true': - #FIXME: Does APK have any sort of verification mechanism? + # if (not self.setup['quick'] and + # entry.get('verify', 'true') == 'true'): + # FIXME: Does APK have any sort of verification mechanism? return True else: self.logger.info(" pkg %s at version %s, not %s" % diff --git a/src/lib/Bcfg2/Client/Tools/FreeBSDPackage.py b/src/lib/Bcfg2/Client/Tools/FreeBSDPackage.py index 31925fa3c..22cf802cf 100644 --- a/src/lib/Bcfg2/Client/Tools/FreeBSDPackage.py +++ b/src/lib/Bcfg2/Client/Tools/FreeBSDPackage.py @@ -29,7 +29,7 @@ class FreeBSDPackage(Bcfg2.Client.Tools.PkgTool): self.installed[name] = version def VerifyPackage(self, entry, _): - if not 'version' in entry.attrib: + if 'version' not in entry.attrib: self.logger.info("Cannot verify unversioned package %s" % entry.attrib['name']) return False diff --git a/src/lib/Bcfg2/Client/Tools/IPS.py b/src/lib/Bcfg2/Client/Tools/IPS.py index aff276c3a..5be8527bf 100644 --- a/src/lib/Bcfg2/Client/Tools/IPS.py +++ b/src/lib/Bcfg2/Client/Tools/IPS.py @@ -38,7 +38,7 @@ class IPS(Bcfg2.Client.Tools.PkgTool): def VerifyPackage(self, entry, _): """Verify package for entry.""" pname = entry.get('name') - if not 'version' in entry.attrib: + if 'version' not in entry.attrib: self.logger.info("Cannot verify unversioned package %s" % (pname)) return False if pname not in self.installed: diff --git a/src/lib/Bcfg2/Client/Tools/MacPorts.py b/src/lib/Bcfg2/Client/Tools/MacPorts.py index bd9d24df3..40d90eec9 100644 --- a/src/lib/Bcfg2/Client/Tools/MacPorts.py +++ b/src/lib/Bcfg2/Client/Tools/MacPorts.py @@ -36,7 +36,7 @@ class MacPorts(Bcfg2.Client.Tools.PkgTool): def VerifyPackage(self, entry, _): """Verify Package status for entry.""" - if not 'version' in entry.attrib: + if 'version' not in entry.attrib: self.logger.info("Cannot verify unversioned package %s" % entry.attrib['name']) return False @@ -44,10 +44,10 @@ class MacPorts(Bcfg2.Client.Tools.PkgTool): if entry.attrib['name'] in self.installed: if (self.installed[entry.attrib['name']] == entry.attrib['version'] or entry.attrib['version'] == 'any'): - #if not self.setup['quick'] and \ - # entry.get('verify', 'true') == 'true': - #FIXME: We should be able to check this once - # http://trac.macports.org/ticket/15709 is implemented + # if (not self.setup['quick'] and + # entry.get('verify', 'true') == 'true'): + # FIXME: We should be able to check this once + # http://trac.macports.org/ticket/15709 is implemented return True else: self.logger.info(" %s: Wrong version installed. " diff --git a/src/lib/Bcfg2/Client/Tools/Pacman.py b/src/lib/Bcfg2/Client/Tools/Pacman.py index a4cfd3315..b931fe028 100644 --- a/src/lib/Bcfg2/Client/Tools/Pacman.py +++ b/src/lib/Bcfg2/Client/Tools/Pacman.py @@ -24,7 +24,6 @@ class Pacman(Bcfg2.Client.Tools.PkgTool): for pkg in self.cmd.run("/usr/bin/pacman -Q").stdout.splitlines(): pkgname = pkg.split(' ')[0].strip() version = pkg.split(' ')[1].strip() - #self.logger.info(" pkgname: %s, version: %s" % (pkgname, version)) self.installed[pkgname] = version def VerifyPackage(self, entry, _): @@ -33,7 +32,7 @@ class Pacman(Bcfg2.Client.Tools.PkgTool): self.logger.info("VerifyPackage: %s : %s" % (entry.get('name'), entry.get('version'))) - if not 'version' in entry.attrib: + if 'version' not in entry.attrib: self.logger.info("Cannot verify unversioned package %s" % entry.attrib['name']) return False @@ -43,10 +42,10 @@ class Pacman(Bcfg2.Client.Tools.PkgTool): return True elif self.installed[entry.attrib['name']] == \ entry.attrib['version']: - #if not self.setup['quick'] and \ - # entry.get('verify', 'true') == 'true': - #FIXME: need to figure out if pacman - # allows you to verify packages + # if (not self.setup['quick'] and + # entry.get('verify', 'true') == 'true'): + # FIXME: need to figure out if pacman + # allows you to verify packages return True else: entry.set('current_version', self.installed[entry.get('name')]) diff --git a/src/lib/Bcfg2/Client/Tools/Portage.py b/src/lib/Bcfg2/Client/Tools/Portage.py index 2d8b66ce5..78ccb2d37 100644 --- a/src/lib/Bcfg2/Client/Tools/Portage.py +++ b/src/lib/Bcfg2/Client/Tools/Portage.py @@ -48,7 +48,7 @@ class Portage(Bcfg2.Client.Tools.PkgTool): def VerifyPackage(self, entry, modlist): """Verify package for entry.""" - if not 'version' in entry.attrib: + if 'version' not in entry.attrib: self.logger.info("Cannot verify unversioned package %s" % (entry.get('name'))) return False @@ -66,11 +66,11 @@ class Portage(Bcfg2.Client.Tools.PkgTool): if ('verify' not in entry.attrib or entry.get('verify').lower() == 'true'): - # Check the package if: - # - Not running in quick mode - # - No verify option is specified in the literal configuration - # OR - # - Verify option is specified and is true + # Check the package if: + # - Not running in quick mode + # - No verify option is specified in the literal configuration + # OR + # - Verify option is specified and is true self.logger.debug('Running equery check on %s' % entry.get('name')) diff --git a/src/lib/Bcfg2/Client/Tools/SMF.py b/src/lib/Bcfg2/Client/Tools/SMF.py index 8b23a4a37..1a580d8a5 100644 --- a/src/lib/Bcfg2/Client/Tools/SMF.py +++ b/src/lib/Bcfg2/Client/Tools/SMF.py @@ -25,7 +25,7 @@ class SMF(Bcfg2.Client.Tools.SvcTool): def GetFMRI(self, entry): """Perform FMRI resolution for service.""" - if not 'FMRI' in entry.attrib: + if 'FMRI' not in entry.attrib: rv = self.cmd.run(["/usr/bin/svcs", "-H", "-o", "FMRI", entry.get('name')]) if rv.success: diff --git a/src/lib/Bcfg2/Client/Tools/YUM.py b/src/lib/Bcfg2/Client/Tools/YUM.py index b4ca32847..15ae5ef8b 100644 --- a/src/lib/Bcfg2/Client/Tools/YUM.py +++ b/src/lib/Bcfg2/Client/Tools/YUM.py @@ -870,7 +870,7 @@ class YUM(Bcfg2.Client.Tools.PkgTool): cleanup() - def Install(self, packages, states): # pylint: disable=R0912,R0914 + def Install(self, packages, states): # pylint: disable=R0912,R0914,R0915 """ Try and fix everything that Yum.VerifyPackages() found wrong for each Package Entry. This can result in individual RPMs being installed (for the first time), deleted, downgraded diff --git a/src/lib/Bcfg2/Server/Admin/Minestruct.py b/src/lib/Bcfg2/Server/Admin/Minestruct.py index 37ca74894..65f99a213 100644 --- a/src/lib/Bcfg2/Server/Admin/Minestruct.py +++ b/src/lib/Bcfg2/Server/Admin/Minestruct.py @@ -11,8 +11,8 @@ class Minestruct(Bcfg2.Server.Admin.StructureMode): __usage__ = ("[options] \n\n" " %-25s%s\n" " %-25s%s\n" % - ("-f ", "build a particular file", - "-g ", "only build config for groups")) + ("-f ", "build a particular file", + "-g ", "only build config for groups")) def __call__(self, args): if len(args) == 0: diff --git a/src/lib/Bcfg2/Server/Admin/Pull.py b/src/lib/Bcfg2/Server/Admin/Pull.py index 459fcec65..fccdb2d94 100644 --- a/src/lib/Bcfg2/Server/Admin/Pull.py +++ b/src/lib/Bcfg2/Server/Admin/Pull.py @@ -18,10 +18,10 @@ class Pull(Bcfg2.Server.Admin.MetadataCore): " %-25s%s\n" " %-25s%s\n" " %-25s%s\n" % - ("-v", "be verbose", - "-f", "force", - "-I", "interactive", - "-s", "stdin")) + ("-v", "be verbose", + "-f", "force", + "-I", "interactive", + "-s", "stdin")) def __init__(self, setup): Bcfg2.Server.Admin.MetadataCore.__init__(self, setup) diff --git a/src/lib/Bcfg2/Server/Admin/Viz.py b/src/lib/Bcfg2/Server/Admin/Viz.py index 2cbd7eaf6..cb2470e17 100644 --- a/src/lib/Bcfg2/Server/Admin/Viz.py +++ b/src/lib/Bcfg2/Server/Admin/Viz.py @@ -14,16 +14,16 @@ class Viz(Bcfg2.Server.Admin.MetadataCore): " %-32s%s\n" " %-32s%s\n" " %-32s%s\n" % - ("-H, --includehosts", - "include hosts in the viz output", - "-b, --includebundles", - "include bundles in the viz output", - "-k, --includekey", - "show a key for different digraph shapes", - "-c, --only-client ", - "show only the groups, bundles for the named client", - "-o, --outfile ", - "write viz output to an output file")) + ("-H, --includehosts", + "include hosts in the viz output", + "-b, --includebundles", + "include bundles in the viz output", + "-k, --includekey", + "show a key for different digraph shapes", + "-c, --only-client ", + "show only the groups, bundles for the named client", + "-o, --outfile ", + "write viz output to an output file")) colors = ['steelblue1', 'chartreuse', 'gold', 'magenta', 'indianred1', 'limegreen', 'orange1', 'lightblue2', diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 4375512e9..44ba0fee8 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -387,7 +387,7 @@ class BaseCore(object): self.setup['plugins'].remove('') for plugin in self.setup['plugins']: - if not plugin in self.plugins: + if plugin not in self.plugins: self.init_plugin(plugin) # Remove blacklisted plugins diff --git a/src/lib/Bcfg2/settings.py b/src/lib/Bcfg2/settings.py index aa784336d..834b04d36 100644 --- a/src/lib/Bcfg2/settings.py +++ b/src/lib/Bcfg2/settings.py @@ -159,7 +159,7 @@ MEDIA_ROOT = '' # trailing slash. STATIC_URL = '/media/' -#TODO - make this unique +# TODO - make this unique # Make this unique, and don't share it with anybody. SECRET_KEY = 'eb5+y%oy-qx*2+62vv=gtnnxg1yig_odu0se5$h0hh#pc*lmo7' @@ -183,7 +183,7 @@ else: 'django.template.loaders.app_directories.Loader', ) -#TODO - review these. auth and sessions aren't really used +# TODO - review these. auth and sessions aren't really used MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index 6008f8896..a6c3149bc 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -438,8 +438,7 @@ Bcfg2 client itself.""") automatch = self.setup.cfp.getboolean("properties", "automatch", default=False) pfile = self.plugins['Properties'].entries[pname] - if (not force and - not automatch and + if (not force and not automatch and pfile.xdata.get("automatch", "false").lower() != "true"): print("Automatch not enabled on %s" % pname) else: diff --git a/src/sbin/bcfg2-lint b/src/sbin/bcfg2-lint index 9ceb1dd04..bb96c2023 100755 --- a/src/sbin/bcfg2-lint +++ b/src/sbin/bcfg2-lint @@ -4,7 +4,6 @@ import sys import time -import inspect import logging import Bcfg2.Logger import Bcfg2.Options @@ -136,8 +135,7 @@ def load_plugins(setup): serverplugins = dict() serverlessplugins = dict() for plugin_name, plugin in allplugins.items(): - if [c for c in inspect.getmro(plugin) - if c == Bcfg2.Server.Lint.ServerPlugin]: + if issubclass(plugin, Bcfg2.Server.Lint.ServerPlugin): serverplugins[plugin_name] = plugin else: serverlessplugins[plugin_name] = plugin diff --git a/src/sbin/bcfg2-yum-helper b/src/sbin/bcfg2-yum-helper index dc6a6cc0b..f2bdf2c97 100755 --- a/src/sbin/bcfg2-yum-helper +++ b/src/sbin/bcfg2-yum-helper @@ -67,6 +67,7 @@ class YumHelper(object): resolution. """ self.yumbase.arch.setup_arch(arch=arch) + class DepSolver(YumHelper): """ Yum dependency solver. This is used for operations that only read from the yum cache, and thus operates in cacheonly mode. """ -- cgit v1.2.3-1-g7c22