8
8
import pytest
9
9
from pytest_operator .plugin import OpsTest
10
10
11
+ from literals import TLS_RELATION
12
+
11
13
from .helpers import (
12
14
APP_NAME ,
13
15
DUMMY_NAME ,
14
16
KAFKA_CONTAINER ,
15
17
REL_NAME_ADMIN ,
18
+ TLS_NAME ,
16
19
ZK_NAME ,
17
20
check_logs ,
18
21
)
23
26
24
27
25
28
@pytest .mark .abort_on_fail
26
- async def test_in_place_upgrade (ops_test : OpsTest , kafka_charm , app_charm ):
29
+ async def test_in_place_upgrade (ops_test : OpsTest , kafka_charm ):
30
+ """Tests happy path upgrade with TLS."""
31
+ tls_config = {"ca-common-name" : "kafka" }
32
+
27
33
await asyncio .gather (
28
34
ops_test .model .deploy (
29
35
ZK_NAME ,
@@ -32,6 +38,86 @@ async def test_in_place_upgrade(ops_test: OpsTest, kafka_charm, app_charm):
32
38
num_units = 1 ,
33
39
trust = True ,
34
40
),
41
+ ops_test .model .deploy (
42
+ APP_NAME ,
43
+ application_name = APP_NAME ,
44
+ num_units = 1 ,
45
+ channel = CHANNEL ,
46
+ trust = True ,
47
+ ),
48
+ ops_test .model .deploy (
49
+ TLS_NAME , channel = "edge" , config = tls_config , revision = 163 , trust = True
50
+ ),
51
+ )
52
+
53
+ await asyncio .gather (
54
+ ops_test .model .add_relation (APP_NAME , ZK_NAME ),
55
+ ops_test .model .add_relation (ZK_NAME , TLS_NAME ),
56
+ ops_test .model .add_relation (f"{ APP_NAME } :{ TLS_RELATION } " , TLS_NAME ),
57
+ )
58
+
59
+ async with ops_test .fast_forward (fast_interval = "60s" ):
60
+ await ops_test .model .wait_for_idle (
61
+ apps = [APP_NAME , ZK_NAME , TLS_NAME ],
62
+ idle_period = 30 ,
63
+ timeout = 1800 ,
64
+ status = "active" ,
65
+ raise_on_error = False ,
66
+ )
67
+
68
+ await ops_test .model .wait_for_idle (
69
+ apps = [APP_NAME , ZK_NAME , TLS_NAME ], status = "active" , idle_period = 30
70
+ )
71
+
72
+ await ops_test .model .applications [APP_NAME ].add_units (count = 2 )
73
+ await ops_test .model .wait_for_idle (
74
+ apps = [APP_NAME ], status = "active" , timeout = 600 , idle_period = 30 , wait_for_exact_units = 3
75
+ )
76
+
77
+ leader_unit = None
78
+ for unit in ops_test .model .applications [APP_NAME ].units :
79
+ if await unit .is_leader_from_status ():
80
+ leader_unit = unit
81
+ assert leader_unit
82
+
83
+ logger .info ("Calling pre-upgrade-check..." )
84
+ action = await leader_unit .run_action ("pre-upgrade-check" )
85
+ await action .wait ()
86
+ await ops_test .model .wait_for_idle (
87
+ apps = [APP_NAME ], timeout = 1000 , idle_period = 15 , status = "active"
88
+ )
89
+
90
+ logger .info ("Upgrading Kafka..." )
91
+ await ops_test .model .applications [APP_NAME ].refresh (
92
+ path = kafka_charm ,
93
+ resources = {"kafka-image" : KAFKA_CONTAINER },
94
+ )
95
+
96
+ async with ops_test .fast_forward (fast_interval = "20s" ):
97
+ await asyncio .sleep (90 )
98
+
99
+ await ops_test .model .wait_for_idle (
100
+ apps = [APP_NAME ], timeout = 1000 , idle_period = 180 , raise_on_error = False
101
+ )
102
+
103
+ action = await leader_unit .run_action ("resume-upgrade" )
104
+ await action .wait ()
105
+ await ops_test .model .wait_for_idle (
106
+ apps = [APP_NAME ], timeout = 1000 , idle_period = 30 , status = "active"
107
+ )
108
+
109
+ # cleanup existing 'current' Kafka, and remove TLS for next test
110
+ await ops_test .model .remove_application (APP_NAME , block_until_done = True )
111
+ await ops_test .model .remove_application (TLS_NAME , block_until_done = True )
112
+ await ops_test .model .wait_for_idle (
113
+ apps = [ZK_NAME ], timeout = 1800 , idle_period = 30 , status = "active"
114
+ )
115
+
116
+
117
+ @pytest .mark .abort_on_fail
118
+ async def test_in_place_upgrade_consistency (ops_test : OpsTest , kafka_charm , app_charm ):
119
+ """Tests non-TLS upgrade data consistency during upgrade."""
120
+ await asyncio .gather (
35
121
ops_test .model .deploy (
36
122
APP_NAME ,
37
123
application_name = APP_NAME ,
0 commit comments