From 79d5477cfa5e85d2480bb07e49ecaeff423f5238 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk 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 @@ + + +Refreshing service 'nu_novell_com'. +Loading repository data... +Reading installed packages... + +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 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 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 + + 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 @@ + + +Loading repository data... +Reading installed packages... + +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. +extensionSUSE 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. +extensionSUSE 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. +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 + 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. + + 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 @@ - - -Loading repository data... -Reading installed packages... - -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. -extensionSUSE 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. -extensionSUSE 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. -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 - 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. - - 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 ', [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 ', + '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