From f2bbf0cb4b3bcb58f4dfaced9864aa36b8361ac0 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 24 Apr 2020 10:56:46 +0300 Subject: Change: don't do an ssh invocation just to get number of CPUS --- contractor | 57 +++++++++++++++++++-------------------------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/contractor b/contractor index 38c4b39..cba9cf7 100755 --- a/contractor +++ b/contractor @@ -70,19 +70,12 @@ class ContractorApplication(cliapp.Application): # while to boot and we can do other things while that # happens. with Timer(self.verbose, 'start-worker'): - # Find number of CPUs. - er = self.exec_quietly(manager, GetCPUCount()) - cpus = 1 - for line in er.stdout.decode('UTF8').splitlines(): - if line.startswith('CPU(s):'): - cpus = int(line.split()[-1]) - execs = [ DestroyWorkerVM(), UndefineWorkerVM(), CopyWorkerImage(), StartGuestNetworking(), - CreateWorkerVM(cpus), + CreateWorkerVM(), TryUnmountWS(), MountWS(), ChownWS(), @@ -108,7 +101,6 @@ class ContractorApplication(cliapp.Application): ] er = self.exec_quietly(manager, *execs) worker_ip = er.stdout.decode('UTF8').strip() - timer.report('wait-for-worker') with Timer(self.verbose, 'prepare-workspace-worker'): self.exec_quietly(manager, AttachWS()) @@ -141,7 +133,6 @@ class ContractorApplication(cliapp.Application): if ws: self.verbose('saving workspace to {}'.format(ws)) self.sync_from_workspace(dest, ws) - timer.report('save-workspace') self.verbose('build finished OK') @@ -486,39 +477,29 @@ class Mkdir(RemoteExecution): return self._argv -class GetCPUCount(RemoteExecution): - - def msg(self): - return 'get CPU count' - - def argv(self): - return ['lscpu'] - - class CreateWorkerVM(RemoteExecution): - def __init__(self, manager_cpus): - self._worker_cpus = max(manager_cpus - 1, 1) - def msg(self): return 'creating worker VM' def argv(self): - return [ - 'virt-install', - '--connect', 'qemu:///system', - '--quiet', - '--name=worker', - '--memory=4096', - '--vcpus={}'.format(self._worker_cpus), - '--cpu=host', - '--import', - '--os-variant=debian9', - '--disk=path={},cache=none'.format(TEMP_IMG), - '--network=network=default', - '--graphics=spice', - '--noautoconsole', - ] + return ['sh', '-euxc', ''' +n="$(grep -c '^processor' /proc/cpuinfo)" +n="$(expr "$n" - 1)" +virt-install \ + --connect=qemu:///system \ + --quiet \ + --name=worker \ + --memory=4096 \ + --vcpus="$n" \ + --cpu=host \ + --import \ + --os-variant=debian9 \ + --disk=path={img} \ + --network=network=default \ + --graphics=spice \ + --noautoconsole \ +'''.format(img=TEMP_IMG)] class AttachWS(RemoteExecution): @@ -624,7 +605,7 @@ class Timer: duration = now - self._prev self._prev = now self._report('time: {:.1f} s {}'.format(duration, self._title)) - return exctype + return False ContractorApplication().run() -- cgit v1.2.1