Merge "HP 3PAR add more info to the share comment"

This commit is contained in:
Jenkins 2015-08-27 06:41:11 +00:00 committed by Gerrit Code Review
commit 9b77e13302
5 changed files with 82 additions and 16 deletions

View File

@ -14,10 +14,12 @@
"""HP 3PAR Driver for OpenStack Manila."""
import datetime
import hashlib
import inspect
import logging
import os
import re
from oslo_config import cfg
from oslo_log import log
@ -81,7 +83,7 @@ class HP3ParShareDriver(driver.ShareDriver):
Supports NFS and CIFS protocols on arrays with File Persona.
"""
VERSION = "1.0.00"
VERSION = "1.0.01"
def __init__(self, *args, **kwargs):
super(HP3ParShareDriver, self).__init__(False, *args, **kwargs)
@ -173,6 +175,22 @@ class HP3ParShareDriver(driver.ShareDriver):
raise exception.InvalidInput(message)
return location
@staticmethod
def build_share_comment(share):
"""Create an informational only comment to help admins and testers."""
info = {
'name': share['display_name'],
'host': share['host'],
'now': datetime.datetime.now().strftime('%H%M%S'),
}
acceptable = re.compile('[^a-zA-Z0-9_=:@# \-]+', re.UNICODE)
comment = ("OpenStack Manila - host=%(host)s orig_name=%(name)s "
"created=%(now)s" % info)
return acceptable.sub('_', comment)[:254] # clean and truncate
def create_share(self, context, share, share_server=None):
"""Is called to create share."""
@ -187,7 +205,8 @@ class HP3ParShareDriver(driver.ShareDriver):
protocol,
extra_specs,
self.fpg, self.vfs,
size=share['size']
size=share['size'],
comment=self.build_share_comment(share)
)
return self._build_export_location(protocol, ip, path)
@ -210,7 +229,8 @@ class HP3ParShareDriver(driver.ShareDriver):
snapshot['share']['share_proto'],
snapshot['id'],
self.fpg,
self.vfs
self.vfs,
comment=self.build_share_comment(share)
)
return self._build_export_location(protocol, ip, path)

View File

@ -36,7 +36,7 @@ MIN_CLIENT_VERSION = (3, 2, 1)
MIN_SMB_CA_VERSION = (3, 2, 2)
DENY = '-'
ALLOW = '+'
OPEN_STACK_MANILA_FSHARE = 'OpenStack Manila fshare'
OPEN_STACK_MANILA = 'OpenStack Manila'
FULL = 1
THIN = 2
DEDUPE = 6
@ -54,7 +54,7 @@ SMB_EXTRA_SPECS_MAP = {
class HP3ParMediator(object):
VERSION = "1.0.00"
VERSION = "1.0.01"
def __init__(self, **kwargs):
@ -307,11 +307,11 @@ class HP3ParMediator(object):
return ','.join(options)
def _build_createfshare_kwargs(self, protocol, fpg, fstore, readonly,
sharedir, extra_specs):
sharedir, extra_specs, comment):
createfshare_kwargs = dict(fpg=fpg,
fstore=fstore,
sharedir=sharedir,
comment=OPEN_STACK_MANILA_FSHARE)
comment=comment)
if protocol == 'nfs':
createfshare_kwargs['clientip'] = '127.0.0.1'
options = self._get_nfs_options(extra_specs, readonly)
@ -333,7 +333,8 @@ class HP3ParMediator(object):
def create_share(self, project_id, share_id, share_proto, extra_specs,
fpg, vfs,
fstore=None, sharedir=None, readonly=False, size=None):
fstore=None, sharedir=None, readonly=False, size=None,
comment=OPEN_STACK_MANILA):
"""Create the share and return its path.
This method can create a share when called by the driver or when
@ -374,14 +375,15 @@ class HP3ParMediator(object):
fstore,
readonly,
sharedir,
extra_specs)
extra_specs,
comment)
if not use_existing_fstore:
try:
result = self._client.createfstore(
vfs, fstore, fpg=fpg,
comment='OpenStack Manila fstore')
comment=comment)
LOG.debug("createfstore result=%s", result)
except Exception as e:
msg = (_('Failed to create fstore %(fstore)s: %(e)s') %
@ -459,7 +461,8 @@ class HP3ParMediator(object):
def create_share_from_snapshot(self, share_id, share_proto, extra_specs,
orig_project_id, orig_share_id, orig_proto,
snapshot_id, fpg, vfs):
snapshot_id, fpg, vfs,
comment=OPEN_STACK_MANILA):
protocol = self.ensure_supported_protocol(share_proto)
snapshot_tag = self.ensure_prefix(snapshot_id)
@ -502,6 +505,7 @@ class HP3ParMediator(object):
fstore=fstore,
sharedir=sharedir,
readonly=True,
comment=comment,
)
def delete_share(self, project_id, share_id, share_proto, fpg, vfs):

View File

@ -33,6 +33,7 @@ EXPECTED_IP_127 = '127.0.0.1'
EXPECTED_PROJECT_ID = 'osf-nfs-project-id'
EXPECTED_SHARE_ID = 'osf-share-id'
EXPECTED_SHARE_NAME = 'share-name'
EXPECTED_HOST = 'hostname@backend#pool'
EXPECTED_SHARE_PATH = '/anyfpg/anyvfs/anyfstore'
EXPECTED_SIZE_1 = 1
EXPECTED_SIZE_2 = 2

View File

@ -14,6 +14,7 @@
import sys
import ddt
import mock
if 'hp3parclient' not in sys.modules:
sys.modules['hp3parclient'] = mock.Mock()
@ -25,6 +26,7 @@ from manila import test
from manila.tests.share.drivers.hp import test_hp_3par_constants as constants
@ddt.ddt
class HP3ParDriverTestCase(test.TestCase):
def setUp(self):
@ -154,6 +156,8 @@ class HP3ParDriverTestCase(test.TestCase):
context = None
share_server = None
share = {
'display_name': constants.EXPECTED_SHARE_NAME,
'host': constants.EXPECTED_HOST,
'project_id': expected_project_id,
'id': expected_share_id,
'share_proto': protocol,
@ -173,6 +177,8 @@ class HP3ParDriverTestCase(test.TestCase):
context = None
share_server = None
share = {
'display_name': constants.EXPECTED_SHARE_NAME,
'host': constants.EXPECTED_HOST,
'id': expected_share_id,
'share_proto': protocol,
'share_type_id': share_type_id,
@ -235,6 +241,7 @@ class HP3ParDriverTestCase(test.TestCase):
constants.EXPECTED_EXTRA_SPECS,
constants.EXPECTED_FPG,
constants.EXPECTED_VFS,
comment=mock.ANY,
size=constants.EXPECTED_SIZE_2)]
self.mock_mediator.assert_has_calls(expected_calls)
@ -261,6 +268,7 @@ class HP3ParDriverTestCase(test.TestCase):
constants.EXPECTED_EXTRA_SPECS,
constants.EXPECTED_FPG,
constants.EXPECTED_VFS,
comment=mock.ANY,
size=constants.EXPECTED_SIZE_1)]
self.mock_mediator.assert_has_calls(expected_calls)
@ -292,7 +300,8 @@ class HP3ParDriverTestCase(test.TestCase):
constants.NFS,
constants.EXPECTED_SNAP_ID,
constants.EXPECTED_FPG,
constants.EXPECTED_VFS),
constants.EXPECTED_VFS,
comment=mock.ANY),
]
self.mock_mediator.assert_has_calls(expected_calls)
@ -323,7 +332,8 @@ class HP3ParDriverTestCase(test.TestCase):
constants.NFS,
constants.EXPECTED_SNAP_ID,
constants.EXPECTED_FPG,
constants.EXPECTED_VFS)
constants.EXPECTED_VFS,
comment=mock.ANY),
]
self.mock_mediator.assert_has_calls(expected_calls)
@ -508,3 +518,34 @@ class HP3ParDriverTestCase(test.TestCase):
result = self.driver.get_share_stats(refresh=True)
self.assertEqual(expected_result, result)
self.assertFalse(self.mock_mediator.get_fpg_status.called)
@ddt.data(('test"dquote', 'test_dquote'),
("test'squote", "test_squote"),
('test-:;,.punc', 'test-:_punc'),
('test with spaces ', 'test with spaces '),
('x' * 300, 'x' * 300))
@ddt.unpack
def test_build_comment(self, display_name, clean_name):
host = 'test-stack1@backend#pool'
share = {
'host': host,
'display_name': display_name
}
comment = self.driver.build_share_comment(share)
cleaned = {
'host': host,
'clean_name': clean_name
}
expected = ("OpenStack Manila - host=%(host)s "
"orig_name=%(clean_name)s created=" % cleaned)[:254]
self.assertLess(len(comment), 255)
self.assertTrue(comment.startswith(expected))
# Test for some chars that are not allowed.
# Don't test with same regex as the code uses.
for c in "'\".,;":
self.assertNotIn(c, comment)

View File

@ -241,7 +241,7 @@ class HP3ParMediatorTestCase(test.TestCase):
expected_share_id):
expected_sharedir = expected_share_id
createfshare_kwargs = dict(comment='OpenStack Manila fshare',
createfshare_kwargs = dict(comment=mock.ANY,
fpg=expected_fpg,
sharedir=expected_sharedir,
fstore=expected_project_id)
@ -263,7 +263,7 @@ class HP3ParMediatorTestCase(test.TestCase):
expected_calls = [
mock.call.createfstore(expected_vfsname, expected_project_id,
comment='OpenStack Manila fstore',
comment=mock.ANY,
fpg=expected_fpg),
mock.call.getfsquota(fpg=expected_fpg,
vfs=expected_vfsname,
@ -298,7 +298,7 @@ class HP3ParMediatorTestCase(test.TestCase):
expected_calls = [
mock.call.createfstore(expected_vfsname, expected_project_id,
comment='OpenStack Manila fstore',
comment=mock.ANY,
fpg=expected_fpg),
mock.call.getfsquota(fpg=expected_fpg,
vfs=expected_vfsname,