-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathlinode_test.py
More file actions
164 lines (141 loc) · 5.1 KB
/
linode_test.py
File metadata and controls
164 lines (141 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from test.unit.base import ClientBaseCase
from test.unit.objects.linode_interface_test import (
build_interface_options_public,
build_interface_options_vlan,
build_interface_options_vpc,
)
from linode_api4 import InstancePlacementGroupAssignment, InterfaceGeneration
from linode_api4.objects import ConfigInterface
class LinodeTest(ClientBaseCase):
"""
Tests methods of the Linode class
"""
def test_instance_create_with_user_data(self):
"""
Tests that the metadata field is populated on Linode create.
"""
with self.mock_post("linode/instances/123") as m:
self.client.linode.instance_create(
"g6-nanode-1",
"us-southeast",
metadata=self.client.linode.build_instance_metadata(
user_data="cool"
),
)
self.assertEqual(
m.call_data,
{
"region": "us-southeast",
"type": "g6-nanode-1",
"metadata": {"user_data": "Y29vbA=="},
},
)
def test_instance_create_with_interfaces_legacy(self):
"""
Tests that user can pass a list of interfaces on Linode create.
"""
interfaces = [
{"purpose": "public"},
ConfigInterface(
purpose="vlan", label="cool-vlan", ipam_address="10.0.0.4/32"
),
]
with self.mock_post("linode/instances/123") as m:
self.client.linode.instance_create(
"us-southeast",
"g6-nanode-1",
interface_generation=InterfaceGeneration.LEGACY_CONFIG,
interfaces=interfaces,
)
self.assertEqual(
m.call_data["interfaces"],
[
{"purpose": "public"},
{
"purpose": "vlan",
"label": "cool-vlan",
"ipam_address": "10.0.0.4/32",
},
],
)
def test_build_instance_metadata(self):
"""
Tests that the metadata field is built correctly.
"""
self.assertEqual(
self.client.linode.build_instance_metadata(user_data="cool"),
{"user_data": "Y29vbA=="},
)
self.assertEqual(
self.client.linode.build_instance_metadata(
user_data="cool", encode_user_data=False
),
{"user_data": "cool"},
)
def test_create_with_placement_group(self):
"""
Tests that you can create a Linode with a Placement Group
"""
with self.mock_post("linode/instances/123") as m:
self.client.linode.instance_create(
"g6-nanode-1",
"eu-west",
placement_group=InstancePlacementGroupAssignment(
id=123,
compliant_only=True,
),
)
self.assertEqual(
m.call_data["placement_group"], {"id": 123, "compliant_only": True}
)
def test_instance_create_with_interfaces_linode(self):
"""
Tests that a Linode can be created alongside multiple LinodeInterfaces.
"""
interfaces = [
build_interface_options_public(),
build_interface_options_vpc(),
build_interface_options_vlan(),
]
with self.mock_post("linode/instances/124") as m:
self.client.linode.instance_create(
"g6-nanode-1",
"us-mia",
interface_generation=InterfaceGeneration.LINODE,
interfaces=interfaces,
)
assert m.call_data == {
"region": "us-mia",
"type": "g6-nanode-1",
"interface_generation": "linode",
"interfaces": [iface._serialize() for iface in interfaces],
}
def test_create_with_maintenance_policy(self):
"""
Tests that you can create a Linode with a maintenance policy
"""
with self.mock_post("linode/instances/123") as m:
self.client.linode.instance_create(
"g6-nanode-1",
"eu-west",
maintenance_policy="linode/migrate",
)
self.assertEqual(m.call_data["maintenance_policy"], "linode/migrate")
class TypeTest(ClientBaseCase):
def test_get_types(self):
"""
Tests that Linode types can be returned
"""
types = self.client.linode.types()
self.assertEqual(len(types), 5)
for t in types:
self.assertTrue(t._populated)
self.assertIsNotNone(t.id)
self.assertIsNotNone(t.label)
self.assertIsNotNone(t.disk)
self.assertIsNotNone(t.type_class)
self.assertIsNotNone(t.gpus)
self.assertIsNone(t.successor)
self.assertIsNotNone(t.region_prices)
self.assertIsNotNone(t.addons.backups.region_prices)
self.assertIsNotNone(t.accelerated_devices)