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
diff --git a/bin/virtualization.py b/bin/virtualization.py
index 3032f71..a3794de 100755
--- a/bin/virtualization.py
+++ b/bin/virtualization.py
@@ -564,7 +564,8 @@ class UVTKVMTest(object):
564 self.release = get_codename_to_test()564 self.release = get_codename_to_test()
565 self.arch = check_output(['dpkg', '--print-architecture'],565 self.arch = check_output(['dpkg', '--print-architecture'],
566 universal_newlines=True).strip()566 universal_newlines=True).strip()
567 self.name = tempfile.mktemp()[5:]567 # max len(name) is 8 chars for use with test-snapd-uvtool snap
568 self.name = tempfile.mktemp()[-8:]
568569
569 def run_command(self, cmd):570 def run_command(self, cmd):
570 task = RunCommand(cmd)571 task = RunCommand(cmd)
@@ -584,11 +585,25 @@ class UVTKVMTest(object):
584 logging.debug(' Command returned no output')585 logging.debug(' Command returned no output')
585 return True586 return True
586587
588 def ssh_command(self, private_key_file, cmd):
589 task = RunCommand("uvt-kvm ip {}".format(self.name))
590 if task.returncode != 0:
591 logging.error('Command {} returnd a code of {}'.format(
592 task.cmd, task.returncode))
593 return False
594 vm_ip = task.stdout
595
596 ssh_cmd = ('ssh ubuntu@{} '
597 '-o UserKnownHostsFile=/dev/null '
598 '-o StrictHostKeyChecking=no '
599 '-i {} {}').format(vm_ip, private_key_file, cmd)
600 return self.run_command(ssh_cmd)
601
587 def get_image_or_source(self):602 def get_image_or_source(self):
588 """603 """
589 An image can be specifed in a filesytem path and used directly in604 An image can be specifed in a filesytem path and used directly in
590 uvt-create with the backing-image option or a url can be605 uvt-create with the backing-image option or a url can be
591 specifed and used in uvt-simpletreams to generate an image.606 specifed and used in uvt-simplestreams to generate an image.
592 """607 """
593 url = urlparse(self.image)608 url = urlparse(self.image)
594609
@@ -633,49 +648,54 @@ class UVTKVMTest(object):
633648
634 def start(self):649 def start(self):
635 # Generate ssh key if needed650 # Generate ssh key if needed
636 home_dir = os.environ['HOME']651 with tempfile.TemporaryDirectory(
637 ssh_key_file = "{}/.ssh/id_rsa".format(home_dir)652 dir=os.path.expandvars("$PLAINBOX_SESSION_SHARE")) as tmp_dir:
638653 ssh_private_key_file = "{}/id_rsa".format(tmp_dir)
639 if not os.path.exists(ssh_key_file):654 ssh_public_key_file = "{}/id_rsa.pub".format(tmp_dir)
640 self.run_command("mkdir -p {}/.ssh".format(home_dir))655
656 if not os.path.exists(ssh_private_key_file):
657 cmd = ('ssh-keygen -f {} -t rsa -N \'\''.format(
658 ssh_private_key_file))
659 if not self.run_command(cmd):
660 return False
661
662 # Create vm
663 logging.debug("Creating VM")
664 cmd = ('uvt-kvm create --ssh-public-key-file {} {} arch={}'.format(
665 ssh_public_key_file, self.name, self.arch))
666
667 logging.debug("Checking for local image")
668 try:
669 self.image.find(".img") > 0
670 except AttributeError:
671 logging.debug("No user provided image found.")
672 logging.debug(
673 "I will attempt to sync the image from ubuntu.com")
674 else:
675 cmd = cmd + " --backing-image-file {} ".format(self.image)
641676
642 cmd = ('ssh-keygen -f {} -t rsa -N \'\''.format(ssh_key_file))
643 if not self.run_command(cmd):677 if not self.run_command(cmd):
644 return False678 return False
645679
646 # Create vm680 logging.debug("Wait for VM to complete creation")
647 logging.debug("Creating VM")681 cmd = 'uvt-kvm wait --ssh-private-key-file {} {}'.format(
648 cmd = ('uvt-kvm create {} arch={}'.format(self.name, self.arch))682 ssh_private_key_file, self.name)
649683 if not self.run_command(cmd):
650 logging.debug("Checking for local image")684 return False
651 try:
652 self.image.find(".img") > 0
653 except AttributeError:
654 logging.debug("No user provided image found.")
655 logging.debug("I will attempt to sync the image from ubuntu.com")
656 else:
657 cmd = cmd + " --backing-image-file {} ".format(self.image)
658
659 if not self.run_command(cmd):
660 return False
661
662 logging.debug("Wait for VM to complete creation")
663 if not self.run_command('uvt-kvm wait {}'.format(self.name)):
664 return False
665685
666 logging.debug("List newly created vm")686 logging.debug("List newly created vm")
667 cmd = ("uvt-kvm list")687 cmd = ("uvt-kvm list")
668 if not self.run_command(cmd):688 if not self.run_command(cmd):
669 return False689 return False
670690
671 logging.debug("Verify VM was created with ssh")691 logging.debug("Verify VM was created with ssh")
672 if not self.run_command('uvt-kvm ssh {}'.format(self.name)):692 if not self.ssh_command(ssh_private_key_file, ""):
673 return False693 return False
674694
675 logging.debug("Verify VM was created with ssh and run a command")695 logging.debug("Verify VM was created with ssh and run a command")
676 if not self.run_command('uvt-kvm ssh {} \"lsb_release -a \"'696 cmd = "lsb_release -a"
677 .format(self.name)):697 if not self.ssh_command(ssh_private_key_file, cmd):
678 return False698 return False
679699
680 return True700 return True
681701
diff --git a/units/virtualization/jobs.pxu b/units/virtualization/jobs.pxu
index 2b6fd99..2b903c7 100644
--- a/units/virtualization/jobs.pxu
+++ b/units/virtualization/jobs.pxu
@@ -5,8 +5,10 @@ user: root
5environ: UVT_IMAGE_OR_SOURCE http_proxy https_proxy5environ: UVT_IMAGE_OR_SOURCE http_proxy https_proxy
6estimated_duration: 300.06estimated_duration: 300.0
7requires:7requires:
8 package.name == 'uvtool'8 executable.name == 'uvt-kvm'
9 package.name == 'uvtool-libvirt'9 executable.name == 'uvt-simplestreams-libvirt'
10 executable.name == 'virsh'
11 executable.name == 'ssh-keygen'
10 virtualization.kvm == 'supported'12 virtualization.kvm == 'supported'
11command: virtualization.py --debug uvt13command: virtualization.py --debug uvt
12_description:14_description:

Subscribers

People subscribed via source and target branches