Merge lp:~silverdrake11/landscape-charm/add_store_password into lp:landscape-charm

Proposed by Kevin Nasto
Status: Merged
Approved by: Mitch Burton
Approved revision: 438
Merged at revision: 437
Proposed branch: lp:~silverdrake11/landscape-charm/add_store_password
Merge into: lp:landscape-charm
Diff against target: 196 lines (+82/-19)
4 files modified
config.yaml (+16/-7)
src/charm.py (+15/-9)
src/settings_files.py (+4/-1)
tests/test_charm.py (+47/-2)
To merge this branch: bzr merge lp:~silverdrake11/landscape-charm/add_store_password
Reviewer Review Type Date Requested Status
Mitch Burton Approve
Review via email: mp+438898@code.launchpad.net

Commit message

Added missing store password

Description of the change

Manual testing instructions:
charmcraft pack
juju deploy ./bundle.yaml
juju ssh landscape-server/0
sudo cat /etc/landscape/service.conf

Take a look at the stores password in the service.conf. Then run:
juju config landscape-server db_schema_password=helloworld

And then look at it again:
juju ssh landscape-server/0
sudo cat /etc/landscape/service.conf

To post a comment you must log in.
Revision history for this message
Mitch Burton (mitchburton) :
review: Needs Fixing
437. By Kevin Nasto

Changes to variable naming/desc and added test cases

Revision history for this message
Kevin Nasto (silverdrake11) :
438. By Kevin Nasto

Fixed code in on_config_changed

Revision history for this message
Mitch Burton (mitchburton) wrote :

+1 LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2023-03-10 23:21:07 +0000
3+++ config.yaml 2023-03-14 21:53:56 +0000
4@@ -145,21 +145,30 @@
5 default:
6 description: |
7 Optionally specify the host instead of getting it from the postgres charm
8- db_password:
9+ db_landscape_password:
10 type: string
11 default:
12- description: Optionally specify db password
13+ description: |
14+ Password for landscape user which does normal read/write operations
15 db_port:
16 type: string
17 default:
18 description: |
19 Optionally specify the db port instead of getting it from the postgres
20 charm. Falls back to the default postgres port
21- db_user:
22- type: string
23- default:
24- description: |
25- Optionally specify the postgres user instead of getting it from the charm
26+ db_schema_user:
27+ type: string
28+ default:
29+ description: |
30+ Database admin user to perform schema checks and migrations. If not
31+ provided, the value from the postgres charm is used
32+ db_schema_password:
33+ type: string
34+ default:
35+ description: |
36+ Password used by database admin to perform schema checks and
37+ migrations. If not set, postgres charm value, followed by
38+ db_landscape_password is used.
39 deployment_mode:
40 type: string
41 default: standalone
42
43=== modified file 'src/charm.py'
44--- src/charm.py 2023-03-13 21:37:24 +0000
45+++ src/charm.py 2023-03-14 21:53:56 +0000
46@@ -204,18 +204,21 @@
47 self._bootstrap_account()
48
49 config_host = self.model.config.get("db_host")
50- config_password = self.model.config.get("db_password")
51+ schema_password = self.model.config.get("db_schema_password")
52+ landscape_password = self.model.config.get("db_landscape_password")
53 config_port = self.model.config.get("db_port")
54- config_user = self.model.config.get("db_user")
55+ config_user = self.model.config.get("db_schema_user")
56 db_kargs = {}
57 if config_host:
58 db_kargs["host"] = config_host
59- if config_password:
60- db_kargs["password"] = config_password
61+ if schema_password:
62+ db_kargs["schema_password"] = schema_password
63 if config_port:
64 db_kargs["port"] = config_port
65 if config_user:
66 db_kargs["user"] = config_user
67+ if landscape_password:
68+ db_kargs["password"] = landscape_password
69 if db_kargs:
70 update_db_conf(**db_kargs)
71 if self._migrate_schema_bootstrap():
72@@ -375,12 +378,14 @@
73 else:
74 host = master["host"]
75
76- config_password = self.model.config.get("db_password")
77- if config_password:
78- password = config_password
79+ landscape_password = self.model.config.get("db_landscape_password")
80+ if landscape_password:
81+ password = landscape_password
82 else:
83 password = master["password"]
84
85+ schema_password = self.model.config.get("db_schema_password")
86+
87 config_port = self.model.config.get("db_port")
88 if config_port:
89 port = config_port
90@@ -389,13 +394,14 @@
91 if not port:
92 port = DEFAULT_POSTGRES_PORT # Fall back to postgres default port if still not set
93
94- config_user = self.model.config.get("db_user")
95+ config_user = self.model.config.get("db_schema_user")
96 if config_user:
97 user = config_user
98 else:
99 user = unit_data["user"]
100
101- update_db_conf(host=host, port=port, user=user, password=password)
102+ update_db_conf(host=host, port=port, user=user, password=password,
103+ schema_password=schema_password)
104
105 if not self._migrate_schema_bootstrap():
106 return
107
108=== modified file 'src/settings_files.py'
109--- src/settings_files.py 2023-03-10 23:21:07 +0000
110+++ src/settings_files.py 2023-03-14 21:53:56 +0000
111@@ -161,7 +161,8 @@
112 "Unable to decode b64-encoded SSL certificate")
113
114
115-def update_db_conf(host=None, password=None, port=DEFAULT_POSTGRES_PORT, user=None):
116+def update_db_conf(host=None, password=None, schema_password=None, port=DEFAULT_POSTGRES_PORT,
117+ user=None):
118 """Postgres specific settings override"""
119 to_update = defaultdict(dict)
120 if host: # Note that host is required if port is changed
121@@ -169,6 +170,8 @@
122 if password:
123 to_update["stores"]["password"] = password
124 to_update["schema"]["store_password"] = password
125+ if schema_password: # Overrides password
126+ to_update["schema"]["store_password"] = schema_password
127 if user:
128 to_update["schema"]["store_user"] = user
129 if to_update:
130
131=== modified file 'tests/test_charm.py'
132--- tests/test_charm.py 2023-03-13 21:37:24 +0000
133+++ tests/test_charm.py 2023-03-14 21:53:56 +0000
134@@ -333,8 +333,8 @@
135 {
136 "db_host": "hello",
137 "db_port": "world",
138- "db_user": "test",
139- "db_password": "test_pass",
140+ "db_schema_user": "test",
141+ "db_landscape_password": "test_pass",
142 }
143 )
144 mock_event = Mock()
145@@ -368,6 +368,51 @@
146 }
147 )
148
149+ def test_db_manual_configs_password(self):
150+ '''
151+ Test specifying both passwords in the juju config
152+ '''
153+ self.harness.disable_hooks()
154+ self.harness.update_config(
155+ {
156+ "db_host": "hello",
157+ "db_port": "world",
158+ "db_schema_user": "test",
159+ "db_landscape_password": "test_pass",
160+ "db_schema_password": "schema_pass",
161+ }
162+ )
163+ mock_event = Mock()
164+ mock_event.relation.data = {
165+ mock_event.unit: {
166+ "allowed-units": self.harness.charm.unit.name,
167+ "master": "host=1.2.3.4 password=testpass",
168+ "host": "1.2.3.4",
169+ "port": "5678",
170+ "user": "testuser",
171+ "password": "testpass",
172+ },
173+ }
174+
175+ with patch("charm.check_call") as check_call_mock:
176+ with patch(
177+ "settings_files.update_service_conf"
178+ ) as update_service_conf_mock:
179+ self.harness.charm._db_relation_changed(mock_event)
180+
181+ update_service_conf_mock.assert_called_once_with(
182+ {
183+ "stores": {
184+ "host": "hello:world",
185+ "password": "test_pass",
186+ },
187+ "schema": {
188+ "store_user": "test",
189+ "store_password": "schema_pass",
190+ },
191+ }
192+ )
193+
194 def test_db_manual_configs_used_partial(self):
195 """
196 Test that if some of the manual configs are provided, the rest are

Subscribers

People subscribed via source and target branches

to all changes: