summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Mick <dan.mick@inktank.com>2013-09-26 18:00:31 -0700
committerDan Mick <dan.mick@inktank.com>2013-09-26 18:06:30 -0700
commit1ba7e47c6abe0699e77b94ccdf9cb2169f8d94f5 (patch)
treeb86fdad20c5fbc6636c6fa45ca0a33e30d40de8c
parent60017e074bcbe67098476d3814bf46672bd2becb (diff)
downloadceph-1ba7e47c6abe0699e77b94ccdf9cb2169f8d94f5.tar.gz
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>
-rwxr-xr-xqa/workunits/cephtool/test.sh11
-rw-r--r--src/mon/MonCommands.h2
-rw-r--r--src/pybind/ceph_argparse.py20
3 files changed, 28 insertions, 5 deletions
diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh
index 51420a2f134..09e55b9a842 100755
--- a/qa/workunits/cephtool/test.sh
+++ b/qa/workunits/cephtool/test.sh
@@ -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
diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h
index baef4ea50a5..b28a84943d4 100644
--- a/src/mon/MonCommands.h
+++ b/src/mon/MonCommands.h
@@ -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
diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py
index 427a4621216..7ec7b8b2f0c 100644
--- a/src/pybind/ceph_argparse.py
+++ b/src/pybind/ceph_argparse.py
@@ -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):