from cinder.exception import VolumeBackendAPIException
from cinder.openstack.common import log as logging
from cinder import test
+from cinder.volume import configuration as conf
from cinder.volume.drivers.netapp import iscsi
+from cinder.volume.drivers.netapp.iscsi import netapp_opts
LOG = logging.getLogger("cinder.volume.driver")
iter_table = {}
+def create_configuration():
+ configuration = conf.Configuration(None)
+ configuration.append_config_values(netapp_opts)
+ return configuration
+
+
class FakeDfmServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""HTTP handler that fakes enough stuff to allow the driver to run."""
super(NetAppDriverTestCase, self).setUp()
self.tempdir = tempfile.mkdtemp()
self.flags(lock_path=self.tempdir)
- driver = iscsi.NetAppISCSIDriver()
+ driver = iscsi.NetAppISCSIDriver(configuration=create_configuration())
self.stubs.Set(httplib, 'HTTPConnection', FakeHTTPConnection)
driver._create_client(wsdl_url='http://localhost:8088/dfm.wsdl',
login='root', password='password',
self._custom_setup()
def _custom_setup(self):
- driver = iscsi.NetAppCmodeISCSIDriver()
+ driver = iscsi.NetAppCmodeISCSIDriver(
+ configuration=create_configuration())
self.stubs.Set(httplib, 'HTTPConnection', FakeCmodeHTTPConnection)
driver._create_client(wsdl_url='http://localhost:8080/ntap_cloud.wsdl',
login='root', password='password',
super(NetAppDirectCmodeISCSIDriverTestCase, self).setUp()
def _custom_setup(self):
- driver = iscsi.NetAppDirectCmodeISCSIDriver()
+ driver = iscsi.NetAppDirectCmodeISCSIDriver(
+ configuration=create_configuration())
self.stubs.Set(httplib, 'HTTPConnection',
FakeDirectCmodeHTTPConnection)
driver._create_client(transport_type='http',
super(NetAppDirect7modeISCSIDriverTestCase_NV, self).setUp()
def _custom_setup(self):
- driver = iscsi.NetAppDirect7modeISCSIDriver()
+ driver = iscsi.NetAppDirect7modeISCSIDriver(
+ configuration=create_configuration())
self.stubs.Set(httplib,
'HTTPConnection', FakeDirect7modeHTTPConnection)
driver._create_client(transport_type='http',
super(NetAppDirect7modeISCSIDriverTestCase_WV, self).setUp()
def _custom_setup(self):
- driver = iscsi.NetAppDirect7modeISCSIDriver()
+ driver = iscsi.NetAppDirect7modeISCSIDriver(
+ configuration=create_configuration())
self.stubs.Set(httplib, 'HTTPConnection',
FakeDirect7modeHTTPConnection)
driver._create_client(transport_type='http',
from cinder.volume import configuration as conf
from cinder.volume.drivers.netapp import api
-from cinder.volume.drivers.netapp import iscsi
from cinder.volume.drivers.netapp import nfs as netapp_nfs
from cinder.volume.drivers import nfs
from lxml import etree
def setUp(self):
self._mox = mox.Mox()
self._driver = netapp_nfs.NetAppNFSDriver(
- configuration=create_configuration())
+ configuration=create_configuration())
def tearDown(self):
self._mox.UnsetStubs()
'netapp_server_hostname',
'netapp_server_port']
+ # set required flags
+ for flag in required_flags:
+ setattr(drv.configuration, flag, None)
+
# check exception raises when flags are not set
self.assertRaises(exception.CinderException,
drv.check_for_setup_error)
# set required flags
for flag in required_flags:
- setattr(iscsi.FLAGS, flag, 'val')
+ setattr(drv.configuration, flag, 'val')
mox.StubOutWithMock(nfs.NfsDriver, 'check_for_setup_error')
nfs.NfsDriver.check_for_setup_error()
# restore initial FLAGS
for flag in required_flags:
- delattr(iscsi.FLAGS, flag)
+ delattr(drv.configuration, flag)
def test_do_setup(self):
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, 'check_for_setup_error')
- mox.StubOutWithMock(netapp_nfs.NetAppNFSDriver, '_get_client')
+ mox.StubOutWithMock(drv, '_get_client')
drv.check_for_setup_error()
- netapp_nfs.NetAppNFSDriver._get_client()
+ drv._get_client()
mox.ReplayAll()
def test_successfull_clone_volume(self):
drv = self._driver
mox = self._prepare_clone_mock('passed')
-
+ # set required flags
+ setattr(drv.configuration, 'synchronous_snapshot_create', False)
mox.ReplayAll()
volume_name = 'volume_name'
def _custom_setup(self):
self._driver = netapp_nfs.NetAppCmodeNfsDriver(
- configuration=create_configuration())
+ configuration=create_configuration())
def tearDown(self):
self._mox.UnsetStubs()
'netapp_server_hostname',
'netapp_server_port']
+ # set required flags
+ for flag in required_flags:
+ setattr(drv.configuration, flag, None)
# check exception raises when flags are not set
self.assertRaises(exception.CinderException,
drv.check_for_setup_error)
# set required flags
for flag in required_flags:
- setattr(iscsi.FLAGS, flag, 'val')
+ setattr(drv.configuration, flag, 'val')
mox.ReplayAll()
# restore initial FLAGS
for flag in required_flags:
- delattr(iscsi.FLAGS, flag)
+ delattr(drv.configuration, flag)
def test_do_setup(self):
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, 'check_for_setup_error')
- mox.StubOutWithMock(netapp_nfs.NetAppCmodeNfsDriver, '_get_client')
+ mox.StubOutWithMock(drv, '_get_client')
drv.check_for_setup_error()
- netapp_nfs.NetAppCmodeNfsDriver._get_client()
+ drv._get_client()
mox.ReplayAll()
"""Test direct NetApp C Mode driver"""
def _custom_setup(self):
self._driver = netapp_nfs.NetAppDirectCmodeNfsDriver(
- configuration=create_configuration())
+ configuration=create_configuration())
def test_check_for_setup_error(self):
mox = self._mox
'netapp_server_hostname',
'netapp_server_port']
+ # set required flags
+ for flag in required_flags:
+ setattr(drv.configuration, flag, None)
# check exception raises when flags are not set
self.assertRaises(exception.CinderException,
drv.check_for_setup_error)
# set required flags
for flag in required_flags:
- setattr(iscsi.FLAGS, flag, 'val')
+ setattr(drv.configuration, flag, 'val')
mox.ReplayAll()
# restore initial FLAGS
for flag in required_flags:
- delattr(iscsi.FLAGS, flag)
+ delattr(drv.configuration, flag)
def test_do_setup(self):
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, 'check_for_setup_error')
- mox.StubOutWithMock(netapp_nfs.NetAppDirectCmodeNfsDriver,
- '_get_client')
+ mox.StubOutWithMock(drv, '_get_client')
mox.StubOutWithMock(drv, '_do_custom_setup')
drv.check_for_setup_error()
- netapp_nfs.NetAppDirectNfsDriver._get_client()
+ drv._get_client()
drv._do_custom_setup(IgnoreArg())
mox.ReplayAll()
"""Test direct NetApp C Mode driver"""
def _custom_setup(self):
self._driver = netapp_nfs.NetAppDirect7modeNfsDriver(
- configuration=create_configuration())
+ configuration=create_configuration())
def test_check_for_setup_error(self):
mox = self._mox
'netapp_server_hostname',
'netapp_server_port']
+ # set required flags
+ for flag in required_flags:
+ setattr(drv.configuration, flag, None)
# check exception raises when flags are not set
self.assertRaises(exception.CinderException,
drv.check_for_setup_error)
# set required flags
for flag in required_flags:
- setattr(iscsi.FLAGS, flag, 'val')
+ setattr(drv.configuration, flag, 'val')
mox.ReplayAll()
# restore initial FLAGS
for flag in required_flags:
- delattr(iscsi.FLAGS, flag)
+ delattr(drv.configuration, flag)
def test_do_setup(self):
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, 'check_for_setup_error')
- mox.StubOutWithMock(netapp_nfs.NetAppDirect7modeNfsDriver,
- '_get_client')
+ mox.StubOutWithMock(drv, '_get_client')
mox.StubOutWithMock(drv, '_do_custom_setup')
drv.check_for_setup_error()
- netapp_nfs.NetAppDirectNfsDriver._get_client()
+ drv._get_client()
drv._do_custom_setup(IgnoreArg())
mox.ReplayAll()
from suds.sax import text
from cinder import exception
-from cinder import flags
from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
from cinder.volume import driver
help='Comma separated eligible volumes for provisioning on'
' 7 mode'), ]
-FLAGS = flags.FLAGS
-FLAGS.register_opts(netapp_opts)
-
class DfmDataset(object):
def __init__(self, id, name, project, type):
def __init__(self, *args, **kwargs):
super(NetAppISCSIDriver, self).__init__(*args, **kwargs)
+ self.configuration.append_config_values(netapp_opts)
self.discovered_luns = []
self.discovered_datasets = []
self.lun_table = {}
required_flags = ['netapp_wsdl_url', 'netapp_login', 'netapp_password',
'netapp_server_hostname', 'netapp_server_port']
for flag in required_flags:
- if not getattr(FLAGS, flag, None):
+ if not getattr(self.configuration, flag, None):
raise exception.InvalidInput(reason=_('%s is not set') % flag)
- if not (FLAGS.netapp_storage_service or
- FLAGS.netapp_storage_service_prefix):
+ if not (self.configuration.netapp_storage_service or
+ self.configuration.netapp_storage_service_prefix):
raise exception.InvalidInput(
reason=_('Either '
'netapp_storage_service or '
"""
self._check_flags()
self._create_client(
- wsdl_url=FLAGS.netapp_wsdl_url,
- login=FLAGS.netapp_login, password=FLAGS.netapp_password,
- hostname=FLAGS.netapp_server_hostname,
- port=FLAGS.netapp_server_port, cache=True)
- self._set_storage_service(FLAGS.netapp_storage_service)
- self._set_storage_service_prefix(FLAGS.netapp_storage_service_prefix)
- self._set_vfiler(FLAGS.netapp_vfiler)
+ wsdl_url=self.configuration.netapp_wsdl_url,
+ login=self.configuration.netapp_login,
+ password=self.configuration.netapp_password,
+ hostname=self.configuration.netapp_server_hostname,
+ port=self.configuration.netapp_server_port, cache=True)
+ self._set_storage_service(self.configuration.netapp_storage_service)
+ self._set_storage_service_prefix(
+ self.configuration.netapp_storage_service_prefix)
+ self._set_vfiler(self.configuration.netapp_vfiler)
def check_for_setup_error(self):
"""Check that the driver is working and can communicate.
def __init__(self, *args, **kwargs):
super(NetAppCmodeISCSIDriver, self).__init__(*args, **kwargs)
+ self.configuration.append_config_values(netapp_opts)
self.lun_table = {}
def _create_client(self, **kwargs):
required_flags = ['netapp_wsdl_url', 'netapp_login', 'netapp_password',
'netapp_server_hostname', 'netapp_server_port']
for flag in required_flags:
- if not getattr(FLAGS, flag, None):
+ if not getattr(self.configuration, flag, None):
msg = _('%s is not set') % flag
raise exception.InvalidInput(data=msg)
"""
self._check_flags()
self._create_client(
- wsdl_url=FLAGS.netapp_wsdl_url,
- login=FLAGS.netapp_login, password=FLAGS.netapp_password,
- hostname=FLAGS.netapp_server_hostname,
- port=FLAGS.netapp_server_port, cache=True)
+ wsdl_url=self.configuration.netapp_wsdl_url,
+ login=self.configuration.netapp_login,
+ password=self.configuration.netapp_password,
+ hostname=self.configuration.netapp_server_hostname,
+ port=self.configuration.netapp_server_port, cache=True)
def check_for_setup_error(self):
"""Check that the driver is working and can communicate.
def __init__(self, *args, **kwargs):
super(NetAppDirectISCSIDriver, self).__init__(*args, **kwargs)
+ self.configuration.append_config_values(netapp_opts)
self.lun_table = {}
def _create_client(self, **kwargs):
"""Ensure that the flags we care about are set."""
required_flags = self.required_flags
for flag in required_flags:
- if not getattr(FLAGS, flag, None):
+ if not getattr(self.configuration, flag, None):
msg = _('%s is not set') % flag
raise exception.InvalidInput(data=msg)
"""
self._check_flags()
self._create_client(
- transport_type=FLAGS.netapp_transport_type,
- login=FLAGS.netapp_login, password=FLAGS.netapp_password,
- hostname=FLAGS.netapp_server_hostname,
- port=FLAGS.netapp_server_port)
+ transport_type=self.configuration.netapp_transport_type,
+ login=self.configuration.netapp_login,
+ password=self.configuration.netapp_password,
+ hostname=self.configuration.netapp_server_hostname,
+ port=self.configuration.netapp_server_port)
self._do_custom_setup()
def check_for_setup_error(self):
def _create_lun_on_eligible_vol(self, name, size, metadata):
"""Creates an actual lun on filer."""
- req_size = float(size) * float(FLAGS.netapp_size_multiplier)
+ req_size = float(size) *\
+ float(self.configuration.netapp_size_multiplier)
volume = self._get_avl_volume_by_size(req_size)
if not volume:
msg = _('Failed to get vol with required size for volume: %s')
def _do_custom_setup(self):
"""Does custom setup for ontap cluster."""
- self.vserver = FLAGS.netapp_vserver
+ self.vserver = self.configuration.netapp_vserver
# Default values to run first api
self.client.set_api_version(1, 15)
(major, minor) = self._get_ontapi_version()
def _do_custom_setup(self):
"""Does custom setup depending on the type of filer."""
- self.vfiler = FLAGS.netapp_vfiler
- self.volume_list = FLAGS.netapp_volume_list
+ self.vfiler = self.configuration.netapp_vfiler
+ self.volume_list = self.configuration.netapp_volume_list
if self.volume_list:
self.volume_list = self.volume_list.split(',')
self.volume_list = [el.strip() for el in self.volume_list]
def _create_lun_handle(self, metadata):
"""Returns lun handle based on filer type."""
if self.vfiler:
- owner = '%s:%s' % (FLAGS.netapp_server_hostname, self.vfiler)
+ owner = '%s:%s' % (self.configuration.netapp_server_hostname,
+ self.vfiler)
else:
- owner = FLAGS.netapp_server_hostname
+ owner = self.configuration.netapp_server_hostname
return '%s:%s' % (owner, metadata['Path'])
def _get_lun_list(self):
from suds.sax import text
from cinder import exception
-from cinder import flags
from cinder.openstack.common import log as logging
from cinder.volume.drivers.netapp.api import NaApiError
from cinder.volume.drivers.netapp.api import NaElement
default=0,
help='Does snapshot creation call returns immediately')]
-FLAGS = flags.FLAGS
-FLAGS.register_opts(netapp_opts)
-FLAGS.register_opts(netapp_nfs_opts)
-
class NetAppNFSDriver(nfs.NfsDriver):
"""Executes commands relating to Volumes."""
self._execute = None
self._context = None
super(NetAppNFSDriver, self).__init__(*args, **kwargs)
+ self.configuration.append_config_values(netapp_opts)
+ self.configuration.append_config_values(netapp_nfs_opts)
def set_execute(self, execute):
self._execute = execute
def do_setup(self, context):
self._context = context
self.check_for_setup_error()
- self._client = NetAppNFSDriver._get_client()
+ self._client = self._get_client()
def check_for_setup_error(self):
"""Returns an error if prerequisites aren't met"""
- NetAppNFSDriver._check_dfm_flags()
+ self._check_dfm_flags()
super(NetAppNFSDriver, self).check_for_setup_error()
def create_volume_from_snapshot(self, volume, snapshot):
self._execute('rm', self._get_volume_path(nfs_mount, snapshot.name),
run_as_root=True)
- @staticmethod
- def _check_dfm_flags():
+ def _check_dfm_flags(self):
"""Raises error if any required configuration flag for OnCommand proxy
is missing."""
required_flags = ['netapp_wsdl_url',
'netapp_server_hostname',
'netapp_server_port']
for flag in required_flags:
- if not getattr(FLAGS, flag, None):
+ if not getattr(self.configuration, flag, None):
raise exception.CinderException(_('%s is not set') % flag)
- @staticmethod
- def _get_client():
+ def _get_client(self):
"""Creates SOAP _client for ONTAP-7 DataFabric Service."""
- client = suds.client.Client(FLAGS.netapp_wsdl_url,
- username=FLAGS.netapp_login,
- password=FLAGS.netapp_password)
- soap_url = 'http://%s:%s/apis/soap/v1' % (FLAGS.netapp_server_hostname,
- FLAGS.netapp_server_port)
+ client = suds.client.Client(
+ self.configuration.netapp_wsdl_url,
+ username=self.configuration.netapp_login,
+ password=self.configuration.netapp_password)
+ soap_url = 'http://%s:%s/apis/soap/v1' % (
+ self.configuration.netapp_server_hostname,
+ self.configuration.netapp_server_port)
client.set_options(location=soap_url)
return client
resp = self._client.service.ApiProxy(Target=host_id,
Request=request)
- if resp.Status == 'passed' and FLAGS.synchronous_snapshot_create:
+ if (resp.Status == 'passed' and
+ self.configuration.synchronous_snapshot_create):
clone_id = resp.Results['clone-id'][0]
clone_id_info = clone_id['clone-id-info'][0]
clone_operation_id = int(clone_id_info['clone-op-id'][0])
return True
except exception.ProcessExecutionError:
tries = tries + 1
- if tries >= FLAGS.num_shell_tries:
+ if tries >= self.configuration.num_shell_tries:
raise
LOG.exception(_("Recovering from a failed execute. "
"Try number %s"), tries)
def do_setup(self, context):
self._context = context
self.check_for_setup_error()
- self._client = NetAppCmodeNfsDriver._get_client()
+ self._client = self._get_client()
def check_for_setup_error(self):
"""Returns an error if prerequisites aren't met"""
- NetAppCmodeNfsDriver._check_flags()
+ self._check_flags()
def _clone_volume(self, volume_name, clone_name, volume_id):
"""Clones mounted volume with NetApp Cloud Services"""
self._client.service.CloneNasFile(host_ip, export_path,
volume_name, clone_name)
- @staticmethod
- def _check_flags():
+ def _check_flags(self):
"""Raises error if any required configuration flag for NetApp Cloud
Webservices is missing."""
required_flags = ['netapp_wsdl_url',
'netapp_server_hostname',
'netapp_server_port']
for flag in required_flags:
- if not getattr(FLAGS, flag, None):
+ if not getattr(self.configuration, flag, None):
raise exception.CinderException(_('%s is not set') % flag)
- @staticmethod
- def _get_client():
+ def _get_client(self):
"""Creates SOAP _client for NetApp Cloud service."""
- client = suds.client.Client(FLAGS.netapp_wsdl_url,
- username=FLAGS.netapp_login,
- password=FLAGS.netapp_password)
+ client = suds.client.Client(
+ self.configuration.netapp_wsdl_url,
+ username=self.configuration.netapp_login,
+ password=self.configuration.netapp_password)
return client
def get_volume_stats(self, refresh=False):
def do_setup(self, context):
self._context = context
self.check_for_setup_error()
- self._client = NetAppDirectNfsDriver._get_client()
+ self._client = self._get_client()
self._do_custom_setup(self._client)
def check_for_setup_error(self):
"""Returns an error if prerequisites aren't met"""
- NetAppDirectNfsDriver._check_flags()
+ self._check_flags()
def _clone_volume(self, volume_name, clone_name, volume_id):
"""Clones mounted volume on NetApp filer"""
raise NotImplementedError()
- @staticmethod
- def _check_flags():
+ def _check_flags(self):
"""Raises error if any required configuration flag for NetApp
filer is missing."""
required_flags = ['netapp_login',
'netapp_server_port',
'netapp_transport_type']
for flag in required_flags:
- if not getattr(FLAGS, flag, None):
+ if not getattr(self.configuration, flag, None):
raise exception.CinderException(_('%s is not set') % flag)
- @staticmethod
- def _get_client():
+ def _get_client(self):
"""Creates NetApp api client."""
- client = NaServer(host=FLAGS.netapp_server_hostname,
- server_type=NaServer.SERVER_TYPE_FILER,
- transport_type=FLAGS.netapp_transport_type,
- style=NaServer.STYLE_LOGIN_PASSWORD,
- username=FLAGS.netapp_login,
- password=FLAGS.netapp_password)
+ client = NaServer(
+ host=self.configuration.netapp_server_hostname,
+ server_type=NaServer.SERVER_TYPE_FILER,
+ transport_type=self.configuration.netapp_transport_type,
+ style=NaServer.STYLE_LOGIN_PASSWORD,
+ username=self.configuration.netapp_login,
+ password=self.configuration.netapp_password)
return client
def _do_custom_setup(self, client):