Merge "[Lightos] standardize connector usage"

This commit is contained in:
Zuul 2022-02-15 03:46:55 +00:00 committed by Gerrit Code Review
commit 4c86a459dc
2 changed files with 24 additions and 21 deletions

View File

@ -71,19 +71,23 @@ class InitiatorConnectorFactoryMocker:
class InitialConnectorMock:
hostnqn = FAKE_CLIENT_HOSTNQN
nqn = FAKE_CLIENT_HOSTNQN
found_discovery_client = True
def get_hostnqn(self):
return self.__class__.hostnqn
return self.__class__.nqn
def find_dsc(self):
return self.__class__.found_discovery_client
def get_connector_properties(self, root):
return dict(nqn=self.__class__.nqn,
found_dsc=self.__class__.found_discovery_client)
def get_connector_properties():
connector = InitialConnectorMock()
return dict(hostnqn=connector.get_hostnqn(),
return dict(nqn=connector.get_hostnqn(),
found_dsc=connector.find_dsc())
@ -522,7 +526,7 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
db.snapshot_destroy(self.ctxt, snapshot.id)
def test_initialize_connection(self):
InitialConnectorMock.hostnqn = "hostnqn1"
InitialConnectorMock.nqn = "hostnqn1"
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
vol_type = test_utils.create_volume_type(self.ctxt, self,
@ -535,10 +539,8 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
get_connector_properties())
self.assertIn('driver_volume_type', connection_props)
self.assertEqual('lightos', connection_props['driver_volume_type'])
self.assertEqual(FAKE_CLIENT_HOSTNQN,
connection_props['data']['hostnqn'])
self.assertEqual(FAKE_LIGHTOS_CLUSTER_INFO['subsystemNQN'],
connection_props['data']['nqn'])
connection_props['data']['subsysnqn'])
self.assertEqual(
self.db.data['projects']['default']['volumes'][0]['UUID'],
connection_props['data']['uuid'])
@ -547,7 +549,7 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
db.volume_destroy(self.ctxt, volume.id)
def test_initialize_connection_no_hostnqn_should_fail(self):
InitialConnectorMock.hostnqn = ""
InitialConnectorMock.nqn = ""
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
vol_type = test_utils.create_volume_type(self.ctxt, self,
@ -562,7 +564,7 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
db.volume_destroy(self.ctxt, volume.id)
def test_initialize_connection_no_dsc_should_fail(self):
InitialConnectorMock.hostnqn = "hostnqn1"
InitialConnectorMock.nqn = "hostnqn1"
InitialConnectorMock.found_discovery_client = False
self.driver.do_setup(None)
vol_type = test_utils.create_volume_type(self.ctxt, self,
@ -577,7 +579,7 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
db.volume_destroy(self.ctxt, volume.id)
def test_terminate_connection_with_hostnqn(self):
InitialConnectorMock.hostnqn = "hostnqn1"
InitialConnectorMock.nqn = "hostnqn1"
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
vol_type = test_utils.create_volume_type(self.ctxt, self,
@ -590,7 +592,7 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
db.volume_destroy(self.ctxt, volume.id)
def test_terminate_connection_with_empty_hostnqn_should_fail(self):
InitialConnectorMock.hostnqn = ""
InitialConnectorMock.nqn = ""
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
vol_type = test_utils.create_volume_type(self.ctxt, self,
@ -605,7 +607,7 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
db.volume_destroy(self.ctxt, volume.id)
def test_force_terminate_connection_with_empty_hostnqn(self):
InitialConnectorMock.hostnqn = ""
InitialConnectorMock.nqn = ""
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
vol_type = test_utils.create_volume_type(self.ctxt, self,
@ -619,13 +621,13 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
db.volume_destroy(self.ctxt, volume.id)
def test_check_for_setup_error(self):
InitialConnectorMock.hostnqn = "hostnqn1"
InitialConnectorMock.nqn = "hostnqn1"
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
self.driver.check_for_setup_error()
def test_check_for_setup_error_no_subsysnqn_should_fail(self):
InitialConnectorMock.hostnqn = "hostnqn1"
InitialConnectorMock.nqn = "hostnqn1"
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
self.driver.cluster.subsystemNQN = ""
@ -633,14 +635,14 @@ class LightOSStorageVolumeDriverTest(test.TestCase):
self.driver.check_for_setup_error)
def test_check_for_setup_error_no_hostnqn_should_fail(self):
InitialConnectorMock.hostnqn = ""
InitialConnectorMock.nqn = ""
InitialConnectorMock.found_discovery_client = True
self.driver.do_setup(None)
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
def test_check_for_setup_error_no_dsc_should_succeed(self):
InitialConnectorMock.hostnqn = "hostnqn1"
InitialConnectorMock.nqn = "hostnqn1"
InitialConnectorMock.found_discovery_client = False
self.driver.do_setup(None)
self.driver.check_for_setup_error()

View File

@ -814,7 +814,9 @@ class LightOSVolumeDriver(driver.VolumeDriver):
' LightOS cluster subsysnqn')
raise exception.VolumeBackendAPIException(message=msg)
hostnqn = self.connector.get_hostnqn()
hostnqn = (
self.connector.get_connector_properties(
utils.get_root_helper())['nqn'])
if not hostnqn:
msg = ("LIGHTOS: Cinder driver requires a local hostnqn for"
" image_to/from_volume operations")
@ -1009,7 +1011,7 @@ class LightOSVolumeDriver(driver.VolumeDriver):
server_properties['lightos_nodes'] = lightos_targets
server_properties['uuid'] = (
self._get_lightos_uuid(project_name, volume))
server_properties['nqn'] = self.cluster.subsystemNQN
server_properties['subsysnqn'] = self.cluster.subsystemNQN
return server_properties
@ -1386,7 +1388,7 @@ class LightOSVolumeDriver(driver.VolumeDriver):
return False
def initialize_connection(self, volume, connector):
hostnqn = connector.get('hostnqn')
hostnqn = connector.get('nqn')
found_dsc = connector.get('found_dsc')
LOG.debug(
'initialize_connection: connector hostnqn is %s found_dsc %s',
@ -1412,12 +1414,11 @@ class LightOSVolumeDriver(driver.VolumeDriver):
raise exception.VolumeBackendAPIException(message=_(msg))
props = self._get_connection_properties(project_name, volume)
props['hostnqn'] = hostnqn
return {'driver_volume_type': ('lightos'), 'data': props}
def terminate_connection(self, volume, connector, **kwargs):
force = 'force' in kwargs
hostnqn = connector.get('hostnqn') if connector else None
hostnqn = connector.get('nqn') if connector else None
LOG.debug(
'terminate_connection: force %s kwargs %s hostnqn %s',
force,