Skip to content

Commit f7c6eef

Browse files
Added support for Block Storage Encryption (#453)
* Implemented changes for Linode Disk Encryption * Added more test cases * Added LA note
1 parent 6fcc069 commit f7c6eef

File tree

9 files changed

+90
-3
lines changed

9 files changed

+90
-3
lines changed

linode_api4/groups/volume.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def create(self, label, region=None, linode=None, size=20, **kwargs):
4545
tags included do not exist, they will be created as part of
4646
this operation.
4747
:type tags: list[str]
48-
48+
:param encryption: Whether the new Volume should opt in or out of disk encryption.
49+
:type encryption: str
50+
Note: Block Storage Disk Encryption is not currently available to all users.
4951
:returns: The new Volume.
5052
:rtype: Volume
5153
"""

linode_api4/objects/linode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ class Instance(Base):
679679
"has_user_data": Property(),
680680
"disk_encryption": Property(),
681681
"lke_cluster_id": Property(),
682+
"capabilities": Property(unordered=True),
682683
}
683684

684685
@property

linode_api4/objects/volume.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Volume(Base):
4646
"filesystem_path": Property(),
4747
"hardware_type": Property(),
4848
"linode_label": Property(),
49+
"encryption": Property(),
4950
}
5051

5152
def attach(self, to_linode, config=None):

test/fixtures/volumes.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,24 @@
4141
"filesystem_path": "this/is/a/file/path",
4242
"hardware_type": "nvme",
4343
"linode_label": "some_label"
44+
},
45+
{
46+
"id": 4,
47+
"label": "block4",
48+
"created": "2017-08-04T03:00:00",
49+
"region": "ap-west-1a",
50+
"linode_id": null,
51+
"size": 40,
52+
"updated": "2017-08-04T04:00:00",
53+
"status": "active",
54+
"tags": ["something"],
55+
"filesystem_path": "this/is/a/file/path",
56+
"hardware_type": "hdd",
57+
"linode_label": null,
58+
"encryption": "enabled"
4459
}
4560
],
46-
"results": 3,
61+
"results": 4,
4762
"pages": 1,
4863
"page": 1
4964
}

test/integration/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,35 @@ def test_volume(test_linode_client):
295295
raise e
296296

297297

298+
@pytest.fixture(scope="session")
299+
def test_volume_with_encryption(test_linode_client):
300+
client = test_linode_client
301+
timestamp = str(time.time_ns())
302+
region = get_region(client, {"Block Storage Encryption"})
303+
label = "TestSDK-" + timestamp
304+
305+
volume = client.volume_create(
306+
label=label, region=region, encryption="enabled"
307+
)
308+
309+
yield volume
310+
311+
timeout = 100 # give 100s for volume to be detached before deletion
312+
313+
start_time = time.time()
314+
315+
while time.time() - start_time < timeout:
316+
try:
317+
res = volume.delete()
318+
if res:
319+
break
320+
else:
321+
time.sleep(3)
322+
except ApiError as e:
323+
if time.time() - start_time > timeout:
324+
raise e
325+
326+
298327
@pytest.fixture
299328
def test_tag(test_linode_client):
300329
client = test_linode_client

test/integration/models/linode/test_linode.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ def linode_for_disk_tests(test_linode_client, e2e_test_firewall):
123123
linode_instance.delete()
124124

125125

126+
@pytest.fixture
127+
def linode_with_block_storage_encryption(test_linode_client, e2e_test_firewall):
128+
client = test_linode_client
129+
chosen_region = get_region(client, {"Linodes", "Block Storage Encryption"})
130+
label = get_test_label()
131+
132+
linode_instance, password = client.linode.instance_create(
133+
"g6-nanode-1",
134+
chosen_region,
135+
image="linode/alpine3.19",
136+
label=label + "block-storage-encryption",
137+
firewall=e2e_test_firewall,
138+
)
139+
140+
yield linode_instance
141+
142+
linode_instance.delete()
143+
144+
126145
@pytest.fixture
127146
def create_linode_for_long_running_tests(test_linode_client, e2e_test_firewall):
128147
client = test_linode_client
@@ -440,6 +459,13 @@ def test_linode_with_disk_encryption_disabled(linode_with_disk_encryption):
440459
)
441460

442461

462+
def test_linode_with_block_storage_encryption(
463+
linode_with_block_storage_encryption,
464+
):
465+
linode = linode_with_block_storage_encryption
466+
assert "Block Storage Encryption" in linode.capabilities
467+
468+
443469
def wait_for_disk_status(disk: Disk, timeout):
444470
start_time = time.time()
445471
while True:

test/integration/models/volume/test_volume.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ def test_get_volume(test_linode_client, test_volume):
6060
assert volume.id == test_volume.id
6161

6262

63+
def test_get_volume_with_encryption(
64+
test_linode_client, test_volume_with_encryption
65+
):
66+
volume = test_linode_client.load(Volume, test_volume_with_encryption.id)
67+
68+
assert volume.id == test_volume_with_encryption.id
69+
assert volume.encryption == "enabled"
70+
71+
6372
def test_update_volume_tag(test_linode_client, test_volume):
6473
volume = test_volume
6574
tag_1 = "volume_test_tag1"

test/unit/linode_client_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_image_create(self):
150150
def test_get_volumes(self):
151151
v = self.client.volumes()
152152

153-
self.assertEqual(len(v), 3)
153+
self.assertEqual(len(v), 4)
154154
self.assertEqual(v[0].label, "block1")
155155
self.assertEqual(v[0].region.id, "us-east-1a")
156156
self.assertEqual(v[1].label, "block2")

test/unit/objects/volume_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def test_get_volume(self):
3131
self.assertEqual(volume.hardware_type, "hdd")
3232
self.assertEqual(volume.linode_label, None)
3333

34+
def test_get_volume_with_encryption(self):
35+
volume = Volume(self.client, 4)
36+
self.assertEqual(volume.encryption, "enabled")
37+
3438
def test_update_volume_tags(self):
3539
"""
3640
Tests that updating tags on an entity send the correct request

0 commit comments

Comments
 (0)