Skip to content

Commit 9f7ebc8

Browse files
test: Update outdated backup test and address test warnings messages (#600)
Co-authored-by: Zhiwei Liang <[email protected]>
1 parent 98cc51c commit 9f7ebc8

File tree

5 files changed

+96
-11
lines changed

5 files changed

+96
-11
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Makefile for more convenient building of the Linode CLI and its baked content
33
#
4-
INTEGRATION_TEST_PATH :=
4+
MODULE :=
55
TEST_CASE_COMMAND :=
66

77
ifdef TEST_CASE
@@ -62,7 +62,7 @@ testunit:
6262

6363
.PHONY: testint
6464
testint:
65-
pytest tests/integration/${INTEGRATION_TEST_PATH} ${TEST_CASE_COMMAND} --disable-warnings
65+
pytest tests/integration/${MODULE} ${TEST_CASE_COMMAND}
6666

6767
.PHONY: testall
6868
testall:
@@ -89,4 +89,4 @@ format: black isort autoflake
8989

9090
@PHONEY: smoketest
9191
smoketest:
92-
pytest -m smoke tests/integration --disable-warnings
92+
pytest -m smoke tests/integration

tests/integration/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,10 @@ def create_vpc_w_subnet():
443443
)[0]
444444

445445
return vpc_json
446+
447+
448+
@pytest.mark.smoke
449+
def pytest_configure(config):
450+
config.addinivalue_line(
451+
"markers", "smoke: mark test as part of smoke test suite"
452+
)

tests/integration/linodes/helpers_linodes.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,38 @@ def create_linode(test_region=DEFAULT_REGION):
9999
return linode_id
100100

101101

102+
def create_linode_backup_disabled(test_region=DEFAULT_REGION):
103+
result = set_backups_enabled_in_account_settings(toggle=False)
104+
105+
# create linode
106+
linode_id = (
107+
exec_test_command(
108+
[
109+
"linode-cli",
110+
"linodes",
111+
"create",
112+
"--type",
113+
DEFAULT_LINODE_TYPE,
114+
"--region",
115+
test_region,
116+
"--image",
117+
DEFAULT_TEST_IMAGE,
118+
"--root_pass",
119+
DEFAULT_RANDOM_PASS,
120+
"--format=id",
121+
"--text",
122+
"--no-headers",
123+
"--backups_enabled",
124+
"false",
125+
]
126+
)
127+
.stdout.decode()
128+
.rstrip()
129+
)
130+
131+
return linode_id
132+
133+
102134
def shutdown_linodes():
103135
linode_ids = (
104136
exec_test_command(
@@ -205,10 +237,30 @@ def create_linode_and_wait(
205237
)
206238
linode_id = output
207239

208-
# wait until linode is running
209-
assert (
210-
wait_until(linode_id=linode_id, timeout=240, status="running"),
211-
"linode failed to change status to running",
212-
)
240+
# wait until linode is running, wait_until returns True when it is in running state
241+
result = (wait_until(linode_id=linode_id, timeout=240, status="running"),)
242+
243+
assert result, "linode failed to change status to running"
213244

214245
return linode_id
246+
247+
248+
def set_backups_enabled_in_account_settings(toggle: bool):
249+
command = [
250+
"linode-cli",
251+
"account",
252+
"settings-update",
253+
"--format",
254+
"backups_enabled",
255+
"--text",
256+
"--no-headers",
257+
]
258+
259+
if toggle:
260+
command.extend(["--backups_enabled", "true"])
261+
else:
262+
command.extend(["--backups_enabled", "false"])
263+
264+
result = exec_test_command(command).stdout.decode().rstrip()
265+
266+
return result

tests/integration/linodes/test_backups.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
BASE_CMD,
99
create_linode,
1010
create_linode_and_wait,
11+
create_linode_backup_disabled,
12+
set_backups_enabled_in_account_settings,
1113
)
1214

1315
# ##################################################################
@@ -26,12 +28,32 @@ def create_linode_setup():
2628
delete_target_id("linodes", linode_id)
2729

2830

29-
def test_create_linode_with_backup_disabled(create_linode_setup):
30-
linode_id = create_linode_setup
31+
@pytest.fixture
32+
def create_linode_backup_disabled_setup():
33+
res = set_backups_enabled_in_account_settings(toggle=False)
34+
35+
if res == "True":
36+
raise ValueError(
37+
"Backups are unexpectedly enabled before setting up the test."
38+
)
39+
40+
linode_id = create_linode_backup_disabled()
41+
42+
yield linode_id
43+
44+
delete_target_id("linodes", linode_id)
45+
46+
47+
def test_create_linode_with_backup_disabled(
48+
create_linode_backup_disabled_setup,
49+
):
50+
linode_id = create_linode_backup_disabled_setup
3151
result = exec_test_command(
3252
BASE_CMD
3353
+ [
3454
"list",
55+
"--id",
56+
linode_id,
3557
"--format=id,enabled",
3658
"--delimiter",
3759
",",
@@ -42,6 +64,10 @@ def test_create_linode_with_backup_disabled(create_linode_setup):
4264

4365
assert re.search(linode_id + ",False", result)
4466

67+
result = set_backups_enabled_in_account_settings(toggle=True)
68+
69+
assert "True" in result
70+
4571

4672
@pytest.mark.smoke
4773
def test_enable_backups(create_linode_setup):

0 commit comments

Comments
 (0)