ceph: need to shift 'DummyRados' class to top
As 'DummyRados' object is being used in other parts of the code, had to shift this to top. Signed-off-by: Arun Kumar Mohan <amohan@redhat.com>
This commit is contained in:
1 parent
72a8a6071b
commit
bb753caf52
1 file changed
+74
-71
@@ -52,6 +52,80 @@ except ModuleNotFoundError:
|
||||
class ExecutionFailureException(Exception):
|
||||
pass
|
||||
|
||||
################################################
|
||||
################## DummyRados ##################
|
||||
################################################
|
||||
# this is mainly for testing and could be used where 'rados' is not available
|
||||
class DummyRados(object):
|
||||
def __init__(self):
|
||||
self.return_val = 0
|
||||
self.err_message = ''
|
||||
self.state = 'connected'
|
||||
self.cmd_output_map = {}
|
||||
self.cmd_names = {}
|
||||
self._init_cmd_output_map()
|
||||
self.dummy_host_ip_map = {}
|
||||
|
||||
def _init_cmd_output_map(self):
|
||||
self.cmd_names['fs ls'] = '''{"format": "json", "prefix": "fs ls"}'''
|
||||
self.cmd_names['quorum_status'] = '''{"format": "json", "prefix": "quorum_status"}'''
|
||||
self.cmd_names['caps_change_default_pool_prefix'] = '''{"caps": ["mon", "allow r, allow command quorum_status, allow command version", "mgr", "allow command config", "osd", "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"], "entity": "client.healthchecker", "format": "json", "prefix": "auth caps"}'''
|
||||
# all the commands and their output
|
||||
self.cmd_output_map[self.cmd_names['fs ls']
|
||||
] = '''[{"name":"myfs","metadata_pool":"myfs-metadata","metadata_pool_id":2,"data_pool_ids":[3],"data_pools":["myfs-data0"]}]'''
|
||||
self.cmd_output_map[self.cmd_names['quorum_status']] = '''{"election_epoch":3,"quorum":[0],"quorum_names":["a"],"quorum_leader_name":"a","quorum_age":14385,"features":{"quorum_con":"4540138292836696063","quorum_mon":["kraken","luminous","mimic","osdmap-prune","nautilus","octopus"]},"monmap":{"epoch":1,"fsid":"af4e1673-0b72-402d-990a-22d2919d0f1c","modified":"2020-05-07T03:36:39.918035Z","created":"2020-05-07T03:36:39.918035Z","min_mon_release":15,"min_mon_release_name":"octopus","features":{"persistent":["kraken","luminous","mimic","osdmap-prune","nautilus","octopus"],"optional":[]},"mons":[{"rank":0,"name":"a","public_addrs":{"addrvec":[{"type":"v2","addr":"10.110.205.174:3300","nonce":0},{"type":"v1","addr":"10.110.205.174:6789","nonce":0}]},"addr":"10.110.205.174:6789/0","public_addr":"10.110.205.174:6789/0","priority":0,"weight":0}]}}'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r, allow command quorum_status", "osd", "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow x pool=default.rgw.buckets.index"], "entity": "client.healthchecker", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.healthchecker","key":"AQDFkbNeft5bFRAATndLNUSEKruozxiZi3lrdA==","caps":{"mon":"allow r, allow command quorum_status","osd":"allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow x pool=default.rgw.buckets.index"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "profile rbd", "osd", "profile rbd"], "entity": "client.csi-rbd-node", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-rbd-node","key":"AQBOgrNeHbK1AxAAubYBeV8S1U/GPzq5SVeq6g==","caps":{"mon":"profile rbd","osd":"profile rbd"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "profile rbd", "mgr", "allow rw", "osd", "profile rbd"], "entity": "client.csi-rbd-provisioner", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-rbd-provisioner","key":"AQBNgrNe1geyKxAA8ekViRdE+hss5OweYBkwNg==","caps":{"mgr":"allow rw","mon":"profile rbd","osd":"profile rbd"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r", "mgr", "allow rw", "osd", "allow rw tag cephfs *=*", "mds", "allow rw"], "entity": "client.csi-cephfs-node", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-cephfs-node","key":"AQBOgrNeENunKxAAPCmgE7R6G8DcXnaJ1F32qg==","caps":{"mds":"allow rw","mgr":"allow rw","mon":"allow r","osd":"allow rw tag cephfs *=*"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r", "mgr", "allow rw", "osd", "allow rw tag cephfs metadata=*"], "entity": "client.csi-cephfs-provisioner", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-cephfs-provisioner","key":"AQBOgrNeAFgcGBAAvGqKOAD0D3xxmVY0R912dg==","caps":{"mgr":"allow rw","mon":"allow r","osd":"allow rw tag cephfs metadata=*"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r, allow command quorum_status, allow command version", "mgr", "allow command config", "osd", "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"], "entity": "client.healthchecker", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.healthchecker","key":"AQDFkbNeft5bFRAATndLNUSEKruozxiZi3lrdA==","caps":{"mon": "allow r, allow command quorum_status, allow command version", "mgr": "allow command config", "osd": "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"}}]'''
|
||||
self.cmd_output_map['''{"format": "json", "prefix": "mgr services"}'''] = '''{"dashboard": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:7000/", "prometheus": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:9283/"}'''
|
||||
self.cmd_output_map['''{"entity": "client.healthchecker", "format": "json", "prefix": "auth get"}'''] = '''{"dashboard": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:7000/", "prometheus": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:9283/"}'''
|
||||
self.cmd_output_map['''{"entity": "client.healthchecker", "format": "json", "prefix": "auth get"}'''] = '''[{"entity":"client.healthchecker","key":"AQDFkbNeft5bFRAATndLNUSEKruozxiZi3lrdA==","caps":{"mon": "allow r, allow command quorum_status, allow command version", "mgr": "allow command config", "osd": "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"}}]'''
|
||||
self.cmd_output_map[self.cmd_names['caps_change_default_pool_prefix']] = '''[{}]'''
|
||||
|
||||
def shutdown(self):
|
||||
pass
|
||||
|
||||
def get_fsid(self):
|
||||
return 'af4e1673-0b72-402d-990a-22d2919d0f1c'
|
||||
|
||||
def conf_read_file(self):
|
||||
pass
|
||||
|
||||
def connect(self):
|
||||
pass
|
||||
|
||||
def pool_exists(self, pool_name):
|
||||
return True
|
||||
|
||||
def mon_command(self, cmd, out):
|
||||
json_cmd = json.loads(cmd)
|
||||
json_cmd_str = json.dumps(json_cmd, sort_keys=True)
|
||||
cmd_output = self.cmd_output_map[json_cmd_str]
|
||||
return self.return_val, \
|
||||
cmd_output, \
|
||||
"{}".format(self.err_message).encode('utf-8')
|
||||
|
||||
def _convert_hostname_to_ip(self, host_name):
|
||||
ip_reg_x = re.compile(r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}')
|
||||
# if provided host is directly an IP address, return the same
|
||||
if ip_reg_x.match(host_name):
|
||||
return host_name
|
||||
import random
|
||||
host_ip = self.dummy_host_ip_map.get(host_name, "")
|
||||
if not host_ip:
|
||||
host_ip = "172.9.{}.{}".format(random.randint(0, 255), random.randint(0, 255))
|
||||
self.dummy_host_ip_map[host_name] = host_ip
|
||||
del random
|
||||
return host_ip
|
||||
|
||||
@classmethod
|
||||
def Rados(conffile=None):
|
||||
return DummyRados()
|
||||
|
||||
|
||||
|
||||
class RadosJSON:
|
||||
EXTERNAL_USER_NAME = "client.healthchecker"
|
||||
@@ -693,77 +767,6 @@ if __name__ == '__main__':
|
||||
################################################
|
||||
##################### TEST #####################
|
||||
################################################
|
||||
# this is mainly for testing and could be used where 'rados' is not available
|
||||
class DummyRados(object):
|
||||
def __init__(self):
|
||||
self.return_val = 0
|
||||
self.err_message = ''
|
||||
self.state = 'connected'
|
||||
self.cmd_output_map = {}
|
||||
self.cmd_names = {}
|
||||
self._init_cmd_output_map()
|
||||
self.dummy_host_ip_map = {}
|
||||
|
||||
def _init_cmd_output_map(self):
|
||||
self.cmd_names['fs ls'] = '''{"format": "json", "prefix": "fs ls"}'''
|
||||
self.cmd_names['quorum_status'] = '''{"format": "json", "prefix": "quorum_status"}'''
|
||||
self.cmd_names['caps_change_default_pool_prefix'] = '''{"caps": ["mon", "allow r, allow command quorum_status, allow command version", "mgr", "allow command config", "osd", "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"], "entity": "client.healthchecker", "format": "json", "prefix": "auth caps"}'''
|
||||
# all the commands and their output
|
||||
self.cmd_output_map[self.cmd_names['fs ls']
|
||||
] = '''[{"name":"myfs","metadata_pool":"myfs-metadata","metadata_pool_id":2,"data_pool_ids":[3],"data_pools":["myfs-data0"]}]'''
|
||||
self.cmd_output_map[self.cmd_names['quorum_status']] = '''{"election_epoch":3,"quorum":[0],"quorum_names":["a"],"quorum_leader_name":"a","quorum_age":14385,"features":{"quorum_con":"4540138292836696063","quorum_mon":["kraken","luminous","mimic","osdmap-prune","nautilus","octopus"]},"monmap":{"epoch":1,"fsid":"af4e1673-0b72-402d-990a-22d2919d0f1c","modified":"2020-05-07T03:36:39.918035Z","created":"2020-05-07T03:36:39.918035Z","min_mon_release":15,"min_mon_release_name":"octopus","features":{"persistent":["kraken","luminous","mimic","osdmap-prune","nautilus","octopus"],"optional":[]},"mons":[{"rank":0,"name":"a","public_addrs":{"addrvec":[{"type":"v2","addr":"10.110.205.174:3300","nonce":0},{"type":"v1","addr":"10.110.205.174:6789","nonce":0}]},"addr":"10.110.205.174:6789/0","public_addr":"10.110.205.174:6789/0","priority":0,"weight":0}]}}'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r, allow command quorum_status", "osd", "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow x pool=default.rgw.buckets.index"], "entity": "client.healthchecker", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.healthchecker","key":"AQDFkbNeft5bFRAATndLNUSEKruozxiZi3lrdA==","caps":{"mon":"allow r, allow command quorum_status","osd":"allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow x pool=default.rgw.buckets.index"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "profile rbd", "osd", "profile rbd"], "entity": "client.csi-rbd-node", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-rbd-node","key":"AQBOgrNeHbK1AxAAubYBeV8S1U/GPzq5SVeq6g==","caps":{"mon":"profile rbd","osd":"profile rbd"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "profile rbd", "mgr", "allow rw", "osd", "profile rbd"], "entity": "client.csi-rbd-provisioner", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-rbd-provisioner","key":"AQBNgrNe1geyKxAA8ekViRdE+hss5OweYBkwNg==","caps":{"mgr":"allow rw","mon":"profile rbd","osd":"profile rbd"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r", "mgr", "allow rw", "osd", "allow rw tag cephfs *=*", "mds", "allow rw"], "entity": "client.csi-cephfs-node", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-cephfs-node","key":"AQBOgrNeENunKxAAPCmgE7R6G8DcXnaJ1F32qg==","caps":{"mds":"allow rw","mgr":"allow rw","mon":"allow r","osd":"allow rw tag cephfs *=*"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r", "mgr", "allow rw", "osd", "allow rw tag cephfs metadata=*"], "entity": "client.csi-cephfs-provisioner", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.csi-cephfs-provisioner","key":"AQBOgrNeAFgcGBAAvGqKOAD0D3xxmVY0R912dg==","caps":{"mgr":"allow rw","mon":"allow r","osd":"allow rw tag cephfs metadata=*"}}]'''
|
||||
self.cmd_output_map['''{"caps": ["mon", "allow r, allow command quorum_status, allow command version", "mgr", "allow command config", "osd", "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"], "entity": "client.healthchecker", "format": "json", "prefix": "auth get-or-create"}'''] = '''[{"entity":"client.healthchecker","key":"AQDFkbNeft5bFRAATndLNUSEKruozxiZi3lrdA==","caps":{"mon": "allow r, allow command quorum_status, allow command version", "mgr": "allow command config", "osd": "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"}}]'''
|
||||
self.cmd_output_map['''{"format": "json", "prefix": "mgr services"}'''] = '''{"dashboard": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:7000/", "prometheus": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:9283/"}'''
|
||||
self.cmd_output_map['''{"entity": "client.healthchecker", "format": "json", "prefix": "auth get"}'''] = '''{"dashboard": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:7000/", "prometheus": "http://rook-ceph-mgr-a-57cf9f84bc-f4jnl:9283/"}'''
|
||||
self.cmd_output_map['''{"entity": "client.healthchecker", "format": "json", "prefix": "auth get"}'''] = '''[{"entity":"client.healthchecker","key":"AQDFkbNeft5bFRAATndLNUSEKruozxiZi3lrdA==","caps":{"mon": "allow r, allow command quorum_status, allow command version", "mgr": "allow command config", "osd": "allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index"}}]'''
|
||||
self.cmd_output_map[self.cmd_names['caps_change_default_pool_prefix']] = '''[{}]'''
|
||||
|
||||
def shutdown(self):
|
||||
pass
|
||||
|
||||
def get_fsid(self):
|
||||
return 'af4e1673-0b72-402d-990a-22d2919d0f1c'
|
||||
|
||||
def conf_read_file(self):
|
||||
pass
|
||||
|
||||
def connect(self):
|
||||
pass
|
||||
|
||||
def pool_exists(self, pool_name):
|
||||
return True
|
||||
|
||||
def mon_command(self, cmd, out):
|
||||
json_cmd = json.loads(cmd)
|
||||
json_cmd_str = json.dumps(json_cmd, sort_keys=True)
|
||||
cmd_output = self.cmd_output_map[json_cmd_str]
|
||||
return self.return_val, \
|
||||
cmd_output, \
|
||||
"{}".format(self.err_message).encode('utf-8')
|
||||
|
||||
def _convert_hostname_to_ip(self, host_name):
|
||||
ip_reg_x = re.compile(r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}')
|
||||
# if provided host is directly an IP address, return the same
|
||||
if ip_reg_x.match(host_name):
|
||||
return host_name
|
||||
import random
|
||||
host_ip = self.dummy_host_ip_map.get(host_name, "")
|
||||
if not host_ip:
|
||||
host_ip = "172.9.{}.{}".format(random.randint(0, 255), random.randint(0, 255))
|
||||
self.dummy_host_ip_map[host_name] = host_ip
|
||||
del random
|
||||
return host_ip
|
||||
|
||||
@classmethod
|
||||
def Rados(conffile=None):
|
||||
return DummyRados()
|
||||
|
||||
|
||||
# inorder to test the package,
|
||||
# cd <script_directory>
|
||||
# python -m unittest --verbose <script_name_without_dot_py>
|
||||
|
||||
Reference in new issue
Block a user