ceph_argparse.py, cephtool/test.sh: fix blacklist with no nonce

It's legal to give a CephEntityAddr to osd blacklist with no nonce,
so allow it in the valid() method; also add validation of any nonce
given that it's a long >= 0.

Also fix comment on CephEntityAddr type description in MonCommands.h,
and add tests for invalid nonces (while fixing the existing tests to remove
the () around expect_false args).

Fixes: #6425
Signed-off-by: Dan Mick <dan.mick@inktank.com>
This commit is contained in:
Dan Mick 2013-09-26 18:00:31 -07:00
parent 60017e074b
commit 1ba7e47c6a
3 changed files with 28 additions and 5 deletions

View File

@ -169,7 +169,16 @@ bl=192.168.0.1:0/1000
ceph osd blacklist add $bl
ceph osd blacklist ls | grep $bl
ceph osd blacklist rm $bl
expect_false "(ceph osd blacklist ls | grep $bl)"
expect_false "ceph osd blacklist ls | grep $bl"
bl=192.168.0.1
# test without nonce, invalid nonce
ceph osd blacklist add $bl
ceph osd blacklist ls | grep $bl
ceph osd blacklist rm $bl
expect_false "ceph osd blacklist ls | grep $bl"
expect_false "ceph osd blacklist $bl/-1"
expect_false "ceph osd blacklist $bl/foo"
ceph osd crush tunables legacy
ceph osd crush tunables bobtail

View File

@ -59,7 +59,7 @@
* CephString: optional badchars
* CephSocketpath: validation involves "is it S_ISSOCK"
* CephIPAddr: v4 or v6 addr with optional port, syntax validated
* CephEntityAddr: CephIPAddr + '/nonce'
* CephEntityAddr: CephIPAddr + optional '/nonce'
* CephPoolname: Plainold string
* CephObjectname: Another plainold string
* CephPgid: n.xxx where n is an int > 0, xxx is a hex number > 0

View File

@ -275,12 +275,26 @@ class CephIPAddr(CephArgtype):
class CephEntityAddr(CephIPAddr):
"""
EntityAddress, that is, IP address/nonce
EntityAddress, that is, IP address[/nonce]
"""
def valid(self, s, partial=False):
ip, nonce = s.split('/')
nonce = None
if '/' in s:
ip, nonce = s.split('/')
else:
ip = s
super(self.__class__, self).valid(ip)
self.nonce = nonce
if nonce:
nonce_long = None
try:
nonce_long = long(nonce)
except ValueError:
pass
if nonce_long is None or nonce_long < 0:
raise ArgumentValid(
'{0}: invalid entity, nonce {1} not integer > 0'.\
format(s, nonce)
)
self.val = s
def __str__(self):