diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-16 16:58:22 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-16 16:58:22 +0000 |
commit | de9a3a22da70f3ae502fb5d50483954976e7ed68 (patch) | |
tree | 205e8c7518b0b505b923670e0dffacb338c28ab5 | |
parent | f01896e62672f71b04798c83752b36ccb628db67 (diff) | |
download | morph-de9a3a22da70f3ae502fb5d50483954976e7ed68.tar.gz |
TEMP
-rwxr-xr-x | morph-cache-server | 1 | ||||
-rwxr-xr-x | scripts/distbuild | 85 |
2 files changed, 70 insertions, 16 deletions
diff --git a/morph-cache-server b/morph-cache-server index c323bd93..fa5ed050 100755 --- a/morph-cache-server +++ b/morph-cache-server @@ -169,6 +169,7 @@ class MorphCacheServer(cliapp.Application): host = self._unescape_parameter(request.query.host) cacheid = self._unescape_parameter(request.query.cacheid) artifacts = self._unescape_parameter(request.query.artifacts) + logging.info('/fetch: %s %s %s', host, cacheid, artifacts) try: response.set_header('Cache-Control', 'no-cache') artifacts = artifacts.split(",") diff --git a/scripts/distbuild b/scripts/distbuild index df4e4dea..9e4991cd 100755 --- a/scripts/distbuild +++ b/scripts/distbuild @@ -34,9 +34,12 @@ will not be deleted when the process exits. ''' -DISTBUILD_HELPER = 'distbuild-helper' -MORPH = 'morph' -MORPH_CACHE_SERVER = 'morph-cache-server' +# Some hackz if you are running Morph from the source tree. +import os +os.environ['PYTHONPATH'] = '/src/morph' +DISTBUILD_HELPER = '/src/morph/distbuild-helper' +MORPH = '/src/morph/morph' +MORPH_CACHE_SERVER = '/src/morph/morph-cache-server' import os @@ -306,23 +309,59 @@ class DistbuildTestHarness(cliapp.Application): finally: self.process_monitor.terminate_all() - def start_cache_servers(self, workdir): - '''Start necessary artifact cache servers. + def cmd_build(self, args): + '''Start a distbuild network and run a single build on it.''' - There needs to be a shared artifact cache server. In a normal distbuild - setup this is part of the Trove system. + to_build = [ + ['baserock:baserock/definitions', + 'c7292b7c81cdd7e5b9e85722406371748453c44f', + 'systems/base-system-x86_64-generic.morph'] + ] * 2 - There is a separate cache server for all the workers. In a real - distbuild setup, each worker machine runs its own instance of - morph-cache-server. The controller uses the same port number for all - workers so in this test harness all workers will have to share one - cache-server process. + try: + datadir = self.settings['datadir'] or tempfile.mkdtemp() - It's not possible to use a single cache server process at present, - because when the /fetch method of the shared cache server is called, it - will break because it can't fetch stuff from itself. + worker_cache, shared_cache = self.start_cache_servers(datadir) - ''' + controller = self.start_distbuild_network( + datadir, worker_cache, shared_cache, + morph_instance=self.settings['morph-instance'], + n_workers=self.settings['workers']) + + print('Data in %s' % datadir) + + initiators = [] + + for i, triplet in enumerate(to_build): + initiator = self.start_build( + 'build-%i' % i, controller, triplet, + log_path=subdir(datadir, str(i))) + initiators.append(initiator) + self.process_monitor.watch(initiator) + + while not any(initiator.poll() for initiator in initiators): + select.select([], [], [], 0.1) + self.process_monitor.check_all() + + if any(initiator.returncode != 0 for initiator in initiators): + print('Initiator fail') + else: + print('Success!') + finally: + self.process_monitor.terminate_all() + print('Test state kept in %s' % datadir) + + def start_cache_servers(self, workdir): + # We have to make a bit of a kludge here. In a real distbuild setup, + # each worker machine runs its own instance of morph-cache-server on + # port 8080. The controller uses the same port number for all workers + # so in this test harness all workers will have to share one + # cache-server process. + # + # That's fine, but we still need a separate process for the *shared* + # artifact cache: artifacts are copied from workers to the shared cache + # using the /fetch method, which just wouldn't work if it had to fetch + # from itself. worker_cache = MorphCacheServerProcess( name='worker-cache-server', cache_path=subdir(workdir, 'worker-cache'), @@ -411,13 +450,27 @@ class DistbuildTestHarness(cliapp.Application): }, log_path=workdir ) + self.process_monitor.watch(controller_helper) # Need to wait for controller-helper to connect to controller. time.sleep(0.1) + self.process_monitor.check_all() return controller + def start_build(self, name, controller, to_build, log_path): + port = controller.controller_initiator_port + return MorphProcess( + name=name, + argv=[MORPH, 'distbuild-morphology'] + to_build, + settings={ + 'controller-initiator-address': 'localhost', + 'controller-initiator-port': port, + 'initiator-step-output-dir': log_path, + }, + log_path=log_path) + DistbuildTestHarness().run() |