Skip to content

Commit 833229c

Browse files
Gaurav AradhyeSangeetha
authored andcommitted
CLOUDSTACK-4637: Fix failures in test_egress_fw_rules.py
Removed log_test_exceptions which did not add any value. Skipped few tests which are incomplete. Added timeout logic and to wait for router to boot. (cherry picked from commit a65f1eb) Signed-off-by: Sangeetha <sangeetha.hariharan@citrix.com>
1 parent 7ef4c7e commit 833229c

1 file changed

Lines changed: 42 additions & 66 deletions

File tree

‎test/integration/component/test_egress_fw_rules.py‎

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@
4242
from marvin.remoteSSHClient import remoteSSHClient
4343
import time
4444

45-
def log_test_exceptions(func):
46-
def test_wrap_exception_log(self, *args, **kwargs):
47-
try:
48-
func(self, *args, **kwargs)
49-
except Exception as e:
50-
self.debug('Test %s Failed due to Exception=%s' % (func, e))
51-
raise e
52-
test_wrap_exception_log.__doc__ = func.__doc__
53-
return test_wrap_exception_log
54-
5545
class Services:
5646
"""Test service data: Egress Firewall rules Tests for Advance Zone.
5747
"""
@@ -117,6 +107,7 @@ def __init__(self):
117107
"serviceCapabilityList": {
118108
"SourceNat": {
119109
"SupportedSourceNatTypes": "peraccount",
110+
"RedundantRouter": "true"
120111
}
121112
},
122113
},
@@ -186,7 +177,7 @@ def create_network_offering(self, egress_policy=True, RR=False):
186177

187178
if RR:
188179
self.debug("Redundant Router Enabled")
189-
self.services["network_offering"]["serviceCapabilityList"]["RedundantRouter"] = "true"
180+
self.services["network_offering"]["serviceCapabilityList"]["SourceNat"]["RedundantRouter"] = "true"
190181

191182
self.network_offering = NetworkOffering.create(self.apiclient,
192183
self.services["network_offering"],
@@ -288,16 +279,31 @@ def exec_script_on_user_vm(self, script, exec_cmd_params, expected_result, negat
288279
ssh.execute('chmod +x %s' % script_file)
289280
self.debug("%s %s" % (script_file, exec_cmd_params))
290281

291-
self.debug('sleep %s seconds for egress rule to affect on Router.' % self.services['sleep'])
292-
time.sleep(self.services['sleep'])
293-
294-
result = ssh.execute("%s %s" % (script_file, exec_cmd_params))
295-
self.debug('Result is=%s' % result)
296-
297282
exec_success = False
298-
if str(result).strip() == expected_result:
299-
self.debug('script executed successfully exec_success=True')
300-
exec_success = True
283+
#Timeout set to 3 minutes
284+
timeout = 180
285+
while timeout:
286+
self.debug('sleep %s seconds for egress rule to affect on Router.' % self.services['sleep'])
287+
time.sleep(self.services['sleep'])
288+
result = ssh.execute("%s %s" % (script_file, exec_cmd_params))
289+
self.debug('Result is=%s' % result)
290+
self.debug('Expected result is=%s' % expected_result)
291+
292+
if str(result).strip() == expected_result:
293+
exec_success = True
294+
break
295+
else:
296+
if result == []:
297+
self.fail("Router is not accessible")
298+
# This means router network did not come up as yet loop back.
299+
if "send" in result[0]:
300+
timeout -= self.services['sleep']
301+
else: # Failed due to some other error
302+
break
303+
#end while
304+
305+
if timeout == 0:
306+
self.fail("Router network failed to come up after 3 minutes.")
301307

302308
ssh.execute('rm -rf %s' % script_file)
303309

@@ -371,18 +377,17 @@ def tearDown(self):
371377
self.virtual_machine.delete(self.apiclient)
372378
wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"])
373379
self.debug("Sleep for VM cleanup to complete.")
374-
time.sleep(self.services['sleep'])
380+
#time.sleep(self.services['sleep'])
375381
self.network.delete(self.apiclient)
376-
wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"])
377382
self.debug("Sleep for Network cleanup to complete.")
378-
time.sleep(self.services['sleep'])
383+
wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"])
384+
#time.sleep(self.services['sleep'])
379385
cleanup_resources(self.apiclient, reversed(self.cleanup))
380386
self.debug("Cleanup complete!")
381387
except Exception as e:
382388
self.debug("Warning! Exception in tearDown: %s" % e)
383389

384390
@attr(tags = ["advanced"])
385-
@log_test_exceptions
386391
def test_01_egress_fr1(self):
387392
"""Test By-default the communication from guest n/w to public n/w is allowed.
388393
"""
@@ -398,7 +403,6 @@ def test_01_egress_fr1(self):
398403
negative_test=False)
399404

400405
@attr(tags = ["advanced"])
401-
@log_test_exceptions
402406
def test_01_1_egress_fr1(self):
403407
"""Test By-default the communication from guest n/w to public n/w is NOT allowed.
404408
"""
@@ -415,7 +419,6 @@ def test_01_1_egress_fr1(self):
415419

416420

417421
@attr(tags = ["advanced"])
418-
@log_test_exceptions
419422
def test_02_egress_fr2(self):
420423
"""Test Allow Communication using Egress rule with CIDR + Port Range + Protocol.
421424
"""
@@ -433,7 +436,6 @@ def test_02_egress_fr2(self):
433436
negative_test=False)
434437

435438
@attr(tags = ["advanced"])
436-
@log_test_exceptions
437439
def test_02_1_egress_fr2(self):
438440
"""Test Allow Communication using Egress rule with CIDR + Port Range + Protocol.
439441
"""
@@ -450,9 +452,7 @@ def test_02_1_egress_fr2(self):
450452
"['0']",
451453
negative_test=False)
452454

453-
454455
@attr(tags = ["advanced"])
455-
@log_test_exceptions
456456
def test_03_egress_fr3(self):
457457
"""Test Communication blocked with network that is other than specified
458458
"""
@@ -474,7 +474,6 @@ def test_03_egress_fr3(self):
474474
negative_test=False)
475475

476476
@attr(tags = ["advanced"])
477-
@log_test_exceptions
478477
def test_03_1_egress_fr3(self):
479478
"""Test Communication blocked with network that is other than specified
480479
"""
@@ -483,7 +482,7 @@ def test_03_1_egress_fr3(self):
483482
# 3. create egress rule with specific CIDR + port range.
484483
# 4. login to VM.
485484
# 5. Try to reach to public network with other protocol/port range
486-
self.create_vm()
485+
self.create_vm(egress_policy=False)
487486
self.exec_script_on_user_vm('ping -c 1 www.google.com',
488487
"| grep -oP \'\d+(?=% packet loss)\'",
489488
"['100']",
@@ -495,9 +494,7 @@ def test_03_1_egress_fr3(self):
495494
"['failed:']",
496495
negative_test=False)
497496

498-
499497
@attr(tags = ["advanced"])
500-
@log_test_exceptions
501498
def test_04_egress_fr4(self):
502499
"""Test Create Egress rule and check the Firewall_Rules DB table
503500
"""
@@ -517,10 +514,10 @@ def test_04_egress_fr4(self):
517514
"Check DB Query result set")
518515
self.assertEqual(qresultset[0][0],
519516
"Firewall",
520-
"DB results not matching")
517+
"DB results not matching, expected: Firewall found: %s " % qresultset[0][0])
521518
self.assertEqual(qresultset[0][1],
522519
"Egress",
523-
"DB results not matching")
520+
"DB results not matching, expected: Egress, found: %s" % qresultset[0][1])
524521
qresultset = self.dbclient.execute("select egress_default_policy from network_offerings where name='%s';" % self.network_offering.name)
525522
self.assertEqual(isinstance(qresultset, list),
526523
True,
@@ -530,12 +527,11 @@ def test_04_egress_fr4(self):
530527
0,
531528
"Check DB Query result set")
532529
self.assertEqual(qresultset[0][0],
533-
"1",
534-
"DB results not matching")
530+
1,
531+
"DB results not matching, expected: 1, found: %s" % qresultset[0][0])
535532

536533

537534
@attr(tags = ["advanced"])
538-
@log_test_exceptions
539535
def test_04_1_egress_fr4(self):
540536
"""Test Create Egress rule and check the Firewall_Rules DB table
541537
"""
@@ -555,10 +551,10 @@ def test_04_1_egress_fr4(self):
555551
"Check DB Query result set")
556552
self.assertEqual(qresultset[0][0],
557553
"Firewall",
558-
"DB results not matching")
554+
"DB results not matching, expected: Firewall found: %s " % qresultset[0][0])
559555
self.assertEqual(qresultset[0][1],
560556
"Egress",
561-
"DB results not matching")
557+
"DB results not matching, expected: Egress, found: %s" % qresultset[0][1])
562558
qresultset = self.dbclient.execute("select egress_default_policy from network_offerings where name='%s';" % self.network_offering.name)
563559
self.assertEqual(isinstance(qresultset, list),
564560
True,
@@ -568,13 +564,11 @@ def test_04_1_egress_fr4(self):
568564
0,
569565
"Check DB Query result set")
570566
self.assertEqual(qresultset[0][0],
571-
"0",
572-
"DB results not matching")
573-
574-
567+
0,
568+
"DB results not matching, expected: 0, found: %s" % qresultset[0][0])
575569

570+
@unittest.skip("Skip")
576571
@attr(tags = ["advanced"])
577-
@log_test_exceptions
578572
def test_05_egress_fr5(self):
579573
"""Test Create Egress rule and check the IP tables
580574
"""
@@ -592,8 +586,8 @@ def test_05_egress_fr5(self):
592586
#TODO: Query VR for expected route rules.
593587

594588

589+
@unittest.skip("Skip")
595590
@attr(tags = ["advanced"])
596-
@log_test_exceptions
597591
def test_05_1_egress_fr5(self):
598592
"""Test Create Egress rule and check the IP tables
599593
"""
@@ -612,7 +606,6 @@ def test_05_1_egress_fr5(self):
612606

613607

614608
@attr(tags = ["advanced"])
615-
@log_test_exceptions
616609
def test_06_egress_fr6(self):
617610
"""Test Create Egress rule without CIDR
618611
"""
@@ -629,7 +622,6 @@ def test_06_egress_fr6(self):
629622
negative_test=False)
630623

631624
@attr(tags = ["advanced"])
632-
@log_test_exceptions
633625
def test_06_1_egress_fr6(self):
634626
"""Test Create Egress rule without CIDR
635627
"""
@@ -645,10 +637,7 @@ def test_06_1_egress_fr6(self):
645637
"['0']",
646638
negative_test=False)
647639

648-
649-
650640
@attr(tags = ["advanced"])
651-
@log_test_exceptions
652641
def test_07_egress_fr7(self):
653642
"""Test Create Egress rule without End Port
654643
"""
@@ -665,7 +654,6 @@ def test_07_egress_fr7(self):
665654
negative_test=False)
666655

667656
@attr(tags = ["advanced"])
668-
@log_test_exceptions
669657
def test_07_1_egress_fr7(self):
670658
"""Test Create Egress rule without End Port
671659
"""
@@ -681,9 +669,8 @@ def test_07_1_egress_fr7(self):
681669
"['failed:']",
682670
negative_test=False)
683671

684-
672+
@unittest.skip("Skip")
685673
@attr(tags = ["advanced"])
686-
@log_test_exceptions
687674
def test_08_egress_fr8(self):
688675
"""Test Port Forwarding and Egress Conflict
689676
"""
@@ -694,8 +681,8 @@ def test_08_egress_fr8(self):
694681
self.create_vm(pfrule=True)
695682
self.createEgressRule()
696683

684+
@unittest.skip("Skip")
697685
@attr(tags = ["advanced"])
698-
@log_test_exceptions
699686
def test_08_1_egress_fr8(self):
700687
"""Test Port Forwarding and Egress Conflict
701688
"""
@@ -708,7 +695,6 @@ def test_08_1_egress_fr8(self):
708695

709696

710697
@attr(tags = ["advanced"])
711-
@log_test_exceptions
712698
def test_09_egress_fr9(self):
713699
"""Test Delete Egress rule
714700
"""
@@ -733,7 +719,6 @@ def test_09_egress_fr9(self):
733719
negative_test=False)
734720

735721
@attr(tags = ["advanced"])
736-
@log_test_exceptions
737722
def test_09_1_egress_fr9(self):
738723
"""Test Delete Egress rule
739724
"""
@@ -759,7 +744,6 @@ def test_09_1_egress_fr9(self):
759744

760745

761746
@attr(tags = ["advanced"])
762-
@log_test_exceptions
763747
def test_10_egress_fr10(self):
764748
"""Test Invalid CIDR and Invalid Port ranges
765749
"""
@@ -771,7 +755,6 @@ def test_10_egress_fr10(self):
771755
self.assertRaises(Exception, self.createEgressRule, '10.2.2.0/24')
772756

773757
@attr(tags = ["advanced"])
774-
@log_test_exceptions
775758
def test_10_1_egress_fr10(self):
776759
"""Test Invalid CIDR and Invalid Port ranges
777760
"""
@@ -784,7 +767,6 @@ def test_10_1_egress_fr10(self):
784767

785768

786769
@attr(tags = ["advanced"])
787-
@log_test_exceptions
788770
def test_11_egress_fr11(self):
789771
"""Test Regression on Firewall + PF + LB + SNAT
790772
"""
@@ -795,7 +777,6 @@ def test_11_egress_fr11(self):
795777
self.create_vm(pfrule=True)
796778

797779
@attr(tags = ["advanced"])
798-
@log_test_exceptions
799780
def test_11_1_egress_fr11(self):
800781
"""Test Regression on Firewall + PF + LB + SNAT
801782
"""
@@ -807,7 +788,6 @@ def test_11_1_egress_fr11(self):
807788

808789

809790
@attr(tags = ["advanced"])
810-
@log_test_exceptions
811791
def test_12_egress_fr12(self):
812792
"""Test Reboot Router
813793
"""
@@ -825,7 +805,6 @@ def test_12_egress_fr12(self):
825805
negative_test=False)
826806

827807
@attr(tags = ["advanced"])
828-
@log_test_exceptions
829808
def test_12_1_egress_fr12(self):
830809
"""Test Reboot Router
831810
"""
@@ -842,9 +821,7 @@ def test_12_1_egress_fr12(self):
842821
"['0']",
843822
negative_test=False)
844823

845-
846824
@attr(tags = ["advanced"])
847-
@log_test_exceptions
848825
def test_13_egress_fr13(self):
849826
"""Test Redundant Router : Master failover
850827
"""
@@ -900,7 +877,6 @@ def test_13_egress_fr13(self):
900877
negative_test=False)
901878

902879
@attr(tags = ["advanced"])
903-
@log_test_exceptions
904880
def test_13_1_egress_fr13(self):
905881
"""Test Redundant Router : Master failover
906882
"""

0 commit comments

Comments
 (0)