Skip to content

Commit a84e898

Browse files
author
Paul Breaux
committed
Added a couple of functional tests and fixed issue with create in ClusterManager not checking device number.
1 parent 9431a64 commit a84e898

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

f5/multi_device/cluster/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def create(self, **kwargs):
156156
if hasattr(self, 'cluster'):
157157
msg = 'The ClusterManager is already managing a cluster.'
158158
raise AlreadyManagingCluster(msg)
159+
self._check_device_number(kwargs['devices'])
159160
print('Adding trusted peers to root BigIP...')
160161
self.trust_domain.create(
161162
devices=kwargs['devices'],

test/functional/cluster/test_cluster.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from f5.bigip import ManagementRoot
1717
from f5.multi_device.cluster import ClusterManager
18+
from f5.multi_device.exceptions import AlreadyManagingCluster
19+
from f5.multi_device.exceptions import ClusterNotSupported
1820

1921
import pytest
2022
from 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

Comments
 (0)