Skip to content

Commit 2037448

Browse files
committed
Fix falling tests: test_get_nb_node and test_update_nb_node. Add new test test_get_nb_with_lke_cluster
1 parent 213d958 commit 2037448

2 files changed

Lines changed: 92 additions & 7 deletions

File tree

test/integration/filters/fixtures.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from test.integration.conftest import get_region
22
from test.integration.helpers import get_test_label
3-
3+
from linode_api4 import (
4+
LKEClusterControlPlaneOptions,
5+
)
46
import pytest
57

68

@@ -35,3 +37,27 @@ def lke_cluster_instance(test_linode_client):
3537
yield cluster
3638

3739
cluster.delete()
40+
41+
42+
@pytest.fixture(scope="package")
43+
def lke_cluster(test_linode_client):
44+
node_type = "g6-dedicated-4" # g6-standard-1
45+
version = test_linode_client.lke.versions()[0]
46+
47+
region = get_region(test_linode_client, {"Kubernetes"})
48+
49+
node_pool = test_linode_client.lke.node_pool(node_type, 3)
50+
label = get_test_label() + "_cluster"
51+
52+
cluster = test_linode_client.lke.cluster_create(
53+
region,
54+
label,
55+
version,
56+
[node_pool],
57+
apl_enabled=True,
58+
control_plane=LKEClusterControlPlaneOptions(high_availability=True),
59+
)
60+
61+
yield cluster
62+
63+
cluster.delete()

test/integration/models/nodebalancer/test_nodebalancer.py

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
get_region,
77
get_token,
88
)
9-
from test.integration.helpers import get_test_label
9+
from test.integration.helpers import (
10+
get_test_label,
11+
wait_for_condition,
12+
)
13+
from test.integration.filters.fixtures import (
14+
lke_cluster,
15+
)
16+
from linode_api4.objects import (
17+
LKECluster,
18+
)
1019

1120
import pytest
1221

@@ -184,10 +193,43 @@ def test_get_nb(test_linode_client, create_nb):
184193
)
185194

186195
assert nb.id == create_nb.id
187-
assert nb.type == 'common'
196+
assert nb.type == "common"
188197
assert nb.lke_cluster is None
189198

190199

200+
def find_related_nodebalancer(client, cluster: LKECluster):
201+
nbs = client.nodebalancers()
202+
for nb in nbs:
203+
if nb.lke_cluster is not None and nb.lke_cluster.id == cluster.id:
204+
return nb.id
205+
return 0
206+
207+
208+
def is_related_nodebalancer_exist(client, cluster: LKECluster):
209+
if find_related_nodebalancer(client, cluster):
210+
return True
211+
return False
212+
213+
214+
def test_get_nb_with_lke_cluster(test_linode_client, lke_cluster):
215+
wait_for_condition(
216+
10,
217+
600,
218+
is_related_nodebalancer_exist,
219+
test_linode_client,
220+
lke_cluster,
221+
)
222+
nb = test_linode_client.load(
223+
NodeBalancer,
224+
find_related_nodebalancer(test_linode_client, lke_cluster),
225+
)
226+
assert nb.type == "common"
227+
assert nb.lke_cluster is not None
228+
assert nb.lke_cluster.label is not None
229+
assert nb.lke_cluster.type == "lkecluster"
230+
assert "/lke/clusters/" in str(nb.lke_cluster.url)
231+
232+
191233
def test_update_nb(test_linode_client, create_nb):
192234
nb = test_linode_client.load(
193235
NodeBalancer,
@@ -207,7 +249,7 @@ def test_update_nb(test_linode_client, create_nb):
207249

208250
assert new_label == nb_updated.label
209251
assert 5 == nb_updated.client_udp_sess_throttle
210-
assert nb.type == 'common'
252+
assert nb.type == "common"
211253
assert nb.lke_cluster is None
212254

213255

@@ -231,15 +273,32 @@ def test_create_nb_node(
231273

232274

233275
@pytest.mark.smoke
234-
def test_get_nb_node(test_linode_client, create_nb_config):
235-
test_linode_client.load(
276+
def test_get_nb_node(
277+
test_linode_client, create_nb_config, linode_with_private_ip
278+
):
279+
address = [
280+
a for a in linode_with_private_ip.ipv4 if re.search("192.168.+", a)
281+
][0]
282+
create_nb_config.node_create(
283+
"node_test", address + ":80", weight=50, mode="accept"
284+
)
285+
node = test_linode_client.load(
236286
NodeBalancerNode,
237287
create_nb_config.nodes[0].id,
238288
(create_nb_config.id, create_nb_config.nodebalancer_id),
239289
)
290+
assert "node_test" == node.label
240291

241292

242-
def test_update_nb_node(test_linode_client, create_nb_config):
293+
def test_update_nb_node(
294+
test_linode_client, create_nb_config, linode_with_private_ip
295+
):
296+
address = [
297+
a for a in linode_with_private_ip.ipv4 if re.search("192.168.+", a)
298+
][0]
299+
create_nb_config.node_create(
300+
"node_test", address + ":80", weight=50, mode="accept"
301+
)
243302
config = test_linode_client.load(
244303
NodeBalancerConfig,
245304
create_nb_config.id,

0 commit comments

Comments
 (0)