def testMultipleWorker2_16(self): self.setup_step(transfer.MultipleFileUpload( workersrcs=["srcfile", "srcdir"], masterdest=self.destdir), worker_version={'*': '2.16'}) self.expect_commands( ExpectStat(file="srcfile", workdir='wkdir').stat_file().exit(0), ExpectUploadFile(slavesrc="srcfile", workdir='wkdir', blocksize=16384, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0), ExpectStat(file="srcdir", workdir='wkdir').stat_dir().exit(0), ExpectUploadDirectory( slavesrc="srcdir", workdir='wkdir', blocksize=16384, compress=None, maxsize=None, writer=ExpectRemoteRef( remotetransfer.DirectoryWriter)).upload_tar_file( 'fake.tar', { "test": "Hello world!" }).exit(0)) self.expect_outcome(result=SUCCESS, state_string="uploading 2 files") d = self.run_step() return d
def testException(self): self.setup_step( transfer.MultipleFileUpload(workersrcs=["srcfile", "srcdir"], masterdest=self.destdir)) writers = [] self.expect_commands( ExpectStat(file="srcfile", workdir='wkdir').stat_file().exit(0), ExpectUploadFile(workersrc="srcfile", workdir='wkdir', blocksize=16384, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n", out_writers=writers, error=RuntimeError('uh oh'))) self.expect_outcome(result=EXCEPTION, state_string="uploading 2 files (exception)") yield self.run_step() self.assertEqual(len(writers), 1) self.assertEqual(writers[0].cancel.called, True) self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
def test_url_text(self): self.setup_step( transfer.MultipleFileUpload(workersrcs=["srcfile"], masterdest=self.destdir, url="http://server/dir", urlText='url text')) self.step.addURL = Mock() self.expect_commands( ExpectStat(file='srcfile', workdir='wkdir').stat_file().exit(0), ExpectUploadFile(workersrc='srcfile', workdir='wkdir', blocksize=16384, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0)) self.expect_outcome(result=SUCCESS, state_string="uploading 1 file") yield self.run_step() self.step.addURL.assert_called_once_with("url text", "http://server/dir")
def testURLText(self): self.setup_step( transfer.FileUpload(workersrc=__file__, masterdest=self.destfile, url="http://server/file", urlText="testfile")) self.step.addURL = Mock() self.expect_commands( ExpectUploadFile(workersrc=__file__, workdir='wkdir', blocksize=262144, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0)) self.expect_outcome( result=SUCCESS, state_string=f"uploading {os.path.basename(__file__)}") yield self.run_step() self.step.addURL.assert_called_once_with("testfile", "http://server/file")
def testTimestamp(self): self.setup_step( transfer.FileUpload(workersrc=__file__, masterdest=self.destfile, keepstamp=True)) timestamp = (os.path.getatime(__file__), os.path.getmtime(__file__)) self.expect_commands( ExpectUploadFile(workersrc=__file__, workdir='wkdir', blocksize=262144, maxsize=None, keepstamp=True, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( 'test\n', timestamp=timestamp).exit(0)) self.expect_outcome( result=SUCCESS, state_string=f"uploading {os.path.basename(__file__)}") yield self.run_step() desttimestamp = (os.path.getatime(self.destfile), os.path.getmtime(self.destfile)) srctimestamp = [int(t) for t in timestamp] desttimestamp = [int(d) for d in desttimestamp] self.assertEqual(srctimestamp[0], desttimestamp[0]) self.assertEqual(srctimestamp[1], desttimestamp[1])
def testSubclass(self): class CustomStep(transfer.MultipleFileUpload): uploadDone = Mock(return_value=None) allUploadsDone = Mock(return_value=None) step = CustomStep(workersrcs=["srcfile", "srcdir"], masterdest=self.destdir) self.setup_step(step) self.expect_commands( ExpectStat(file="srcfile", workdir='wkdir').stat_file().exit(0), ExpectUploadFile(workersrc="srcfile", workdir='wkdir', blocksize=16384, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0), ExpectStat(file="srcdir", workdir='wkdir').stat_dir().exit(0), ExpectUploadDirectory( workersrc="srcdir", workdir='wkdir', blocksize=16384, compress=None, maxsize=None, writer=ExpectRemoteRef( remotetransfer.DirectoryWriter)).upload_tar_file( 'fake.tar', { "test": "Hello world!" }).exit(0)) self.expect_outcome(result=SUCCESS, state_string="uploading 2 files") yield self.run_step() self.assertEqual(step.uploadDone.call_count, 2) self.assertEqual( step.uploadDone.call_args_list[0], ((SUCCESS, 'srcfile', os.path.join(self.destdir, 'srcfile')), {})) self.assertEqual( step.uploadDone.call_args_list[1], ((SUCCESS, 'srcdir', os.path.join(self.destdir, 'srcdir')), {})) self.assertEqual(step.allUploadsDone.call_count, 1) self.assertEqual(step.allUploadsDone.call_args_list[0], ((SUCCESS, ['srcfile', 'srcdir'], self.destdir), {}))
def testBasic(self): self.setup_step( transfer.FileUpload(workersrc='srcfile', masterdest=self.destfile)) self.expect_commands( ExpectUploadFile(workersrc="srcfile", workdir='wkdir', blocksize=262144, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0)) self.expect_outcome(result=SUCCESS, state_string="uploading srcfile") d = self.run_step() return d
def testMultipleString(self): self.setup_step( transfer.MultipleFileUpload(workersrcs="srcfile", masterdest=self.destdir)) self.expect_commands( ExpectStat(file="srcfile", workdir='wkdir').stat_file().exit(0), ExpectUploadFile(workersrc="srcfile", workdir='wkdir', blocksize=16384, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0)) self.expect_outcome(result=SUCCESS, state_string="uploading 1 file") d = self.run_step() return d
def testFailure(self): self.setup_step( transfer.FileUpload(workersrc='srcfile', masterdest=self.destfile)) self.expect_commands( ExpectUploadFile(workersrc="srcfile", workdir='wkdir', blocksize=262144, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).exit(1)) self.expect_outcome(result=FAILURE, state_string="uploading srcfile (failure)") d = self.run_step() return d
def test_getFileContentFromWorker2_16(self): @defer.inlineCallbacks def testFunc(x): res = yield x.getFileContentFromWorker("file.txt") self.assertEqual(res, "Hello world!") self.setup_step(CompositeUser(testFunc), worker_version={'*': '2.16'}) self.expect_commands( ExpectUploadFile( slavesrc="file.txt", workdir='wkdir', blocksize=32 * 1024, maxsize=None, writer=ExpectRemoteRef( remotetransfer.StringFileWriter)).upload_string( "Hello world!").exit(0)) self.expect_outcome(result=SUCCESS) return self.run_step()
def do_test_suppressions(self, step, supps_file='', stdout='', exp_warning_count=0, exp_warning_log='', exp_exception=False, props=None): self.setup_step(step) if props is not None: for key in props: self.build.setProperty(key, props[key], "") if supps_file is not None: self.expect_commands( # step will first get the remote suppressions file ExpectUploadFile(blocksize=32768, maxsize=None, workersrc='supps', workdir='wkdir', writer=ExpectRemoteRef( remotetransfer.StringFileWriter) ).upload_string(supps_file).exit(0), # and then run the command ExpectShell(workdir='wkdir', command=["make"]).stdout(stdout).exit(0)) else: self.expect_commands( ExpectShell(workdir='wkdir', command=["make"]).stdout(stdout).exit(0)) if exp_exception: self.expect_outcome(result=EXCEPTION, state_string="'make' (exception)") else: if exp_warning_count != 0: self.expect_outcome(result=WARNINGS, state_string="'make' (warnings)") self.expect_log_file(f"warnings ({exp_warning_count})", exp_warning_log) else: self.expect_outcome(result=SUCCESS, state_string="'make'") self.expect_property("warnings-count", exp_warning_count) return self.run_step()
def testFailure(self): self.setup_step( transfer.MultipleFileUpload(workersrcs=["srcfile", "srcdir"], masterdest=self.destdir)) self.expect_commands( ExpectStat(file="srcfile", workdir='wkdir').stat_file().exit(0), ExpectUploadFile(workersrc="srcfile", workdir='wkdir', blocksize=16384, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).exit(1)) self.expect_outcome(result=FAILURE, state_string="uploading 2 files (failure)") d = self.run_step() return d
def test_interrupt(self): self.setup_step( transfer.FileUpload(workersrc='srcfile', masterdest=self.destfile)) self.expect_commands( ExpectUploadFile(workersrc='srcfile', workdir='wkdir', blocksize=262144, maxsize=None, keepstamp=False, writer=ExpectRemoteRef(remotetransfer.FileWriter), interrupted=True).exit(0)) self.interrupt_nth_remote_command(0) self.expect_outcome(result=CANCELLED, state_string="uploading srcfile (cancelled)") self.expect_log_file('interrupt', 'interrupt reason') yield self.run_step()
def testGlob(self): self.setup_step( transfer.MultipleFileUpload(workersrcs=["src*"], masterdest=self.destdir, glob=True)) self.expect_commands( ExpectGlob(path=os.path.join('wkdir', 'src*'), log_environ=False).files(["srcfile"]).exit(0), ExpectStat(file="srcfile", workdir='wkdir').stat_file().exit(0), ExpectUploadFile(workersrc="srcfile", workdir='wkdir', blocksize=16384, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0)) self.expect_outcome(result=SUCCESS, state_string="uploading 1 file") d = self.run_step() return d
def testDescriptionDone(self): self.setup_step( transfer.FileUpload(workersrc=__file__, masterdest=self.destfile, url="http://server/file", descriptionDone="Test File Uploaded")) self.step.addURL = Mock() self.expect_commands( ExpectUploadFile(workersrc=__file__, workdir='wkdir', blocksize=262144, maxsize=None, keepstamp=False, writer=ExpectRemoteRef( remotetransfer.FileWriter)).upload_string( "Hello world!\n").exit(0)) self.expect_outcome(result=SUCCESS, state_string="Test File Uploaded") d = self.run_step() return d