Skip to content

Commit 8032e0f

Browse files
Merge pull request #775 from linode/dev
v5.58.0
2 parents c5f2d30 + ff292fc commit 8032e0f

File tree

11 files changed

+761
-106
lines changed

11 files changed

+761
-106
lines changed

tests/integration/cli/test_help.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_help_page_for_non_aliased_actions():
2222
assert contains_at_least_one_of(
2323
wrapped_output,
2424
[
25-
"API Documentation: https://www.linode.com/docs/api/linode-instances/#linodes-list",
25+
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode",
2626
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-instances",
2727
],
2828
)
@@ -44,7 +44,7 @@ def test_help_page_for_aliased_actions():
4444
assert contains_at_least_one_of(
4545
wrapped_output,
4646
[
47-
"API Documentation: https://www.linode.com/docs/api/linode-instances/#linodes-list",
47+
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode",
4848
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-instances",
4949
],
5050
)

tests/integration/firewalls/test_firewalls.py

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import json
12
import re
23
import time
34

45
import pytest
6+
from pytest import MonkeyPatch
57

68
from linodecli.exit_codes import ExitCodes
79
from tests.integration.helpers import (
810
delete_target_id,
911
exec_failing_test_command,
1012
exec_test_command,
13+
get_random_text,
1114
)
1215

1316
BASE_CMD = ["linode-cli", "firewalls"]
14-
FIREWALL_LABEL = "label-fw-test" + str(int(time.time()))
17+
FIREWALL_LABEL = "fw-" + get_random_text(5)
1518

1619

1720
@pytest.fixture
@@ -253,3 +256,87 @@ def test_update_firewall(test_firewall_id):
253256
)
254257

255258
assert re.search(firewall_id + "," + updated_label + ",enabled", result)
259+
260+
261+
@pytest.mark.skip("skip until there is a way to delete default firewall")
262+
def test_firewall_settings_update_and_list(test_firewall_id):
263+
for cmd in [
264+
BASE_CMD
265+
+ [
266+
"firewall-settings-update",
267+
"--default_firewall_ids.vpc_interfac",
268+
test_firewall_id,
269+
"--default_firewall_ids.public_interface",
270+
test_firewall_id,
271+
"--default_firewall_ids.nodebalancer",
272+
test_firewall_id,
273+
"--default_firewall_ids.linode",
274+
test_firewall_id,
275+
"--json",
276+
],
277+
BASE_CMD
278+
+ [
279+
"firewall-settings-list",
280+
"--json",
281+
],
282+
]:
283+
data = json.loads(exec_test_command(cmd).stdout.decode().rstrip())
284+
firewall_ids = data[0]["default_firewall_ids"]
285+
for key in [
286+
"linode",
287+
"nodebalancer",
288+
"public_interface",
289+
"vpc_interface",
290+
]:
291+
assert firewall_ids[key] == int(test_firewall_id)
292+
293+
294+
def test_firewall_templates_list(monkeypatch: MonkeyPatch):
295+
monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta")
296+
data = json.loads(
297+
exec_test_command(BASE_CMD + ["templates-list", "--json"])
298+
.stdout.decode()
299+
.rstrip()
300+
)
301+
302+
slugs = {template["slug"] for template in data}
303+
expected_slugs = {"akamai-non-prod", "vpc", "public"}
304+
assert expected_slugs.issubset(slugs)
305+
306+
for template in data:
307+
assert "slug" in template
308+
assert "rules" in template
309+
rules = template["rules"]
310+
311+
assert "inbound_policy" in rules
312+
assert "outbound_policy" in rules
313+
assert isinstance(rules.get("inbound", []), list)
314+
assert isinstance(rules.get("outbound", []), list)
315+
316+
for rule in rules.get("inbound", []):
317+
assert "action" in rule
318+
assert "protocol" in rule
319+
assert "label" in rule
320+
assert "addresses" in rule
321+
322+
323+
def test_firewall_template_view(monkeypatch: MonkeyPatch):
324+
monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta")
325+
for slug in ["akamai-non-prod", "vpc", "public"]:
326+
data = json.loads(
327+
exec_test_command(BASE_CMD + ["template-view", slug, "--json"])
328+
.stdout.decode()
329+
.rstrip()
330+
)
331+
template = data[0]
332+
333+
assert template["slug"] == slug
334+
assert "rules" in template
335+
assert "inbound" in template["rules"]
336+
assert "outbound" in template["rules"]
337+
assert "inbound_policy" in template["rules"]
338+
assert "outbound_policy" in template["rules"]
339+
assert template["rules"]["inbound_policy"] == "DROP"
340+
assert template["rules"]["outbound_policy"] == "ACCEPT"
341+
assert isinstance(template["rules"]["inbound"], list)
342+
assert isinstance(template["rules"]["outbound"], list)

tests/integration/firewalls/test_firewalls_rules.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import json
22
import re
3-
import time
43

54
import pytest
65

7-
from tests.integration.helpers import delete_target_id, exec_test_command
6+
from tests.integration.helpers import (
7+
delete_target_id,
8+
exec_test_command,
9+
get_random_text,
10+
)
811

912
BASE_CMD = ["linode-cli", "firewalls", "rules-update"]
10-
FIREWALL_LABEL = "label-fw-test" + str(int(time.time()))
13+
FIREWALL_LABEL = "fw-" + get_random_text(5)
1114

1215

1316
@pytest.fixture
@@ -35,7 +38,7 @@ def test_firewall_id():
3538
)
3639

3740
yield firewall_id
38-
# teardown - delete all firewalls
41+
3942
delete_target_id(target="firewalls", id=firewall_id)
4043

4144

@@ -81,8 +84,7 @@ def test_add_multiple_rules(test_firewall_id):
8184

8285

8386
def test_swap_rules():
84-
timestamp = str(time.time_ns())
85-
firewall_label = "label-fw-test" + timestamp
87+
firewall_label = "fw-" + get_random_text(5)
8688
inbound_rule_1 = '{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["198.0.0.1/32"]}, "action": "ACCEPT", "label": "swap_rule_1"}'
8789
inbound_rule_2 = '{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["198.0.0.2/32"]}, "action": "ACCEPT", "label": "swap_rule_2"}'
8890
inbound_rules = "[" + inbound_rule_1 + "," + inbound_rule_2 + "]"
@@ -160,8 +162,7 @@ def test_update_inbound_and_outbound_policy(test_firewall_id):
160162

161163

162164
def test_remove_one_rule_via_rules_update():
163-
timestamp = str(time.time_ns())
164-
firewall_label = "label-fw-test" + timestamp
165+
firewall_label = "fw-" + get_random_text(5)
165166
inbound_rule_1 = '{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["198.0.0.1/32"]}, "action": "ACCEPT", "label": "test_rule_1"}'
166167
inbound_rule_2 = '{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["198.0.0.2/32"]}, "action": "ACCEPT", "label": "rule_to_delete"}'
167168
inbound_rules = "[" + inbound_rule_1 + "," + inbound_rule_2 + "]"

tests/integration/helpers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ def wait_for_condition(interval: int, timeout: int, condition: Callable):
3636

3737

3838
def exec_test_command(args: List[str]):
39-
process = subprocess.run(args, stdout=subprocess.PIPE)
40-
assert process.returncode == 0
39+
process = subprocess.run(
40+
args, stdout=subprocess.PIPE, stderr=subprocess.PIPE
41+
)
42+
if process.returncode != 0:
43+
raise RuntimeError(
44+
f"Command failed with exit code {process.returncode}\n"
45+
f"Command: {' '.join(args)}\n"
46+
f"Stdout:\n{process.stdout.decode()}\n"
47+
f"Stderr:\n{process.stderr.decode()}"
48+
)
4149
return process
4250

4351

tests/integration/linodes/helpers_linodes.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,40 @@ def wait_until(linode_id: "str", timeout, status: "str", period=5):
7272

7373

7474
def create_linode(
75-
firewall_id: "str", test_region=DEFAULT_REGION, disk_encryption=False
75+
firewall_id: str,
76+
test_region=DEFAULT_REGION,
77+
disk_encryption=False,
78+
interface_generation: str = None,
79+
interfaces: str = None,
7680
):
77-
# create linode
78-
linode_id = (
79-
exec_test_command(
80-
[
81-
"linode-cli",
82-
"linodes",
83-
"create",
84-
"--type",
85-
DEFAULT_LINODE_TYPE,
86-
"--region",
87-
test_region,
88-
"--image",
89-
DEFAULT_TEST_IMAGE,
90-
"--root_pass",
91-
DEFAULT_RANDOM_PASS,
92-
"--firewall_id",
93-
firewall_id,
94-
"--disk_encryption",
95-
"enabled" if disk_encryption else "disabled",
96-
"--format=id",
97-
"--text",
98-
"--no-headers",
99-
]
100-
)
101-
.stdout.decode()
102-
.rstrip()
103-
)
81+
# Base command
82+
command = [
83+
"linode-cli",
84+
"linodes",
85+
"create",
86+
"--type",
87+
DEFAULT_LINODE_TYPE,
88+
"--region",
89+
test_region,
90+
"--image",
91+
DEFAULT_TEST_IMAGE,
92+
"--root_pass",
93+
DEFAULT_RANDOM_PASS,
94+
"--firewall_id",
95+
firewall_id,
96+
"--disk_encryption",
97+
"enabled" if disk_encryption else "disabled",
98+
]
99+
100+
if interface_generation:
101+
command.extend(["--interface_generation", interface_generation])
102+
103+
if interfaces:
104+
command.extend(["--interfaces", interfaces])
105+
106+
command.extend(["--format=id", "--text", "--no-headers"])
107+
108+
linode_id = exec_test_command(command).stdout.decode().rstrip()
104109

105110
return linode_id
106111

tests/integration/linodes/test_interfaces.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,6 @@
1717
linode_label = DEFAULT_LABEL + timestamp
1818

1919

20-
@pytest.fixture
21-
def linode_with_vpc_interface(linode_cloud_firewall):
22-
vpc_json = create_vpc_w_subnet()
23-
24-
vpc_region = vpc_json["region"]
25-
vpc_id = str(vpc_json["id"])
26-
subnet_id = str(vpc_json["subnets"][0]["id"])
27-
28-
linode_json = json.loads(
29-
exec_test_command(
30-
BASE_CMD
31-
+ [
32-
"create",
33-
"--type",
34-
"g6-nanode-1",
35-
"--region",
36-
vpc_region,
37-
"--image",
38-
DEFAULT_TEST_IMAGE,
39-
"--root_pass",
40-
DEFAULT_RANDOM_PASS,
41-
"--firewall_id",
42-
linode_cloud_firewall,
43-
"--interfaces.purpose",
44-
"vpc",
45-
"--interfaces.primary",
46-
"true",
47-
"--interfaces.subnet_id",
48-
subnet_id,
49-
"--interfaces.ipv4.nat_1_1",
50-
"any",
51-
"--interfaces.ipv4.vpc",
52-
"10.0.0.5",
53-
"--interfaces.ip_ranges",
54-
json.dumps(["10.0.0.6/32"]),
55-
"--interfaces.purpose",
56-
"public",
57-
"--json",
58-
"--suppress-warnings",
59-
]
60-
)
61-
.stdout.decode()
62-
.rstrip()
63-
)[0]
64-
65-
yield linode_json, vpc_json
66-
67-
delete_target_id(target="linodes", id=str(linode_json["id"]))
68-
delete_target_id(target="vpcs", id=vpc_id)
69-
70-
7120
@pytest.fixture
7221
def linode_with_vpc_interface_as_json(linode_cloud_firewall):
7322
vpc_json = create_vpc_w_subnet()
@@ -150,9 +99,5 @@ def assert_interface_configuration(
15099
assert public_interface["purpose"] == "public"
151100

152101

153-
def test_with_vpc_interface(linode_with_vpc_interface):
154-
assert_interface_configuration(*linode_with_vpc_interface)
155-
156-
157102
def test_with_vpc_interface_as_json(linode_with_vpc_interface_as_json):
158103
assert_interface_configuration(*linode_with_vpc_interface_as_json)

0 commit comments

Comments
 (0)