Browse Source

Fix zookeeper tests

Change-Id: I90a609992a41a2802245a9b80b95c9eb16203bb4
Georgy Dyuldin 2 years ago
parent
commit
7bb3233061

+ 10
- 6
plugin_test/vapor/vapor/fixtures/system_services.py View File

@@ -16,16 +16,20 @@ import pytest
16 16
 
17 17
 
18 18
 @pytest.fixture
19
-def znodes_list(nodes_ips):
20
-    hosts_list = ""
19
+def zoo_client(nodes_ips):
20
+    hosts_list = []
21 21
     contrail_controllers_fqdns = settings.CONTRAIL_ROLES_DISTRIBUTION[
22 22
         settings.ROLE_CONTRAIL_CONTROLLER]
23 23
     for name in nodes_ips:
24 24
         if name in contrail_controllers_fqdns:
25
-            hosts_list += "{}:{},".format(nodes_ips[name][0],
26
-                                          settings.ZOOKEEPER_PORT)
27
-    hosts_list = hosts_list[:-1]
28
-    zk = client.KazooClient(hosts=hosts_list)
25
+            hosts_list.append("{}:{}".format(nodes_ips[name][0],
26
+                                             settings.ZOOKEEPER_PORT))
27
+    return client.KazooClient(hosts=','.join(hosts_list))
28
+
29
+
30
+@pytest.fixture
31
+def znodes_list(zoo_client):
32
+    zk = zoo_client
29 33
     zk.start()
30 34
     znodes_list_ = zk.get_children("/")
31 35
     zk.stop()

+ 26
- 3
plugin_test/vapor/vapor/tests/test_smoke.py View File

@@ -10,8 +10,12 @@
10 10
 # License for the specific language governing permissions and limitations
11 11
 # under the License.
12 12
 
13
+import collections
14
+import re
15
+
13 16
 from hamcrest import (assert_that, has_item, has_entry, is_not, empty,
14
-                      has_property, contains_inanyorder)  # noqa: H301
17
+                      has_property, contains_inanyorder, has_length,
18
+                      greater_than)  # noqa: H301
15 19
 import jmespath
16 20
 import pycontrail.types as types
17 21
 import pytest
@@ -173,5 +177,24 @@ def test_contrail_alarms_is_empty(client_contrail_analytics):
173 177
 
174 178
 
175 179
 def test_zookeeper_status(znodes_list):
176
-    expected_znodes_list = settings.ZOOKEEPER_NODES
177
-    assert_that(znodes_list, contains_inanyorder(*expected_znodes_list))
180
+    expected_znodes_list = set(settings.ZOOKEEPER_NODES)
181
+    znodes_list = set(znodes_list)
182
+    min_intersection = len(znodes_list) // 2
183
+    assert_that(znodes_list & expected_znodes_list,
184
+                has_length(greater_than(min_intersection)))
185
+
186
+
187
+def test_zookeeper_leader_followers(zoo_client):
188
+    """Check that only one zookeeper host has leader mode."""
189
+    hosts = ['{}:{}'.format(ip, port) for (ip, port) in zoo_client.hosts]
190
+    pattern = re.compile('Mode: (follower|leader)')
191
+    modes = collections.defaultdict(set)
192
+    for host in hosts:
193
+        zoo_client.set_hosts(host)
194
+        zoo_client.start()
195
+        result = zoo_client.command('stat')
196
+        mode = pattern.search(result).group(1)
197
+        modes[mode].add(host)
198
+        zoo_client.stop()
199
+    zoo_client.close()
200
+    assert_that(modes['leader'], has_length(1))

Loading…
Cancel
Save