Skip to content

Commit 9c7c601

Browse files
siddharthsalottilne
authored andcommitted
Update FSx Lustre integration test to test manual backups
1 parent 091fb15 commit 9c7c601

File tree

1 file changed

+67
-9
lines changed

1 file changed

+67
-9
lines changed

tests/integration-tests/tests/storage/test_fsx_lustre.py

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import boto3
1616
import pytest
17+
from botocore.exceptions import ClientError
1718
from retrying import retry
1819

1920
import utils
@@ -87,11 +88,18 @@ def test_fsx_lustre_backup(
8788
):
8889
"""
8990
Test FSx Lustre backup feature. As part of this test, following steps are performed
90-
- Create a cluster with FSx automatic backups feature enabled.
91-
- Mount the file system and create a test file in it.
92-
- Wait for automatic backup to be created.
93-
- Restore a cluster from the automatic backup taken in step 3. Verify whether test file
94-
created in step 2 exists in the restored file system.
91+
1. Create a cluster with FSx automatic backups feature enabled.
92+
2. Mount the file system and create a test file in it.
93+
3. Wait for automatic backup to be created.
94+
4. Create a manual FSx Lustre backup of the file system.
95+
5. Delete the cluster.
96+
6. Verify whether automatic backup is deleted. NOTE: FSx team is planning to change this
97+
behavior to retain automatic backups upon filesystem deletion. The test case should
98+
be update when this change is in place.
99+
7. Restore a cluster from the manual backup taken in step 4. Verify whether test file
100+
created in step 2 exists in the restored file system.
101+
8. Delete manual backup created in step 4.
102+
95103
"""
96104
mount_dir = "/fsx_mount_dir"
97105
utc_now_plus_15 = datetime.datetime.utcnow() + datetime.timedelta(minutes=15)
@@ -112,12 +120,21 @@ def test_fsx_lustre_backup(
112120
# Create a text file in the mount directory.
113121
create_backup_test_file(remote_command_executor, mount_dir)
114122

115-
# Wait for the creation of automatic backup
116-
backup = monitor_fs_backup(remote_command_executor, fsx_fs_id, region)
123+
# Wait for the creation of automatic backup and assert if it is in available state.
124+
automatic_backup = monitor_automatic_backup_creation(remote_command_executor, fsx_fs_id, region)
125+
126+
# Create a manual FSx Lustre backup using boto3 client.
127+
manual_backup = create_manual_fs_backup(remote_command_executor, fsx_fs_id, region)
128+
129+
# Delete original cluster.
130+
cluster.delete()
131+
132+
# Verify whether automatic backup is also deleted along with the cluster.
133+
_test_automatic_backup_deletion(remote_command_executor, automatic_backup, region)
117134

118135
# Restore backup into a new cluster
119136
cluster_config_restore = pcluster_config_reader(
120-
config_file="pcluster_restore_fsx.config.ini", mount_dir=mount_dir, fsx_backup_id=backup.get("BackupId"),
137+
config_file="pcluster_restore_fsx.config.ini", mount_dir=mount_dir, fsx_backup_id=manual_backup.get("BackupId"),
121138
)
122139

123140
cluster_restore = clusters_factory(cluster_config_restore)
@@ -130,6 +147,9 @@ def test_fsx_lustre_backup(
130147
# Validate whether text file created in the original file system is present in the restored file system.
131148
_test_restore_from_backup(remote_command_executor_restore, mount_dir)
132149

150+
# Test deletion of manual backup
151+
_test_delete_manual_backup(remote_command_executor, manual_backup, region)
152+
133153

134154
def _test_fsx_lustre_correctly_mounted(remote_command_executor, mount_dir, os, region, fsx_fs_id):
135155
logging.info("Testing fsx lustre is correctly mounted")
@@ -275,7 +295,7 @@ def create_backup_test_file(remote_command_executor, mount_dir):
275295
assert_that(result.stdout).is_equal_to("FSx Lustre Backup test file")
276296

277297

278-
def monitor_fs_backup(remote_command_executor, fsx_fs_id, region):
298+
def monitor_automatic_backup_creation(remote_command_executor, fsx_fs_id, region):
279299
logging.info("Monitoring automatic backup for FSx Lustre file system: {fs_id}".format(fs_id=fsx_fs_id))
280300
fsx = boto3.client("fsx", region_name=region)
281301
backup = poll_on_automatic_backup_creation(fsx_fs_id, fsx)
@@ -298,7 +318,45 @@ def poll_on_automatic_backup_creation(fsx_fs_id, fsx):
298318
return backup
299319

300320

321+
def _test_automatic_backup_deletion(remote_command_executor, automatic_backup, region):
322+
backup_id = automatic_backup.get("BackupId")
323+
logging.info("Verifying whether automatic backup '{0}' was deleted".format(backup_id))
324+
error_message = "Backup '{backup_id}' does not exist.".format(backup_id=backup_id)
325+
fsx = boto3.client("fsx", region_name=region)
326+
with pytest.raises(ClientError, match=error_message):
327+
return fsx.describe_backups(BackupIds=[backup_id])
328+
329+
330+
def create_manual_fs_backup(remote_command_executor, fsx_fs_id, region):
331+
logging.info("Create manual backup for FSx Lustre file system: {fs_id}".format(fs_id=fsx_fs_id))
332+
fsx = boto3.client("fsx", region_name=region)
333+
backup = fsx.create_backup(FileSystemId=fsx_fs_id).get("Backup")
334+
backup = poll_on_manual_backup_creation(backup, fsx)
335+
assert_that(backup.get("Lifecycle")).is_equal_to("AVAILABLE")
336+
return backup
337+
338+
339+
@retry(
340+
retry_on_result=lambda result: result.get("Lifecycle") in ["CREATING"],
341+
wait_fixed=seconds(5),
342+
stop_max_delay=minutes(7),
343+
)
344+
def poll_on_manual_backup_creation(backup, fsx):
345+
logging.info(
346+
"Backup {backup_id}: {status}".format(backup_id=backup.get("BackupId"), status=backup.get("Lifecycle"))
347+
)
348+
return fsx.describe_backups(BackupIds=[backup.get("BackupId")]).get("Backups")[0]
349+
350+
301351
def _test_restore_from_backup(remote_command_executor, mount_dir):
302352
logging.info("Testing fsx lustre correctly restored from backup")
303353
result = remote_command_executor.run_remote_command("cat {mount_dir}/file_to_backup".format(mount_dir=mount_dir))
304354
assert_that(result.stdout).is_equal_to("FSx Lustre Backup test file")
355+
356+
357+
def _test_delete_manual_backup(remote_command_executor, backup, region):
358+
backup_id = backup.get("BackupId")
359+
logging.info("Testing deletion of manual backup {0}".format(backup_id))
360+
fsx = boto3.client("fsx", region_name=region)
361+
response = fsx.delete_backup(BackupId=backup_id)
362+
assert_that(response.get("Lifecycle")).is_equal_to("DELETED")

0 commit comments

Comments
 (0)