mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-05 18:50:09 +02:00
buildserver: make --clean destroy reliably
This prevents v.destroy() from running if Vagrantfile.yaml does not exist, since that is required for vagrant to run: is the core config including the name of the box, etc. Otherwise, it would exit with an error. This also does complete cleanup when using libvirt.
This commit is contained in:
parent
299ed82a88
commit
988ac21e7f
@ -291,6 +291,32 @@ def sha256_for_file(path):
|
|||||||
return s.hexdigest()
|
return s.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def destroy_current_image(v, serverdir):
|
||||||
|
global config
|
||||||
|
|
||||||
|
# cannot run vagrant without the config in the YAML file
|
||||||
|
if os.path.exists(os.path.join(serverdir, 'Vagrantfile.yaml')):
|
||||||
|
v.destroy()
|
||||||
|
elif options.verbose:
|
||||||
|
print('Cannot run destroy vagrant setup since Vagrantfile.yaml is not setup!')
|
||||||
|
if config['vm_provider'] == 'libvirt':
|
||||||
|
import libvirt
|
||||||
|
try:
|
||||||
|
domain = 'buildserver_default'
|
||||||
|
virConnect = libvirt.open('qemu:///system')
|
||||||
|
virDomain = virConnect.lookupByName(domain)
|
||||||
|
if virDomain:
|
||||||
|
virDomain.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE
|
||||||
|
| libvirt.VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA
|
||||||
|
| libvirt.VIR_DOMAIN_UNDEFINE_NVRAM)
|
||||||
|
storagePool = virConnect.storagePoolLookupByName('default')
|
||||||
|
if storagePool:
|
||||||
|
for vol in storagePool.listAllVolumes():
|
||||||
|
vol.delete()
|
||||||
|
except libvirt.libvirtError as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
def run_via_vagrant_ssh(v, cmdlist):
|
def run_via_vagrant_ssh(v, cmdlist):
|
||||||
if (isinstance(cmdlist, str) or isinstance(cmdlist, bytes)):
|
if (isinstance(cmdlist, str) or isinstance(cmdlist, bytes)):
|
||||||
cmd = cmdlist
|
cmd = cmdlist
|
||||||
@ -383,10 +409,7 @@ def main():
|
|||||||
tail.start()
|
tail.start()
|
||||||
|
|
||||||
if options.clean:
|
if options.clean:
|
||||||
v.destroy()
|
destroy_current_image(v, serverdir)
|
||||||
if config['vm_provider'] == 'libvirt':
|
|
||||||
subprocess.call(['virsh', 'undefine', 'buildserver_default'])
|
|
||||||
subprocess.call(['virsh', 'vol-delete', '/var/lib/libvirt/images/buildserver_default.img'])
|
|
||||||
|
|
||||||
# Check against the existing Vagrantfile.yaml, and if they differ, we
|
# Check against the existing Vagrantfile.yaml, and if they differ, we
|
||||||
# need to create a new box:
|
# need to create a new box:
|
||||||
@ -399,7 +422,7 @@ def main():
|
|||||||
oldconfig = yaml.load(f)
|
oldconfig = yaml.load(f)
|
||||||
if config != oldconfig:
|
if config != oldconfig:
|
||||||
print("Server configuration has changed, rebuild from scratch is required")
|
print("Server configuration has changed, rebuild from scratch is required")
|
||||||
v.destroy()
|
destroy_current_image(v, serverdir)
|
||||||
else:
|
else:
|
||||||
print("Re-provisioning existing server")
|
print("Re-provisioning existing server")
|
||||||
writevf = False
|
writevf = False
|
||||||
|
Loading…
Reference in New Issue
Block a user