Merge "Fix the creation issue when special meanings words in queue name"
This commit is contained in:
commit
9c83beb5d0
@ -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.
|
@ -13,6 +13,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from zaqarclient._i18n import _ # noqa
|
from zaqarclient._i18n import _ # noqa
|
||||||
from zaqarclient import errors
|
from zaqarclient import errors
|
||||||
from zaqarclient.queues.v1 import claim as claim_api
|
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 iterator
|
||||||
from zaqarclient.queues.v1 import message
|
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):
|
class Queue(object):
|
||||||
|
|
||||||
@ -45,6 +51,10 @@ class Queue(object):
|
|||||||
if name == "":
|
if name == "":
|
||||||
raise ValueError(_('Queue name does not have a value'))
|
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
|
# NOTE(flaper87) Queue Info
|
||||||
self._name = name
|
self._name = name
|
||||||
self._metadata = metadata
|
self._metadata = metadata
|
||||||
|
@ -71,6 +71,12 @@ class QueuesV1QueueUnitTest(base.QueuesTestBase):
|
|||||||
def test_queue_valid_name(self):
|
def test_queue_valid_name(self):
|
||||||
self.assertRaises(ValueError, self.client.queue, "")
|
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):
|
def test_queue_delete(self):
|
||||||
with mock.patch.object(self.transport, 'send',
|
with mock.patch.object(self.transport, 'send',
|
||||||
autospec=True) as send_method:
|
autospec=True) as send_method:
|
||||||
|
Loading…
Reference in New Issue
Block a user