From 3346765dd06ea2a972ddec964504711362e539b3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 10 Feb 2020 15:44:08 -0600 Subject: [PATCH] cephadm: shell: allow -e Set environment variables for shell commands. Signed-off-by: Sage Weil --- qa/workunits/cephadm/test_cephadm.sh | 1 + src/cephadm/cephadm | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/qa/workunits/cephadm/test_cephadm.sh b/qa/workunits/cephadm/test_cephadm.sh index 4de0d93985684..c5cd1894ce27b 100755 --- a/qa/workunits/cephadm/test_cephadm.sh +++ b/qa/workunits/cephadm/test_cephadm.sh @@ -109,6 +109,7 @@ systemctl status docker && ( $CEPHADM --docker version | grep 'ceph version' ) ## test shell before bootstrap, when crash dir isn't (yet) present on this host $CEPHADM shell --fsid $FSID -- ceph -v | grep 'ceph version' +$CEPHADM shell --fsid $FSID -e FOO=BAR -- printenv | grep FOO=BAR ## bootstrap ORIG_CONFIG=`mktemp -p $TMPDIR` diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 80ab398cf29bd..4bbb976095f77 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1488,8 +1488,9 @@ class CephContainer: volume_mounts={}, cname='', container_args=[], + envs=None, privileged=False): - # type: (str, str, List[str], Dict[str, str], str, List[str], Optional[bool]) -> None + # type: (str, str, List[str], Dict[str, str], str, List[str], Optional[List[str]], Optional[bool]) -> None self.image = image self.entrypoint = entrypoint self.args = args @@ -1497,6 +1498,7 @@ class CephContainer: self.cname = cname self.container_args = container_args self.privileged = privileged + self.envs = envs def run_cmd(self): # type: () -> List[str] @@ -1519,6 +1521,9 @@ class CephContainer: '-e', 'CONTAINER_IMAGE=%s' % self.image, '-e', 'NODE_NAME=%s' % get_hostname(), ] + if self.envs: + for e in self.envs: + envs.extend(['-e', e]) cname = ['--name', self.cname] if self.cname else [] return [ str(container_path), @@ -1547,6 +1552,9 @@ class CephContainer: '-e', 'CONTAINER_IMAGE=%s' % self.image, '-e', 'NODE_NAME=%s' % get_hostname(), ] + if self.envs: + for e in self.envs: + envs.extend(['-e', e]) cmd_args = [] # type: List[str] if cmd: cmd_args = ['-c'] + cmd @@ -2085,6 +2093,7 @@ def command_shell(): args=[], container_args=container_args, volume_mounts=mounts, + envs=args.env, privileged=True) command = c.shell_cmd(command) @@ -2996,6 +3005,11 @@ def _get_parser(): parser_shell.add_argument( '--keyring', '-k', help='ceph.keyring to pass through to the container') + parser_shell.add_argument( + '--env', '-e', + action='append', + default=[], + help='set environment variable') parser_shell.add_argument( 'command', nargs='*', help='command (optional)') -- 2.39.5