From 57e8cdb9dd8e24919bc2243438a6bded53491b3e Mon Sep 17 00:00:00 2001 From: Jim Branen Date: Fri, 4 Apr 2014 13:36:42 -0700 Subject: [PATCH] Fixes HP LeftHand driver with Paramiko 1.13.0 With Paramiko 1.13.0, the method exec_command now returns Unicode. This causes a problem when the driver tries to build the XML returned from the LeftHand array. The XML header returned from the array defines the encoding as encoding=UTF-8. Therefore, we must now ensure the encoding passed to the parser is utf-8. Change-Id: I7b504626e2d9a0ee2b62820b11f56eb136e31987 closes-bug: #1298608 --- cinder/tests/test_hplefthand.py | 54 ++++++++++++++++++- .../drivers/san/hp/hp_lefthand_cliq_proxy.py | 5 +- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/cinder/tests/test_hplefthand.py b/cinder/tests/test_hplefthand.py index 040ad86bf..d9ad1a8e0 100644 --- a/cinder/tests/test_hplefthand.py +++ b/cinder/tests/test_hplefthand.py @@ -309,6 +309,42 @@ class TestHPLeftHandCLIQISCSIDriver(HPLeftHandBaseDriver, test.TestCase): """ return output, None + def test_paramiko_1_13_0(cliq_args): + + # paramiko 1.13.0 now returns unicode + output = unicode( + '\n' + '\n\n \n \n' + ' \n' + ' \n \n \n\n' + '\n ') + return output, None + + def test_paramiko_1_10_0(cliq_args): + + # paramiko 1.10.0 returns python default encoding. + output = ( + '\n' + '\n\n \n \n' + ' \n' + ' \n \n \n\n' + '\n ') + return output, None + self.assertEqual(cliq_args['output'], 'XML') try: verbs = {'createVolume': create_volume, @@ -324,7 +360,9 @@ class TestHPLeftHandCLIQISCSIDriver(HPLeftHandBaseDriver, test.TestCase): 'getSnapshotInfo': get_snapshot_info, 'getServerInfo': get_server_info, 'createServer': create_server, - 'testError': test_error} + 'testError': test_error, + 'testParamiko_1.10.1': test_paramiko_1_10_0, + 'testParamiko_1.13.1': test_paramiko_1_13_0} except KeyError: raise NotImplementedError() @@ -593,6 +631,20 @@ class TestHPLeftHandCLIQISCSIDriver(HPLeftHandBaseDriver, test.TestCase): # validate call chain mock_cliq_run.assert_has_calls(expected) + def test_cliq_run_xml_paramiko_1_13_0(self): + + # set up driver with default config + self.setup_driver() + xml = self.driver.proxy._cliq_run_xml('testParamiko_1.13.1', {}) + self.assertIsNotNone(xml) + + def test_cliq_run_xml_paramiko_1_10_0(self): + + # set up driver with default config + self.setup_driver() + xml = self.driver.proxy._cliq_run_xml('testParamiko_1.10.1', {}) + self.assertIsNotNone(xml) + class TestHPLeftHandRESTISCSIDriver(HPLeftHandBaseDriver, test.TestCase): diff --git a/cinder/volume/drivers/san/hp/hp_lefthand_cliq_proxy.py b/cinder/volume/drivers/san/hp/hp_lefthand_cliq_proxy.py index 2127133dd..0b36ee7f5 100644 --- a/cinder/volume/drivers/san/hp/hp_lefthand_cliq_proxy.py +++ b/cinder/volume/drivers/san/hp/hp_lefthand_cliq_proxy.py @@ -72,9 +72,10 @@ class HPLeftHandCLIQProxy(SanISCSIDriver): 1.2.0 - Ported into the new HP LeftHand driver. 1.2.1 - Fixed bug #1279897, HP LeftHand CLIQ proxy may return incorrect capacity values. + 1.2.2 - Fixed driver with Paramiko 1.13.0, bug #1298608. """ - VERSION = "1.2.1" + VERSION = "1.2.2" device_stats = {} @@ -106,7 +107,7 @@ class HPLeftHandCLIQProxy(SanISCSIDriver): LOG.debug(_("CLIQ command returned %s"), out) - result_xml = etree.fromstring(out) + result_xml = etree.fromstring(out.encode('utf8')) if check_cliq_result: response_node = result_xml.find("response") if response_node is None: -- 2.45.2