summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-12-20 23:42:24 +0000
committerGerrit Code Review <review@openstack.org>2012-12-20 23:42:24 +0000
commitff04ded017802af199fa672ad4b673f46d98ca27 (patch)
treee4988ce43b1d2bd3960bd00091841164360ac654 /nova/tests
parent15528379fcd138cbb68f2522bb177d2aede73b10 (diff)
parent617c92b0b56cac51b3110443c1ff29b951e812d7 (diff)
Merge "Baremetal VIF and Volume sub-drivers."
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/baremetal/db/test_bm_interface.py17
-rw-r--r--nova/tests/baremetal/db/utils.py1
-rw-r--r--nova/tests/baremetal/test_driver.py19
-rw-r--r--nova/tests/baremetal/test_volume_driver.py166
4 files changed, 203 insertions, 0 deletions
diff --git a/nova/tests/baremetal/db/test_bm_interface.py b/nova/tests/baremetal/db/test_bm_interface.py
index a9168bff6..9f051ac9b 100644
--- a/nova/tests/baremetal/db/test_bm_interface.py
+++ b/nova/tests/baremetal/db/test_bm_interface.py
@@ -35,3 +35,20 @@ class BareMetalInterfaceTestCase(base.BMDBTestCase):
pif2_id = db.bm_interface_create(self.context, 2, '11:11:11:11:11:11',
'0x2', 2)
self.assertTrue(pif2_id is not None)
+
+ def test_unique_vif_uuid(self):
+ pif1_id = db.bm_interface_create(self.context, 1, '11:11:11:11:11:11',
+ '0x1', 1)
+ pif2_id = db.bm_interface_create(self.context, 2, '22:22:22:22:22:22',
+ '0x2', 2)
+ db.bm_interface_set_vif_uuid(self.context, pif1_id, 'AAAA')
+ self.assertRaises(exception.NovaException,
+ db.bm_interface_set_vif_uuid,
+ self.context, pif2_id, 'AAAA')
+
+ def test_vif_not_found(self):
+ pif_id = db.bm_interface_create(self.context, 1, '11:11:11:11:11:11',
+ '0x1', 1)
+ self.assertRaises(exception.NovaException,
+ db.bm_interface_set_vif_uuid,
+ self.context, pif_id + 1, 'AAAA')
diff --git a/nova/tests/baremetal/db/utils.py b/nova/tests/baremetal/db/utils.py
index 034f2f25a..800305402 100644
--- a/nova/tests/baremetal/db/utils.py
+++ b/nova/tests/baremetal/db/utils.py
@@ -60,6 +60,7 @@ def new_bm_interface(**kwargs):
x.address = kwargs.pop('address', None)
x.datapath_id = kwargs.pop('datapath_id', None)
x.port_no = kwargs.pop('port_no', None)
+ x.vif_uuid = kwargs.pop('vif_uuid', None)
if len(kwargs) > 0:
raise test.TestingException("unknown field: %s"
% ','.join(kwargs.keys()))
diff --git a/nova/tests/baremetal/test_driver.py b/nova/tests/baremetal/test_driver.py
index 117520e94..51019c439 100644
--- a/nova/tests/baremetal/test_driver.py
+++ b/nova/tests/baremetal/test_driver.py
@@ -31,15 +31,30 @@ from nova.tests import utils as test_utils
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import db
from nova.virt.baremetal import driver as bm_driver
+from nova.virt.baremetal import volume_driver
from nova.virt.firewall import NoopFirewallDriver
CONF = cfg.CONF
+class FakeVifDriver(object):
+
+ def plug(self, instance, vif):
+ pass
+
+ def unplug(self, instance, vif):
+ pass
+
FakeFirewallDriver = NoopFirewallDriver
+class FakeVolumeDriver(volume_driver.VolumeDriver):
+ def __init__(self, virtapi):
+ super(FakeVolumeDriver, self).__init__(virtapi)
+ self._initiator = "testtesttest"
+
+
NODE = utils.new_bm_node(cpus=2, memory_mb=4096, service_host="host1")
NICS = [
{'address': '01:23:45:67:89:01', 'datapath_id': '0x1', 'port_no': 1, },
@@ -55,7 +70,9 @@ COMMON_FLAGS = dict(
baremetal_sql_connection='sqlite:///:memory:',
baremetal_driver='nova.virt.baremetal.fake.Fake',
power_manager='nova.virt.baremetal.fake.FakePowerManager',
+ baremetal_vif_driver=class_path(FakeVifDriver),
firewall_driver=class_path(FakeFirewallDriver),
+ baremetal_volume_driver=class_path(FakeVolumeDriver),
instance_type_extra_specs=['cpu_arch:test'],
host=NODE['service_host'],
)
@@ -154,7 +171,9 @@ class BaremetalDriverTestCase(test_virt_drivers._VirtDriverTestCase,
from nova.virt.baremetal import fake
drv = bm_driver.BareMetalDriver(None)
self.assertTrue(isinstance(drv.baremetal_nodes, fake.Fake))
+ self.assertTrue(isinstance(drv._vif_driver, FakeVifDriver))
self.assertTrue(isinstance(drv._firewall_driver, FakeFirewallDriver))
+ self.assertTrue(isinstance(drv._volume_driver, FakeVolumeDriver))
def test_get_host_stats(self):
self.flags(instance_type_extra_specs=['cpu_arch:x86_64',
diff --git a/nova/tests/baremetal/test_volume_driver.py b/nova/tests/baremetal/test_volume_driver.py
new file mode 100644
index 000000000..dacca6e53
--- /dev/null
+++ b/nova/tests/baremetal/test_volume_driver.py
@@ -0,0 +1,166 @@
+# Copyright (c) 2012 NTT DOCOMO, INC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+Tests for baremetal volume driver.
+"""
+
+import mox
+
+from nova.openstack.common import cfg
+from nova import test
+from nova import utils
+
+from nova.virt.baremetal import volume_driver
+
+CONF = cfg.CONF
+
+SHOW_OUTPUT = """Target 1: iqn.2010-10.org.openstack:volume-00000001
+ System information:
+ Driver: iscsi
+ State: ready
+ I_T nexus information:
+ I_T nexus: 8
+ Initiator: iqn.1993-08.org.debian:01:7780c6a16b4
+ Connection: 0
+ IP Address: 172.17.12.10
+ LUN information:
+ LUN: 0
+ Type: controller
+ SCSI ID: IET 00010000
+ SCSI SN: beaf10
+ Size: 0 MB, Block size: 1
+ Online: Yes
+ Removable media: No
+ Readonly: No
+ Backing store type: null
+ Backing store path: None
+ Backing store flags:
+ LUN: 1
+ Type: disk
+ SCSI ID: IET 00010001
+ SCSI SN: beaf11
+ Size: 1074 MB, Block size: 512
+ Online: Yes
+ Removable media: No
+ Readonly: No
+ Backing store type: rdwr
+ Backing store path: /dev/nova-volumes/volume-00000001
+ Backing store flags:
+ Account information:
+ ACL information:
+ ALL
+Target 2: iqn.2010-10.org.openstack:volume-00000002
+ System information:
+ Driver: iscsi
+ State: ready
+ I_T nexus information:
+ LUN information:
+ LUN: 0
+ Type: controller
+ SCSI ID: IET 00020000
+ SCSI SN: beaf20
+ Size: 0 MB, Block size: 1
+ Online: Yes
+ Removable media: No
+ Readonly: No
+ Backing store type: null
+ Backing store path: None
+ Backing store flags:
+ LUN: 1
+ Type: disk
+ SCSI ID: IET 00020001
+ SCSI SN: beaf21
+ Size: 2147 MB, Block size: 512
+ Online: Yes
+ Removable media: No
+ Readonly: No
+ Backing store type: rdwr
+ Backing store path: /dev/nova-volumes/volume-00000002
+ Backing store flags:
+ Account information:
+ ACL information:
+ ALL
+Target 1000001: iqn.2010-10.org.openstack.baremetal:1000001-dev.vdc
+ System information:
+ Driver: iscsi
+ State: ready
+ I_T nexus information:
+ LUN information:
+ LUN: 0
+ Type: controller
+ SCSI ID: IET f42410000
+ SCSI SN: beaf10000010
+ Size: 0 MB, Block size: 1
+ Online: Yes
+ Removable media: No
+ Readonly: No
+ Backing store type: null
+ Backing store path: None
+ Backing store flags:
+ LUN: 1
+ Type: disk
+ SCSI ID: IET f42410001
+ SCSI SN: beaf10000011
+ Size: 1074 MB, Block size: 512
+ Online: Yes
+ Removable media: No
+ Readonly: No
+ Backing store type: rdwr
+ Backing store path: /dev/disk/by-path/ip-172.17.12.10:3260-iscsi-\
+iqn.2010-10.org.openstack:volume-00000001-lun-1
+ Backing store flags:
+ Account information:
+ ACL information:
+ ALL
+"""
+
+
+def fake_show_tgtadm():
+ return SHOW_OUTPUT
+
+
+class BareMetalVolumeTestCase(test.TestCase):
+
+ def setUp(self):
+ super(BareMetalVolumeTestCase, self).setUp()
+ self.stubs.Set(volume_driver, '_show_tgtadm', fake_show_tgtadm)
+
+ def test_list_backingstore_path(self):
+ l = volume_driver._list_backingstore_path()
+ self.assertEqual(len(l), 3)
+ self.assertIn('/dev/nova-volumes/volume-00000001', l)
+ self.assertIn('/dev/nova-volumes/volume-00000002', l)
+ self.assertIn('/dev/disk/by-path/ip-172.17.12.10:3260-iscsi-'
+ 'iqn.2010-10.org.openstack:volume-00000001-lun-1', l)
+
+ def test_get_next_tid(self):
+ tid = volume_driver._get_next_tid()
+ self.assertEqual(1000002, tid)
+
+ def test_find_tid_found(self):
+ tid = volume_driver._find_tid(
+ 'iqn.2010-10.org.openstack.baremetal:1000001-dev.vdc')
+ self.assertEqual(1000001, tid)
+
+ def test_find_tid_not_found(self):
+ tid = volume_driver._find_tid(
+ 'iqn.2010-10.org.openstack.baremetal:1000002-dev.vdc')
+ self.assertTrue(tid is None)
+
+ def test_get_iqn(self):
+ self.flags(baremetal_iscsi_iqn_prefix='iqn.2012-12.a.b')
+ iqn = volume_driver._get_iqn('instname', '/dev/vdx')
+ self.assertEquals('iqn.2012-12.a.b:instname-dev-vdx', iqn)