Exemple #1
0
def initialize(context):
    structure.ensure_repo_structure(context.cli)
    upload_manager = _upload_manager(context)

    repo_section = structure.repo_section(context.cli)
    repo_section.add_command(repo_create_update.PkgRepoCreateCommand(context))
    repo_section.add_command(repo_create_update.PkgRepoUpdateCommand(context))
    repo_section.add_command(cudl.DeleteRepositoryCommand(context))
    repo_section.add_command(repo_list.RepoListCommand(context))
    repo_section.add_command(
        RepoSearchCommand(context, constants.REPO_NOTE_PKG))

    copy_section = structure.repo_copy_section(context.cli)
    copy_section.add_command(copy_commands.MsiCopyCommand(context))
    copy_section.add_command(copy_commands.MsmCopyCommand(context))
    copy_section.add_command(copy_commands.AllCopyCommand(context))

    remove_section = structure.repo_remove_section(context.cli)
    remove_section.add_command(remove.MsiRemoveCommand(context))
    remove_section.add_command(remove.MsmRemoveCommand(context))

    contents_section = structure.repo_contents_section(context.cli)
    contents_section.add_command(contents.SearchMsiCommand(context))
    contents_section.add_command(contents.SearchMsmCommand(context))

    uploads_section = structure.repo_uploads_section(context.cli)
    for cls_ in [
            package.CreateMsiCommand, package.CreateMsmCommand,
            upload.ResumeCommand, upload.CancelCommand, upload.ListCommand
    ]:
        uploads_section.add_command(cls_(context, upload_manager))

    sync_section = structure.repo_sync_section(context.cli)
    renderer = status.PackageStatusRenderer(context)
    sync_section.add_command(
        sync_publish.RunSyncRepositoryCommand(context, renderer))
    sync_section.add_command(sync_publish.SyncStatusCommand(context, renderer))

    publish_section = structure.repo_publish_section(context.cli)
    renderer = PublishStepStatusRenderer(context)
    distributor_id = ids.TYPE_ID_DISTRIBUTOR_WIN
    publish_section.add_command(
        sync_publish.RunPublishRepositoryCommand(context, renderer,
                                                 distributor_id))
    publish_section.add_command(
        sync_publish.PublishStatusCommand(context, renderer))

    sync_schedules_section = structure.repo_sync_schedules_section(context.cli)
    sync_schedules_section.add_command(
        sync_schedules.PkgCreateScheduleCommand(context))
    sync_schedules_section.add_command(
        sync_schedules.PkgUpdateScheduleCommand(context))
    sync_schedules_section.add_command(
        sync_schedules.PkgDeleteScheduleCommand(context))
    sync_schedules_section.add_command(
        sync_schedules.PkgListScheduleCommand(context))

    sync_schedules_section.add_command(
        sync_schedules.PkgNextRunCommand(context))
    def test_create_structure(self):
        command = repo_create_update.PkgRepoUpdateCommand(self.context)

        self.assertTrue(isinstance(command, ImporterConfigMixin))

        # Ensure the required option groups
        found_group_names = set([o.name for o in command.option_groups])
        self.assertTrue(repo_options.NAME_PUBLISHING in found_group_names)

        # Ensure the correct method is wired up
        self.assertEqual(command.method, command.run)

        # Ensure the correct metadata
        self.assertEqual(command.name, 'update')
        self.assertEqual(command.description, cudl.DESC_UPDATE)
    def test_run(self):
        # Setup
        data = {
            options.OPTION_REPO_ID.keyword: 'test-repo',
            options.OPTION_NAME.keyword: 'Test Name',
            options.OPTION_DESCRIPTION.keyword: 'Test Description',
            options.OPTION_NOTES.keyword: {
                'b': 'b'
            },
            self.options_bundle.opt_feed.keyword: 'http://localhost',
            repo_options.OPT_SERVE_HTTP.keyword: True,
            repo_options.OPT_SERVE_HTTPS.keyword: True,
            repo_options.OPT_SKIP.keyword: [ids.TYPE_ID_MSM],
        }

        self.server_mock.request.return_value = 200, {}

        # Test
        command = repo_create_update.PkgRepoUpdateCommand(self.context)
        command.run(**data)

        # Verify
        self.assertEqual(1, self.server_mock.request.call_count)

        body = self.server_mock.request.call_args[0][2]
        body = json.loads(body)

        delta = body['delta']
        self.assertEqual(delta['display_name'], 'Test Name')
        self.assertEqual(delta['description'], 'Test Description')
        self.assertEqual(delta['notes'], {'b': 'b'})

        yum_imp_config = body['importer_config']
        self.assertEqual(yum_imp_config[constants.KEY_FEED],
                         'http://localhost')
        self.assertEqual(yum_imp_config[repo_create_update.CONFIG_KEY_SKIP],
                         [ids.TYPE_ID_MSM])

        yum_dist_config = body['distributor_configs'][
            ids.TYPE_ID_DISTRIBUTOR_WIN]
        self.assertEqual(yum_dist_config['http'], True)
        self.assertEqual(yum_dist_config['https'], True)
        self.assertEqual(yum_dist_config['skip'], [ids.TYPE_ID_MSM])
    def test_remove_skip_types(self):
        # Setup
        self.server_mock.request.return_value = 201, {}

        # Test
        command = repo_create_update.PkgRepoUpdateCommand(self.context)
        self.cli.add_command(command)
        cmd = ("update --repo-id r --skip")
        self.cli.run(cmd.split() + [''])

        # Verify
        self.assertEqual(1, self.server_mock.request.call_count)

        body = self.server_mock.request.call_args[0][2]
        body = json.loads(body)

        self.assertEqual(body['importer_config']['type_skip_list'], None)
        self.assertEqual(
            body['distributor_configs'][ids.TYPE_ID_DISTRIBUTOR_WIN]['skip'],
            None)
    def test_run_through_cli(self):
        """
        See the note in test_run_through_cli under the create tests for
        more info.
        """

        # Setup
        self.server_mock.request.return_value = 201, {}

        # Test
        command = repo_create_update.PkgRepoUpdateCommand(self.context)
        self.cli.add_command(command)
        cmd = ("update --repo-id r --validate true")
        self.cli.run(cmd.split())

        # Verify
        self.assertEqual(1, self.server_mock.request.call_count)

        body = self.server_mock.request.call_args[0][2]
        body = json.loads(body)

        self.assertEqual(body['importer_config'][constants.KEY_VALIDATE],
                         True)  # not the string "true"
    def test_run_202(self):
        # Setup
        data = {
            options.OPTION_REPO_ID.keyword: 'test-repo',
            options.OPTION_NAME.keyword: 'Test Name',
            options.OPTION_DESCRIPTION.keyword: 'Test Description',
            options.OPTION_NOTES.keyword: {
                'b': 'b'
            },
            self.options_bundle.opt_feed.keyword: 'http://localhost',
            repo_options.OPT_SERVE_HTTP.keyword: True,
            repo_options.OPT_SERVE_HTTPS.keyword: True,
            repo_options.OPT_SKIP.keyword: [ids.TYPE_ID_MSM],
        }

        self.server_mock.request.return_value = 202, {}

        # Test
        command = repo_create_update.PkgRepoUpdateCommand(self.context)
        command.run(**data)

        # Verify that things at least didn't blow up, which they were for BZ 1096931
        self.assertEqual(1, self.server_mock.request.call_count)