From d14ac4bf38f23e429572f210f7b0560493968b15 Mon Sep 17 00:00:00 2001 From: Nirmal Ranganathan Date: Tue, 1 May 2012 14:02:16 -0500 Subject: Adding 'host' info to volume-compute connection information. Added a new key 'host' for the initialize/terminate volume connection information. Updated the HpSanISCSIDriver to use teh initialize and terminate methods. Added missing unit tests for the HpSanISCSIDriver. Fixes bug 992729. Change-Id: I09fad6b5328cbfb860ab2c7ae5d206010f3dd45d --- nova/tests/test_libvirt.py | 8 +- nova/tests/test_virt_drivers.py | 1 + nova/tests/volume/__init__.py | 13 ++ nova/tests/volume/test_HpSanISCSIDriver.py | 212 +++++++++++++++++++++++++++++ 4 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 nova/tests/volume/__init__.py create mode 100644 nova/tests/volume/test_HpSanISCSIDriver.py (limited to 'nova/tests') diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 9a459545c..ee17abc4f 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -142,7 +142,8 @@ class LibvirtVolumeTestCase(test.TestCase): self.fake_conn = FakeLibvirtConnection() self.connr = { 'ip': '127.0.0.1', - 'initiator': 'fake_initiator' + 'initiator': 'fake_initiator', + 'host': 'fake_host' } def test_libvirt_iscsi_driver(self): @@ -478,12 +479,15 @@ class LibvirtConnTestCase(test.TestCase): def test_get_connector(self): initiator = 'fake.initiator.iqn' ip = 'fakeip' + host = 'fakehost' self.flags(my_ip=ip) + self.flags(host=host) conn = connection.LibvirtConnection(True) expected = { 'ip': ip, - 'initiator': initiator + 'initiator': initiator, + 'host': host } volume = { 'id': 'fake' diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 592926597..f8ed0f2ea 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -231,6 +231,7 @@ class _VirtDriverTestCase(test.TestCase): result = self.connection.get_volume_connector({'id': 'fake'}) self.assertTrue('ip' in result) self.assertTrue('initiator' in result) + self.assertTrue('host' in result) @catch_notimplementederror def test_attach_detach_volume(self): diff --git a/nova/tests/volume/__init__.py b/nova/tests/volume/__init__.py new file mode 100644 index 000000000..4549abf92 --- /dev/null +++ b/nova/tests/volume/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2012 OpenStack LLC +# +# 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. diff --git a/nova/tests/volume/test_HpSanISCSIDriver.py b/nova/tests/volume/test_HpSanISCSIDriver.py new file mode 100644 index 000000000..467c5d728 --- /dev/null +++ b/nova/tests/volume/test_HpSanISCSIDriver.py @@ -0,0 +1,212 @@ +# Copyright 2012 OpenStack LLC +# +# 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. +from nova import exception +from nova import log as logging +from nova.volume import san +from nova import test + +LOG = logging.getLogger(__name__) + + +class HpSanISCSITestCase(test.TestCase): + + def setUp(self): + super(HpSanISCSITestCase, self).setUp() + self.stubs.Set(san.HpSanISCSIDriver, "_cliq_run", + self._fake_cliq_run) + self.stubs.Set(san.HpSanISCSIDriver, "_get_iscsi_properties", + self._fake_get_iscsi_properties) + self.driver = san.HpSanISCSIDriver() + self.volume_name = "fakevolume" + self.connector = {'ip': '10.0.0.2', + 'initiator': 'iqn.1993-08.org.debian:01:222', + 'host': 'fakehost'} + self.properties = {'target_discoverd': True, + 'target_portal': '10.0.1.6:3260', + 'target_iqn': + 'iqn.2003-10.com.lefthandnetworks:group01:25366:fakev', + 'volume_id': 1} + + def tearDown(self): + super(HpSanISCSITestCase, self).tearDown() + + def _fake_get_iscsi_properties(self, volume): + return self.properties + + def _fake_cliq_run(self, verb, cliq_args): + """Return fake results for the various methods.""" + + def create_volume(cliq_args): + """ + input = "createVolume description="fake description" + clusterName=Cluster01 volumeName=fakevolume + thinProvision=0 output=XML size=1GB" + """ + output = """ + + """ + self.assertEqual(cliq_args['volumeName'], self.volume_name) + self.assertEqual(cliq_args['thinProvision'], '1') + self.assertEqual(cliq_args['size'], '1GB') + return output, None + + def delete_volume(cliq_args): + """ + input = "deleteVolume volumeName=fakevolume prompt=false + output=XML" + """ + output = """ + + """ + self.assertEqual(cliq_args['volumeName'], self.volume_name) + self.assertEqual(cliq_args['prompt'], 'false') + return output, None + + def assign_volume(cliq_args): + """ + input = "assignVolumeToServer volumeName=fakevolume + serverName=fakehost + output=XML" + """ + output = """ + + """ + self.assertEqual(cliq_args['volumeName'], self.volume_name) + self.assertEqual(cliq_args['serverName'], self.connector['host']) + return output, None + + def unassign_volume(cliq_args): + """ + input = "unassignVolumeToServer volumeName=fakevolume + serverName=fakehost output=XML + """ + output = """ + + """ + self.assertEqual(cliq_args['volumeName'], self.volume_name) + self.assertEqual(cliq_args['serverName'], self.connector['host']) + return output, None + + def get_cluster_info(cliq_args): + """ + input = "getClusterInfo clusterName=Cluster01 searchDepth=1 + verbose=0 output=XML" + """ + output = """ + + + + + + """ + return output, None + + def get_volume_info(cliq_args): + """ + input = "getVolumeInfo volumeName=fakevolume output=XML" + """ + output = """ + + + + + """ + return output, None + + def test_error(cliq_args): + output = """ + + """ + return output, None + + self.assertEqual(cliq_args['output'], 'XML') + try: + verbs = {'createVolume': create_volume, + 'deleteVolume': delete_volume, + 'assignVolumeToServer': assign_volume, + 'unassignVolumeToServer': unassign_volume, + 'getClusterInfo': get_cluster_info, + 'getVolumeInfo': get_volume_info, + 'testError': test_error} + except KeyError: + raise NotImplementedError() + + return verbs[verb](cliq_args) + + def test_create_volume(self): + volume = {'name': self.volume_name, 'size': 1} + model_update = self.driver.create_volume(volume) + expected_iqn = "iqn.2003-10.com.lefthandnetworks:group01:25366:fakev" + expected_location = "10.0.1.6:3260,1 %s" % expected_iqn + self.assertEqual(model_update['provider_location'], expected_location) + + def test_delete_volume(self): + volume = {'name': self.volume_name} + self.driver.delete_volume(volume) + + def test_initialize_connection(self): + volume = {'name': self.volume_name} + result = self.driver.initialize_connection(volume, self.connector) + self.assertEqual(result['driver_volume_type'], 'iscsi') + self.assertDictMatch(result['data'], self.properties) + + def test_terminate_connection(self): + volume = {'name': self.volume_name} + self.driver.terminate_connection(volume, self.connector) + + def test_create_snapshot(self): + try: + self.driver.create_snapshot("") + except NotImplementedError: + pass + + def test_create_volume_from_snapshot(self): + try: + self.driver.create_volume_from_snapshot("", "") + except NotImplementedError: + pass + + def test_cliq_error(self): + try: + self.driver._cliq_run_xml("testError", {}) + except exception.Error: + pass -- cgit