@@ -513,6 +513,171 @@ def test_ipsec_tunnel_status_not_found(self, check_firewall_mock):
513
513
reason = "Tunnel NotMyTunnel not found."
514
514
)
515
515
516
+ def test_ipsec_tunnel_status_proxyids_not_found (self , check_firewall_mock ):
517
+ """tunnel with proxyids - proxyids given but not found"""
518
+ check_firewall_mock ._node .get_tunnels .return_value = {
519
+ "IPSec" : {
520
+ "east1-vpn:ProxyID1" : {"state" : "active" },
521
+ "east1-vpn:ProxyID2" : {"state" : "active" },
522
+ "central1-vpn:ProxyID1" : {"state" : "init" },
523
+ }
524
+ }
525
+ assert check_firewall_mock .check_ipsec_tunnel_status (
526
+ tunnel_name = "east1-vpn" , proxy_ids = ["ProxyID1" , "ProxyID3" ]
527
+ ) == CheckResult (reason = "Tunnel east1-vpn has missing ProxyIDs in ['ProxyID1', 'ProxyID3']." )
528
+
529
+ @pytest .mark .parametrize (
530
+ "require_all_active, expected_status" ,
531
+ [
532
+ (True , CheckStatus .SUCCESS ),
533
+ (False , CheckStatus .SUCCESS ),
534
+ ],
535
+ )
536
+ def test_ipsec_tunnel_status_proxyids_all_active (self , require_all_active , expected_status , check_firewall_mock ):
537
+ """tunnel with proxyids - proxyids given and all active
538
+ Should return success whether require_all_active is True or False.
539
+ """
540
+ check_firewall_mock ._node .get_tunnels .return_value = {
541
+ "IPSec" : {
542
+ "east1-vpn:ProxyID1" : {"state" : "active" },
543
+ "east1-vpn:ProxyID2" : {"state" : "active" },
544
+ "east1-vpn:ProxyID3" : {"state" : "active" },
545
+ "central1-vpn:ProxyID1" : {"state" : "init" },
546
+ }
547
+ }
548
+ assert check_firewall_mock .check_ipsec_tunnel_status (
549
+ tunnel_name = "east1-vpn" , proxy_ids = ["ProxyID1" , "ProxyID2" , "ProxyID3" ], require_all_active = require_all_active
550
+ ) == CheckResult (expected_status )
551
+
552
+ @pytest .mark .parametrize (
553
+ "require_all_active, expected_status, reason" ,
554
+ [
555
+ (True , CheckStatus .FAIL , "Tunnel:ProxyID east1-vpn:ProxyID3 in state: init." ),
556
+ (False , CheckStatus .SUCCESS , "" ),
557
+ ],
558
+ )
559
+ def test_ipsec_tunnel_status_proxyids_some_active (self , require_all_active , expected_status , reason , check_firewall_mock ):
560
+ """tunnel with proxyids - proxyids given and some active
561
+ Should return fail by default. Success if require_all_active is False.
562
+ """
563
+ check_firewall_mock ._node .get_tunnels .return_value = {
564
+ "IPSec" : {
565
+ "east1-vpn:ProxyID1" : {"state" : "active" },
566
+ "east1-vpn:ProxyID2" : {"state" : "active" },
567
+ "east1-vpn:ProxyID3" : {"state" : "init" },
568
+ "central1-vpn:ProxyID1" : {"state" : "init" },
569
+ }
570
+ }
571
+ assert check_firewall_mock .check_ipsec_tunnel_status (
572
+ tunnel_name = "east1-vpn" , proxy_ids = ["ProxyID1" , "ProxyID2" , "ProxyID3" ], require_all_active = require_all_active
573
+ ) == CheckResult (expected_status , reason = reason )
574
+
575
+ @pytest .mark .parametrize (
576
+ "require_all_active, expected_status, reason" ,
577
+ [
578
+ (True , CheckStatus .FAIL , "Tunnel:ProxyID east1-vpn:ProxyID1 in state: init." ),
579
+ (False , CheckStatus .FAIL , "No active state for tunnel east1-vpn in ProxyIDs ['ProxyID1', 'ProxyID2', 'ProxyID3']." ),
580
+ ],
581
+ )
582
+ def test_ipsec_tunnel_status_proxyids_none_active (self , require_all_active , expected_status , reason , check_firewall_mock ):
583
+ """tunnel with proxyids - proxyids given and all not active
584
+ Should return fail whether require_all_active is True or False.
585
+ """
586
+ check_firewall_mock ._node .get_tunnels .return_value = {
587
+ "IPSec" : {
588
+ "east1-vpn:ProxyID1" : {"state" : "init" },
589
+ "east1-vpn:ProxyID2" : {"state" : "init" },
590
+ "east1-vpn:ProxyID3" : {"state" : "init" },
591
+ "central1-vpn:ProxyID1" : {"state" : "active" },
592
+ }
593
+ }
594
+ assert check_firewall_mock .check_ipsec_tunnel_status (
595
+ tunnel_name = "east1-vpn" , proxy_ids = ["ProxyID1" , "ProxyID2" , "ProxyID3" ], require_all_active = require_all_active
596
+ ) == CheckResult (expected_status , reason = reason )
597
+
598
+ @pytest .mark .parametrize (
599
+ "require_all_active, expected_status" ,
600
+ [
601
+ (True , CheckStatus .SUCCESS ),
602
+ (False , CheckStatus .SUCCESS ),
603
+ ],
604
+ )
605
+ def test_ipsec_tunnel_status_none_proxyids_all_active (self , require_all_active , expected_status , check_firewall_mock ):
606
+ """tunnel with proxyids - proxyids not given and all active"""
607
+ check_firewall_mock ._node .get_tunnels .return_value = {
608
+ "IPSec" : {
609
+ "east1-vpn:ProxyID1" : {"state" : "active" },
610
+ "east1-vpn:ProxyID2" : {"state" : "active" },
611
+ "east1-vpn:ProxyID3" : {"state" : "active" },
612
+ "central1-vpn:ProxyID1" : {"state" : "init" },
613
+ }
614
+ }
615
+ assert check_firewall_mock .check_ipsec_tunnel_status (
616
+ tunnel_name = "east1-vpn" , require_all_active = require_all_active
617
+ ) == CheckResult (expected_status )
618
+
619
+ assert check_firewall_mock .check_ipsec_tunnel_status (
620
+ tunnel_name = "east1-vpn" , proxy_ids = [], require_all_active = require_all_active
621
+ ) == CheckResult (expected_status )
622
+
623
+ @pytest .mark .parametrize (
624
+ "require_all_active, expected_status, reason" ,
625
+ [
626
+ (True , CheckStatus .FAIL , "Tunnel:ProxyID east1-vpn:ProxyID2 in state: init." ),
627
+ (False , CheckStatus .SUCCESS , "" ),
628
+ ],
629
+ )
630
+ def test_ipsec_tunnel_status_none_proxyids_some_active (
631
+ self , require_all_active , expected_status , reason , check_firewall_mock
632
+ ):
633
+ """tunnel with proxyids - proxyids not given and some active
634
+ Should return fail by default. Success if require_all_active is False.
635
+ """
636
+ check_firewall_mock ._node .get_tunnels .return_value = {
637
+ "IPSec" : {
638
+ "east1-vpn:ProxyID1" : {"state" : "active" },
639
+ "east1-vpn:ProxyID2" : {"state" : "init" },
640
+ "east1-vpn:ProxyID3" : {"state" : "active" },
641
+ "central1-vpn:ProxyID1" : {"state" : "init" },
642
+ }
643
+ }
644
+ assert check_firewall_mock .check_ipsec_tunnel_status (
645
+ tunnel_name = "east1-vpn" , require_all_active = require_all_active
646
+ ) == CheckResult (expected_status , reason = reason )
647
+
648
+ assert check_firewall_mock .check_ipsec_tunnel_status (
649
+ tunnel_name = "east1-vpn" , proxy_ids = [], require_all_active = require_all_active
650
+ ) == CheckResult (expected_status , reason = reason )
651
+
652
+ @pytest .mark .parametrize (
653
+ "require_all_active, expected_status, reason" ,
654
+ [
655
+ (True , CheckStatus .FAIL , "Tunnel:ProxyID east1-vpn:ProxyID1 in state: init." ),
656
+ (False , CheckStatus .FAIL , "No active state for tunnel east1-vpn in ProxyIDs ['ProxyID1', 'ProxyID2', 'ProxyID3']." ),
657
+ ],
658
+ )
659
+ def test_ipsec_tunnel_status_none_proxyids_none_active (
660
+ self , require_all_active , expected_status , reason , check_firewall_mock
661
+ ):
662
+ """tunnel with proxyids - proxyids not given and not active
663
+ Should return fail whether require_all_active is True or False.
664
+ """
665
+ check_firewall_mock ._node .get_tunnels .return_value = {
666
+ "IPSec" : {
667
+ "east1-vpn:ProxyID1" : {"state" : "init" },
668
+ "east1-vpn:ProxyID2" : {"state" : "init" },
669
+ "east1-vpn:ProxyID3" : {"state" : "init" },
670
+ "central1-vpn:ProxyID1" : {"state" : "active" },
671
+ }
672
+ }
673
+ assert check_firewall_mock .check_ipsec_tunnel_status (
674
+ tunnel_name = "east1-vpn" , require_all_active = require_all_active
675
+ ) == CheckResult (expected_status , reason = reason )
676
+
677
+ assert check_firewall_mock .check_ipsec_tunnel_status (
678
+ tunnel_name = "east1-vpn" , proxy_ids = [], require_all_active = require_all_active
679
+ ) == CheckResult (expected_status , reason = reason )
680
+
516
681
def test_check_free_disk_space_ok (self , check_firewall_mock ):
517
682
check_firewall_mock ._node .get_disk_utilization .return_value = {"/opt/panrepo" : 50000 }
518
683
0 commit comments