14
14
"""Integration tests for the RDS API DBCluster resource
15
15
"""
16
16
17
- import boto3
18
- import datetime
19
- import logging
20
17
import time
21
- from typing import Dict
22
18
23
19
import pytest
24
20
25
21
from acktest .k8s import resource as k8s
26
22
from e2e import service_marker , CRD_GROUP , CRD_VERSION , load_rds_resource
27
23
from e2e .replacement_values import REPLACEMENT_VALUES
28
24
from e2e .bootstrap_resources import get_bootstrap_resources
25
+ from e2e .fixtures import k8s_secret
26
+ from e2e import db_cluster
29
27
30
28
RESOURCE_PLURAL = 'dbclusters'
31
29
32
- DELETE_WAIT_INTERVAL_SLEEP_SECONDS = 15
33
30
DELETE_WAIT_AFTER_SECONDS = 120
34
- DELETE_TIMEOUT_SECONDS = 600
35
31
36
- CREATE_INTERVAL_SLEEP_SECONDS = 15
37
- CREATE_TIMEOUT_SECONDS = 600
38
32
# Time we wait after resource becoming available in RDS and checking the CR's
39
33
# Status has been updated
40
- CHECK_STATUS_WAIT_SECONDS = 10
34
+ CHECK_STATUS_WAIT_SECONDS = 20
41
35
42
36
MODIFY_WAIT_AFTER_SECONDS = 20
43
37
44
38
45
- @pytest .fixture (scope = "module" )
46
- def rds_client ():
47
- return boto3 .client ('rds' )
48
-
49
-
50
- @pytest .fixture (scope = "module" )
51
- def master_user_pass_secret ():
52
- ns = "default"
53
- name = "dbclustersecrets"
54
- key = "master_user_password"
55
- secret_val = "secretpass123456"
56
- k8s .create_opaque_secret (ns , name , key , secret_val )
57
- yield ns , name , key
58
- k8s .delete_secret (ns , name )
59
-
60
-
61
39
@service_marker
62
40
@pytest .mark .canary
63
41
class TestDBCluster :
42
+
43
+ # MUP == Master user password...
44
+ MUP_NS = "default"
45
+ MUP_SEC_NAME = "dbclustersecrets"
46
+ MUP_SEC_KEY = "master_user_password"
47
+ MUP_SEC_VAL = "secretpass123456"
48
+
64
49
def test_create_delete_mysql_serverless (
65
50
self ,
66
- rds_client ,
67
- master_user_pass_secret ,
51
+ k8s_secret ,
68
52
):
69
53
db_cluster_id = "my-aurora-mysql"
70
54
db_name = "mydb"
71
- mup_sec_ns , mup_sec_name , mup_sec_key = master_user_pass_secret
55
+ secret = k8s_secret (
56
+ self .MUP_NS ,
57
+ self .MUP_SEC_NAME ,
58
+ self .MUP_SEC_KEY ,
59
+ self .MUP_SEC_VAL ,
60
+ )
72
61
73
62
replacements = REPLACEMENT_VALUES .copy ()
74
63
replacements ['COPY_TAGS_TO_SNAPSHOT' ] = "False"
75
64
replacements ["DB_CLUSTER_ID" ] = db_cluster_id
76
65
replacements ["DB_NAME" ] = db_name
77
- replacements ["MASTER_USER_PASS_SECRET_NAMESPACE" ] = mup_sec_ns
78
- replacements ["MASTER_USER_PASS_SECRET_NAME" ] = mup_sec_name
79
- replacements ["MASTER_USER_PASS_SECRET_KEY" ] = mup_sec_key
66
+ replacements ["MASTER_USER_PASS_SECRET_NAMESPACE" ] = secret . ns
67
+ replacements ["MASTER_USER_PASS_SECRET_NAME" ] = secret . name
68
+ replacements ["MASTER_USER_PASS_SECRET_KEY" ] = secret . key
80
69
81
70
resource_data = load_rds_resource (
82
71
"db_cluster_mysql_serverless" ,
@@ -95,23 +84,10 @@ def test_create_delete_mysql_serverless(
95
84
assert 'status' in cr ['status' ]
96
85
assert cr ['status' ]['status' ] == 'creating'
97
86
98
- # Let's check that the DB cluster appears in RDS
99
- aws_res = rds_client .describe_db_clusters (DBClusterIdentifier = db_cluster_id )
100
- assert aws_res is not None
101
- assert len (aws_res ['DBClusters' ]) == 1
102
- dbc_rec = aws_res ['DBClusters' ][0 ]
103
-
104
- now = datetime .datetime .now ()
105
- timeout = now + datetime .timedelta (seconds = CREATE_TIMEOUT_SECONDS )
106
-
107
- # TODO(jaypipes): Move this into generic AWS-side waiter
108
- while dbc_rec ['Status' ] != "available" :
109
- if datetime .datetime .now () >= timeout :
110
- pytest .fail ("failed to find available DBCluster before timeout" )
111
- time .sleep (CREATE_INTERVAL_SLEEP_SECONDS )
112
- aws_res = rds_client .describe_db_clusters (DBClusterIdentifier = db_cluster_id )
113
- assert len (aws_res ['DBClusters' ]) == 1
114
- dbc_rec = aws_res ['DBClusters' ][0 ]
87
+ db_cluster .wait_until (
88
+ db_cluster_id ,
89
+ db_cluster .status_matches ('available' ),
90
+ )
115
91
116
92
time .sleep (CHECK_STATUS_WAIT_SECONDS )
117
93
@@ -132,38 +108,22 @@ def test_create_delete_mysql_serverless(
132
108
# We're now going to modify the CopyTagsToSnapshot field of the DB
133
109
# instance, wait some time and verify that the RDS server-side resource
134
110
# shows the new value of the field.
135
- assert dbc_rec ['CopyTagsToSnapshot' ] == False
111
+ latest = db_cluster .get (db_cluster_id )
112
+ assert latest is not None
113
+ assert latest ['CopyTagsToSnapshot' ] == False
136
114
updates = {
137
115
"spec" : {"copyTagsToSnapshot" : True },
138
116
}
139
117
k8s .patch_custom_resource (ref , updates )
140
118
time .sleep (MODIFY_WAIT_AFTER_SECONDS )
141
119
142
- aws_res = rds_client .describe_db_clusters (DBClusterIdentifier = db_cluster_id )
143
- assert aws_res is not None
144
- assert len (aws_res ['DBClusters' ]) == 1
145
- dbc_rec = aws_res ['DBClusters' ][0 ]
146
- assert dbc_rec ['CopyTagsToSnapshot' ] == True
120
+ latest = db_cluster .get (db_cluster_id )
121
+ assert latest is not None
122
+ assert latest ['CopyTagsToSnapshot' ] == True
147
123
148
124
# Delete the k8s resource on teardown of the module
149
125
k8s .delete_custom_resource (ref )
150
126
151
127
time .sleep (DELETE_WAIT_AFTER_SECONDS )
152
128
153
- now = datetime .datetime .now ()
154
- timeout = now + datetime .timedelta (seconds = DELETE_TIMEOUT_SECONDS )
155
-
156
- # DB instance should no longer appear in RDS
157
- while True :
158
- if datetime .datetime .now () >= timeout :
159
- pytest .fail ("Timed out waiting for DB cluster to being deleted in RDS API" )
160
- time .sleep (DELETE_WAIT_INTERVAL_SLEEP_SECONDS )
161
-
162
- try :
163
- aws_res = rds_client .describe_db_clusters (DBClusterIdentifier = db_cluster_id )
164
- assert len (aws_res ['DBClusters' ]) == 1
165
- dbc_rec = aws_res ['DBClusters' ][0 ]
166
- if dbc_rec ['Status' ] != "deleting" :
167
- pytest .fail ("Status is not 'deleting' for DB cluster that was deleted. Status is " + dbc_rec ['Status' ])
168
- except rds_client .exceptions .DBClusterNotFoundFault :
169
- break
129
+ db_cluster .wait_until_deleted (db_cluster_id )
0 commit comments