Fix the creation issue when special meanings words in queue name

Now 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.

Change-Id: Ia776bb4f7253b1698ec97702e0fc69704b97ed7e
Closes-Bug: #1584639
This commit is contained in:
wanghao 2017-06-13 09:58:30 +08:00
parent 6f4b6e30ad
commit 8e55b55f3a
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: