]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use self.configuration to support the multi-backend case
authorzhangchao010 <zhangchao010@huawei.com>
Fri, 15 Mar 2013 15:14:39 +0000 (23:14 +0800)
committerzhangchao010 <zhangchao010@huawei.com>
Fri, 15 Mar 2013 15:43:50 +0000 (23:43 +0800)
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

cinder/tests/test_huawei.py
cinder/volume/drivers/huawei/huawei_iscsi.py

index fc4d2249e9fdb11ce2aa6aa295617f398e63aff3..a88023c5b26ac6ed05cc01a6ab88d8a756f9609d 100644 (file)
@@ -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()
index 7f0ed0b350acf9164b01e7d764d7c8c118fb05e6..956c2730d1bc6a73a70d3e99d20cd2a21be0d38c 100644 (file)
@@ -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]]