Пример #1
0
    def testException(self):
        self.setup_step(
            transfer.DirectoryUpload(workersrc='srcdir',
                                     masterdest=self.destdir))

        writers = []

        self.expect_commands(
            ExpectUploadDirectory(
                workersrc="srcdir",
                workdir='wkdir',
                blocksize=16384,
                compress=None,
                maxsize=None,
                writer=ExpectRemoteRef(
                    remotetransfer.DirectoryWriter)).upload_tar_file(
                        'fake.tar', {"test": "Hello world!"},
                        error=RuntimeError('uh oh'),
                        out_writers=writers))

        self.expect_outcome(result=EXCEPTION,
                            state_string="uploading srcdir (exception)")
        yield self.run_step()

        self.assertEqual(len(writers), 1)
        self.assertEqual(writers[0].cancel.called, True)

        self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
Пример #2
0
    def testException(self):
        self.setupStep(
            transfer.DirectoryUpload(slavesrc='srcdir',
                                     masterdest=self.destdir))

        behavior = UploadError(uploadTarFile('fake.tar', test="Hello world!"))

        self.expectCommands(
            Expect(
                'uploadDirectory',
                dict(slavesrc="srcdir",
                     workdir='wkdir',
                     blocksize=16384,
                     compress=None,
                     maxsize=None,
                     writer=ExpectRemoteRef(transfer._DirectoryWriter))) +
            Expect.behavior(behavior))

        self.expectOutcome(result=EXCEPTION,
                           status_text=["upload", "exception"])
        d = self.runStep()

        @d.addCallback
        def check(_):
            self.assertEqual(behavior.writer.cancel.called, True)
            self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)

        return d
Пример #3
0
    def test_url_text(self):
        self.setup_step(
            transfer.DirectoryUpload(workersrc="srcdir",
                                     masterdest=self.destdir,
                                     url="http://server/dir",
                                     urlText='url text'))

        self.step.addURL = Mock()

        self.expect_commands(
            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 srcdir")

        yield self.run_step()

        self.step.addURL.assert_called_once_with("url text",
                                                 "http://server/dir")
Пример #4
0
    def test_init_workersrc_old_api_warns(self):
        with assertProducesWarning(
                DeprecatedWorkerNameWarning,
                message_pattern="'slavesrc' keyword argument is deprecated"):
            step = transfer.DirectoryUpload(slavesrc='srcfile',
                                            masterdest='dstfile')

        self.assertEqual(step.workersrc, 'srcfile')
Пример #5
0
    def test_workersrc_old_api(self):
        step = transfer.DirectoryUpload(workersrc='srcfile', masterdest='dstfile')

        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            new = step.workersrc

        with assertProducesWarning(
                DeprecatedWorkerNameWarning,
                message_pattern="'slavesrc' attribute is deprecated"):
            old = step.slavesrc

        self.assertIdentical(new, old)
Пример #6
0
    def testFailure(self):
        self.setupStep(
            transfer.DirectoryUpload(workersrc="srcdir", masterdest=self.destdir))

        self.expectCommands(
            Expect('uploadDirectory', dict(
                workersrc="srcdir", workdir='wkdir',
                blocksize=16384, compress=None, maxsize=None,
                writer=ExpectRemoteRef(remotetransfer.DirectoryWriter)))
            + 1)

        self.expectOutcome(result=FAILURE,
                           state_string="uploading srcdir (failure)")
        yield self.runStep()
Пример #7
0
    def testFailure(self):
        self.setupStep(
            transfer.DirectoryUpload(slavesrc="srcdir", masterdest=self.destdir))

        self.expectCommands(
            Expect('uploadDirectory', dict(
                slavesrc="srcdir", workdir='wkdir',
                blocksize=16384, compress=None, maxsize=None,
                writer=ExpectRemoteRef(transfer._DirectoryWriter)))
            + 1)

        self.expectOutcome(result=FAILURE, status_text=["uploading", "srcdir"])
        d = self.runStep()
        return d
Пример #8
0
    def testBasic(self):
        self.setupStep(
            transfer.DirectoryUpload(slavesrc="srcdir", masterdest=self.destdir))

        self.expectCommands(
            Expect('uploadDirectory', dict(
                slavesrc="srcdir", workdir='wkdir',
                blocksize=16384, compress=None, maxsize=None,
                writer=ExpectRemoteRef(transfer._DirectoryWriter)))
            + Expect.behavior(uploadTarFile('fake.tar', test="Hello world!"))
            + 0)

        self.expectOutcome(result=SUCCESS, status_text=["uploading", "srcdir"])
        d = self.runStep()
        return d
Пример #9
0
    def testWorker2_16(self):
        self.setupStep(
            transfer.DirectoryUpload(workersrc="srcdir", masterdest=self.destdir),
            worker_version={'*': '2.16'})

        self.expectCommands(
            Expect('uploadDirectory', dict(
                slavesrc="srcdir", workdir='wkdir',
                blocksize=16384, compress=None, maxsize=None,
                writer=ExpectRemoteRef(remotetransfer.DirectoryWriter)))
            + Expect.behavior(uploadTarFile('fake.tar', test="Hello world!"))
            + 0)

        self.expectOutcome(result=SUCCESS,
                           state_string="uploading srcdir")
        d = self.runStep()
        return d
Пример #10
0
    def test_url_text(self):
        self.setupStep(transfer.DirectoryUpload(workersrc="srcdir", masterdest=self.destdir,
                                                url="http://server/dir", urlText='url text'))

        self.step.addURL = Mock()

        self.expectCommands(
            Expect('uploadDirectory', {'workersrc': 'srcdir', 'workdir': 'wkdir',
                                       'blocksize': 16384, 'compress': None, 'maxsize': None,
                                       'writer': ExpectRemoteRef(remotetransfer.DirectoryWriter)})
            + Expect.behavior(uploadTarFile('fake.tar', test="Hello world!"))
            + 0)

        self.expectOutcome(result=SUCCESS,
                           state_string="uploading srcdir")

        yield self.runStep()

        self.step.addURL.assert_called_once_with("url text", "http://server/dir")
Пример #11
0
    def testWorker2_16(self):
        self.setup_step(transfer.DirectoryUpload(workersrc="srcdir",
                                                 masterdest=self.destdir),
                        worker_version={'*': '2.16'})

        self.expect_commands(
            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 srcdir")
        d = self.run_step()
        return d
Пример #12
0
    def testException(self):
        self.setupStep(
            transfer.DirectoryUpload(workersrc='srcdir', masterdest=self.destdir))

        behavior = UploadError(uploadTarFile('fake.tar', test="Hello world!"))

        self.expectCommands(
            Expect('uploadDirectory', dict(
                workersrc="srcdir", workdir='wkdir',
                blocksize=16384, compress=None, maxsize=None,
                writer=ExpectRemoteRef(remotetransfer.DirectoryWriter)))
            + Expect.behavior(behavior))

        self.expectOutcome(
            result=EXCEPTION,
            state_string="uploading srcdir (exception)")
        yield self.runStep()

        self.assertEqual(behavior.writer.cancel.called, True)
        self.assertEqual(
            len(self.flushLoggedErrors(RuntimeError)), 1)
Пример #13
0
    def testBasic(self):
        self.setupStep(
            transfer.DirectoryUpload(slavesrc="srcdir", masterdest=self.destdir))

        def upload_behavior(command):
            from cStringIO import StringIO
            f = StringIO()
            archive = tarfile.TarFile(fileobj=f, name='fake.tar', mode='w')
            archive.addfile(tarfile.TarInfo("test"), StringIO("Hello World!"))
            writer = command.args['writer']
            writer.remote_write(f.getvalue())
            writer.remote_unpack()

        self.expectCommands(
            Expect('uploadDirectory', dict(
                slavesrc="srcdir", workdir='wkdir',
                blocksize=16384, compress=None, maxsize=None,
                writer=ExpectRemoteRef(transfer._DirectoryWriter)))
            + Expect.behavior(upload_behavior)
            + 0)

        self.expectOutcome(result=SUCCESS, status_text=["uploading", "srcdir"])
        d = self.runStep()
        return d
Пример #14
0
 def test_init_positional_args(self):
     self.assertRaises(TypeError, lambda: transfer.DirectoryUpload())
     self.assertRaises(TypeError, lambda: transfer.DirectoryUpload('src'))
Пример #15
0
    def test_init_workersrc_positional(self):
        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            step = transfer.DirectoryUpload('srcfile', 'dstfile')

        self.assertEqual(step.workersrc, 'srcfile')
Пример #16
0
    def test_init_workersrc_keyword(self):
        step = transfer.DirectoryUpload(
            workersrc='srcfile', masterdest='dstfile')

        self.assertEqual(step.workersrc, 'srcfile')
Пример #17
0
    def test_init_workersrc_new_api_no_warns(self):
        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            step = transfer.DirectoryUpload(workersrc='srcfile',
                                            masterdest='dstfile')

        self.assertEqual(step.workersrc, 'srcfile')
Пример #18
0
    def test_init_workersrc_positional(self):
        step = transfer.DirectoryUpload('srcfile', 'dstfile')

        self.assertEqual(step.workersrc, 'srcfile')
Пример #19
0
 def test_init_positional_args(self):
     with self.assertRaises(TypeError):
         transfer.DirectoryUpload()
     with self.assertRaises(TypeError):
         transfer.DirectoryUpload('src')