[PATCH] Add a test for accesses of yum.preconf outside of _resetYum.

Chris Lumens clumens at redhat.com
Fri Nov 22 19:22:03 UTC 2013


Note that there are two places where this is still okay:  throughout
scripts/anaconda-yum which is a separate process, and once where we set
up the config file path.
---
 pyanaconda/packaging/yumpayload.py |  3 +++
 scripts/anaconda-yum               |  1 +
 tests/Makefile.am                  |  1 +
 tests/pylint/preconf.py            | 44 ++++++++++++++++++++++++++++++++++++++
 tests/pylint/pylint-one.sh         |  2 +-
 5 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 tests/pylint/preconf.py

diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py
index 454a993..32d9d95 100644
--- a/pyanaconda/packaging/yumpayload.py
+++ b/pyanaconda/packaging/yumpayload.py
@@ -212,6 +212,8 @@ class YumPayload(PackagePayload):
         """ Delete and recreate the payload's YumBase instance.
 
             Setup _yum.preconf -- DO NOT TOUCH IT OUTSIDE THIS METHOD
+            NOTE:  This is enforced by tests/pylint/preconf.py.  If the name
+            of this method changes, change it there too.
         """
         if root is None:
             root = self._root_dir
@@ -1498,6 +1500,7 @@ reposdir=%s
         #        all yumvars and writing out the expanded pairs to the conf
         yb = yum.YumBase()
         yum_conf_path = "/etc/yum.conf"
+        # pylint: disable-msg=W9910
         yb.preconf.fn = ROOT_PATH + yum_conf_path
         yb.conf.multilib_policy = "all"
 
diff --git a/scripts/anaconda-yum b/scripts/anaconda-yum
index 09d5429..cf98f70 100755
--- a/scripts/anaconda-yum
+++ b/scripts/anaconda-yum
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# pylint: disable-msg=W9910
 #
 # Copyright (C) 2013  Red Hat, Inc.
 #
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 693f0f3..848a95a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,7 @@ dist_check_SCRIPTS = accelerators/check_accelerators.py \
 		     accelerators/run_check_accelerators.sh \
 		     nosetests.sh \
 		     pylint/intl.py \
+		     pylint/preconf.py \
 		     pylint/runpylint.sh \
 		     pylint/pylint-one.sh \
 		     testenv.sh \
diff --git a/tests/pylint/preconf.py b/tests/pylint/preconf.py
new file mode 100644
index 0000000..a15413f
--- /dev/null
+++ b/tests/pylint/preconf.py
@@ -0,0 +1,44 @@
+# yum preconf pylint module
+#
+# Copyright (C) 2013  Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+# Public License for more details.  You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Chris Lumens <clumens at redhat.com>
+#
+
+import astroid
+
+from pylint.checkers import BaseChecker
+from pylint.checkers.utils import check_messages
+from pylint.interfaces import IAstroidChecker
+
+class PreconfChecker(BaseChecker):
+    __implements__ = (IAstroidChecker, )
+    name = "Yum preconf"
+    msgs = {"W9910": ("Accessing yum.preconf outside of _resetYum",
+                      "bad-preconf-access",
+                      "Accessing yum.preconf outside of _resetYum will cause tracebacks"),
+           }
+
+    @check_messages("W9910")
+    def visit_getattr(self, node):
+        if node.attrname == "preconf":
+            if not isinstance(node.scope(), astroid.Function) or not node.scope().name == "_resetYum":
+                self.add_message("W9910", node=node)
+
+def register(linter):
+    """required method to auto register this checker """
+    linter.register_checker(PreconfChecker(linter))
diff --git a/tests/pylint/pylint-one.sh b/tests/pylint/pylint-one.sh
index 58cc2b5..a27bd3d 100755
--- a/tests/pylint/pylint-one.sh
+++ b/tests/pylint/pylint-one.sh
@@ -16,7 +16,7 @@ pylint_output="$(pylint \
     --dummy-variables-rgx=_ \
     --ignored-classes=DefaultInstall,Popen,QueueFactory,TransactionSet \
     --defining-attr-methods=__init__,_grabObjects,initialize,reset,start,setUp \
-    --load-plugins=intl \
+    --load-plugins=intl,preconf \
     $DISABLED_WARN_OPTIONS \
     $DISABLED_ERR_OPTIONS \
     $NON_STRICT_OPTIONS $1 2>&1 | \
-- 
1.8.3.1



More information about the anaconda-patches mailing list