def test_all_available_products_are_already_installed(self): """ Test all the available products are already installed""" products = read_data_from_fixture('list_products_simplified.data') res4 = next(p for p in products if p['friendly_name'] == 'RES 4' and p['arch'] == 'x86_64') options = get_options("add product".split()) available_products = parse_products([res4], self.mgr_sync.log) chosen_product = available_products[0] self.mgr_sync._fetch_remote_products = MagicMock( return_value=available_products) stubbed_xmlrpm_call = MagicMock() self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call # set the product as already installed chosen_product.status = Product.Status.INSTALLED with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask') as mock: mock.return_value = str( available_products.index(chosen_product) + 1) with ConsoleRecorder() as recorder: try: self.mgr_sync.run(options) except SystemExit, ex: self.assertEqual(0, ex.code)
def test_add_products_with_an_optional_channel_unavailable(self): """ Test adding a product with an optional channel unavailable. """ products = read_data_from_fixture('list_products_simplified.data') res4 = next(p for p in products if p['friendly_name'] == 'RES 4 x86_64' and p['arch'] == 'x86_64') options = get_options("add product".split()) available_products = parse_products([res4], self.mgr_sync.log) chosen_product = available_products[0] self.mgr_sync._fetch_remote_products = MagicMock( return_value=available_products) stubbed_xmlrpm_call = MagicMock() stubbed_xmlrpm_call.side_effect = xmlrpc_product_sideeffect self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call # set the 1st required channel as optional and unavailable chosen_product.channels[0].optional = True chosen_product.channels[0].status = Channel.Status.UNAVAILABLE with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask') as mock: mock.return_value = str( available_products.index(chosen_product) + 1) with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_output = """Available Products: (R) - recommended extension Status: - [I] - product is installed - [ ] - product is not installed, but is available - [U] - product is unavailable 001) [ ] RES 4 x86_64 Adding channels required by 'RES 4 x86_64' product Added 'rhel-x86_64-as-4' channel Added 'res4-as-x86_64' channel Scheduling reposync for following channels: - rhel-x86_64-as-4 - res4-as-x86_64 Product successfully added""" self.assertEqual(expected_output.split("\n"), recorder.stdout) expected_xmlrpc_calls = [call(self.mgr_sync.conn.sync.content, "listChannels", self.fake_auth_token)] mandatory_channels = [channel for channel in chosen_product.channels if not channel.optional] for channel in mandatory_channels: expected_xmlrpc_calls.append(call(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, channel.label, '')) expected_xmlrpc_calls.append(call(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [channel.label for channel in mandatory_channels])) stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls)
def test_all_available_products_are_already_installed(self): """ Test all the available products are already installed""" products = read_data_from_fixture('list_products_simplified.data') res4 = next(p for p in products if p['friendly_name'] == 'RES 4' and p['arch'] == 'x86_64') options = get_options("add product".split()) available_products = parse_products([res4], self.mgr_sync.log) chosen_product = available_products[0] self.mgr_sync._fetch_remote_products = MagicMock( return_value=available_products) stubbed_xmlrpm_call = MagicMock() self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call # set the product as already installed chosen_product.status = Product.Status.INSTALLED with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask') as mock: mock.return_value = str( available_products.index(chosen_product) + 1) with ConsoleRecorder() as recorder: try: self.mgr_sync.run(options) except SystemExit as ex: self.assertEqual(0, ex.code) expected_output = """Available Products: (R) - recommended extension Status: - [I] - product is installed - [ ] - product is not installed, but is available - [U] - product is unavailable [I] RES 4 (x86_64) All the available products have already been installed, nothing to do""" self.assertEqual(expected_output.split("\n"), recorder.stdout) self.assertFalse(stubbed_xmlrpm_call.mock_calls)
def test_add_products_interactive_with_a_required_channel_unavailable( self): """ Test should not be able to select an unavailable product """ products = read_data_from_fixture('list_products_simplified.data') res4 = next(p for p in products if p['friendly_name'] == 'RES 4' and p['arch'] == 'x86_64') options = get_options("add product".split()) available_products = parse_products([res4], self.mgr_sync.log) chosen_product = available_products[0] self.mgr_sync._fetch_remote_products = MagicMock( return_value=available_products) stubbed_xmlrpm_call = MagicMock() stubbed_xmlrpm_call.side_effect = xmlrpc_sideeffect self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call # set the 1st required channel as already installed chosen_product.status = Product.Status.UNAVAILABLE with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask' ) as mock_cli_ask: with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) self.assertFalse(mock_cli_ask.mock_calls) expected_output = """Available Products: (R) - recommended extension Status: - [I] - product is installed - [ ] - product is not installed, but is available - [U] - product is unavailable [U] RES 4 (x86_64) All the available products have already been installed, nothing to do""" self.assertEqual(expected_output.split("\n"), recorder.stdout) self.assertFalse(stubbed_xmlrpm_call.mock_calls)
def test_add_products_interactive_with_a_channel_already_installed(self): """ Test adding a product with one of the required channels already installed """ products = read_data_from_fixture('list_products_simplified.data') res4 = next(p for p in products if p['friendly_name'] == 'RES 4' and p['arch'] == 'x86_64') options = get_options("add product".split()) available_products = parse_products([res4], self.mgr_sync.log) chosen_product = available_products[0] self.mgr_sync._fetch_remote_products = MagicMock( return_value=available_products) # the installed status is verified against the remote fetched # channels self.mgr_sync._fetch_remote_channels = MagicMock(return_value=dict( (c.label, c) for c in chosen_product.channels)) stubbed_xmlrpm_call = MagicMock() stubbed_xmlrpm_call.side_effect = xmlrpc_product_sideeffect self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call # set the base channel as already installed for channel in chosen_product.channels: if channel.label == 'rhel-x86_64-as-4': channel.status = Channel.Status.INSTALLED channel_to_not_add = channel break with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask') as mock: mock.return_value = str( available_products.index(chosen_product) + 1) with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_output = """Available Products: (R) - recommended extension Status: - [I] - product is installed - [ ] - product is not installed, but is available - [U] - product is unavailable 001) [ ] RES 4 (x86_64) Adding channels required by 'RES 4' product Added 'res4-as-suse-manager-tools-x86_64' channel Channel 'rhel-x86_64-as-4' has already been added Added 'res4-as-x86_64' channel Scheduling reposync for following channels: - res4-as-suse-manager-tools-x86_64 - rhel-x86_64-as-4 - res4-as-x86_64 Product successfully added""" self.assertEqual(expected_output.split("\n"), recorder.stdout) expected_xmlrpc_calls = [] mandatory_channels = [ c for c in chosen_product.channels if not c.optional ] for channel in mandatory_channels: if channel is not channel_to_not_add: expected_xmlrpc_calls.append( call._execute_xmlrpc_method( self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, channel.label, '')) expected_xmlrpc_calls.append( call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [c.label for c in mandatory_channels])) stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls)
def test_channel_interactive_child_with_parent_already_added(self): """Tests that if the parent is added at the beggining, depending child channels do not try or display the adding of the parent""" products = read_data_from_fixture('list_products.data') sled = next( p for p in products if p['friendly_name'] == 'SUSE Linux Enterprise Desktop 11 SP3' and p['arch'] == 'x86_64') options = get_options("add product".split()) available_products = parse_products([sled], self.mgr_sync.log) chosen_product = available_products[0] self.mgr_sync._fetch_remote_products = MagicMock( return_value=available_products) # the installed status is verified against the remote fetched # channels self.mgr_sync._fetch_remote_channels = MagicMock(return_value=dict( (c.label, c) for c in chosen_product.channels)) stubbed_xmlrpm_call = MagicMock() stubbed_xmlrpm_call.side_effect = xmlrpc_sideeffect self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask') as mock: mock.return_value = str( available_products.index(chosen_product) + 1) with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_output = """Available Products: (R) - recommended extension Status: - [I] - product is installed - [ ] - product is not installed, but is available - [U] - product is unavailable 001) [ ] SUSE Linux Enterprise Desktop 11 SP3 (x86_64) Adding channels required by 'SUSE Linux Enterprise Desktop 11 SP3' product Added 'sled11-sp3-pool-x86_64' channel Added 'sles11-sp3-suse-manager-tools-x86_64-sled-sp3' channel Added 'sled11-sp3-updates-x86_64' channel Scheduling reposync for following channels: - sled11-sp3-pool-x86_64 - sles11-sp3-suse-manager-tools-x86_64-sled-sp3 - sled11-sp3-updates-x86_64 Product successfully added""" self.assertEqual(expected_output.split("\n"), recorder.stdout) expected_xmlrpc_calls = [] mandatory_channels = [ c for c in chosen_product.channels if not c.optional ] for channel in mandatory_channels: expected_xmlrpc_calls.append( call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, channel.label, '')) expected_xmlrpc_calls.append( call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [c.label for c in mandatory_channels])) stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls)
def test_add_products_interactive_with_mirror(self): """ Test adding a product with all the required channels available. """ mirror_url = "http://smt.suse.de" products = read_data_from_fixture('list_products_simplified.data') res4 = next(p for p in products if p['friendly_name'] == 'RES 4' and p['arch'] == 'x86_64') options = get_options( "add product --from-mirror {0}".format(mirror_url).split()) available_products = parse_products([res4], self.mgr_sync.log) chosen_product = available_products[0] self.mgr_sync._fetch_remote_products = MagicMock( return_value=available_products) stubbed_xmlrpm_call = MagicMock() stubbed_xmlrpm_call.side_effect = xmlrpc_product_sideeffect self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask') as mock: mock.return_value = str( available_products.index(chosen_product) + 1) with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_output = """Available Products: (R) - recommended extension Status: - [I] - product is installed - [ ] - product is not installed, but is available - [U] - product is unavailable 001) [ ] RES 4 (x86_64) Adding channels required by 'RES 4' product 'res4-as-suse-manager-tools-x86_64' depends on channel 'rhel-x86_64-as-4' which has not been added yet Going to add 'rhel-x86_64-as-4' Added 'rhel-x86_64-as-4' channel Scheduling reposync for following channels: - rhel-x86_64-as-4 Added 'res4-as-suse-manager-tools-x86_64' channel Added 'rhel-x86_64-as-4' channel Added 'res4-as-x86_64' channel Scheduling reposync for following channels: - res4-as-suse-manager-tools-x86_64 - rhel-x86_64-as-4 - res4-as-x86_64 Product successfully added""" self.assertEqual(expected_output.split("\n"), recorder.stdout) expected_xmlrpc_calls = [] mandatory_channels = [ c for c in chosen_product.channels if not c.optional ] for channel in mandatory_channels: expected_xmlrpc_calls.append( call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, channel.label, mirror_url)) expected_xmlrpc_calls.append(self._mock_iterator()) expected_xmlrpc_calls.append( call._execute_xmlrpc_method( self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, channel.label))
def setUp(self): self.mgr_sync = MgrSync() self.mgr_sync.log = self.mgr_sync.__init__logger = MagicMock( return_value=logger.Logger(3, "tmp.log")) self.products = parse_products( read_data_from_fixture("list_products.data"), self.mgr_sync.log)
def _fetch_remote_products(self): """ Returns the list of products as reported by the remote server """ return parse_products( self._execute_xmlrpc_method(self.conn.sync.content, "listProducts", self.auth.token()), self.log)