def setUp(self): conf_dict = { importer_constants.KEY_FEED: 'http://fake.com/file_feed/', importer_constants.KEY_MAX_SPEED: 500.0, importer_constants.KEY_MAX_DOWNLOADS: 5, importer_constants.KEY_SSL_VALIDATION: False, importer_constants.KEY_SSL_CLIENT_CERT: "Trust me, I'm who I say I am.", importer_constants.KEY_SSL_CLIENT_KEY: "Secret Key", importer_constants.KEY_SSL_CA_CERT: "Uh, I guess that's the right server.", importer_constants.KEY_PROXY_HOST: 'proxy.com', importer_constants.KEY_PROXY_PORT: 1234, importer_constants.KEY_PROXY_USER: "******", importer_constants.KEY_PROXY_PASS: '******', importer_constants.KEY_VALIDATE: False, } self.real_config = self.get_basic_config(**conf_dict) self.real_conduit = self.get_sync_conduit() self.mock_repo = Mock() self.mock_conduit = Mock() self.mock_config = Mock() self.mock_working_dir = Mock() self.dlstep = DownloadStep("fake_download", repo=self.mock_repo, conduit=self.mock_conduit, config=self.mock_config, working_dir=self.mock_working_dir, plugin_type="fake plugin", description='foo')
def test__process_block(self): mock_downloader = Mock() mock_downloads = ['fake', 'downloads'] dlstep = DownloadStep('fake-step', downloads=mock_downloads) dlstep.downloader = mock_downloader dlstep._process_block() mock_downloader.download.assert_called_once_with(['fake', 'downloads'])
def test_cancel(self): dlstep = DownloadStep('fake-step') dlstep.parent = MagicMock() dlstep.initialize() dlstep.cancel() self.assertTrue(dlstep.downloader.is_canceled)
def test_downloads_property(self): generator = (DownloadRequest(url, '/a/b/c') for url in ['http://pulpproject.org']) dlstep = DownloadStep('fake-step', downloads=generator) downloads = dlstep.downloads self.assertTrue(isinstance(downloads, list)) self.assertEqual(len(downloads), 1) self.assertTrue(isinstance(downloads[0], DownloadRequest))
def test_download_failed(self): dlstep = DownloadStep('fake-step') mock_report = Mock() mock_report_progress = Mock() dlstep.report_progress = mock_report_progress dlstep.download_failed(mock_report) self.assertEquals(dlstep.progress_failures, 1) # assert report_progress was called with no args mock_report_progress.assert_called_once_with()
def __init__(self, repo=None, conduit=None, config=None, working_dir=None): """ :param repo: repository to sync :type repo: pulp.plugins.model.Repository :param conduit: sync conduit to use :type conduit: pulp.plugins.conduits.repo_sync.RepoSyncConduit :param config: config object for the sync :type config: pulp.plugins.config.PluginCallConfiguration :param working_dir: full path to the directory in which transient files should be stored before being moved into long-term storage. This should be deleted by the caller after step processing is complete. :type working_dir: basestring """ super(SyncStep, self).__init__(constants.SYNC_STEP_MAIN, repo, conduit, config, working_dir, constants.IMPORTER_TYPE_ID) self.description = _('Syncing Docker Repository') # Unit keys, populated by GetMetadataStep self.available_units = [] # populated by GetMetadataStep self.tags = {} self.validate(config) download_config = nectar_config.importer_config_to_nectar_config( config.flatten()) upstream_name = config.get(constants.CONFIG_KEY_UPSTREAM_NAME) url = config.get(importer_constants.KEY_FEED) # create a Repository object to interact with self.index_repository = Repository(upstream_name, download_config, url, working_dir) self.add_child(GetMetadataStep(working_dir=working_dir)) # save this step so its "units_to_download" attribute can be accessed later self.step_get_local_units = GetLocalImagesStep( constants.IMPORTER_TYPE_ID, constants.IMAGE_TYPE_ID, ['image_id'], working_dir) self.add_child(self.step_get_local_units) self.add_child( DownloadStep(constants.SYNC_STEP_DOWNLOAD, downloads=self.generate_download_requests(), repo=repo, config=config, working_dir=working_dir, description=_('Downloading remote files'))) self.add_child(SaveUnits(working_dir))
def __init__(self, **kwargs): """ :param repo: repository to sync :type repo: pulp.plugins.model.Repository :param conduit: sync conduit to use :type conduit: pulp.plugins.conduits.repo_sync.RepoSyncConduit :param config: config object for the sync :type config: pulp.plugins.config.PluginCallConfiguration :param working_dir: full path to the directory in which transient files should be stored before being moved into long-term storage. This should be deleted by the caller after step processing is complete. :type working_dir: basestring """ super(SyncStep, self).__init__(constants.IMPORT_STEP_MAIN, plugin_type=constants.WEB_IMPORTER_TYPE_ID, **kwargs) self.description = _('Syncing Repository') # Unit keys, populated by GetMetadataStep self.available_units = [] # config = self.get_config() working_dir = self.get_working_dir() self.deb_data = {} # repo = self.get_repo() # create a Repository object to interact with self.add_child(GetMetadataStep()) self.step_get_local_units = GetLocalUnitsStepDeb() self.add_child(self.step_get_local_units) self.add_child( DownloadStep(constants.SYNC_STEP_DOWNLOAD, downloads=self.generate_download_requests(), repo=kwargs["repo"], config=kwargs["config"], working_dir=kwargs["working_dir"], description=_('Downloading remote files'))) self.add_child(SaveUnits(working_dir))
def test__get_total(self): mock_downloads = ['fake', 'downloads'] dlstep = DownloadStep('fake-step', downloads=mock_downloads) self.assertEquals(dlstep._get_total(), 2)