|
|
|
@@ -123,6 +123,10 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|
|
|
|
def get_hypervisor_type(self):
|
|
|
|
|
return self.hyperv
|
|
|
|
|
self.fake_conn = FakeLibvirtConnection("Xen")
|
|
|
|
|
self.connr = {
|
|
|
|
|
'ip': '127.0.0.1',
|
|
|
|
|
'initiator': 'fake_initiator'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_libvirt_iscsi_driver(self):
|
|
|
|
|
# NOTE(vish) exists is to make driver assume connecting worked
|
|
|
|
@@ -136,8 +140,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|
|
|
|
'name': name,
|
|
|
|
|
'provider_auth': None,
|
|
|
|
|
'provider_location': '%s,fake %s' % (location, iqn)}
|
|
|
|
|
address = '127.0.0.1'
|
|
|
|
|
connection_info = vol_driver.initialize_connection(vol, '127.0.0.1')
|
|
|
|
|
connection_info = vol_driver.initialize_connection(vol, self.connr)
|
|
|
|
|
mount_device = "vde"
|
|
|
|
|
xml = libvirt_driver.connect_volume(connection_info, mount_device)
|
|
|
|
|
tree = xml_to_tree(xml)
|
|
|
|
@@ -145,7 +148,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|
|
|
|
self.assertEqual(tree.get('type'), 'block')
|
|
|
|
|
self.assertEqual(tree.find('./source').get('dev'), dev_str)
|
|
|
|
|
libvirt_driver.disconnect_volume(connection_info, mount_device)
|
|
|
|
|
connection_info = vol_driver.terminate_connection(vol, '127.0.0.1')
|
|
|
|
|
connection_info = vol_driver.terminate_connection(vol, self.connr)
|
|
|
|
|
expected_commands = [('iscsiadm', '-m', 'node', '-T', iqn,
|
|
|
|
|
'-p', location),
|
|
|
|
|
('iscsiadm', '-m', 'node', '-T', iqn,
|
|
|
|
@@ -167,8 +170,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|
|
|
|
libvirt_driver = volume.LibvirtNetVolumeDriver(self.fake_conn)
|
|
|
|
|
name = 'volume-00000001'
|
|
|
|
|
vol = {'id': 1, 'name': name}
|
|
|
|
|
address = '127.0.0.1'
|
|
|
|
|
connection_info = vol_driver.initialize_connection(vol, address)
|
|
|
|
|
connection_info = vol_driver.initialize_connection(vol, self.connr)
|
|
|
|
|
mount_device = "vde"
|
|
|
|
|
xml = libvirt_driver.connect_volume(connection_info, mount_device)
|
|
|
|
|
tree = xml_to_tree(xml)
|
|
|
|
@@ -176,15 +178,14 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|
|
|
|
self.assertEqual(tree.find('./source').get('protocol'), 'sheepdog')
|
|
|
|
|
self.assertEqual(tree.find('./source').get('name'), name)
|
|
|
|
|
libvirt_driver.disconnect_volume(connection_info, mount_device)
|
|
|
|
|
connection_info = vol_driver.terminate_connection(vol, '127.0.0.1')
|
|
|
|
|
connection_info = vol_driver.terminate_connection(vol, self.connr)
|
|
|
|
|
|
|
|
|
|
def test_libvirt_rbd_driver(self):
|
|
|
|
|
vol_driver = volume_driver.RBDDriver()
|
|
|
|
|
libvirt_driver = volume.LibvirtNetVolumeDriver(self.fake_conn)
|
|
|
|
|
name = 'volume-00000001'
|
|
|
|
|
vol = {'id': 1, 'name': name}
|
|
|
|
|
address = '127.0.0.1'
|
|
|
|
|
connection_info = vol_driver.initialize_connection(vol, address)
|
|
|
|
|
connection_info = vol_driver.initialize_connection(vol, self.connr)
|
|
|
|
|
mount_device = "vde"
|
|
|
|
|
xml = libvirt_driver.connect_volume(connection_info, mount_device)
|
|
|
|
|
tree = xml_to_tree(xml)
|
|
|
|
@@ -193,7 +194,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|
|
|
|
rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
|
|
|
|
|
self.assertEqual(tree.find('./source').get('name'), rbd_name)
|
|
|
|
|
libvirt_driver.disconnect_volume(connection_info, mount_device)
|
|
|
|
|
connection_info = vol_driver.terminate_connection(vol, '127.0.0.1')
|
|
|
|
|
connection_info = vol_driver.terminate_connection(vol, self.connr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CacheConcurrencyTestCase(test.TestCase):
|
|
|
|
@@ -355,6 +356,22 @@ class LibvirtConnTestCase(test.TestCase):
|
|
|
|
|
|
|
|
|
|
return db.service_create(context.get_admin_context(), service_ref)
|
|
|
|
|
|
|
|
|
|
def test_get_connector(self):
|
|
|
|
|
initiator = 'fake.initiator.iqn'
|
|
|
|
|
ip = 'fakeip'
|
|
|
|
|
self.flags(my_ip=ip)
|
|
|
|
|
|
|
|
|
|
conn = connection.LibvirtConnection(True)
|
|
|
|
|
expected = {
|
|
|
|
|
'ip': ip,
|
|
|
|
|
'initiator': initiator
|
|
|
|
|
}
|
|
|
|
|
volume = {
|
|
|
|
|
'id': 'fake'
|
|
|
|
|
}
|
|
|
|
|
result = conn.get_volume_connector(volume)
|
|
|
|
|
self.assertDictMatch(expected, result)
|
|
|
|
|
|
|
|
|
|
def test_preparing_xml_info(self):
|
|
|
|
|
conn = connection.LibvirtConnection(True)
|
|
|
|
|
instance_ref = db.instance_create(self.context, self.test_instance)
|
|
|
|
@@ -1764,6 +1781,17 @@ class NWFilterTestCase(test.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LibvirtUtilsTestCase(test.TestCase):
|
|
|
|
|
def test_get_iscsi_initiator(self):
|
|
|
|
|
self.mox.StubOutWithMock(utils, 'execute')
|
|
|
|
|
initiator = 'fake.initiator.iqn'
|
|
|
|
|
rval = ("junk\nInitiatorName=%s\njunk\n" % initiator, None)
|
|
|
|
|
utils.execute('cat', '/etc/iscsi/initiatorname.iscsi',
|
|
|
|
|
run_as_root=True).AndReturn(rval)
|
|
|
|
|
# Start test
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
result = libvirt_utils.get_iscsi_initiator()
|
|
|
|
|
self.assertEqual(initiator, result)
|
|
|
|
|
|
|
|
|
|
def test_create_image(self):
|
|
|
|
|
self.mox.StubOutWithMock(utils, 'execute')
|
|
|
|
|
utils.execute('qemu-img', 'create', '-f', 'raw',
|
|
|
|
|