Fixed md5 calculation
authorAleksey Maksimov <ctpeko3a@gmail.com>
Wed, 23 Apr 2014 13:07:07 +0000 (21:07 +0800)
committerAleksey Maksimov <ctpeko3a@gmail.com>
Fri, 25 Apr 2014 13:54:53 +0000 (21:54 +0800)
jenkinsapi/api.py
jenkinsapi/artifact.py
jenkinsapi/build.py
jenkinsapi_tests/systests/job_configs.py
jenkinsapi_tests/systests/test_downstream_upstream.py
jenkinsapi_tests/systests/test_jenkins_artifacts.py
jenkinsapi_tests/systests/test_parameterized_builds.py

index 283f7ad7a83900e86a2ecbdd626402a5d639c73b..c191907136db774fa6ca80f802f9f7d52f96fc70 100644 (file)
@@ -132,7 +132,7 @@ def block_until_complete(jenkinsurl, jobs, maxwait=12000, interval=30,
 
     obj_jenkins = Jenkins(jenkinsurl, username=username, password=password)
     obj_jobs = [obj_jenkins[jid] for jid in jobs]
-    for time_left in xrange(maxwait, 0, -interval):
+    for time_left in range(maxwait, 0, -interval):
         still_running = [j for j in obj_jobs if j.is_queued_or_running()]
         if not still_running:
             return
@@ -191,7 +191,7 @@ def install_artifacts(artifacts, dirstruct, installdir, basestaticurl):
                 # It's probably a static file,
                 # we can get it from the static collection
                 staticurl = urlparse.urljoin(basestaticurl, artifactname)
-                theartifact = Artifact(artifactname, staticurl)
+                theartifact = Artifact(artifactname, staticurl, None)
             theartifact.save(destpath)
             installed.append(destpath)
     return installed
index b84dac91a628541ef3bca93058e9764dbd7f70ad..0490bf103a3892e3161ec982d9f78b4911006207 100644 (file)
@@ -93,7 +93,10 @@ class Artifact(object):
         try:
             with open(fspath, 'rb') as f:
                 for chunk in iter(lambda: f.read(chunksize), ''):
-                    md5.update(chunk)
+                    if chunk:
+                        md5.update(chunk)
+                    else:
+                        break
         except:
             raise
         return md5.hexdigest()
index d150cc5df55cdabeec1bb3dc5faa1cdf25f9aae5..a235531cc72ae797e70d9850c429e0aafd2dcd13 100644 (file)
@@ -364,7 +364,7 @@ class Build(JenkinsBase):
         Return the current state of the text console.
         """
         url = "%s/consoleText" % self.baseurl
-        return self.job.jenkins.requester.get_url(url).content
+        return self.job.jenkins.requester.get_url(url).content.decode('utf-8')
 
     def stop(self):
         """
index 15448e7b8c59f2181fc7fb2c1a015601f7293088..1cf58a6e32b972f29fc206abfcd6b6c16bb11d34 100644 (file)
@@ -38,7 +38,7 @@ LONG_RUNNING_JOB = """
   <concurrentBuild>false</concurrentBuild>
   <builders>
     <hudson.tasks.Shell>
-      <command>ping -c 200 localhost</command>
+      <command>ping -c 50 localhost</command>
     </hudson.tasks.Shell>
   </builders>
   <publishers/>
@@ -140,7 +140,7 @@ JOB_WITH_ARTIFACTS = """
   <concurrentBuild>false</concurrentBuild>
   <builders>
     <hudson.tasks.Shell>
-      <command>ping -c 5 localhost | tee out.txt
+      <command>ping -c 10 localhost | tee out.txt
 gzip &lt; out.txt &gt; out.gz</command>
     </hudson.tasks.Shell>
   </builders>
index df9c97f98e39037ca02e9314e42831af5feea47a..1d25205382a806dca6192177909221c49af4c720 100644 (file)
@@ -101,7 +101,7 @@ class TestDownstreamUpstream(BaseSystemTest):
 
         self.jenkins['A'].invoke()
 
-        for _ in xrange(10):
+        for _ in range(10):
             try:
                 self.jenkins['C'].get_last_completed_buildnumber() > 0
             except NoBuildData:
index 77755451b170206f4fd9c2480ebacda3ce8a997b..4de95a6d9df6a2b67302686cd9fb87b4009b3a13 100644 (file)
@@ -20,7 +20,7 @@ from jenkinsapi_tests.test_utils.random_strings import random_string
 
 class TestPingerJob(BaseSystemTest):
 
-    def test_invoke_job(self):
+    def test_artefacts(self):
         job_name = 'create_%s' % random_string()
         job = self.jenkins.create_job(job_name, JOB_WITH_ARTIFACTS)
         job.invoke(block=True)
@@ -41,14 +41,19 @@ class TestPingerJob(BaseSystemTest):
         try:
             # Verify that we can handle text artifacts
             text_artifact.save_to_dir(tempDir)
-            readBackText = open(os.path.join(
-                tempDir, text_artifact.filename), 'rb').read().strip()
+            readBackText = open(os.path.join(tempDir,
+                                             text_artifact.filename),
+                                'rb').read().strip()
+            readBackText = readBackText.decode('ascii')
             self.assertTrue(re.match(r'^PING \S+ \(127.0.0.1\)', readBackText))
             self.assertTrue(readBackText.endswith('ms'))
 
             # Verify that we can hande binary artifacts
             binary_artifact.save_to_dir(tempDir)
-            readBackText = gzip.open(os.path.join(tempDir, binary_artifact.filename,), 'rb').read().strip()
+            readBackText = gzip.open(os.path.join(tempDir,
+                                                  binary_artifact.filename,),
+                                     'rb').read().strip()
+            readBackText = readBackText.decode('ascii')
             self.assertTrue(re.match(r'^PING \S+ \(127.0.0.1\)', readBackText))
             self.assertTrue(readBackText.endswith('ms'))
         finally:
index d9bcc5dbafb5ec71b19cbb8b7186560524a65b7f..2c69cfde92cd67194099113790174ae4273fb65b 100644 (file)
@@ -7,7 +7,10 @@ try:
     import unittest2 as unittest
 except ImportError:
     import unittest
-from StringIO import StringIO
+try:
+    from StringIO import StringIO
+except ImportError:
+    from io import StringIO
 from jenkinsapi_tests.systests.base import BaseSystemTest
 from jenkinsapi_tests.test_utils.random_strings import random_string
 from jenkinsapi_tests.systests.job_configs import JOB_WITH_FILE
@@ -25,11 +28,11 @@ class TestParameterizedBuilds(BaseSystemTest):
         job = self.jenkins.create_job(job_name, JOB_WITH_FILE)
         job.invoke(block=True, files={'file.txt': param_file})
 
-        b = job.get_last_build()
-        while b.is_running():
+        build = job.get_last_build()
+        while build.is_running():
             time.sleep(0.25)
 
-        artifacts = b.get_artifact_dict()
+        artifacts = build.get_artifact_dict()
         self.assertIsInstance(artifacts, dict)
         art_file = artifacts['file.txt']
         self.assertTrue(art_file.get_data().strip(), file_data)
@@ -41,16 +44,16 @@ class TestParameterizedBuilds(BaseSystemTest):
         job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)
         job.invoke(block=True, build_params={'B': param_B})
 
-        b = job.get_last_build()
-        while b.is_running():
+        build = job.get_last_build()
+        while build.is_running():
             time.sleep(0.25)
 
-        artifacts = b.get_artifact_dict()
+        artifacts = build.get_artifact_dict()
         self.assertIsInstance(artifacts, dict)
         artB = artifacts['b.txt']
         self.assertTrue(artB.get_data().strip(), param_B)
 
-        self.assertIn(param_B, b.get_console())
+        self.assertIn(param_B, build.get_console())
 
     def test_parameterized_job_build_queuing(self):
         """Accept multiple builds of parameterized jobs with unique
@@ -66,19 +69,19 @@ class TestParameterizedBuilds(BaseSystemTest):
 
         self.assertTrue(job.has_queued_build(params))
 
-        while(job.has_queued_build(params)):
+        while job.has_queued_build(params):
             time.sleep(0.25)
 
-        b = job.get_last_build()
-        while b.is_running():
+        build = job.get_last_build()
+        while build.is_running():
             time.sleep(0.25)
 
-        artifacts = b.get_artifact_dict()
+        artifacts = build.get_artifact_dict()
         self.assertIsInstance(artifacts, dict)
         artB = artifacts['b.txt']
         self.assertTrue(artB.get_data().strip(), param_B)
 
-        self.assertIn(param_B, b.get_console())
+        self.assertIn(param_B, build.get_console())
 
     def test_parameterized_job_build_rejection(self):
         """Reject build of paramterized job when existing build with same