microstack/tests/test_basic.py
Dmitrii Shcherbakov 35ad8fbef0 Use microstack-support interface, drop devmode
With https://github.com/snapcore/snapd/pull/8926 merged and snapd 2.53.2
released we can now test changes without devmode.

Change-Id: I9980b171e537530d67f0a7eed332147f06fe7c3c
2021-11-26 18:23:03 +03:00

126 lines
4.1 KiB
Python
Executable File

#!/usr/bin/env python
"""
basic_test.py
This is a basic test of microstack functionality. We verify that:
1) We can install the snap.
2) We can launch a cirros image.
3) Horizon is running, and we can hit the landing page.
4) We can login to Horizon successfully.
The Horizon testing bits were are based on code generated by the Selinum
Web IDE.
"""
import argparse
import os
import sys
import unittest
sys.path.append(os.getcwd())
from tests.framework import Framework # noqa E402
class TestBasics(Framework):
snap_try = False
use_lvm = False
def test_basics(self):
"""Basic test
Install microstack, and verify that we can launch a machine and
open the Horizon GUI.
"""
self._localhost.install_snapd(channel='stable')
self._localhost.install_microstack(path='microstack_ussuri_amd64.snap',
snap_try=self.snap_try)
init_args = ['--auto', '--control']
if self.use_lvm:
init_args.extend([
'--setup-loop-based-cinder-lvm-backend',
'--loop-device-file-size=24',
])
self._localhost.init_microstack(init_args)
endpoints = self._localhost.check_output(
['/snap/bin/microstack.openstack', 'endpoint', 'list']
).decode('utf-8')
control_ip = self._localhost.check_output(
['sudo', 'snap', 'get', 'microstack', 'config.network.control-ip'],
).decode('utf-8')
# Endpoints should contain the control IP.
self.assertTrue(control_ip in endpoints)
# Endpoints should not contain localhost
self.assertFalse("localhost" in endpoints)
# We should be able to launch an instance
instance_name = 'test-instance'
print("Testing microstack.launch ...")
self._localhost.check_output(
['/snap/bin/microstack.launch', 'cirros',
'--name', instance_name, '--retry']
)
self.verify_instance_networking(self._localhost, instance_name)
# The Horizon Dashboard should function
self.verify_gui(self._localhost)
# Verify that we can uninstall the snap cleanly, and that the
# ovs bridge goes away.
# Check to verify that our bridge is there.
self.assertTrue(
'br-ex' in self._localhost.check_output(
['ip', 'a']).decode('utf-8'))
self._localhost.setup_tempest_verifier()
# Make sure there are no verification failures in the report.
failures = self._localhost.run_verifications(self.use_lvm)
self.assertEqual(failures, 0, 'Verification tests had failure.')
# Try to remove the snap without sudo.
self.assertEqual(self._localhost.call([
'snap', 'remove', '--purge', 'microstack']), 1)
# Retry with sudo (should succeed).
self._localhost.check_call(
['sudo', 'snap', 'remove', '--purge', 'microstack'])
# Verify that MicroStack is gone.
self.assertEqual(self._localhost.call(
['snap', 'list', 'microstack']), 1)
# Verify that bridge is gone.
self.assertFalse(
'br-ex' in self._localhost.check_output(
['ip', 'a']).decode('utf-8'))
# We made it to the end. Set passed to True!
self.passed = True
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("--use-lvm", help="Init snap with experimental lvm "
"support", action='store_true')
parser.add_argument('unittest_args', nargs='*')
args = parser.parse_args()
TestBasics.snap_try = args.snap_try
TestBasics.use_lvm = args.use_lvm
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.)
unittest.main(warnings='ignore')