]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-daemon: Allow env var for setting the used image 31913/head
authorThomas Bechtold <tbechtold@suse.com>
Thu, 28 Nov 2019 05:08:42 +0000 (06:08 +0100)
committerThomas Bechtold <tbechtold@suse.com>
Thu, 28 Nov 2019 08:06:18 +0000 (09:06 +0100)
Instead of always adding "--image my-custom-image" when calling
ceph-daemon with a non-standard image, allow to set the environment
variable called CEPH_DAEMON_IMAGE which will adjust the --image
default.
That way, the command line arguments when using ceph-daemon with a
custom image are a bit shorter.

Signed-off-by: Thomas Bechtold <tbechtold@suse.com>
qa/standalone/test_ceph_daemon.sh
src/ceph-daemon/ceph-daemon
src/ceph-daemon/tests/test_ceph_daemon.py
src/ceph-daemon/tox.ini

index 907b2d12dffd19343c38234af9f5f59c4d827ff6..7445eff3a201a33fead8f4fb9a1b267e98c9ef81 100755 (executable)
@@ -76,7 +76,7 @@ function expect_false()
 }
 
 ## version + --image
-$SUDO $CEPH_DAEMON --image $IMAGE_NAUTILUS version \
+$SUDO CEPH_DAEMON_IMAGE=$IMAGE_NAUTILUS $CEPH_DAEMON version \
     | grep 'ceph version 14'
 $SUDO $CEPH_DAEMON --image $IMAGE_MIMIC version \
     | grep 'ceph version 13'
index 4ff8b6104cc226400023e3acdc262461651bfc08..e1520b424367a7e2df668801cc51b38a8c164ddf 100755 (executable)
@@ -1623,8 +1623,9 @@ def _get_parser():
         formatter_class=argparse.ArgumentDefaultsHelpFormatter)
     parser.add_argument(
         '--image',
-        default=DEFAULT_IMAGE,
-        help='container image')
+        default=os.environ.get('CEPH_DAEMON_IMAGE', DEFAULT_IMAGE),
+        help='container image. Can also be set via the "CEPH_DAEMON_IMAGE" '
+        'env var')
     parser.add_argument(
         '--docker',
         action='store_true',
index 65f98e47fc8767b5a365e0cce4e2770eba011aea..3e812c3eaccbcc7f43d5a10cc9a19c4856f04553 100644 (file)
@@ -1,5 +1,7 @@
 import imp
 import unittest
+import mock
+import os
 
 
 cd = imp.load_source("ceph-daemon", "ceph-daemon")
@@ -8,3 +10,14 @@ cd = imp.load_source("ceph-daemon", "ceph-daemon")
 class TestCephDaemon(unittest.TestCase):
     def test_is_fsid(self):
         self.assertFalse(cd.is_fsid('no-uuid'))
+
+    def test__get_parser_image(self):
+        p = cd._get_parser()
+        args = p.parse_args(['--image', 'foo', 'version'])
+        assert args.image == 'foo'
+
+    @mock.patch.dict(os.environ,{'CEPH_DAEMON_IMAGE':'bar'})
+    def test__get_parser_image_with_envvar(self):
+        p = cd._get_parser()
+        args = p.parse_args(['version'])
+        assert args.image == 'bar'
index 9ade4d4300127d8f8386bff947c278cf92746834..7407aac9c89944ee9709a5364769213d7ea46b5a 100644 (file)
@@ -4,7 +4,9 @@ envlist = py27, py3, mypy
 [testenv]
 skipsdist=true
 skip_install=true
-deps = pytest
+deps =
+  pytest
+  mock
 commands=pytest {posargs}
 
 [testenv:mypy]