Skip to content

Commit

Permalink
cephadm: support multiple mounts when running shell
Browse files Browse the repository at this point in the history
This commit adds the multiple mounts support when running the
interactive shell.

ie:
```
--mount /foo /bar:/bar:z
```

Keeping default destination `/mnt` when no destination is passed for
backward compatibility. In the above example `/foo` will be mounted in
`/mnt/foo` and `/bar` in `/bar`

Signed-off-by: Guillaume Abrioux <[email protected]>
  • Loading branch information
guits committed Sep 15, 2020
1 parent ebdb8e5 commit 3ed3cff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc/man/8/cephadm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Synopsis
| **cephadm** **run** [-h] --name NAME --fsid FSID
| **cephadm** **shell** [-h] [--fsid FSID] [--name NAME] [--config CONFIG]
[--keyring KEYRING] [--mount MOUNT] [--env ENV]
[--keyring KEYRING] --mount [MOUNT [MOUNT ...]] [--env ENV]
[--] [command [command ...]]
| **cephadm** **enter** [-h] [--fsid FSID] --name NAME [command [command ...]]
Expand Down
3 changes: 2 additions & 1 deletion qa/workunits/cephadm/test_cephadm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fi

# TMPDIR for test data
[ -d "$TMPDIR" ] || TMPDIR=$(mktemp -d tmp.$SCRIPT_NAME.XXXXXX)
[ -d "$TMPDIR_TEST_MULTIPLE_MOUNTS" ] || TMPDIR_TEST_MULTIPLE_MOUNTS=$(mktemp -d tmp.$SCRIPT_NAME.XXXXXX)

function cleanup()
{
Expand Down Expand Up @@ -388,7 +389,7 @@ $CEPHADM shell --fsid $FSID -- true
$CEPHADM shell --fsid $FSID -- test -d /var/log/ceph
expect_false $CEPHADM --timeout 10 shell --fsid $FSID -- sleep 60
$CEPHADM --timeout 60 shell --fsid $FSID -- sleep 10
$CEPHADM shell --fsid $FSID --mount $TMPDIR -- stat /mnt/$(basename $TMPDIR)
$CEPHADM shell --fsid $FSID --mount $TMPDIR $TMPDIR_TEST_MULTIPLE_MOUNTS -- stat /mnt/$(basename $TMPDIR)

## enter
expect_false $CEPHADM enter
Expand Down
18 changes: 14 additions & 4 deletions src/cephadm/cephadm
Original file line number Diff line number Diff line change
Expand Up @@ -3308,9 +3308,15 @@ def command_shell():
if args.keyring:
mounts[pathify(args.keyring)] = '/etc/ceph/ceph.keyring:z'
if args.mount:
mount = pathify(args.mount)
filename = os.path.basename(mount)
mounts[mount] = '/mnt/{}:z'.format(filename)
for _mount in args.mount:
split_src_dst = _mount.split(':')
mount = pathify(split_src_dst[0])
filename = os.path.basename(split_src_dst[0])
if len(split_src_dst) > 1:
dst = split_src_dst[1] + ':z' if len(split_src_dst) == 3 else split_src_dst[1]
mounts[mount] = dst
else:
mounts[mount] = '/mnt/{}:z'.format(filename)
if args.command:
command = args.command
else:
Expand Down Expand Up @@ -5454,7 +5460,11 @@ def _get_parser():
help='ceph.keyring to pass through to the container')
parser_shell.add_argument(
'--mount', '-m',
help='mount a file or directory under /mnt in the container')
help=("mount a file or directory in the container. "
"Support multiple mounts. "
"ie: `--mount /foo /bar:/bar`. "
"When no destination is passed, default is /mnt"),
nargs='+')
parser_shell.add_argument(
'--env', '-e',
action='append',
Expand Down

0 comments on commit 3ed3cff

Please sign in to comment.