Repository: RedHatInsights/insights-core

Issue:
Spec `yum -C repolist` should not load plugins
Running the command `yum -C repolist` can cause yum plugins to be loaded.  This command should be run with the `--noplugins` switch to prevent this.


Discussion:

Resolving patch:
diff --git a/insights/parsers/yum.py b/insights/parsers/yum.py
--- a/insights/parsers/yum.py
+++ b/insights/parsers/yum.py
@@ -4,10 +4,10 @@
 Parsers for ``yum`` commands.
 
 This module contains the classes that parse the output of the commands
-`yum -C repolist`.
+`yum -C --noplugins repolist`.
 
-YumRepoList - command ``yum -C repolist``
------------------------------------------
+YumRepoList - command ``yum -C --noplugins repolist``
+-----------------------------------------------------
 """
 
 from insights import parser, CommandParser
@@ -43,11 +43,10 @@
 @parser(Specs.yum_repolist)
 class YumRepoList(CommandParser):
     """
-    Class for parsing the output of `yum -C repolist` command.
+    Class for parsing the output of `yum -C --noplugins repolist` command.
 
     Typical output of the command is::
 
-        Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
         repo id                                             repo name                                                                                                    status
         rhel-7-server-e4s-rpms/x86_64                       Red Hat Enterprise Linux 7 Server - Update Services for SAP Solutions (RPMs)                                 12,250
         !rhel-ha-for-rhel-7-server-e4s-rpms/x86_64          Red Hat Enterprise Linux High Availability (for RHEL 7 Server) Update Services for SAP Solutions (RPMs)         272
@@ -56,7 +55,6 @@ class YumRepoList(CommandParser):
 
     Or sometimes it just outputs repo id and status::
 
-        Loaded plugins: package_upload, product-id, search-disabled-repos, security, subscription-manager
         repo id                                                                               status
         LME_EPEL_6_x86_64                                                                        26123
         LME_FSMLabs_Timekeeper_timekeeper                                                            2
diff --git a/insights/specs/default.py b/insights/specs/default.py
--- a/insights/specs/default.py
+++ b/insights/specs/default.py
@@ -1035,7 +1035,7 @@ def xfs_mounts(broker):
     yum_conf = simple_file("/etc/yum.conf")
     yum_list_installed = simple_command("yum -C --noplugins list installed")
     yum_log = simple_file("/var/log/yum.log")
-    yum_repolist = simple_command("/usr/bin/yum -C repolist")
+    yum_repolist = simple_command("/usr/bin/yum -C --noplugins repolist")
     yum_repos_d = glob_file("/etc/yum.repos.d/*")
     zipl_conf = simple_file("/etc/zipl.conf")
 
diff --git a/insights/specs/insights_archive.py b/insights/specs/insights_archive.py
--- a/insights/specs/insights_archive.py
+++ b/insights/specs/insights_archive.py
@@ -290,4 +290,4 @@ class InsightsArchiveSpecs(Specs):
     virt_what = simple_file("insights_commands/virt-what")
     woopsie = simple_file("insights_commands/find_.var.crash_.var.tmp_-path_.reports-_.whoopsie-report")
     yum_list_installed = simple_file("insights_commands/yum_-C_--noplugins_list_installed")
-    yum_repolist = simple_file("insights_commands/yum_-C_repolist")
+    yum_repolist = first_file(["insights_commands/yum_-C_--noplugins_repolist", "insights_commands/yum_-C_repolist"])


Test patch:
diff --git a/insights/parsers/tests/test_yum_repolist.py b/insights/parsers/tests/test_yum_repolist.py
--- a/insights/parsers/tests/test_yum_repolist.py
+++ b/insights/parsers/tests/test_yum_repolist.py
@@ -16,6 +16,16 @@
 
 """.strip()
 
+YUM_REPOLIST_CONTENT_NOPLUGINS = """
+repo id                                         repo name                status
+rhel-7-server-rpms/7Server/x86_64               Red Hat Enterprise Linux 10415
+rhel-7-server-satellite-6.1-rpms/x86_64         Red Hat Satellite 6.1 (f   660
+rhel-7-server-satellite-capsule-6.1-rpms/x86_64 Red Hat Satellite Capsul   265
+rhel-server-rhscl-7-rpms/7Server/x86_64         Red Hat Software Collect  4571
+repolist: 15911
+
+""".strip()
+
 YUM_REPOLIST_CONTENT_EUS = """
 Loaded plugins: product-id, rhnplugin, security, subscription-manager
 Updating certificate-based repositories.
@@ -120,6 +130,17 @@ def test_yum_repolist():
     assert repo_list.eus == []
 
 
+def test_yum_repolist_noplugins():
+    repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_NOPLUGINS))
+    assert len(repo_list) == 4
+    assert repo_list[0] == {"id": "rhel-7-server-rpms/7Server/x86_64",
+                            "name": "Red Hat Enterprise Linux",
+                            "status": "10415"}
+    assert 'rhel-7-server-rpms/7Server/x86_64' in repo_list
+    assert repo_list['rhel-7-server-rpms/7Server/x86_64'] == repo_list[0]
+    assert repo_list.eus == []
+
+
 def test_eus():
     repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_EUS))
     assert len(repo_list) == 2