1515
1616from f5 .bigip import ManagementRoot
1717from f5 .multi_device .cluster import ClusterManager
18+ from f5 .multi_device .exceptions import AlreadyManagingCluster
19+ from f5 .multi_device .exceptions import ClusterNotSupported
1820
1921import pytest
2022from pytest import symbols
@@ -87,7 +89,7 @@ class TestCluster(object):
8789 def test_new_failover_cluster_two_member (self , BigIPSetup ):
8890 a , b = BigIPSetup
8991 bigip_list = [a , b ]
90- for x in range (5 ):
92+ for x in range (2 ):
9193 cm = ClusterManager ()
9294
9395 cm .create (
@@ -97,7 +99,9 @@ def test_new_failover_cluster_two_member(self, BigIPSetup):
9799 device_group_type = 'sync-failover' )
98100 cm .teardown ()
99101
100- def test_existing_failover_cluster (self , BigIPSetup ):
102+ def test_existing_failover_cluster (
103+ self , BigIPSetup , TwoBigIPTeardownSyncFailover
104+ ):
101105 a , b = BigIPSetup
102106 bigip_list = [a , b ]
103107 cm = ClusterManager ()
@@ -106,8 +110,50 @@ def test_existing_failover_cluster(self, BigIPSetup):
106110 'device_group_partition' : PARTITION ,
107111 'device_group_type' : 'sync-failover' }
108112 cm .create (** kwargs )
109-
113+ assert sorted ( cm . cluster . devices ) == sorted ( bigip_list )
110114 del cm
111115
112- cm = ClusterManager (** kwargs )
113- cm .teardown ()
116+ cm2 = ClusterManager (** kwargs )
117+ assert sorted (cm2 .cluster .devices ) == sorted (bigip_list )
118+
119+ def test_too_few_devices (self , BigIPSetup ):
120+ a , b = BigIPSetup
121+ bigip_list = [a ]
122+ cm = ClusterManager ()
123+ with pytest .raises (ClusterNotSupported ) as ex :
124+ kwargs = {'devices' : bigip_list ,
125+ 'device_group_name' : DEVICE_GROUP_NAME ,
126+ 'device_group_partition' : PARTITION ,
127+ 'device_group_type' : 'sync-failover' }
128+ cm .create (** kwargs )
129+ assert 'The number of devices to cluster is not supported.' in \
130+ ex .value .message
131+
132+ def test_too_many_devices (self , BigIPSetup ):
133+ a , b = BigIPSetup
134+ bigip_list = [a , b , a , a , a , a , a ]
135+ cm = ClusterManager ()
136+ with pytest .raises (ClusterNotSupported ) as ex :
137+ kwargs = {'devices' : bigip_list ,
138+ 'device_group_name' : DEVICE_GROUP_NAME ,
139+ 'device_group_partition' : PARTITION ,
140+ 'device_group_type' : 'sync-failover' }
141+ cm .create (** kwargs )
142+ assert 'The number of devices to cluster is not supported.' in \
143+ ex .value .message
144+
145+ def test_already_managing_cluster (
146+ self , BigIPSetup , TwoBigIPTeardownSyncFailover
147+ ):
148+ a , b = BigIPSetup
149+ bigip_list = [a , b ]
150+ cm = ClusterManager ()
151+ kwargs = {'devices' : bigip_list ,
152+ 'device_group_name' : DEVICE_GROUP_NAME ,
153+ 'device_group_partition' : PARTITION ,
154+ 'device_group_type' : 'sync-failover' }
155+ cm .create (** kwargs )
156+ with pytest .raises (AlreadyManagingCluster ) as ex :
157+ cm .create (** kwargs )
158+ assert 'The ClusterManager is already managing a cluster.' in \
159+ ex .value .message
0 commit comments