tests/vm: Add support for aarch64 VMs
cover tests/vm: Add support for aarch64 VMs
This is version 1 of the patch series to
add support for 2 aarch64 VMs.
- Ubuntu 18.04 aarch64 VM
- CentOS 8 aarch64 VM
Changes in version 1
- Added environment variable QEMU_LOCAL=1 which means
use the appropriate QEMU binary from the current build.
- Improved support of aarch64 VMs to be backwards compatible
by default with older versions of QEMU.
- Fixed a locale issue with ubuntu.aarch64 VM.
The issue here was that we were not waiting for the cloud-init to finish, prior to rebooting the VM.
- Workaround of issue where the test hangs as QEMU is waiting for the consumption of character device data. Workaround adds a thread to the test framework to consume these characters and dump them to a file. The test then consumes these characters from the file instead of from the character device as it did previously.
One advantage of this change is that there is now a log file which contains the console output for debug.
- Change creation of aarch64 flash files to be in temp directory.
- Added changes to convert existing scripts to using self._config for SSH_KEY_PUB, GUEST_USER, GUEST_PASS, ROOT_PASS.
- Created example config file for x86, renamed existing
example file to aarch64.
- Make gen_cloud_init_iso() common to basevm.
- Updated wait_ssh() to only extend time when we are under TCG.
- Changed wait_ssh() to wait for root or wait for guest user, not both.
- Removed SSH_KEY global as it is no longer needed.
- Clarified use of ssh_key_file and ssh_pub_key_file,
added tmp to the names to clarify, and added a comment to explain use here.
- Cleaned up handling of the boot_console option.
- Moved tweak to Makefile.include to a separate patch.
- Removed setting of tcg,thread=multi in aarch64 VMs.
- Moved the validation of ssh keys to a common location.
- Reworked the handling of the config file yaml to
simply set the values into the config dictionary in one step.
More details on the patch in general:
In order to add support for the two new aarch64 VMs, we generalized and parameterized basevm.py.
We added a new concept of a configuration, which is really just a set of parameters which define how to configure the VM. Some examples of parameters are "machine", "memory" and "cpu". We preserved current default parameters.
Current configuration of pre-existing VMs is supported by default without need to override default parameters.
For example, previously only the 'pc' machine was supported in basevm.py. The new aarch64 VMs will override machine to use virt.
There are a few other examples where we needed to add parameters in order to add support for these aarch64 VMs.
In some other cases we added parameters that we thought would be useful in general, for example username/password, ssh keys,
In the case of the aarch64 VMs, they override certain parameters by default. However, it is also of value to be able to dynamically specify other values for these parameters.
Take the case where you create a new VM using vm-build,
but then want to test it using various hardware configurations such as for example different NUMA topologies.
Or maybe you want to use a different amount of memory or a different cpu type.
In order to support these use cases we added support
for a configuration .yml file, which allows the user to specify certain values dynamically such as:
- machine
- cpu
- memory size
- other qemu args, which allow configuring alternate hardware topologies such as NUMA nodes.
- username, password
- ssh keys
For an example of a .yml file, see the included config_example.yml
The main use case for using this config.yml file is for where we are testing/debugging with qemu (vm-build), and need to configure the VM differently. However, there is another use case we have developed, which is a project called lisa-qemu
(https://github.com/rf972/lisa-qemu).
This project is an integration between the LISA tool and QEMU. This project uses the VMs created by
QEMU's vm-build scripts for use in testing with LISA.
This use case is similar to the vm-build case in that,
the VM gets created once, and we want to launch the VM with different configurations (memory, cpu, etc.).
As part of developing the scripts for these VMs, we implemented a few enhancements to help with testing.
For example, we added support for allowing debug mode to show the ssh output.
We also added support for a new --boot-console option which will show the boot console as the VM boots up to aid in debugging problems during VM boot.
Robert Foley (14):
tests/vm: use $(PYTHON) consistently
tests/vm: Debug mode shows ssh output. tests/vm: increased max timeout for vm boot. tests/vm: give wait_ssh() option to wait for root tests/vm: Added gen_cloud_init_iso() to basevm.py tests/vm: Add logging of console to file. tests/vm: Add configuration to basevm.py tests/vm: Added configuration file support tests/vm: add --boot-console switch
tests/vm: Add ability to select QEMU from current build. tests/vm: allow wait_ssh() to specify command tests/vm: Added a new script for ubuntu.aarch64. tests/vm: Added a new script for centos.aarch64. tests/vm: change scripts to use self._config
tests/vm/Makefile.include | 16 +- tests/vm/aarch64vm.py | 100 +++++++++ tests/vm/basevm.py | 324 +++++++++++++++++++++++++----- tests/vm/centos | 33 +-- tests/vm/centos-8-aarch64.ks | 51 +++++ tests/vm/centos.aarch64 | 221 ++++++++++++++++++++ tests/vm/conf_example_aarch64.yml | 51 +++++ tests/vm/conf_example_x86.yml | 50 +++++ tests/vm/fedora | 17 +- tests/vm/freebsd | 16 +- tests/vm/netbsd | 19 +- tests/vm/openbsd | 17 +- tests/vm/socket_thread.py | 73 +++++++ tests/vm/ubuntu.aarch64 | 113 +++++++++++ tests/vm/ubuntu.i386 | 37 +--- 15 files changed, 987 insertions(+), 151 deletions(-) create mode 100644 tests/vm/aarch64vm.py create mode 100644 tests/vm/centos-8-aarch64.ks create mode 100755 tests/vm/centos.aarch64 create mode 100644 tests/vm/conf_example_aarch64.yml create mode 100644 tests/vm/conf_example_x86.yml create mode 100644 tests/vm/socket_thread.py create mode 100755 tests/vm/ubuntu.aarch64
Signature · 1 line
2.17.1
PATCH 1/14 tests/vm: use $(PYTHON) consistently
Change Makefile.include to use $(PYTHON) so for vm-boot-ssh to be consistent with other cases like vm-build.
--- tests/vm/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/vm/Makefile.include +1 -1
@@ -80,7 +80,7 @@ vm-boot-serial-%: $(IMAGES_DIR)/%.img vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(call quiet-command, \ - $(SRC_PATH)/tests/vm/$* \ + $(PYTHON) $(SRC_PATH)/tests/vm/$* \ $(if $(J),--jobs $(J)) \ --image "$<" \ --interactive \
Signature · 1 line
2.17.1
Re: [PATCH v1 01/14] tests/vm: use $(PYTHON) consistently
Quoted 4 lines · Robert Foley
Change Makefile.include to use $(PYTHON) so for vm-boot-ssh to be consistent with other cases like vm-build.
Signed-off-by Robert Foley <[email protected]>
Quoted 17 lines
--- tests/vm/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/vm/Makefile.include +1
-1@@ -80,7 +80,7 @@ vm-boot-serial-%: $(IMAGES_DIR)/%.img vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(call quiet-command, \ - $(SRC_PATH)/tests/vm/$* \ + $(PYTHON) $(SRC_PATH)/tests/vm/$* \ $(if $(J),--jobs $(J)) \ --image "$<" \ --interactive \
Signature · 1 line
Alex Bennée
PATCH 2/14 tests/vm: Debug mode shows ssh output.
In reply to Robert FoleyAdd changes to tests/vm/basevm.py so that during debug mode we show ssh output.
--- tests/vm/basevm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tests/vm/basevm.py +6 -1
@@ -122,11 +122,16 @@ class BaseVM(object): return fname def _ssh_do(self, user, cmd, check): - ssh_cmd = ["ssh", "-q", "-t", + ssh_cmd = ["ssh", + "-t", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=" + os.devnull, "-o", "ConnectTimeout=1", "-p", self.ssh_port, "-i", self._ssh_key_file] + # If not in debug mode, set ssh to quiet mode to + # avoid printing the results of commands. + if not self.debug: + ssh_cmd.append("-q") for var in self.envvars: ssh_cmd += ['-o', "SendEnv=%s" % var ] assert not isinstance(cmd, str)
Signature · 1 line
2.17.1
PATCH 3/14 tests/vm: increased max timeout for vm boot.
In reply to Robert FoleyAdd change to increase timeout waiting for VM to boot. Needed for some emulation cases where it can take longer than 5 minutes to boot.
--- tests/vm/basevm.py | 7 +++++++ 1 file changed, 7 insertions(+)
tests/vm/basevm.py +7 -0
@@ -59,6 +59,10 @@ class BaseVM(object): poweroff = "poweroff" # enable IPv6 networking ipv6 = True + # Scale up some timeouts under TCG. + # 4 is arbitrary, but greater than 2, + # since we found we need to wait more than twice as long. + tcg_ssh_timeout_multiplier = 4 def __init__(self, debug=False, vcpus=None): self._guest = None self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",
@@ -311,6 +315,9 @@ class BaseVM(object): sys.stderr.write("### %s ...\n" % text) def wait_ssh(self, seconds=300): + # Allow more time for VM to boot under TCG. + if not kvm_available(self.arch): + seconds *= self.tcg_ssh_timeout_multiplier starttime = datetime.datetime.now() endtime = starttime + datetime.timedelta(seconds=seconds) guest_up = False
Signature · 1 line
2.17.1
Re: [PATCH v1 03/14] tests/vm: increased max timeout for vm boot.
Quoted 5 lines · Robert Foley
Add change to increase timeout waiting for VM to boot. Needed for some emulation cases where it can take longer than 5 minutes to boot.
Signed-off-by Robert Foley <[email protected]>
Quoted 29 lines
--- tests/vm/basevm.py | 7 +++++++ 1 file changed, 7 insertions(+)tests/vm/basevm.py +7
-0@@ -59,6 +59,10 @@ class BaseVM(object): poweroff = "poweroff" # enable IPv6 networking ipv6 = True + # Scale up some timeouts under TCG. + # 4 is arbitrary, but greater than 2, + # since we found we need to wait more than twice as long. + tcg_ssh_timeout_multiplier = 4 def __init__(self, debug=False, vcpus=None): self._guest = None self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",@@ -311,6 +315,9 @@ class BaseVM(object): sys.stderr.write("### %s ...\n" % text) def wait_ssh(self, seconds=300): + # Allow more time for VM to boot under TCG. + if not kvm_available(self.arch): + seconds *= self.tcg_ssh_timeout_multiplier starttime = datetime.datetime.now() endtime = starttime + datetime.timedelta(seconds=seconds) guest_up = False
Signature · 1 line
Alex Bennée
PATCH 4/14 tests/vm: give wait_ssh() option to wait for root
In reply to Robert FoleyAllow wait_ssh to wait for root user to be ready. This solves the issue where we perform a wait_ssh() successfully, but the root user is not yet ready to be logged in.
--- tests/vm/basevm.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tests/vm/basevm.py +5 -3
@@ -314,7 +314,7 @@ class BaseVM(object): def print_step(self, text): sys.stderr.write("### %s ...\n" % text) - def wait_ssh(self, seconds=300): + def wait_ssh(self, wait_root=False, seconds=300): # Allow more time for VM to boot under TCG. if not kvm_available(self.arch): seconds *= self.tcg_ssh_timeout_multiplier
@@ -322,7 +322,10 @@ class BaseVM(object): endtime = starttime + datetime.timedelta(seconds=seconds) guest_up = False while datetime.datetime.now() < endtime: - if self.ssh("exit 0") == 0: + if wait_root and self.ssh_root("exit 0") == 0: + guest_up = True + break + elif self.ssh("exit 0") == 0: guest_up = True break seconds = (endtime - datetime.datetime.now()).total_seconds()
@@ -333,7 +336,6 @@ class BaseVM(object): def shutdown(self): self._guest.shutdown() - def wait(self): self._guest.wait()
Signature · 1 line
2.17.1
Re: [PATCH v1 04/14] tests/vm: give wait_ssh() option to wait for root
Quoted 36 lines · Robert Foley
Allow
wait_sshto wait for root user to be ready. This solves the issue where we perform await_ssh()successfully, but the root user is not yet ready to be logged in.Signed-off-by Robert Foley <[email protected]>--- tests/vm/basevm.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)tests/vm/basevm.py +5
-2@@ -314,7 +314,7 @@ class BaseVM(object): def print_step(self, text): sys.stderr.write("### %s ...\n" % text) - def wait_ssh(self, seconds=300): + def wait_ssh(self, wait_root=False, seconds=300): # Allow more time for VM to boot under TCG. if not kvm_available(self.arch): seconds *= self.tcg_ssh_timeout_multiplier@@ -322,7 +322,10 @@ class BaseVM(object): endtime = starttime + datetime.timedelta(seconds=seconds) guest_up = False while datetime.datetime.now() < endtime: - if self.ssh("exit 0") == 0: + if wait_root and self.ssh_root("exit 0") == 0: + guest_up = True + break + elif self.ssh("exit 0") == 0: guest_up = True break seconds = (endtime - datetime.datetime.now()).total_seconds()
tests/vm/basevm.py class BaseVM(object): · line 336
Quoted 4 lines
tests/vm/basevm.py +0
-1@@ -333,7 +336,6 @@ class BaseVM(object): def shutdown(self): self._guest.shutdown() -
Stray line deletion. Otherwise:
Signature · 1 line
Alex Bennée
PATCH 5/14 tests/vm: Added gen_cloud_init_iso() to basevm.py
In reply to Robert FoleyThis method was located in both centos and ubuntu.i386.
--- tests/vm/basevm.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/vm/centos | 33 +-------------------------------- tests/vm/ubuntu.i386 | 37 +------------------------------------ 3 files changed, 42 insertions(+), 68 deletions(-)
tests/vm/basevm.py +40 -0
@@ -346,6 +346,46 @@ class BaseVM(object): def qmp(self, *args, **kwargs): return self._guest.qmp(*args, **kwargs) + def gen_cloud_init_iso(self): + cidir = self._tmpdir + mdata = open(os.path.join(cidir, "meta-data"), "w") + name = self.name.replace(".","-") + mdata.writelines(["instance-id: {}-vm-0\n".format(name), + "local-hostname: {}-guest\n".format(name)]) + mdata.close() + udata = open(os.path.join(cidir, "user-data"), "w") + print("guest user:pw {}:{}".format(self._config['guest_user'], + self._config['guest_pass'])) + udata.writelines(["#cloud-config\n", + "chpasswd:\n", + " list: |\n", + " root:%s\n" % self._config['root_pass'], + " %s:%s\n" % (self._config['guest_user'], + self._config['guest_pass']), + " expire: False\n", + "users:\n", + " - name: %s\n" % self._config['guest_user'], + " sudo: ALL=(ALL) NOPASSWD:ALL\n", + " ssh-authorized-keys:\n", + " - %s\n" % self._config['ssh_pub_key'], + " - name: root\n", + " ssh-authorized-keys:\n", + " - %s\n" % self._config['ssh_pub_key'], + "locale: en_US.UTF-8\n"]) + proxy = os.environ.get("http_proxy") + if not proxy is None: + udata.writelines(["apt:\n", + " proxy: %s" % proxy]) + udata.close() + subprocess.check_call(["genisoimage", "-output", "cloud-init.iso", + "-volid", "cidata", "-joliet", "-rock", + "user-data", "meta-data"], + cwd=cidir, + stdin=self._devnull, stdout=self._stdout, + stderr=self._stdout) + + return os.path.join(cidir, "cloud-init.iso") + def parse_args(vmcls): def get_default_jobs():
tests/vm/centos +1 -32
@@ -31,37 +31,6 @@ class CentosVM(basevm.BaseVM): make docker-test-mingw@fedora {verbose} J={jobs} NETWORK=1; """ - def _gen_cloud_init_iso(self): - cidir = self._tmpdir - mdata = open(os.path.join(cidir, "meta-data"), "w") - mdata.writelines(["instance-id: centos-vm-0\n", - "local-hostname: centos-guest\n"]) - mdata.close() - udata = open(os.path.join(cidir, "user-data"), "w") - udata.writelines(["#cloud-config\n", - "chpasswd:\n", - " list: |\n", - " root:%s\n" % self.ROOT_PASS, - " %s:%s\n" % (self.GUEST_USER, self.GUEST_PASS), - " expire: False\n", - "users:\n", - " - name: %s\n" % self.GUEST_USER, - " sudo: ALL=(ALL) NOPASSWD:ALL\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - " - name: root\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - "locale: en_US.UTF-8\n"]) - udata.close() - subprocess.check_call(["genisoimage", "-output", "cloud-init.iso", - "-volid", "cidata", "-joliet", "-rock", - "user-data", "meta-data"], - cwd=cidir, - stdin=self._devnull, stdout=self._stdout, - stderr=self._stdout) - return os.path.join(cidir, "cloud-init.iso") - def build_image(self, img): cimg = self._download_with_cache("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1802.qcow2.xz") img_tmp = img + ".tmp"
@@ -69,7 +38,7 @@ class CentosVM(basevm.BaseVM): subprocess.check_call(["ln", "-f", cimg, img_tmp + ".xz"]) subprocess.check_call(["xz", "--keep", "-dvf", img_tmp + ".xz"]) self.exec_qemu_img("resize", img_tmp, "50G") - self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) + self.boot(img_tmp, extra_args = ["-cdrom", self.gen_cloud_init_iso()]) self.wait_ssh() self.ssh_root_check("touch /etc/cloud/cloud-init.disabled") self.ssh_root_check("yum update -y")
tests/vm/ubuntu.i386 +1 -36
@@ -29,41 +29,6 @@ class UbuntuX86VM(basevm.BaseVM): make --output-sync {target} -j{jobs} {verbose}; """ - def _gen_cloud_init_iso(self): - cidir = self._tmpdir - mdata = open(os.path.join(cidir, "meta-data"), "w") - mdata.writelines(["instance-id: ubuntu-vm-0\n", - "local-hostname: ubuntu-guest\n"]) - mdata.close() - udata = open(os.path.join(cidir, "user-data"), "w") - udata.writelines(["#cloud-config\n", - "chpasswd:\n", - " list: |\n", - " root:%s\n" % self.ROOT_PASS, - " %s:%s\n" % (self.GUEST_USER, self.GUEST_PASS), - " expire: False\n", - "users:\n", - " - name: %s\n" % self.GUEST_USER, - " sudo: ALL=(ALL) NOPASSWD:ALL\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - " - name: root\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - "locale: en_US.UTF-8\n"]) - proxy = os.environ.get("http_proxy") - if not proxy is None: - udata.writelines(["apt:\n", - " proxy: %s" % proxy]) - udata.close() - subprocess.check_call(["genisoimage", "-output", "cloud-init.iso", - "-volid", "cidata", "-joliet", "-rock", - "user-data", "meta-data"], - cwd=cidir, - stdin=self._devnull, stdout=self._stdout, - stderr=self._stdout) - return os.path.join(cidir, "cloud-init.iso") - def build_image(self, img): cimg = self._download_with_cache( "https://cloud-images.ubuntu.com/releases/bionic/release-20191114/ubuntu-18.04-server-cloudimg-i386.img",
@@ -71,7 +36,7 @@ class UbuntuX86VM(basevm.BaseVM): img_tmp = img + ".tmp" subprocess.check_call(["cp", "-f", cimg, img_tmp]) self.exec_qemu_img("resize", img_tmp, "50G") - self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) + self.boot(img_tmp, extra_args = ["-cdrom", self.gen_cloud_init_iso()]) self.wait_ssh() self.ssh_root_check("touch /etc/cloud/cloud-init.disabled") self.ssh_root_check("apt-get update")
Signature · 1 line
2.17.1
Re: [PATCH v1 05/14] tests/vm: Added gen_cloud_init_iso() to basevm.py
Quoted 3 lines · Robert Foley
This method was located in both centos and ubuntu.i386.
Signed-off-by Robert Foley <[email protected]>
Quoted 163 lines
--- tests/vm/basevm.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/vm/centos | 33 +-------------------------------- tests/vm/ubuntu.i386 | 37 +------------------------------------ 3 files changed, 42 insertions(+), 68 deletions(-)tests/vm/basevm.py +40
-0@@ -346,6 +346,46 @@ class BaseVM(object): def qmp(self, *args, **kwargs): return self._guest.qmp(*args, **kwargs) + def gen_cloud_init_iso(self): + cidir = self._tmpdir + mdata = open(os.path.join(cidir, "meta-data"), "w") + name = self.name.replace(".","-") + mdata.writelines(["instance-id: {}-vm-0\n".format(name), + "local-hostname: {}-guest\n".format(name)]) + mdata.close() + udata = open(os.path.join(cidir, "user-data"), "w") + print("guest user:pw {}:{}".format(self._config['guest_user'], + self._config['guest_pass'])) + udata.writelines(["#cloud-config\n", + "chpasswd:\n", + " list: |\n", + " root:%s\n" % self._config['root_pass'], + " %s:%s\n" % (self._config['guest_user'], + self._config['guest_pass']), + " expire: False\n", + "users:\n", + " - name: %s\n" % self._config['guest_user'], + " sudo: ALL=(ALL) NOPASSWD:ALL\n", + " ssh-authorized-keys:\n", + " - %s\n" % self._config['ssh_pub_key'], + " - name: root\n", + " ssh-authorized-keys:\n", + " - %s\n" % self._config['ssh_pub_key'], + "locale: en_US.UTF-8\n"]) + proxy = os.environ.get("http_proxy") + if not proxy is None: + udata.writelines(["apt:\n", + " proxy: %s" % proxy]) + udata.close() + subprocess.check_call(["genisoimage", "-output", "cloud-init.iso", + "-volid", "cidata", "-joliet", "-rock", + "user-data", "meta-data"], + cwd=cidir, + stdin=self._devnull, stdout=self._stdout, + stderr=self._stdout) + + return os.path.join(cidir, "cloud-init.iso") + def parse_args(vmcls): def get_default_jobs():tests/vm/centos +1
-32@@ -31,37 +31,6 @@ class CentosVM(basevm.BaseVM): make docker-test-mingw@fedora {verbose} J={jobs} NETWORK=1; """ - def _gen_cloud_init_iso(self): - cidir = self._tmpdir - mdata = open(os.path.join(cidir, "meta-data"), "w") - mdata.writelines(["instance-id: centos-vm-0\n", - "local-hostname: centos-guest\n"]) - mdata.close() - udata = open(os.path.join(cidir, "user-data"), "w") - udata.writelines(["#cloud-config\n", - "chpasswd:\n", - " list: |\n", - " root:%s\n" % self.ROOT_PASS, - " %s:%s\n" % (self.GUEST_USER, self.GUEST_PASS), - " expire: False\n", - "users:\n", - " - name: %s\n" % self.GUEST_USER, - " sudo: ALL=(ALL) NOPASSWD:ALL\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - " - name: root\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - "locale: en_US.UTF-8\n"]) - udata.close() - subprocess.check_call(["genisoimage", "-output", "cloud-init.iso", - "-volid", "cidata", "-joliet", "-rock", - "user-data", "meta-data"], - cwd=cidir, - stdin=self._devnull, stdout=self._stdout, - stderr=self._stdout) - return os.path.join(cidir, "cloud-init.iso") - def build_image(self, img): cimg = self._download_with_cache("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1802.qcow2.xz") img_tmp = img + ".tmp"@@ -69,7 +38,7 @@ class CentosVM(basevm.BaseVM): subprocess.check_call(["ln", "-f", cimg, img_tmp + ".xz"]) subprocess.check_call(["xz", "--keep", "-dvf", img_tmp + ".xz"]) self.exec_qemu_img("resize", img_tmp, "50G") - self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) + self.boot(img_tmp, extra_args = ["-cdrom", self.gen_cloud_init_iso()]) self.wait_ssh() self.ssh_root_check("touch /etc/cloud/cloud-init.disabled") self.ssh_root_check("yum update -y")tests/vm/ubuntu.i386 +1
-36@@ -29,41 +29,6 @@ class UbuntuX86VM(basevm.BaseVM): make --output-sync {target} -j{jobs} {verbose}; """ - def _gen_cloud_init_iso(self): - cidir = self._tmpdir - mdata = open(os.path.join(cidir, "meta-data"), "w") - mdata.writelines(["instance-id: ubuntu-vm-0\n", - "local-hostname: ubuntu-guest\n"]) - mdata.close() - udata = open(os.path.join(cidir, "user-data"), "w") - udata.writelines(["#cloud-config\n", - "chpasswd:\n", - " list: |\n", - " root:%s\n" % self.ROOT_PASS, - " %s:%s\n" % (self.GUEST_USER, self.GUEST_PASS), - " expire: False\n", - "users:\n", - " - name: %s\n" % self.GUEST_USER, - " sudo: ALL=(ALL) NOPASSWD:ALL\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - " - name: root\n", - " ssh-authorized-keys:\n", - " - %s\n" % basevm.SSH_PUB_KEY, - "locale: en_US.UTF-8\n"]) - proxy = os.environ.get("http_proxy") - if not proxy is None: - udata.writelines(["apt:\n", - " proxy: %s" % proxy]) - udata.close() - subprocess.check_call(["genisoimage", "-output", "cloud-init.iso", - "-volid", "cidata", "-joliet", "-rock", - "user-data", "meta-data"], - cwd=cidir, - stdin=self._devnull, stdout=self._stdout, - stderr=self._stdout) - return os.path.join(cidir, "cloud-init.iso") - def build_image(self, img): cimg = self._download_with_cache( "https://cloud-images.ubuntu.com/releases/bionic/release-20191114/ubuntu-18.04-server-cloudimg-i386.img",@@ -71,7 +36,7 @@ class UbuntuX86VM(basevm.BaseVM): img_tmp = img + ".tmp" subprocess.check_call(["cp", "-f", cimg, img_tmp]) self.exec_qemu_img("resize", img_tmp, "50G") - self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) + self.boot(img_tmp, extra_args = ["-cdrom", self.gen_cloud_init_iso()]) self.wait_ssh() self.ssh_root_check("touch /etc/cloud/cloud-init.disabled") self.ssh_root_check("apt-get update")
Signature · 1 line
Alex Bennée
PATCH 6/14 tests/vm: Add logging of console to file.
In reply to Robert FoleyThis adds logging of the char device used by the console to a file. The basevm.py then uses this file to read chars from the console.
One reason to add this is to aid with debugging. But another is because there is an issue where the QEMU might hang if the characters from the character device are not consumed by the script.
--- tests/vm/basevm.py | 48 ++++++++++++++++++++++--- tests/vm/socket_thread.py | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 tests/vm/socket_thread.py
tests/vm/basevm.py +43 -5
@@ -31,12 +31,17 @@ import tempfile import shutil import multiprocessing import traceback +from socket_thread import SocketThread SSH_KEY = open(os.path.join(os.path.dirname(__file__), "..", "keys", "id_rsa")).read() SSH_PUB_KEY = open(os.path.join(os.path.dirname(__file__), "..", "keys", "id_rsa.pub")).read() +class ConsoleTimeoutException(Exception): + """Raise this exception when read from console times out.""" + pass + class BaseVM(object): GUEST_USER = "qemu" GUEST_PASS = "qemupass"
@@ -59,12 +64,18 @@ class BaseVM(object): poweroff = "poweroff" # enable IPv6 networking ipv6 = True + # This is the timeout on the wait for console bytes. + socket_timeout = 120 # Scale up some timeouts under TCG. # 4 is arbitrary, but greater than 2, # since we found we need to wait more than twice as long. tcg_ssh_timeout_multiplier = 4 + console_logfile = "console.log" def __init__(self, debug=False, vcpus=None): self._guest = None + self._console_fd = None + self._socket_thread = None + self._console_timeout_sec = self.socket_timeout self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-", suffix=".tmp", dir="."))
@@ -179,6 +190,15 @@ class BaseVM(object): "-device", "virtio-blk,drive=%s,serial=%s,bootindex=1" % (name, name)] + def init_console(self, socket): + """Init the thread to dump console to a file. + Also open the file descriptor we will use to + read from the console.""" + self._socket_thread = SocketThread(socket, self.console_logfile) + self._console_fd = open(self.console_logfile, "r") + self._socket_thread.start() + print("console logfile is: {}".format(self.console_logfile)) + def boot(self, img, extra_args=[]): args = self._args + [ "-device", "VGA",
@@ -201,6 +221,7 @@ class BaseVM(object): raise atexit.register(self.shutdown) self._guest = guest + self.init_console(guest.console_socket) usernet_info = guest.qmp("human-monitor-command", command_line="info usernet") self.ssh_port = None
@@ -212,9 +233,10 @@ class BaseVM(object): raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \ usernet_info) - def console_init(self, timeout = 120): - vm = self._guest - vm.console_socket.settimeout(timeout) + def console_init(self, timeout = None): + if timeout == None: + timeout = self.socket_timeout + self._console_timeout_sec = timeout def console_log(self, text): for line in re.split("[\r\n]", text):
@@ -230,13 +252,27 @@ class BaseVM(object): # log console line sys.stderr.write("con recv: %s\n" % line) + def console_recv(self, n): + """Read n chars from the console_logfile being dumped to + by the socket thread we created earlier.""" + start_time = time.time() + while True: + data = self._console_fd.read(1) + if data != "": + break + time.sleep(0.1) + elapsed_sec = time.time() - start_time + if elapsed_sec > self._console_timeout_sec: + raise ConsoleTimeoutException + return data.encode('latin1') + def console_wait(self, expect, expectalt = None): vm = self._guest output = "" while True: try: - chars = vm.console_socket.recv(1) - except socket.timeout: + chars = self.console_recv(1) + except ConsoleTimeoutException: sys.stderr.write("console: *** read timeout ***\n") sys.stderr.write("console: waiting for: '%s'\n" % expect) if not expectalt is None:
@@ -335,6 +371,8 @@ class BaseVM(object): raise Exception("Timeout while waiting for guest ssh") def shutdown(self): + self._socket_thread.join() + self._console_fd.close() self._guest.shutdown() def wait(self): self._guest.wait()
tests/vm/socket_thread.py new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v1 06/14] tests/vm: Add logging of console to file.
Quoted 4 lines · Robert Foley
This adds logging of the char device used by the console to a file. The
basevm.pythen uses this file to read chars from the console.
One reason to add this is to aid with debugging.
I can certainly see an argument for saving the install log.
Quoted 3 lines
But another is because there is an issue where the QEMU might hang if the characters from the character device are not consumed by the script.
I'm a little confused by this. Outputting to a file and then parsing the file seems a bit more janky than injesting the output in the script and then logging it.
Is this to work around the hang because the socket buffers fill up and aren't drained?
Quoted 31 lines
Signed-off-by Robert Foley <[email protected]>--- tests/vm/basevm.py | 48 ++++++++++++++++++++++--- tests/vm/socket_thread.py | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 tests/vm/socket_thread.pytests/vm/basevm.py +5
-0@@ -31,12 +31,17 @@ import tempfile import shutil import multiprocessing import traceback +from socket_thread import SocketThread SSH_KEY = open(os.path.join(os.path.dirname(__file__), "..", "keys", "id_rsa")).read() SSH_PUB_KEY = open(os.path.join(os.path.dirname(__file__), "..", "keys", "id_rsa.pub")).read() +class ConsoleTimeoutException(Exception): + """Raise this exception when read from console times out.""" + pass + class BaseVM(object): GUEST_USER = "qemu" GUEST_PASS = "qemupass"
tests/vm/basevm.py class BaseVM(object): · line 73
Quoted 10 lines
tests/vm/basevm.py +3
-0@@ -59,12 +64,18 @@ class BaseVM(object): poweroff = "poweroff" # enable IPv6 networking ipv6 = True + # This is the timeout on the wait for console bytes. + socket_timeout = 120 # Scale up some timeouts under TCG. # 4 is arbitrary, but greater than 2, # since we found we need to wait more than twice as long. tcg_ssh_timeout_multiplier = 4 + console_logfile = "console.log"
We should probably dump the log somewhere other than cwd. Given we cache stuff in ~/.cache/qemu-vm maybe something of the form:
~/.cache/qemu-vm/ubuntu.aarch64.install.log
?
Quoted 54 lines
tests/vm/basevm.py +21
-3def __init__(self, debug=False, vcpus=None): self._guest = None + self._console_fd = None + self._socket_thread = None + self._console_timeout_sec = self.socket_timeout self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-", suffix=".tmp", dir="."))@@ -179,6 +190,15 @@ class BaseVM(object): "-device", "virtio-blk,drive=%s,serial=%s,bootindex=1" % (name, name)] + def init_console(self, socket): + """Init the thread to dump console to a file. + Also open the file descriptor we will use to + read from the console.""" + self._socket_thread = SocketThread(socket, self.console_logfile) + self._console_fd = open(self.console_logfile, "r") + self._socket_thread.start() + print("console logfile is: {}".format(self.console_logfile)) + def boot(self, img, extra_args=[]): args = self._args + [ "-device", "VGA",@@ -201,6 +221,7 @@ class BaseVM(object): raise atexit.register(self.shutdown) self._guest = guest + self.init_console(guest.console_socket) usernet_info = guest.qmp("human-monitor-command", command_line="info usernet") self.ssh_port = None@@ -212,9 +233,10 @@ class BaseVM(object): raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \ usernet_info) - def console_init(self, timeout = 120): - vm = self._guest - vm.console_socket.settimeout(timeout) + def console_init(self, timeout = None): + if timeout == None: + timeout = self.socket_timeout + self._console_timeout_sec = timeout def console_log(self, text): for line in re.split("[\r\n]", text):@@ -230,13 +252,27 @@ class BaseVM(object): # log console line sys.stderr.write("con recv: %s\n" % line) + def console_recv(self, n): + """Read n chars from the console_logfile being dumped to + by the socket thread we created earlier.""" + start_time = time.time()
tests/vm/basevm.py class BaseVM(object): · line 268
Quoted 10 lines
tests/vm/basevm.py +10
-0+ while True: + data = self._console_fd.read(1) + if data != "": + break + time.sleep(0.1) + elapsed_sec = time.time() - start_time + if elapsed_sec > self._console_timeout_sec: + raise ConsoleTimeoutException + return data.encode('latin1') +
Is latin1 really the best choice here? I would expect things to be utf-8 clean.
Quoted 90 lines
tests/vm/basevm.py +4
-2def console_wait(self, expect, expectalt = None): vm = self._guest output = "" while True: try: - chars = vm.console_socket.recv(1) - except socket.timeout: + chars = self.console_recv(1) + except ConsoleTimeoutException: sys.stderr.write("console: *** read timeout ***\n") sys.stderr.write("console: waiting for: '%s'\n" % expect) if not expectalt is None:@@ -335,6 +371,8 @@ class BaseVM(object): raise Exception("Timeout while waiting for guest ssh") def shutdown(self): + self._socket_thread.join() + self._console_fd.close() self._guest.shutdown() def wait(self): self._guest.wait()tests/vm/socket_thread.py new file +63
-0@@ -0,0 +1,73 @@ +#!/usr/bin/env python +# +# This python module defines a thread object which +# reads from a socket and dumps it to a file. +# +# The main use case is for reading QEMU console char dev and +# dumping them to a file either for debugging or for +# parsing by QEMU itself. +# +# Copyright 2020 Linaro +# +# Authors: +# Robert Foley <[email protected]> +# +# This code is licensed under the GPL version 2 or later. See +# the COPYING file in the top-level directory. +# +import sys +import re +import threading +import time +import traceback +import gettext + +class SocketThread(threading.Thread): + """ Implements the standard threading.Thread API.(start, join, etc.). + dumps all characters received on socket into a file. + """ + def __init__(self, socket, filename): + super(SocketThread, self).__init__() + self.alive = threading.Event() + self.alive.set() + self.socket = socket + self.log_file = open(filename, "w") + self.debug = True + + def receive(self): + """Until the user calls join, we will read chars from + the socket and dump them as is to the file.""" + self.socket.setblocking(0) + self.socket.settimeout(1.0) + while self.alive.isSet(): + try: + chars = self.socket.recv(1) + except: + continue + output = chars.decode("latin1") + self.log_file.write("{}".format(output)) + # Flush the file since we need the characters to be + # always up to date in case someone is reading the file + # waiting for some characters to show up. + self.log_file.flush() + self.socket.setblocking(1) + + def run(self): + """This is the main loop of the socket thread. + Simply receive from the file until the user + calls join.""" + while self.alive.isSet(): + try: + self.receive() + except Exception as e: + sys.stderr.write("Exception encountered\n")
tests/vm/socket_thread.py line 73
Quoted 10 lines
tests/vm/socket_thread.py new file +10
-0+ traceback.print_exc() + continue + + def join(self, timeout=None): + """Time to destroy the thread. + Clear the event to stop the thread, and wait for + it to complete.""" + self.alive.clear() + threading.Thread.join(self, timeout) + self.log_file.close()
I'm note sure about this - introducing threading into Python seems very un-pythonic. I wonder if the python experts have any view on a better way to achieve what we want which I think is:
- a buffer that properly drains output from QEMU
- which can optionally be serialised onto disk for logging
What else are we trying to achieve here?
Signature · 1 line
Alex Bennée
Re: [PATCH v1 06/14] tests/vm: Add logging of console to file.
Quoted 13 lines · Alex Bennée
Quoted 4 lines · Robert Foley
This adds logging of the char device used by the console to a file. The
basevm.pythen uses this file to read chars from the console.
One reason to add this is to aid with debugging.I can certainly see an argument for saving the install log.
Quoted 3 lines
But another is because there is an issue where the QEMU might hang if the characters from the character device are not consumed by the script.
Quoted 6 lines
I'm a little confused by this. Outputting to a file and then parsing the file seems a bit more janky than injesting the output in the script and then logging it.
Is this to work around the hang because the socket buffers fill up and aren't drained?
Yes, exactly. This is to work around the hang we are seeing when we try to use these new VMs.
Quoted 8 lines
Quoted 1 line
+
console_logfile= "console.log"We should probably dump the log somewhere other than cwd. Given we cache stuff in ~/.cache/qemu-vm maybe something of the form:
~/.cache/qemu-vm/ubuntu.aarch64.install.log
?
Good point, we will locate the log file there.
Quoted 7 lines
tests/vm/basevm.py class BaseVM(object): · line 268
Quoted 5 lines
tests/vm/basevm.py +5
-0+ elapsed_sec = time.time() - start_time + if elapsed_sec > self._console_timeout_sec: + raise ConsoleTimeoutException + return data.encode('latin1') +Is latin1 really the best choice here? I would expect things to be utf-8 clean.
We were trying to follow the existing code, which is using latin1. For example, console_wait() or console_consume() are using latin1. However on further inspection we see that console_send() is using utf-8. We will look at changing these latin1 cases to be utf-8.
I also found a case in get_qemu_version() we will change to utf-8 also.
Quoted 9 lines
tests/vm/socket_thread.py line 73
Quoted 8 lines
tests/vm/socket_thread.py new file +8
-0+ + def join(self, timeout=None): + """Time to destroy the thread. + Clear the event to stop the thread, and wait for + it to complete.""" + self.alive.clear() + threading.Thread.join(self, timeout) + self.log_file.close()
Quoted 8 lines
I'm note sure about this - introducing threading into Python seems very un-pythonic. I wonder if the python experts have any view on a better way to achieve what we want which I think is:
- a buffer that properly drains output from QEMU
- which can optionally be serialised onto disk for loggingWhat else are we trying to achieve here?
I think that covers what we are trying to achieve here.
The logging to file is a nice to have, but
the draining of the output from QEMU is the main objective here. We will do a bit more research here to seek out a cleaner way to achieve this, but certainly we would also be interested if any python experts have a view on a cleaner approach.
Thanks & Regards,
-Rob
Quoted 3 lines
--
Alex Bennée
Re: [PATCH v1 06/14] tests/vm: Add logging of console to file.
Quoted 18 lines · Robert Foley
Quoted 16 lines · Alex Bennée
tests/vm/socket_thread.py line 73
Quoted 8 lines
tests/vm/socket_thread.py new file +8
-0+ + def join(self, timeout=None): + """Time to destroy the thread. + Clear the event to stop the thread, and wait for + it to complete.""" + self.alive.clear() + threading.Thread.join(self, timeout) + self.log_file.close()I'm note sure about this - introducing threading into Python seems very un-pythonic. I wonder if the python experts have any view on a better way to achieve what we want which I think is:
- a buffer that properly drains output from QEMU
- which can optionally be serialised onto disk for logging
Quoted 9 lines
Quoted 1 line
What else are we trying to achieve here?
I think that covers what we are trying to achieve here.
The logging to file is a nice to have, but
the draining of the output from QEMU is the main objective here. We will do a bit more research here to seek out a cleaner way to achieve this, but certainly we would also be interested if any python experts have a view on a cleaner approach.
We have a few more ideas on how to make this a bit cleaner.
We could create a new class "ConsoleSocket", based on asyncore.dispatcher. The asyncore python library allows for overriding certain functionality of an underlying socket.
We could override the handle_read() method in order to get a callback when data is available to be read from the console. This is much cleaner than us simply waiting with a read() on the socket in a thread. Note that even asyncore requires a thread around asyncore.loop(), but we would only be responsible for start/stop of the thread and the thread body is defined for us (literally just asyncore.loop()).
The thread starting/stopping would be completely transparent
to the users of this new ConsoleSocket. The thread would be created on initialization of ConsoleSocket, and destroyed upon close() of the socket.
As the console bytes get consumed we can dump them to an in memory stream, rather than dumping them to a file right away.
We could perhaps use an io.StringIO text stream. This stream will get the bytes of the console and the test will consume the bytes directly from this stream.
In addition, we could optionally dump the bytes to a file as well.
How does this sound? Just looking for a bit of feedback before we head in this direction.
Thanks & Regards,
-Rob
PATCH 7/14 tests/vm: Add configuration to basevm.py
In reply to Robert FoleyAdded use of a configuration to tests/vm/basevm.py.
The configuration provides parameters used to configure a VM. This allows for providing alternate configurations to the VM being created/launched. cpu, machine, memory, and NUMA configuration are all examples of configuration which we might want to vary on the VM being created or launched.
This will for example allow for creating an aarch64 vm.
--- tests/vm/basevm.py | 141 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 111 insertions(+), 30 deletions(-)
tests/vm/basevm.py +111 -30
@@ -33,19 +33,43 @@ import multiprocessing import traceback from socket_thread import SocketThread -SSH_KEY = open(os.path.join(os.path.dirname(__file__), - "..", "keys", "id_rsa")).read() -SSH_PUB_KEY = open(os.path.join(os.path.dirname(__file__), - "..", "keys", "id_rsa.pub")).read() +SSH_KEY_FILE = os.path.join(os.path.dirname(__file__), + "..", "keys", "id_rsa") +SSH_PUB_KEY_FILE = os.path.join(os.path.dirname(__file__), + "..", "keys", "id_rsa.pub") class ConsoleTimeoutException(Exception): """Raise this exception when read from console times out.""" pass +# This is the standard configuration. +# Any or all of these can be overridden by +# passing in a config argument to the VM constructor. +DEFAULT_CONFIG = { + 'cpu' : "max", + 'machine' : 'pc', + 'guest_user' : "qemu", + 'guest_pass' : "qemupass", + 'root_pass' : "qemupass", + 'ssh_key_file' : SSH_KEY_FILE, + 'ssh_pub_key_file': SSH_PUB_KEY_FILE, + 'memory' : "4G", + 'extra_args' : [], + 'qemu_args' : "", + 'dns' : "", + 'ssh_port' : 0, + 'install_cmds' : "", + 'boot_dev_type' : "block", + 'ssh_timeout' : 1, +} +BOOT_DEVICE = { + 'block' : "-drive file={},if=none,id=drive0,cache=writeback "\ + "-device virtio-blk,drive=drive0,bootindex=0", + 'scsi' : "-device virtio-scsi-device,id=scsi "\ + "-drive file={},format=raw,if=none,id=hd0 "\ + "-device scsi-hd,drive=hd0,bootindex=0", +} class BaseVM(object): - GUEST_USER = "qemu" - GUEST_PASS = "qemupass" - ROOT_PASS = "qemupass" envvars = [ "https_proxy",
@@ -71,22 +95,33 @@ class BaseVM(object): # since we found we need to wait more than twice as long. tcg_ssh_timeout_multiplier = 4 console_logfile = "console.log" - def __init__(self, debug=False, vcpus=None): + def __init__(self, debug=False, vcpus=None, config=None): self._guest = None self._console_fd = None self._socket_thread = None self._console_timeout_sec = self.socket_timeout + # Allow input config to override defaults. + self._config = DEFAULT_CONFIG.copy() + if config != None: + self._config.update(config) + self.validate_ssh_keys() self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-", suffix=".tmp", dir=".")) atexit.register(shutil.rmtree, self._tmpdir) - - self._ssh_key_file = os.path.join(self._tmpdir, "id_rsa") - open(self._ssh_key_file, "w").write(SSH_KEY) - subprocess.check_call(["chmod", "600", self._ssh_key_file]) - - self._ssh_pub_key_file = os.path.join(self._tmpdir, "id_rsa.pub") - open(self._ssh_pub_key_file, "w").write(SSH_PUB_KEY) + # Copy the key files to a temporary directory. + # Also chmod the key file to agree with ssh requirements. + self._config['ssh_key'] = \ + open(self._config['ssh_key_file']).read().rstrip() + self._config['ssh_pub_key'] = \ + open(self._config['ssh_pub_key_file']).read().rstrip() + self._ssh_tmp_key_file = os.path.join(self._tmpdir, "id_rsa") + open(self._ssh_tmp_key_file, "w").write(self._config['ssh_key']) + subprocess.check_call(["chmod", "600", self._ssh_tmp_key_file]) + + self._ssh_tmp_pub_key_file = os.path.join(self._tmpdir, "id_rsa.pub") + open(self._ssh_tmp_pub_key_file, + "w").write(self._config['ssh_pub_key']) self.debug = debug self._stderr = sys.stderr
@@ -95,11 +130,14 @@ class BaseVM(object): self._stdout = sys.stdout else: self._stdout = self._devnull + netdev = "user,id=vnet,hostfwd=:127.0.0.1:{}-:22" self._args = [ \ - "-nodefaults", "-m", "4G", - "-cpu", "max", - "-netdev", "user,id=vnet,hostfwd=:127.0.0.1:0-:22" + - (",ipv6=no" if not self.ipv6 else ""), + "-nodefaults", "-m", self._config['memory'], + "-cpu", self._config['cpu'], + "-netdev", + netdev.format(self._config['ssh_port']) + + (",ipv6=no" if not self.ipv6 else "") + + (",dns=" + self._config['dns'] if self._config['dns'] else ""), "-device", "virtio-net-pci,netdev=vnet", "-vnc", "127.0.0.1:0,to=20"] if vcpus and vcpus > 1:
@@ -110,6 +148,45 @@ class BaseVM(object): logging.info("KVM not available, not using -enable-kvm") self._data_args = [] + if self._config['qemu_args'] != None: + qemu_args = self._config['qemu_args'] + qemu_args = qemu_args.replace('\n',' ').replace('\r','') + # Remove any empty strings from list. + self._config['extra_args'] = [x for x in qemu_args.split(' ') if x] + + def validate_ssh_keys(self): + """Check to see if the ssh key files exist.""" + if 'ssh_key_file' not in self._config or\ + not os.path.exists(self._config['ssh_key_file']): + raise Exception("ssh key file not found.") + if 'ssh_pub_key_file' not in self._config or\ + not os.path.exists(self._config['ssh_pub_key_file']): + raise Exception("ssh pub key file not found.") + + def wait_boot(self, wait_string=None): + """Wait for the standard string we expect + on completion of a normal boot. + The user can also choose to override with an + alternate string to wait for.""" + if wait_string is None: + if self.login_prompt is None: + raise Exception("self.login_prompt not defined") + wait_string = self.login_prompt + # Intentionally bump up the default timeout under TCG, + # since the console wait below takes longer. + timeout = self.socket_timeout + if not kvm_available(self.arch): + timeout *= 8 + self.console_init(timeout=timeout) + self.console_wait(wait_string) + + def __getattr__(self, name): + # Support direct access to config by key. + # for example, access self._config['cpu'] by self.cpu + if name.lower() in self._config.keys(): + return self._config[name.lower()] + return object.__getattribute__(self, name) + def _download_with_cache(self, url, sha256sum=None, sha512sum=None): def check_sha256sum(fname): if not sha256sum:
@@ -141,8 +218,9 @@ class BaseVM(object): "-t", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=" + os.devnull, - "-o", "ConnectTimeout=1", - "-p", self.ssh_port, "-i", self._ssh_key_file] + "-o", + "ConnectTimeout={}".format(self._config["ssh_timeout"]), + "-p", self.ssh_port, "-i", self._ssh_tmp_key_file] # If not in debug mode, set ssh to quiet mode to # avoid printing the results of commands. if not self.debug:
@@ -200,15 +278,15 @@ class BaseVM(object): print("console logfile is: {}".format(self.console_logfile)) def boot(self, img, extra_args=[]): - args = self._args + [ - "-device", "VGA", - "-drive", "file=%s,if=none,id=drive0,cache=writeback" % img, - "-device", "virtio-blk,drive=drive0,bootindex=0"] - args += self._data_args + extra_args + boot_dev = BOOT_DEVICE[self._config['boot_dev_type']] + boot_params = boot_dev.format(img) + args = self._args + boot_params.split(' ') + args += self._data_args + extra_args + self._config['extra_args'] + args += ["-device", "VGA"] logging.debug("QEMU args: %s", " ".join(args)) qemu_bin = os.environ.get("QEMU", "qemu-system-" + self.arch) guest = QEMUMachine(binary=qemu_bin, args=args) - guest.set_machine('pc') + guest.set_machine(self._config['machine']) guest.set_console() try: guest.launch()
@@ -332,7 +410,8 @@ class BaseVM(object): self.console_send(command) def console_ssh_init(self, prompt, user, pw): - sshkey_cmd = "echo '%s' > .ssh/authorized_keys\n" % SSH_PUB_KEY.rstrip() + sshkey_cmd = "echo '%s' > .ssh/authorized_keys\n" \ + % self._config['ssh_pub_key'].rstrip() self.console_wait_send("login:", "%s\n" % user) self.console_wait_send("Password:", "%s\n" % pw) self.console_wait_send(prompt, "mkdir .ssh\n")
@@ -461,15 +540,17 @@ def parse_args(vmcls): parser.disable_interspersed_args() return parser.parse_args() -def main(vmcls): +def main(vmcls, config=None): try: + if config == None: + config = {} args, argv = parse_args(vmcls) if not argv and not args.build_qemu and not args.build_image: print("Nothing to do?") return 1 logging.basicConfig(level=(logging.DEBUG if args.debug else logging.WARN)) - vm = vmcls(debug=args.debug, vcpus=args.jobs) + vm = vmcls(debug=args.debug, vcpus=args.jobs, config=config) if args.build_image: if os.path.exists(args.image) and not args.force: sys.stderr.writelines(["Image file exists: %s\n" % args.image,
Signature · 1 line
2.17.1
PATCH 8/14 tests/vm: Added configuration file support
In reply to Robert FoleyChanges to tests/vm/basevm.py to allow accepting a configuration file as a parameter. Allows for specifying VM options such as
cpu, machine, memory, and arbitrary qemu arguments for specifying options such as NUMA configuration.
Also added an example conf_example_aarch64.yml and conf_example_x86.yml.
--- tests/vm/Makefile.include | 2 ++ tests/vm/basevm.py | 29 +++++++++++++++++- tests/vm/conf_example_aarch64.yml | 51 +++++++++++++++++++++++++++++++ tests/vm/conf_example_x86.yml | 50 ++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 tests/vm/conf_example_aarch64.yml create mode 100644 tests/vm/conf_example_x86.yml
tests/vm/Makefile.include +2 -0
@@ -35,6 +35,8 @@ vm-help vm-test: @echo " V=1 - Enable verbose ouput on host and guest commands" @echo " QEMU=/path/to/qemu - Change path to QEMU binary" @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" + @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." + @echo " See conf_example_*.yml for file format details." vm-build-all: $(addprefix vm-build-, $(IMAGES))
tests/vm/basevm.py +28 -1
@@ -32,6 +32,7 @@ import shutil import multiprocessing import traceback from socket_thread import SocketThread +import yaml SSH_KEY_FILE = os.path.join(os.path.dirname(__file__), "..", "keys", "id_rsa")
@@ -500,9 +501,31 @@ class BaseVM(object): cwd=cidir, stdin=self._devnull, stdout=self._stdout, stderr=self._stdout) - return os.path.join(cidir, "cloud-init.iso") +def parse_config(config, args): + """ Parse yaml config and populate our config structure. + The yaml config allows the user to override the + defaults for VM parameters. In many cases these + defaults can be overridden without rebuilding the VM.""" + if args.config: + config_file = args.config + elif 'QEMU_CONFIG' in os.environ: + config_file = os.environ['QEMU_CONFIG'] + else: + return config + if not os.path.exists(config_file): + raise Exception("config file {} does not exist".format(config_file)) + with open(config_file) as f: + yaml_dict = yaml.safe_load(f) + + if 'qemu-conf' in yaml_dict: + config.update(yaml_dict['qemu-conf']) + else: + raise Exception("config file {} is not valid"\ + " missing qemu-conf".format(config_file)) + return config + def parse_args(vmcls): def get_default_jobs():
@@ -537,6 +560,9 @@ def parse_args(vmcls): help="Interactively run command") parser.add_option("--snapshot", "-s", action="store_true", help="run tests with a snapshot") + parser.add_option("--config", "-c", default=None, + help="Provide config yaml for configuration. "\ + "See config_example.yaml for example.") parser.disable_interspersed_args() return parser.parse_args()
@@ -548,6 +574,7 @@ def main(vmcls, config=None): if not argv and not args.build_qemu and not args.build_image: print("Nothing to do?") return 1 + config = parse_config(config, args) logging.basicConfig(level=(logging.DEBUG if args.debug else logging.WARN)) vm = vmcls(debug=args.debug, vcpus=args.jobs, config=config)
tests/vm/conf_example_aarch64.yml new file +51 -0
51 lines not on this page · raw message
tests/vm/conf_example_x86.yml new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v1 08/14] tests/vm: Added configuration file support
Quoted 34 lines · Robert Foley
Changes to
tests/vm/basevm.pyto allow accepting a configuration file as a parameter. Allows for specifying VM options such as
cpu, machine, memory, and arbitrary qemu arguments for specifying options such as NUMA configuration.
Also added an example conf_example_aarch64.yml and conf_example_x86.yml.Signed-off-by Robert Foley <[email protected]>--- tests/vm/Makefile.include | 2 ++ tests/vm/basevm.py | 29 +++++++++++++++++- tests/vm/conf_example_aarch64.yml | 51 +++++++++++++++++++++++++++++++ tests/vm/conf_example_x86.yml | 50 ++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 tests/vm/conf_example_aarch64.yml create mode 100644 tests/vm/conf_example_x86.ymltests/vm/Makefile.include +2
-0@@ -35,6 +35,8 @@ vm-help vm-test: @echo " V=1 - Enable verbose ouput on host and guest commands" @echo " QEMU=/path/to/qemu - Change path to QEMU binary" @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" + @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." + @echo " See conf_example_*.yml for file format details." vm-build-all: $(addprefix vm-build-, $(IMAGES))tests/vm/basevm.py +0
-0
tests/vm/basevm.py import shutil · line 35
Quoted 4 lines
tests/vm/basevm.py +1
-0@@ -32,6 +32,7 @@ import shutil import multiprocessing import traceback from socket_thread import SocketThread +import yaml
So this throws my setup on my Gentoo SynQuacer. Is this meant to be in the standard library or is this a separate dependency?
Signature · 1 line
Alex Bennée
Re: [PATCH v1 08/14] tests/vm: Added configuration file support
Quoted 6 lines · Alex Bennée
Quoted 2 lines
from
socket_threadimport SocketThread
+import yamlSo this throws my setup on my Gentoo SynQuacer. Is this meant to be in the standard library or is this a separate dependency?
This is a separate dependency. On Ubuntu the package is python3-yaml. This brings up an interesting point.
If the yaml dependency is not there, should we expect to gracefully handle this in the python script, and
simply not allow yaml files? I suppose we could error out if a yaml file is supplied
and ask for the dependency to get installed.
Or is there something we should do earlier, maybe in the configure, to warn or error about the missing
dependency?
Thanks & Regards,
-Rob
Quoted 2 lines
--
Alex Bennée
PATCH 9/14 tests/vm: add --boot-console switch
In reply to Robert FoleyAdded ability to view console during boot via
--boot-console switch to basevm.py. This helps debug issues that occur during the boot sequence.
Also added a new special variable to vm-build:
BOOT_CONSOLE=1 will cause this new --boot-console switch to be set.
--- tests/vm/Makefile.include | 4 ++++ tests/vm/basevm.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
tests/vm/Makefile.include +4 -0
@@ -32,6 +32,7 @@ vm-help vm-test: @echo ' EXTRA_CONFIGURE_OPTS="..."' @echo " J=[0..9]* - Override the -jN parameter for make commands" @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" + @echo " BOOT_CONSOLE=1 - Show the console output at boot time. " @echo " V=1 - Enable verbose ouput on host and guest commands" @echo " QEMU=/path/to/qemu - Change path to QEMU binary" @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool"
@@ -50,6 +51,7 @@ $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \ $(call quiet-command, \ $(PYTHON) $< \ $(if $(V)$(DEBUG), --debug) \ + $(if $(BOOT_CONSOLE),--boot-console) \ --image "$@" \ --force \ --build-image $@, \
@@ -64,6 +66,7 @@ vm-build-%: $(IMAGES_DIR)/%.img $(if $(DEBUG), --interactive) \ $(if $(J),--jobs $(J)) \ $(if $(V),--verbose) \ + $(if $(BOOT_CONSOLE),--boot-console) \ --image "$<" \ $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ --snapshot \
@@ -84,6 +87,7 @@ vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(call quiet-command, \ $(PYTHON) $(SRC_PATH)/tests/vm/$* \ $(if $(J),--jobs $(J)) \ + $(if $(BOOT_CONSOLE),--boot-console) \ --image "$<" \ --interactive \ false, \
tests/vm/basevm.py +9 -2
@@ -96,9 +96,11 @@ class BaseVM(object): # since we found we need to wait more than twice as long. tcg_ssh_timeout_multiplier = 4 console_logfile = "console.log" - def __init__(self, debug=False, vcpus=None, config=None): + def __init__(self, debug=False, vcpus=None, config=None, + boot_console=None): self._guest = None self._console_fd = None + self._boot_console = boot_console self._socket_thread = None self._console_timeout_sec = self.socket_timeout # Allow input config to override defaults.
@@ -563,6 +565,8 @@ def parse_args(vmcls): parser.add_option("--config", "-c", default=None, help="Provide config yaml for configuration. "\ "See config_example.yaml for example.") + parser.add_option("--boot-console", action="store_true", + help="Show console during boot. ") parser.disable_interspersed_args() return parser.parse_args()
@@ -577,7 +581,8 @@ def main(vmcls, config=None): config = parse_config(config, args) logging.basicConfig(level=(logging.DEBUG if args.debug else logging.WARN)) - vm = vmcls(debug=args.debug, vcpus=args.jobs, config=config) + vm = vmcls(debug=args.debug, vcpus=args.jobs, config=config, + boot_console=args.boot_console) if args.build_image: if os.path.exists(args.image) and not args.force: sys.stderr.writelines(["Image file exists: %s\n" % args.image,
@@ -597,6 +602,8 @@ def main(vmcls, config=None): if args.snapshot: img += ",snapshot=on" vm.boot(img) + if vm._boot_console: + vm.wait_boot() vm.wait_ssh() except Exception as e: if isinstance(e, SystemExit) and e.code == 0:
Signature · 1 line
2.17.1
PATCH 10/14 tests/vm: Add ability to select QEMU from current build.
In reply to Robert FoleyAdded a new special variable QEMU_LOCAL=1, which will indicate to take the QEMU binary from the current build.
--- tests/vm/Makefile.include | 4 ++++ tests/vm/basevm.py | 28 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-)
tests/vm/Makefile.include +4 -0
@@ -34,6 +34,7 @@ vm-help vm-test: @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" @echo " BOOT_CONSOLE=1 - Show the console output at boot time. " @echo " V=1 - Enable verbose ouput on host and guest commands" + @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build." @echo " QEMU=/path/to/qemu - Change path to QEMU binary" @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file."
@@ -52,6 +53,7 @@ $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \ $(PYTHON) $< \ $(if $(V)$(DEBUG), --debug) \ $(if $(BOOT_CONSOLE),--boot-console) \ + --build-path $(BUILD_DIR)\ --image "$@" \ --force \ --build-image $@, \
@@ -67,6 +69,7 @@ vm-build-%: $(IMAGES_DIR)/%.img $(if $(J),--jobs $(J)) \ $(if $(V),--verbose) \ $(if $(BOOT_CONSOLE),--boot-console) \ + --build-path $(BUILD_DIR)\ --image "$<" \ $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ --snapshot \
@@ -88,6 +91,7 @@ vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(PYTHON) $(SRC_PATH)/tests/vm/$* \ $(if $(J),--jobs $(J)) \ $(if $(BOOT_CONSOLE),--boot-console) \ + --build-path $(BUILD_DIR)\ --image "$<" \ --interactive \ false, \
tests/vm/basevm.py +24 -4
@@ -97,9 +97,10 @@ class BaseVM(object): tcg_ssh_timeout_multiplier = 4 console_logfile = "console.log" def __init__(self, debug=False, vcpus=None, config=None, - boot_console=None): + boot_console=None, build_path=None): self._guest = None self._console_fd = None + self._build_path = build_path self._boot_console = boot_console self._socket_thread = None self._console_timeout_sec = self.socket_timeout
@@ -287,8 +288,8 @@ class BaseVM(object): args += self._data_args + extra_args + self._config['extra_args'] args += ["-device", "VGA"] logging.debug("QEMU args: %s", " ".join(args)) - qemu_bin = os.environ.get("QEMU", "qemu-system-" + self.arch) - guest = QEMUMachine(binary=qemu_bin, args=args) + qemu_path = get_qemu_path(self.arch, self._build_path) + guest = QEMUMachine(binary=qemu_path, args=args) guest.set_machine(self._config['machine']) guest.set_console() try:
@@ -505,6 +506,22 @@ class BaseVM(object): stderr=self._stdout) return os.path.join(cidir, "cloud-init.iso") +def get_qemu_path(arch, build_path=None): + """Fetch the path to the qemu binary.""" + qemu_local = os.environ.get("QEMU_LOCAL", 0) + # If QEMU environment variable set, it takes precedence + if "QEMU" in os.environ: + qemu_path = os.environ["QEMU"] + elif qemu_local: + if not build_path: + raise Exception("--build-path option required with QEMU_LOCAL") + qemu_path = os.path.join(build_path, arch + "-softmmu") + qemu_path = os.path.join(qemu_path, "qemu-system-" + arch) + else: + # Default is to use system path for qemu. + qemu_path = "qemu-system-" + arch + return qemu_path + def parse_config(config, args): """ Parse yaml config and populate our config structure. The yaml config allows the user to override the
@@ -567,6 +584,8 @@ def parse_args(vmcls): "See config_example.yaml for example.") parser.add_option("--boot-console", action="store_true", help="Show console during boot. ") + parser.add_option("--build-path", default=None, + help="Path of build directory. ") parser.disable_interspersed_args() return parser.parse_args()
@@ -582,7 +601,8 @@ def main(vmcls, config=None): logging.basicConfig(level=(logging.DEBUG if args.debug else logging.WARN)) vm = vmcls(debug=args.debug, vcpus=args.jobs, config=config, - boot_console=args.boot_console) + boot_console=args.boot_console, + build_path=args.build_path) if args.build_image: if os.path.exists(args.image) and not args.force: sys.stderr.writelines(["Image file exists: %s\n" % args.image,
Signature · 1 line
2.17.1
PATCH 11/14 tests/vm: allow wait_ssh() to specify command
In reply to Robert FoleyThis allows for waiting for completion of arbitrary commands.
--- tests/vm/basevm.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
tests/vm/basevm.py +7 -7
@@ -433,24 +433,24 @@ class BaseVM(object): def print_step(self, text): sys.stderr.write("### %s ...\n" % text) - def wait_ssh(self, wait_root=False, seconds=300): + def wait_ssh(self, wait_root=False, seconds=300, cmd="exit 0"): # Allow more time for VM to boot under TCG. if not kvm_available(self.arch): seconds *= self.tcg_ssh_timeout_multiplier starttime = datetime.datetime.now() endtime = starttime + datetime.timedelta(seconds=seconds) - guest_up = False + cmd_success = False while datetime.datetime.now() < endtime: - if wait_root and self.ssh_root("exit 0") == 0: - guest_up = True + if wait_root and self.ssh_root(cmd) == 0: + cmd_success = True break - elif self.ssh("exit 0") == 0: - guest_up = True + elif self.ssh(cmd) == 0: + cmd_success = True break seconds = (endtime - datetime.datetime.now()).total_seconds() logging.debug("%ds before timeout", seconds) time.sleep(1) - if not guest_up: + if not cmd_success: raise Exception("Timeout while waiting for guest ssh") def shutdown(self):
Signature · 1 line
2.17.1
PATCH 12/14 tests/vm: Added a new script for ubuntu.aarch64.
In reply to Robert Foleyubuntu.aarch64 provides a script to create an Ubuntu 18.04 VM. Another new file is also added aarch64vm.py, which is a module with common methods used by aarch64 VMs, such as how to create the flash images.
--- tests/vm/Makefile.include | 3 +- tests/vm/aarch64vm.py | 100 +++++++++++++++++++++++++++++++++ tests/vm/basevm.py | 8 +++ tests/vm/ubuntu.aarch64 | 113 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 tests/vm/aarch64vm.py create mode 100755 tests/vm/ubuntu.aarch64
tests/vm/Makefile.include +2 -1
@@ -2,7 +2,7 @@ .PHONY: vm-build-all vm-clean-all -IMAGES := ubuntu.i386 freebsd netbsd openbsd centos fedora +IMAGES := ubuntu.i386 freebsd netbsd openbsd centos fedora ubuntu.aarch64 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
@@ -18,6 +18,7 @@ vm-help vm-test: @echo " vm-build-openbsd - Build QEMU in OpenBSD VM" @echo " vm-build-centos - Build QEMU in CentOS VM, with Docker" @echo " vm-build-fedora - Build QEMU in Fedora VM" + @echo " vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 VM" @echo "" @echo " vm-build-all - Build QEMU in all VMs" @echo " vm-clean-all - Clean up VM images"
tests/vm/aarch64vm.py new file +100 -0
100 lines not on this page · raw message
tests/vm/basevm.py +8 -0
@@ -522,6 +522,14 @@ def get_qemu_path(arch, build_path=None): qemu_path = "qemu-system-" + arch return qemu_path +def get_qemu_version(qemu_path): + """Get the version number from the current QEMU, + and return the major number.""" + output = subprocess.check_output([qemu_path, '--version']) + version_line = output.decode("latin1") + version_num = re.split(' |\(', version_line)[3].split('.')[0] + return int(version_num) + def parse_config(config, args): """ Parse yaml config and populate our config structure. The yaml config allows the user to override the
tests/vm/ubuntu.aarch64 new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 13/14 tests/vm: Added a new script for centos.aarch64.
In reply to Robert Foleycentos.aarch64 creates a CentOS 8 image.
Also added a new kickstart script used to build the centos.aarch64 image.
--- tests/vm/Makefile.include | 3 +- tests/vm/centos-8-aarch64.ks | 51 ++++++++ tests/vm/centos.aarch64 | 221 +++++++++++++++++++++++++++++++++++ 3 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 tests/vm/centos-8-aarch64.ks create mode 100755 tests/vm/centos.aarch64
tests/vm/Makefile.include +2 -1
@@ -2,7 +2,7 @@ .PHONY: vm-build-all vm-clean-all -IMAGES := ubuntu.i386 freebsd netbsd openbsd centos fedora ubuntu.aarch64 +IMAGES := ubuntu.i386 freebsd netbsd openbsd centos fedora ubuntu.aarch64 centos.aarch64 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
@@ -19,6 +19,7 @@ vm-help vm-test: @echo " vm-build-centos - Build QEMU in CentOS VM, with Docker" @echo " vm-build-fedora - Build QEMU in Fedora VM" @echo " vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 VM" + @echo " vm-build-centos.aarch64 - Build QEMU in CentOS aarch64 VM" @echo "" @echo " vm-build-all - Build QEMU in all VMs" @echo " vm-clean-all - Clean up VM images"
tests/vm/centos-8-aarch64.ks new file +51 -0
51 lines not on this page · raw message
tests/vm/centos.aarch64 new file +221 -0
221 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 14/14 tests/vm: change scripts to use self._config
In reply to Robert FoleyThis change converts existing scripts to using for example self.ROOT_PASS, to self._config['root_pass'].
We made similar changes for GUEST_USER, and GUEST_PASS.
This allows us also to remove the change in basevm.py,
which adds __getattr__ for backwards compatibility.
--- tests/vm/basevm.py | 11 ++--------- tests/vm/fedora | 17 +++++++++-------- tests/vm/freebsd | 16 ++++++++-------- tests/vm/netbsd | 19 ++++++++++--------- tests/vm/openbsd | 17 +++++++++-------- 5 files changed, 38 insertions(+), 42 deletions(-)
tests/vm/basevm.py +2 -9
@@ -184,13 +184,6 @@ class BaseVM(object): self.console_init(timeout=timeout) self.console_wait(wait_string) - def __getattr__(self, name): - # Support direct access to config by key. - # for example, access self._config['cpu'] by self.cpu - if name.lower() in self._config.keys(): - return self._config[name.lower()] - return object.__getattribute__(self, name) - def _download_with_cache(self, url, sha256sum=None, sha512sum=None): def check_sha256sum(fname): if not sha256sum:
@@ -240,13 +233,13 @@ class BaseVM(object): return r def ssh(self, *cmd): - return self._ssh_do(self.GUEST_USER, cmd, False) + return self._ssh_do(self._config["guest_user"], cmd, False) def ssh_root(self, *cmd): return self._ssh_do("root", cmd, False) def ssh_check(self, *cmd): - self._ssh_do(self.GUEST_USER, cmd, True) + self._ssh_do(self._config["guest_user"], cmd, True) def ssh_root_check(self, *cmd): self._ssh_do("root", cmd, True)
tests/vm/fedora +9 -8
@@ -105,20 +105,20 @@ class FedoraVM(basevm.BaseVM): self.console_wait_send("7) [!] Root password", "7\n") self.console_wait("Password:") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait("Password (confirm):") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait_send("8) [ ] User creation", "8\n") self.console_wait_send("1) [ ] Create user", "1\n") self.console_wait_send("3) User name", "3\n") - self.console_wait_send("ENTER:", "%s\n" % self.GUEST_USER) + self.console_wait_send("ENTER:", "%s\n" % self._config["guest_user"]) self.console_wait_send("4) [ ] Use password", "4\n") self.console_wait_send("5) Password", "5\n") self.console_wait("Password:") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait("Password (confirm):") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait_send("7) Groups", "c\n") while True:
@@ -136,7 +136,7 @@ class FedoraVM(basevm.BaseVM): if good: break time.sleep(10) - self.console_send("r\n" % self.GUEST_PASS) + self.console_send("r\n" % self._config["guest_pass"]) self.console_wait_send("'b' to begin install", "b\n")
@@ -147,12 +147,13 @@ class FedoraVM(basevm.BaseVM): # setup qemu user prompt = " ~]$" - self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS) + self.console_ssh_init(prompt, self._config["guest_user"], + self._config["guest_pass"]) self.console_wait_send(prompt, "exit\n") # setup root user prompt = " ~]#" - self.console_ssh_init(prompt, "root", self.ROOT_PASS) + self.console_ssh_init(prompt, "root", self._config["root_pass"]) self.console_sshd_config(prompt) # setup virtio-blk #1 (tarfile)
tests/vm/freebsd +8 -8
@@ -110,9 +110,9 @@ class FreeBSDVM(basevm.BaseVM): # post-install configuration self.console_wait("New Password:") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait("Retype New Password:") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait_send("Network Configuration", "\n") self.console_wait_send("IPv4", "y")
@@ -131,9 +131,9 @@ class FreeBSDVM(basevm.BaseVM): # qemu user self.console_wait_send("Add User Accounts", "y") self.console_wait("Username") - self.console_send("%s\n" % self.GUEST_USER) + self.console_send("%s\n" % self._config["guest_user"]) self.console_wait("Full name") - self.console_send("%s\n" % self.GUEST_USER) + self.console_send("%s\n" % self._config["guest_user"]) self.console_wait_send("Uid", "\n") self.console_wait_send("Login group", "\n") self.console_wait_send("Login group", "\n")
@@ -145,9 +145,9 @@ class FreeBSDVM(basevm.BaseVM): self.console_wait_send("Use an empty password", "\n") self.console_wait_send("Use a random password", "\n") self.console_wait("Enter password:") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait("Enter password again:") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait_send("Lock out", "\n") self.console_wait_send("OK", "yes\n") self.console_wait_send("Add another user", "no\n")
@@ -161,12 +161,12 @@ class FreeBSDVM(basevm.BaseVM): # setup qemu user prompt = "$" - self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS) + self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"]) self.console_wait_send(prompt, "exit\n") # setup root user prompt = "root@freebsd:~ #" - self.console_ssh_init(prompt, "root", self.ROOT_PASS) + self.console_ssh_init(prompt, "root", self._config["root_pass"]) self.console_sshd_config(prompt) # setup serial console
tests/vm/netbsd +10 -9
@@ -128,24 +128,24 @@ class NetBSDVM(basevm.BaseVM): self.console_wait_send("d: Change root password", "d\n") self.console_wait_send("a: Yes", "a\n") self.console_wait("New password:") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait("New password:") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait("Retype new password:") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait_send("o: Add a user", "o\n") self.console_wait("username") - self.console_send("%s\n" % self.GUEST_USER) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait("to group wheel") self.console_wait_send("a: Yes", "a\n") self.console_wait_send("a: /bin/sh", "a\n") self.console_wait("New password:") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait("New password:") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait("Retype new password:") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait_send("a: Configure network", "a\n") self.console_wait_send("a: vioif0", "a\n")
@@ -178,12 +178,13 @@ class NetBSDVM(basevm.BaseVM): # setup qemu user prompt = "localhost$" - self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS) + self.console_ssh_init(prompt, self._config["guest_user"], + self._config["guest_pass"]) self.console_wait_send(prompt, "exit\n") # setup root user prompt = "localhost#" - self.console_ssh_init(prompt, "root", self.ROOT_PASS) + self.console_ssh_init(prompt, "root", self._config["root_pass"]) self.console_sshd_config(prompt) # setup virtio-blk #1 (tarfile)
tests/vm/openbsd +9 -8
@@ -95,9 +95,9 @@ class OpenBSDVM(basevm.BaseVM): self.console_wait_send("Which network interface", "done\n") self.console_wait_send("DNS domain name", "localnet\n") self.console_wait("Password for root account") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait("Password for root account") - self.console_send("%s\n" % self.ROOT_PASS) + self.console_send("%s\n" % self._config["root_pass"]) self.console_wait_send("Start sshd(8)", "yes\n") self.console_wait_send("X Window System", "\n") self.console_wait_send("xenodm", "\n")
@@ -105,13 +105,13 @@ class OpenBSDVM(basevm.BaseVM): self.console_wait_send("Which speed", "\n") self.console_wait("Setup a user") - self.console_send("%s\n" % self.GUEST_USER) + self.console_send("%s\n" % self._config["guest_user"]) self.console_wait("Full name") - self.console_send("%s\n" % self.GUEST_USER) + self.console_send("%s\n" % self._config["guest_user"]) self.console_wait("Password") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait("Password") - self.console_send("%s\n" % self.GUEST_PASS) + self.console_send("%s\n" % self._config["guest_pass"]) self.console_wait_send("Allow root ssh login", "yes\n") self.console_wait_send("timezone", "UTC\n")
@@ -132,12 +132,13 @@ class OpenBSDVM(basevm.BaseVM): # setup qemu user prompt = "$" - self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS) + self.console_ssh_init(prompt, self._config["guest_user"], + self._config["guest_pass"]) self.console_wait_send(prompt, "exit\n") # setup root user prompt = "openbsd#" - self.console_ssh_init(prompt, "root", self.ROOT_PASS) + self.console_ssh_init(prompt, "root", self._config["root_pass"]) self.console_sshd_config(prompt) # setup virtio-blk #1 (tarfile)
Signature · 1 line
2.17.1
Quoted 4 lines · Robert Foley
This is version 1 of the patch series to
add support for 2 aarch64 VMs.
- Ubuntu 18.04 aarch64 VM
- CentOS 8 aarch64 VM
Testing under TCG with:
make vm-build-ubuntu.aarch64 V=1 QEMU=aarch64-softmmu/qemu-system-aarch64
I'm seeing it hang:
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] sed -ie 's/"1"/"0"/g' /etc/apt/apt.conf.d/20auto-upgrades
Warning: Permanently added '[127.0.0.1]:37431' (ECDSA) to the list of known hosts.
bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)
Connection to 127.0.0.1 closed.
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] sync && reboot
Warning: Permanently added '[127.0.0.1]:37431' (ECDSA) to the list of known hosts.
bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)
Connection to 127.0.0.1 closed by remote host.
Connection to 127.0.0.1 closed.
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] exit 0
Warning: Permanently added '[127.0.0.1]:37431' (ECDSA) to the list of known hosts.
bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)
Connection to 127.0.0.1 closed.
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] locale ssh_exchange_identification: Connection closed by remote host
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] sed -ie s/^#\ deb-src/deb-src/g /etc/apt/sources.list ssh_exchange_identification: Connection closed by remote host
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] apt-get update ssh_exchange_identification: Connection closed by remote host
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] apt-get build-dep -y qemu ssh_exchange_identification: Connection closed by remote host
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] apt-get install -y libfdt-dev flex bison ssh_exchange_identification: Connection closed by remote host
DEBUG:root:ssh_cmd: ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=60 -p 37431 -i /home/alex.bennee/lsrc/qemu.git/builds/all/vm-test-xxrw1r36.tmp/id_rsa -o SendEnv=https_proxy -o SendEnv=http_proxy -o SendEnv=ftp_proxy -o SendEnv=no_proxy [email protected] poweroff ssh_exchange_identification: Connection closed by remote host
Signature · 1 line
Alex Bennée