Browse Source

Fix security group tests

Change-Id: I13e05c0b73fe8faef2bf5dd5d54eadfac416dfe2
Georgy Dyuldin 2 years ago
parent
commit
933873f36f

+ 2
- 2
plugin_test/vapor/vapor/fixtures/contrail_resources.py View File

@@ -40,7 +40,7 @@ def contrail_2_networks(create_network, create_subnet):
40 40
 def contrail_2_servers_different_networks(
41 41
         request,
42 42
         flavor,
43
-        security_group,
43
+        neutron_security_group,
44 44
         sorted_hypervisors,
45 45
         contrail_2_networks,
46 46
         server_steps):
@@ -91,7 +91,7 @@ def contrail_2_servers_different_networks(
91 91
             networks=[network],
92 92
             keypair=keypair,
93 93
             availability_zone='nova:{}'.format(hypervisor.service['host']),
94
-            security_groups=[security_group],
94
+            security_groups=[neutron_security_group],
95 95
             username=username,
96 96
             password=password,
97 97
             check=False)[0]

+ 18
- 5
plugin_test/vapor/vapor/helpers/connectivity.py View File

@@ -13,7 +13,7 @@
13 13
 import contextlib
14 14
 import time
15 15
 
16
-from hamcrest import is_
16
+from hamcrest import assert_that, is_, greater_than, has_value
17 17
 from stepler.third_party import ping
18 18
 from stepler.third_party import tcpdump
19 19
 from stepler.third_party import waiter
@@ -108,13 +108,14 @@ def start_port_listener(server_ssh,
108 108
 
109 109
 
110 110
 @contextlib.contextmanager
111
-def calc_packets_count(os_faults_steps, nodes, iface, filters):
111
+def calc_packets_count(os_faults_steps, nodes, iface, filters,
112
+                       max_packets=10000):
112 113
     """CM to calc packages count on nodes' iface.
113 114
 
114 115
     Returns dict: fqdn -> captured packets count.
115 116
     """
116 117
     tcpdump_base_path = os_faults_steps.start_tcpdump(
117
-        nodes, '-i {0} {1}'.format(iface, filters))
118
+        nodes, '-i {0} {1} -c {2}'.format(iface, filters, max_packets))
118 119
     result = {node.fqdn: 0 for node in nodes}
119 120
     yield result
120 121
     os_faults_steps.stop_tcpdump(nodes, tcpdump_base_path)
@@ -138,8 +139,20 @@ def start_iperf_pair(client_ssh, server_ssh, ip, port, udp=False, timeout=10):
138 139
 
139 140
     server_ssh.background_call(server_cmd.format(proto=proto, port=port))
140 141
 
141
-    if not udp:
142
-        time.sleep(10)
142
+    # if not udp:
143
+    time.sleep(10)
143 144
 
144 145
     client_ssh.background_call(
145 146
         client_cmd.format(proto=proto, ip=ip, port=port, time=timeout))
147
+
148
+
149
+def check_packets_on_iface(os_faults_steps, node, iface, filters,
150
+                           should_be=True):
151
+    with calc_packets_count(os_faults_steps, node, iface,
152
+                            filters) as tcp_counts:
153
+        time.sleep(1)
154
+    if should_be:
155
+        matcher = greater_than(0)
156
+    else:
157
+        matcher = is_(0)
158
+    assert_that(tcp_counts, has_value(matcher), 'Wrong packets count')

+ 35
- 39
plugin_test/vapor/vapor/tests/common/test_security_group.py View File

@@ -310,7 +310,7 @@ def test_security_group_rules_uuid_in_contrail_and_neutron(contrail_api_client,
310 310
     ids=['ubuntu'])
311 311
 def test_add_remove_security_group_with_active_flow(
312 312
         contrail_2_servers_diff_nets_with_floating,
313
-        security_group,
313
+        neutron_security_group,
314 314
         contrail_api_client,
315 315
         contrail_network_policy,
316 316
         set_network_policy,
@@ -345,7 +345,8 @@ def test_add_remove_security_group_with_active_flow(
345 345
         set_network_policy(network, contrail_network_policy)
346 346
 
347 347
     # Add rule to group
348
-    contrail_sg = contrail_api_client.security_group_read(id=security_group.id)
348
+    contrail_sg = contrail_api_client.security_group_read(
349
+        id=neutron_security_group['id'])
349 350
     sg_entries = contrail_sg.security_group_entries
350 351
     rules = [
351 352
         types.PolicyRuleType(
@@ -401,6 +402,12 @@ def test_add_remove_security_group_with_active_flow(
401 402
         server2_ssh = enter(server_steps.get_server_ssh(server2))
402 403
 
403 404
         # Start TCP and UDP traffic
405
+        connectivity.start_iperf_pair(
406
+            client_ssh=server2_ssh,
407
+            server_ssh=server1_ssh,
408
+            ip=ip1,
409
+            port=TCP_PORT,
410
+            timeout=60 * 1000)
404 411
         connectivity.start_iperf_pair(
405 412
             client_ssh=server1_ssh,
406 413
             server_ssh=server2_ssh,
@@ -408,46 +415,35 @@ def test_add_remove_security_group_with_active_flow(
408 415
             port=UDP_PORT,
409 416
             udp=True,
410 417
             timeout=60 * 1000)
411
-        connectivity.start_iperf_pair(
412
-            client_ssh=server2_ssh,
413
-            server_ssh=server1_ssh,
414
-            ip=ip1,
415
-            port=TCP_PORT,
416
-            timeout=60 * 1000)
417 418
 
418 419
         # Check that some packets are captured
419
-        with connectivity.calc_packets_count(os_faults_steps, computes[0],
420
-                                             ifaces[0],
421
-                                             tcp_filter) as tcp_counts:
422
-            with connectivity.calc_packets_count(os_faults_steps, computes[1],
423
-                                                 ifaces[1],
424
-                                                 udp_filter) as udp_counts:
425
-                time.sleep(1)
426
-        assert_that(next(iter(tcp_counts.values())), greater_than(0))
427
-        assert_that(next(iter(udp_counts.values())), greater_than(0))
420
+        connectivity.check_packets_on_iface(os_faults_steps, computes[0],
421
+                                            ifaces[0], tcp_filter)
422
+        connectivity.check_packets_on_iface(os_faults_steps, computes[1],
423
+                                            ifaces[1], udp_filter)
428 424
 
429 425
         # Remove security group from server1
430
-        server1.remove_security_group(security_group.id)
431
-
432
-        with connectivity.calc_packets_count(os_faults_steps, computes[0],
433
-                                             ifaces[0],
434
-                                             tcp_filter) as tcp_counts:
435
-            with connectivity.calc_packets_count(os_faults_steps, computes[1],
436
-                                                 ifaces[1],
437
-                                                 udp_filter) as udp_counts:
438
-                time.sleep(1)
439
-        assert_that(next(iter(tcp_counts.values())), equal_to(0))
440
-        assert_that(next(iter(udp_counts.values())), equal_to(0))
426
+        server1.remove_security_group(neutron_security_group['id'])
427
+
428
+        connectivity.check_packets_on_iface(
429
+            os_faults_steps,
430
+            computes[0],
431
+            ifaces[0],
432
+            tcp_filter,
433
+            should_be=False)
434
+        connectivity.check_packets_on_iface(
435
+            os_faults_steps,
436
+            computes[1],
437
+            ifaces[1],
438
+            udp_filter,
439
+            should_be=False)
441 440
 
442 441
         # Add security group from server1
443
-        server1.add_security_group(security_group.id)
444
-
445
-        with connectivity.calc_packets_count(os_faults_steps, computes[0],
446
-                                             ifaces[0],
447
-                                             tcp_filter) as tcp_counts:
448
-            with connectivity.calc_packets_count(os_faults_steps, computes[1],
449
-                                                 ifaces[1],
450
-                                                 udp_filter) as udp_counts:
451
-                time.sleep(1)
452
-        assert_that(next(iter(tcp_counts.values())), greater_than(0))
453
-        assert_that(next(iter(udp_counts.values())), greater_than(0))
442
+        server1.add_security_group(neutron_security_group['id'])
443
+
444
+        time.sleep(10)
445
+
446
+        connectivity.check_packets_on_iface(os_faults_steps, computes[0],
447
+                                            ifaces[0], tcp_filter)
448
+        connectivity.check_packets_on_iface(os_faults_steps, computes[1],
449
+                                            ifaces[1], udp_filter)

Loading…
Cancel
Save