Merge "Fix the creation issue when special meanings words in queue name"

This commit is contained in:
Jenkins 2017-06-21 01:27:02 +00:00 committed by Gerrit Code Review
commit 9c83beb5d0
3 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,9 @@
---
fixes:
- Fix the creation issue when special meanings words in queue name.
When using zaqarclient to create a queue with some special
meanings words like "#" and "%", then cli will return the queue
with the name has created successfully, but in zaqar server side,
the name is not as same as the client side.
Add the check for some special meanings words, it will raise error message
when using those words in queue name.

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import re
from zaqarclient._i18n import _ # noqa
from zaqarclient import errors
from zaqarclient.queues.v1 import claim as claim_api
@ -20,6 +22,10 @@ from zaqarclient.queues.v1 import core
from zaqarclient.queues.v1 import iterator
from zaqarclient.queues.v1 import message
# NOTE(wanghao): This is copied from Zaqar server side, so if server have
# updated it someday, we should update it here to keep consistent.
QUEUE_NAME_REGEX = re.compile('^[a-zA-Z0-9_\-]+$')
class Queue(object):
@ -45,6 +51,10 @@ class Queue(object):
if name == "":
raise ValueError(_('Queue name does not have a value'))
if not QUEUE_NAME_REGEX.match(str(name)):
raise ValueError(_('The queue name may only contain ASCII '
'letters, digits, underscores and dashes.'))
# NOTE(flaper87) Queue Info
self._name = name
self._metadata = metadata

View File

@ -71,6 +71,12 @@ class QueuesV1QueueUnitTest(base.QueuesTestBase):
def test_queue_valid_name(self):
self.assertRaises(ValueError, self.client.queue, "")
def test_queue_valid_name_with_pound(self):
self.assertRaises(ValueError, self.client.queue, "123#456")
def test_queue_valid_name_with_percent(self):
self.assertRaises(ValueError, self.client.queue, "123%456")
def test_queue_delete(self):
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method: