HNAS driver: Fix SSH and cluster_admin_ip0 bug

HNAS driver has 2 configuration options:
- SSC (ssh_enabled: False ): requires a local utility package
installed to run the commands
- SSH (ssh_enabled: True): Runs the commands using the utility
package installed on HNAS

Currently, the HNAS driver is considering the "ssh_enabled" and the
"cluster_admin_ip0" tags to decide if the command to get the utility
package version should be ran locally or not. This is not correct
because the "cluster_admin_ip0" tag is not mandatory even if the SSH
mode is enabled.
So, if we have a situation that SSH is enabled and the
"cluster_admin_ip0" does not exist in the configuration, the driver
tries to run the command to get the utility package version locally
and its initialization breaks.
This patch makes the driver consider only the "ssh_enabled" tag
value to decide if the command to get the utility package version
is necessary.

Change-Id: I29fb5d7199e10eafee329dbd4ccef524245fbc28
Closes-Bug: 1543208
This commit is contained in:
Adriano Rosso 2016-02-05 15:41:01 -02:00
parent 04b2cdf9b5
commit 4f39141e32
2 changed files with 39 additions and 15 deletions

View File

@ -355,14 +355,15 @@ class HDSHNASBendTest(test.TestCase):
return_value=(HNAS_RESULT5, ''))
@mock.patch.object(utils, 'execute')
@mock.patch.object(time, 'sleep')
def test_run_cmd(self, m_sleep, m_utl, m_ssh, m_ssh_cli,
m_pvt_key, m_file, m_open):
def test_run_cmd(self, m_sleep, m_utl, m_ssh, m_ssh_cli, m_pvt_key,
m_file, m_open):
save_hkey_file = CONF.ssh_hosts_key_file
save_spath = CONF.state_path
CONF.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
CONF.state_path = '/var/lib/cinder'
# Test main flow
self.hnas_bend.drv_configs['ssh_enabled'] = 'True'
out, err = self.hnas_bend.run_cmd('ssh', '0.0.0.0',
'supervisor', 'supervisor',
'df', '-a')
@ -407,6 +408,27 @@ class HDSHNASBendTest(test.TestCase):
self.assertIn('11.2.3319.14', out)
self.assertIn('83-68-96-AA-DA-5D', out)
@mock.patch.object(hnas_backend.HnasBackend, 'run_cmd',
side_effect=m_run_cmd)
def test_get_version_ssh_cluster(self, m_cmd):
self.hnas_bend.drv_configs['ssh_enabled'] = 'True'
self.hnas_bend.drv_configs['cluster_admin_ip0'] = '1.1.1.1'
out = self.hnas_bend.get_version("ssh", "1.0", "0.0.0.0", "supervisor",
"supervisor")
self.assertIn('11.2.3319.14', out)
self.assertIn('83-68-96-AA-DA-5D', out)
@mock.patch.object(hnas_backend.HnasBackend, 'run_cmd',
side_effect=m_run_cmd)
@mock.patch.object(utils, 'execute', return_value=UTILS_EXEC_OUT)
def test_get_version_ssh_disable(self, m_cmd, m_exec):
self.hnas_bend.drv_configs['ssh_enabled'] = 'False'
out = self.hnas_bend.get_version("ssh", "1.0", "0.0.0.0", "supervisor",
"supervisor")
self.assertIn('11.2.3319.14', out)
self.assertIn('83-68-96-AA-DA-5D', out)
self.assertIn('Utility_version', out)
@mock.patch.object(hnas_backend.HnasBackend, 'run_cmd',
side_effect=m_run_cmd)
def test_get_iscsi_info(self, m_execute):

View File

@ -74,7 +74,6 @@ class HnasBackend(object):
raise exception.HNASConnError(msg)
else:
raise
else:
if self.drv_configs['cluster_admin_ip0'] is None:
# Connect to SMU through SSH and run ssc locally
@ -126,20 +125,12 @@ class HnasBackend(object):
:param ip0: string IP address of controller
:param user: string user authentication for array
:param pw: string password authentication for array
:returns: formated string with version information
:returns: formatted string with version information
"""
if (self.drv_configs['ssh_enabled'] == 'True' and
self.drv_configs['cluster_admin_ip0'] is not None):
util = 'SMU ' + cmd
else:
out, err = utils.execute(cmd,
"-version",
check_exit_code=True)
util = out.split()[1]
out, err = self.run_cmd(cmd, ip0, user, pw, "cluster-getmac",
check_exit_code=True)
hardware = out.split()[2]
out, err = self.run_cmd(cmd, ip0, user, pw, "ver",
check_exit_code=True)
lines = out.split('\n')
@ -151,8 +142,19 @@ class HnasBackend(object):
if 'Software:' in line:
ver = line.split()[1]
out = "Array_ID: %s (%s) version: %s LU: 256 RG: 0 RG_LU: 0 \
Utility_version: %s" % (hardware, model, ver, util)
# If not using SSH, the local utility version can be different from the
# one used in HNAS
if self.drv_configs['ssh_enabled'] != 'True':
out, err = utils.execute(cmd, "-version", check_exit_code=True)
util = out.split()[1]
out = ("Array_ID: %(arr)s (%(mod)s) version: %(ver)s LU: 256 "
"RG: 0 RG_LU: 0 Utility_version: %(util)s" %
{'arr': hardware, 'mod': model, 'ver': ver, 'util': util})
else:
out = ("Array_ID: %(arr)s (%(mod)s) version: %(ver)s LU: 256 "
"RG: 0 RG_LU: 0" %
{'arr': hardware, 'mod': model, 'ver': ver})
LOG.debug('get_version: %(out)s -- %(err)s', {'out': out, 'err': err})
return out