Enable rw snap mount for test debugging

Add support for using unsquashfs to uncompress the microstack snap
followed by 'snap try ./squashfs-root/'. This enables installation
of the snap as an rw mount, and local files can be modified in
./squashfs-root/ and will go live instantly. See 'snap try --help'
for more details.

New tox targets are added for snap-try, snap-try-basic, and
snap-try-cluster.

Change-Id: I54fb8dc864fd4f346f20ae986155ad36bb7c1fac
This commit is contained in:
Corey Bryant 2021-03-12 08:53:23 -05:00
parent 0ac2f83505
commit c853b3e8c8
4 changed files with 72 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import logging
import json
import unittest
import subprocess
import unittest
import yaml
import petname
@ -62,6 +62,15 @@ class TestHost:
def install_snap(self, name, options):
self.check_output(['sudo', 'snap', 'install', name, *options])
def try_snap(self, name):
try:
self.check_output(['unsquashfs', name])
except subprocess.CalledProcessError:
logger.warning("Re-using existing squashfs-root directory with "
"'snap try squashfs-root'")
self.check_output(['sudo', 'snap', 'try', 'squashfs-root',
'--devmode'])
def remove_snap(self, name, options):
self.check_output(['sudo', 'snap', 'remove', name, *options])
@ -69,13 +78,16 @@ class TestHost:
self.check_output(['sudo', 'snap', 'connect',
f'{snap_name}:{plug_name}'])
def install_microstack(self, *, channel='edge', path=None):
def install_microstack(self, *, channel='edge', path=None, snap_try=False):
"""Install MicroStack at this host and connect relevant plugs.
"""
if path is not None:
self.install_snap(path, ['--devmode'])
if path and snap_try:
self.try_snap(path)
else:
self.install_snap('microstack', [f'--{channel}', '--devmode'])
if path is not None:
self.install_snap(path, ['--devmode'])
else:
self.install_snap('microstack', [f'--{channel}', '--devmode'])
# TODO: add microstack-support once it is merged into snapd.
plugs = [

View File

@ -14,6 +14,7 @@ Web IDE.
"""
import argparse
import os
import sys
import unittest
@ -24,6 +25,7 @@ from tests.framework import Framework # noqa E402
class TestBasics(Framework):
snap_try = False
def test_basics(self):
"""Basic test
@ -32,7 +34,8 @@ class TestBasics(Framework):
open the Horizon GUI.
"""
self._localhost.install_microstack(path='microstack_ussuri_amd64.snap')
self._localhost.install_microstack(path='microstack_ussuri_amd64.snap',
snap_try=self.snap_try)
self._localhost.init_microstack([
'--auto',
'--control',
@ -100,6 +103,14 @@ class TestBasics(Framework):
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--snap-try", help="Install snap as rw mount from "
"squashfs-root directory", action='store_true')
parser.add_argument('unittest_args', nargs='*')
args = parser.parse_args()
TestBasics.snap_try = args.snap_try
sys.argv[1:] = args.unittest_args
# Run our tests, ignoring deprecation warnings and warnings about
# unclosed sockets. (TODO: setup a selenium server so that we can
# move from PhantomJS, which is deprecated, to to Selenium headless.)

View File

@ -10,6 +10,7 @@ vms.
"""
import argparse
import json
import os
import sys
@ -32,11 +33,13 @@ logger.addHandler(stream)
class TestCluster(Framework):
snap_try = False
def test_cluster(self):
openstack_cmd = '/snap/bin/microstack.openstack'
control_host = self._localhost
control_host.install_microstack(path='microstack_ussuri_amd64.snap')
control_host.install_microstack(path='microstack_ussuri_amd64.snap',
snap_try=self.snap_try)
# Get an IP address on the lxdbr0 bridge and use it for the
# control IP so that the tunnel ports of the compute node target the
@ -74,7 +77,13 @@ class TestCluster(Framework):
wait_addr()
compute_host.install_microstack(path='microstack_ussuri_amd64.snap')
if self.snap_try:
# Note(coreycb): Work-around for https://pad.lv/1908424
compute_host.check_call([
'sudo', 'apt', 'install', '--yes', '--allow-downgrades',
'snapd=2.44.3+20.04'])
compute_host.install_microstack(path='microstack_ussuri_amd64.snap',
snap_try=self.snap_try)
# TODO add the following to args for init
compute_host.check_call([
@ -143,4 +152,12 @@ class TestCluster(Framework):
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--snap-try", help="Install snap as rw mount from "
"squashfs-root directory", action='store_true')
parser.add_argument('unittest_args', nargs='*')
args = parser.parse_args()
TestCluster.snap_try = args.snap_try
sys.argv[1:] = args.unittest_args
unittest.main(warnings='ignore')

24
tox.ini
View File

@ -30,6 +30,30 @@ commands =
bash -c "unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ; {toxinidir}/tests/test_basic.py"
bash -c "unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ; {toxinidir}/tests/test_cluster.py"
[testenv:snap-try]
# Testing environment for local debugging. Mounts rw snap from squashfs-root dir.
commands =
{toxinidir}/tools/lxd_build.sh
flake8 {toxinidir}/tests/
# Specify tests in sequence, as they can't run in parallel if not
# using multipass.
bash -c "unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ; {toxinidir}/tests/test_basic.py --snap-try"
bash -c "unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ; {toxinidir}/tests/test_cluster.py --snap-try"
[testenv:snap-try-basic]
# Testing environment for local debugging. Mounts rw snap from squashfs-root dir.
commands =
{toxinidir}/tools/lxd_build.sh
flake8 {toxinidir}/tests/
bash -c "unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ; {toxinidir}/tests/test_basic.py --snap-try"
[testenv:snap-try-cluster]
# Testing environment for local debugging. Mounts rw snap from squashfs-root dir.
commands =
{toxinidir}/tools/lxd_build.sh
flake8 {toxinidir}/tests/
bash -c "unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ; {toxinidir}/tests/test_cluster.py --snap-try"
[testenv:multipass]
# Default testing environment for a human operated machine. Builds the
# snap in a multipass instance, then runs tests in a separate multipass