summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-20 12:49:41 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-27 11:53:02 +0000
commit4443bd116899e3e62bbd3e4ec8e3e767a08b0c9c (patch)
treeb685100df81169c2a8a2d54fae3890ba3a8ed0fd
parent7101a42e85cd793fe0bc450cbe184adc0fb9e776 (diff)
downloadmorph-4443bd116899e3e62bbd3e4ec8e3e767a08b0c9c.tar.gz
fix code for tests
Change-Id: I5106328eab0c7b472f6e5058787623bd049d1b8c
-rw-r--r--gear/client.py25
-rw-r--r--gear/worker.py22
2 files changed, 27 insertions, 20 deletions
diff --git a/gear/client.py b/gear/client.py
index 2da25571..d14edd31 100644
--- a/gear/client.py
+++ b/gear/client.py
@@ -26,11 +26,11 @@ class theController():
self.builder_client = BuilderClient(self)
self.cache_client = CacheRequestClient(self)
self.builder_client.addServer('localhost')
- self.builder_client.waitForServer() # Wait for at least one server to be connected
+ self.builder_client.waitForServer()
self.graph_client.addServer('localhost')
- self.graph_client.waitForServer() # Wait for at least one server to be connected
+ self.graph_client.waitForServer()
self.cache_client.addServer('localhost')
- self.cache_client.waitForServer() # Wait for at least one server to be connected
+ self.cache_client.waitForServer()
self.artifact = None
self.build_started = False
@@ -53,8 +53,6 @@ class theController():
print "Setting them as unbuilt"
self._map_build_graph(self.artifact, set_initial_state)
print "Setting them as unbuilt done"
- # TODO: check cache before marking as started:
- # http://stackoverflow.com/questions/9110593/asynchronous-requests-with-python-requests
self._check_cache_state(self.artifact)
@@ -107,13 +105,14 @@ class theController():
mapped_components.append(a)
return result, mapped_components
- def find_artifacts_that_are_ready_to_build(self, root_artifact, components=[]):
+ def find_artifacts_that_are_ready_to_build(self, root_artifact,
+ components=[]):
'''Return unbuilt artifacts whose dependencies are all built.
- The 'root_artifact' parameter is expected to be a tree of ArtifactReference
- objects. These must have the 'state' attribute set to BUILT or UNBUILT. If
- 'components' is passed, then only those artifacts and their dependencies
- will be built.
+ The 'root_artifact' parameter is expected to be a tree of
+ ArtifactReference objects. These must have the 'state' attribute set
+ to BUILT or UNBUILT. If 'components' is passed, then only those
+ artifacts and their dependencies will be built.
'''
def is_ready_to_build(artifact):
@@ -155,7 +154,7 @@ class theController():
# we're also building all the chunk artifacts
# in this source
same_chunk_artifacts = [a for a in artifacts
- if a.cache_key == artifact.cache_key]
+ if a.cache_key == artifact.cache_key]
for a in same_chunk_artifacts:
a.state = BUILDING
artifacts.remove(a)
@@ -285,6 +284,6 @@ while True:
import time
time.sleep(0.0001)
if controller.artifact != None and controller.build_started == True:
- to_build = controller.find_artifacts_that_are_ready_to_build(controller.artifact)
- #print to_build
+ to_build = controller.find_artifacts_that_are_ready_to_build(
+ controller.artifact)
controller._queue_worker_builds(to_build)
diff --git a/gear/worker.py b/gear/worker.py
index 55b4fa4c..222a5297 100644
--- a/gear/worker.py
+++ b/gear/worker.py
@@ -45,19 +45,25 @@ def upload_files(cache_key, suffixes):
print "DEBUG: start upload_files"
cache_dir = '/src/cache/artifacts'
remote_cache_dir = '/src/cache_server/'
- files_to_upload = [os.path.join(cache_dir, cache_key + '.' + suffix) for suffix in suffixes]
- with ssh_manager('127.0.0.1', 22, 'root', '/root/gerritbot/gerritbot_rsa') as client:
+ files_to_upload = [os.path.join(cache_dir,
+ cache_key + '.' + suffix)
+ for suffix in suffixes]
+ with ssh_manager('127.0.0.1', 22, 'root',
+ '/root/gerritbot/gerritbot_rsa') as client:
sftp = client.open_sftp()
for single_file in files_to_upload:
- remote_dest = os.path.join(remote_cache_dir, os.path.basename(single_file))
- remote_dest_tmp = os.path.join(remote_cache_dir, os.path.basename(single_file) + '.tmp')
+ remote_dest = os.path.join(remote_cache_dir,
+ os.path.basename(single_file))
+ remote_dest_tmp = os.path.join(remote_cache_dir,
+ os.path.basename(single_file)
+ + '.tmp')
print "DEBUG: going to upload %s" % single_file
print "DEBUG: upload destination %s" % remote_dest
try:
sftp.stat(remote_dest)
print "DEBUG: file already exists"
return
- except:
+ except IOError:
print "DEBUG: file not found in cache, uploading"
sftp.put(single_file, remote_dest_tmp)
sftp.rename(remote_dest_tmp, remote_dest)
@@ -78,10 +84,12 @@ while True:
bg_request['ref'],
bg_request['system'])
# TODO: There should be another way of doing this.
- cmd = ['morph', 'calculate-build-graph', '--quiet', bg_request['repo'], bg_request['ref'], bg_request['system']]
+ cmd = ['morph', 'calculate-build-graph', '--quiet',
+ bg_request['repo'], bg_request['ref'], bg_request['system']]
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
output = p.stdout.read()
- # TODO: catch errors calculating build-graph here instead of sending the error as build-graph :)
+ # TODO: catch errors calculating build-graph here instead of sending
+ # the error as build-graph :)
print "DEBUG: finished computing build graph"
job.sendWorkComplete(output)
elif job.name == "build-artifact":