コード例 #1
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)
コード例 #2
0
    def test_list_installed_only_channels_interactive(self):
        """ Test listing channels when interactive more is set """
        stubbed_xmlrpm_call = MagicMock(return_value=read_data_from_fixture(
            'list_channels_simplified.data'))
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        available_channels = []
        with ConsoleRecorder() as recorder:
            available_channels = self.mgr_sync._list_channels(
                expand=False,
                filter=None,
                no_optionals=True,
                show_interactive_numbers=True,
                only_installed=True)
        expected_output = """Available Channels:


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

  1) [I] SLES10-SP4-Pool for x86_64 SUSE Linux Enterprise Server 10 SP4 x86_64 [sles10-sp4-pool-x86_64]
      2) [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)

        self.assertEqual(
            ['sles10-sp4-pool-x86_64', 'sle10-sdk-sp4-updates-x86_64'],
            available_channels)
コード例 #3
0
ファイル: test_channel.py プロジェクト: ncounter/uyuni
    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]))
コード例 #4
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)
コード例 #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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)
        ]
コード例 #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
ファイル: test_channel.py プロジェクト: ncounter/uyuni
    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))
コード例 #16
0
ファイル: test_merge_rd.py プロジェクト: renner/uyuni
    def test_should_create_a_new_initrd_starting_from_a_xz_compressed_one(
            self):
        self.ensure_package_is_installed("tar", "xz")
        self.ensure_package_is_installed("xz")

        (status, stdout, stderr) = my_popen([
            "/bin/sh", MERGE_RD_CMD, self.initrd_xz, self.final_initrd,
            helper.path_to_fixture("ks-tree-shadow/")
        ])

        # ensure the new initrd has been created
        errors = "".join(stderr.readlines())
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))
        self.assertTrue(os.path.exists(self.final_initrd))

        # ensure the new initrd is compressed using gzip
        (status, stdout, stderr) = my_popen([
            "file",
            self.final_initrd,
        ])
        errors = "".join(stderr.readlines())
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))
        self.assertTrue("gzip compressed data" in "".join(stdout.readlines()))

        # uncompress the initrd
        (status, stdout, stderr) = my_popen(["gzip", "-d", self.final_initrd])
        errors = "".join(stderr.readlines())
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))

        # extract the contents of the initrd
        uncomp_dir = os.path.join(self.data_dir, "uncompressed")
        os.mkdir(uncomp_dir)

        os.chdir(uncomp_dir)
        (status, stdout, stderr) = my_popen(
            ["cpio", "-idF",
             self.final_initrd.replace(".gz", "")])
        errors = "".join(stderr.readlines())
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))

        test_file = os.path.join(uncomp_dir, "susemanager", "test_file")
        self.assertTrue(os.path.exists(test_file))

        expected_data = helper.read_data_from_fixture(
            "ks-tree-shadow/susemanager/test_file")
        with open(test_file) as file:
            self.assertEqual(file.read(), expected_data)

        # the "uncomp_dir" is going to be removed at the end of the tests
        os.chdir("/")
コード例 #17
0
    def test_list_products_with_interactive_mode_enabled(self):
        """ Test listing products """

        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._list_products(filter=None,
                                         show_interactive_numbers=True)

        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)
002) [ ] RES 4 (x86_64)
003) [ ] RES 5 (x86_64)
004) [ ] RES 6 (x86_64)
005) [ ] SUSE Linux Enterprise Desktop 11 SP2 (x86_64)
006) [ ] SUSE Linux Enterprise Desktop 11 SP3 (x86_64)
007) [ ] SUSE Linux Enterprise Server 10 SP1 SAP AiO 11 SP1 (x86_64)
008) [ ] SUSE Linux Enterprise Server 10 SP1 SAP AiO 11 SP2 (x86_64)
009) [ ] SUSE Linux Enterprise Server 10 SP1 SAP AiO 11 SP3 (x86_64)
010) [ ] SUSE Linux Enterprise Server 10 SP3 (x86_64)
     [I] SUSE Linux Enterprise Server 10 SP4 (x86_64)
011)   [ ] SUSE Linux Enterprise Software Development Kit 10 SP4 (x86_64)
012) [ ] SUSE Linux Enterprise Server 11 SP1 (x86_64)
013) [ ] SUSE Linux Enterprise Server 11 SP2 (x86_64)
     [I] SUSE Linux Enterprise Server 11 SP3 (x86_64)
014)   [ ] Novell Open Enterprise Server 2 11.2 (x86_64)
015)   [ ] SUSE Cloud 2.0 (x86_64)
016)   [ ] SUSE Cloud 3 (x86_64)
017)   [ ] SUSE Linux Enterprise High Availability Extension 11 SP3 (x86_64)
018)   [ ] SUSE Linux Enterprise Point of Service 11 SP3 (x86_64)
019)   [ ] SUSE Linux Enterprise Real Time 11 (x86_64)
       [I] SUSE Linux Enterprise Software Development Kit 11 SP3 (x86_64)
020)   [ ] SUSE Linux Enterprise Subscription Management Tool 11 SP3 (x86_64)
021)   [ ] SUSE WebYaST 1.3 (x86_64)
022) [ ] SUSE Linux Enterprise Server 11 SP3 VMWare (x86_64)
023) [ ] SUSE Manager Proxy 1.2 (x86_64)
024) [ ] SUSE Manager Proxy 1.7 (x86_64)
025) [ ] SUSE Manager Proxy 2.1 (x86_64)
026) [ ] SUSE Manager Server 2.1 (x86_64)"""

        self.assertEqual(recorder.stdout, expected_output.split("\n"))
コード例 #18
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)
コード例 #19
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)
コード例 #20
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)
コード例 #21
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"])
コード例 #22
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)
コード例 #23
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)
コード例 #24
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."])
コード例 #25
0
    def test_list_credentials_interactive(self):
        """ Test listing credentials when interactive mode is set """
        stubbed_xmlrpm_call = MagicMock(
            return_value=read_data_from_fixture("list_credentials.data"))
        self.mgr_sync._execute_xmlrpc_method = stubbed_xmlrpm_call
        credentials = []

        with ConsoleRecorder() as recorder:
            credentials = self.mgr_sync._list_credentials(show_interactive_numbers=True)
        expected_output = """Credentials:
01) foo (primary)
02) 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)
コード例 #26
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)
コード例 #27
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)
コード例 #28
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)
コード例 #29
0
    def test_list_channels_filter_set(self):
        """ Testing list channel output when a filter is set """
        options = get_options("list channel --filter rhel".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]"""

        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)
コード例 #30
0
def xmlrpc_product_sideeffect(*args, **kwargs):
    if args[1] == "addChannels":
        return [args[3]]
    return read_data_from_fixture('list_channels_simplified.data')