Fix HDS HNAS manage incorrect share size

Method get_quota does not handle quotas smaller than 1 GB.
When the share quota is KB or MB, get_quota transforms everything to GB.
It is impacting directly on managing shares.
As an example, managing a 500 MB share results in 500 GB share in HDS HNAS
Driver.
The unit TB was already being transformed in GB.

This patch implements a condition to deny share with quota smaller than
1GB.

Closes-bug: #1496917
Change-Id: I73edc1f413bd307a856702f8a024a8b50886207b
This commit is contained in:
Alyson Rosa 2015-09-17 13:14:08 -03:00
parent cc66f22781
commit dd77cf98c1
2 changed files with 41 additions and 6 deletions

View File

@ -666,12 +666,16 @@ class HNASSSHBackend(object):
'No quotas matching' not in items[i]):
if 'Limit' in items[i] and 'Hard' in items[i]:
quota = float(items[i].split(' ')[12])
# If the quota is 1 or more TB, converts to GB
if items[i].split(' ')[13] == 'TB':
return quota * units.Ki
return quota
size_unit = items[i].split(' ')[13]
if size_unit in ('TB', 'GB'):
# If the quota is 1 or more TB, converts to GB
if size_unit == 'TB':
return quota * units.Ki
return quota
else:
msg = (_("Share %s does not support quota values "
"below 1GB.") % share_id)
raise exception.HNASBackendException(msg=msg)
else:
# Returns None if the quota is unset
return None

View File

@ -122,6 +122,22 @@ Generate Events : Disabled
Global id : 28a3c9f8-ae05-11d0-9025-836896aada5d
Last modified : 2015-06-23 22:37:17.363660800+00:00 """
HNAS_RESULT_quota_mb = """Type : Explicit
Target : ViVol: vvol_test
Usage : 0 B
Limit : 500 MB (Hard)
Warning : Unset
Critical : Unset
Reset : 5% (51.2 MB)
File Count : 1
Limit : Unset
Warning : Unset
Critical : Unset
Reset : 5% (0)
Generate Events : Disabled
Global id : 28a3c9f8-ae05-11d0-9025-836896aada5d
Last modified : 2015-06-23 22:37:17.363660800+00:00 """
HNAS_RESULT_quota_unset = """Type : Explicit
Target : ViVol: vvol_test
Usage : 0 B
@ -922,6 +938,21 @@ class HNASSSHTestCase(test.TestCase):
self.vvol, self.vvol['id'])
ssh.HNASSSHBackend._execute.assert_called_with(fake_list_command)
def test_manage_existing_share_invalid_size(self):
fake_list_command = ['quota', 'list', 'file_system', 'vvol_test']
self.mock_object(ssh.HNASSSHBackend, '_execute',
mock.Mock(side_effect=[(HNAS_RESULT_fs, ""),
(HNAS_RESULT_fs, ""),
(HNAS_RESULT_vvol, ""),
(HNAS_RESULT_quota, ""),
(HNAS_RESULT_export, ""),
(HNAS_RESULT_quota_mb, "")]))
self.assertRaises(exception.HNASBackendException,
self._driver.manage_existing,
self.vvol, self.vvol['id'])
ssh.HNASSSHBackend._execute.assert_called_with(fake_list_command)
def test_create_snapshot(self):
fake_create_command = ['tree-clone-job-submit', '-e',
'-f', 'file_system', '/shares/vvol_test',