def get_secret(data): """ keyring files look like:: [mon.] key = AQBvaBFZAAAAABAA9VHgwCg3rWn8fMaX8KL01A== caps mon = "allow *" Fetch that keyring file and extract the actual key, no spaces. .. warning:: If multiple mon dirs exist, this utility will pick the first one it finds. There are checks that will complain about multiple mon dirs """ file_paths = data['paths']['/var/lib/ceph']['files'].keys() _path = data['paths']['/var/lib/ceph']['files'] for _file in file_paths: if _file.startswith('/var/lib/ceph/mon/') and _file.endswith( 'keyring'): contents = _path[_file]['contents'] #.split('\n') conf = configuration.load_string(contents) try: return conf.get_safe('mon.', 'key', '').split('\n')[0] except IndexError: # is it really possible to get a keyring file that doesn't # have a monitor secret? return ''
def get_ceph_conf(data): path = '/etc/ceph/%s.conf' % metadata['cluster_name'] try: conf_file = data['paths']['/etc/ceph']['files'][path] except KeyError: return None return configuration.load_string(conf_file['contents'])
def test_loads_valid_ceph_key(self): contents = dedent(""" [global] cluster = ceph """) conf = configuration.load_string(contents) assert conf.get_safe('global', 'cluster') == 'ceph'
def test_loads_key_with_spaces_converted(self): contents = dedent(""" [global] some key here = ceph """) conf = configuration.load_string(contents) assert conf.get_safe('global', 'some_key_here') == 'ceph'
def setup(self): contents = dedent(""" [global] # """) conf = configuration.load_string(contents) ceph_medic.config.file = conf runner.metadata = base_metadata runner.metadata['cluster_name'] = 'ceph' runner.Runner().run()
def get_fsid(data): # FIXME: might want to load this thing into ConfigParser so that we can fetch # information. ceph-deploy is a good example on how to do this. See: # https://github.com/ceph/ceph-deploy/blob/master/ceph_deploy/conf/ceph.py cluster_path = '/etc/ceph/%s.conf' % metadata['cluster_name'] contents = data['paths']['/etc/ceph']['files'][cluster_path]['contents'] conf = configuration.load_string(contents) try: return conf.get_safe('global', 'fsid', '') except IndexError: return ''
def test_oc_with_context(self, stub_check): contents = dedent(""" [openshift] context = 87 """) conf = configuration.load_string(contents) ceph_medic.config.file = conf check = stub_check((['{"items": {}}'], [], 1)) hosts.container_platform() command = check.calls[0]['args'][1] assert command == [ 'oc', '--context', '87', '--request-timeout=5', 'get', '-n', 'rook-ceph', 'pods', '-o', 'json' ]