Merge pull request #34695 from isbm/isbm-zypper-product-boolean-values

Bugfix: Zypper `pkg.list_products` returns False on some empty values (2015.8)
This commit is contained in:
Mike Place 2016-07-15 15:08:00 -06:00 committed by GitHub
commit 4cb1ded520
4 changed files with 11 additions and 6 deletions

View File

@ -1498,7 +1498,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:

View File

@ -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>

View File

@ -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

View File

@ -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):