Exemple #1
0
    def test_run_bad_config(self):
        """
        Test the run() function with a bad config.
        """
        command = create_update.ISORepoCreateCommand(self.context)
        user_input = {
            std_options.OPTION_REPO_ID.keyword: 'repo_id',
            command.options_bundle.opt_feed_cert.keyword: '/wrong/path'
        }
        # Set up a mock on create_and_configure, so we can make sure it doesn't get called
        self.context.server.repo.create_and_configure = mock.MagicMock()
        command.prompt = mock.MagicMock()

        fail_code = command.run(**user_input)

        # create_and_configure() shouldn't get called
        self.assertEqual(
            self.context.server.repo.create_and_configure.call_count, 0)

        # We should have told the user that there was FAIL
        self.assertEqual(command.prompt.render_success_message.call_count, 0)
        self.assertEqual(command.prompt.render_failure_message.call_count, 1)
        self.assertEqual(
            command.prompt.render_failure_message.mock_calls[0][2]['tag'],
            'create-failed')
        self.assertEqual(fail_code, os.EX_DATAERR)
    def test__perform_command(self):
        """
        Test the _perform_command() method.
        """
        command = create_update.ISORepoCreateCommand(self.context)
        repo_id = 'repo_id'
        display_name = 'Display Name'
        description = 'The repository.'
        notes = {'a_note': 'This is a note.'}
        importer_config = {
            importer_constants.KEY_FEED: 'https://feed.com/isos',
            importer_constants.KEY_SSL_CLIENT_CERT: 'This is a file.',
            importer_constants.KEY_SSL_CLIENT_KEY: 'This is a file.'}
        distributors = [{'distributor_type': ids.TYPE_ID_DISTRIBUTOR_ISO,
                         'distributor_config': {'serve_http': True},
                         'auto_publish': True, 'distributor_id': ids.TYPE_ID_DISTRIBUTOR_ISO}]
        # Set up a mock on create_and_configure, so we can intercept the call and inspect
        self.context.server.repo.create_and_configure = mock.MagicMock()
        command.prompt = mock.MagicMock()

        command._perform_command(repo_id, display_name, description, notes,
                                 importer_config, distributors, {})

        # Make sure the correct call was made to create the repo
        self.context.server.repo.create_and_configure.assert_called_once_with(
            repo_id, display_name, description, notes, ids.TYPE_ID_IMPORTER_ISO,
            importer_config, distributors)

        # We should have told the user that the repo was created successfully
        self.assertEqual(command.prompt.render_success_message.call_count, 1)
        self.assertEqual(command.prompt.render_success_message.mock_calls[0][2]['tag'],
                         'repo-created')
    def test_run_good_config_subset_of_options(self):
        """
        Test the run() function with a good config, with only a subset of options set.
        This helps us to know that we only send the options that the user set.
        """
        command = create_update.ISORepoCreateCommand(self.context)
        user_input = {
            std_options.OPTION_REPO_ID.keyword: 'repo_id',
            command.options_bundle.opt_feed.keyword: 'https://feed.com/isos',
            command.options_bundle.opt_feed_cert.keyword:
            '/path/to/other/cert',
            command.options_bundle.opt_feed_key.keyword: '/path/to/key'
        }
        # Set up a mock on create_and_configure, so we can intercept the call and inspect
        self.context.server.repo.create_and_configure = mock.MagicMock()
        command.prompt = mock.MagicMock()

        command.run(**user_input)

        # Assert that we passed all of the correct arguments to create_and_configure()
        self.assertEqual(
            self.context.server.repo.create_and_configure.call_count, 1)
        args = self.context.server.repo.create_and_configure.mock_calls[0][1]
        self.assertEqual(args[0], 'repo_id')
        self.assertEqual(args[1], None)
        self.assertEqual(args[2], None)

        # Inspect the repo notes
        expected_notes = {
            pulp_constants.REPO_NOTE_TYPE_KEY: constants.REPO_NOTE_ISO
        }
        # Our note was modified to include the repo type
        self.assertEqual(args[3], expected_notes)

        # Inspect the importer config
        self.assertEqual(args[4], ids.TYPE_ID_IMPORTER_ISO)
        expected_importer_config = {
            importer_constants.KEY_FEED: 'https://feed.com/isos',
            importer_constants.KEY_SSL_CLIENT_CERT: 'This is a file.',
            importer_constants.KEY_SSL_CLIENT_KEY: 'This is a file.'
        }
        self.assertEqual(args[5], expected_importer_config)

        # Inspect the distributors
        expected_distributor_config = {}
        expected_distributor = {
            'distributor_type_id': ids.TYPE_ID_DISTRIBUTOR_ISO,
            'distributor_config': expected_distributor_config,
            'auto_publish': True,
            'distributor_id': ids.TYPE_ID_DISTRIBUTOR_ISO
        }
        self.assertEqual(args[6], [expected_distributor])

        # We should have told the user that the repo was created successfully
        self.assertEqual(command.prompt.render_success_message.call_count, 1)
        self.assertEqual(
            command.prompt.render_success_message.mock_calls[0][2]['tag'],
            'repo-created')
    def test_populate_unit_policy(self, populate_unit_policy):
        """
        Make sure that we are only adding the --remove-missing option (and not the
        --remove-old-count option).
        """
        command = create_update.ISORepoCreateCommand(self.context)

        populate_unit_policy.assert_called_once_with(command)
        self.assertEqual(command.unit_policy_group.options,
                         [command.options_bundle.opt_remove_missing])
    def test___init__(self, create_repo_init, importer_config_init,
                      distributor_config_init):
        """
        Test the __init__() method, ensuring that it calls the __init__() methods for all
        its superclasses.
        """
        command = create_update.ISORepoCreateCommand(self.context)

        create_repo_init.assert_called_once_with(command, self.context)
        importer_config_init.assert_called_once_with(
            command, include_sync=True, include_ssl=True, include_proxy=True,
            include_throttling=True, include_unit_policy=True)
        distributor_config_init.assert_called_once_with(command)

        # Make sure we don't present the --retain-old-count option to the user
        self.assertEqual(len(command.unit_policy_group.options), 1)
Exemple #6
0
def add_repo_section(context, parent_section):
    """
    Add the repo section and all of its children to the parent section.

    :param context: ClientContext containing the CLI instance being configured
    :type  context: pulp.client.extensions.core.ClientContext
    :param parent_section: The parent CLI section that we wish to add the repo subsection to.
    :type  parent_section: pulp.client.extensions.extensions.PulpCliSection
    """
    repo_section = parent_section.create_subsection(SECTION_REPO, DESC_REPO)

    add_publish_section(context, repo_section)
    add_sync_section(context, repo_section)
    add_uploads_section(context, repo_section)

    repo_section.add_command(create_update.ISORepoCreateCommand(context))
    repo_section.add_command(create_update.ISORepoUpdateCommand(context))
    repo_section.add_command(cudl.DeleteRepositoryCommand(context))
    repo_section.add_command(repo_list.ISORepoListCommand(context))
    repo_section.add_command(association.IsoCopyCommand(context))
    repo_section.add_command(association.IsoRemoveCommand(context))
    repo_section.add_command(contents.ISOSearchCommand(context, name='isos'))
    def test_run_good_config_all_options(self):
        """
        Test the run() function with a good config, with all options set.
        """
        command = create_update.ISORepoCreateCommand(self.context)
        user_input = {
            std_options.OPTION_REPO_ID.keyword: 'repo_id',
            std_options.OPTION_DESCRIPTION.keyword: 'description',
            std_options.OPTION_NAME.keyword: 'name',
            std_options.OPTION_NOTES.keyword: {'a_note': 'note'},
            command.opt_http.keyword: 'true',
            command.opt_https.keyword: 'false',
            command.opt_auth_ca.keyword: '/path/to/file',
            command.options_bundle.opt_feed.keyword: 'http://feed.com/isos',
            command.options_bundle.opt_validate.keyword: 'true',
            command.options_bundle.opt_proxy_host.keyword: 'proxy.host.com',
            command.options_bundle.opt_proxy_port.keyword: '1234',
            command.options_bundle.opt_proxy_user.keyword: 'proxy_user',
            command.options_bundle.opt_proxy_pass.keyword: 'password',
            command.options_bundle.opt_max_speed.keyword: '56.6',
            command.options_bundle.opt_max_downloads.keyword: '4',
            command.options_bundle.opt_feed_ca_cert.keyword: '/path/to/cert',
            command.options_bundle.opt_verify_feed_ssl.keyword: 'true',
            command.options_bundle.opt_feed_cert.keyword: '/path/to/other/cert',
            command.options_bundle.opt_feed_key.keyword: '/path/to/key',
            command.options_bundle.opt_remove_missing.keyword: 'true'}
        # Set up a mock on create_and_configure, so we can intercept the call and inspect
        self.context.server.repo.create_and_configure = mock.MagicMock()
        command.prompt = mock.MagicMock()

        command.run(**user_input)

        # Assert that we passed all of the correct arguments to create_and_configure()
        self.assertEqual(self.context.server.repo.create_and_configure.call_count, 1)
        args = self.context.server.repo.create_and_configure.mock_calls[0][1]
        self.assertEqual(args[0], 'repo_id')
        self.assertEqual(args[1], 'name')
        self.assertEqual(args[2], 'description')

        # Inspect the repo notes
        expected_notes = {'a_note': 'note',
                          pulp_constants.REPO_NOTE_TYPE_KEY: constants.REPO_NOTE_ISO}
        # Our note was modified to include the repo type
        self.assertEqual(args[3], expected_notes)

        # Inspect the importer config
        self.assertEqual(args[4], ids.TYPE_ID_IMPORTER_ISO)
        expected_importer_config = {
            importer_constants.KEY_FEED: 'http://feed.com/isos',
            importer_constants.KEY_MAX_DOWNLOADS: '4',
            importer_constants.KEY_MAX_SPEED: '56.6',
            importer_constants.KEY_PROXY_HOST: 'proxy.host.com',
            importer_constants.KEY_PROXY_PASS: '******',
            importer_constants.KEY_PROXY_PORT: '1234',
            importer_constants.KEY_PROXY_USER: '******',
            importer_constants.KEY_SSL_CA_CERT: 'This is a file.',
            importer_constants.KEY_SSL_CLIENT_CERT: 'This is a file.',
            importer_constants.KEY_SSL_CLIENT_KEY: 'This is a file.',
            importer_constants.KEY_SSL_VALIDATION: 'true',
            importer_constants.KEY_UNITS_REMOVE_MISSING: 'true',
            importer_constants.KEY_VALIDATE: 'true'}
        self.assertEqual(args[5], expected_importer_config)

        # Inspect the distributors
        expected_distributor_config = {
            constants.CONFIG_SERVE_HTTP: 'true', constants.CONFIG_SERVE_HTTPS: 'false',
            constants.CONFIG_SSL_AUTH_CA_CERT: 'This is a file.'}
        expected_distributor = {
            'distributor_type_id': ids.TYPE_ID_DISTRIBUTOR_ISO,
            'distributor_config': expected_distributor_config,
            'auto_publish': True, 'distributor_id': ids.TYPE_ID_DISTRIBUTOR_ISO}
        self.assertEqual(args[6], [expected_distributor])

        # We should have told the user that the repo was created successfully
        self.assertEqual(command.prompt.render_success_message.call_count, 1)
        self.assertEqual(command.prompt.render_success_message.mock_calls[0][2]['tag'],
                         'repo-created')