def getScript(self, test_args=None): """Return an ArchivePopulator instance.""" if test_args is None: test_args = [] script = ArchivePopulator("test copy archives", test_args=test_args) script.logger = BufferLogger() script.txn = self.layer.txn return script
def runScript( self, archive_name=None, suite='hoary', user='******', exists_before=None, exists_after=None, exception_type=None, exception_text=None, extra_args=None, copy_archive_name=None, reason=None, output_substr=None, nonvirtualized=False): """Run the script to test. :type archive_name: `str` :param archive_name: the name of the copy archive to create. :type suite: `str` :param suite: the name of the copy archive suite. :type user: `str` :param user: the name of the user creating the archive. :type exists_before: `bool` :param exists_before: copy archive with given name should already exist if True. :type exists_after: `True` :param exists_after: the copy archive is expected to exist after script invocation if True. :type exception_type: type :param exception_type: the type of exception expected in case of failure. :type exception_text: `str` :param exception_text: expected exception text prefix in case of failure. :type extra_args: list of strings :param extra_args: additional arguments to be passed to the script (if any). :type copy_archive_name: `IArchive` :param copy_archive_name: optional copy archive instance, used for merge copy testing. :param reason: if empty do not provide '--reason' cmd line arg to the script :param output_substr: this must be part of the script's output """ if copy_archive_name is None: now = int(time.time()) if archive_name is None: archive_name = "ra%s" % now else: archive_name = copy_archive_name distro_name = 'ubuntu' distro = getUtility(IDistributionSet).getByName(distro_name) copy_archive = getUtility(IArchiveSet).getByDistroPurpose( distro, ArchivePurpose.COPY, archive_name) # Enforce these assertions only if the 'exists_before' flag was # specified in first place. if exists_before is not None: if exists_before: self.assertTrue(copy_archive is not None) else: self.assertTrue(copy_archive is None) # Command line arguments required for the invocation of the # 'populate-archive.py' script. script_args = [ '--from-distribution', distro_name, '--from-suite', suite, '--to-distribution', distro_name, '--to-suite', suite, '--to-archive', archive_name, '--to-user', user, ] # Empty reason string indicates that the '--reason' command line # argument should be ommitted. if reason is not None and not reason.isspace(): script_args.extend(['--reason', reason]) elif reason is None: reason = "copy archive, %s" % datetime.ctime(datetime.utcnow()) script_args.extend(['--reason', reason]) if nonvirtualized: script_args.append('--nonvirtualized') if extra_args is not None: script_args.extend(extra_args) script = ArchivePopulator( 'populate-archive', dbuser=config.uploader.dbuser, test_args=script_args) script.logger = BufferLogger() script.txn = FakeTransaction() if exception_type is not None: self.assertRaisesWithContent( exception_type, exception_text, script.mainTask) else: script.mainTask() # Does the script's output contain the specified sub-string? if output_substr is not None and not output_substr.isspace(): output = script.logger.getLogBuffer() self.assertTrue(output_substr in output) copy_archive = getUtility(IArchiveSet).getByDistroPurpose( distro, ArchivePurpose.COPY, archive_name) # Enforce these assertions only if the 'exists_after' flag was # specified in first place. if exists_after is not None: if exists_after: self.assertTrue(copy_archive is not None) else: self.assertTrue(copy_archive is None) return copy_archive