|
4 | 4 | get_region, |
5 | 5 | get_token, |
6 | 6 | ) |
7 | | -from test.integration.helpers import get_test_label |
| 7 | +from test.integration.helpers import ( |
| 8 | + get_test_label, |
| 9 | + retry_sending_request, |
| 10 | + wait_for_condition, |
| 11 | +) |
8 | 12 |
|
9 | 13 | import pytest |
10 | 14 |
|
11 | | -from linode_api4 import LinodeClient |
| 15 | +from linode_api4 import Instance, LinodeClient |
12 | 16 | from linode_api4.objects import Config, ConfigInterfaceIPv4, Firewall, IPAddress |
13 | 17 | from linode_api4.objects.networking import NetworkTransferPrice, Price |
14 | 18 |
|
@@ -163,3 +167,45 @@ def test_allocate_and_delete_ip(test_linode_client, create_linode): |
163 | 167 | is_deleted = ip.delete() |
164 | 168 |
|
165 | 169 | assert is_deleted is True |
| 170 | + |
| 171 | + |
| 172 | +def get_status(linode: Instance, status: str): |
| 173 | + return linode.status == status |
| 174 | + |
| 175 | + |
| 176 | +def test_create_and_delete_vlan(test_linode_client, linode_for_vlan_tests): |
| 177 | + linode = linode_for_vlan_tests |
| 178 | + |
| 179 | + config: Config = linode.configs[0] |
| 180 | + |
| 181 | + config.interfaces = [] |
| 182 | + config.save() |
| 183 | + |
| 184 | + vlan_label = "testvlan" |
| 185 | + interface = config.interface_create_vlan( |
| 186 | + label=vlan_label, ipam_address="10.0.0.2/32" |
| 187 | + ) |
| 188 | + |
| 189 | + config.invalidate() |
| 190 | + |
| 191 | + assert interface.id == config.interfaces[0].id |
| 192 | + assert interface.purpose == "vlan" |
| 193 | + assert interface.label == vlan_label |
| 194 | + |
| 195 | + # Remove the VLAN interface and reboot Linode |
| 196 | + config.interfaces = [] |
| 197 | + config.save() |
| 198 | + |
| 199 | + wait_for_condition(3, 100, get_status, linode, "running") |
| 200 | + |
| 201 | + retry_sending_request(3, linode.reboot) |
| 202 | + |
| 203 | + wait_for_condition(3, 100, get_status, linode, "rebooting") |
| 204 | + assert linode.status == "rebooting" |
| 205 | + |
| 206 | + # Delete the VLAN |
| 207 | + is_deleted = test_linode_client.networking.delete_vlan( |
| 208 | + vlan_label, linode.region |
| 209 | + ) |
| 210 | + |
| 211 | + assert is_deleted is True |
0 commit comments