6
6
import pytest as pytest
7
7
from pytest_operator .plugin import OpsTest
8
8
9
- from tests .helpers import METADATA
10
9
from tests .integration .helpers import (
11
- CHARM_SERIES ,
12
10
DATABASE_APP_NAME ,
11
+ build_and_deploy ,
13
12
check_database_creation ,
14
13
check_database_users_existence ,
15
- get_primary ,
16
14
get_unit_address ,
17
15
)
18
16
19
- FIRST_DISCOURSE_APP_NAME = "discourse-k8s"
20
- SECOND_DISCOURSE_APP_NAME = "discourse-charmers-discourse-k8s"
17
+ DISCOURSE_APP_NAME = "discourse-charmers-discourse-k8s"
21
18
REDIS_APP_NAME = "redis-k8s"
22
19
APPLICATION_UNITS = 1
23
20
DATABASE_UNITS = 3
24
21
25
22
26
23
@pytest .mark .abort_on_fail
27
- async def test_build_and_deploy (ops_test : OpsTest ):
28
- """Build the charm-under-test and deploy it.
29
-
30
- Assert on the unit status before any relations/configurations take place.
31
- """
24
+ async def test_discourse_from_discourse_charmers (ops_test : OpsTest ):
25
+ # Build and deploy charm from local source folder (and also redis from Charmhub).
26
+ # Both are needed by Discourse.
32
27
async with ops_test .fast_forward ():
33
- # Build and deploy charm from local source folder (and also redis from Charmhub).
34
- # Both are needed by Discourse charms.
35
- charm = await ops_test .build_charm ("." )
36
- resources = {
37
- "postgresql-image" : METADATA ["resources" ]["postgresql-image" ]["upstream-source" ],
38
- }
39
28
await asyncio .gather (
40
- ops_test .model .deploy (
41
- charm ,
42
- resources = resources ,
43
- application_name = DATABASE_APP_NAME ,
44
- trust = True ,
45
- num_units = DATABASE_UNITS ,
46
- series = CHARM_SERIES ,
47
- ),
48
- ops_test .model .deploy (
49
- FIRST_DISCOURSE_APP_NAME , application_name = FIRST_DISCOURSE_APP_NAME
50
- ),
29
+ build_and_deploy (ops_test , DATABASE_UNITS ),
51
30
ops_test .model .deploy (REDIS_APP_NAME , application_name = REDIS_APP_NAME ),
52
31
)
53
32
await ops_test .model .wait_for_idle (
54
- apps = [DATABASE_APP_NAME , REDIS_APP_NAME ], status = "active" , timeout = 1000
33
+ apps = [DATABASE_APP_NAME , REDIS_APP_NAME ], status = "active" , timeout = 1500
55
34
)
56
- # Discourse waits for relations.
57
- await ops_test .model .wait_for_idle (
58
- apps = [FIRST_DISCOURSE_APP_NAME ], status = "waiting" , timeout = 1000
59
- )
60
-
61
-
62
- async def test_discourse (ops_test : OpsTest ):
63
- # Test the first Discourse charm.
64
- # Add both relations to Discourse (PostgreSQL and Redis)
65
- # and wait for it to be ready.
66
- await ops_test .model .add_relation (
67
- f"{ DATABASE_APP_NAME } :db-admin" ,
68
- FIRST_DISCOURSE_APP_NAME ,
69
- )
70
- await ops_test .model .add_relation (
71
- REDIS_APP_NAME ,
72
- FIRST_DISCOURSE_APP_NAME ,
73
- )
74
-
75
- # Discourse requests extensions through relation, so check that the PostgreSQL charm
76
- # becomes blocked.
77
- primary_name = await get_primary (ops_test )
78
- await ops_test .model .block_until (
79
- lambda : ops_test .model .units [primary_name ].workload_status == "blocked" , timeout = 60
80
- )
81
- assert (
82
- ops_test .model .units [primary_name ].workload_status_message
83
- == "extensions requested through relation"
84
- )
85
-
86
- # Destroy the relation to remove the blocked status.
87
- await ops_test .model .applications [DATABASE_APP_NAME ].destroy_relation (
88
- f"{ DATABASE_APP_NAME } :db-admin" , FIRST_DISCOURSE_APP_NAME
89
- )
90
-
91
-
92
- async def test_discourse_from_discourse_charmers (ops_test : OpsTest ):
93
- # Test the second Discourse charm.
94
35
95
36
# Get the Redis instance IP address.
96
37
redis_host = await get_unit_address (ops_test , f"{ REDIS_APP_NAME } /0" )
97
38
98
39
# Deploy Discourse and wait for it to be blocked waiting for database relation.
99
40
await ops_test .model .deploy (
100
- SECOND_DISCOURSE_APP_NAME ,
101
- application_name = SECOND_DISCOURSE_APP_NAME ,
41
+ DISCOURSE_APP_NAME ,
42
+ application_name = DISCOURSE_APP_NAME ,
102
43
config = {
103
44
"redis_host" : redis_host ,
104
45
"developer_emails" : "user@foo.internal" ,
@@ -108,17 +49,15 @@ async def test_discourse_from_discourse_charmers(ops_test: OpsTest):
108
49
},
109
50
)
110
51
# Discourse becomes blocked waiting for PostgreSQL relation.
111
- await ops_test .model .wait_for_idle (
112
- apps = [SECOND_DISCOURSE_APP_NAME ], status = "blocked" , timeout = 1000
113
- )
52
+ await ops_test .model .wait_for_idle (apps = [DISCOURSE_APP_NAME ], status = "blocked" , timeout = 1000 )
114
53
115
54
# Relate PostgreSQL and Discourse, waiting for Discourse to be ready.
116
55
relation = await ops_test .model .add_relation (
117
56
f"{ DATABASE_APP_NAME } :db-admin" ,
118
- SECOND_DISCOURSE_APP_NAME ,
57
+ DISCOURSE_APP_NAME ,
119
58
)
120
59
await ops_test .model .wait_for_idle (
121
- apps = [DATABASE_APP_NAME , SECOND_DISCOURSE_APP_NAME , REDIS_APP_NAME ],
60
+ apps = [DATABASE_APP_NAME , DISCOURSE_APP_NAME , REDIS_APP_NAME ],
122
61
status = "active" ,
123
62
timeout = 2000 , # Discourse takes a longer time to become active (a lot of setup).
124
63
)
0 commit comments