# Copyright (c) 2015 FUJITSU LIMITED
#
#    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 oslo_config import cfg
from oslo_utils import importutils

from cinder import test
import cinder.volume.drivers.fujitsu.eternus_dx_common as eternus_dx_common


CONF = cfg.CONF

FUJITSU_FC_MODULE = ('cinder.volume.drivers.fujitsu.'
                     'eternus_dx_fc.FJDXFCDriver')

FUJITSU_ISCSI_MODULE = ('cinder.volume.drivers.fujitsu.'
                        'eternus_dx_iscsi.FJDXISCSIDriver')


class FJDriverCompatibility(test.TestCase):

    def setUp(self):
        super(FJDriverCompatibility, self).setUp()
        self.manager = importutils.import_object(CONF.volume_manager)

        # Stub definition
        self.stubs.Set(
            eternus_dx_common.FJDXCommon, '__init__', self.fake_init)

    def _load_driver(self, driver):
        self.manager.__init__(volume_driver=driver)

    def _driver_module_name(self):
        


    def fake_init(self, prtcl, configuration=None):
        msg = "selected protocol is %s" % prtcl
        self.assertTrue((prtcl == 'FC') or (prtcl == 'iSCSI'), msg=msg)

    def test_fujitsu_driver_fc_old(self):
        self._load_driver(
            'cinder.volume.drivers.fujitsu_eternus_dx_fc.FJDXFCDriver')
        self.assertEqual(FUJITSU_FC_MODULE, self._driver_module_name())

    def test_fujitsu_driver_fc_new(self):
        self._load_driver(FUJITSU_FC_MODULE)
        self.assertEqual(FUJITSU_FC_MODULE, self._driver_module_name())

    def test_fujitsu_driver_iscsi_old(self):
        self._load_driver(
            'cinder.volume.drivers.fujitsu_eternus_dx_iscsi.FJDXISCSIDriver')
        self.assertEqual(FUJITSU_ISCSI_MODULE, self._driver_module_name())

    def test_fujitsu_driver_iscsi_new(self):
        self._load_driver(FUJITSU_ISCSI_MODULE)
        self.assertEqual(FUJITSU_ISCSI_MODULE, self._driver_module_name())

return "%s.%s" % (self.manager.driver.__class__.__module__,
                          self.manager.driver.__class__.__name__)