File 0030-Bugfix-on-SLE11-series-base-product-reported-as-addi.patch of Package salt.3514

From 79d5477cfa5e85d2480bb07e49ecaeff423f5238 Mon Sep 17 00:00:00 2001
From: Bo Maryniuk <bo@suse.de>
Date: Thu, 10 Mar 2016 13:25:20 +0100
Subject: [PATCH 30/33] Bugfix: on SLE11 series base product reported as
 additional

Add SLE11 product info snapshot, rename previous

Update test case to cover SLE11 and SLE12
---
 salt/modules/zypper.py                             |  2 +-
 .../unit/modules/zypp/zypper-products-sle11sp3.xml | 37 +++++++++++++++
 .../unit/modules/zypp/zypper-products-sle12sp1.xml | 37 +++++++++++++++
 tests/unit/modules/zypp/zypper-products.xml        | 37 ---------------
 tests/unit/modules/zypper_test.py                  | 52 +++++++++++++---------
 5 files changed, 107 insertions(+), 58 deletions(-)
 create mode 100644 tests/unit/modules/zypp/zypper-products-sle11sp3.xml
 create mode 100644 tests/unit/modules/zypp/zypper-products-sle12sp1.xml
 delete mode 100644 tests/unit/modules/zypp/zypper-products.xml

diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
index d6628aa..1c6b31d 100644
--- a/salt/modules/zypper.py
+++ b/salt/modules/zypper.py
@@ -1373,7 +1373,7 @@ def list_products(all=False, refresh=False):
     for prd in doc.getElementsByTagName('product-list')[0].getElementsByTagName('product'):
         p_nfo = dict()
         for k_p_nfo, v_p_nfo in prd.attributes.items():
-            p_nfo[k_p_nfo] = k_p_nfo not in ['isbase', 'installed'] and v_p_nfo or v_p_nfo == 'true'
+            p_nfo[k_p_nfo] = k_p_nfo not in ['isbase', 'installed'] and v_p_nfo or v_p_nfo in ['true', '1']
         p_nfo['eol'] = prd.getElementsByTagName('endoflife')[0].getAttribute('text')
         p_nfo['eol_t'] = int(prd.getElementsByTagName('endoflife')[0].getAttribute('time_t'))
         p_nfo['description'] = " ".join(
diff --git a/tests/unit/modules/zypp/zypper-products-sle11sp3.xml b/tests/unit/modules/zypp/zypper-products-sle11sp3.xml
new file mode 100644
index 0000000..89a85e3
--- /dev/null
+++ b/tests/unit/modules/zypp/zypper-products-sle11sp3.xml
@@ -0,0 +1,37 @@
+<?xml version='1.0'?>
+<stream>
+<message type="info">Refreshing service &apos;nu_novell_com&apos;.</message>
+<message type="info">Loading repository data...</message>
+<message type="info">Reading installed packages...</message>
+<product-list>
+<product name="SUSE_SLES" version="11.3" release="1.138" epoch="0" arch="x86_64" productline="" registerrelease="" vendor="SUSE LINUX Products GmbH, Nuernberg, Germany" summary="SUSE Linux Enterprise Server 11 SP3" shortname="" flavor="" isbase="0" repo="nu_novell_com:SLES11-SP3-Pool" installed="0"><endoflife time_t="0" text="1970-01-01T01:00:00+0100"/>0x7ffdb538e948<description>SUSE Linux Enterprise offers a comprehensive
+        suite of products built on a single code base.
+        The platform addresses business needs from
+        the smallest thin-client devices to the world’s
+        most powerful high-performance computing
+        and mainframe servers. SUSE Linux Enterprise
+        offers common management tools and technology
+        certifications across the platform, and
+        each product is enterprise-class.</description></product>
+<product name="SUSE_SLES-SP4-migration" version="11.3" release="1.4" epoch="0" arch="x86_64" productline="" registerrelease="" vendor="SUSE LINUX Products GmbH, Nuernberg, Germany" summary="SUSE_SLES Service Pack 4 Migration Product" shortname="" flavor="" isbase="0" repo="nu_novell_com:SLES11-SP3-Updates" installed="0"><endoflife time_t="0" text="1970-01-01T01:00:00+0100"/>0x7ffdb538e948<description>SUSE Linux Enterprise offers a comprehensive
+        suite of products built on a single code base.
+        The platform addresses business needs from
+        the smallest thin-client devices to the world’s
+        most powerful high-performance computing
+        and mainframe servers. SUSE Linux Enterprise
+        offers common management tools and technology
+        certifications across the platform, and
+        each product is enterprise-class.</description></product>
+<product name="SUSE_SLES" version="11.3" release="1.201" epoch="0" arch="x86_64" productline="" registerrelease="" vendor="SUSE LINUX Products GmbH, Nuernberg, Germany" summary="SUSE Linux Enterprise Server 11 SP3" shortname="" flavor="" isbase="0" repo="nu_novell_com:SLES11-SP3-Updates" installed="0"><endoflife time_t="0" text="1970-01-01T01:00:00+0100"/>0x7ffdb538e948<description>SUSE Linux Enterprise offers a comprehensive
+        suite of products built on a single code base.
+        The platform addresses business needs from
+        the smallest thin-client devices to the world’s
+        most powerful high-performance computing
+        and mainframe servers. SUSE Linux Enterprise
+        offers common management tools and technology
+        certifications across the platform, and
+        each product is enterprise-class.</description></product>
+<product name="SUSE-Manager-Server" version="2.1" release="1.2" epoch="0" arch="x86_64" productline="" registerrelease="" vendor="SUSE LINUX Products GmbH, Nuernberg, Germany" summary="SUSE Manager Server" shortname="" flavor="cd" isbase="0" repo="nu_novell_com:SUSE-Manager-Server-2.1-Pool" installed="0"><endoflife time_t="0" text="1970-01-01T01:00:00+0100"/>0x7ffdb538e948<description>SUSE Manager Server appliance</description></product>
+<product name="SUSE-Manager-Server" version="2.1" release="1.2" epoch="0" arch="x86_64" productline="manager" registerrelease="" vendor="SUSE LINUX Products GmbH, Nuernberg, Germany" summary="SUSE Manager Server" shortname="" flavor="cd" isbase="1" repo="@System" installed="1"><endoflife time_t="0" text="1970-01-01T01:00:00+0100"/>0x7ffdb538e948<description>SUSE Manager Server appliance</description></product>
+</product-list>
+</stream>
diff --git a/tests/unit/modules/zypp/zypper-products-sle12sp1.xml b/tests/unit/modules/zypp/zypper-products-sle12sp1.xml
new file mode 100644
index 0000000..1a50363
--- /dev/null
+++ b/tests/unit/modules/zypp/zypper-products-sle12sp1.xml
@@ -0,0 +1,37 @@
+<?xml version='1.0'?>
+<stream>
+<message type="info">Loading repository data...</message>
+<message type="info">Reading installed packages...</message>
+<product-list>
+<product name="SLES" version="12.1" release="0" epoch="0" arch="x86_64" vendor="SUSE LLC &lt;https://www.suse.com/&gt;" summary="SUSE Linux Enterprise Server 12 SP1" repo="SLE12-SP1-x86_64-Pool" productline="" registerrelease="" shortname="SLES12-SP1" flavor="POOL" isbase="false" installed="false"><endoflife time_t="1730332800" text="2024-10-31T01:00:00+01"/><registerflavor/><description>SUSE Linux Enterprise offers a comprehensive
+        suite of products built on a single code base.
+        The platform addresses business needs from
+        the smallest thin-client devices to the world&apos;s
+        most powerful high-performance computing
+        and mainframe servers. SUSE Linux Enterprise
+        offers common management tools and technology
+        certifications across the platform, and
+        each product is enterprise-class.</description></product>
+<product name="SUSE-Manager-Proxy" version="3.0" release="0" epoch="0" arch="x86_64" vendor="obs://build.suse.de/Devel:Galaxy:Manager:Head" summary="SUSE Manager Proxy" repo="SUSE-Manager-Head" productline="" registerrelease="" shortname="SUSE Manager Proxy" flavor="DVD" isbase="false" installed="false"><endoflife time_t="1522454400" text="2018-03-31T02:00:00+02"/><registerflavor>extension</registerflavor><description>SUSE Manager Proxies extend large and/or geographically
+dispersed SUSE Manager environments to reduce load on the SUSE Manager
+Server, lower bandwidth needs, and provide faster local
+updates.</description></product>
+<product name="SUSE-Manager-Server" version="3.0" release="0" epoch="0" arch="x86_64" vendor="obs://build.suse.de/Devel:Galaxy:Manager:Head" summary="SUSE Manager Server" repo="SUSE-Manager-Head" productline="" registerrelease="" shortname="SUSE Manager Server" flavor="DVD" isbase="false" installed="false"><endoflife time_t="1522454400" text="2018-03-31T02:00:00+02"/><registerflavor>extension</registerflavor><description>SUSE Manager lets you efficiently manage physical, virtual,
+and cloud-based Linux systems. It provides automated and cost-effective
+configuration and software management, asset management, and system
+provisioning.</description></product>
+<product name="sle-manager-tools-beta" version="12" release="0" epoch="0" arch="x86_64" vendor="obs://build.suse.de/Devel:Galaxy:Manager:Head" summary="SUSE Manager Tools" repo="SUSE-Manager-Head" productline="" registerrelease="" shortname="Manager-Tools" flavor="POOL" isbase="false" installed="false"><endoflife time_t="1509408000" text="2017-10-31T01:00:00+01"/><registerflavor>extension</registerflavor><description>&lt;p&gt;
+      SUSE Manager Tools provide packages required to connect to a
+      SUSE Manager Server.
+	&lt;p&gt;</description></product>
+<product name="SLES" version="12.1" release="0" epoch="0" arch="x86_64" vendor="SUSE" summary="SUSE Linux Enterprise Server 12 SP1" repo="@System" productline="sles" registerrelease="" shortname="SLES12-SP1" flavor="DVD" isbase="true" installed="true"><endoflife time_t="1730332800" text="2024-10-31T01:00:00+01"/><registerflavor/><description>SUSE Linux Enterprise offers a comprehensive
+        suite of products built on a single code base.
+        The platform addresses business needs from
+        the smallest thin-client devices to the world&apos;s
+        most powerful high-performance computing
+        and mainframe servers. SUSE Linux Enterprise
+        offers common management tools and technology
+        certifications across the platform, and
+        each product is enterprise-class.</description></product>
+</product-list>
+</stream>
diff --git a/tests/unit/modules/zypp/zypper-products.xml b/tests/unit/modules/zypp/zypper-products.xml
deleted file mode 100644
index 1a50363..0000000
--- a/tests/unit/modules/zypp/zypper-products.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version='1.0'?>
-<stream>
-<message type="info">Loading repository data...</message>
-<message type="info">Reading installed packages...</message>
-<product-list>
-<product name="SLES" version="12.1" release="0" epoch="0" arch="x86_64" vendor="SUSE LLC &lt;https://www.suse.com/&gt;" summary="SUSE Linux Enterprise Server 12 SP1" repo="SLE12-SP1-x86_64-Pool" productline="" registerrelease="" shortname="SLES12-SP1" flavor="POOL" isbase="false" installed="false"><endoflife time_t="1730332800" text="2024-10-31T01:00:00+01"/><registerflavor/><description>SUSE Linux Enterprise offers a comprehensive
-        suite of products built on a single code base.
-        The platform addresses business needs from
-        the smallest thin-client devices to the world&apos;s
-        most powerful high-performance computing
-        and mainframe servers. SUSE Linux Enterprise
-        offers common management tools and technology
-        certifications across the platform, and
-        each product is enterprise-class.</description></product>
-<product name="SUSE-Manager-Proxy" version="3.0" release="0" epoch="0" arch="x86_64" vendor="obs://build.suse.de/Devel:Galaxy:Manager:Head" summary="SUSE Manager Proxy" repo="SUSE-Manager-Head" productline="" registerrelease="" shortname="SUSE Manager Proxy" flavor="DVD" isbase="false" installed="false"><endoflife time_t="1522454400" text="2018-03-31T02:00:00+02"/><registerflavor>extension</registerflavor><description>SUSE Manager Proxies extend large and/or geographically
-dispersed SUSE Manager environments to reduce load on the SUSE Manager
-Server, lower bandwidth needs, and provide faster local
-updates.</description></product>
-<product name="SUSE-Manager-Server" version="3.0" release="0" epoch="0" arch="x86_64" vendor="obs://build.suse.de/Devel:Galaxy:Manager:Head" summary="SUSE Manager Server" repo="SUSE-Manager-Head" productline="" registerrelease="" shortname="SUSE Manager Server" flavor="DVD" isbase="false" installed="false"><endoflife time_t="1522454400" text="2018-03-31T02:00:00+02"/><registerflavor>extension</registerflavor><description>SUSE Manager lets you efficiently manage physical, virtual,
-and cloud-based Linux systems. It provides automated and cost-effective
-configuration and software management, asset management, and system
-provisioning.</description></product>
-<product name="sle-manager-tools-beta" version="12" release="0" epoch="0" arch="x86_64" vendor="obs://build.suse.de/Devel:Galaxy:Manager:Head" summary="SUSE Manager Tools" repo="SUSE-Manager-Head" productline="" registerrelease="" shortname="Manager-Tools" flavor="POOL" isbase="false" installed="false"><endoflife time_t="1509408000" text="2017-10-31T01:00:00+01"/><registerflavor>extension</registerflavor><description>&lt;p&gt;
-      SUSE Manager Tools provide packages required to connect to a
-      SUSE Manager Server.
-	&lt;p&gt;</description></product>
-<product name="SLES" version="12.1" release="0" epoch="0" arch="x86_64" vendor="SUSE" summary="SUSE Linux Enterprise Server 12 SP1" repo="@System" productline="sles" registerrelease="" shortname="SLES12-SP1" flavor="DVD" isbase="true" installed="true"><endoflife time_t="1730332800" text="2024-10-31T01:00:00+01"/><registerflavor/><description>SUSE Linux Enterprise offers a comprehensive
-        suite of products built on a single code base.
-        The platform addresses business needs from
-        the smallest thin-client devices to the world&apos;s
-        most powerful high-performance computing
-        and mainframe servers. SUSE Linux Enterprise
-        offers common management tools and technology
-        certifications across the platform, and
-        each product is enterprise-class.</description></product>
-</product-list>
-</stream>
diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py
index f89d18f..5c4eb67 100644
--- a/tests/unit/modules/zypper_test.py
+++ b/tests/unit/modules/zypper_test.py
@@ -150,26 +150,38 @@ class ZypperTestCase(TestCase):
         '''
         List products test.
         '''
-        ref_out = {
-                'retcode': 0,
-                'stdout': get_test_data('zypper-products.xml')
-        }
-        with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=ref_out)}):
-            products = zypper.list_products()
-            self.assertEqual(len(products), 5)
-            self.assertEqual(['SLES', 'SLES', 'SUSE-Manager-Proxy', 'SUSE-Manager-Server', 'sle-manager-tools-beta'],
-                    sorted([prod['name'] for prod in products]))
-            self.assertIn('SUSE LLC <https://www.suse.com/>', [product['vendor'] for product in products])
-            self.assertEqual([False, False, False, False, True],
-                    sorted([product['isbase'] for product in products]))
-            self.assertEqual([False, False, False, False, True],
-                    sorted([product['installed'] for product in products]))
-            self.assertEqual(['0', '0', '0', '0', '0'],
-                    sorted([product['release'] for product in products]))
-            self.assertEqual([False, False, False, False, u'sles'],
-                    sorted([product['productline'] for product in products]))
-            self.assertEqual([1509408000, 1522454400, 1522454400, 1730332800, 1730332800],
-                    sorted([product['eol_t'] for product in products]))
+        for filename, test_data in {
+            'zypper-products-sle12sp1.xml': {
+                'name': ['SLES', 'SLES', 'SUSE-Manager-Proxy',
+                         'SUSE-Manager-Server', 'sle-manager-tools-beta'],
+                'vendor': 'SUSE LLC <https://www.suse.com/>',
+                'release': ['0', '0', '0', '0', '0'],
+                'productline': [False, False, False, False, 'sles'],
+                'eol_t': [1509408000, 1522454400, 1522454400, 1730332800, 1730332800],
+                'isbase': [False, False, False, False, True],
+                'installed': [False, False, False, False, True],
+            },
+            'zypper-products-sle11sp3.xml': {
+                'name': ['SUSE-Manager-Server', 'SUSE-Manager-Server',
+                         'SUSE_SLES', 'SUSE_SLES', 'SUSE_SLES-SP4-migration'],
+                'vendor': 'SUSE LINUX Products GmbH, Nuernberg, Germany',
+                'release': ['1.138', '1.2', '1.2', '1.201', '1.4'],
+                'productline': [False, False, False, False, 'manager'],
+                'eol_t': [0, 0, 0, 0, 0],
+                'isbase': [False, False, False, False, True],
+                'installed': [False, False, False, False, True],
+            }}.items():
+            ref_out = {
+                    'retcode': 0,
+                    'stdout': get_test_data(filename)
+            }
+
+            with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=ref_out)}):
+                products = zypper.list_products()
+                self.assertEqual(len(products), 5)
+                self.assertIn(test_data['vendor'], [product['vendor'] for product in products])
+                for kwd in ['name', 'isbase', 'installed', 'release', 'productline', 'eol_t']:
+                    self.assertEqual(test_data[kwd], sorted([prod[kwd] for prod in products]))
 
     def test_refresh_db(self):
         '''
-- 
2.1.4

openSUSE Build Service is sponsored by