Skip to content

Commit

Permalink
tests/vm: Added gen_cloud_init_iso() to basevm.py
Browse files Browse the repository at this point in the history
This method was located in both centos and ubuntu.i386.

Signed-off-by: Robert Foley <robert.foley@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Peter Puhov <peter.puhov@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200219163537.22098-6-robert.foley@linaro.org>
Message-Id: <20200303150622.20133-6-alex.bennee@linaro.org>
  • Loading branch information
Robert Foley authored and stsquad committed Mar 4, 2020
1 parent fbb3aa2 commit b081986
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 68 deletions.
40 changes: 40 additions & 0 deletions tests/vm/basevm.py
Expand Up @@ -345,6 +345,46 @@ def graceful_shutdown(self):
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():
Expand Down
33 changes: 1 addition & 32 deletions tests/vm/centos
Expand Up @@ -31,45 +31,14 @@ 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"
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"])
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")
Expand Down
37 changes: 1 addition & 36 deletions tests/vm/ubuntu.i386
Expand Up @@ -29,49 +29,14 @@ 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",
sha256sum="28969840626d1ea80bb249c08eef1a4533e8904aa51a327b40f37ac4b4ff04ef")
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")
Expand Down

0 comments on commit b081986

Please sign in to comment.