def test_process_export_distributor_serve_protocol_defaults(self): # Setup distributor_config = {} # will be populated in this call command = repo_create_update.RpmRepoCreateCommand(self.context) # Test command.process_export_distributor_serve_protocol(distributor_config) # Verify self.assertEqual(distributor_config['http'], False) self.assertEqual(distributor_config['https'], True)
def test_process_export_distributor_serve_protocol_new_values(self): # Setup distributor_config = {'http': True, 'https': False} command = repo_create_update.RpmRepoCreateCommand(self.context) # Test command.process_export_distributor_serve_protocol(distributor_config) # Verify self.assertEqual(distributor_config['http'], True) self.assertEqual(distributor_config['https'], False)
def test_process_relative_url_specified(self): # Setup repo_id = 'specified' importer_config = {} distributor_config = {'relative_url': 'wombat'} command = repo_create_update.RpmRepoCreateCommand(self.context) # Test command.process_relative_url(repo_id, importer_config, distributor_config) # Verify self.assertTrue('relative_url' in distributor_config) self.assertEqual(distributor_config['relative_url'], 'wombat')
def test_process_relative_url_no_feed(self): # Setup repo_id = 'no-feed-repo' importer_config = {} distributor_config = {} # will be populated in this call command = repo_create_update.RpmRepoCreateCommand(self.context) # Test command.process_relative_url(repo_id, importer_config, distributor_config) # Verify self.assertTrue('relative_url' in distributor_config) self.assertEqual(distributor_config['relative_url'], repo_id)
def test_process_relative_url_with_feed(self): # Setup repo_id = 'feed-repo' importer_config = {constants.KEY_FEED: 'http://localhost/foo/bar/baz'} distributor_config = {} # will be populated in this call command = repo_create_update.RpmRepoCreateCommand(self.context) # Test command.process_relative_url(repo_id, importer_config, distributor_config) # Verify self.assertTrue('relative_url' in distributor_config) self.assertEqual(distributor_config['relative_url'], '/foo/bar/baz')
def test_create_structure(self): command = repo_create_update.RpmRepoCreateCommand(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_AUTH in found_group_names) 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, 'create') self.assertEqual(command.description, cudl.DESC_CREATE)
def test_run_through_cli(self): # Setup self.server_mock.request.return_value = 201, {} # Test command = repo_create_update.RpmRepoCreateCommand(self.context) self.cli.add_command(command) self.cli.run("create --repo-id r --validate true".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['id'], 'r') self.assertEqual(body['importer_config'][constants.KEY_VALIDATE], True) # not the string "true"
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))
def test_run(self): # Setup cert_file = os.path.join(DATA_DIR, 'cert.crt') cert_key = os.path.join(DATA_DIR, 'cert.key') ca_cert = os.path.join(DATA_DIR, 'valid_ca.crt') gpg_key = os.path.join(DATA_DIR, 'cert.key') # contents shouldn't matter data = { options.OPTION_REPO_ID.keyword: 'test-repo', options.OPTION_NAME.keyword: 'Test Name', options.OPTION_DESCRIPTION.keyword: 'Test Description', options.OPTION_NOTES.keyword: { 'a': 'a' }, self.options_bundle.opt_feed.keyword: 'http://localhost', self.options_bundle.opt_validate.keyword: True, self.options_bundle.opt_remove_missing.keyword: True, self.options_bundle.opt_retain_old_count.keyword: 2, self.options_bundle.opt_proxy_host.keyword: 'http://localhost', self.options_bundle.opt_proxy_port.keyword: 80, self.options_bundle.opt_proxy_user.keyword: 'user', self.options_bundle.opt_proxy_pass.keyword: 'pass', self.options_bundle.opt_basic_auth_user.keyword: 'basicuser', self.options_bundle.opt_basic_auth_pass.keyword: 'basicpass', self.options_bundle.opt_max_speed.keyword: 1024, self.options_bundle.opt_max_downloads.keyword: 8, self.options_bundle.opt_feed_ca_cert.keyword: ca_cert, self.options_bundle.opt_verify_feed_ssl.keyword: True, self.options_bundle.opt_feed_cert.keyword: cert_file, self.options_bundle.opt_feed_key.keyword: cert_key, repo_options.OPT_SKIP.keyword: [ids.TYPE_ID_RPM], repo_options.OPT_RELATIVE_URL.keyword: '/repo', repo_options.OPT_SERVE_HTTP.keyword: True, repo_options.OPT_SERVE_HTTPS.keyword: True, repo_options.OPT_CHECKSUM_TYPE.keyword: 'sha256', repo_options.OPT_UPDATEINFO_CHECKSUM_TYPE.keyword: 'md5', repo_options.OPT_GPG_KEY.keyword: gpg_key, repo_options.OPT_HOST_CA.keyword: ca_cert, repo_options.OPT_AUTH_CA.keyword: ca_cert, repo_options.OPT_AUTH_CERT.keyword: cert_file, repo_options.OPT_REPOVIEW.keyword: True, } self.server_mock.request.return_value = 201, {} # Test command = repo_create_update.RpmRepoCreateCommand(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) self.assertEqual(body['display_name'], 'Test Name') self.assertEqual(body['description'], 'Test Description') self.assertEqual(body['notes'], {'_repo-type': 'rpm-repo', 'a': 'a'}) self.assertEqual(ids.TYPE_ID_IMPORTER_YUM, body['importer_type_id']) importer_config = body['importer_config'] self.assertEqual(importer_config[constants.KEY_FEED], 'http://localhost') self.assertTrue(importer_config[constants.KEY_SSL_CA_CERT] is not None) self.assertTrue( importer_config[constants.KEY_SSL_CLIENT_CERT] is not None) self.assertTrue( importer_config[constants.KEY_SSL_CLIENT_KEY] is not None) self.assertEqual(importer_config[constants.KEY_SSL_VALIDATION], True) self.assertEqual(importer_config[constants.KEY_VALIDATE], True) self.assertEqual(importer_config[constants.KEY_PROXY_HOST], 'http://localhost') self.assertEqual(importer_config[constants.KEY_PROXY_PORT], 80) self.assertEqual(importer_config[constants.KEY_PROXY_USER], 'user') self.assertEqual(importer_config[constants.KEY_PROXY_PASS], 'pass') self.assertEqual(importer_config[constants.KEY_BASIC_AUTH_USER], 'basicuser') self.assertEqual(importer_config[constants.KEY_BASIC_AUTH_PASS], 'basicpass') self.assertEqual(importer_config[constants.KEY_MAX_SPEED], 1024) self.assertEqual(importer_config[constants.KEY_MAX_DOWNLOADS], 8) self.assertEqual(importer_config[rpm_constants.CONFIG_SKIP], [ids.TYPE_ID_RPM]) self.assertEqual(importer_config[constants.KEY_UNITS_REMOVE_MISSING], True) self.assertEqual(importer_config[constants.KEY_UNITS_RETAIN_OLD_COUNT], 2) # The API will be changing to be a dict for each distributor, not a # list. This code will have to change to look up the parts by key # instead of index. yum_distributor = body['distributors'][0] self.assertEqual(ids.TYPE_ID_DISTRIBUTOR_YUM, yum_distributor['distributor_type_id']) self.assertEqual(True, yum_distributor['auto_publish']) self.assertEqual(ids.YUM_DISTRIBUTOR_ID, yum_distributor['distributor_id']) yum_config = yum_distributor['distributor_config'] self.assertEqual(yum_config['relative_url'], '/repo') self.assertEqual(yum_config['http'], True) self.assertEqual(yum_config['https'], True) self.assertTrue(yum_config['gpgkey'] is not None) self.assertEqual(yum_config['checksum_type'], 'sha256') self.assertEqual(yum_config['updateinfo_checksum_type'], 'md5') self.assertTrue(yum_config['auth_ca'] is not None) self.assertTrue(yum_config['auth_cert'] is not None) self.assertTrue(yum_config['https_ca'] is not None) self.assertEqual(yum_config['skip'], [ids.TYPE_ID_RPM]) self.assertEqual(yum_config['repoview'], True) self.assertEqual(yum_config['generate_sqlite'], True) iso_distributor = body['distributors'][1] self.assertEqual(ids.TYPE_ID_DISTRIBUTOR_EXPORT, iso_distributor['distributor_id']) self.assertEqual(False, iso_distributor['auto_publish']) self.assertEqual(ids.EXPORT_DISTRIBUTOR_ID, iso_distributor['distributor_id']) iso_config = iso_distributor['distributor_config'] self.assertEqual(iso_config['http'], True) self.assertEqual(iso_config['https'], True) self.assertEqual(iso_config['relative_url'], '/repo') self.assertEqual(iso_config['skip'], [ids.TYPE_ID_RPM]) self.assertEqual(iso_config['checksum_type'], 'sha256') self.assertEqual(iso_config['updateinfo_checksum_type'], 'md5') self.assertEqual([TAG_SUCCESS], self.prompt.get_write_tags())