diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-04-09 14:44:52 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-04-09 14:44:52 +0300 |
commit | 5fca00b7aadbd5d3f52dca3fdc7f0c084d9e3136 (patch) | |
tree | 0934832ff76183e4d85d9bf13105516e2ef5dc38 /contractor | |
parent | b290bdfed8232056b87d6a96c158cf31dc21b6d9 (diff) | |
download | ick-contractor-5fca00b7aadbd5d3f52dca3fdc7f0c084d9e3136.tar.gz |
Fix random things
Diffstat (limited to 'contractor')
-rwxr-xr-x | contractor | 53 |
1 files changed, 30 insertions, 23 deletions
@@ -83,7 +83,7 @@ class ContractorApplication(cliapp.Application): self.verbose( 'uploading image to worker: {}'.format(bs.worker_image())) - if m.upload_worker_image(bs.worker_image()) != 0: + if m.upload_worker_image(bs.worker_image()).failed(): self.error('could not upload image to worker') sys.exit(1) @@ -97,7 +97,7 @@ class ContractorApplication(cliapp.Application): if install: self.verbose( 'installing packages: {}'.format(', '.join(install))) - if w.install_packages(install) != 0: + if w.install_packages(install).failed(): self.error('failed to install packages') sys.exit(1) else: @@ -106,12 +106,12 @@ class ContractorApplication(cliapp.Application): ws = bs.workspace() if ws and os.path.exists(ws): self.verbose('upload saved workspace from {}'.format(ws)) - if w.upload_workspace(ws) != 0: + if w.upload_workspace(ws).failed(): self.error('failed to upload workspace') sys.exit(1) self.verbose('upload source code from{}'.format(bs.source())) - if w.upload_source(bs.source()): + if w.upload_source(bs.source()).failed(): self.error('failed to upload source') sys.exit(1) @@ -408,7 +408,7 @@ class Manager: return rsync(filename, '{}:worker.img'.format(self._target)) def start_worker(self): - if self.copy_worker_image() != 0: + if self.copy_worker_image().failed(): logging.error('Could not copy worker image for new instance') return None @@ -421,7 +421,7 @@ class Manager: logging.error('Could not start worker due to missing CPU count') return None - out, err, exit_code = self.ssh([ + er = self.ssh([ 'virt-install', '--connect', 'qemu:///system', '--quiet', @@ -437,7 +437,7 @@ class Manager: '--graphics=spice', '--noautoconsole', ]) - if exit_code != 0: + if er.failed(): logging.error('Could not create worker VM') return None @@ -445,16 +445,15 @@ class Manager: def copy_worker_image(self): self.ssh(['rm', '-f', 'temp.img']) - out, err, exit_code = self.ssh(['cp', 'worker.img', 'temp.img']) - return exit_code + return self.ssh(['cp', 'worker.img', 'temp.img']) def get_cpu_count(self): - out, err, exit_code = self.ssh(['lscpu'], quiet=True) - if exit_code != 0: + er = self.ssh(['lscpu'], quiet=True) + if er.failed(): logging.error('lscpu on manager failed: {!r}'.format(err)) return None - for line in out.decode('UTF8').splitlines(): + for line in er.stdout.decode('UTF8').splitlines(): if line.startswith('CPU(s):'): return int(line.split()[-1]) @@ -463,13 +462,12 @@ class Manager: def worker_ip(self): filename = '/var/lib/libvirt/dnsmasq/virbr0.status' - out, err, exit_code = self.ssh(['cat', filename], quiet=True) - if exit_code != 0: + er = self.ssh(['cat', filename], quiet=True) + if er.failed(): logging.error('Could not read dnsmasq status file') return None - logging.debug('virbr0.status from manager: {!r}'.format(out)) - status = json.loads(out) + status = json.loads(er.stdout) if not status: return None @@ -484,8 +482,7 @@ class Manager: if ip is None: continue w = Worker(self, ip) - out, err, exit_code = w.ssh(['true'], quiet=True) - if exit_code == 0: + if not w.ssh(['true'], quiet=True).failed(): return w time.sleep(2) @@ -502,10 +499,9 @@ class Worker: return self._manager.ssh(argv, quiet=quiet) def install_packages(self, pkgs): - out, err, exit_code = self.ssh( + return self.ssh( ['sudo', 'DEBIAN_FRONTEND=noninteractive', 'apt-get', '-y', 'install'] + pkgs) - return exit_code def upload_workspace(self, dirname): return rsync( @@ -513,15 +509,26 @@ class Worker: '{}/workspace/.'.format(self._target)) def upload_source(self, dirname): - out, err, exit_code = self.ssh( + er = self.ssh(['sudo', 'chown', 'worker:worker', '/workspace']) + if er.failed(): + logging.error('Could not set /workspace ownership') + return er + + er = self.ssh( ['sudo', 'install', '-d', '--owner=worker', '--group=worker', '/workspace/src']) - if exit_code != 0: + if er.failed(): logging.error('Could not create /workspace/src on worker') - return None + return er + return rsync( '{}/.'.format(dirname), '{}:/workspace/src/.'.format(self._target)) + def create_dir(self, dirname): + return self.ssh( + ['sudo', 'install', '-d', '--owner=worker', '--group=worker', + dirname]) + ContractorApplication().run() |