1*e56833b4SRobert Foley#!/usr/bin/env python3 2*e56833b4SRobert Foley# 3*e56833b4SRobert Foley# Ubuntu VM testing library 4*e56833b4SRobert Foley# 5*e56833b4SRobert Foley# Copyright 2017 Red Hat Inc. 6*e56833b4SRobert Foley# Copyright 2020 Linaro 7*e56833b4SRobert Foley# 8*e56833b4SRobert Foley# Authors: 9*e56833b4SRobert Foley# Robert Foley <robert.foley@linaro.org> 10*e56833b4SRobert Foley# Originally based on ubuntu.i386 Fam Zheng <famz@redhat.com> 11*e56833b4SRobert Foley# 12*e56833b4SRobert Foley# This code is licensed under the GPL version 2 or later. See 13*e56833b4SRobert Foley# the COPYING file in the top-level directory. 14*e56833b4SRobert Foley 15*e56833b4SRobert Foleyimport os 16*e56833b4SRobert Foleyimport subprocess 17*e56833b4SRobert Foleyimport basevm 18*e56833b4SRobert Foley 19*e56833b4SRobert Foleyclass UbuntuVM(basevm.BaseVM): 20*e56833b4SRobert Foley 21*e56833b4SRobert Foley def __init__(self, args, config=None): 22*e56833b4SRobert Foley self.login_prompt = "ubuntu-{}-guest login:".format(self.arch) 23*e56833b4SRobert Foley basevm.BaseVM.__init__(self, args, config) 24*e56833b4SRobert Foley 25*e56833b4SRobert Foley def build_image(self, img): 26*e56833b4SRobert Foley """Build an Ubuntu VM image. The child class will 27*e56833b4SRobert Foley define the install_cmds to init the VM.""" 28*e56833b4SRobert Foley os_img = self._download_with_cache(self.image_link, 29*e56833b4SRobert Foley sha256sum=self.image_sha256) 30*e56833b4SRobert Foley img_tmp = img + ".tmp" 31*e56833b4SRobert Foley subprocess.check_call(["cp", "-f", os_img, img_tmp]) 32*e56833b4SRobert Foley self.exec_qemu_img("resize", img_tmp, "+50G") 33*e56833b4SRobert Foley ci_img = self.gen_cloud_init_iso() 34*e56833b4SRobert Foley 35*e56833b4SRobert Foley self.boot(img_tmp, extra_args = [ "-device", "VGA", "-cdrom", ci_img, ]) 36*e56833b4SRobert Foley 37*e56833b4SRobert Foley # First command we issue is fix for slow ssh login. 38*e56833b4SRobert Foley self.wait_ssh(wait_root=True, 39*e56833b4SRobert Foley cmd="chmod -x /etc/update-motd.d/*") 40*e56833b4SRobert Foley # Wait for cloud init to finish 41*e56833b4SRobert Foley self.wait_ssh(wait_root=True, 42*e56833b4SRobert Foley cmd="ls /var/lib/cloud/instance/boot-finished") 43*e56833b4SRobert Foley self.ssh_root("touch /etc/cloud/cloud-init.disabled") 44*e56833b4SRobert Foley # Disable auto upgrades. 45*e56833b4SRobert Foley # We want to keep the VM system state stable. 46*e56833b4SRobert Foley self.ssh_root('sed -ie \'s/"1"/"0"/g\' '\ 47*e56833b4SRobert Foley '/etc/apt/apt.conf.d/20auto-upgrades') 48*e56833b4SRobert Foley self.ssh_root("sed -ie s/^#\ deb-src/deb-src/g /etc/apt/sources.list") 49*e56833b4SRobert Foley 50*e56833b4SRobert Foley # If the user chooses not to do the install phase, 51*e56833b4SRobert Foley # then we will jump right to the graceful shutdown 52*e56833b4SRobert Foley if self._config['install_cmds'] != "": 53*e56833b4SRobert Foley # Issue the install commands. 54*e56833b4SRobert Foley # This can be overriden by the user in the config .yml. 55*e56833b4SRobert Foley install_cmds = self._config['install_cmds'].split(',') 56*e56833b4SRobert Foley for cmd in install_cmds: 57*e56833b4SRobert Foley self.ssh_root(cmd) 58*e56833b4SRobert Foley self.graceful_shutdown() 59*e56833b4SRobert Foley os.rename(img_tmp, img) 60*e56833b4SRobert Foley return 0 61