コード例 #1
0
ファイル: test_errata.py プロジェクト: sitedata/uyuni
    def test_errata_findbycve_cvelist(self, shell):
        """
        Test do_errata_findbycve with CVE list.

        :param shell:
        :return:
        """
        shell.help_errata_findbycve = MagicMock()
        shell.client.errata.findByCve = MagicMock(side_effect=[
            [{"advisory_name": "CVE-123-a"}, {"advisory_name": "CVE-123-b"}],
            [{"advisory_name": "CVE-234-a"}, {"advisory_name": "CVE-234-b"}, {"advisory_name": "CVE-234-c"}],
            [{"advisory_name": "CVE-345-a"}],
        ])
        mprint = MagicMock()

        with patch("spacecmd.errata.print", mprint) as prt:
            spacecmd.errata.do_errata_findbycve(shell, "123 234 345")

        assert not shell.help_errata_findbycve.called
        assert shell.client.errata.findByCve.called
        assert mprint.called

        assert_list_args_expect(mprint.call_args_list,
                                ['123:', 'CVE-123-a', 'CVE-123-b', '----------',
                                 '234:', 'CVE-234-a', 'CVE-234-b', 'CVE-234-c',
                                 '----------', '345:', 'CVE-345-a'])
コード例 #2
0
ファイル: test_package.py プロジェクト: skymysky/uyuni
    def test_package_listdependencies_invalid_package(self, shell):
        """
        Test do_packge_listdependencies with invalid packages
            :param self:
            :param shell:
        """
        shell.do_package_search = MagicMock(
            return_value=["vi", "vim", "gvim", "xvim"])
        shell.help_package_listdependencies = MagicMock()
        shell.get_package_id = MagicMock(return_value=[None])
        shell.client.packages.list_dependencies = MagicMock()

        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.package.print", mprint) as prn, \
            patch("spacecmd.package.logging", logger) as lgr:
            spacecmd.package.do_package_listdependencies(shell, "bad-editor")

        assert not shell.client.packages.list_dependencies.called
        assert not mprint.called
        assert not shell.help_package_listdependencies.called
        assert shell.do_package_search.called
        assert logger.warning.called
        assert shell.get_package_id.called

        expectations = [
            'vi is not a valid package', 'vim is not a valid package',
            'gvim is not a valid package', 'xvim is not a valid package'
        ]
        assert_list_args_expect(logger.warning.call_args_list, expectations)
コード例 #3
0
ファイル: test_errata.py プロジェクト: uyuni-project/uyuni
    def test_errata_publish_no_errata(self, shell):
        """
        Test do_errata_publish no errata found.

        :param shell:
        :return:
        """
        shell.help_errata_publish = MagicMock()
        shell.expand_errata = MagicMock(return_value=[])
        shell.user_confirm = MagicMock()
        shell.client.errata.publish = MagicMock()
        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.errata.print", mprint) as prt, \
                patch("spacecmd.errata.logging", logger) as lgr:
            spacecmd.errata.do_errata_publish(shell, "CVE-1 base_channel")

        assert not shell.user_confirm.called
        assert not shell.client.errata.publish.called
        assert not mprint.called
        assert not shell.help_errata_publish.called
        assert shell.expand_errata.called
        assert logger.warning.called
        assert_list_args_expect(logger.warning.call_args_list,
                                ["No patches to publish"])
コード例 #4
0
ファイル: test_group.py プロジェクト: vzhestkov/uyuni
    def test_group_removesystems_nossm_sys(self, shell):
        """
        Test do_group_removesystems with filters and found systems.

        :param shell:
        :return:
        """

        shell.help_group_removesystems = MagicMock()
        shell.get_system_id = MagicMock(side_effect=["1000010000", "1000010001"])
        shell.expand_systems = MagicMock(return_value=["one", "two"])
        shell.client.systemgroup.addOrRemoveSystems = MagicMock()
        shell.ssm.keys = MagicMock()
        shell.user_confirm = MagicMock(return_value=True)
        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.group.print", mprint) as prn, \
            patch("spacecmd.group.logging", logger) as lgr:
            spacecmd.group.do_group_removesystems(shell, "somegroup somesystem")

        assert not logger.error.called
        assert not shell.help_group_removesystems.called
        assert not shell.ssm.keys.called
        assert shell.get_system_id.called
        assert shell.user_confirm.called
        assert mprint.called
        assert shell.expand_systems.called
        assert shell.client.systemgroup.addOrRemoveSystems.called

        assert_args_expect(shell.client.systemgroup.addOrRemoveSystems.call_args_list,
                           [((shell.session, 'somegroup', ['1000010000', '1000010001'], False), {})])
        assert_list_args_expect(mprint.call_args_list,
                                ["Systems", "-------", "one\ntwo"])
コード例 #5
0
    def test_kickstart_clone_interactive_wrong_profile_entered(self, shell):
        """
        Test do_kickstart_clone interactive. Wrong profile has been entered.

        :param shell:
        :return:
        """
        mprint = MagicMock()
        logger = MagicMock()
        prompter = MagicMock(side_effect=[
            "posix_compliance_problem", "POSIX"])
        shell.do_kickstart_list = MagicMock(return_value=[
            "default_kickstart_profile", "some_other_profile"])
        with patch("spacecmd.kickstart.print", mprint) as prt, \
                patch("spacecmd.kickstart.logging", logger) as lgr, \
                patch("spacecmd.kickstart.prompt_user", prompter) as pmt:
            spacecmd.kickstart.do_kickstart_clone(shell, "")

        assert not shell.client.kickstart.cloneProfile.called
        assert mprint.called
        assert prompter.called
        assert logger.error.called

        assert_expect(logger.error.call_args_list,
                      "Kickstart profile you've entered was not found")
        assert_list_args_expect(mprint.call_args_list,
                                ['', 'Kickstart Profiles', '------------------',
                                 'default_kickstart_profile\nsome_other_profile', ''])
        assert_args_expect(prompter.call_args_list,
                           [(('Original Profile:',), {"noblank": True}),
                            (('Cloned Profile:',), {"noblank": True})])
コード例 #6
0
def test_listsystems_noargs_channel_no_data(shell):
    """
    Test do_softwarechannel_listsystems one channel, no data.

    :param shell:
    :return:
    """
    shell.client.channel.software.listSubscribedSystems = MagicMock(
        return_value=[
            {
                "name": "one.acme.lan"
            },
            {
                "name": "two.acme.lan"
            },
            {
                "name": "zetta.acme.lan"
            },
            {
                "name": "third.zoo.lan"
            },
        ])
    mprint = MagicMock()
    with patch("spacecmd.softwarechannel.print", mprint):
        out = spacecmd.softwarechannel.do_softwarechannel_listsystems(
            shell, "my_channel")

    assert not shell.help_softwarechannel_listsystems.called
    assert out is None
    assert mprint.called
    assert shell.client.channel.software.listSubscribedSystems.called
    assert_list_args_expect(
        mprint.call_args_list,
        ['one.acme.lan\nthird.zoo.lan\ntwo.acme.lan\nzetta.acme.lan'])
コード例 #7
0
    def test_repo_listfilters_stdout(self, shell):
        """
        Test do_repo_listfilters stdout check

        :param shell:
        :return:
        """
        shell.help_repo_listfilters = MagicMock()
        shell.client.channel.software.listRepoFilters = MagicMock(
            return_value=[
                {
                    "flag": "+",
                    "filter": "stuff"
                },
                {
                    "flag": "-",
                    "filter": "other"
                },
            ])
        mprint = MagicMock()

        with patch("spacecmd.repo.print", mprint):
            out = spacecmd.repo.do_repo_listfilters(shell, "some-filter")

        assert out is 0
        assert not shell.help_repo_listfilters.called
        assert shell.client.channel.software.listRepoFilters.called
        assert mprint.called

        assert_list_args_expect(mprint.call_args_list, ['+stuff', '-other'])
コード例 #8
0
ファイル: test_errata.py プロジェクト: uyuni-project/uyuni
    def test_errata_listcves_expanded(self, shell):
        """
        Test do_errata_listcves data print check.

        :param shell:
        :return:
        """
        shell.help_errata_listcves = MagicMock()
        shell.client.errata.listCves = MagicMock(side_effect=[
            ["CVE-1", "CVE-2", "CVE-3"],
            ["CVE-11", "CVE-22", "CVE-33"],
        ])
        shell.expand_errata = MagicMock(return_value=["one", "two"])
        mprint = MagicMock()

        with patch("spacecmd.errata.print", mprint) as prt:
            spacecmd.errata.do_errata_listcves(shell, "CVE*")

        assert not shell.help_errata_listcves.called
        assert shell.client.errata.listCves.called
        assert shell.expand_errata.called
        assert mprint.called

        assert_list_args_expect(mprint.call_args_list, [
            'one:', 'CVE-1\nCVE-2\nCVE-3', '----------', 'two:',
            'CVE-11\nCVE-22\nCVE-33'
        ])
コード例 #9
0
def test_softwarechannel_listmanageablechannels_noarg(shell):
    """
    Test do_softwarechannel_listmanageablechannels without arguments.

    :param shell:
    :return:
    """
    shell.client.channel.listManageableChannels = MagicMock(return_value=[
        {
            "label": "x_channel"
        },
        {
            "label": "z_channel"
        },
        {
            "label": "a_channel"
        },
    ])

    mprint = MagicMock()
    with patch("spacecmd.softwarechannel.print", mprint):
        out = spacecmd.softwarechannel.do_softwarechannel_listmanageablechannels(
            shell, "")

    assert out is None
    assert not shell.client.channel.software.getDetails.called
    assert shell.client.channel.listManageableChannels.called
    assert_list_args_expect(mprint.call_args_list,
                            ["a_channel", "x_channel", "z_channel"])
コード例 #10
0
ファイル: test_errata.py プロジェクト: sitedata/uyuni
    def test_errata_listaffectedsystems_by_errata_name(self, shell):
        """
        Test do_errata_listaffectedsystems with errata name.

        :param shell:
        :return:
        """

        shell.help_errata_listaffectedsystems = MagicMock()
        shell.expand_errata = MagicMock(return_value=["webstack", "databases"])
        shell.client.errata.listAffectedSystems = MagicMock(side_effect=[
            [{"name": "web1.suse.com"}, {"name": "web2.suse.com"}, {"name": "web3.suse.com"}],
            [{"name": "db1.suse.com"}, {"name": "db2.suse.com"}, {"name": "db3.suse.com"}],
        ])
        mprint = MagicMock()

        with patch("spacecmd.errata.print", mprint) as prt:
            spacecmd.errata.do_errata_listaffectedsystems(shell, "foo")

        assert not shell.help_errata_listaffectedsystems.called
        assert shell.client.errata.listAffectedSystems.called
        assert shell.expand_errata.called
        assert mprint.called

        assert_list_args_expect(mprint.call_args_list,
                                ['webstack:', 'web1.suse.com\nweb2.suse.com\nweb3.suse.com',
                                 '----------', 'databases:', 'db1.suse.com\ndb2.suse.com\ndb3.suse.com'])
コード例 #11
0
ファイル: test_group.py プロジェクト: vzhestkov/uyuni
    def test_group_backup_all_group_list(self, shell):
        """
        Test do_group_backup with all groups lookup

        :param shell:
        :return:
        """
        def exp_user(path):
            """
            Fake expand user

            :param path:
            :return:
            """
            return os.path.join("/opt/spacecmd", path.replace("~", "").strip("/"))

        shell.help_group_backup = MagicMock()
        shell.do_group_list = MagicMock(return_value=["group-a", "group-b"])
        shell.client.systemgroup.getDetails = MagicMock(
            side_effect=[
                {"description": "Group A description"},
                {"description": "Group B description"},
            ]
        )
        mprint = MagicMock()
        logger = MagicMock()
        opener = MagicMock()
        _open = MagicMock(return_value=opener)

        _datetime = MagicMock()
        _datetime.now = MagicMock(return_value=datetime.datetime(2019, 1, 1))

        with patch("spacecmd.group.print", mprint) as prn, \
            patch("spacecmd.group.logging", logger) as lgr, \
            patch("spacecmd.group.os.path.expanduser", exp_user) as exu, \
            patch("spacecmd.group.open", _open) as opr, \
            patch("spacecmd.group.datetime", _datetime) as dtm:
            spacecmd.group.do_group_backup(shell, "ALL")

        assert not logger.called
        assert not shell.help_group_backup.called
        assert shell.do_group_list.called
        assert shell.client.systemgroup.getDetails.called
        assert mprint.called
        assert opener.write.called
        assert opener.close.called

        assert_list_args_expect(mprint.call_args_list,
                                ['Backup Group: group-a',
                                 'Output File: /opt/spacecmd/spacecmd-backup/group/2019-01-01/group-a',
                                 'Backup Group: group-b',
                                 'Output File: /opt/spacecmd/spacecmd-backup/group/2019-01-01/group-b'
                                 ])

        assert_list_args_expect(opener.write.call_args_list,
                                ["Group A description", "Group B description"])
        assert_args_expect(_open.call_args_list,
                           [(('/opt/spacecmd/spacecmd-backup/group/2019-01-01/group-a', 'w'), {}),
                            (('/opt/spacecmd/spacecmd-backup/group/2019-01-01/group-b', 'w'), {}),])
コード例 #12
0
ファイル: test_org.py プロジェクト: vzhestkov/uyuni
    def test_org_trustdetails(self, shell):
        """
        Test do_or_trustdetails

        :param shell:
        :return:
        """
        shell.help_org_trustdetails = MagicMock()
        shell.get_org_id = MagicMock(return_value=1)
        shell.client.org.trusts.getDetails = MagicMock(
            return_value={
                "trusted_since": "Mi 29. Mai 15:02:26 CEST 2019",
                "systems_transferred_from": 3,
                "systems_transferred_to": 8
            })
        shell.client.org.trusts.listChannelsConsumed = MagicMock(return_value=[
            {
                "name": "base_channel"
            },
            {
                "name": "special_channel"
            },
        ])
        shell.client.org.trusts.listChannelsProvided = MagicMock(return_value=[
            {
                "name": "base_channel"
            },
            {
                "name": "suse_channel"
            },
            {
                "name": "rh_channel"
            },
        ])

        logger = MagicMock()
        mprint = MagicMock()
        with patch("spacecmd.org.print", mprint) as prn, \
            patch("spacecmd.org.logging", logger) as lgr:
            spacecmd.org.do_org_trustdetails(shell, "myorg")

        assert not shell.help_org_trustdetails.called
        assert not logger.warning.called
        assert shell.client.org.trusts.getDetails.called
        assert shell.client.org.trusts.listChannelsConsumed.called
        assert shell.client.org.trusts.listChannelsProvided.called
        assert shell.get_org_id.called
        assert mprint.called

        exp = [
            'Trusted Organization:   myorg',
            'Trusted Since:          Mi 29. Mai 15:02:26 CEST 2019',
            'Systems Transferred From:  3', 'Systems Transferred To:    8', '',
            'Channels Consumed', '-----------------',
            'base_channel\nspecial_channel', '', 'Channels Provided',
            '-----------------', 'base_channel\nrh_channel\nsuse_channel'
        ]

        assert_list_args_expect(mprint.call_args_list, exp)
コード例 #13
0
    def test_schedule_getoutput_scripts(self, shell):
        """
        Test do_schedule_getoutput with scripts

        :param shell:
        :return:
        """
        shell.get_system_name = MagicMock(
            side_effect=["web.foo.com", "db.foo.com"])
        shell.client.schedule.listCompletedSystems = MagicMock(return_value=[])
        shell.client.schedule.listFailedSystems = MagicMock(return_value=[])
        shell.client.system.getScriptResults = MagicMock(
            return_value=[{
                "serverId": 1000010000,
                "startDate": "2019-01-01",
                "stopDate": "2019-01-02",
                "returnCode": 42,
                "output": "Normal output"
            }, {
                "startDate": "2019-02-01",
                "stopDate": "2019-02-02",
                "returnCode": 1,
                "output_enc64": True,
                "output": b"Tm93IHlvdSBzZWUgbWUh\n"
            }, {
                "serverId": 1000010001,
                "startDate": "2019-01-11",
                "stopDate": "2019-01-22",
                "returnCode": 13,
                "output": None
            }])
        shell.help_schedule_getoutput = MagicMock()

        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.schedule.print", mprint) as prt, \
                patch("spacecmd.schedule.logging", logger) as lgr:
            spacecmd.schedule.do_schedule_getoutput(shell, "42")

        assert not logger.warning.called
        assert not shell.help_schedule_getoutput.called
        assert not shell.client.schedule.listCompletedSystems.called
        assert not shell.client.schedule.listFailedSystems.called
        assert not logger.debug.called
        assert not logger.error.called
        assert mprint.called
        assert shell.client.system.getScriptResults.called

        assert_list_args_expect(mprint.call_args_list, [
            'System:      web.foo.com', 'Start Time:  2019-01-01',
            'Stop Time:   2019-01-02', 'Return Code: 42', '', 'Output',
            '------', 'Normal output', '----------', 'System:      UNKNOWN',
            'Start Time:  2019-02-01', 'Stop Time:   2019-02-02',
            'Return Code: 1', '', 'Output', '------', 'Now you see me!',
            '----------', 'System:      db.foo.com', 'Start Time:  2019-01-11',
            'Stop Time:   2019-01-22', 'Return Code: 13', '', 'Output',
            '------', 'N/A'
        ])
コード例 #14
0
ファイル: test_group.py プロジェクト: vzhestkov/uyuni
    def test_group_details_long_report(self, shell):
        """
        Test do_group_details long report.

        :param shell:
        :return:
        """
        shell.help_group_details = MagicMock()
        shell.client.systemgroup.getDetails = MagicMock(side_effect=[
            {"id": 1, "name": "Group A", "description": "Test group A", "system_count": 5},
            {"id": 2, "name": "Group B", "description": "Test group B", "system_count": 10},
            {"id": 3, "name": "Group C", "description": "Test group C", "system_count": 25}
        ])
        shell.client.systemgroup.listSystems = MagicMock(side_effect=[
            [{"profile_name": "prf-a"}, {"profile_name": "prf-b"}],
            [{"profile_name": "prf-c"}, {"profile_name": "prf-d"}],
            [{"profile_name": "prf-e"}, {"profile_name": "prf-f"}],
        ])

        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.group.print", mprint) as prt, \
            patch("spacecmd.group.logging", logger) as lgr:
            spacecmd.group.do_group_details(shell, "group-a group-b group-c")

        assert not shell.help_group_details.called
        assert not logger.warning.called
        assert shell.client.systemgroup.getDetails.called
        assert shell.client.systemgroup.listSystems.called
        assert mprint.called

        assert_list_args_expect(mprint.call_args_list,
                                ['ID:                1',
                                 'Name:              Group A',
                                 'Description:       Test group A',
                                 'Number of Systems: 5',
                                 '',
                                 'Members',
                                 '-------',
                                 'prf-a\nprf-b',
                                 '----------',
                                 'ID:                2',
                                 'Name:              Group B',
                                 'Description:       Test group B',
                                 'Number of Systems: 10',
                                 '',
                                 'Members',
                                 '-------',
                                 'prf-c\nprf-d',
                                 '----------',
                                 'ID:                3',
                                 'Name:              Group C',
                                 'Description:       Test group C',
                                 'Number of Systems: 25',
                                 '',
                                 'Members',
                                 '-------',
                                 'prf-e\nprf-f'])
コード例 #15
0
ファイル: test_package.py プロジェクト: skymysky/uyuni
    def test_package_listerrata_packages(self, shell):
        """
        Test do_package_listerrata with a package names.

            :param shell:
            :param args:
        """
        shell.do_package_search = MagicMock(
            return_value=["emacs", "xemacs", "emacs-nox"])
        shell.client.packages.listProvidingErrata = MagicMock(
            side_effect=[[
                {
                    "advisory": "RHBA-2019:4231"
                },
                {
                    "advisory": "CVE-2019:123-4"
                },
            ],
                         [
                             {
                                 "advisory": "RHBA-2019:4231"
                             },
                             {
                                 "advisory": "RHBA-2019:4232"
                             },
                             {
                                 "advisory": "RHBA-2019:4233"
                             },
                         ], [{
                             "advisory": "CVE-2018:152-5"
                         }]])
        shell.get_package_id = MagicMock(return_value=["bogus-package-id"])
        shell.help_package_listerrata = MagicMock()

        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.package.print", mprint) as prn, \
            patch("spacecmd.package.logging", logger) as lgr:
            spacecmd.package.do_package_listerrata(shell, "emacs")

        assert not logger.warning.called
        assert not shell.help_package_listerrata.called
        assert shell.client.packages.listProvidingErrata.called
        assert shell.get_package_id.called
        assert mprint.called
        assert shell.do_package_search.called

        expectations = [
            'emacs', '-----', 'CVE-2019:123-4\nRHBA-2019:4231', '----------',
            'xemacs', '------',
            'RHBA-2019:4231\nRHBA-2019:4232\nRHBA-2019:4233', '----------',
            'emacs-nox', '---------', 'CVE-2018:152-5'
        ]

        assert_list_args_expect(mprint.call_args_list, expectations)
コード例 #16
0
ファイル: test_errata.py プロジェクト: sitedata/uyuni
    def test_errata_details_erratum_none_data(self, shell):
        """
        Test do_errata_details erratum none data.

        :param shell:
        :return:
        """
        shell.help_errata_details = MagicMock()
        shell.client.errata.getDetails = MagicMock(side_effect=[{}, {}])
        shell.client.errata.listPackages = MagicMock(side_effect=[
            [
                {"name": "vim", "version": "42", "release": "123", "arch": "x86"},
                {"name": "pico", "version": "1", "release": "234", "arch": "x86"},
            ],
            [
                {"name": "vim", "version": "28", "release": "45", "arch": "x86"},
                {"name": "pico", "version": "2", "release": "12", "arch": "x86"},
            ],
        ])
        shell.client.errata.listAffectedSystems = MagicMock(side_effect=[[], []])
        shell.client.errata.listCves = MagicMock(side_effect=[[], []])
        shell.client.errata.applicableToChannels = MagicMock(side_effect=[[{}, {}], [{}, {}]])
        shell.expand_errata = MagicMock(return_value=["cve-one", "cve-two"])
        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.errata.print", mprint) as prt, \
                patch("spacecmd.errata.logging", logger) as lgr:
            spacecmd.errata.do_errata_details(shell, "cve*")

        assert not logger.warning.called
        assert not shell.help_errata_details.called
        assert shell.client.errata.getDetails.called
        assert shell.client.errata.listPackages.called
        assert shell.client.errata.listAffectedSystems.called
        assert shell.client.errata.listCves.called
        assert shell.client.errata.applicableToChannels.called
        assert mprint.called

        assert_list_args_expect(mprint.call_args_list,
                                ['Name:       cve-one', 'Product:    N/A', 'Type:       N/A', 'Issue Date: N/A', '',
                                 'Topic', '-----', 'N/A', '', 'Description', '-----------', 'N/A', '', 'CVEs', '----',
                                 '', '', 'Solution', '--------', 'N/A', '', 'References', '----------', 'N/A', '',
                                 'Affected Channels',
                                 '-----------------', '', '', 'Affected Systems', '----------------', '0', '',
                                 'Affected Packages', '-----------------', 'pico-1-234.x86\nvim-42-123.x86',
                                 '----------', 'Name:       cve-two', 'Product:    N/A', 'Type:       N/A',
                                 'Issue Date: N/A', '', 'Topic', '-----', 'N/A', '', 'Description', '-----------',
                                 'N/A', '', 'CVEs', '----', '', '', 'Solution', '--------', 'N/A', '', 'References',
                                 '----------', 'N/A', '', 'Affected Channels', '-----------------', '', '',
                                 'Affected Systems', '----------------', '0', '', 'Affected Packages',
                                 '-----------------', 'pico-2-12.x86\nvim-28-45.x86'])
コード例 #17
0
    def test_repo_details_repo_data(self, shell):
        """
        Test do_repo_details for repo data.

        :param shell:
        :return:
        """
        shell.client.channel.software.getRepoDetails = MagicMock(side_effect=[
            {
                "label": "some-repository",
                "sourceUrl": "http://somehost/somerepo",
                "type": "yum"
            },
            {
                "label": "some-other-repository",
                "sourceUrl": "file:///tmp/someotherrepo",
                "type": "zypper",
                "sslCaDesc": "Ca Descr",
                "sslCertDesc": "Cert descr",
                "sslKeyDesc": "Key descr"
            },
        ])
        shell.do_repo_list = MagicMock(
            return_value=["some-repo", "some-other-repo"])
        shell.help_repo_details = MagicMock()
        mprint = MagicMock()
        with patch("spacecmd.repo.print", mprint):
            out = spacecmd.repo.do_repo_details(shell, "some*")

        assert not shell.help_repo_details.called
        assert shell.client.channel.software.getRepoDetails.called
        assert out is 0
        assert mprint.called

        exp = [
            'Repository Label:                  some-repository',
            'Repository URL:                    http://somehost/somerepo',
            'Repository Type:                   yum',
            'Repository SSL Ca Certificate:     None',
            'Repository SSL Client Certificate: None',
            'Repository SSL Client Key:         None', '----------',
            'Repository Label:                  some-other-repository',
            'Repository URL:                    file:///tmp/someotherrepo',
            'Repository Type:                   zypper',
            'Repository SSL Ca Certificate:     Ca Descr',
            'Repository SSL Client Certificate: Cert descr',
            'Repository SSL Client Key:         Key descr'
        ]
        assert_list_args_expect(mprint.call_args_list, exp)
コード例 #18
0
def test_softwarechannel_listmanageablechannels_default_verbose(shell):
    """
    Test do_softwarechannel_listmanageablechannels with verbose arg (all).

    :param shell:
    :return:
    """
    shell.client.channel.listManageableChannels = MagicMock(return_value=[
        {
            "label": "x_channel"
        },
        {
            "label": "z_channel"
        },
        {
            "label": "b_channel"
        },
        {
            "label": "a_channel"
        },
    ])
    shell.client.channel.software.getDetails = MagicMock(side_effect=[
        {
            "summary": "A summary"
        },
        {
            "summary": "B summary"
        },
        {
            "summary": "X summary"
        },
        {
            "summary": "Z summary"
        },
    ])

    mprint = MagicMock()
    with patch("spacecmd.softwarechannel.print", mprint):
        out = spacecmd.softwarechannel.do_softwarechannel_listmanageablechannels(
            shell, "--verbose")

    assert out is None
    assert shell.client.channel.software.getDetails.called
    assert shell.client.channel.listManageableChannels.called
    assert_list_args_expect(mprint.call_args_list, [
        "a_channel : A summary", "b_channel : B summary",
        "x_channel : X summary", "z_channel : Z summary"
    ])
コード例 #19
0
    def test_help_system_listevents_new_version_api_deprecation(self, shell):
        """
            test help_system_listevents to ensure the deprecation warning is shown for recent API version
        """
        shell.check_api_version = MagicMock(return_value=True)

        m_logger = MagicMock()

        with patch("spacecmd.system.logging", m_logger):
            spacecmd.system.help_system_listevents(shell)

        assert m_logger.warning.called
        assert_list_args_expect(m_logger.warning.call_args_list, [
            'This method is deprecated and will be removed in a future API version. '
            'Please use system_listeventhistory instead.\n'
        ])
コード例 #20
0
ファイル: test_errata.py プロジェクト: uyuni-project/uyuni
    def test_errata_delete_no_errata_non_interactive(self, shell):
        """
        Test do_errata_delete without errata (non-interactive mode).

        :param shell:
        :return:
        """
        shell.help_errata_delete = MagicMock()
        shell.expand_errata = MagicMock(return_value=["CVE-1", "CVE-2"])
        shell.user_confirm = MagicMock()
        shell.client.errata.applicableToChannels = MagicMock(side_effect=[
            ["base_channel", "special_channel"],
            ["vim_users_channel"],
        ])
        shell.client.errata.delete = MagicMock()
        shell.generate_errata_cache = MagicMock()
        shell.options.yes = True
        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.errata.print", mprint) as prt, \
                patch("spacecmd.errata.logging", logger) as lgr:
            spacecmd.errata.do_errata_delete(shell, "CVE-X")

        assert not shell.help_errata_delete.called
        assert not logger.warning.called
        assert not shell.user_confirm.called
        assert shell.client.errata.applicableToChannels.called
        assert shell.client.errata.delete.called
        assert shell.generate_errata_cache.called
        assert mprint.called
        assert logger.info.called
        assert shell.expand_errata.called

        assert_list_args_expect(mprint.call_args_list, [
            'Erratum            Channels', '-------            --------',
            'CVE-1                     2', 'CVE-2                     1'
        ])
        assert_list_args_expect(logger.info.call_args_list,
                                ['Deleted 2 patches'])
        assert_args_expect(shell.client.errata.delete.call_args_list, [((
            shell.session,
            "CVE-1",
        ), {}), ((
            shell.session,
            "CVE-2",
        ), {})])
コード例 #21
0
ファイル: test_errata.py プロジェクト: uyuni-project/uyuni
    def test_errata_apply_non_interactive_affects_no_system(self, shell):
        """
        Test do_errata_apply non-interactive, no systems affected.

        :param shell:
        :return:
        """
        shell.help_errata_apply = MagicMock()
        shell.user_confirm = MagicMock()
        shell.check_api_version = MagicMock()
        shell.get_system_id = MagicMock()
        shell.expand_errata = MagicMock(
            return_value=["cve-one", "cve-two", "cve-three"])
        shell.client.errata.listAffectedSystems = MagicMock(return_value=[])
        shell.client.system.getUnscheduledErrata = MagicMock()
        shell.client.system.scheduleApplyErrata = MagicMock()
        shell.all_errata = {}
        shell.options = MagicMock()
        shell.options.yes = True
        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.errata.print", mprint) as prt, \
                patch("spacecmd.errata.logging", logger) as lgr:
            spacecmd.errata.do_errata_apply(shell, "cve* -s 201901011030")

        assert not shell.help_errata_apply.called
        assert not shell.user_confirm.called
        assert not shell.check_api_version.called
        assert not shell.get_system_id.called
        assert not shell.client.system.getUnscheduledErrata.called
        assert not shell.client.system.scheduleApplyErrata.called
        assert not mprint.called
        assert shell.client.errata.listAffectedSystems.called
        assert shell.expand_errata.called
        assert logger.warning.called
        assert logger.debug.called

        assert_list_args_expect(logger.debug.call_args_list, [
            'cve-one does not affect any systems',
            'cve-two does not affect any systems',
            'cve-three does not affect any systems'
        ])
        assert_expect(logger.warning.call_args_list, "No patches to apply")
コード例 #22
0
    def test_do_system_event_details_noevent(self, shell):
        """
        Test do_system_event_details with no event
        """

        shell.help_system_eventdetails = MagicMock()
        shell.client.system.getEventDetails = MagicMock()

        m_logger = MagicMock()

        with patch("spacecmd.system.logging", m_logger):
            spacecmd.system.do_system_eventdetails(shell, "123456789")

        assert m_logger.warning.called
        assert_list_args_expect(m_logger.warning.call_args_list,
                                ['No event specified'])

        assert not shell.help_system_eventdetails.called
        assert not shell.client.system.getEventDetails.called
コード例 #23
0
ファイル: test_org.py プロジェクト: vzhestkov/uyuni
    def test_org_details(self, shell):
        """
        Test do_org_details output.

        :param shell:
        :return:
        """
        shell.help_org_details = MagicMock()
        shell.client.org.getDetails = MagicMock(
            return_value={
                "name": "Test Organisation",
                "active_users": 42,
                "systems": 5,
                "trusts": 1,
                "system_groups": 6,
                "activation_keys": 2,
                "kickstart_profiles": 7,
                "configuration_channels": 1
            })

        logger = MagicMock()
        mprint = MagicMock()
        with patch("spacecmd.org.print", mprint) as prn, \
            patch("spacecmd.org.logging", logger) as lgr:
            spacecmd.org.do_org_details(shell, "testorg")

        assert not logger.warning.called
        assert not shell.help_org_details.called
        assert mprint.called
        assert shell.client.org.getDetails.called

        exp = [
            'Name:                   Test Organisation',
            'Active Users:           42',
            'Systems:                5',
            'Trusts:                 1',
            'System Groups:          6',
            'Activation Keys:        2',
            'Kickstart Profiles:     7',
            'Configuration Channels: 1',
        ]
        assert_list_args_expect(mprint.call_args_list, exp)
コード例 #24
0
ファイル: test_org.py プロジェクト: vzhestkov/uyuni
    def test_org_listtrusts(self, shell):
        """
        Test do_org_listtrusts output.

        :param shell:
        :return:
        """
        shell.help_org_listtrusts = MagicMock()
        shell.get_org_id = MagicMock(return_value=1)
        shell.client.org.trusts.listTrusts = MagicMock(return_value=[
            {
                "orgName": "suse",
                "trustEnabled": True
            },
            {
                "orgName": "west",
                "trustEnabled": True
            },
            {
                "orgName": "acme",
                "trustEnabled": True
            },
            {
                "orgName": "ubuntu",
                "trustEnabled": False
            },
        ])

        logger = MagicMock()
        mprint = MagicMock()
        with patch("spacecmd.org.print", mprint) as prn, \
            patch("spacecmd.org.logging", logger) as lgr:
            spacecmd.org.do_org_listtrusts(shell, "notfound")

        assert not logger.warning.called
        assert not shell.help_org_listtrusts.called
        assert shell.client.org.trusts.listTrusts.called
        assert shell.get_org_id.called
        assert mprint.called

        assert_list_args_expect(mprint.call_args_list,
                                ["acme", "suse", "west"])
コード例 #25
0
def test_listlatestpackages_channel_packages(shell):
    """
    Test do_softwarechannel_listlatestpackages with channel supplied.

    :return:
    """
    shell.client.channel.software.listAllPackages = MagicMock(return_value=[
        {
            "name": "emacs",
            "version": "42.0",
            "release": "9",
            "epoch": "",
            "arch": "x86_64"
        },
        {
            "name": "emacs-nox",
            "version": "42.0",
            "release": "10",
            "epoch": "",
            "arch_label": "x86_64"
        },
        {
            "name": "tiff",
            "version": "1.0",
            "release": "11",
            "epoch": "3",
            "arch": "amd64"
        },
    ])
    mprint = MagicMock()
    with patch("spacecmd.softwarechannel.print", mprint):
        out = spacecmd.softwarechannel.do_softwarechannel_listlatestpackages(
            shell, "some_channel")

    assert out is None
    assert not shell.help_softwarechannel_listlatestpackages.called
    assert shell.client.channel.software.listAllPackages.called

    assert_list_args_expect(mprint.call_args_list, [
        'emacs-42.0-9.x86_64\nemacs-nox-42.0-10.x86_64\ntiff-1.0-11:3.x86_64'
    ])
コード例 #26
0
ファイル: test_user.py プロジェクト: vzhestkov/uyuni
    def test_user_details_invalid_users(self, shell):
        """
        Test do_user_details with invalid/not-found users.

        :param shell:
        :return:
        """
        shell.help_user_details = MagicMock()
        shell.client.user.getDetails = MagicMock(side_effect=xmlrpclib.Fault(
            faultCode=42, faultString="User caused disks spinning backwards"))
        shell.client.user.listRoles = MagicMock()
        shell.client.user.listAssignedSystemGroups = MagicMock()
        shell.client.user.listDefaultSystemGroups = MagicMock()
        shell.client.org.getDetails = MagicMock()
        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.user.print", mprint) as prt, \
                patch("spacecmd.user.logging", logger) as lgr:
            spacecmd.user.do_user_details(shell, "hairypointed othermissing")

        assert not shell.client.user.listRoles.called
        assert not shell.client.user.listAssignedSystemGroups.called
        assert not shell.client.user.listDefaultSystemGroups.called
        assert not shell.client.org.getDetails.called
        assert not shell.help_user_details.called
        assert not mprint.called
        assert logger.warning.called
        assert logger.debug.called
        assert shell.client.user.getDetails.called

        assert_list_args_expect(logger.warning.call_args_list, [
            "hairypointed is not a valid user",
            "othermissing is not a valid user"
        ])
        assert_list_args_expect(logger.debug.call_args_list, [
            "Error '42' while getting data about user "
            "'hairypointed': User caused disks spinning backwards",
            "Error '42' while getting data about user "
            "'othermissing': User caused disks spinning backwards"
        ])
コード例 #27
0
    def test_do_system_event_details_old_version(self, shell):
        """
        Test do_system_event_details when using an old version of the API
         """

        shell.help_system_eventdetails = MagicMock()
        shell.client.system.getEventDetails = MagicMock()
        shell.check_api_version = MagicMock(return_value=None)

        m_logger = MagicMock()

        with patch("spacecmd.system.logging", m_logger):
            spacecmd.system.do_system_eventdetails(shell, "123456789")

        assert m_logger.warning.called
        assert_list_args_expect(
            m_logger.warning.call_args_list,
            ["This version of the API doesn't support this method"])

        assert not shell.help_system_eventdetails.called
        assert not shell.client.system.getEventDetails.called
コード例 #28
0
def test_softwarechannel_list_noreturn_labels_verbose_tree(shell):
    """
    Test do_softwarechannel_list with label, no return data, verbose output with tree.

    :param shell:
    :return:
    """
    shell.client.channel.listAllChannels = MagicMock(return_value=[
        {
            "any_channel": "any_channel"
        },
    ])
    shell.client.channel.software.getDetails = MagicMock(side_effect=[
        {
            "summary": "Summary of test_channel"
        },
        {
            "summary": "Summary of child_channel"
        },
    ])
    shell.list_child_channels = MagicMock(return_value=["child_channel"])

    shell.list_base_channels = MagicMock(return_value=["base_channel"])

    mprint = MagicMock()
    with patch("spacecmd.softwarechannel.print", mprint):
        out = spacecmd.softwarechannel.do_softwarechannel_list(shell,
                                                               "-v -t",
                                                               doreturn=False)

    assert out is None
    assert not shell.client.channel.listAllChannels.called
    assert not shell.help_softwarechannel_list.called
    assert shell.list_child_channels.called
    assert shell.client.channel.software.getDetails.called

    assert_list_args_expect(mprint.call_args_list, [
        'base_channel : Summary of test_channel',
        ' |-child_channel : Summary of child_channel'
    ])
コード例 #29
0
    def test_kickstart_listscripts_scripts_found(self, shell):
        """
        Test do_kickstart_listscripts list scripts for the specified profile.

        :param shell:
        :return:
        """
        mprint = MagicMock()
        logger = MagicMock()
        shell.client.kickstart.profile.listScripts = MagicMock(
            return_value=[
                {"id": 1, "script_type": "shell",
                 "chroot": "/dev/null", "interpreter": "/bin/bash",
                 "contents": """#!/bin/bash
echo 'Hello there!'
                 """},
                {"id": 2, "script_type": "shell",
                 "chroot": "/dev/null", "interpreter": "/bin/bash",
                 "contents": """#!/bin/bash
echo 'some more hello'
                 """
                 },
            ])
        with patch("spacecmd.kickstart.print", mprint) as prt, \
                patch("spacecmd.kickstart.logging", logger) as lgr:
            spacecmd.kickstart.do_kickstart_listscripts(shell, "some_profile")

        assert not shell.help_kickstart_listscripts.called
        assert not logger.error.called
        assert mprint.called
        assert shell.client.kickstart.profile.listScripts.called

        assert_list_args_expect(mprint.call_args_list,
                                ['ID:          1', 'Type:        shell',
                                 'Chroot:      /dev/null', 'Interpreter: /bin/bash', '',
                                 'Contents', '--------', "#!/bin/bash\necho 'Hello there!'\n                 ",
                                 '----------', 'ID:          2', 'Type:        shell',
                                 'Chroot:      /dev/null', 'Interpreter: /bin/bash', '',
                                 'Contents', '--------', "#!/bin/bash\necho 'some more hello'\n                 "]
                                )
コード例 #30
0
    def test_schedule_reschedule_failed_actions(self, shell):
        """
        Test do_schedule_reschedule with failed actions.

        :param shell:
        :return:
        """

        shell.help_schedule_reschedule = MagicMock()
        shell.client.schedule.listFailedActions = MagicMock(
            return_value=[{
                "id": 1
            }, {
                "id": 2
            }, {
                "id": 3
            }, {
                "id": 4
            }])
        shell.client.schedule.rescheduleActions = MagicMock()
        shell.user_confirm = MagicMock(return_value=False)
        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.schedule.print", mprint) as prt, \
                patch("spacecmd.schedule.logging", logger) as lgr:
            spacecmd.schedule.do_schedule_reschedule(shell, "one 2 3, 5 and 4")

        assert not shell.help_schedule_reschedule.called
        assert not shell.user_confirm.called
        assert shell.client.schedule.rescheduleActions.called
        assert mprint.called
        assert logger.warning.called
        assert shell.client.schedule.listFailedActions.called

        assert_expect(mprint.call_args_list, "Rescheduled 2 action(s)")
        assert_list_args_expect(logger.warning.call_args_list, [
            '"one" is not a valid ID', '"3," is not a valid ID',
            '"5" is not a failed action', '"and" is not a valid ID'
        ])