summaryrefslogtreecommitdiff
path: root/bin
diff options
authorJonathan Cave <jonathan.cave@canonical.com>2021-05-11 18:43:26 +0100
committerJonathan Cave <jonathan.cave@canonical.com>2021-05-11 18:43:26 +0100
commit1ab21b2b090a351daa1fde330b5b4ccb730e61fb (patch)
tree691e555692dbddf70fed3a87760ef9808fe53b06 /bin
parent1bfa4912d9529d113773ab09d8b54a440f57ea13 (diff)
Change: make verify_lxd usable on Ubuntu Core
The lsb_release python module is not suitable for use on Ubuntu Core as it attempts to call apt-cache. The distro module is now preferred. Use the output to perform a suitable mapping to a codename to use. Fallback to lsb_release if distro not available.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/virtualization.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/bin/virtualization.py b/bin/virtualization.py
index 2f17d32..237f61d 100755
--- a/bin/virtualization.py
+++ b/bin/virtualization.py
@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
from argparse import ArgumentParser
import os
import logging
-import lsb_release
import requests
import shlex
from subprocess import (
@@ -125,6 +124,33 @@ QEMU_ARCH_CONFIG = {
}
+def get_release_to_test():
+ try:
+ import distro
+ if distro.id() == 'ubuntu-core':
+ return '{}.04'.format(distro.version())
+ return distro.version()
+ except (ImportError, CalledProcessError):
+ import lsb_release
+ return lsb_release.get_distro_information()["RELEASE"]
+
+
+def get_codename_to_test():
+ try:
+ import distro
+ if distro.id() == 'ubuntu-core':
+ codename = 'focal'
+ if distro.version() == '18':
+ codename = 'bionic'
+ elif distro.version() == '16':
+ codename = 'xenial'
+ return codename
+ return distro.codename()
+ except (ImportError, CalledProcessError):
+ import lsb_release
+ lsb_release.get_distro_information()["CODENAME"]
+
+
class QemuRunner(object):
def __init__(self, arch):
self.arch = arch
@@ -197,7 +223,7 @@ class KVMTest(object):
self.arch = check_output(['dpkg', '--print-architecture'],
universal_newlines=True).strip()
self.qemu_config = QEMU_ARCH_CONFIG[self.arch]
- self.release = lsb_release.get_distro_information()["CODENAME"]
+ self.release = get_codename_to_test()
def url_to_path(self, image_path):
"""
@@ -287,7 +313,7 @@ class KVMTest(object):
url.path == '' or
not (url.path.endswith(".img") or
url.path.endswith(".tar.gz"))
- ):
+ ):
# If we have a relative URL (local copies of official images)
# http://192.168.0.1/ or http://192.168.0.1/images/
cloud_iso = _construct_filename()
@@ -535,7 +561,7 @@ class UVTKVMTest(object):
def __init__(self, image=None):
self.image = image
- self.release = lsb_release.get_distro_information()["CODENAME"]
+ self.release = get_codename_to_test()
self.arch = check_output(['dpkg', '--print-architecture'],
universal_newlines=True).strip()
self.name = tempfile.mktemp()[5:]
@@ -664,7 +690,7 @@ class LXDTest(object):
self.name = 'testbed'
self.image_alias = uuid4().hex
self.default_remote = "ubuntu:"
- self.os_version = lsb_release.get_distro_information()["RELEASE"]
+ self.os_version = get_release_to_test()
def run_command(self, cmd):
task = RunCommand(cmd)