From 4eba837f611063c95494f3de93cb9853f343896d Mon Sep 17 00:00:00 2001 From: zhangchao010 Date: Fri, 15 Mar 2013 23:14:39 +0800 Subject: [PATCH] Use self.configuration to support the multi-backend case Use self.configuration instead of using FLAGS directly to make the driver work in a multi backend environment. And remove three repeated lines:en = out.split('\r\n') Fixes bug: 1154125 Change-Id: I6e08706104eabb71677ec8583b9abb9711553504 (cherry picked from commit 7817d12439a4c86d3015ce8e6a74f72804fdfd24) --- cinder/tests/test_huawei.py | 3 ++- cinder/volume/drivers/huawei/huawei_iscsi.py | 10 ++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cinder/tests/test_huawei.py b/cinder/tests/test_huawei.py index fc4d2249e..a88023c5b 100644 --- a/cinder/tests/test_huawei.py +++ b/cinder/tests/test_huawei.py @@ -23,6 +23,7 @@ from xml.etree import ElementTree as ET from cinder import exception from cinder.openstack.common import log as logging from cinder import test +from cinder.volume import configuration as conf from cinder.volume.drivers.huawei import huawei_iscsi LOG = logging.getLogger(__name__) @@ -184,7 +185,7 @@ class HuaweiVolumeTestCase(test.TestCase): def __init__(self, *args, **kwargs): super(HuaweiVolumeTestCase, self).__init__(*args, **kwargs) - self.driver = FakeHuaweiStorage() + self.driver = FakeHuaweiStorage(configuration=conf.Configuration(None)) self.driver.do_setup({}) self.driver._test_flg = 'check_for_fail' self._test_check_for_setup_errors() diff --git a/cinder/volume/drivers/huawei/huawei_iscsi.py b/cinder/volume/drivers/huawei/huawei_iscsi.py index 7f0ed0b35..956c2730d 100644 --- a/cinder/volume/drivers/huawei/huawei_iscsi.py +++ b/cinder/volume/drivers/huawei/huawei_iscsi.py @@ -26,7 +26,6 @@ from oslo.config import cfg from xml.etree import ElementTree as ET from cinder import exception -from cinder import flags from cinder.openstack.common import excutils from cinder.openstack.common import log as logging from cinder import utils @@ -39,9 +38,6 @@ huawei_opt = [ default='/etc/cinder/cinder_huawei_conf.xml', help='config data for cinder huawei plugin')] -FLAGS = flags.FLAGS -FLAGS.register_opts(huawei_opt) - HOST_GROUP_NAME = 'HostGroup_OpenStack' HOST_NAME_PREFIX = 'Host_' HOST_PORT_PREFIX = 'HostPort_' @@ -107,6 +103,7 @@ class HuaweiISCSIDriver(driver.ISCSIDriver): def __init__(self, *args, **kwargs): super(HuaweiISCSIDriver, self).__init__(*args, **kwargs) + self.configuration.append_config_values(huawei_opt) self.device_type = {} self.login_info = {} self.hostgroup_id = None @@ -542,7 +539,7 @@ class HuaweiISCSIDriver(driver.ISCSIDriver): def _read_xml(self): """Open xml file.""" - filename = FLAGS.cinder_huawei_conf_file + filename = self.configuration.cinder_huawei_conf_file try: tree = ET.parse(filename) root = tree.getroot() @@ -875,7 +872,6 @@ class HuaweiISCSIDriver(driver.ISCSIDriver): if len(en) < 6: return None - en = out.split('\r\n') for i in range(6, len(en) - 2): r = en[i].split() if r[1] == hostname: @@ -894,7 +890,6 @@ class HuaweiISCSIDriver(driver.ISCSIDriver): hostportinfo = [] list_key = ['id', 'name', 'info', 'type', 'hostid', 'linkstatus', 'multioathtype'] - en = out.split('\r\n') for i in range(6, len(en) - 2): list_val = en[i].split() hostport_dic = dict(map(None, list_key, list_val)) @@ -1087,7 +1082,6 @@ class HuaweiISCSIDriver(driver.ISCSIDriver): mapinfo = [] list_tmp = [] list_key = ['mapid', 'devlunid', 'hostlunid'] - en = out.split('\r\n') for i in range(6, len(en) - 2): list_tmp = en[i].split() list_val = [list_tmp[0], list_tmp[2], list_tmp[4]] -- 2.45.2