21
21
22
22
from acktest .resources import random_suffix_name
23
23
from acktest .k8s import resource as k8s
24
- from acktest import adoption as adoption
25
24
from acktest import tags as tags
26
25
from e2e import service_marker , CRD_GROUP , CRD_VERSION , load_s3_resource
27
26
from e2e .tests .test_bucket import bucket_exists , get_bucket
@@ -39,29 +38,47 @@ class AdoptionPolicy(str, Enum):
39
38
ADOPT_OR_CREATE = "adopt-or-create"
40
39
41
40
42
- @pytest .fixture ( scope = "module" )
43
- def adoption_policy_adopt_bucket ( s3_client ):
41
+ @pytest .fixture
42
+ def bucket_adoption_policy ( request , s3_client ):
44
43
replacements = REPLACEMENT_VALUES .copy ()
45
44
bucket_name = replacements ["ADOPTION_BUCKET_NAME" ]
45
+
46
46
replacements ["ADOPTION_POLICY" ] = AdoptionPolicy .ADOPT
47
47
replacements ["ADOPTION_FIELDS" ] = f'{{\\ \" name\\ \" : \\ \" { bucket_name } \\ \" }}'
48
+ replacements ["BUCKET_NAME" ] = bucket_name
49
+
50
+ filename = ""
51
+
52
+ resource_name = ""
53
+
54
+ marker = request .node .get_closest_marker ("resource_data" )
55
+ assert marker is not None
56
+ data = marker .args [0 ]
57
+ assert 'adoption-policy' in data
58
+ replacements ["ADOPTION_POLICY" ] = data ['adoption-policy' ]
59
+ assert 'filename' in data
60
+ filename = data ['filename' ]
61
+ assert 'resource-name' in data
62
+ resource_name = random_suffix_name (data ['resource-name' ], 32 )
63
+ replacements ["RANDOM_BUCKET_NAME" ] = resource_name
48
64
49
65
resource_data = load_s3_resource (
50
- "bucket_adoption_policy" ,
66
+ filename ,
51
67
additional_replacements = replacements ,
52
68
)
53
69
54
70
# Create k8s resource
55
71
ref = k8s .CustomResourceReference (
56
72
CRD_GROUP , CRD_VERSION , "buckets" ,
57
- bucket_name , namespace = "default" )
73
+ resource_name , namespace = "default" )
58
74
k8s .create_custom_resource (ref , resource_data )
59
75
60
76
time .sleep (CREATE_WAIT_AFTER_SECONDS )
61
77
cr = k8s .wait_resource_consumed_by_controller (ref )
62
78
79
+ k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
80
+ cr = k8s .get_resource (ref )
63
81
assert cr is not None
64
- assert k8s .get_resource_exists (ref )
65
82
66
83
yield (ref , cr )
67
84
@@ -101,10 +118,11 @@ def adopt_stack_bucket(s3_client):
101
118
@service_marker
102
119
@pytest .mark .canary
103
120
class TestAdoptionPolicyBucket :
104
- def test_adoption_policy (
105
- self , s3_client , adoption_policy_adopt_bucket , s3_resource
121
+ @pytest .mark .resource_data ({'adoption-policy' : AdoptionPolicy .ADOPT , 'filename' : 'bucket_adopt' , 'resource-name' : 'adopt' })
122
+ def test_adopt_policy (
123
+ self , s3_client , bucket_adoption_policy , s3_resource
106
124
):
107
- (ref , cr ) = adoption_policy_adopt_bucket
125
+ (ref , cr ) = bucket_adoption_policy
108
126
109
127
# Spec will be added by controller
110
128
assert 'spec' in cr
@@ -132,6 +150,49 @@ def test_adoption_policy(
132
150
assert latest is not None
133
151
versioning = latest .Versioning ()
134
152
assert versioning .status == status
153
+
154
+ @pytest .mark .resource_data ({'adoption-policy' : AdoptionPolicy .ADOPT_OR_CREATE , 'filename' : 'bucket_adopt_or_create' , 'resource-name' : 'adopt-or-create' })
155
+ def test_adopt_or_create_policy (
156
+ self , s3_client , bucket_adoption_policy , s3_resource
157
+ ):
158
+ (ref , cr ) = bucket_adoption_policy
159
+
160
+ # Spec will be added by controller
161
+ k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
162
+ assert 'spec' in cr
163
+ assert 'name' in cr ['spec' ]
164
+ bucket_name = cr ['spec' ]['name' ]
165
+
166
+ latest = get_bucket (s3_resource , bucket_name )
167
+ assert latest is not None
168
+ tagging = latest .Tagging ()
169
+
170
+ initial_tags = {
171
+ "tag_key" : "tag_value"
172
+ }
173
+ tags .assert_ack_system_tags (
174
+ tags = tagging .tag_set ,
175
+ )
176
+ tags .assert_equal_without_ack_tags (
177
+ expected = initial_tags ,
178
+ actual = tagging .tag_set ,
179
+ )
180
+
181
+
182
+ @pytest .mark .resource_data ({'adoption-policy' : AdoptionPolicy .ADOPT_OR_CREATE , 'filename' : 'bucket_adopt_or_create_not_exist' , 'resource-name' : 'adopt-or-create-not-exist' })
183
+ def test_adopt_or_create_policy_non_existent (
184
+ self , s3_client , bucket_adoption_policy , s3_resource
185
+ ):
186
+ (ref , cr ) = bucket_adoption_policy
187
+
188
+ # Spec will be added by controller
189
+ assert 'spec' in cr
190
+ assert 'name' in cr ['spec' ]
191
+ k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
192
+
193
+ name = cr ['spec' ]['name' ]
194
+ latest = get_bucket (s3_resource , name )
195
+ assert latest is not None
135
196
136
197
def test_adoption_update_tags (
137
198
self , s3_client , adopt_stack_bucket , s3_resource
0 commit comments