Skip to content

Commit ce4d9c8

Browse files
committed
Improved unit test for access point
1 parent f0ced0c commit ce4d9c8

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

cli/src/pcluster/config/cluster_config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
PlacementGroupCapacityTypeValidator,
150150
PlacementGroupNamingValidator,
151151
)
152-
from pcluster.validators.efs_validators import EfsMountOptionsValidator
152+
from pcluster.validators.efs_validators import EfsMountOptionsValidator, EfsAccessPointOptionsValidator
153153
from pcluster.validators.feature_validators import FeatureRegionValidator
154154
from pcluster.validators.fsx_validators import (
155155
FsxAutoImportValidator,
@@ -400,10 +400,13 @@ def _register_validators(self, context: ValidatorContext = None): # noqa: D102
400400
EfsMountOptionsValidator,
401401
encryption_in_transit=self.encryption_in_transit,
402402
iam_authorization=self.iam_authorization,
403-
access_point_id=self.access_point_id,
404403
name=self.name,
405404
)
406-
405+
self._register_validator(
406+
EfsAccessPointOptionsValidator,
407+
access_point_id=self.access_point_id,
408+
file_system_id=self.file_system_id,
409+
)
407410

408411
class BaseSharedFsx(Resource):
409412
"""Represent the shared FSX resource."""

cli/src/pcluster/schemas/cluster_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class EfsSettingsSchema(BaseSchema):
322322
validate=validate.OneOf(DELETION_POLICIES), metadata={"update_policy": UpdatePolicy.SUPPORTED}
323323
)
324324
access_point_id = fields.Str(
325-
validate=validate.Regexp(r"^fsap-[0-9a-z]{17}$"), metadata={"update_policy": UpdatePolicy.SUPPORTED}
325+
validate=validate.Regexp(r"^fsap-[0-9a-z]{17}$"), metadata={"update_policy": UpdatePolicy.UNSUPPORTED}
326326
)
327327
encryption_in_transit = fields.Bool(metadata={"update_policy": UpdatePolicy.UNSUPPORTED})
328328
iam_authorization = fields.Bool(metadata={"update_policy": UpdatePolicy.UNSUPPORTED})

cli/src/pcluster/validators/efs_validators.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,24 @@ class EfsMountOptionsValidator(Validator):
1818
IAM Authorization requires Encryption in Transit.
1919
"""
2020

21-
def _validate(self, encryption_in_transit: bool, iam_authorization: bool, access_point_id: str, name: str):
21+
def _validate(self, encryption_in_transit: bool, iam_authorization: bool, name: str):
2222
if iam_authorization and not encryption_in_transit:
2323
self._add_failure(
2424
"EFS IAM authorization cannot be enabled when encryption in-transit is disabled. "
2525
f"Please either disable IAM authorization or enable encryption in-transit for file system {name}",
2626
FailureLevel.ERROR,
2727
)
28-
if access_point_id and not name:
28+
29+
class EfsAccessPointOptionsValidator(Validator):
30+
"""
31+
EFS Mount Options validator.
32+
33+
IAM Authorization requires Encryption in Transit.
34+
"""
35+
36+
def _validate(self, access_point_id: str, file_system_id: str):
37+
38+
if access_point_id and not file_system_id:
2939
self._add_failure(
3040
"An access point can only be specified when using an existing EFS file system. "
3141
f"Please either remove the access point id {access_point_id} or provide the file system id for the access point",

cli/tests/pcluster/validators/test_efs_validators.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import pytest
1313

14-
from pcluster.validators.efs_validators import EfsMountOptionsValidator
14+
from pcluster.validators.efs_validators import EfsMountOptionsValidator, EfsAccessPointOptionsValidator
1515
from tests.pcluster.validators.utils import assert_failure_messages
1616

1717

@@ -43,16 +43,16 @@
4343
],
4444
)
4545
def test_efs_mount_options_validator(
46-
encryption_in_transit, iam_authorization, access_point_id, file_system_id, expected_message
46+
encryption_in_transit, iam_authorization, expected_message
4747
):
4848
actual_failures = EfsMountOptionsValidator().execute(
49-
encryption_in_transit, iam_authorization, None, "<name-of-the-file-system>"
49+
encryption_in_transit, iam_authorization, "<name-of-the-file-system>"
5050
)
5151
assert_failure_messages(actual_failures, expected_message)
5252

5353

5454
@pytest.mark.parametrize(
55-
"access_point_id, name_of_the_file_system, expected_message",
55+
"access_point_id, file_system_id, expected_message",
5656
[
5757
(
5858
None,
@@ -68,16 +68,18 @@ def test_efs_mount_options_validator(
6868
),
6969
(
7070
"<access_point_id>",
71-
"<name-of-the-file-system>",
71+
"<file-systemd-id>",
7272
None,
7373
),
7474
(
7575
None,
76-
"<name-of-the-file-system>",
76+
"<file-systemd-id>",
7777
None,
7878
),
7979
],
8080
)
81-
def test_efs_access_point_validator(access_point_id, name_of_the_file_system, expected_message):
82-
actual_failures = EfsMountOptionsValidator().execute(False, False, access_point_id, name_of_the_file_system)
81+
def test_efs_access_point_with_filesystem_validator(access_point_id, file_system_id, expected_message):
82+
actual_failures = EfsAccessPointOptionsValidator().execute(access_point_id, file_system_id)
8383
assert_failure_messages(actual_failures, expected_message)
84+
85+

0 commit comments

Comments
 (0)