]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: shell: allow -e 33191/head
authorSage Weil <sage@redhat.com>
Mon, 10 Feb 2020 21:44:08 +0000 (15:44 -0600)
committerSage Weil <sage@redhat.com>
Tue, 11 Feb 2020 21:52:07 +0000 (15:52 -0600)
Set environment variables for shell commands.

Signed-off-by: Sage Weil <sage@redhat.com>
qa/workunits/cephadm/test_cephadm.sh
src/cephadm/cephadm

index 4de0d93985684663156cb2354ab4e3bddaf619eb..c5cd1894ce27bc2b425e873c54d7539c36d43e60 100755 (executable)
@@ -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`
index 80ab398cf29bdc44ccd609be6297f829a0ea2bcc..4bbb976095f77f00275e1a48f08eb6b905adb712 100755 (executable)
@@ -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)')