summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-11-16 21:24:26 +0000
committerGerrit Code Review <review@openstack.org>2016-11-16 21:24:26 +0000
commit235cb476b3df9513532b35af3864774781547221 (patch)
treef5853c199ea148942b3b2dce0baa69d7f5c7e3fc
parenta704dc8be69eabd22b6701243e3876e50320d70b (diff)
parent3f2800ede54692510c4c652c34176aa6c10c7f97 (diff)
Merge "Compare the encoded tag more accurately for huawei driver"
-rw-r--r--manila/share/drivers/huawei/v3/helper.py2
-rw-r--r--manila/tests/share/drivers/huawei/test_huawei_nas.py73
2 files changed, 74 insertions, 1 deletions
diff --git a/manila/share/drivers/huawei/v3/helper.py b/manila/share/drivers/huawei/v3/helper.py
index e2df939..371c897 100644
--- a/manila/share/drivers/huawei/v3/helper.py
+++ b/manila/share/drivers/huawei/v3/helper.py
@@ -190,7 +190,7 @@ class RestHelper(object):
190 need_encode = False 190 need_encode = False
191 for key in ['UserName', 'UserPassword']: 191 for key in ['UserName', 'UserPassword']:
192 node = root.find('Storage/%s' % key) 192 node = root.find('Storage/%s' % key)
193 if node.text.find(prefix_name) > -1: 193 if node.text.startswith(prefix_name):
194 logininfo[key] = base64.b64decode( 194 logininfo[key] = base64.b64decode(
195 six.b(node.text[4:])).decode() 195 six.b(node.text[4:])).decode()
196 else: 196 else:
diff --git a/manila/tests/share/drivers/huawei/test_huawei_nas.py b/manila/tests/share/drivers/huawei/test_huawei_nas.py
index 2d3d1f3..805af85 100644
--- a/manila/tests/share/drivers/huawei/test_huawei_nas.py
+++ b/manila/tests/share/drivers/huawei/test_huawei_nas.py
@@ -26,6 +26,7 @@ import xml.dom.minidom
26import ddt 26import ddt
27import mock 27import mock
28from oslo_serialization import jsonutils 28from oslo_serialization import jsonutils
29from xml.etree import ElementTree as ET
29 30
30from manila.common import constants as common_constants 31from manila.common import constants as common_constants
31from manila import context 32from manila import context
@@ -823,6 +824,45 @@ class FakeHuaweiNasDriver(huawei_nas.HuaweiNasDriver):
823 self.plugin.private_storage = FakePrivateStorage() 824 self.plugin.private_storage = FakePrivateStorage()
824 825
825 826
827class FakeConfigParseTree(object):
828 class FakeNode(object):
829 def __init__(self, text):
830 self._text = text
831
832 @property
833 def text(self):
834 return self._text
835
836 @text.setter
837 def text(self, text):
838 self._text = text
839
840 class FakeRoot(object):
841 def __init__(self):
842 self._node_map = {}
843
844 def findtext(self, path, default=None):
845 if path in self._node_map:
846 return self._node_map[path].text
847 return default
848
849 def find(self, path):
850 if path in self._node_map:
851 return self._node_map[path]
852 return None
853
854 def __init__(self, path_value):
855 self.root = self.FakeRoot()
856 for k in path_value:
857 self.root._node_map[k] = self.FakeNode(path_value[k])
858
859 def getroot(self):
860 return self.root
861
862 def write(self, filename, format):
863 pass
864
865
826@ddt.ddt 866@ddt.ddt
827class HuaweiShareDriverTestCase(test.TestCase): 867class HuaweiShareDriverTestCase(test.TestCase):
828 """Tests GenericShareDriver.""" 868 """Tests GenericShareDriver."""
@@ -4492,3 +4532,36 @@ class HuaweiShareDriverTestCase(test.TestCase):
4492 logininfo = self.driver.plugin.helper._get_login_info() 4532 logininfo = self.driver.plugin.helper._get_login_info()
4493 self.assertEqual('admin', logininfo['UserName']) 4533 self.assertEqual('admin', logininfo['UserName'])
4494 self.assertEqual('Admin@storage', logininfo['UserPassword']) 4534 self.assertEqual('Admin@storage', logininfo['UserPassword'])
4535
4536 @ddt.data({
4537 'username': 'abc',
4538 'password': '123456',
4539 'expect_username': 'abc',
4540 'expect_password': '123456',
4541 }, {
4542 'username': '!$$$YWJj',
4543 'password': '!$$$MTIzNDU2',
4544 'expect_username': 'abc',
4545 'expect_password': '123456',
4546 }, {
4547 'username': 'ab!$$$c',
4548 'password': '123!$$$456',
4549 'expect_username': 'ab!$$$c',
4550 'expect_password': '123!$$$456',
4551 })
4552 @ddt.unpack
4553 def test__get_login_info(self, username, password, expect_username,
4554 expect_password):
4555 configs = {
4556 'Storage/RestURL': 'https://123456',
4557 'Storage/UserName': username,
4558 'Storage/UserPassword': password,
4559 }
4560 self.mock_object(
4561 ET, 'parse',
4562 mock.Mock(return_value=FakeConfigParseTree(configs)))
4563
4564 result = self.driver.plugin.helper._get_login_info()
4565 self.assertEqual(expect_username, result['UserName'])
4566 self.assertEqual(expect_password, result['UserPassword'])
4567 ET.parse.assert_called_once_with(self.fake_conf_file)