Beispiel #1
0
    def test_kickstart_listcryptokeys_cryptokeys_to_stdout(self, shell):
        """
        Test do_kickstart_listcryptokeys cryptokeys to stdout.

        :param shell:
        :return:
        """
        shell.client.kickstart.profile.system.listKeys = MagicMock(return_value=[
            {"description": "c_key"},
            {"description": "b_key"},
            {"description": "a_key"},
            {"description": "z_key"},
            {"description": "x_key"},
        ])
        mprint = MagicMock()
        with patch("spacecmd.kickstart.print", mprint) as prt:
            data = spacecmd.kickstart.do_kickstart_listcryptokeys(shell, "some_profile")

        assert not shell.help_kickstart_listcryptokeys.called
        assert mprint.called
        assert data is None
        assert shell.client.kickstart.profile.system.listKeys.called

        assert_expect(mprint.call_args_list,
                      'a_key\nb_key\nc_key\nx_key\nz_key')
Beispiel #2
0
    def test_errata_publish_no_interactive(self, shell):
        """
        Test do_errata_publish publish to channel without interactive mode

        :param shell:
        :return:
        """
        shell.help_errata_publish = MagicMock()
        shell.expand_errata = MagicMock(return_value=["one", "two", "three"])
        shell.user_confirm = MagicMock()
        shell.client.errata.publish = 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_publish(shell, "CVE-1 base_channel")

        assert not logger.warning.called
        assert not shell.help_errata_publish.called
        assert not shell.user_confirm.called
        assert shell.client.errata.publish.called
        assert mprint.called
        assert shell.expand_errata.called
        assert_expect(mprint.call_args_list, 'one\nthree\ntwo')
        assert_args_expect(shell.client.errata.publish.call_args_list,
                           [((shell.session, 'one', ['base_channel']), {}),
                            ((shell.session, 'two', ['base_channel']), {}),
                            ((shell.session, 'three', ['base_channel']), {})])
Beispiel #3
0
    def test_cryptokey_details_rpc_error(self, shell):
        """
        Test do_cryptokey_details captures xmlrpc failure.

        :param shell:
        :return:
        """
        shell.client.kickstart.keys.getDetails = MagicMock(
            side_effect=xmlrpclib.Fault(faultCode=42, faultString="Kaboom")
        )
        shell.do_cryptokey_list = MagicMock(return_value=["somekey"])
        shell.help_cryptokey_details = MagicMock()
        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.cryptokey.print", mprint) as mpt, \
            patch("spacecmd.cryptokey.logging", logger) as lgr:
            spacecmd.cryptokey.do_cryptokey_details(shell, "somekey")

        assert not mprint.called
        assert not shell.help_cryptokey_details.called
        assert not logger.error.called
        assert shell.client.kickstart.keys.getDetails.called
        assert shell.do_cryptokey_list.called
        assert logger.warning.called

        assert_expect(logger.warning.call_args_list, "somekey is not a valid crypto key")
Beispiel #4
0
    def test_org_listusers_no_org(self, shell):
        """
        Test do_org_listusers where org was not found.

        :param shell:
        :return:
        """
        shell.help_org_listusers = MagicMock()
        shell.client.org.listUsers = MagicMock()
        shell.get_org_id = MagicMock(return_value=None)
        logger = MagicMock()
        mprint = MagicMock()
        with patch("spacecmd.org.print", mprint) as prn, \
            patch("spacecmd.org.logging", logger) as lgr:
            spacecmd.org.do_org_listusers(shell, "foo")

        assert not shell.client.org.listUsers.called
        assert not shell.help_org_listusers.called
        assert shell.get_org_id.called
        assert mprint.called
        assert logger.warning.called
        assert_expect(mprint.call_args_list,
                      "Organisation 'foo' was not found")
        assert_args_expect(
            logger.warning.call_args_list,
            [(('No organisation found for the name %s', 'foo'), {})])
Beispiel #5
0
    def test_org_delete_no_org_found(self, shell):
        """
        Test do_org_delete org not found (None).

            :param self:
            :param shell:
        """
        shell.help_org_delete = MagicMock()
        shell.get_org_id = MagicMock(return_value=None)
        shell.client.org.delete = MagicMock()

        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.org.print", mprint) as prn, \
            patch("spacecmd.org.logging", logger) as lgr:
            spacecmd.org.do_org_delete(shell, "ACME-Enterprises")

        assert not shell.client.org.delete.called
        assert not shell.help_org_delete.called
        assert shell.get_org_id.called
        assert logger.warning.called
        assert mprint.called

        assert_expect(mprint.call_args_list,
                      "Organisation 'ACME-Enterprises' was not found")
        expectations = [('No organisation found for the name %s',
                         'ACME-Enterprises')]
        for call in logger.warning.call_args_list:
            args, kw = call
            assert args == next(iter(expectations))
            expectations.pop(0)
        assert not expectations
Beispiel #6
0
    def test_org_removetrust_no_dst(self, shell):
        """
        Test for do_org_removetrust destination org not found.

        :param shell:
        :return:
        """
        shell.help_org_removetrust = MagicMock()
        shell.get_org_id = MagicMock(side_effect=[0, None])
        shell.client.org.trusts.listSystemsAffected = MagicMock()

        logger = MagicMock()
        mprint = MagicMock()
        with patch("spacecmd.org.print", mprint) as prn, \
            patch("spacecmd.org.logging", logger) as lgr:
            spacecmd.org.do_org_removetrust(shell, "trust bad-guys")

        assert not shell.client.org.trusts.removeTrust.called
        assert not shell.help_org_removetrust.called
        assert shell.get_org_id.called
        assert logger.warning.called
        assert mprint.called

        assert_expect(mprint.call_args_list,
                      "Organisation 'bad-guys' to trust for, was not found")
        assert_args_expect(logger.warning.call_args_list, [
            (('No trust organisation found for the name %s', 'bad-guys'), {})
        ])
Beispiel #7
0
    def test_org_list_noret(self, shell):
        """
        Test do_org_list no data return.

        :param shell:
        :return:
        """
        shell.client.org.listOrgs = MagicMock(return_value=[
            {
                "name": "suse"
            },
            {
                "name": "rh"
            },
            {
                "name": "other"
            },
        ])
        mprint = MagicMock()
        with patch("spacecmd.org.print", mprint):
            out = spacecmd.org.do_org_list(shell, "", doreturn=False)

        assert out is None
        assert mprint.called
        assert_expect(mprint.call_args_list, 'other\nrh\nsuse')
Beispiel #8
0
    def test_package_remove_specific_pkg_aborted(self, shell):
        """
        Test do_package_remove with unconfirmed valid packages.

            :param shell:
        """
        shell.help_package_remove = MagicMock()
        shell.get_package_names = MagicMock(return_value=[
            "vim", "vim-plugins", "vim-data", "gvim", "gvim-ext", "pico",
            "pico-data", "emacs", "emacs-nox", "xemacs"
        ])
        shell.get_package_id = MagicMock()
        shell.client.packages.removePackage = MagicMock()
        shell.generate_package_cache = MagicMock()
        shell.user_confirm = MagicMock(return_value=False)
        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.package.print", mprint) as prn, \
            patch("spacecmd.package.logging", logger) as lgr:
            spacecmd.package.do_package_remove(shell, "vim* gvim pico")

        assert not shell.get_package_id.called
        assert not shell.client.packages.removePackage.called
        assert not shell.generate_package_cache.called
        assert not shell.help_package_remove.called
        assert not logger.debug.called
        assert shell.user_confirm.called
        assert shell.get_package_names.called
        assert mprint.called

        assert_expect(mprint.call_args_list, "No packages has been removed")
Beispiel #9
0
    def test_package_listinstallsystems_package_not_found(self, shell):
        """
        Test do_package_listinstallsystems with not found package

            :param self:
            :param shell:
        """
        shell.help_package_listinstalledsystems = MagicMock()
        shell.do_package_search = MagicMock(return_value=[])
        shell.get_package_id = MagicMock()
        shell.client.system.listSystemsWithPackage = MagicMock()
        shell.SEPARATOR = "-" * 10

        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.package.print", mprint) as prn, \
            patch("spacecmd.package.logging", logger) as lgr:
            spacecmd.package.do_package_listinstalledsystems(
                shell, "darth-vader")

        assert not shell.get_package_id.called
        assert not shell.client.system.listSystemsWithPackage.called
        assert not shell.help_package_listinstalledsystems.called
        assert not mprint.called
        assert logger.warning.called
        assert shell.do_package_search.called

        assert_expect(logger.warning.call_args_list, "No packages found")
Beispiel #10
0
    def test_package_search(self, shell):
        """
        Test do_package_search with arguments of standard fields
        """
        shell.help_package_search = MagicMock()
        shell.get_package_names = MagicMock(return_value=[
            "emacs-x11", "emacs-melpa", "emacs-nox", "vim", "pico", "gedit",
            "sed"
        ])
        shell.client.packages.search.advanced = MagicMock()

        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.package.print", mprint) as prn, \
            patch("spacecmd.package.logging", logger) as lgr:
            out = spacecmd.package.do_package_search(shell,
                                                     "emacs*",
                                                     doreturn=False)

        assert not shell.help_package_search.called
        assert not logger.debug.called
        assert not shell.client.packages.search.advanced.called
        assert out is None
        assert mprint.called
        assert_expect(mprint.call_args_list,
                      'emacs-melpa\nemacs-nox\nemacs-x11')
Beispiel #11
0
    def test_package_remove_no_pkg_found(self, shell):
        """
        Test do_package_remove with no valid packages (packages not found).

            :param shell:
        """
        shell.help_package_remove = MagicMock()
        shell.get_package_names = MagicMock(return_value=[])
        shell.get_package_id = MagicMock()
        shell.client.packages.removePackage = MagicMock()
        shell.generate_package_cache = MagicMock()
        shell.user_configm = MagicMock(return_value=True)
        mprint = MagicMock()
        logger = MagicMock()
        with patch("spacecmd.package.print", mprint) as prn, \
            patch("spacecmd.package.logging", logger) as lgr:
            spacecmd.package.do_package_remove(shell, "i-do-not-exist")

        assert not shell.get_package_id.called
        assert not shell.client.packages.removePackage.called
        assert not shell.generate_package_cache.called
        assert not shell.user_configm.called
        assert not shell.help_package_remove.called
        assert shell.get_package_names.called
        assert logger.debug.called
        assert mprint.called

        assert_expect(mprint.call_args_list, "No packages found to remove")
Beispiel #12
0
    def test_group_listsystems_nodata(self, shell):
        """
        Test do_group_listsystems without data return, but STDOUT.

        :param shell:
        :return:
        """
        shell.help_group_listsystems = MagicMock()
        shell.client.systemgroup.listSystems = MagicMock(return_value=[
            {"profile_name": "system-d"}, {"profile_name": "system-c"},
            {"profile_name": "system-b"}, {"profile_name": "system-a"},
        ])
        mprint = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.group.print", mprint) as prt, \
            patch("spacecmd.group.logging", logger) as lgr:
            out = spacecmd.group.do_group_listsystems(shell, "group-a", doreturn=False)

        assert not shell.help_group_listsystems.called
        assert not logger.warning.called
        assert shell.client.systemgroup.listSystems.called
        assert out is None
        assert mprint.called
        assert_expect(mprint.call_args_list, "system-a\nsystem-b\nsystem-c\nsystem-d")
Beispiel #13
0
    def test_group_removesystems_nossm_nosys(self, shell):
        """
        Test do_group_removesystems with filters and without 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=[])
        shell.client.systemgroup.addOrRemoveSystems = MagicMock()
        shell.ssm.keys = MagicMock()
        shell.user_confirm = MagicMock()
        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 shell.get_system_id.called
        assert not shell.client.systemgroup.addOrRemoveSystems.called
        assert not shell.user_confirm.called
        assert not logger.error.called
        assert not shell.help_group_removesystems.called
        assert not shell.ssm.keys.called
        assert mprint.called
        assert shell.expand_systems.called

        assert_expect(mprint.call_args_list, "No systems found")
Beispiel #14
0
    def test_group_details_no_valid_group(self, shell):
        """
        Test do_group_details with no arguments.

        :param shell:
        :return:
        """
        shell.help_group_details = MagicMock()
        shell.client.systemgroup.getDetails = MagicMock(
            side_effect=xmlrpclib.Fault(faultCode=42, faultString="kaboom!"))
        shell.client.systemgroup.listSystems = MagicMock()

        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, "cucumber-group")

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

        assert_expect(logger.warning.call_args_list,
                      'The group "cucumber-group" is invalid')
Beispiel #15
0
    def test_schedule_getoutput_invalid_action_id(self, shell):
        """
        Test do_schedule_getoutput with an invalid action ID.

        :param shell:
        :return:
        """
        shell.client.schedule.listCompletedSystems = MagicMock()
        shell.client.system.getScriptResults = MagicMock()
        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, "fortytwo")

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

        assert logger.error.called

        assert_expect(logger.error.call_args_list,
                      '"fortytwo" is not a valid action ID')
Beispiel #16
0
    def test_package_listerrata_not_found_packages(self, shell):
        """
        Test do_package_listerrata with invalid package names.

            :param shell:
            :param args:
        """
        shell.do_package_search = MagicMock(return_value=[])
        shell.client.packages.listProvidingErrata = MagicMock()
        shell.get_package_id = MagicMock()
        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, "iron-man")

        assert not shell.help_package_listerrata.called
        assert not shell.client.packages.listProvidingErrata.called
        assert not shell.get_package_id.called
        assert not mprint.called
        assert logger.warning.called
        assert shell.do_package_search.called
        assert_expect(logger.warning.call_args_list, "No packages found")
Beispiel #17
0
    def test_org_addtrust_no_src_org(self, shell):
        """
        Test do_org_addtrust, source org not found

        :param shell:
        :return:
        """
        shell.help_org_addtrust = MagicMock()
        shell.get_org_id = MagicMock(side_effect=[None, 0])
        shell.client.org.trusts.addTrust = MagicMock()

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

        assert not shell.client.org.trusts.addTrust.called
        assert not shell.help_org_addtrust.called
        assert shell.get_org_id.called
        assert mprint.called
        assert logger.warning.called
        assert_expect(mprint.call_args_list,
                      "Organisation 'trust' was not found")
        assert_args_expect(logger.warning.call_args_list, [((
            'No organisation found for the name %s',
            'trust',
        ), {})])
Beispiel #18
0
    def test_package_listdependencies_no_packages_found(self, shell):
        """
        Test do_packge_listdependencies no packages found.
            :param self:
            :param shell:
        """
        shell.do_package_search = MagicMock(return_value=[])
        shell.help_package_listdependencies = MagicMock()
        shell.get_package_id = MagicMock()
        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, "thor")

        assert not shell.get_package_id.called
        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_expect(logger.warning.call_args_list, "No packages found")
Beispiel #19
0
    def test_org_trustdetails_no_org_found(self, shell):
        """
        Test for do_org_trustdetails no org found.

        :param shell:
        :return:
        """
        shell.help_org_trustdetails = MagicMock()
        shell.get_org_id = MagicMock(return_value=None)
        shell.client.org.trusts.getDetails = MagicMock()
        shell.client.org.trusts.listChannelsConsumed = MagicMock()
        shell.client.org.trusts.listChannelsProvided = MagicMock()

        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, "notfound")

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

        assert_expect(mprint.call_args_list,
                      "Trusted organisation 'notfound' was not found")
        assert_args_expect(logger.warning.call_args_list, [
            (('No trusted organisation found for the name %s', 'notfound'), {})
        ])
Beispiel #20
0
    def test_distribution_delete_args_no_match(self, shell):
        """
        Test do_distribution_delete with wrong arguments.

        :param shell:
        :return:
        """
        shell.do_distribution_list = MagicMock(return_value=["bar"])
        shell.help_distribution_delete = MagicMock()
        shell.client.kickstart.tree.delete = MagicMock()
        shell.user_confirm = MagicMock()
        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.distribution.print", mprint) as prn, \
                patch("spacecmd.distribution.logging", logger) as lgr:
            spacecmd.distribution.do_distribution_delete(shell, "foo*")

        assert logger.debug.called
        assert logger.error.called
        assert not mprint.called
        assert not shell.client.kickstart.tree.delete.called
        assert not shell.user_confirm.called
        assert not shell.help_distribution_delete.called

        assert_expect(logger.debug.call_args_list,
                      "distribution_delete called with args ['foo.*'], dists=[]")
        assert_expect(logger.error.call_args_list,
                      "No distributions matched argument ['foo.*']")
Beispiel #21
0
    def test_org_listtrusts_no_trusts(self, shell):
        """
        Test do_org_listtrusts trust orgs were not found.

        :param shell:
        :return:
        """
        shell.help_org_listtrusts = MagicMock()
        shell.get_org_id = MagicMock(return_value=1)
        shell.client.org.trusts.listTrusts = MagicMock(return_value=[])

        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 shell.help_org_listtrusts.called
        assert shell.client.org.trusts.listTrusts.called
        assert shell.get_org_id.called
        assert mprint.called
        assert logger.warning.called

        assert_expect(mprint.call_args_list,
                      "No trust organisation has been found")
        assert_expect(logger.warning.call_args_list,
                      "No trust organisation has been found")
Beispiel #22
0
    def test_distribution_details_no_dists(self, shell):
        """
        Test do_distribution_details with no distributions found.

        :param shell:
        :return:
        """
        shell.help_distribution_details = MagicMock()
        shell.client.kickstart.tree.getDetails = MagicMock()
        shell.client.channel.software.getDetails = MagicMock()
        shell.do_distribution_list = MagicMock(return_value=[])
        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.distribution.print", mprint) as prn, \
                patch("spacecmd.distribution.logging", logger) as lgr:
            spacecmd.distribution.do_distribution_details(shell, "test*")

        assert not shell.client.kickstart.tree.getDetails.called
        assert not shell.client.channel.software.getDetails.called
        assert not shell.help_distribution_details.called
        assert not mprint.called
        assert logger.debug.called
        assert logger.error.called
        assert shell.do_distribution_list.called

        assert_expect(logger.debug.call_args_list,
                      "distribution_details called with args ['test.*'], dists=[]")
        assert_expect(logger.error.call_args_list,
                      "No distributions matched argument ['test.*']")
Beispiel #23
0
    def test_org_listusers(self, shell):
        """
        Test do_org_listusers output

        :param shell:
        :return:
        """
        shell.help_org_listusers = MagicMock()
        shell.client.org.listUsers = MagicMock(
            return_value=[{
                "login": "******"
            }, {
                "login": "******"
            }])
        shell.get_org_id = MagicMock(return_value=1)
        logger = MagicMock()
        mprint = MagicMock()
        with patch("spacecmd.org.print", mprint) as prn, \
            patch("spacecmd.org.logging", logger) as lgr:
            spacecmd.org.do_org_listusers(shell, "suse")

        assert not shell.help_org_listusers.called
        assert not logger.warning.called
        assert shell.client.org.listUsers.called
        assert shell.get_org_id.called
        assert mprint.called
        assert_expect(mprint.call_args_list, 'gunnuhver\nolafur')
Beispiel #24
0
    def test_distribution_create_args_ds_update_mode(self, shell):
        """
        Test do_distribution_create with distribution name in update mode.

        :param shell:
        :return:
        """
        shell.client.kickstart.tree.listInstallTypes = MagicMock(return_value=[
            {"label": "image"},
        ])
        shell.client.kickstart.tree.update = MagicMock()
        shell.client.kickstart.tree.create = MagicMock()
        shell.list_base_channels = MagicMock(return_value=["base-channel"])

        mprint = MagicMock()
        prompt = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.distribution.print", mprint) as prn, \
            patch("spacecmd.distribution.prompt_user", prompt) as prmt, \
            patch("spacecmd.distribution.logging", logger) as lgr:
            spacecmd.distribution.do_distribution_create(shell, "-n myname", update=True)

        assert not mprint.called
        assert not prompt.called
        assert not shell.client.kickstart.tree.listInstallTypes.called
        assert not shell.client.kickstart.tree.create.called
        assert not shell.client.kickstart.tree.update.called
        assert logger.error.called

        assert_expect(logger.error.call_args_list, "A path is required")
Beispiel #25
0
    def test_errata_delete_no_errata(self, shell):
        """
        Test do_errata_delete without errata.

        :param shell:
        :return:
        """
        shell.help_errata_delete = MagicMock()
        shell.expand_errata = MagicMock(return_value=[])
        shell.user_confirm = MagicMock()
        shell.client.errata.applicableToChannels = MagicMock()
        shell.client.errata.delete = MagicMock()
        shell.generate_errata_cache = MagicMock()
        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.user_confirm.called
        assert not shell.client.errata.applicableToChannels.called
        assert not shell.client.errata.delete.called
        assert not shell.generate_errata_cache.called
        assert not mprint.called
        assert not logger.info.called
        assert not shell.help_errata_delete.called
        assert logger.warning.called
        assert shell.expand_errata.called

        assert_expect(logger.warning.call_args_list,
                      "No patches to delete")
Beispiel #26
0
    def test_schedule_details_invalid_action_id(self, shell):
        """
        Test do_schedule_details with invalid action ID.

        :param shell:
        :return:
        """
        shell.client.schedule.listCompletedSystems = MagicMock()
        shell.client.schedule.listFailedSystems = MagicMock()
        shell.client.schedule.listInProgressSystems = MagicMock()
        shell.client.schedule.listAllActions = MagicMock()

        shell.help_schedule_details = MagicMock()

        mprint = MagicMock()
        logger = MagicMock()

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

        assert not shell.client.schedule.listCompletedSystems.called
        assert not shell.client.schedule.listFailedSystems.called
        assert not shell.client.schedule.listInProgressSystems.called
        assert not shell.client.schedule.listAllActions.called

        assert not mprint.called
        assert logger.warning.called
        assert not shell.help_schedule_details.called

        assert_expect(logger.warning.call_args_list,
                      'The ID "something" is invalid')
Beispiel #27
0
    def test_cryptokey_delete_confirmed_deleted(self, shell):
        """
        Test do_cryptokey_delete with non-existing key.

        :return:
        """
        shell.help_cryptokey_delete = MagicMock()
        shell.client.kickstart.keys.delete = MagicMock()
        shell.user_confirm = MagicMock(return_value=True)
        shell.do_cryptokey_list = MagicMock(return_value=["one", "two", "three"])
        logger = MagicMock()
        mprint = MagicMock()

        with patch("spacecmd.cryptokey.logging", logger) as lgr, \
            patch("spacecmd.cryptokey.print", mprint) as prn:
            spacecmd.cryptokey.do_cryptokey_delete(shell, "t*")

        assert not logger.error.called
        assert not shell.help_cryptokey_delete.called
        assert shell.client.kickstart.keys.delete.called
        assert shell.user_confirm.called
        assert mprint.called

        assert_expect(mprint.call_args_list, 'three\ntwo')
        exp = [
            (shell.session, "two",),
            (shell.session, "three",),
        ]

        for call in shell.client.kickstart.keys.delete.call_args_list:
            args, kw = call
            assert not kw
            assert args == next(iter(exp))
            exp.pop(0)
        assert not exp
Beispiel #28
0
    def test_schedule_cancel_globbing(self, shell):
        """
        Test do_schedule_cancel with globbing.

        :param shell:
        :return:
        """

        shell.help_schedule_cancel = MagicMock()
        shell.client.schedule.listInProgressActions = MagicMock()
        shell.client.schedule.cancelActions = 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_cancel(shell, "*")

        assert not shell.client.schedule.listInProgressActions.called
        assert not shell.client.schedule.cancelActions.called
        assert not mprint.called
        assert not logger.warning.called
        assert not shell.help_schedule_cancel.called
        assert shell.user_confirm.called
        assert logger.info.called

        assert_expect(logger.info.call_args_list,
                      "All pending actions left untouched")
Beispiel #29
0
    def test_cryptokey_create_interactive_wrong_key_type(self, shell):
        """
        Test do_cryptokey_create without arguments (interactive, wrong key type).

        :param shell:
        :return:
        """
        shell.help_cryptokey_create = MagicMock()
        shell.client.kickstart.keys.create = MagicMock()
        shell.user_confirm = MagicMock(return_value=True)
        read_file = MagicMock(return_value="contents")
        prompt_user = MagicMock(side_effect=["x", "interactive descr", "/tmp/file.txt"])
        editor = MagicMock()
        logger = MagicMock()

        with patch("spacecmd.cryptokey.prompt_user", prompt_user) as pmu, \
            patch("spacecmd.cryptokey.read_file", read_file) as rfl, \
            patch("spacecmd.cryptokey.editor", editor) as edt, \
            patch("spacecmd.cryptokey.logging", logger) as lgr:
            spacecmd.cryptokey.do_cryptokey_create(shell, "")

        assert not shell.help_cryptokey_create.called
        assert not shell.client.kickstart.keys.create.called
        assert not editor.called
        assert read_file.called
        assert prompt_user.called
        assert logger.error.called

        assert_expect(logger.error.call_args_list, "Invalid key type")
Beispiel #30
0
    def test_kickstart_delete_some_invalid_profile(self, shell):
        """
        Test do_kickstart_delete invalid profile (not found).

        :param shell:
        :return:
        """
        shell.do_kickstart_list = MagicMock(return_value=[
            "first_profile", "second_profile", "third_profile"
        ])
        logger = MagicMock()
        with patch("spacecmd.kickstart.logging", logger) as lgr:
            spacecmd.kickstart.do_kickstart_delete(
                shell, "fourth_profile zero_profile first_profile second_profile")

        assert not shell.client.kickstart.deleteProfile.called
        assert not shell.help_kickstart_delete.called
        assert logger.error.called
        assert shell.do_kickstart_list.called
        assert logger.debug.called

        assert_expect(logger.debug.call_args_list,
                      "Got labels to delete of ['first_profile', 'second_profile']")
        assert_args_expect(logger.error.call_args_list,
                           [(('The following kickstart labels are invalid:',
                              'fourth_profile, zero_profile'), {})])