Пример #1
0
    def test_run_bad_config(self):
        """
        Test the run() function with a bad config.
        """
        command = create_update.ISORepoUpdateCommand(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)
Пример #2
0
    def test_run_good_config(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.ISORepoUpdateCommand(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 update_repo_and_plugins, so we can intercept the call and inspect
        self.context.server.repo.update_repo_and_plugins = mock.MagicMock()

        class Response(object):
            def is_async(self):
                return False

        self.context.server.repo.update_repo_and_plugins.return_value = Response(
        )
        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.update_repo_and_plugins.call_count, 1)
        args = self.context.server.repo.update_repo_and_plugins.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
        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[4], expected_importer_config)

        # Inspect the distributors
        expected_distributor = {ids.TYPE_ID_DISTRIBUTOR_ISO: {}}
        self.assertEqual(args[5], expected_distributor)

        # We should have told the user that the repo was updated successfully
        self.assertEqual(command.prompt.render_success_message.call_count, 1)
        self.assertEqual(
            command.prompt.render_success_message.mock_calls[0][2]['tag'],
            'repo-updated')
Пример #3
0
    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.ISORepoUpdateCommand(self.context)

        populate_unit_policy.assert_called_once_with(command)
        self.assertEqual(command.unit_policy_group.options,
                         [command.options_bundle.opt_remove_missing])
Пример #4
0
    def test__perform_command_async(self):
        """
        Test the _perform_command() method with an asynchronous response.
        """
        command = create_update.ISORepoUpdateCommand(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.update_repo_and_plugins = mock.MagicMock()
        command.poll = mock.MagicMock()

        class Response(object):
            def is_async(self):
                return True

            @property
            def response_body(self):
                body = mock.MagicMock()
                body.reasons = 'Is this a good reason?'
                return body

        self.context.server.repo.update_repo_and_plugins.return_value = Response(
        )
        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
        distributor_configs = {
            distributors[0]['distributor_id']:
            distributors[0]['distributor_config']
        }
        self.context.server.repo.update_repo_and_plugins.assert_called_once_with(
            repo_id, display_name, description, notes, importer_config,
            distributor_configs)

        # We should have called the polling loop
        self.assertTrue(command.poll.called)
Пример #5
0
    def test__perform_command_sync(self):
        """
        Test the _perform_command() method with a synchronous response.
        """
        command = create_update.ISORepoUpdateCommand(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.update_repo_and_plugins = mock.MagicMock()

        class Response(object):
            def is_async(self):
                return False

        self.context.server.repo.update_repo_and_plugins.return_value = Response(
        )
        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
        distributor_configs = {
            distributors[0]['distributor_id']:
            distributors[0]['distributor_config']
        }
        self.context.server.repo.update_repo_and_plugins.assert_called_once_with(
            repo_id, display_name, description, notes, importer_config,
            distributor_configs)

        # 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-updated')
Пример #6
0
    def test___init__(self, update_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.ISORepoUpdateCommand(self.context)

        update_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)
Пример #7
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'))