Skip to content

Commit 29ead18

Browse files
Rewrite Bucket tests to patch for each test (#43)
Description of changes: - Update to new E2E test bootstrapping method (no bootstrap resources, so no noticeable change for tests) - Patch each of the `Put` fields onto a single bucket, so we can test diff, update and delete properties individually By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f4df629 commit 29ead18

11 files changed

+255
-134
lines changed

test/e2e/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__pycache__/
22
*.py[cod]
3-
**/bootstrap.yaml
3+
**/bootstrap.pkl

test/e2e/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import Dict, Any
1616
from pathlib import Path
1717

18-
from acktest.k8s import resource
18+
from acktest.k8s.resource import load_and_create_resource
1919
from acktest.resources import load_resource_file
2020

2121
SERVICE_NAME = "s3"
@@ -40,7 +40,7 @@ def create_s3_resource(
4040
Wrapper around k8s.load_and_create_resource to create an S3 resource
4141
"""
4242

43-
reference, spec, resource = resource.load_and_create_resource(
43+
reference, spec, resource = load_and_create_resource(
4444
resource_directory,
4545
CRD_GROUP,
4646
CRD_VERSION,

test/e2e/bootstrap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test/e2e/bootstrap_resources.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@
1010
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1111
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
13+
1314
"""Declares the structure of the bootstrapped resources and provides a loader
1415
for them.
1516
"""
16-
from dataclasses import dataclass
1717

18+
from dataclasses import dataclass
19+
from acktest.bootstrapping import Resources
20+
from acktest.bootstrapping.iam import Role
21+
from acktest.bootstrapping.s3 import Bucket
22+
from acktest.bootstrapping.sns import Topic
1823
from e2e import bootstrap_directory
19-
from acktest.resources import read_bootstrap_config
2024

2125
@dataclass
22-
class TestBootstrapResources:
23-
pass
26+
class BootstrapResources(Resources):
27+
ReplicationBucket: Bucket
28+
ReplicationRole: Role
29+
NotificationTopic: Topic
2430

2531
_bootstrap_resources = None
2632

27-
def get_bootstrap_resources(bootstrap_file_name: str = "bootstrap.yaml"):
33+
def get_bootstrap_resources(bootstrap_file_name: str = "bootstrap.pkl") -> BootstrapResources:
2834
global _bootstrap_resources
2935
if _bootstrap_resources is None:
30-
_bootstrap_resources = TestBootstrapResources(
31-
**read_bootstrap_config(bootstrap_directory, bootstrap_file_name=bootstrap_file_name),
32-
)
33-
return _bootstrap_resources
36+
_bootstrap_resources = BootstrapResources.deserialize(bootstrap_directory, bootstrap_file_name=bootstrap_file_name)
37+
return _bootstrap_resources

test/e2e/conftest.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# permissions and limitations under the License.
1313

1414
import os
15+
import boto3
1516
import pytest
1617

1718
from acktest import k8s
@@ -22,9 +23,6 @@ def pytest_addoption(parser):
2223

2324

2425
def pytest_configure(config):
25-
config.addinivalue_line(
26-
"markers", "canary: mark test to also run in canary tests"
27-
)
2826
config.addinivalue_line(
2927
"markers", "service(arg): mark test associated with a given service"
3028
)
@@ -44,3 +42,11 @@ def pytest_collection_modifyitems(config, items):
4442
@pytest.fixture(scope='class')
4543
def k8s_client():
4644
return k8s._get_k8s_api_client()
45+
46+
@pytest.fixture(scope='module')
47+
def s3_client():
48+
return boto3.client('s3')
49+
50+
@pytest.fixture(scope='module')
51+
def s3_resource():
52+
return boto3.resource('s3')

test/e2e/replacement_values.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
S3-specific test variables.
1515
"""
1616

17+
from e2e.bootstrap_resources import get_bootstrap_resources
18+
1719
REPLACEMENT_VALUES = {
18-
20+
"REPLICATION_ROLE_ARN": get_bootstrap_resources().ReplicationRole.arn,
21+
"REPLICATION_BUCKET_NAME": get_bootstrap_resources().ReplicationBucket.name,
22+
"NOTIFICATION_TOPIC_ARN": get_bootstrap_resources().NotificationTopic.arn,
1923
}

test/e2e/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@955d7831ee374a212250179e95a5f3b75e555fd9
1+
acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@5220331d003e3a23de4470e68d02c99b16c81989

test/e2e/resources/bucket_notification.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ spec:
77
notification:
88
topicConfigurations:
99
- id: "Publish new objects to SNS"
10-
topicARN: "$SNS_TOPIC_ARN"
10+
topicARN: "$NOTIFICATION_TOPIC_ARN"
1111
events:
1212
- "s3:ObjectCreated:Put"

test/e2e/service_bootstrap.py

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,70 @@
1414
"""
1515

1616
import logging
17+
import json
1718
from pathlib import Path
1819

19-
from acktest import resources
20+
from acktest.bootstrapping import Resources, BootstrapFailureException
21+
from acktest.bootstrapping.iam import Role, UserPolicies
22+
from acktest.bootstrapping.s3 import Bucket
23+
from acktest.bootstrapping.sns import Topic
2024
from e2e import bootstrap_directory
21-
from e2e.bootstrap_resources import TestBootstrapResources
25+
from e2e.bootstrap_resources import BootstrapResources
2226

2327

24-
def service_bootstrap() -> dict:
28+
def service_bootstrap() -> Resources:
2529
logging.getLogger().setLevel(logging.INFO)
30+
31+
replication_policy = json.dumps({
32+
"Version": "2012-10-17",
33+
"Statement": [
34+
{
35+
"Effect": "Allow",
36+
"Action": [
37+
"s3:ReplicateObject",
38+
"s3:GetObjectVersionTagging",
39+
"s3:ReplicateTags",
40+
"s3:GetObjectVersionAcl",
41+
"s3:ListBucket",
42+
"s3:GetReplicationConfiguration",
43+
"s3:ReplicateDelete",
44+
"s3:GetObjectVersion"
45+
],
46+
"Resource": "*"
47+
}
48+
]
49+
})
2650

27-
return TestBootstrapResources(
28-
).__dict__
51+
notification_policy = json.dumps({
52+
"Version": "2008-10-17",
53+
"Statement": [
54+
{
55+
"Effect": "Allow",
56+
"Principal": {
57+
"Service": "s3.amazonaws.com"
58+
},
59+
"Action": "SNS:Publish",
60+
"Resource": "*"
61+
}
62+
]
63+
})
64+
65+
resources = BootstrapResources(
66+
ReplicationBucket=Bucket("ack-s3-replication", enable_versioning=True),
67+
ReplicationRole=Role("ack-s3-replication-role", "s3.amazonaws.com",
68+
user_policies=UserPolicies("ack-s3-replication-policy", [replication_policy])
69+
),
70+
NotificationTopic=Topic("ack-s3-notification", policy=notification_policy)
71+
)
72+
73+
try:
74+
resources.bootstrap()
75+
except BootstrapFailureException as ex:
76+
exit(254)
77+
78+
return resources
2979

3080
if __name__ == "__main__":
3181
config = service_bootstrap()
32-
resources.write_bootstrap_config(config, bootstrap_directory)
82+
# Write config to current directory by default
83+
config.serialize(bootstrap_directory)

test/e2e/service_cleanup.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
import logging
1717
from pathlib import Path
1818

19-
from acktest import resources
19+
from acktest.bootstrapping import Resources
2020
from e2e import bootstrap_directory
21-
from e2e.bootstrap_resources import TestBootstrapResources
2221

23-
def service_cleanup(config: dict):
22+
def service_cleanup():
2423
logging.getLogger().setLevel(logging.INFO)
2524

26-
resources = TestBootstrapResources(
27-
**config
28-
)
25+
resources = Resources.deserialize(bootstrap_directory)
26+
resources.cleanup()
2927

3028
if __name__ == "__main__":
31-
bootstrap_config = resources.read_bootstrap_config(bootstrap_directory)
32-
service_cleanup(bootstrap_config)
29+
service_cleanup()

0 commit comments

Comments
 (0)