Allow overriding the host field

This patch adds the ability to override the host
that is populated into the connector when collecting
information about the initiator.  Nova sometimes overrides
the host depending on it's CONF.host value, so we need to
support that instead of always using the socket.gethostname()

Change-Id: I63ec4f291d9990e8911b696a4030d3ffe377bd6e
This commit is contained in:
Walter A. Boring IV 2015-05-21 16:11:45 +00:00
parent 20b9a0e9e5
commit 3433f5d583
2 changed files with 13 additions and 7 deletions

View File

@ -66,7 +66,8 @@ def _check_multipathd_running(root_helper, enforce_multipath):
return True
def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath):
def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath,
host=None):
"""Get the connection properties for all protocols.
When the connector wants to use multipath, multipath=True should be
@ -83,7 +84,7 @@ def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath):
props = {}
props['ip'] = my_ip
props['host'] = socket.gethostname()
props['host'] = host if host else socket.gethostname()
initiator = iscsi.get_initiator()
if initiator:
props['initiator'] = initiator

View File

@ -13,7 +13,6 @@
# under the License.
import os.path
import socket
import string
import tempfile
import time
@ -41,7 +40,6 @@ MY_IP = '10.0.0.1'
class ConnectorUtilsTestCase(base.TestCase):
@mock.patch.object(socket, 'gethostname', return_value='fakehost')
@mock.patch.object(connector.ISCSIConnector, 'get_initiator',
return_value='fakeinitiator')
@mock.patch.object(linuxfc.LinuxFibreChannel, 'get_fc_wwpns',
@ -52,13 +50,15 @@ class ConnectorUtilsTestCase(base.TestCase):
enforce_multipath,
multipath_result,
mock_wwnns, mock_wwpns,
mock_initiator, mock_gethostname):
mock_initiator,
host='fakehost'):
props_actual = connector.get_connector_properties('sudo',
MY_IP,
multipath,
enforce_multipath)
enforce_multipath,
host=host)
props = {'initiator': 'fakeinitiator',
'host': 'fakehost',
'host': host,
'ip': MY_IP,
'multipath': multipath_result}
self.assertEqual(props, props_actual)
@ -88,6 +88,11 @@ class ConnectorUtilsTestCase(base.TestCase):
self._test_brick_get_connector_properties,
True, True, None)
def test_brick_connector_properties_override_hostname(self):
override_host = 'myhostname'
self._test_brick_get_connector_properties(False, False, False,
host=override_host)
class ConnectorTestCase(base.TestCase):