Skip to content

Commit 3c5adee

Browse files
TPT-3501: update existing tests to validate python sdk support nodebalancer lke cluster and type fields (#716)
* TPT-3501: add assertion for new fields related to NodeBalancer endpoints * Fix falling tests: test_get_nb_node and test_update_nb_node. Add new test test_get_nb_with_lke_cluster * Fix falling tests: test_get_nb_node and test_update_nb_node. Add new test test_get_nb_with_lke_cluster * Apply code review suggestions * Apply code review suggestions * Add missing import * Add missing import
1 parent 74d80f7 commit 3c5adee

2 files changed

Lines changed: 97 additions & 4 deletions

File tree

test/integration/filters/fixtures.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
import pytest
55

6+
from linode_api4 import (
7+
LKEClusterControlPlaneOptions,
8+
)
9+
610

711
@pytest.fixture(scope="package")
812
def domain_instance(test_linode_client):
@@ -35,3 +39,27 @@ def lke_cluster_instance(test_linode_client):
3539
yield cluster
3640

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

test/integration/models/nodebalancer/test_nodebalancer.py

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
get_region,
77
get_token,
88
)
9-
from test.integration.helpers import get_test_label
9+
from test.integration.filters.fixtures import ( # noqa: F401
10+
create_lke_cluster_with_related_nb,
11+
)
12+
from test.integration.helpers import (
13+
get_test_label,
14+
wait_for_condition,
15+
)
1016

1117
import pytest
1218

1319
from linode_api4 import ApiError, LinodeClient, NodeBalancer
1420
from linode_api4.objects import (
21+
LKECluster,
1522
NodeBalancerConfig,
1623
NodeBalancerNode,
1724
NodeBalancerType,
@@ -167,7 +174,7 @@ def test_create_nb_with_reserved_ip(
167174

168175

169176
def test_get_nodebalancer_config(test_linode_client, create_nb_config):
170-
config = test_linode_client.load(
177+
test_linode_client.load(
171178
NodeBalancerConfig,
172179
create_nb_config.id,
173180
create_nb_config.nodebalancer_id,
@@ -212,6 +219,45 @@ def test_get_nb(test_linode_client, create_nb):
212219
)
213220

214221
assert nb.id == create_nb.id
222+
assert nb.type == "common"
223+
assert nb.lke_cluster is None
224+
225+
226+
def find_related_nodebalancer(client, cluster: LKECluster):
227+
nbs = client.nodebalancers()
228+
for nb in nbs:
229+
if nb.lke_cluster is not None and nb.lke_cluster.id == cluster.id:
230+
return nb.id
231+
return 0
232+
233+
234+
def is_related_nodebalancer_exist(client, cluster: LKECluster):
235+
if find_related_nodebalancer(client, cluster):
236+
return True
237+
return False
238+
239+
240+
def test_get_nb_with_lke_cluster(
241+
test_linode_client, create_lke_cluster_with_related_nb
242+
):
243+
wait_for_condition(
244+
10,
245+
600,
246+
is_related_nodebalancer_exist,
247+
test_linode_client,
248+
create_lke_cluster_with_related_nb,
249+
)
250+
nb = test_linode_client.load(
251+
NodeBalancer,
252+
find_related_nodebalancer(
253+
test_linode_client, create_lke_cluster_with_related_nb
254+
),
255+
)
256+
assert nb.type == "common"
257+
assert nb.lke_cluster is not None
258+
assert nb.lke_cluster.label is not None
259+
assert nb.lke_cluster.type == "lkecluster"
260+
assert "/lke/clusters/" in str(nb.lke_cluster.url)
215261

216262

217263
def test_update_nb(test_linode_client, create_nb):
@@ -233,6 +279,8 @@ def test_update_nb(test_linode_client, create_nb):
233279

234280
assert new_label == nb_updated.label
235281
assert 5 == nb_updated.client_udp_sess_throttle
282+
assert nb.type == "common"
283+
assert nb.lke_cluster is None
236284

237285

238286
@pytest.mark.smoke
@@ -255,15 +303,32 @@ def test_create_nb_node(
255303

256304

257305
@pytest.mark.smoke
258-
def test_get_nb_node(test_linode_client, create_nb_config):
306+
def test_get_nb_node(
307+
test_linode_client, create_nb_config, linode_with_private_ip
308+
):
309+
address = [
310+
a for a in linode_with_private_ip.ipv4 if re.search("192.168.+", a)
311+
][0]
312+
create_nb_config.node_create(
313+
"node_test", address + ":80", weight=50, mode="accept"
314+
)
259315
node = test_linode_client.load(
260316
NodeBalancerNode,
261317
create_nb_config.nodes[0].id,
262318
(create_nb_config.id, create_nb_config.nodebalancer_id),
263319
)
320+
assert "node_test" == node.label
264321

265322

266-
def test_update_nb_node(test_linode_client, create_nb_config):
323+
def test_update_nb_node(
324+
test_linode_client, create_nb_config, linode_with_private_ip
325+
):
326+
address = [
327+
a for a in linode_with_private_ip.ipv4 if re.search("192.168.+", a)
328+
][0]
329+
create_nb_config.node_create(
330+
"node_test", address + ":80", weight=50, mode="accept"
331+
)
267332
config = test_linode_client.load(
268333
NodeBalancerConfig,
269334
create_nb_config.id,

0 commit comments

Comments
 (0)