14
14
"""Integration tests for the RDS API DBInstance resource
15
15
"""
16
16
17
- import datetime
18
- import logging
19
17
import time
20
- from typing import Dict
21
18
22
19
import pytest
23
20
24
21
from acktest .k8s import resource as k8s
25
22
from e2e import service_marker , CRD_GROUP , CRD_VERSION , load_rds_resource
26
23
from e2e .replacement_values import REPLACEMENT_VALUES
27
24
from e2e .bootstrap_resources import get_bootstrap_resources
28
- from e2e .fixtures import rds_client , k8s_secret
25
+ from e2e .fixtures import k8s_secret
26
+ from e2e import db_instance
29
27
30
28
RESOURCE_PLURAL = 'dbinstances'
31
29
32
- DELETE_WAIT_INTERVAL_SLEEP_SECONDS = 15
33
30
DELETE_WAIT_AFTER_SECONDS = 120
34
- # NOTE(jaypipes): I've seen this take upwards of 5 minutes or more to fully see
35
- # the DB instance not appear in the DescribeDBInstances call once
36
- # DeleteDBInstance has been called (even with SkipFinalSnapshot=true)
37
- DELETE_TIMEOUT_SECONDS = 60 * 10
38
-
39
- CREATE_INTERVAL_SLEEP_SECONDS = 15
40
- # Time to wait before we get to an expected `available` state.
41
- # NOTE(jaypipes): I have seen creation of t3-micro PG instances take more than
42
- # 20 minutes to get to `available`...
43
- CREATE_TIMEOUT_SECONDS = 60 * 30
31
+
44
32
# Time we wait after resource becoming available in RDS and checking the CR's
45
33
# Status has been updated
46
- CHECK_STATUS_WAIT_SECONDS = 10
34
+ CHECK_STATUS_WAIT_SECONDS = 20
47
35
48
36
MODIFY_WAIT_AFTER_SECONDS = 20
49
37
@@ -60,10 +48,9 @@ class TestDBInstance:
60
48
61
49
def test_crud_postgres13_t3_micro (
62
50
self ,
63
- rds_client ,
64
51
k8s_secret ,
65
52
):
66
- db_id = "pg13-t3-micro"
53
+ db_instance_id = "pg13-t3-micro"
67
54
secret = k8s_secret (
68
55
self .MUP_NS ,
69
56
self .MUP_SEC_NAME ,
@@ -73,7 +60,7 @@ def test_crud_postgres13_t3_micro(
73
60
74
61
replacements = REPLACEMENT_VALUES .copy ()
75
62
replacements ['COPY_TAGS_TO_SNAPSHOT' ] = "False"
76
- replacements ["DB_INSTANCE_ID" ] = db_id
63
+ replacements ["DB_INSTANCE_ID" ] = db_instance_id
77
64
replacements ["MASTER_USER_PASS_SECRET_NAMESPACE" ] = secret .ns
78
65
replacements ["MASTER_USER_PASS_SECRET_NAME" ] = secret .name
79
66
replacements ["MASTER_USER_PASS_SECRET_KEY" ] = secret .key
@@ -82,12 +69,11 @@ def test_crud_postgres13_t3_micro(
82
69
"db_instance_postgres13_t3_micro" ,
83
70
additional_replacements = replacements ,
84
71
)
85
- logging .debug (resource_data )
86
72
87
73
# Create the k8s resource
88
74
ref = k8s .CustomResourceReference (
89
75
CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
90
- db_id , namespace = "default" ,
76
+ db_instance_id , namespace = "default" ,
91
77
)
92
78
k8s .create_custom_resource (ref , resource_data )
93
79
cr = k8s .wait_resource_consumed_by_controller (ref )
@@ -97,23 +83,10 @@ def test_crud_postgres13_t3_micro(
97
83
assert 'dbInstanceStatus' in cr ['status' ]
98
84
assert cr ['status' ]['dbInstanceStatus' ] == 'creating'
99
85
100
- # Let's check that the DB instance appears in RDS
101
- aws_res = rds_client .describe_db_instances (DBInstanceIdentifier = db_id )
102
- assert aws_res is not None
103
- assert len (aws_res ['DBInstances' ]) == 1
104
- dbi_rec = aws_res ['DBInstances' ][0 ]
105
-
106
- now = datetime .datetime .now ()
107
- timeout = now + datetime .timedelta (seconds = CREATE_TIMEOUT_SECONDS )
108
-
109
- # TODO(jaypipes): Move this into generic AWS-side waiter
110
- while dbi_rec ['DBInstanceStatus' ] != "available" :
111
- if datetime .datetime .now () >= timeout :
112
- pytest .fail ("failed to find available DBInstance before timeout" )
113
- time .sleep (CREATE_INTERVAL_SLEEP_SECONDS )
114
- aws_res = rds_client .describe_db_instances (DBInstanceIdentifier = db_id )
115
- assert len (aws_res ['DBInstances' ]) == 1
116
- dbi_rec = aws_res ['DBInstances' ][0 ]
86
+ db_instance .wait_until (
87
+ db_instance_id ,
88
+ db_instance .status_matches ('available' ),
89
+ )
117
90
118
91
time .sleep (CHECK_STATUS_WAIT_SECONDS )
119
92
@@ -134,38 +107,21 @@ def test_crud_postgres13_t3_micro(
134
107
# We're now going to modify the CopyTagsToSnapshot field of the DB
135
108
# instance, wait some time and verify that the RDS server-side resource
136
109
# shows the new value of the field.
137
- assert dbi_rec ['CopyTagsToSnapshot' ] == False
110
+ latest = db_instance .get (db_instance_id )
111
+ assert latest is not None
112
+ assert latest ['CopyTagsToSnapshot' ] == False
138
113
updates = {
139
114
"spec" : {"copyTagsToSnapshot" : True },
140
115
}
141
116
k8s .patch_custom_resource (ref , updates )
142
117
time .sleep (MODIFY_WAIT_AFTER_SECONDS )
143
118
144
- aws_res = rds_client .describe_db_instances (DBInstanceIdentifier = db_id )
145
- assert aws_res is not None
146
- assert len (aws_res ['DBInstances' ]) == 1
147
- dbi_rec = aws_res ['DBInstances' ][0 ]
148
- assert dbi_rec ['CopyTagsToSnapshot' ] == True
119
+ latest = db_instance .get (db_instance_id )
120
+ assert latest is not None
121
+ assert latest ['CopyTagsToSnapshot' ] == True
149
122
150
- # Delete the k8s resource on teardown of the module
151
123
k8s .delete_custom_resource (ref )
152
124
153
125
time .sleep (DELETE_WAIT_AFTER_SECONDS )
154
126
155
- now = datetime .datetime .now ()
156
- timeout = now + datetime .timedelta (seconds = DELETE_TIMEOUT_SECONDS )
157
-
158
- # DB instance should no longer appear in RDS
159
- while True :
160
- if datetime .datetime .now () >= timeout :
161
- pytest .fail ("Timed out waiting for DB instance to being deleted in RDS API" )
162
- time .sleep (DELETE_WAIT_INTERVAL_SLEEP_SECONDS )
163
-
164
- try :
165
- aws_res = rds_client .describe_db_instances (DBInstanceIdentifier = db_id )
166
- assert len (aws_res ['DBInstances' ]) == 1
167
- dbi_rec = aws_res ['DBInstances' ][0 ]
168
- if dbi_rec ['DBInstanceStatus' ] != "deleting" :
169
- pytest .fail ("DBInstanceStatus is not 'deleting' for DB instance that was deleted. DBInstanceStatus is " + dbi_rec ['DBInstanceStatus' ])
170
- except rds_client .exceptions .DBInstanceNotFoundFault :
171
- break
127
+ db_instance .wait_until_deleted (db_instance_id )
0 commit comments