コード例 #1
0
    def test_list_channels_filter_show_parent_when_child_matches(self):
        """ Testing list channel output when a filter is set.  Should show the
        parent even if it does not match the filter as long as one of his
        children match the filter.
        """

        options = get_options("list channel --filter update".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 = """Available Channels:


Status:
  - [I] - channel is installed
  - [ ] - channel is not installed, but is available
  - [U] - channel is unavailable

[I] SLES10-SP4-Pool for x86_64 SUSE Linux Enterprise Server 10 SP4 x86_64 [sles10-sp4-pool-x86_64]
    [I] SLE10-SDK-SP4-Updates for x86_64 SUSE Linux Enterprise Software Development Kit 10 SP4 Software Development Kit [sle10-sdk-sp4-updates-x86_64]"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listChannels",
            self.fake_auth_token)
コード例 #2
0
    def test_add_available_child_channel_with_unavailable_parent(self):
        """Test adding an available child channel which has an unavailable parent.

        Should refuse to perform the operation, print to stderr and exit with
        an error code.
        This should never occur.
        """

        channels = parse_channels(read_data_from_fixture("list_channels.data"),
                                  self.mgr_sync.log)
        parent = channels['rhel-i386-es-4']
        parent.status = Channel.Status.UNAVAILABLE
        child = 'res4-es-i386'

        options = get_options("add channel {0}".format(child).split())
        self.mgr_sync._fetch_remote_channels = MagicMock(return_value=channels)

        with ConsoleRecorder() as recorder:
            self.assertEqual(1, self.mgr_sync.run(options))

        expected_output = """Error, 'res4-es-i386' depends on channel 'rhel-i386-es-4' which is not available
'res4-es-i386' has not been added"""

        self.assertFalse(recorder.stdout)
        self.assertEqual(expected_output.split("\n"), recorder.stderr)
コード例 #3
0
    def test_list_channels_compact_mode_enabled(self):
        """ Testing list channel output """
        options = get_options("list channel -c".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 = """Available Channels:


Status:
  - [I] - channel is installed
  - [ ] - channel is not installed, but is available
  - [U] - channel is unavailable

[ ] rhel-i386-as-4
[ ] rhel-x86_64-as-4
[I] sles10-sp4-pool-x86_64
    [ ] sle10-sdk-sp4-pool-x86_64
    [I] sle10-sdk-sp4-updates-x86_64"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listChannels",
            self.fake_auth_token)
コード例 #4
0
    def test_add_channels_interactive_no_sync(self):
        options = get_options("add channel --no-sync".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)]
            self.assertEqual(expected_output, recorder.stdout)

            self.mgr_sync._list_channels.assert_called_once_with(
                expand=False,
                filter=None,
                no_optionals=False,
                show_interactive_numbers=True,
                compact=False,
                only_installed=False)

            expected_xmlrpc_calls = [
                call._execute_xmlrpc_method(self.mgr_sync.conn.sync.content,
                                            "addChannels",
                                            self.fake_auth_token,
                                            chosen_channel, '')
            ]

            stubbed_xmlrpm_call.assert_has_calls(expected_xmlrpc_calls)
コード例 #5
0
    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)
コード例 #6
0
    def test_list_products_with_filtering(self):
        """ Test listing products with filtering"""

        options = get_options("list product --filter proxy".split())
        stubbed_xmlrpm_call = MagicMock(
            return_value=read_data_from_fixture('list_products.data'))
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        with ConsoleRecorder() as recorder:
            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

[ ] SUSE Manager Proxy 1.2 (x86_64)
[ ] SUSE Manager Proxy 1.7 (x86_64)
[ ] SUSE Manager Proxy 2.1 (x86_64)"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listProducts",
            self.fake_auth_token)
コード例 #7
0
    def test_list_channels(self):
        """ Testing list channel output """
        options = get_options("list channel".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 = """Available Channels:


Status:
  - [I] - channel is installed
  - [ ] - channel is not installed, but is available
  - [U] - channel is unavailable

[ ] RHEL i386 AS 4 RES 4 [rhel-i386-as-4]
[ ] RHEL x86_64 AS 4 RES 4 [rhel-x86_64-as-4]
[I] SLES10-SP4-Pool for x86_64 SUSE Linux Enterprise Server 10 SP4 x86_64 [sles10-sp4-pool-x86_64]
    [ ] SLE10-SDK-SP4-Pool for x86_64 SUSE Linux Enterprise Software Development Kit 10 SP4 Software Development Kit [sle10-sdk-sp4-pool-x86_64]
    [I] SLE10-SDK-SP4-Updates for x86_64 SUSE Linux Enterprise Software Development Kit 10 SP4 Software Development Kit [sle10-sdk-sp4-updates-x86_64]"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listChannels",
            self.fake_auth_token)
コード例 #8
0
    def test_list_products_with_filtering_matches_also_children(self):
        """ Test listing products with filtering should match children even when
        their parent does not.
        """

        options = get_options("list product --filter cloud".split())
        stubbed_xmlrpm_call = MagicMock(
            return_value=read_data_from_fixture('list_products.data'))
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        with ConsoleRecorder() as recorder:
            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

[ ] SUSE Linux Enterprise Server 11 SP2 (x86_64)
  [ ] SUSE Cloud 1.0 (x86_64)
[I] SUSE Linux Enterprise Server 11 SP3 (x86_64)
  [ ] SUSE Cloud 2.0 (x86_64)
  [ ] SUSE Cloud 3 (x86_64)"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listProducts",
            self.fake_auth_token)
コード例 #9
0
    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)
コード例 #10
0
    def test_refresh(self):
        """ Test the refresh action """

        options = get_options("refresh".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 Channel families                    [DONE]
Refreshing SUSE products                       [DONE]
Refreshing SUSE repositories                   [DONE]
Refreshing Subscriptions                       [DONE]"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        expected_calls = [
            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,
                                        "synchronizeRepositories",
                                        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)
コード例 #11
0
    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)
        ]
コード例 #12
0
    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)
コード例 #13
0
    def test_list_products(self):
        """ Test listing products """

        options = get_options("list product".split())
        stubbed_xmlrpm_call = MagicMock(return_value=read_data_from_fixture(
            'list_products_simplified.data'))
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        with ConsoleRecorder() as recorder:
            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

[ ] RES 4 x86_64
[ ] RES 4 x86_64
[ ] RES 5 x86_64
[ ] RES 6 x86_64
[ ] SUSE Linux Enterprise Desktop 11 SP2 x86_64
[ ] SUSE Linux Enterprise Desktop 11 SP3 x86_64
[ ] SUSE Linux Enterprise Server 10 SP1 SAP AiO 11 SP1 x86_64
[ ] SUSE Linux Enterprise Server 10 SP1 SAP AiO 11 SP2 x86_64
[ ] SUSE Linux Enterprise Server 10 SP1 SAP AiO 11 SP3 x86_64
[ ] SUSE Linux Enterprise Server 10 SP3 x86_64
[I] SUSE Linux Enterprise Server 10 SP4 x86_64
  [ ] SUSE Linux Enterprise Software Development Kit 10 SP4 x86_64
[ ] SUSE Linux Enterprise Server 11 SP1 x86_64
[ ] SUSE Linux Enterprise Server 11 SP2 x86_64
[I] SUSE Linux Enterprise Server 11 SP3 x86_64
  [ ] Novell Open Enterprise Server 2 11.2 x86_64
  [ ] SUSE Cloud 2.0 x86_64
  [ ] SUSE Cloud 3 x86_64
  [ ] SUSE Linux Enterprise High Availability Extension 11 SP3 x86_64
  [ ] SUSE Linux Enterprise Point of Service 11 SP3 x86_64
  [ ] SUSE Linux Enterprise Real Time 11 x86_64
  [I] SUSE Linux Enterprise Software Development Kit 11 SP3 x86_64
  [ ] SUSE Linux Enterprise Subscription Management Tool 11 SP3 x86_64
  [ ] SUSE WebYaST 1.3 x86_64
[ ] SUSE Linux Enterprise Server 11 SP3 VMWare x86_64
[ ] SUSE Manager Proxy 1.2 x86_64
[ ] SUSE Manager Proxy 1.7 x86_64
[ ] SUSE Manager Proxy 2.1 x86_64
[ ] SUSE Manager Server 2.1 x86_64"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content,
            "listProducts",
            self.fake_auth_token)
コード例 #14
0
    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)
コード例 #15
0
    def test_list_product(self):
        options = get_options("list product".split())
        stubbed_xmlrpm_call = MagicMock(return_value=[])
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        with ConsoleRecorder() as recorder:
            self.mgr_sync.run(options)
        self.assertEqual(recorder.stdout, ["No products found."])

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listProducts",
            self.fake_auth_token)
コード例 #16
0
    def test_should_handle_max_number_of_authentication_failures(self):

        def raise_maximum_number_of_authentication_failures(options):
            raise MaximumNumberOfAuthenticationFailures
        self.mgr_sync._process_user_request = MagicMock()
        self.mgr_sync._process_user_request.side_effect = raise_maximum_number_of_authentication_failures

        options = get_options("list channels".split())
        with ConsoleRecorder() as recorder:
            self.assertEqual(1, self.mgr_sync.run(options))
        self.assertEqual(['mgr-sync: Authentication failure'], recorder.stderr)
コード例 #17
0
    def test_should_always_write_the_session_token_to_the_local_configuration(self):
        self.mgr_sync.config.token = "old token"
        self.mgr_sync.auth.user = '******'
        self.mgr_sync.auth.password = '******'
        self.mgr_sync._execute_xmlrpc_method = MagicMock(return_value=[])

        options = get_options("list channels".split())
        with ConsoleRecorder():
            self.assertEqual(0, self.mgr_sync.run(options))
        self.assertEqual(self.fake_auth_token, self.mgr_sync.config.token)

        self.mgr_sync.config.write.assert_called_once_with()
コード例 #18
0
    def test_list_credentials_no_credentials(self):
        """ Test listing credentials with none present """
        options = get_options("list credentials".split())
        stubbed_xmlrpm_call = MagicMock(return_value=[])
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        with ConsoleRecorder() as recorder:
            self.mgr_sync.run(options)

        self.assertEqual(recorder.stdout, ["No credentials found"])

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listCredentials",
            self.fake_auth_token)
コード例 #19
0
    def test_add_credentials_non_interactive(self):
        """ Test adding credentials non-interactively """
        options = get_options("add credentials foobar foo".split())
        self.mgr_sync._fetch_credentials = MagicMock(
            return_value=read_data_from_fixture("list_credentials.data"))

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

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "addCredentials",
            self.fake_auth_token, "foobar", "foo", False)
コード例 #20
0
    def test_refresh_should_not_trigger_reposync_when_there_is_an_error(self):
        """ The refresh action should not trigger a reposync when something
            went wrong during one of the refresh steps.
        """

        options = get_options("refresh --refresh-channels".split())
        stubbed_xmlrpm_call = MagicMock(side_effect=Exception("Boom baby!"))
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        mock_reposync = MagicMock()
        self.mgr_sync._schedule_channel_reposync = mock_reposync

        with ConsoleRecorder() as recorder:
            self.assertEqual(1, self.mgr_sync.run(options))

        self.assertTrue(recorder.stderr)
        self.assertFalse(mock_reposync.mock_calls)
コード例 #21
0
    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)
コード例 #22
0
    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)
コード例 #23
0
    def test_delete_credentials_non_interactive(self):
        """ Test deleting credentials non-interactively """
        options = get_options("delete credentials foo".split())
        self.mgr_sync._fetch_credentials = MagicMock(
            return_value=read_data_from_fixture("list_credentials.data"))
        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))

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "deleteCredentials",
            self.fake_auth_token, "foo")

        self.assertEqual(recorder.stdout,
                         ["Successfully deleted credentials: foo"])
コード例 #24
0
    def test_list_credentials(self):
        """ Test listing credentials """
        options = get_options("list credentials".split())
        stubbed_xmlrpm_call = MagicMock(
            return_value=read_data_from_fixture('list_credentials.data'))
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        with ConsoleRecorder() as recorder:
            self.mgr_sync.run(options)
        expected_output = """Credentials:
foo (primary)
bar"""

        self.assertEqual(expected_output.split("\n"), recorder.stdout)

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "listCredentials",
            self.fake_auth_token)
コード例 #25
0
    def test_add_unavailable_child_channel(self):
        """Test adding an unavailable child channel

        Should refuse to perform the operation, print to stderr and exit with
        an error code"""

        options = get_options("add channel sle10-sdk-sp4-pool-x86_64".split())
        self.mgr_sync._fetch_remote_channels = MagicMock(
            return_value=parse_channels(
                read_data_from_fixture("list_channels.data"),
                self.mgr_sync.log))

        with ConsoleRecorder() as recorder:
            self.assertEqual(1, self.mgr_sync.run(options))

        self.assertEqual(
            ["Channel 'sle10-sdk-sp4-pool-x86_64' is not available, skipping"],
            recorder.stdout)
コード例 #26
0
    def test_add_credentials_interactive(self):
        """ Test adding credentials interactively """
        options = get_options("add credentials".split())
        self.mgr_sync._fetch_credentials = MagicMock(
            return_value=read_data_from_fixture("list_credentials.data"))

        stubbed_xmlrpm_call = MagicMock()
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call

        with patch('spacewalk.susemanager.mgr_sync.mgr_sync.cli_ask') as mock:
            mock.side_effect = ["foobar", "foo", "foo"]
            with ConsoleRecorder() as recorder:
                self.assertEqual(0, self.mgr_sync.run(options))

        stubbed_xmlrpm_call.assert_called_once_with(
            self.mgr_sync.conn.sync.content, "addCredentials",
            self.fake_auth_token, "foobar", "foo", False)

        self.assertEqual(recorder.stdout, ["Successfully added credentials."])
コード例 #27
0
    def test_sync_channels_interactive_with_children(self):
        options = get_options("sync channels --with-children".split())
        available_channels = [
            'sles10-sp4-pool-x86_64', 'sle10-sdk-sp4-updates-x86_64'
        ]
        chosen_channel = available_channels[0]
        self.mgr_sync._list_channels = MagicMock(
            return_value=available_channels)
        stubbed_xmlrpm_call = MagicMock(return_value=read_data_from_fixture(
            'list_channels_simplified.data'))
        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 = [
                "Scheduling reposync for following channels:",
                "- sles10-sp4-pool-x86_64",
                "- sle10-sdk-sp4-updates-x86_64",
            ]
            self.assertEqual(expected_output, recorder.stdout)

            self.mgr_sync._list_channels.assert_called_once_with(
                expand=False,
                filter=None,
                no_optionals=False,
                show_interactive_numbers=True,
                compact=False,
                only_installed=True)

            expected_xmlrpc_calls = [
                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_xmlrpc_calls)
コード例 #28
0
    def test_refresh_never_ask_credentials_when_schedule_option_is_set(self):
        """ Refresh with the 'schedule' option should just schedule the
            operation. User credentials must not be asked.
        """

        options = get_options("refresh --schedule".split())
        mock_execute_xmlrpc = MagicMock()
        self.mgr_sync._execute_xmlrpc_method = mock_execute_xmlrpc
        mock_reposync = MagicMock()
        self.mgr_sync._schedule_channel_reposync = mock_reposync
        mock_schedule_taskomatic_refresh = MagicMock()
        self.mgr_sync._schedule_taskomatic_refresh = mock_schedule_taskomatic_refresh

        with ConsoleRecorder() as recorder:
            self.assertEqual(0, self.mgr_sync.run(options))

        self.assertEqual(['Refresh successfully scheduled'], recorder.stdout)

        self.assertTrue(mock_schedule_taskomatic_refresh.mock_calls)
        self.assertFalse(mock_execute_xmlrpc.mock_calls)
        self.assertFalse(mock_reposync.mock_calls)
コード例 #29
0
    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)
コード例 #30
0
    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)