def test_rpm_group_export_setup(self, mock_add_option, mock_create_flag): """ Test to make sure the export run command is set up correctly """ mock_renderer = mock.Mock(spec=status.StatusRenderer) expected_options = [ FLAG_BACKGROUND, options.OPTION_GROUP_ID, export.OPTION_EXPORT_DIR, export.OPTION_END_DATE, export.OPTION_START_DATE, export.OPTION_ISO_PREFIX, export.OPTION_ISO_SIZE ] # Test export.RpmGroupExportCommand(self.context, mock_renderer, ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT) # Check that all the flags were added self.assertEqual(2, mock_create_flag.call_count) self.assertEqual('--' + export.SERVE_HTTP, mock_create_flag.call_args_list[0][0][1]) self.assertEqual(export.DESC_SERVE_HTTP, mock_create_flag.call_args_list[0][0][2]) self.assertEqual('--' + export.SERVE_HTTPS, mock_create_flag.call_args_list[1][0][1]) self.assertEqual(export.DESC_SERVE_HTTPS, mock_create_flag.call_args_list[1][0][2]) # Check that all the options were added actual_options = [] for call_args, kwargs in mock_add_option.call_args_list: actual_options.append(call_args[1]) self.assertEqual(set(actual_options), set(expected_options))
def test_progress(self): mock_renderer = mock.MagicMock() command = export.RpmGroupExportCommand( self.context, mock_renderer, ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT) test_task = Task({"progress_report": 'foo'}) command.progress(test_task, None) mock_renderer.display_report.assert_called_once_with('foo')
def test_rpm_group_export_run(self, mock_distributors, mock_create, mock_publish): """ Test to make sure the publish binding is called correctly with an existing distributor. """ # Setup mock_distributor = { 'distributor_type_id': ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT, 'id': 'foo-distributor' } mock_distributors.return_value = Response(200, [mock_distributor]) mock_publish.return_value = Response(200, []) expected_publish_config = { constants.PUBLISH_HTTP_KEYWORD: True, constants.PUBLISH_HTTPS_KEYWORD: True, } # Test command = export.RpmGroupExportCommand( self.context, mock.MagicMock(), ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT) command.run(**self.kwargs) # Assert that the call get get the distributor was made correctly self.assertEqual(1, mock_distributors.call_count) self.assertEqual('test-group', mock_distributors.call_args[0][1]) mock_publish.assert_called_once_with(mock.ANY, 'test-group', mock.ANY, expected_publish_config)
def test_rpm_group_export_missing_distributor(self, mock_distributors, mock_create, mock_publish): """ Test that when there is no distributor attached to the repository group, one is added """ # Setup mock_distributors.return_value = Response(200, []) mock_publish.return_value = Response(200, []) expected_distributor_config = { constants.PUBLISH_HTTP_KEYWORD: True, constants.PUBLISH_HTTPS_KEYWORD: True, } # Test command = export.RpmGroupExportCommand( self.context, mock.MagicMock(), ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT) command.run(**self.kwargs) # Assert that the call get get the distributor was made correctly self.assertEqual(1, mock_distributors.call_count) self.assertEqual('test-group', mock_distributors.call_args[0][1]) # Assert that when the NonFoundException is raised, a call to create a distributor is made self.assertEqual(1, mock_create.call_count) self.assertEqual('test-group', mock_create.call_args[0][1]) self.assertEqual(ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT, mock_create.call_args[0][2]) self.assertEqual(expected_distributor_config, mock_create.call_args[0][3])
def test_rpm_group_export_setup(self, mock_add_option): """ Test to make sure the export run command is set up correctly """ mock_renderer = mock.Mock(spec=status.StatusRenderer) expected_options = [ FLAG_BACKGROUND, options.OPTION_GROUP_ID, export.FLAG_MANIFEST, export.OPTION_EXPORT_DIR, export.OPTION_RELATIVE_URL, export.OPTION_END_DATE, export.OPTION_START_DATE, export.OPTION_ISO_PREFIX, export.OPTION_ISO_SIZE, export.OPTION_SERVE_HTTPS, export.OPTION_SERVE_HTTP, export.OPTION_INCREMENTAL_MD, repo_options.OPT_CHECKSUM_TYPE, repo_options.OPT_UPDATEINFO_CHECKSUM_TYPE, ] # Test export.RpmGroupExportCommand(self.context, mock_renderer, ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT) # Check that all the options were added actual_options = [] for call_args, kwargs in mock_add_option.call_args_list: actual_options.append(call_args[1]) self.assertEqual(set(actual_options), set(expected_options))
def test_rpm_group_export_existing_task(self, mock_distributor, mock_publish, mock_poll): """ Make sure that when there is already a publish operation in progress for the repository, a second one is not started """ # Setup mock_distributor.return_value = (200, mock.Mock(spec=Response)) self.mock_get_publish_tasks.return_value = 'Not None' # Test command = export.RpmGroupExportCommand(mock.MagicMock(), mock.MagicMock(), ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT) command.run(**self.kwargs) self.assertEqual(0, mock_publish.call_count) mock_poll.assert_called_once_with('Not None', mock.ANY)
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.RpmRepoCreateCommand(context)) repo_section.add_command(repo_create_update.RpmRepoUpdateCommand(context)) repo_section.add_command(cudl.DeleteRepositoryCommand(context)) repo_section.add_command(repo_list.RpmRepoListCommand(context)) repo_section.add_command( RepoSearchCommand(context, constants.REPO_NOTE_RPM)) copy_section = structure.repo_copy_section(context.cli) copy_section.add_command(copy_commands.RpmCopyCommand(context)) copy_section.add_command(copy_commands.ErrataCopyCommand(context)) copy_section.add_command(copy_commands.DistributionCopyCommand(context)) copy_section.add_command(copy_commands.PackageGroupCopyCommand(context)) copy_section.add_command(copy_commands.PackageCategoryCopyCommand(context)) copy_section.add_command( copy_commands.PackageEnvironmentCopyCommand(context)) copy_section.add_command(copy_commands.AllCopyCommand(context)) copy_section.add_command(copy_commands.SrpmCopyCommand(context)) copy_section.add_command(copy_commands.YumRepoMetadataFileCommand(context)) copy_section.add_command(copy_commands.DrpmCopyCommand(context)) # Disabled as per 950690. We'll likely be able to add these back once the new # yum importer is finished and DRPMs are properly handled. # copy_section.add_command(copy_commands.DrpmCopyCommand(context)) remove_section = structure.repo_remove_section(context.cli) remove_section.add_command(remove.RpmRemoveCommand(context)) remove_section.add_command(remove.SrpmRemoveCommand(context)) remove_section.add_command(remove.DrpmRemoveCommand(context)) remove_section.add_command(remove.ErrataRemoveCommand(context)) remove_section.add_command(remove.PackageGroupRemoveCommand(context)) remove_section.add_command(remove.PackageCategoryRemoveCommand(context)) remove_section.add_command(remove.PackageEnvironmentRemoveCommand(context)) remove_section.add_command(remove.DistributionRemoveCommand(context)) remove_section.add_command(remove.YumMetadataFileRemoveCommand(context)) contents_section = structure.repo_contents_section(context.cli) contents_section.add_command(contents.SearchRpmsCommand(context)) contents_section.add_command(contents.SearchDrpmsCommand(context)) contents_section.add_command(contents.SearchSrpmsCommand(context)) contents_section.add_command(contents.SearchPackageGroupsCommand(context)) contents_section.add_command( contents.SearchPackageCategoriesCommand(context)) contents_section.add_command( contents.SearchPackageEnvironmentsCommand(context)) contents_section.add_command(contents.SearchDistributionsCommand(context)) contents_section.add_command(contents.SearchErrataCommand(context)) contents_section.add_command( contents.SearchYumMetadataFileCommand(context)) # Add the group section, all its subsections, and commands group_export_section = structure.repo_group_export_section(context.cli) renderer = PublishStepStatusRenderer(context) group_export_section.add_command( export.RpmGroupExportCommand(context, renderer)) group_export_section.add_command( export.GroupExportStatusCommand(context, renderer)) uploads_section = structure.repo_uploads_section(context.cli) uploads_section.add_command( package.CreateRpmCommand(context, upload_manager)) uploads_section.add_command( package.CreateSrpmCommand(context, upload_manager)) uploads_section.add_command( errata.CreateErratumCommand(context, upload_manager)) uploads_section.add_command( package_group.CreatePackageGroupCommand(context, upload_manager)) uploads_section.add_command( category.CreatePackageCategoryCommand(context, upload_manager)) uploads_section.add_command( comps.CreateCompsCommand(context, upload_manager)) uploads_section.add_command( environment.CreatePackageEnvironmentCommand(context, upload_manager)) uploads_section.add_command(upload.ResumeCommand(context, upload_manager)) uploads_section.add_command(upload.CancelCommand(context, upload_manager)) uploads_section.add_command(upload.ListCommand(context, upload_manager)) sync_section = structure.repo_sync_section(context.cli) renderer = status.RpmStatusRenderer(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_YUM publish_section.add_command( sync_publish.RunPublishRepositoryCommand(context, renderer, distributor_id)) publish_section.add_command( sync_publish.PublishStatusCommand(context, renderer)) repo_export_section = structure.repo_export_section(context.cli) renderer = PublishStepStatusRenderer(context) repo_export_section.add_command(export.RpmExportCommand(context, renderer)) repo_export_section.add_command( sync_publish.PublishStatusCommand(context, renderer, description=DESC_EXPORT_STATUS)) sync_schedules_section = structure.repo_sync_schedules_section(context.cli) sync_schedules_section.add_command( sync_schedules.RpmCreateScheduleCommand(context)) sync_schedules_section.add_command( sync_schedules.RpmUpdateScheduleCommand(context)) sync_schedules_section.add_command( sync_schedules.RpmDeleteScheduleCommand(context)) sync_schedules_section.add_command( sync_schedules.RpmListScheduleCommand(context)) sync_schedules_section.add_command( sync_schedules.RpmNextRunCommand(context))