diff --git a/cinder/tests/unit/test_hitachi_hnas_backend.py b/cinder/tests/unit/test_hitachi_hnas_backend.py index fe2872653a9..d34d1e03c7c 100644 --- a/cinder/tests/unit/test_hitachi_hnas_backend.py +++ b/cinder/tests/unit/test_hitachi_hnas_backend.py @@ -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): diff --git a/cinder/volume/drivers/hitachi/hnas_backend.py b/cinder/volume/drivers/hitachi/hnas_backend.py index a72dff9418c..36506aaf04f 100644 --- a/cinder/volume/drivers/hitachi/hnas_backend.py +++ b/cinder/volume/drivers/hitachi/hnas_backend.py @@ -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