]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc: make get_mons() cluster-aware
authorJosh Durgin <jdurgin@redhat.com>
Tue, 15 Mar 2016 21:26:02 +0000 (14:26 -0700)
committerJosh Durgin <jdurgin@redhat.com>
Mon, 11 Apr 2016 21:36:04 +0000 (14:36 -0700)
Use the is_type() helper to keep the logic in one place.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/misc.py
teuthology/test/test_misc.py

index 4947b2e0ac426121f6d16f1cf289330ebdf42db8..2df4b1fd3ff560f59c8be0074f1a3fad811a41eb 100644 (file)
@@ -272,9 +272,10 @@ def get_mons(roles, ips):
     mons = {}
     mon_ports = {}
     mon_id = 0
+    is_mon = is_type('mon')
     for idx, roles in enumerate(roles):
         for role in roles:
-            if not role.startswith('mon.'):
+            if not is_mon(role):
                 continue
             if ips[idx] not in mon_ports:
                 mon_ports[ips[idx]] = 6789
index 645cb53990839c5138c148cb14f8a5efcaa9a84a..6b392bfbe2bca276595fcc3616ebd1ad50f0d1f4 100644 (file)
@@ -128,6 +128,27 @@ def test_is_type():
     assert not is_client('hadoop.master.0')
 
 
+def test_get_mons():
+    ips = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
+    addrs = ['1.1.1.1:6789', '1.1.1.1:6790', '1.1.1.1:6791']
+
+    mons = misc.get_mons([['mon.a']], ips)
+    assert mons == {'mon.a': addrs[0]}
+
+    mons = misc.get_mons([['cluster-a.mon.foo', 'client.b'], ['osd.0']], ips)
+    assert mons == {'cluster-a.mon.foo': addrs[0]}
+
+    mons = misc.get_mons([['mon.a', 'mon.b', 'ceph.mon.c']], ips)
+    assert mons == {'mon.a': addrs[0],
+                    'mon.b': addrs[1],
+                    'ceph.mon.c': addrs[2]}
+
+    mons = misc.get_mons([['mon.a'], ['mon.b'], ['ceph.mon.c']], ips)
+    assert mons == {'mon.a': addrs[0],
+                    'mon.b': ips[1] + ':6789',
+                    'ceph.mon.c': ips[2] + ':6789'}
+
+
 class TestHostnames(object):
     def setup(self):
         config._conf = dict()