def __call__(self): """ Invoke the callable object. All work is performed in the repository working directory and cleaned up after the call. :return: The final synchronization report. :rtype: SyncProgressReport """ self.canceled = False self.report = SyncProgressReport(self.conduit) self.tmp_dir = mkdtemp(dir=self.repo.working_dir) try: manifest = self._fetch_manifest() if manifest is not None: module_paths = self._fetch_modules(manifest) self._import_modules(module_paths) finally: # Update the progress report one last time self.report.update_progress() shutil.rmtree(self.tmp_dir) self.tmp_dir = None return self.report
def __init__(self, repo, sync_conduit, config, is_cancelled_call): self.repo = repo self.sync_conduit = sync_conduit self.config = config self.is_cancelled_call = is_cancelled_call self.progress_report = SyncProgressReport(sync_conduit)
def __init__(self, repo, sync_conduit, config): self.repo = repo self.sync_conduit = sync_conduit self.config = config self.progress_report = SyncProgressReport(sync_conduit) self.downloader = None # Since SynchronizeWithPuppetForge creates a Nectar downloader for each unit, we cannot # rely on telling the current downloader to cancel. Therefore, we need another state # tracker to check in the download units loop. self._canceled = False
def test_forge_synchronization(self, failed_call, mock_call): conduit = Mock() repository = Mock() config = {constants.CONFIG_FEED: 'http://host/tmp/forge'} # directory synchronization failure needed so the importer # will retry using the forge synchronization. failed_report = SyncProgressReport(conduit) failed_report.metadata_state = constants.STATE_FAILED failed_call.return_value = failed_report progress_report = SyncProgressReport(conduit) progress_report.metadata_state = constants.STATE_FAILED mock_call.return_value = progress_report # test plugin = PuppetModuleImporter() report = plugin.sync_repo(repository, conduit, config) # validation mock_call.assert_called_with() self.assertEquals(report, conduit.build_failure_report.return_value)
def test_directory_synchronization(self, forge_call, mock_call): conduit = Mock() repository = Mock() config = {constants.CONFIG_FEED: 'http://host/tmp/%s' % constants.MANIFEST_FILENAME} progress_report = SyncProgressReport(conduit) progress_report.metadata_state = constants.STATE_SUCCESS progress_report.modules_state = constants.STATE_SUCCESS mock_call.return_value = progress_report # test plugin = PuppetModuleImporter() report = plugin.sync_repo(repository, conduit, config) # validation mock_call.assert_called_with() self.assertEquals(report, conduit.build_success_report.return_value) self.assertFalse(forge_call.called)