From aae1c09957eab3c89a6c8f78a579cdf9dcfbe188 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Tue, 12 Apr 2016 13:52:35 +0200 Subject: [PATCH 11/12] Check if EOL is available in a particular product (bsc#975093) Update SLE11 SP3 data Update SLE12 SP1 data Adjust test values according to the testing data --- salt/modules/zypper.py | 13 +++++++-- .../unit/modules/zypp/zypper-products-sle11sp3.xml | 10 +++++++ .../unit/modules/zypp/zypper-products-sle12sp1.xml | 8 ++++++ tests/unit/modules/zypper_test.py | 32 ++++++++++++---------- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py index 9702f42..4ce5853 100644 --- a/salt/modules/zypper.py +++ b/salt/modules/zypper.py @@ -1318,12 +1318,19 @@ def list_products(all=False, refresh=False): call = __salt__['cmd.run_all'](cmd, output_loglevel='trace') doc = dom.parseString(_zypper_check_result(call, xml=True)) - for prd in doc.getElementsByTagName('product-list')[0].getElementsByTagName('product'): + product_list = doc.getElementsByTagName('product-list') + if not product_list: + return ret # No products found + + 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'] - p_nfo['eol'] = prd.getElementsByTagName('endoflife')[0].getAttribute('text') - p_nfo['eol_t'] = int(prd.getElementsByTagName('endoflife')[0].getAttribute('time_t')) + + eol = prd.getElementsByTagName('endoflife') + if eol: + p_nfo['eol'] = eol[0].getAttribute('text') + p_nfo['eol_t'] = int(eol[0].getAttribute('time_t') or 0) p_nfo['description'] = " ".join( [line.strip() for line in _get_first_aggregate_text( prd.getElementsByTagName('description') diff --git a/tests/unit/modules/zypp/zypper-products-sle11sp3.xml b/tests/unit/modules/zypp/zypper-products-sle11sp3.xml index 89a85e3..99444fe 100644 --- a/tests/unit/modules/zypp/zypper-products-sle11sp3.xml +++ b/tests/unit/modules/zypp/zypper-products-sle11sp3.xml @@ -31,7 +31,17 @@ offers common management tools and technology certifications across the platform, and each product is enterprise-class. +0x7ffdb538e948SUSE 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. 0x7ffdb538e948SUSE Manager Server appliance 0x7ffdb538e948SUSE Manager Server appliance +0x7ffdb538e948SUSE Manager Server appliance diff --git a/tests/unit/modules/zypp/zypper-products-sle12sp1.xml b/tests/unit/modules/zypp/zypper-products-sle12sp1.xml index 1a50363..a086058 100644 --- a/tests/unit/modules/zypp/zypper-products-sle12sp1.xml +++ b/tests/unit/modules/zypp/zypper-products-sle12sp1.xml @@ -24,6 +24,14 @@ provisioning. SUSE Manager Tools provide packages required to connect to a SUSE Manager Server. <p> +extension<p> + SUSE Manager Tools provide packages required to connect to a + SUSE Manager Server. + <p> +extension<p> + SUSE Manager Tools provide packages required to connect to a + SUSE Manager Server. + <p> SUSE Linux Enterprise offers a comprehensive suite of products built on a single code base. The platform addresses business needs from diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py index 67cf52a..97e42ef 100644 --- a/tests/unit/modules/zypper_test.py +++ b/tests/unit/modules/zypper_test.py @@ -153,24 +153,26 @@ class ZypperTestCase(TestCase): for filename, test_data in { 'zypper-products-sle12sp1.xml': { 'name': ['SLES', 'SLES', 'SUSE-Manager-Proxy', - 'SUSE-Manager-Server', 'sle-manager-tools-beta'], + 'SUSE-Manager-Server', 'sle-manager-tools-beta', + 'sle-manager-tools-beta-broken-eol', 'sle-manager-tools-beta-no-eol'], 'vendor': 'SUSE LLC ', - '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], + 'release': ['0', '0', '0', '0', '0', '0', '0'], + 'productline': [False, False, False, False, False, False, '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], }, 'zypper-products-sle11sp3.xml': { - 'name': ['SUSE-Manager-Server', 'SUSE-Manager-Server', - 'SUSE_SLES', 'SUSE_SLES', 'SUSE_SLES-SP4-migration'], + '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.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], + 'release': ['1.138', '1.2', '1.2', '1.2', '1.201', '1.201', '1.4'], + 'productline': [False, False, False, False, False, '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], }}.items(): + ref_out = { 'retcode': 0, 'stdout': get_test_data(filename) @@ -178,10 +180,10 @@ class ZypperTestCase(TestCase): with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=ref_out)}): products = zypper.list_products() - self.assertEqual(len(products), 5) + 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']: - self.assertEqual(test_data[kwd], sorted([prod[kwd] for prod in products])) + self.assertEqual(test_data[kwd], sorted([prod.get(kwd) for prod in products])) def test_refresh_db(self): ''' -- 2.1.4