Exemplo n.º 1
0
    def test_parse_channels(self):
        with open(path_to_fixture("expected_channels.json"), "r") as file:
            expected_channels = json.load(file)

        with open(path_to_fixture("expected_hierarchy.json"), "r") as file:
            expected_hierarchy = json.load(file)

        channels = parse_channels(
            read_data_from_fixture("list_channels.data"),
            self.mgr_sync.log)

        self.assertEqual(sorted(channels.keys()),
                         sorted(expected_hierarchy.keys()))
        for label, bc in channels.items():
            self.assertEqual(label, bc.label)
            self.assertEqual(
                bc.status,
                expected_channels[bc.label])

            if bc.children and bc.status == Channel.Status.INSTALLED:
                children = sorted([c.label for c in bc.children])
                self.assertEqual(children,
                                 sorted(expected_hierarchy[bc.label]))
            else:
                self.assertEqual(0, len(expected_hierarchy[bc.label]))
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
        ]
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def test_find_channel_by_label(self):
        channels = parse_channels(
            read_data_from_fixture("list_channels.data"), self.mgr_sync.log)

        for label in ['rhel-x86_64-es-4',
                      'sles11-sp2-updates-i586']:
            bc = find_channel_by_label(label, channels, self.mgr_sync.log)
            self.assertIsNotNone(bc)
            self.assertEqual(label, bc.label)

        self.assertIsNone(find_channel_by_label('foobar', channels, self.mgr_sync.log))
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def _fetch_remote_channels(self):
     """ Returns the list of channels as reported by the remote server """
     return parse_channels(
         self._execute_xmlrpc_method(self.conn.sync.content,
                                     "listChannels", self.auth.token()), self.log)