[Buildbot-commits] buildbot/buildbot/test runutils.py, 1.16, 1.17 test_transfer.py, 1.3, 1.4

Brian Warner warner at users.sourceforge.net
Sat Dec 9 09:16:38 UTC 2006


Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28528/buildbot/test

Modified Files:
	runutils.py test_transfer.py 
Log Message:
[project @ cleanup/enhance transfer.FileUpload/FileDownload]

Original author: warner at lothar.com
Date: 2006-12-09 09:13:31

Index: runutils.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/runutils.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- runutils.py	17 Sep 2006 20:35:49 -0000	1.16
+++ runutils.py	9 Dec 2006 09:16:36 -0000	1.17
@@ -229,6 +229,10 @@
     s3.stepStarted()
     return s3
 
+def fake_slaveVersion(command, oldversion=None):
+    from buildbot.slave.registry import commandRegistry
+    return commandRegistry[command]
+
 def makeBuildStep(basedir, step_class=BuildStep, **kwargs):
     bss = setupBuildStepStatus(basedir)
 
@@ -242,6 +246,7 @@
     s = step_class(build=b, **kwargs)
     s.setStepStatus(bss)
     b.setupStatus(bss.getBuild())
+    s.slaveVersion = fake_slaveVersion
     return s
 
 

Index: test_transfer.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_transfer.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- test_transfer.py	24 Nov 2006 07:19:40 -0000	1.3
+++ test_transfer.py	9 Dec 2006 09:16:36 -0000	1.4
@@ -1,6 +1,7 @@
 # -*- test-case-name: buildbot.test.test_transfer -*-
 
 import os
+from stat import ST_MODE
 from twisted.trial import unittest
 from buildbot.twcompat import maybeWait
 from buildbot.steps.transfer import FileUpload, FileDownload
@@ -20,8 +21,8 @@
         return args
 
     def testSuccess(self):
-        self.slavebase = "testUpload.slave"
-        self.masterbase = "testUpload.master"
+        self.slavebase = "Upload.testSuccess.slave"
+        self.masterbase = "Upload.testSuccess.master"
         sb = self.makeSlaveBuilder()
         os.mkdir(os.path.join(self.slavebase, self.slavebuilderbase,
                               "build"))
@@ -37,6 +38,77 @@
                                 self.slavebuilderbase,
                                 "build",
                                 "source.txt")
+        contents = "this is the source file\n" * 1000
+        open(slavesrc, "w").write(contents)
+        f = open(masterdest, "w")
+        f.write("overwrite me\n")
+        f.close()
+
+        d = self.runStep(step)
+        def _checkUpload(results):
+            step_status = step.step_status
+            #l = step_status.getLogs()
+            #if l:
+            #    logtext = l[0].getText()
+            #    print logtext
+            self.failUnlessEqual(results, SUCCESS)
+            self.failUnless(os.path.exists(masterdest))
+            masterdest_contents = open(masterdest, "r").read()
+            self.failUnlessEqual(masterdest_contents, contents)
+        d.addCallback(_checkUpload)
+        return maybeWait(d)
+
+    def testMaxsize(self):
+        self.slavebase = "Upload.testMaxsize.slave"
+        self.masterbase = "Upload.testMaxsize.master"
+        sb = self.makeSlaveBuilder()
+        os.mkdir(os.path.join(self.slavebase, self.slavebuilderbase,
+                              "build"))
+        masterdest = os.path.join(self.masterbase, "dest2.text")
+        step = self.makeStep(FileUpload,
+                             slavesrc="source.txt",
+                             masterdest=masterdest,
+                             maxsize=12345)
+        slavesrc = os.path.join(self.slavebase,
+                                self.slavebuilderbase,
+                                "build",
+                                "source.txt")
+        contents = "this is the source file\n" * 1000
+        open(slavesrc, "w").write(contents)
+        f = open(masterdest, "w")
+        f.write("overwrite me\n")
+        f.close()
+
+        d = self.runStep(step)
+        def _checkUpload(results):
+            step_status = step.step_status
+            #l = step_status.getLogs()
+            #if l:
+            #    logtext = l[0].getText()
+            #    print logtext
+            self.failUnlessEqual(results, FAILURE)
+            self.failUnless(os.path.exists(masterdest))
+            masterdest_contents = open(masterdest, "r").read()
+            self.failUnlessEqual(len(masterdest_contents), 12345)
+            self.failUnlessEqual(masterdest_contents, contents[:12345])
+        d.addCallback(_checkUpload)
+        return maybeWait(d)
+
+    def testMode(self):
+        self.slavebase = "Upload.testMode.slave"
+        self.masterbase = "Upload.testMode.master"
+        sb = self.makeSlaveBuilder()
+        os.mkdir(os.path.join(self.slavebase, self.slavebuilderbase,
+                              "build"))
+        masterdest = os.path.join(self.masterbase, "dest3.text")
+        step = self.makeStep(FileUpload,
+                             slavesrc="source.txt",
+                             masterdest=masterdest,
+                             mode=0755)
+        slavesrc = os.path.join(self.slavebase,
+                                self.slavebuilderbase,
+                                "build",
+                                "source.txt")
         contents = "this is the source file\n"
         open(slavesrc, "w").write(contents)
         f = open(masterdest, "w")
@@ -54,17 +126,22 @@
             self.failUnless(os.path.exists(masterdest))
             masterdest_contents = open(masterdest, "r").read()
             self.failUnlessEqual(masterdest_contents, contents)
+            # and with 0777 to ignore sticky bits
+            dest_mode = os.stat(masterdest)[ST_MODE] & 0777
+            self.failUnlessEqual(dest_mode, 0755,
+                                 "target mode was %o, we wanted %o" %
+                                 (dest_mode, 0755))
         d.addCallback(_checkUpload)
         return maybeWait(d)
 
     def testMissingFile(self):
-        self.slavebase = "testUploadMissingFile.slave"
-        self.masterbase = "testUploadMissingFile.master"
+        self.slavebase = "Upload.testMissingFile.slave"
+        self.masterbase = "Upload.testMissingFile.master"
         sb = self.makeSlaveBuilder()
         step = self.makeStep(FileUpload,
                              slavesrc="MISSING.txt",
                              masterdest="dest.txt")
-        masterdest = os.path.join(self.masterbase, "dest.txt")
+        masterdest = os.path.join(self.masterbase, "dest4.txt")
 
         d = self.runStep(step)
         def _checkUpload(results):
@@ -88,8 +165,8 @@
         return args
 
     def testSuccess(self):
-        self.slavebase = "testDownload.slave"
-        self.masterbase = "testDownload.master"
+        self.slavebase = "Download.testSuccess.slave"
+        self.masterbase = "Download.testSuccess.master"
         sb = self.makeSlaveBuilder()
         os.mkdir(os.path.join(self.slavebase, self.slavebuilderbase,
                               "build"))
@@ -101,6 +178,70 @@
         step = self.makeStep(FileDownload,
                              mastersrc=mastersrc,
                              slavedest="dest.txt")
+        contents = "this is the source file\n" * 1000  # 24kb, so two blocks
+        open(mastersrc, "w").write(contents)
+        f = open(slavedest, "w")
+        f.write("overwrite me\n")
+        f.close()
+
+        d = self.runStep(step)
+        def _checkDownload(results):
+            step_status = step.step_status
+            self.failUnlessEqual(results, SUCCESS)
+            self.failUnless(os.path.exists(slavedest))
+            slavedest_contents = open(slavedest, "r").read()
+            self.failUnlessEqual(slavedest_contents, contents)
+        d.addCallback(_checkDownload)
+        return maybeWait(d)
+
+    def testMaxsize(self):
+        self.slavebase = "Download.testMaxsize.slave"
+        self.masterbase = "Download.testMaxsize.master"
+        sb = self.makeSlaveBuilder()
+        os.mkdir(os.path.join(self.slavebase, self.slavebuilderbase,
+                              "build"))
+        mastersrc = os.path.join(self.masterbase, "source.text")
+        slavedest = os.path.join(self.slavebase,
+                                 self.slavebuilderbase,
+                                 "build",
+                                 "dest.txt")
+        step = self.makeStep(FileDownload,
+                             mastersrc=mastersrc,
+                             slavedest="dest.txt",
+                             maxsize=12345)
+        contents = "this is the source file\n" * 1000  # 24kb, so two blocks
+        open(mastersrc, "w").write(contents)
+        f = open(slavedest, "w")
+        f.write("overwrite me\n")
+        f.close()
+
+        d = self.runStep(step)
+        def _checkDownload(results):
+            step_status = step.step_status
+            # the file should be truncated, and the step a FAILURE
+            self.failUnlessEqual(results, FAILURE)
+            self.failUnless(os.path.exists(slavedest))
+            slavedest_contents = open(slavedest, "r").read()
+            self.failUnlessEqual(len(slavedest_contents), 12345)
+            self.failUnlessEqual(slavedest_contents, contents[:12345])
+        d.addCallback(_checkDownload)
+        return maybeWait(d)
+
+    def testMode(self):
+        self.slavebase = "Download.testMode.slave"
+        self.masterbase = "Download.testMode.master"
+        sb = self.makeSlaveBuilder()
+        os.mkdir(os.path.join(self.slavebase, self.slavebuilderbase,
+                              "build"))
+        mastersrc = os.path.join(self.masterbase, "source.text")
+        slavedest = os.path.join(self.slavebase,
+                                 self.slavebuilderbase,
+                                 "build",
+                                 "dest.txt")
+        step = self.makeStep(FileDownload,
+                             mastersrc=mastersrc,
+                             slavedest="dest.txt",
+                             mode=0755)
         contents = "this is the source file\n"
         open(mastersrc, "w").write(contents)
         f = open(slavedest, "w")
@@ -114,12 +255,17 @@
             self.failUnless(os.path.exists(slavedest))
             slavedest_contents = open(slavedest, "r").read()
             self.failUnlessEqual(slavedest_contents, contents)
+            # and with 0777 to ignore sticky bits
+            dest_mode = os.stat(slavedest)[ST_MODE] & 0777
+            self.failUnlessEqual(dest_mode, 0755,
+                                 "target mode was %o, we wanted %o" %
+                                 (dest_mode, 0755))
         d.addCallback(_checkDownload)
         return maybeWait(d)
 
     def testMissingFile(self):
-        self.slavebase = "testDownloadMissingFile.slave"
-        self.masterbase = "testDownloadMissingFile.master"
+        self.slavebase = "Download.testMissingFile.slave"
+        self.masterbase = "Download.testMissingFile.master"
         sb = self.makeSlaveBuilder()
         os.mkdir(os.path.join(self.slavebase, self.slavebuilderbase,
                               "build"))
@@ -140,17 +286,14 @@
             l = step_status.getLogs()
             logtext = l[0].getText().strip()
             self.failUnless(logtext.endswith(" not available at master"))
-        d.addCallback(_checkDownload)
-        return maybeWait(d)
+        d.addCallbacks(_checkDownload)
 
+        return maybeWait(d)
 
 
 # TODO:
-#  test relative paths
+#  test relative paths, ~/paths
 #   need to implement expanduser() for slave-side
 #  test error message when master-side file is in a missing directory
-#  test maxsize=
 #  remove workdir= default?
-#  clean up command start/finish code
-#  detect slave-too-old
 





More information about the Commits mailing list