Merge ~jocave/plainbox-provider-checkbox:uvtkvm-test-on-ubuntucore into plainbox-provider-checkbox:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 21d7884f1ab252bfbef7fb08da7d104ce0fcb550
Merged at revision: 163ded339ecc4ec35b8e33316abb9bdf483cc9cd
Proposed branch: ~jocave/plainbox-provider-checkbox:uvtkvm-test-on-ubuntucore
Merge into: plainbox-provider-checkbox:master
Diff against target: 149 lines (+62/-40)
2 files modified
bin/virtualization.py (+58/-38)
units/virtualization/jobs.pxu (+4/-2)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Michael Reed Approve
Jeff Lane  Approve
Review via email: mp+403636@code.launchpad.net

Description of the change

Modifications to the virtualization/kvm_check_vm test that support use of the test-snapd-uvtool snap in the store hence allowing the test to run on Ubuntu Core.

Test steps required to run on Ubuntu Core:

 * sudo snap install test-snapd-uvtool --devmode (--edge currently)
 * sudo snap alias test-snapd-uvtool.uvt-kvm uvt-kvm
 * sudo snap alias test-snapd-uvtool.uvt-simplestreams-libvirt uvt-simplestreams-libvirt
 * sudo snap alias test-snapd-uvtool.virsh virsh

 .. install checkbox-snappy, run test

Tested on a R340.

To post a comment you must log in.
Revision history for this message
Jeff Lane  (bladernr) wrote :

Hey,

While youre at it, could you add a packaging.pxu file to explicitly install uvtool and uvtool-libvirt?

There is no packaging metadata that i can find, and turns out that on focal, installing uvtool also installs uvtool-libvirt, but on bionic, you have to explicitly install both. So a quick fix would be to just add a packaging metadata definition to explicitly install both regardless of release.

That's just a side request that could be done here... otherwise, everything below makes sense to me.

review: Needs Information
Revision history for this message
Jonathan Cave (jocave) wrote :

Sylvain pointed out that packages are included as dependencies for plainbox-provider-certification-server: https://git.launchpad.net/plainbox-provider-certification-server/tree/units/packaging.pxu

So I don't think we can our would want to have packaging units in this provider.

Revision history for this message
Jeff Lane  (bladernr) wrote :

Gah... disregard, then. I didn't see them in PPC and didn't remember them at all being in PPCS. Thanks for pointing it out.

review: Approve
Revision history for this message
Michael Reed (mreed8855) wrote :

The code looks good to me and I ran the test and it passed. +1

review: Approve
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Thanks for the tempdir fixes, LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/virtualization.py b/bin/virtualization.py
2index 3032f71..a3794de 100755
3--- a/bin/virtualization.py
4+++ b/bin/virtualization.py
5@@ -564,7 +564,8 @@ class UVTKVMTest(object):
6 self.release = get_codename_to_test()
7 self.arch = check_output(['dpkg', '--print-architecture'],
8 universal_newlines=True).strip()
9- self.name = tempfile.mktemp()[5:]
10+ # max len(name) is 8 chars for use with test-snapd-uvtool snap
11+ self.name = tempfile.mktemp()[-8:]
12
13 def run_command(self, cmd):
14 task = RunCommand(cmd)
15@@ -584,11 +585,25 @@ class UVTKVMTest(object):
16 logging.debug(' Command returned no output')
17 return True
18
19+ def ssh_command(self, private_key_file, cmd):
20+ task = RunCommand("uvt-kvm ip {}".format(self.name))
21+ if task.returncode != 0:
22+ logging.error('Command {} returnd a code of {}'.format(
23+ task.cmd, task.returncode))
24+ return False
25+ vm_ip = task.stdout
26+
27+ ssh_cmd = ('ssh ubuntu@{} '
28+ '-o UserKnownHostsFile=/dev/null '
29+ '-o StrictHostKeyChecking=no '
30+ '-i {} {}').format(vm_ip, private_key_file, cmd)
31+ return self.run_command(ssh_cmd)
32+
33 def get_image_or_source(self):
34 """
35 An image can be specifed in a filesytem path and used directly in
36 uvt-create with the backing-image option or a url can be
37- specifed and used in uvt-simpletreams to generate an image.
38+ specifed and used in uvt-simplestreams to generate an image.
39 """
40 url = urlparse(self.image)
41
42@@ -633,49 +648,54 @@ class UVTKVMTest(object):
43
44 def start(self):
45 # Generate ssh key if needed
46- home_dir = os.environ['HOME']
47- ssh_key_file = "{}/.ssh/id_rsa".format(home_dir)
48-
49- if not os.path.exists(ssh_key_file):
50- self.run_command("mkdir -p {}/.ssh".format(home_dir))
51+ with tempfile.TemporaryDirectory(
52+ dir=os.path.expandvars("$PLAINBOX_SESSION_SHARE")) as tmp_dir:
53+ ssh_private_key_file = "{}/id_rsa".format(tmp_dir)
54+ ssh_public_key_file = "{}/id_rsa.pub".format(tmp_dir)
55+
56+ if not os.path.exists(ssh_private_key_file):
57+ cmd = ('ssh-keygen -f {} -t rsa -N \'\''.format(
58+ ssh_private_key_file))
59+ if not self.run_command(cmd):
60+ return False
61+
62+ # Create vm
63+ logging.debug("Creating VM")
64+ cmd = ('uvt-kvm create --ssh-public-key-file {} {} arch={}'.format(
65+ ssh_public_key_file, self.name, self.arch))
66+
67+ logging.debug("Checking for local image")
68+ try:
69+ self.image.find(".img") > 0
70+ except AttributeError:
71+ logging.debug("No user provided image found.")
72+ logging.debug(
73+ "I will attempt to sync the image from ubuntu.com")
74+ else:
75+ cmd = cmd + " --backing-image-file {} ".format(self.image)
76
77- cmd = ('ssh-keygen -f {} -t rsa -N \'\''.format(ssh_key_file))
78 if not self.run_command(cmd):
79 return False
80
81- # Create vm
82- logging.debug("Creating VM")
83- cmd = ('uvt-kvm create {} arch={}'.format(self.name, self.arch))
84-
85- logging.debug("Checking for local image")
86- try:
87- self.image.find(".img") > 0
88- except AttributeError:
89- logging.debug("No user provided image found.")
90- logging.debug("I will attempt to sync the image from ubuntu.com")
91- else:
92- cmd = cmd + " --backing-image-file {} ".format(self.image)
93-
94- if not self.run_command(cmd):
95- return False
96-
97- logging.debug("Wait for VM to complete creation")
98- if not self.run_command('uvt-kvm wait {}'.format(self.name)):
99- return False
100+ logging.debug("Wait for VM to complete creation")
101+ cmd = 'uvt-kvm wait --ssh-private-key-file {} {}'.format(
102+ ssh_private_key_file, self.name)
103+ if not self.run_command(cmd):
104+ return False
105
106- logging.debug("List newly created vm")
107- cmd = ("uvt-kvm list")
108- if not self.run_command(cmd):
109- return False
110+ logging.debug("List newly created vm")
111+ cmd = ("uvt-kvm list")
112+ if not self.run_command(cmd):
113+ return False
114
115- logging.debug("Verify VM was created with ssh")
116- if not self.run_command('uvt-kvm ssh {}'.format(self.name)):
117- return False
118+ logging.debug("Verify VM was created with ssh")
119+ if not self.ssh_command(ssh_private_key_file, ""):
120+ return False
121
122- logging.debug("Verify VM was created with ssh and run a command")
123- if not self.run_command('uvt-kvm ssh {} \"lsb_release -a \"'
124- .format(self.name)):
125- return False
126+ logging.debug("Verify VM was created with ssh and run a command")
127+ cmd = "lsb_release -a"
128+ if not self.ssh_command(ssh_private_key_file, cmd):
129+ return False
130
131 return True
132
133diff --git a/units/virtualization/jobs.pxu b/units/virtualization/jobs.pxu
134index 2b6fd99..2b903c7 100644
135--- a/units/virtualization/jobs.pxu
136+++ b/units/virtualization/jobs.pxu
137@@ -5,8 +5,10 @@ user: root
138 environ: UVT_IMAGE_OR_SOURCE http_proxy https_proxy
139 estimated_duration: 300.0
140 requires:
141- package.name == 'uvtool'
142- package.name == 'uvtool-libvirt'
143+ executable.name == 'uvt-kvm'
144+ executable.name == 'uvt-simplestreams-libvirt'
145+ executable.name == 'virsh'
146+ executable.name == 'ssh-keygen'
147 virtualization.kvm == 'supported'
148 command: virtualization.py --debug uvt
149 _description:

Subscribers

People subscribed via source and target branches