mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
create_storage_netfs started the pool without a build, so a netfs pool
whose target directory was missing failed to mount ("mount point ... does
not exist"): the page showed the error and the pool stayed defined and
inactive. It now starts with VIR_STORAGE_POOL_CREATE_WITH_BUILD, as the
dir and logical pools do, which makes the mount point.
The Vagrant computes export /srv/wvcnfs to 127.0.0.1, and the live pool
test creates an NFS pool on it at a missing mount point when
TEST_LIBVIRT_NFS_EXPORT is set.
66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
"""Live check that a directory or NFS pool created on the storages page
|
|
starts when its directory does not exist yet: libvirt builds it. Runs only
|
|
with TEST_LIBVIRT_HOST set; the NFS case needs TEST_LIBVIRT_NFS_EXPORT, a
|
|
directory the host exports to its 127.0.0.1 (the Vagrant computes do)."""
|
|
|
|
import os
|
|
import unittest
|
|
|
|
import libvirt
|
|
from computes.models import Compute
|
|
from django.contrib.auth import get_user_model
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
from instances.tests import livetest
|
|
from vrtManager.connection import connection_manager
|
|
|
|
P = livetest.PREFIX
|
|
|
|
|
|
@unittest.skipUnless(livetest.enabled(), "Set TEST_LIBVIRT_HOST to run the live libvirt tests")
|
|
class LivePoolsTestCase(TestCase):
|
|
def setUp(self):
|
|
args = dict(
|
|
hostname=os.environ["TEST_LIBVIRT_HOST"],
|
|
login=os.environ.get("TEST_LIBVIRT_LOGIN", ""),
|
|
password=os.environ.get("TEST_LIBVIRT_PASSWORD", ""),
|
|
type=int(os.environ.get("TEST_LIBVIRT_TYPE", 1)),
|
|
)
|
|
self.conn = connection_manager.get_connection(*args.values())
|
|
self.compute = Compute.objects.create(name="live-pools", **args)
|
|
self.client.force_login(get_user_model().objects.create_superuser("live-pools", "lp@example.com", "x"))
|
|
|
|
def remove_pool(self, name):
|
|
try:
|
|
pool = self.conn.storagePoolLookupByName(name)
|
|
except libvirt.libvirtError:
|
|
return
|
|
if pool.isActive():
|
|
pool.destroy() # unmounts an NFS pool
|
|
pool.delete(0) # removes the directory
|
|
pool.undefine()
|
|
|
|
def assert_created(self, data):
|
|
self.remove_pool(data["name"])
|
|
self.addCleanup(self.remove_pool, data["name"])
|
|
response = self.client.post(reverse("storages", args=[self.compute.id]), {"create": "", **data})
|
|
self.assertRedirects(
|
|
response, reverse("storage", args=[self.compute.id, data["name"]]), fetch_redirect_response=False
|
|
)
|
|
pool = self.conn.storagePoolLookupByName(data["name"])
|
|
self.assertTrue(pool.isActive())
|
|
self.assertTrue(pool.autostart())
|
|
|
|
def test_a_missing_directory_is_built(self):
|
|
self.assert_created({"name": P + "dir", "stg_type": "dir", "target": f"/var/lib/libvirt/{P}dir"})
|
|
|
|
@unittest.skipUnless(os.environ.get("TEST_LIBVIRT_NFS_EXPORT"), "Set TEST_LIBVIRT_NFS_EXPORT to run the NFS pool test")
|
|
def test_a_missing_mount_point_is_built(self):
|
|
self.assert_created({
|
|
"name": P + "nfs",
|
|
"stg_type": "netfs",
|
|
"netfs_host": "127.0.0.1",
|
|
"source": os.environ["TEST_LIBVIRT_NFS_EXPORT"],
|
|
"source_format": "nfs",
|
|
"target": f"/var/lib/libvirt/{P}nfs",
|
|
})
|