def test_add_available_base_channel(self): """ Test adding an available base channel""" channel = "rhel-i386-as-4" options = get_options("add channel {0}".format(channel).split()) self.mgr_sync._fetch_remote_channels = MagicMock( return_value=parse_channels( read_data_from_fixture("list_channels.data"), self.mgr_sync.log)) stubbed_xmlrpm_call = MagicMock() stubbed_xmlrpm_call.side_effect = xmlrpc_sideeffect self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_xmlrpc_calls = [ call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, channel, ''), call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [channel]) ] stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls) expected_output = [ "Added '{0}' channel".format(channel), "Scheduling reposync for following channels:", "- {0}".format(channel) ] self.assertEqual(expected_output, recorder.stdout)
def test_add_available_base_channel_with_mirror(self): """ Test adding an available base channel""" mirror_url = "http://smt.suse.de" channel = "rhel-i386-as-4" options = get_options("add channel {0} --from-mirror {1}".format( channel, mirror_url).split()) self.mgr_sync._fetch_remote_channels = MagicMock( return_value=parse_channels( read_data_from_fixture("list_channels.data"), self.mgr_sync.log)) stubbed_xmlrpm_call = MagicMock() self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_xmlrpc_calls = [ call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, channel, mirror_url), self._mock_iterator(), call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [channel]) ] stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls) expected_output = [ "Adding '{0}' channel".format(channel), "Scheduling reposync for '{0}' channel".format(channel) ]
def test_add_already_installed_channel(self): """Test adding an already added channel. Should only trigger the reposync for the channel""" channel = "sles11-sp3-pool-x86_64" options = get_options("add channel {0}".format(channel).split()) self.mgr_sync._fetch_remote_channels = MagicMock( return_value=parse_channels( read_data_from_fixture("list_channels.data"), self.mgr_sync.log)) stubbed_xmlrpm_call = MagicMock() self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_xmlrpc_calls = [ call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [channel]) ] stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls) expected_output = [ "Channel '{0}' has already been added".format(channel), "Scheduling reposync for following channels:", "- {0}".format(channel) ] self.assertEqual(expected_output, recorder.stdout)
def test_add_available_channel_with_available_base_channel(self): """ Test adding an available channel whose parent is available. Should add both of them.""" base_channel = "rhel-i386-es-4" channel = "res4-es-i386" options = get_options("add channel {0}".format(channel).split()) self.mgr_sync._fetch_remote_channels = MagicMock( return_value=parse_channels( read_data_from_fixture("list_channels.data"), self.mgr_sync.log)) stubbed_xmlrpm_call = MagicMock() stubbed_xmlrpm_call.side_effect = xmlrpc_sideeffect self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call with ConsoleRecorder() as recorder: self.assertEqual(0, self.mgr_sync.run(options)) expected_xmlrpc_calls = [ call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, base_channel, ''), call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [base_channel]), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, channel, ''), call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [channel]) ] stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls) expected_output = """'res4-es-i386' depends on channel 'rhel-i386-es-4' which has not been added yet Going to add 'rhel-i386-es-4' Added 'rhel-i386-es-4' channel Scheduling reposync for following channels: - rhel-i386-es-4 Added 'res4-es-i386' channel Scheduling reposync for following channels: - res4-es-i386""" self.assertEqual(expected_output.split("\n"), recorder.stdout)
def test_add_channels_interactive_no_optional(self): options = get_options("add channel --no-optional".split()) available_channels = ['ch1', 'ch2'] chosen_channel = available_channels[0] self.mgr_sync._list_channels = MagicMock( return_value=available_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_channels.index(chosen_channel) + 1) with ConsoleRecorder() as recorder: self.mgr_sync.run(options) expected_output = [ "Added '{0}' channel".format(chosen_channel), "Scheduling reposync for following channels:", "- {0}".format(chosen_channel) ] self.assertEqual(expected_output, recorder.stdout) self.mgr_sync._list_channels.assert_called_once_with( expand=False, filter=None, no_optionals=True, show_interactive_numbers=True, compact=False) expected_xmlrpc_calls = [ call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "addChannels", self.fake_auth_token, chosen_channel, ''), call._execute_xmlrpc_method(self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, [chosen_channel]) ] stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls)
def test_refresh_from_mirror(self): """ Test the refresh action """ mirror_url = "http://smt.suse.de" options = get_options( "refresh --from-mirror {0}".format(mirror_url).split()) stubbed_xmlrpm_call = MagicMock(return_value=True) self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call stubbed_reposync = MagicMock() self.mgr_sync._schedule_channel_reposync = stubbed_reposync with ConsoleRecorder() as recorder: self.mgr_sync.run(options) expected_output = """Refreshing Channels [DONE] Refreshing Channel families [DONE] Refreshing SUSE products [DONE] Refreshing SUSE Product channels [DONE] Refreshing Subscriptions [DONE]""" self.assertEqual(expected_output.split("\n"), recorder.stdout) expected_calls = [ call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeChannels", self.fake_auth_token, mirror_url), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeChannelFamilies", self.fake_auth_token), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeProducts", self.fake_auth_token), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeProductChannels", self.fake_auth_token), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeSubscriptions", self.fake_auth_token) ] stubbed_xmlrpm_call.assert_has_calls(expected_calls) self.assertFalse(stubbed_reposync.mock_calls)
def test_refresh_enable_reposync(self): """ Test the refresh action """ options = get_options("refresh --refresh-channels".split()) stubbed_xmlrpm_call = MagicMock(return_value=read_data_from_fixture( 'list_channels_simplified.data')) self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call with ConsoleRecorder() as recorder: self.mgr_sync.run(options) expected_output = """Refreshing Channels [DONE] Refreshing Channel families [DONE] Refreshing SUSE products [DONE] Refreshing SUSE Product channels [DONE] Refreshing Subscriptions [DONE] Scheduling refresh of all the available channels Scheduling reposync for following channels: - sles10-sp4-pool-x86_64 - sle10-sdk-sp4-updates-x86_64""" self.assertEqual(expected_output.split("\n"), recorder.stdout) expected_calls = [ call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeChannels", self.fake_auth_token, ''), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeChannelFamilies", self.fake_auth_token), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeProducts", self.fake_auth_token), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeProductChannels", self.fake_auth_token), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "synchronizeSubscriptions", self.fake_auth_token), call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content, "listChannels", self.fake_auth_token), call._execute_xmlrpc_method( self.mgr_sync.conn.channel.software, "syncRepo", self.fake_auth_token, ["sles10-sp4-pool-x86_64", "sle10-sdk-sp4-updates-x86_64"]), ] stubbed_xmlrpm_call.assert_has_calls(expected_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))