Commit fda3d987 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Thomas Thrainer

Add unittests for Hotplug support

Try base InstanceSetParams tests that modify instance's
devices with hotplug=True.

Add some unittests for kvm hypervisor regarding runtime file
manipulation. Based on a sample runtime file search for
specific disk and nic entries based on their UUID.

Add unittest for kvm device id generation.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarThomas Thrainer <thomasth@google.com>
parent e61c0f24
......@@ -1318,6 +1318,7 @@ TEST_FILES = \
test/data/kvm_0.9.1_help_boot_test.txt \
test/data/kvm_1.0_help.txt \
test/data/kvm_1.1.2_help.txt \
test/data/kvm_runtime.json \
test/data/lvs_lv.txt \
test/data/NEWS_OK.txt \
test/data/NEWS_previous_unreleased.txt \
......
[
[
"/usr/bin/kvm",
"-name",
"xen-test-inst2",
"-m",
1024,
"-smp",
"1",
"-pidfile",
"/var/run/ganeti/kvm-hypervisor/pid/xen-test-inst2",
"-balloon",
"virtio",
"-daemonize",
"-machine",
"pc-1.1",
"-monitor",
"unix:/var/run/ganeti/kvm-hypervisor/ctrl/xen-test-inst2.monitor,server,nowait",
"-serial",
"unix:/var/run/ganeti/kvm-hypervisor/ctrl/xen-test-inst2.serial,server,nowait",
"-usb",
"-usbdevice",
"tablet",
"-vnc",
":5100"
],
[
{
"mac": "aa:00:00:bf:2f:16",
"nicparams": {
"link": "br0",
"mode": "bridged"
},
"pci": 6,
"uuid": "003fc157-66a8-4e6d-8b7e-ec4f69751396"
}
],
{
"acpi": true,
"boot_order": "disk",
"cdrom2_image_path": "",
"cdrom_disk_type": "",
"cdrom_image_path": "",
"cpu_cores": 0,
"cpu_mask": "all",
"cpu_sockets": 0,
"cpu_threads": 0,
"cpu_type": "",
"disk_cache": "default",
"disk_type": "paravirtual",
"floppy_image_path": "",
"initrd_path": "",
"kernel_args": "ro",
"kernel_path": "",
"keymap": "",
"kvm_extra": "",
"kvm_flag": "",
"kvm_path": "/usr/bin/kvm",
"machine_version": "",
"mem_path": "",
"migration_bandwidth": 32,
"migration_downtime": 30,
"migration_mode": "live",
"migration_port": 8102,
"nic_type": "paravirtual",
"reboot_behavior": "reboot",
"root_path": "/dev/vda1",
"security_domain": "",
"security_model": "none",
"serial_console": true,
"serial_speed": 38400,
"soundhw": "",
"spice_bind": "",
"spice_image_compression": "",
"spice_ip_version": 0,
"spice_jpeg_wan_compression": "",
"spice_password_file": "",
"spice_playback_compression": true,
"spice_streaming_video": "",
"spice_tls_ciphers": "HIGH:-DES:-3DES:-EXPORT:-ADH",
"spice_use_tls": false,
"spice_use_vdagent": true,
"spice_zlib_glz_wan_compression": "",
"usb_devices": "",
"usb_mouse": "",
"use_chroot": false,
"use_localtime": false,
"vga": "",
"vhost_net": false,
"vnc_bind_address": "0.0.0.0",
"vnc_password_file": "",
"vnc_tls": false,
"vnc_x509_path": "",
"vnc_x509_verify": false,
"vnet_hdr": true
},
[
[
{
"dev_type": "lvm",
"iv_name": "disk/0",
"logical_id": [
"autovg",
"b9d4ee8e-c81b-42eb-9899-60481886c7ac.disk0"
],
"mode": "rw",
"name": "disk0",
"params": {
"stripes": 1
},
"pci": 4,
"size": 1024,
"uuid": "7c079136-2573-4112-82d0-0d3d2aa90d8f"
},
"/var/run/ganeti/instance-disks/xen-test-inst2:0",
"rbd://123451214123/"
],
[
{
"dev_type": "lvm",
"iv_name": "disk/1",
"logical_id": [
"autovg",
"602c0a3b-d09b-4ebe-9774-5f12ef654a1f.disk1"
],
"mode": "rw",
"name": "disk1",
"params": {
"stripes": 1
},
"pci": 5,
"size": 512,
"uuid": "9f5c5bd4-6f60-480b-acdc-9bb1a4b7df79"
},
"/var/run/ganeti/instance-disks/xen-test-inst2:1",
null
]
]
]
......@@ -1970,6 +1970,13 @@ class TestLUInstanceSetParams(CmdlibTestCase):
nics=[(constants.DDM_ADD, -1, {})])
self.ExecOpCode(op)
def testHotAddNic(self):
op = self.CopyOpCode(self.op,
nics=[(constants.DDM_ADD, -1, {})],
hotplug=True)
self.ExecOpCode(op)
self.assertTrue(self.rpc.call_hotplug_device.called)
def testAddNicWithIp(self):
op = self.CopyOpCode(self.op,
nics=[(constants.DDM_ADD, -1,
......@@ -2053,6 +2060,13 @@ class TestLUInstanceSetParams(CmdlibTestCase):
nics=[(constants.DDM_MODIFY, 0, {})])
self.ExecOpCode(op)
def testHotModifyNic(self):
op = self.CopyOpCode(self.op,
nics=[(constants.DDM_MODIFY, 0, {})],
hotplug=True)
self.ExecOpCode(op)
self.assertTrue(self.rpc.call_hotplug_device.called)
def testRemoveLastNic(self):
op = self.CopyOpCode(self.op,
nics=[(constants.DDM_REMOVE, 0, {})])
......@@ -2067,6 +2081,16 @@ class TestLUInstanceSetParams(CmdlibTestCase):
nics=[(constants.DDM_REMOVE, 0, {})])
self.ExecOpCode(op)
def testHotRemoveNic(self):
inst = self.cfg.AddNewInstance(nics=[self.cfg.CreateNic(),
self.cfg.CreateNic()])
op = self.CopyOpCode(self.op,
instance_name=inst.name,
nics=[(constants.DDM_REMOVE, 0, {})],
hotplug=True)
self.ExecOpCode(op)
self.assertTrue(self.rpc.call_hotplug_device.called)
def testSetOffline(self):
op = self.CopyOpCode(self.op,
offline=True)
......@@ -2141,6 +2165,35 @@ class TestLUInstanceSetParams(CmdlibTestCase):
}]])
self.ExecOpCode(op)
def testHotAddDisk(self):
self.rpc.call_blockdev_assemble.return_value = \
self.RpcResultsBuilder() \
.CreateSuccessfulNodeResult(self.master, ("/dev/mocked_path",
"/var/run/ganeti/instance-disks/mocked_d"))
op = self.CopyOpCode(self.op,
disks=[[constants.DDM_ADD, -1,
{
constants.IDISK_SIZE: 1024,
}]],
hotplug=True)
self.ExecOpCode(op)
self.assertTrue(self.rpc.call_blockdev_create.called)
self.assertTrue(self.rpc.call_blockdev_assemble.called)
self.assertTrue(self.rpc.call_hotplug_device.called)
def testHotRemoveDisk(self):
inst = self.cfg.AddNewInstance(disks=[self.cfg.CreateDisk(),
self.cfg.CreateDisk()])
op = self.CopyOpCode(self.op,
instance_name=inst.name,
disks=[[constants.DDM_REMOVE, -1,
{}]],
hotplug=True)
self.ExecOpCode(op)
self.assertTrue(self.rpc.call_hotplug_device.called)
self.assertTrue(self.rpc.call_blockdev_shutdown.called)
self.assertTrue(self.rpc.call_blockdev_remove.called)
def testModifyDiskWithSize(self):
op = self.CopyOpCode(self.op,
disks=[[constants.DDM_MODIFY, 0,
......
......@@ -27,6 +27,7 @@ import unittest
import socket
import os
import struct
import re
from ganeti import serializer
from ganeti import constants
......@@ -384,5 +385,52 @@ class TestProbeTapVnetHdr(unittest.TestCase):
self.assertFalse(hv_kvm._ProbeTapVnetHdr(fd, _features_fn=lambda _: None))
class TestGenerateDeviceKVMId(unittest.TestCase):
def test(self):
device = objects.NIC()
target = constants.HOTPLUG_TARGET_NIC
fn = hv_kvm._GenerateDeviceKVMId
self.assertRaises(errors.HotplugError, fn, target, device)
device.pci = 5
device.uuid = "003fc157-66a8-4e6d-8b7e-ec4f69751396"
self.assertTrue(re.match("hotnic-003fc157-pci-5", fn(target, device)))
class TestGetRuntimeInfo(unittest.TestCase):
@classmethod
def _GetRuntime(cls):
data = testutils.ReadTestData("kvm_runtime.json")
return hv_kvm._AnalyzeSerializedRuntime(data)
def _fail(self, target, device, runtime):
device.uuid = "aaaaaaaa-66a8-4e6d-8b7e-ec4f69751396"
self.assertRaises(errors.HotplugError,
hv_kvm._GetExistingDeviceInfo,
target, device, runtime)
def testNIC(self):
device = objects.NIC()
target = constants.HOTPLUG_TARGET_NIC
runtime = self._GetRuntime()
self._fail(target, device, runtime)
device.uuid = "003fc157-66a8-4e6d-8b7e-ec4f69751396"
devinfo = hv_kvm._GetExistingDeviceInfo(target, device, runtime)
self.assertTrue(devinfo.pci==6)
def testDisk(self):
device = objects.Disk()
target = constants.HOTPLUG_TARGET_DISK
runtime = self._GetRuntime()
self._fail(target, device, runtime)
device.uuid = "9f5c5bd4-6f60-480b-acdc-9bb1a4b7df79"
(devinfo, _, __) = hv_kvm._GetExistingDeviceInfo(target, device, runtime)
self.assertTrue(devinfo.pci==5)
if __name__ == "__main__":
testutils.GanetiTestProgram()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment