]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Fix Python2.7 isssue 32198/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 16 Dec 2019 11:19:03 +0000 (12:19 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Mon, 16 Dec 2019 11:19:03 +0000 (12:19 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/cephadm/cephadm
src/cephadm/tests/test_ceph_daemon.py

index 2f436f8c43c4ccf5c9854d71a4a038061e30c091..9fea0b3add05e476a34f1b00823d903059a7d65d 100755 (executable)
@@ -75,7 +75,7 @@ class Error(Exception):
 
 
 class Ceph(object):
-    daemons = ['mon', 'mgr', 'mds', 'osd', 'rgw', 'rbd-mirror']
+    daemons = ('mon', 'mgr', 'mds', 'osd', 'rgw', 'rbd-mirror')
 
 
 class Monitoring(object):
@@ -1497,7 +1497,7 @@ def command_deploy():
     # type: () -> None
     (daemon_type, daemon_id) = args.name.split('.', 1)
 
-    supported_daemons = Ceph.daemons.copy()
+    supported_daemons = list(Ceph.daemons)
     supported_daemons.extend(Monitoring.components)
 
     if daemon_type not in supported_daemons:
@@ -1991,14 +1991,13 @@ def command_check_host():
 class CustomValidation(argparse.Action):
 
     def _check_name(self, values):
-
         try:
             (daemon_type, daemon_id) = values.split('.', 1)
         except ValueError:
             raise argparse.ArgumentError(self,
                                          "must be of the format <type>.<id>. For example, osd.1 or prometheus.myhost.com")
 
-        daemons = Ceph.daemons.copy()
+        daemons = list(Ceph.daemons)
         daemons.extend(Monitoring.components.keys())
 
         if daemon_type not in daemons:
index db94ba5d099f8beb304b179a68be0b246f9de4e6..8adafe6fb7f3d62786cd6aaf348f84fc7abd4938 100644 (file)
@@ -1,8 +1,11 @@
+import argparse
 import mock
 import os
 import sys
 import unittest
 
+import pytest
+
 if sys.version_info >= (3, 3):
     from importlib.machinery import SourceFileLoader
     cd = SourceFileLoader('cephadm', 'cephadm').load_module()
@@ -24,3 +27,10 @@ class TestCephDaemon(unittest.TestCase):
         p = cd._get_parser()
         args = p.parse_args(['version'])
         assert args.image == 'bar'
+
+    def test_CustomValidation(self):
+        p = cd._get_parser()
+        assert p.parse_args(['deploy', '--name', 'mon.a', '--fsid', 'fsid'])
+
+        with pytest.raises(SystemExit):
+            p.parse_args(['deploy', '--name', 'wrong', '--fsid', 'fsid'])