1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-26 08:05:22 +00:00
webvirtcloud/instances/tests.py

1095 lines
36 KiB
Python
Raw Normal View History

2020-10-15 05:58:42 +00:00
import re
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
from accounts.models import UserAttributes, UserInstance, UserSSHKey
from appsettings.models import AppSettings
from computes.models import Compute
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.http.response import Http404
2020-07-13 09:33:09 +00:00
from django.shortcuts import reverse
2015-02-27 08:53:51 +00:00
from django.test import TestCase
from instances.views import instance
2020-10-15 05:58:42 +00:00
from libvirt import VIR_DOMAIN_UNDEFINE_NVRAM
from vrtManager.create import wvmCreate
from vrtManager.util import randomUUID
2015-02-27 08:53:51 +00:00
2020-10-15 05:58:42 +00:00
from .models import Flavor, Instance
from .utils import refr
2020-07-13 09:33:09 +00:00
class InstancesTestCase(TestCase):
2020-10-15 05:58:42 +00:00
@classmethod
def setUpClass(cls):
super().setUpClass()
# Add users for testing purposes
User = get_user_model()
cls.admin_user = User.objects.get(pk=1)
2022-11-02 05:54:35 +00:00
cls.test_user = User.objects.create(username="test-user")
2020-10-15 05:58:42 +00:00
UserAttributes.objects.create(
user=cls.test_user,
max_instances=1,
max_cpus=1,
max_memory=128,
max_disk_size=1,
)
2022-11-02 05:54:35 +00:00
permission = Permission.objects.get(codename="clone_instances")
2020-10-15 05:58:42 +00:00
cls.test_user.user_permissions.add(permission)
# Add localhost compute
cls.compute = Compute(
2022-11-02 05:54:35 +00:00
name="test-compute",
hostname="localhost",
login="",
password="",
details="local",
2020-07-13 09:33:09 +00:00
type=4,
2020-10-15 05:58:42 +00:00
)
cls.compute.save()
cls.connection = wvmCreate(
cls.compute.hostname,
cls.compute.login,
cls.compute.password,
cls.compute.type,
)
# Add disks for testing
cls.connection.create_volume(
2022-11-02 05:54:35 +00:00
"default",
"test-volume",
2020-10-15 05:58:42 +00:00
1,
2022-11-02 05:54:35 +00:00
"qcow2",
2020-10-15 05:58:42 +00:00
False,
0,
0,
)
# XML for testing vm
2022-11-02 05:54:35 +00:00
with open("conf/test-vm.xml", "r") as f:
2020-10-15 05:58:42 +00:00
cls.xml = f.read()
# Create testing vm from XML
cls.connection._defineXML(cls.xml)
refr(cls.compute)
cls.instance: Instance = Instance.objects.get(pk=1)
@classmethod
def tearDownClass(cls):
# Destroy testing vm
cls.instance.proxy.delete_all_disks()
cls.instance.proxy.delete(VIR_DOMAIN_UNDEFINE_NVRAM)
super().tearDownClass()
def setUp(self):
2022-11-02 05:54:35 +00:00
self.client.login(username="admin", password="admin")
self.rsa_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC6OOdbfv27QVnSC6sKxGaHb6YFc+3gxCkyVR3cTSXE/n5BEGf8aOgBpepULWa1RZfxYHY14PlKULDygdXSdrrR2kNSwoKz/Oo4d+3EE92L7ocl1+djZbptzgWgtw1OseLwbFik+iKlIdqPsH+IUQvX7yV545ZQtAP8Qj1R+uCqkw== test@test"
2020-07-13 09:33:09 +00:00
def test_index(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:index"))
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 200)
self.client.force_login(self.test_user)
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:index"))
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
def test_create_select_type(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:create_instance_select_type", args=[1])
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
def test_instance_page(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:instance", args=[self.instance.id])
)
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 200)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
self.client.force_login(self.test_user)
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:instance", args=[self.instance.id])
)
2020-10-15 05:58:42 +00:00
self.assertRaises(Http404)
# def test_create_volume(self):
# response = self.client.post(
# reverse('create_volume', args=[self.compute.id, 'default']),
# {
# 'name': 'test',
# 'format': 'qcow2',
# 'size': '1',
# 'meta_prealloc': False,
# },
# )
# self.assertRedirects(response, reverse('storage', args=[self.compute.id, 'default']))
def test_create_destroy_instance(self):
# Create
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse(
"instances:create_instance", args=[self.compute.id, "x86_64", "q35"]
)
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse(
"instances:create_instance", args=[self.compute.id, "x86_64", "q35"]
),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test",
"firmware": "BIOS",
"vcpu": 1,
"vcpu_mode": "host-model",
"memory": 128,
"device0": "disk",
"bus0": "virtio",
"images": "test-volume.qcow2",
"storage-control": "default",
"image-control": "test.qcow2",
"networks": "default",
"network-control": "default",
"cache_mode": "directsync",
"nwfilter": "",
"graphics": "spice",
"video": "vga",
"listener_addr": "0.0.0.0",
"console_pass": "",
"qemu_ga": False,
"virtio": True,
"create": True,
2020-07-13 09:33:09 +00:00
},
)
self.assertEqual(response.status_code, 302)
2022-11-02 05:54:35 +00:00
instance_qs: Instance = Instance.objects.filter(name="test")
2020-10-15 05:58:42 +00:00
self.assertEqual(len(instance_qs), 1)
instance = instance_qs[0]
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
# Destroy
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:destroy", args=[instance.id]))
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:destroy", args=[instance.id]),
2020-10-15 05:58:42 +00:00
{}, # do not destroy disk image
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
2022-11-02 05:54:35 +00:00
self.assertRedirects(response, reverse("instances:index"))
2020-10-15 05:58:42 +00:00
def test_create_from_xml(self):
uuid = randomUUID()
2022-11-02 05:54:35 +00:00
xml = self.xml.replace("test-vm", "test-vm-xml")
xml = re.sub("\s?<uuid>.*?</uuid>", f"<uuid>{uuid}</uuid>", xml)
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:create_instance_select_type", args=[self.compute.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"create_xml": True,
"dom_xml": xml,
2020-10-15 05:58:42 +00:00
},
)
self.assertEqual(response.status_code, 302)
2022-11-02 05:54:35 +00:00
xml_instance_qs: Instance = Instance.objects.filter(name="test-vm-xml")
2020-10-15 05:58:42 +00:00
self.assertEqual(len(xml_instance_qs), 1)
xml_instance = xml_instance_qs[0]
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
# destroy started instance to maximize coverage
xml_instance.proxy.start()
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:destroy", args=[xml_instance.id]),
2020-10-15 05:58:42 +00:00
{}, # do not delete disk image
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
2022-11-02 05:54:35 +00:00
self.assertRedirects(response, reverse("instances:index"))
2020-10-15 05:58:42 +00:00
def test_resize_cpu(self):
self.assertEqual(self.instance.vcpu, 1)
self.assertEqual(self.instance.cur_vcpu, 1)
2022-11-02 05:54:35 +00:00
response = self.client.post(
reverse("instances:resizevm_cpu", args=[self.instance.id]),
{
"vcpu": 4,
"cur_vcpu": 2,
},
)
self.assertRedirects(
response, reverse("instances:instance", args=[self.instance.id]) + "#resize"
)
2020-07-13 09:33:09 +00:00
# reset cached properties
2020-10-15 05:58:42 +00:00
del self.instance.vcpu
del self.instance.cur_vcpu
self.assertEqual(self.instance.vcpu, 4)
self.assertEqual(self.instance.cur_vcpu, 2)
def test_resize_cpu_with_quota(self):
# test for non admin user with quotas
vcpu = self.instance.vcpu
cur_vcpu = self.instance.cur_vcpu
2022-11-02 05:54:35 +00:00
UserInstance.objects.create(
user=self.test_user, instance=self.instance, is_change=True
)
2020-10-15 05:58:42 +00:00
self.client.force_login(self.test_user)
2022-11-02 05:54:35 +00:00
response = self.client.post(
reverse("instances:resizevm_cpu", args=[self.instance.id]),
{
"vcpu": 4,
"cur_vcpu": 2,
},
)
self.assertRedirects(
response, reverse("instances:instance", args=[self.instance.id]) + "#resize"
)
2020-10-15 05:58:42 +00:00
del self.instance.vcpu
del self.instance.cur_vcpu
# no changes as user reached quota
self.assertEqual(self.instance.vcpu, vcpu)
self.assertEqual(self.instance.cur_vcpu, cur_vcpu)
def test_resize_memory(self):
self.assertEqual(self.instance.memory, 128)
self.assertEqual(self.instance.cur_memory, 128)
2022-11-02 05:54:35 +00:00
response = self.client.post(
reverse("instances:resize_memory", args=[self.instance.id]),
{"memory": 512, "cur_memory": 256},
)
self.assertRedirects(
response, reverse("instances:instance", args=[self.instance.id]) + "#resize"
)
2020-10-15 05:58:42 +00:00
del self.instance.memory
del self.instance.cur_memory
self.assertEqual(self.instance.memory, 512)
self.assertEqual(self.instance.cur_memory, 256)
2022-11-02 05:54:35 +00:00
response = self.client.post(
reverse("instances:resize_memory", args=[self.instance.id]),
{"memory_custom": 500, "cur_memory_custom": 200},
)
self.assertRedirects(
response, reverse("instances:instance", args=[self.instance.id]) + "#resize"
)
2020-10-15 05:58:42 +00:00
del self.instance.memory
del self.instance.cur_memory
self.assertEqual(self.instance.memory, 500)
self.assertEqual(self.instance.cur_memory, 200)
def test_resize_memory_with_quota(self):
# test for non admin user with quotas
memory = self.instance.memory
cur_memory = self.instance.cur_memory
2022-11-02 05:54:35 +00:00
UserInstance.objects.create(
user=self.test_user, instance=self.instance, is_change=True
)
2020-10-15 05:58:42 +00:00
self.client.force_login(self.test_user)
2022-11-02 05:54:35 +00:00
response = self.client.post(
reverse("instances:resize_memory", args=[self.instance.id]),
{"memory": 512, "cur_memory": 256},
)
self.assertRedirects(
response, reverse("instances:instance", args=[self.instance.id]) + "#resize"
)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
del self.instance.memory
del self.instance.cur_memory
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
# no changes as user reached quota
self.assertEqual(self.instance.memory, memory)
self.assertEqual(self.instance.cur_memory, cur_memory)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_resize_disk(self):
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.disks[0]["size"], 1024**3)
2020-10-15 05:58:42 +00:00
2022-11-02 05:54:35 +00:00
response = self.client.post(
reverse("instances:resize_disk", args=[self.instance.id]),
{
"disk_size_vda": 2,
},
)
self.assertRedirects(
response, reverse("instances:instance", args=[self.instance.id]) + "#resize"
)
2020-10-15 05:58:42 +00:00
del self.instance.disks
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.disks[0]["size"], 2 * 1024**3)
2020-10-15 05:58:42 +00:00
def test_resize_disk_with_quota(self):
# test for non admin user with quotas
2022-11-02 05:54:35 +00:00
disk_size = self.instance.disks[0]["size"]
UserInstance.objects.create(
user=self.test_user, instance=self.instance, is_change=True
)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
self.client.force_login(self.test_user)
2022-11-02 05:54:35 +00:00
response = self.client.post(
reverse("instances:resize_disk", args=[self.instance.id]),
{
"disk_size_vda": 3,
},
)
self.assertRedirects(
response, reverse("instances:instance", args=[self.instance.id]) + "#resize"
)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
# no changes as user reached quota
del self.instance.disks
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.disks[0]["size"], disk_size)
2020-10-15 05:58:42 +00:00
def test_add_delete_new_volume(self):
self.assertEqual(len(self.instance.disks), 1)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:add_new_vol", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"storage": "default",
"name": "test-volume-2",
"size": 1,
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.disks
self.assertEqual(len(self.instance.disks), 2)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:delete_vol", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"storage": "default",
"dev": "vdb",
"name": "test-volume-2.qcow2",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.disks
self.assertEqual(len(self.instance.disks), 1)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_detach_attach_volume(self):
2020-07-13 09:33:09 +00:00
# detach volume
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:detach_vol", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"dev": "vda",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.disks
self.assertEqual(len(self.instance.disks), 0)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
# reattach volume
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:add_existing_vol", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"selected_storage": "default",
"vols": "test-volume.qcow2",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.disks
self.assertEqual(len(self.instance.disks), 1)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_edit_volume(self):
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:edit_volume", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"vol_path": "/var/lib/libvirt/images/test-volume.qcow2",
2020-07-13 09:33:09 +00:00
# 'vol_shareable': False,
# 'vol_readonly': False,
2022-11-02 05:54:35 +00:00
"vol_bus": "virtio",
"vol_bus_old": "virtio",
"vol_format": "qcow2",
"dev": "vda",
"edit_volume": True,
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
def test_attach_detach_cdrom(self):
self.assertEqual(len(self.instance.media), 1)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:add_cdrom", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"bus": "sata",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.media
self.assertEqual(len(self.instance.media), 2)
2020-07-13 09:33:09 +00:00
# create dummy iso
# with tempfile.NamedTemporaryFile() as f:
# f.write(b'\x00' * 1024**2)
# response = self.client.post(
# reverse('storage', args=[instance.compute.id, 'default']),
# {
# 'iso_upload': True,
# 'file': f
# },
# )
2020-10-15 05:58:42 +00:00
# detach CD-ROM drive
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:detach_cdrom", args=[self.instance.id, "sda"]),
2020-07-13 09:33:09 +00:00
{},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.media
self.assertEqual(len(self.instance.media), 1)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_snapshots(self):
self.assertEqual(len(self.instance.snapshots), 0)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:snapshot", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test-snapshot",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.snapshots
self.assertEqual(len(self.instance.snapshots), 1)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:revert_snapshot", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test-snapshot",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:delete_snapshot", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test-snapshot",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.snapshots
self.assertEqual(len(self.instance.snapshots), 0)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_autostart(self):
self.assertEqual(self.instance.autostart, 0)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_autostart", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.autostart
self.assertEqual(self.instance.autostart, 1)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:unset_autostart", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.autostart
self.assertEqual(self.instance.autostart, 0)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_bootmenu(self):
self.assertEqual(self.instance.bootmenu, True)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:unset_bootmenu", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.bootmenu
self.assertEqual(self.instance.bootmenu, False)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_bootmenu", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.bootmenu
self.assertEqual(self.instance.bootmenu, True)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_guest_agent(self):
self.assertEqual(self.instance.guest_agent, False)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_guest_agent", args=[self.instance.id]),
{"guest_agent": True},
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.guest_agent
self.assertEqual(self.instance.guest_agent, True)
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_guest_agent", args=[self.instance.id]),
{"guest_agent": False},
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.guest_agent
self.assertEqual(self.instance.guest_agent, False)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_video_model(self):
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.video_model, "vga")
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_video_model", args=[self.instance.id]),
{"video_model": "virtio"},
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.video_model
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.video_model, "virtio")
2020-10-15 05:58:42 +00:00
def test_owner(self):
self.assertEqual(UserInstance.objects.count(), 0)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:add_owner", args=[self.instance.id]),
{"user_id": self.admin_user.id},
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
self.assertEqual(UserInstance.objects.count(), 1)
user_instance: UserInstance = UserInstance.objects.get(id=1)
self.assertEqual(user_instance.instance_id, self.instance.id)
self.assertEqual(user_instance.user_id, self.admin_user.id)
# test when no multiple owners allowed
2022-11-02 05:54:35 +00:00
setting = AppSettings.objects.get(key="ALLOW_INSTANCE_MULTIPLE_OWNER")
setting.value = "False"
2020-10-15 05:58:42 +00:00
setting.save()
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:add_owner", args=[self.instance.id]),
{"user_id": self.test_user.id},
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
self.assertEqual(UserInstance.objects.count(), 1)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:del_owner", args=[self.instance.id]),
{"userinstance": user_instance.id},
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
self.assertEqual(UserInstance.objects.count(), 0)
def test_clone(self):
instance_count = Instance.objects.count()
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:clone", args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test-vm-clone",
"clone-net-mac-0": "de:ad:be:ef:de:ad",
"disk-vda": "test-clone.img",
"clone-title": "",
"clone-description": "",
"clone": "",
2020-07-13 09:33:09 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
self.assertEqual(Instance.objects.count(), instance_count + 1)
2020-07-13 09:33:09 +00:00
2022-11-02 05:54:35 +00:00
clone_qs = Instance.objects.filter(name="test-vm-clone")
2020-10-15 05:58:42 +00:00
self.assertEqual(len(clone_qs), 1)
clone = clone_qs[0]
2022-11-02 05:54:35 +00:00
self.assertEqual(clone.proxy.get_net_devices()[0]["mac"], "de:ad:be:ef:de:ad")
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:snapshot", args=[clone.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:destroy", args=[clone.id]),
{"delete_disk": True, "delete_nvram": True},
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
2022-11-02 05:54:35 +00:00
self.assertRedirects(response, reverse("instances:index"))
2020-10-15 05:58:42 +00:00
self.assertEqual(Instance.objects.count(), instance_count)
def test_clone_with_quota(self):
# test for non admin user with quotas
instance_count = Instance.objects.count()
UserInstance.objects.create(user=self.test_user, instance=self.instance)
self.client.force_login(self.test_user)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:clone", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test-vm-clone",
"clone-net-mac-0": "de:ad:be:ef:de:ad",
"disk-vda": "test-clone.img",
"clone-title": "",
"clone-description": "",
"clone": "",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
# no new instances created as user reached quota
self.assertEqual(Instance.objects.count(), instance_count)
def test_clone_errors(self):
instance_count = Instance.objects.count()
# duplicate name
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:clone", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test-vm",
"clone-net-mac-0": "de:ad:be:ef:de:ad",
"disk-vda": "test.img",
"clone-title": "",
"clone-description": "",
"clone": "",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
self.assertEqual(Instance.objects.count(), instance_count)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
# wrong name
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:clone", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "!@#$",
"clone-net-mac-0": "de:ad:be:ef:de:ad",
"disk-vda": "!@#$.img",
"clone-title": "",
"clone-description": "",
"clone": "",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
self.assertEqual(Instance.objects.count(), instance_count)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
# wrong mac
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:clone", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"name": "test-vm-clone",
"clone-net-mac-0": "gh:ad:be:ef:de:ad",
"disk-vda": "test-clone.img",
"clone-title": "",
"clone-description": "",
"clone": "",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
self.assertEqual(Instance.objects.count(), instance_count)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_console(self):
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:update_console", args=[self.instance.id]),
{"type": "spice", "listen_on": "0.0.0.0", "password": "", "keymap": "auto"},
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_status(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:status", args=[self.instance.id]))
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
def test_stats(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:stats", args=[self.instance.id]))
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
def test_guess_mac_address(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:guess_mac_address", args=[self.instance.name])
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
def test_random_mac_address(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:random_mac_address"))
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
def test_guess_clone_name(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:guess_clone_name"))
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
def test_sshkeys(self):
2022-11-02 05:54:35 +00:00
UserSSHKey.objects.create(
keyname="keyname", keypublic=self.rsa_key, user=self.test_user
)
2020-10-15 05:58:42 +00:00
UserInstance.objects.create(user=self.test_user, instance=self.instance)
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:sshkeys", args=[self.instance.id])
)
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 200)
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:sshkeys", args=[self.instance.id]) + "?plain=true"
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2020-10-15 05:58:42 +00:00
def test_check_instance(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:check_instance", args=["test-vm"])
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 200)
2022-11-02 05:54:35 +00:00
self.assertJSONEqual(response.content, {"vname": "test-vm", "exists": True})
2020-10-15 05:58:42 +00:00
def test_start_template(self):
# starting templates must fail
self.assertEqual(self.instance.status, 5)
self.instance.is_template = True
self.instance.save()
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:poweron", args=[self.instance.id]),
HTTP_REFERER=reverse("index"),
)
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 302)
del self.instance.status
self.assertEqual(self.instance.status, 5)
self.instance.is_template = False
self.instance.save()
def test_power(self):
# poweron
self.assertEqual(self.instance.status, 5)
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:poweron", args=[self.instance.id]),
HTTP_REFERER=reverse("index"),
)
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 302)
del self.instance.status
self.assertEqual(self.instance.status, 1)
2020-07-13 09:33:09 +00:00
# suspend
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:suspend", args=[self.instance.id]),
HTTP_REFERER=reverse("index"),
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.status
self.assertEqual(self.instance.status, 3)
2020-07-13 09:33:09 +00:00
# resume
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:resume", args=[self.instance.id]),
HTTP_REFERER=reverse("index"),
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.status
self.assertEqual(self.instance.status, 1)
2020-07-13 09:33:09 +00:00
# poweroff
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:poweroff", args=[self.instance.id]),
HTTP_REFERER=reverse("index"),
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 302)
# as no OS is installed ACPI won't work
2020-10-15 05:58:42 +00:00
del self.instance.status
self.assertEqual(self.instance.status, 1)
2020-07-13 09:33:09 +00:00
# powercycle
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:powercycle", args=[self.instance.id]),
HTTP_REFERER=reverse("index"),
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.status
self.assertEqual(self.instance.status, 1)
2020-07-13 09:33:09 +00:00
# force_off
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:force_off", args=[self.instance.id]),
HTTP_REFERER=reverse("index"),
)
2020-07-13 09:33:09 +00:00
self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
del self.instance.status
self.assertEqual(self.instance.status, 5)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_vv_file(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(
reverse("instances:getvvfile", args=[self.instance.id])
)
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 200)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_vcpu_hotplug(self):
2020-07-13 09:33:09 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_vcpu_hotplug", args=[self.instance.id]),
{"vcpu_hotplug": "True"},
HTTP_REFERER=reverse("index"),
2020-07-13 09:33:09 +00:00
)
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 302)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_change_network(self):
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.networks[0]["mac"], "52:54:00:a2:3c:e7")
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:change_network", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"net-mac-0": "52:54:00:a2:3c:e8",
"net-source-0": "net:default",
"net-nwfilter-0": "",
"net-model-0": "virtio",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
del self.instance.networks
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.networks[0]["mac"], "52:54:00:a2:3c:e8")
2020-10-15 05:58:42 +00:00
def test_add_delete_network(self):
self.assertEqual(len(self.instance.networks), 1)
2022-11-02 05:54:35 +00:00
net_mac = self.instance.networks[0]["mac"]
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:add_network", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"add-net-mac": "52:54:00:a2:3c:e9",
"add-net-network": "net:default",
"add_net-nwfilter": "",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
del self.instance.networks
self.assertEqual(len(self.instance.networks), 2)
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.networks[1]["mac"], "52:54:00:a2:3c:e9")
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:delete_network", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"delete_network": "52:54:00:a2:3c:e9",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
del self.instance.networks
self.assertEqual(len(self.instance.networks), 1)
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.networks[0]["mac"], net_mac)
2020-07-13 09:33:09 +00:00
2020-10-15 05:58:42 +00:00
def test_set_link_state(self):
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.networks[0]["state"], "up")
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_link_state", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"mac": self.instance.networks[0]["mac"],
"set_link_state": "up",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
del self.instance.networks
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.networks[0]["state"], "down")
2020-10-15 05:58:42 +00:00
def test_set_unset_qos(self):
self.assertEqual(len(self.instance.qos.keys()), 0)
2022-11-02 05:54:35 +00:00
net_mac = self.instance.networks[0]["mac"]
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:set_qos", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"net-mac-0": net_mac,
"qos_direction": "inbound",
"qos_average": 1,
"qos_peak": 1,
"qos_burst": 1,
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
del self.instance.qos
self.assertEqual(len(self.instance.qos.keys()), 1)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:unset_qos", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"net-mac": net_mac,
"qos_direction": "inbound",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
del self.instance.qos
self.assertEqual(len(self.instance.qos.keys()), 0)
# test on running instance
# self.instance.proxy.start()
2020-07-13 09:33:09 +00:00
# response = self.client.post(
2020-10-15 05:58:42 +00:00
# reverse('instances:set_qos', args=[self.instance.id]),
2020-07-13 09:33:09 +00:00
# {
2020-10-15 05:58:42 +00:00
# 'net-mac-0': net_mac,
# 'qos_direction': 'inbound',
# 'qos_average': 1,
# 'qos_peak': 1,
# 'qos_burst': 1,
2020-07-13 09:33:09 +00:00
# },
# HTTP_REFERER=reverse('index'),
# )
# self.assertEqual(response.status_code, 302)
2020-10-15 05:58:42 +00:00
# self.instance.proxy.force_shutdown()
def test_change_options(self):
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.title, "")
self.assertEqual(self.instance.description, "")
2020-10-15 05:58:42 +00:00
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:change_options", args=[self.instance.id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"title": "test-vm-title",
"description": "test-vm description",
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
del self.instance.title
del self.instance.description
2022-11-02 05:54:35 +00:00
self.assertEqual(self.instance.title, "test-vm-title")
self.assertEqual(self.instance.description, "test-vm description")
2020-10-15 05:58:42 +00:00
def test_flavors(self):
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:flavor_create"))
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 200)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:flavor_create"),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"label": "test_flavor",
"memory": 256,
"vcpu": 1,
"disk": 10,
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
id = Flavor.objects.last().id
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:flavor_update", args=[id]))
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 200)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:flavor_update", args=[id]),
2020-10-15 05:58:42 +00:00
{
2022-11-02 05:54:35 +00:00
"label": "test_flavor_",
"memory": 256,
"vcpu": 1,
"disk": 10,
2020-10-15 05:58:42 +00:00
},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
2022-11-02 05:54:35 +00:00
response = self.client.get(reverse("instances:flavor_delete", args=[id]))
2020-10-15 05:58:42 +00:00
self.assertEqual(response.status_code, 200)
response = self.client.post(
2022-11-02 05:54:35 +00:00
reverse("instances:flavor_delete", args=[id]),
2020-10-15 05:58:42 +00:00
{},
2022-11-02 05:54:35 +00:00
HTTP_REFERER=reverse("index"),
2020-10-15 05:58:42 +00:00
)
self.assertEqual(response.status_code, 302)
# def donot_test_instance(self):
# compute: Compute = Compute.objects.get(pk=1)
# user: User = User.objects.get(pk=1)
# # delete started instance with disks
# self.instance.proxy.start()
# del self.instance.status
# self.assertEqual(self.instance.status, 1)
# # create volume
# response = self.client.post(
# reverse('create_volume', args=[compute.id, 'default']),
# {
# 'name': 'test3',
# 'format': 'qcow2',
# 'size': '1',
# 'meta_prealloc': False,
# },
# )
# self.assertRedirects(response, reverse('storage', args=[compute.id, 'default']))
# # delete volume
# response = self.client.post(
# reverse('instances:delete_vol', args=[instance.id]),
# {
# 'storage': 'default',
# 'dev': 'vdb',
# 'name': 'test3.qcow2',
# },
# HTTP_REFERER=reverse('index'),
# )
# self.assertEqual(response.status_code, 302)
# , list(response.context['messages'])[0]