@@ -1187,7 +1187,7 @@ def test_major_version_upgrade(self):
1187
1187
Test major version upgrade: with full upgrade, maintenance window, and annotation
1188
1188
"""
1189
1189
def check_version ():
1190
- p = k8s .patroni_rest ("acid-upgrade-test-0" , "" )
1190
+ p = k8s .patroni_rest ("acid-upgrade-test-0" , "" ) or {}
1191
1191
version = p .get ("server_version" , 0 ) // 10000
1192
1192
return version
1193
1193
@@ -1237,7 +1237,7 @@ def get_annotations():
1237
1237
# should not upgrade because current time is not in maintenanceWindow
1238
1238
current_time = datetime .now ()
1239
1239
maintenance_window_future = f"{ (current_time + timedelta (minutes = 60 )).strftime ('%H:%M' )} -{ (current_time + timedelta (minutes = 120 )).strftime ('%H:%M' )} "
1240
- pg_patch_version_15 = {
1240
+ pg_patch_version_15_outside_mw = {
1241
1241
"spec" : {
1242
1242
"postgresql" : {
1243
1243
"version" : "15"
@@ -1248,7 +1248,7 @@ def get_annotations():
1248
1248
}
1249
1249
}
1250
1250
k8s .api .custom_objects_api .patch_namespaced_custom_object (
1251
- "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-upgrade-test" , pg_patch_version_15 )
1251
+ "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-upgrade-test" , pg_patch_version_15_outside_mw )
1252
1252
self .eventuallyEqual (lambda : k8s .get_operator_state (), {"0" : "idle" }, "Operator does not get in sync" )
1253
1253
1254
1254
# no pod replacement outside of the maintenance window
@@ -1259,12 +1259,12 @@ def get_annotations():
1259
1259
second_annotations = get_annotations ()
1260
1260
self .assertIsNone (second_annotations .get ("last-major-upgrade-failure" ), "Annotation for last upgrade's failure should not be set" )
1261
1261
1262
- # change the version again to trigger operator sync
1262
+ # change maintenanceWindows to current
1263
1263
maintenance_window_current = f"{ (current_time - timedelta (minutes = 30 )).strftime ('%H:%M' )} -{ (current_time + timedelta (minutes = 30 )).strftime ('%H:%M' )} "
1264
- pg_patch_version_16 = {
1264
+ pg_patch_version_15_in_mw = {
1265
1265
"spec" : {
1266
1266
"postgresql" : {
1267
- "version" : "16 "
1267
+ "version" : "15 "
1268
1268
},
1269
1269
"maintenanceWindows" : [
1270
1270
maintenance_window_current
@@ -1273,13 +1273,13 @@ def get_annotations():
1273
1273
}
1274
1274
1275
1275
k8s .api .custom_objects_api .patch_namespaced_custom_object (
1276
- "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-upgrade-test" , pg_patch_version_16 )
1276
+ "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-upgrade-test" , pg_patch_version_15_in_mw )
1277
1277
self .eventuallyEqual (lambda : k8s .get_operator_state (), {"0" : "idle" }, "Operator does not get in sync" )
1278
1278
1279
1279
k8s .wait_for_pod_failover (master_nodes , 'spilo-role=master,' + cluster_label )
1280
1280
k8s .wait_for_pod_start ('spilo-role=master,' + cluster_label )
1281
1281
k8s .wait_for_pod_start ('spilo-role=replica,' + cluster_label )
1282
- self .eventuallyEqual (check_version , 16 , "Version should be upgraded from 14 to 16 " )
1282
+ self .eventuallyEqual (check_version , 15 , "Version should be upgraded from 14 to 15 " )
1283
1283
1284
1284
# check if annotation for last upgrade's success is updated after second upgrade
1285
1285
third_annotations = get_annotations ()
@@ -1306,16 +1306,17 @@ def get_annotations():
1306
1306
k8s .wait_for_pod_failover (master_nodes , 'spilo-role=replica,' + cluster_label )
1307
1307
k8s .wait_for_pod_start ('spilo-role=master,' + cluster_label )
1308
1308
k8s .wait_for_pod_start ('spilo-role=replica,' + cluster_label )
1309
- self .eventuallyEqual (check_version , 16 , "Version should not be upgraded because annotation for last upgrade's failure is set" )
1309
+ self .eventuallyEqual (check_version , 15 , "Version should not be upgraded because annotation for last upgrade's failure is set" )
1310
1310
1311
1311
# change the version back to 15 and should remove failure annotation
1312
1312
k8s .api .custom_objects_api .patch_namespaced_custom_object (
1313
- "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-upgrade-test" , pg_patch_version_15 )
1313
+ "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-upgrade-test" , pg_patch_version_15_in_mw )
1314
1314
self .eventuallyEqual (lambda : k8s .get_operator_state (), {"0" : "idle" }, "Operator does not get in sync" )
1315
1315
1316
1316
k8s .wait_for_pod_start ('spilo-role=master,' + cluster_label )
1317
1317
k8s .wait_for_pod_start ('spilo-role=replica,' + cluster_label )
1318
1318
1319
+ self .eventuallyEqual (check_version , 15 , "Version should not be upgraded from 15" )
1319
1320
fourth_annotations = get_annotations ()
1320
1321
self .assertIsNone (fourth_annotations .get ("last-major-upgrade-failure" ), "Annotation for last upgrade's failure is not removed" )
1321
1322
0 commit comments