Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ceph-daemon: infer fsid for some commands #31702

Merged
merged 1 commit into from Nov 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 35 additions & 4 deletions src/ceph-daemon/ceph-daemon
Expand Up @@ -60,6 +60,7 @@ except ImportError:
import uuid

from distutils.spawn import find_executable
from functools import wraps
from glob import glob

try:
Expand Down Expand Up @@ -226,6 +227,35 @@ def is_fsid(s):
return False
return True

def infer_fsid(func):
"""
If we only find a single fsid in /var/lib/ceph/*, use that
"""
@wraps(func)
def _infer_fsid():
if args.fsid:
logger.debug('Using specified fsid: %s' % args.fsid)
return

fsid_list = []
for i in os.listdir(args.data_dir):
if is_fsid(i):
fsid_list.append(i)

logger.debug('Found fsids %s' % str(fsid_list))

if not fsid_list:
# TODO: raise?
return

if len(fsid_list) > 1:
raise RuntimeError('Cannot infer fsid, must specify --fsid')

logger.info('Inferring fsid %s' % fsid_list[0])
args.fsid = fsid_list[0]
return func()
return _infer_fsid

def makedirs(dir, uid, gid, mode):
# type: (str, int, int, int) -> None
if not os.path.exists(dir):
Expand Down Expand Up @@ -1258,6 +1288,7 @@ def command_run():

##################################

@infer_fsid
def command_shell():
# type: () -> int
if args.fsid:
Expand Down Expand Up @@ -1296,6 +1327,7 @@ def command_shell():

##################################

@infer_fsid
def command_enter():
# type: () -> int
(daemon_type, daemon_id) = args.name.split('.', 1)
Expand All @@ -1315,6 +1347,7 @@ def command_enter():

##################################

@infer_fsid
def command_ceph_volume():
# type: () -> None
make_log_dir(args.fsid)
Expand Down Expand Up @@ -1357,6 +1390,7 @@ def command_ceph_volume():

##################################

@infer_fsid
def command_unit():
# type: () -> None
(daemon_type, daemon_id) = args.name.split('.', 1)
Expand All @@ -1368,6 +1402,7 @@ def command_unit():

##################################

@infer_fsid
def command_logs():
# type: () -> None
cmd = [container_path, 'logs']
Expand Down Expand Up @@ -1751,7 +1786,6 @@ def _get_parser():
parser_enter.set_defaults(func=command_enter)
parser_enter.add_argument(
'--fsid',
required=True,
help='cluster FSID')
parser_enter.add_argument(
'--name', '-n',
Expand All @@ -1766,7 +1800,6 @@ def _get_parser():
parser_ceph_volume.set_defaults(func=command_ceph_volume)
parser_ceph_volume.add_argument(
'--fsid',
required=True,
help='cluster FSID')
parser_ceph_volume.add_argument(
'--config-and-keyring',
Expand All @@ -1783,7 +1816,6 @@ def _get_parser():
help='systemd command (start, stop, restart, enable, disable, ...)')
parser_unit.add_argument(
'--fsid',
required=True,
help='cluster FSID')
parser_unit.add_argument(
'--name', '-n',
Expand All @@ -1795,7 +1827,6 @@ def _get_parser():
parser_logs.set_defaults(func=command_logs)
parser_logs.add_argument(
'--fsid',
required=True,
help='cluster FSID')
parser_logs.add_argument(
'--name', '-n',
Expand Down