tests/vm: misc fixes and optimizations
cover tests/vm: misc fixes and optimizations
A collection of simple fixes and misc optimizations I found myself doing while investigating a console issue with the vm tests.
Cleber Rosa (4):
tests/vm: avoid extra compressed image copy tests/vm: avoid image presence check and removal tests/vm: pin ubuntu.i386 image tests/vm: add source repos on ubuntu.i386
tests/vm/centos | 6 ++---- tests/vm/freebsd | 6 ++---- tests/vm/netbsd | 6 ++---- tests/vm/openbsd | 6 ++---- tests/vm/ubuntu.i386 | 7 ++++--- 5 files changed, 12 insertions(+), 19 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/4 tests/vm: avoid extra compressed image copy
The image copy is only really needed because xz doesn't know to properly decompress a file not named properly. Instead of decompressing to stdout, and having to rely on a shell, let's just create a link instead of copying the file.
--- tests/vm/centos | 4 ++-- tests/vm/freebsd | 4 ++-- tests/vm/netbsd | 4 ++-- tests/vm/openbsd | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
tests/vm/centos +2 -2
@@ -66,8 +66,8 @@ class CentosVM(basevm.BaseVM): cimg = self._download_with_cache("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1802.qcow2.xz") img_tmp = img + ".tmp" sys.stderr.write("Extracting the image...\n") - subprocess.check_call(["cp", "-f", cimg, img_tmp + ".xz"]) - subprocess.check_call(["xz", "-dvf", img_tmp + ".xz"]) + subprocess.check_call(["ln", "-f", cimg, img_tmp + ".xz"]) + subprocess.check_call(["xz", "--keep", "-dvf", img_tmp + ".xz"]) subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"]) self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) self.wait_ssh()
tests/vm/freebsd +2 -2
@@ -34,8 +34,8 @@ class FreeBSDVM(basevm.BaseVM): img_tmp_xz = img + ".tmp.xz" img_tmp = img + ".tmp" sys.stderr.write("Extracting the image...\n") - subprocess.check_call(["cp", "-f", cimg, img_tmp_xz]) - subprocess.check_call(["xz", "-dvf", img_tmp_xz]) + subprocess.check_call(["ln", "-f", cimg, img_tmp_xz]) + subprocess.check_call(["xz", "--keep", "-dvf", img_tmp_xz]) if os.path.exists(img): os.remove(img) os.rename(img_tmp, img)
tests/vm/netbsd +2 -2
@@ -34,8 +34,8 @@ class NetBSDVM(basevm.BaseVM): img_tmp_xz = img + ".tmp.xz" img_tmp = img + ".tmp" sys.stderr.write("Extracting the image...\n") - subprocess.check_call(["cp", "-f", cimg, img_tmp_xz]) - subprocess.check_call(["xz", "-dvf", img_tmp_xz]) + subprocess.check_call(["ln", "-f", cimg, img_tmp_xz]) + subprocess.check_call(["xz", "--keep", "-dvf", img_tmp_xz]) if os.path.exists(img): os.remove(img) os.rename(img_tmp, img)
tests/vm/openbsd +2 -2
@@ -36,8 +36,8 @@ class OpenBSDVM(basevm.BaseVM): img_tmp_xz = img + ".tmp.xz" img_tmp = img + ".tmp" sys.stderr.write("Extracting the image...\n") - subprocess.check_call(["cp", "-f", cimg, img_tmp_xz]) - subprocess.check_call(["xz", "-dvf", img_tmp_xz]) + subprocess.check_call(["ln", "-f", cimg, img_tmp_xz]) + subprocess.check_call(["xz", "--keep", "-dvf", img_tmp_xz]) if os.path.exists(img): os.remove(img) os.rename(img_tmp, img)
Signature · 1 line
2.21.0
PATCH 2/4 tests/vm: avoid image presence check and removal
In reply to Cleber RosaPython's os.rename() will silently replace an existing file, so there's no need for the extra check and removal.
Reference: https://docs.python.org/3/library/os.html#os.rename
--- tests/vm/centos | 2 -- tests/vm/freebsd | 2 -- tests/vm/netbsd | 2 -- tests/vm/openbsd | 2 -- tests/vm/ubuntu.i386 | 2 -- 5 files changed, 10 deletions(-)
tests/vm/centos +0 -2
@@ -77,8 +77,6 @@ class CentosVM(basevm.BaseVM): self.ssh_root_check("systemctl enable docker") self.ssh_root("poweroff") self.wait() - if os.path.exists(img): - os.remove(img) os.rename(img_tmp, img) return 0
tests/vm/freebsd +0 -2
@@ -36,8 +36,6 @@ class FreeBSDVM(basevm.BaseVM): sys.stderr.write("Extracting the image...\n") subprocess.check_call(["ln", "-f", cimg, img_tmp_xz]) subprocess.check_call(["xz", "--keep", "-dvf", img_tmp_xz]) - if os.path.exists(img): - os.remove(img) os.rename(img_tmp, img) if __name__ == "__main__":
tests/vm/netbsd +0 -2
@@ -36,8 +36,6 @@ class NetBSDVM(basevm.BaseVM): sys.stderr.write("Extracting the image...\n") subprocess.check_call(["ln", "-f", cimg, img_tmp_xz]) subprocess.check_call(["xz", "--keep", "-dvf", img_tmp_xz]) - if os.path.exists(img): - os.remove(img) os.rename(img_tmp, img) if __name__ == "__main__":
tests/vm/openbsd +0 -2
@@ -38,8 +38,6 @@ class OpenBSDVM(basevm.BaseVM): sys.stderr.write("Extracting the image...\n") subprocess.check_call(["ln", "-f", cimg, img_tmp_xz]) subprocess.check_call(["xz", "--keep", "-dvf", img_tmp_xz]) - if os.path.exists(img): - os.remove(img) os.rename(img_tmp, img) if __name__ == "__main__":
tests/vm/ubuntu.i386 +0 -2
@@ -80,8 +80,6 @@ class UbuntuX86VM(basevm.BaseVM): self.ssh_root_check("apt-get install -y libfdt-dev flex bison") self.ssh_root("poweroff") self.wait() - if os.path.exists(img): - os.remove(img) os.rename(img_tmp, img) return 0
Signature · 1 line
2.21.0
PATCH 3/4 tests/vm: pin ubuntu.i386 image
In reply to Cleber RosaIt's a good practice to always have the same components used in tests. According to:
https://cloud-images.ubuntu.com/releases/16.04/
New images are released from time to time, and the "release/" directory points to the latest release. Let's pin to the latest available version, and while at it, set a hash for verification.
--- tests/vm/ubuntu.i386 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/vm/ubuntu.i386 +3 -1
@@ -61,7 +61,9 @@ class UbuntuX86VM(basevm.BaseVM): return os.path.join(cidir, "cloud-init.iso") def build_image(self, img): - cimg = self._download_with_cache("https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-i386-disk1.img") + cimg = self._download_with_cache( + "https://cloud-images.ubuntu.com/releases/16.04/release-20190605/ubuntu-16.04-server-cloudimg-i386-disk1.img", + sha256sum="e30091144c73483822b7c27193e9d47346dd1064229da577c3fedcf943f7cfcc") img_tmp = img + ".tmp" subprocess.check_call(["cp", "-f", cimg, img_tmp]) subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"])
Signature · 1 line
2.21.0
PATCH 4/4 tests/vm: add source repos on ubuntu.i386
In reply to Cleber RosaPossibly because of different behavior on the newly update cloud-image, trying to run 'apt-get build-dep' results in:
E: You must put some 'source' URIs in your sources.list
This enables all source repos (even though some are not needed) for simplicity sake.
--- tests/vm/ubuntu.i386 | 1 + 1 file changed, 1 insertion(+)
tests/vm/ubuntu.i386 +1 -0
@@ -77,6 +77,7 @@ class UbuntuX86VM(basevm.BaseVM): time.sleep(5) self.wait_ssh() # The previous update sometimes doesn't survive a reboot, so do it again + self.ssh_root_check("sed -ie s/^#\ deb-src/deb-src/g /etc/apt/sources.list") self.ssh_root_check("apt-get update") self.ssh_root_check("apt-get build-dep -y qemu") self.ssh_root_check("apt-get install -y libfdt-dev flex bison")
Signature · 1 line
2.21.0
Quoted 3 lines · Cleber Rosa
A collection of simple fixes and misc optimizations I found myself doing while investigating a console issue with the vm tests.
Queued to testing/next, thanks.
Quoted 7 lines
Cleber Rosa (4):
tests/vm: avoid extra compressed image copy tests/vm: avoid image presence check and removal tests/vm: pin ubuntu.i386 image tests/vm: add source repos on ubuntu.i386
Quoted 6 lines
tests/vm/centos | 6 ++---- tests/vm/freebsd | 6 ++---- tests/vm/netbsd | 6 ++---- tests/vm/openbsd | 6 ++---- tests/vm/ubuntu.i386 | 7 ++++--- 5 files changed, 12 insertions(+), 19 deletions(-)
--
Alex Bennée