From 281172994bcd7fcf083df0a6995216cd9252a3cc Mon Sep 17 00:00:00 2001
From: Bo Maryniuk <bo@suse.de>
Date: Fri, 15 Jul 2016 17:11:31 +0200
Subject: [PATCH 60/60] Bugfix: return boolean only for 'isbase' and
 'installed' attributes

* Update test data for 'registerrelease' and 'productline' fields
---
 salt/modules/zypper.py                               | 5 ++++-
 tests/unit/modules/zypp/zypper-products-sle11sp3.xml | 2 +-
 tests/unit/modules/zypp/zypper-products-sle12sp1.xml | 2 +-
 tests/unit/modules/zypper_test.py                    | 8 +++++---
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
index 371d758..c686eed 100644
--- a/salt/modules/zypper.py
+++ b/salt/modules/zypper.py
@@ -1475,7 +1475,10 @@ def list_products(all=False, refresh=False):
     for prd in 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 in ['true', '1']
+            if k_p_nfo in ['isbase', 'installed']:
+                p_nfo[k_p_nfo] = bool(v_p_nfo in ['true', '1'])
+            elif v_p_nfo:
+                p_nfo[k_p_nfo] = v_p_nfo
 
         eol = prd.getElementsByTagName('endoflife')
         if eol:
diff --git a/tests/unit/modules/zypp/zypper-products-sle11sp3.xml b/tests/unit/modules/zypp/zypper-products-sle11sp3.xml
index 99444fe..8db5c68 100644
--- a/tests/unit/modules/zypp/zypper-products-sle11sp3.xml
+++ b/tests/unit/modules/zypp/zypper-products-sle11sp3.xml
@@ -42,6 +42,6 @@
         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 name="SUSE-Manager-Server-Broken-EOL" 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 wrong="attribute"/>0x7ffdb538e948<description>SUSE Manager Server appliance</description></product>
+<product name="SUSE-Manager-Server-Broken-EOL" version="2.1" release="1.2" epoch="0" arch="x86_64" productline="manager" registerrelease="42" vendor="SUSE LINUX Products GmbH, Nuernberg, Germany" summary="SUSE Manager Server" shortname="" flavor="cd" isbase="1" repo="@System" installed="1"><endoflife wrong="attribute"/>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
index a086058..1ac32b9 100644
--- a/tests/unit/modules/zypp/zypper-products-sle12sp1.xml
+++ b/tests/unit/modules/zypp/zypper-products-sle12sp1.xml
@@ -32,7 +32,7 @@ provisioning.</description></product>
       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
+<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="123" 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
diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py
index c4f7597..2f2b323 100644
--- a/tests/unit/modules/zypper_test.py
+++ b/tests/unit/modules/zypper_test.py
@@ -196,20 +196,22 @@ class ZypperTestCase(TestCase):
                          'sle-manager-tools-beta-broken-eol', 'sle-manager-tools-beta-no-eol'],
                 'vendor': 'SUSE LLC <https://www.suse.com/>',
                 'release': ['0', '0', '0', '0', '0', '0', '0'],
-                'productline': [False, False, False, False, False, False, 'sles'],
+                'productline': [None, None, None, None, None, None, 'sles'],
                 'eol_t': [None, 0, 1509408000, 1522454400, 1522454400, 1730332800, 1730332800],
                 'isbase': [False, False, False, False, False, False, True],
                 'installed': [False, False, False, False, False, False, True],
+                'registerrelease': [None, None, None, None, None, None, '123'],
             },
             'zypper-products-sle11sp3.xml': {
                 'name': ['SUSE-Manager-Server', 'SUSE-Manager-Server', 'SUSE-Manager-Server-Broken-EOL',
                          'SUSE_SLES', 'SUSE_SLES', 'SUSE_SLES', 'SUSE_SLES-SP4-migration'],
                 'vendor': 'SUSE LINUX Products GmbH, Nuernberg, Germany',
                 'release': ['1.138', '1.2', '1.2', '1.2', '1.201', '1.201', '1.4'],
-                'productline': [False, False, False, False, False, 'manager', 'manager'],
+                'productline': [None, None, None, None, None, 'manager', 'manager'],
                 'eol_t': [None, 0, 0, 0, 0, 0, 0],
                 'isbase': [False, False, False, False, False, True, True],
                 'installed': [False, False, False, False, False, True, True],
+                'registerrelease': [None, None, None, None, None, None, "42"],
             }}.items():
 
             ref_out = {
@@ -221,7 +223,7 @@ class ZypperTestCase(TestCase):
                 products = zypper.list_products()
                 self.assertEqual(len(products), 7)
                 self.assertIn(test_data['vendor'], [product['vendor'] for product in products])
-                for kwd in ['name', 'isbase', 'installed', 'release', 'productline', 'eol_t']:
+                for kwd in ['name', 'isbase', 'installed', 'release', 'productline', 'eol_t', 'registerrelease']:
                     self.assertEqual(test_data[kwd], sorted([prod.get(kwd) for prod in products]))
 
     def test_refresh_db(self):
-- 
2.9.1

