"""
import os
+from StringIO import StringIO
import tempfile
import mock
+from cinder import exception
from cinder.openstack.common import log as logging
from cinder import test
from cinder.volume import configuration as conf
</config>
"""
+HNAS_WRONG_CONF1 = """<?xml version="1.0" encoding="UTF-8" ?>
+<config>
+ <hnas_cmd>ssc</hnas_cmd>
+ <mgmt_ip0>172.17.44.15</mgmt_ip0>
+ <username>supervisor</username>
+ <password>supervisor</password>
+ <volume_type>default</volume_type>
+ <hdp>172.17.39.132:/cinder</hdp>
+ </svc_0>
+</config>
+"""
+
+HNAS_WRONG_CONF2 = """<?xml version="1.0" encoding="UTF-8" ?>
+<config>
+ <hnas_cmd>ssc</hnas_cmd>
+ <mgmt_ip0>172.17.44.15</mgmt_ip0>
+ <username>supervisor</username>
+ <password>supervisor</password>
+ <svc_0>
+ <volume_type>default</volume_type>
+ </svc_0>
+ <svc_1>
+ <volume_type>silver</volume_type>
+ </svc_1>
+</config>
+"""
+
# The following information is passed on to tests, when creating a volume
_VOLUME = {'name': 'testvol', 'volume_id': '1234567890', 'size': 128,
'volume_type': None, 'provider_location': None, 'id': 'abcdefg'}
vol['provider_location'] = loc['provider_location']
return vol
+ @mock.patch('__builtin__.open')
+ @mock.patch.object(os, 'access')
+ def test_read_config(self, m_access, m_open):
+ # Test exception when file is not found
+ m_access.return_value = False
+ m_open.return_value = StringIO(HNASCONF)
+ self.assertRaises(exception.NotFound, iscsi._read_config, '')
+
+ # Test exception when config file has parsing errors
+ # due to missing <svc> tag
+ m_access.return_value = True
+ m_open.return_value = StringIO(HNAS_WRONG_CONF1)
+ self.assertRaises(exception.ConfigNotFound, iscsi._read_config, '')
+
+ # Test exception when config file has parsing errors
+ # due to missing <hdp> tag
+ m_open.return_value = StringIO(HNAS_WRONG_CONF2)
+ self.configuration.hds_hnas_iscsi_config_file = ''
+ self.assertRaises(exception.ParameterNotFound, iscsi._read_config, '')
+
def test_create_volume(self):
loc = self.driver.create_volume(_VOLUME)
self.assertNotEqual(loc, None)
#
import os
+from StringIO import StringIO
import tempfile
import mock
+from cinder import exception
from cinder.openstack.common import log as logging
from cinder import test
from cinder.volume import configuration as conf
</config>
"""
+HNAS_WRONG_CONF1 = """<?xml version="1.0" encoding="UTF-8" ?>
+<config>
+ <hnas_cmd>ssc</hnas_cmd>
+ <mgmt_ip0>172.17.44.15</mgmt_ip0>
+ <username>supervisor</username>
+ <password>supervisor</password>
+ <volume_type>default</volume_type>
+ <hdp>172.17.39.132:/cinder</hdp>
+ </svc_0>
+</config>
+"""
+
+HNAS_WRONG_CONF2 = """<?xml version="1.0" encoding="UTF-8" ?>
+<config>
+ <hnas_cmd>ssc</hnas_cmd>
+ <mgmt_ip0>172.17.44.15</mgmt_ip0>
+ <username>supervisor</username>
+ <password>supervisor</password>
+ <svc_0>
+ <volume_type>default</volume_type>
+ </svc_0>
+ <svc_1>
+ <volume_type>silver</volume_type>
+ </svc_1>
+</config>
+"""
+
# The following information is passed on to tests, when creating a volume
_SHARE = '172.17.39.132:/cinder'
_EXPORT = '/cinder'
os.remove(self.config_file)
os.remove(self.shares_file)
+ @mock.patch('__builtin__.open')
+ @mock.patch.object(os, 'access')
+ def test_read_config(self, m_access, m_open):
+ # Test exception when file is not found
+ m_access.return_value = False
+ m_open.return_value = StringIO(HNASCONF)
+ self.assertRaises(exception.NotFound, nfs._read_config, '')
+
+ # Test exception when config file has parsing errors
+ # due to missing <svc> tag
+ m_access.return_value = True
+ m_open.return_value = StringIO(HNAS_WRONG_CONF1)
+ self.assertRaises(exception.ConfigNotFound, nfs._read_config, '')
+
+ # Test exception when config file has parsing errors
+ # due to missing <hdp> tag
+ m_open.return_value = StringIO(HNAS_WRONG_CONF2)
+ self.configuration.hds_hnas_iscsi_config_file = ''
+ self.assertRaises(exception.ParameterNotFound, nfs._read_config, '')
+
@mock.patch.object(nfs.HDSNFSDriver, '_id_to_vol')
@mock.patch.object(nfs.HDSNFSDriver, '_get_provider_location')
@mock.patch.object(nfs.HDSNFSDriver, '_get_export_path')
from oslo_utils import units
from cinder import exception
-from cinder.i18n import _LE, _LI, _LW
+from cinder.i18n import _, _LE, _LI, _LW
from cinder.openstack.common import log as logging
from cinder.volume import driver
from cinder.volume.drivers.hds.hnas_backend import HnasBackend
"""Read hds driver specific xml config file."""
if not os.access(xml_config_file, os.R_OK):
- raise exception.NotFound(_LE("Can't open config file: %s"),
- xml_config_file)
+ msg = (_("Can't open config file: %s") % xml_config_file)
+ raise exception.NotFound(message=msg)
try:
root = ETree.parse(xml_config_file).getroot()
except Exception:
- raise exception.ConfigNotFound(_LE("Error parsing config file: %s"),
- xml_config_file)
+ msg = (_("Error parsing config file: %s") % xml_config_file)
+ raise exception.ConfigNotFound(message=msg)
# mandatory parameters
config = {}
"""
if not os.access(xml_config_file, os.R_OK):
- raise exception.NotFound(_LE("Can't open config file: %s"),
- xml_config_file)
+ msg = (_("Can't open config file: %s") % xml_config_file)
+ raise exception.NotFound(message=msg)
try:
root = ETree.parse(xml_config_file).getroot()
except Exception:
- raise exception.ConfigNotFound(_LE("Error parsing config file: %s"),
- xml_config_file)
+ msg = (_("Error parsing config file: %s") % xml_config_file)
+ raise exception.ConfigNotFound(message=msg)
# mandatory parameters
config = {}