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
=== modified file 'config.yaml'
--- config.yaml 2023-03-10 23:21:07 +0000
+++ config.yaml 2023-03-14 21:53:56 +0000
@@ -145,21 +145,30 @@
145 default:145 default:
146 description: |146 description: |
147 Optionally specify the host instead of getting it from the postgres charm147 Optionally specify the host instead of getting it from the postgres charm
148 db_password:148 db_landscape_password:
149 type: string149 type: string
150 default:150 default:
151 description: Optionally specify db password151 description: |
152 Password for landscape user which does normal read/write operations
152 db_port:153 db_port:
153 type: string154 type: string
154 default:155 default:
155 description: |156 description: |
156 Optionally specify the db port instead of getting it from the postgres157 Optionally specify the db port instead of getting it from the postgres
157 charm. Falls back to the default postgres port158 charm. Falls back to the default postgres port
158 db_user:159 db_schema_user:
159 type: string160 type: string
160 default:161 default:
161 description: |162 description: |
162 Optionally specify the postgres user instead of getting it from the charm163 Database admin user to perform schema checks and migrations. If not
164 provided, the value from the postgres charm is used
165 db_schema_password:
166 type: string
167 default:
168 description: |
169 Password used by database admin to perform schema checks and
170 migrations. If not set, postgres charm value, followed by
171 db_landscape_password is used.
163 deployment_mode:172 deployment_mode:
164 type: string173 type: string
165 default: standalone174 default: standalone
166175
=== modified file 'src/charm.py'
--- src/charm.py 2023-03-13 21:37:24 +0000
+++ src/charm.py 2023-03-14 21:53:56 +0000
@@ -204,18 +204,21 @@
204 self._bootstrap_account()204 self._bootstrap_account()
205205
206 config_host = self.model.config.get("db_host")206 config_host = self.model.config.get("db_host")
207 config_password = self.model.config.get("db_password")207 schema_password = self.model.config.get("db_schema_password")
208 landscape_password = self.model.config.get("db_landscape_password")
208 config_port = self.model.config.get("db_port")209 config_port = self.model.config.get("db_port")
209 config_user = self.model.config.get("db_user")210 config_user = self.model.config.get("db_schema_user")
210 db_kargs = {}211 db_kargs = {}
211 if config_host:212 if config_host:
212 db_kargs["host"] = config_host213 db_kargs["host"] = config_host
213 if config_password:214 if schema_password:
214 db_kargs["password"] = config_password215 db_kargs["schema_password"] = schema_password
215 if config_port:216 if config_port:
216 db_kargs["port"] = config_port217 db_kargs["port"] = config_port
217 if config_user:218 if config_user:
218 db_kargs["user"] = config_user219 db_kargs["user"] = config_user
220 if landscape_password:
221 db_kargs["password"] = landscape_password
219 if db_kargs:222 if db_kargs:
220 update_db_conf(**db_kargs)223 update_db_conf(**db_kargs)
221 if self._migrate_schema_bootstrap():224 if self._migrate_schema_bootstrap():
@@ -375,12 +378,14 @@
375 else:378 else:
376 host = master["host"]379 host = master["host"]
377380
378 config_password = self.model.config.get("db_password")381 landscape_password = self.model.config.get("db_landscape_password")
379 if config_password:382 if landscape_password:
380 password = config_password383 password = landscape_password
381 else:384 else:
382 password = master["password"]385 password = master["password"]
383386
387 schema_password = self.model.config.get("db_schema_password")
388
384 config_port = self.model.config.get("db_port")389 config_port = self.model.config.get("db_port")
385 if config_port:390 if config_port:
386 port = config_port391 port = config_port
@@ -389,13 +394,14 @@
389 if not port:394 if not port:
390 port = DEFAULT_POSTGRES_PORT # Fall back to postgres default port if still not set395 port = DEFAULT_POSTGRES_PORT # Fall back to postgres default port if still not set
391396
392 config_user = self.model.config.get("db_user")397 config_user = self.model.config.get("db_schema_user")
393 if config_user:398 if config_user:
394 user = config_user399 user = config_user
395 else:400 else:
396 user = unit_data["user"]401 user = unit_data["user"]
397402
398 update_db_conf(host=host, port=port, user=user, password=password)403 update_db_conf(host=host, port=port, user=user, password=password,
404 schema_password=schema_password)
399405
400 if not self._migrate_schema_bootstrap():406 if not self._migrate_schema_bootstrap():
401 return407 return
402408
=== modified file 'src/settings_files.py'
--- src/settings_files.py 2023-03-10 23:21:07 +0000
+++ src/settings_files.py 2023-03-14 21:53:56 +0000
@@ -161,7 +161,8 @@
161 "Unable to decode b64-encoded SSL certificate")161 "Unable to decode b64-encoded SSL certificate")
162162
163163
164def update_db_conf(host=None, password=None, port=DEFAULT_POSTGRES_PORT, user=None):164def update_db_conf(host=None, password=None, schema_password=None, port=DEFAULT_POSTGRES_PORT,
165 user=None):
165 """Postgres specific settings override"""166 """Postgres specific settings override"""
166 to_update = defaultdict(dict)167 to_update = defaultdict(dict)
167 if host: # Note that host is required if port is changed168 if host: # Note that host is required if port is changed
@@ -169,6 +170,8 @@
169 if password:170 if password:
170 to_update["stores"]["password"] = password171 to_update["stores"]["password"] = password
171 to_update["schema"]["store_password"] = password172 to_update["schema"]["store_password"] = password
173 if schema_password: # Overrides password
174 to_update["schema"]["store_password"] = schema_password
172 if user:175 if user:
173 to_update["schema"]["store_user"] = user176 to_update["schema"]["store_user"] = user
174 if to_update:177 if to_update:
175178
=== modified file 'tests/test_charm.py'
--- tests/test_charm.py 2023-03-13 21:37:24 +0000
+++ tests/test_charm.py 2023-03-14 21:53:56 +0000
@@ -333,8 +333,8 @@
333 {333 {
334 "db_host": "hello",334 "db_host": "hello",
335 "db_port": "world",335 "db_port": "world",
336 "db_user": "test",336 "db_schema_user": "test",
337 "db_password": "test_pass",337 "db_landscape_password": "test_pass",
338 }338 }
339 )339 )
340 mock_event = Mock()340 mock_event = Mock()
@@ -368,6 +368,51 @@
368 }368 }
369 )369 )
370370
371 def test_db_manual_configs_password(self):
372 '''
373 Test specifying both passwords in the juju config
374 '''
375 self.harness.disable_hooks()
376 self.harness.update_config(
377 {
378 "db_host": "hello",
379 "db_port": "world",
380 "db_schema_user": "test",
381 "db_landscape_password": "test_pass",
382 "db_schema_password": "schema_pass",
383 }
384 )
385 mock_event = Mock()
386 mock_event.relation.data = {
387 mock_event.unit: {
388 "allowed-units": self.harness.charm.unit.name,
389 "master": "host=1.2.3.4 password=testpass",
390 "host": "1.2.3.4",
391 "port": "5678",
392 "user": "testuser",
393 "password": "testpass",
394 },
395 }
396
397 with patch("charm.check_call") as check_call_mock:
398 with patch(
399 "settings_files.update_service_conf"
400 ) as update_service_conf_mock:
401 self.harness.charm._db_relation_changed(mock_event)
402
403 update_service_conf_mock.assert_called_once_with(
404 {
405 "stores": {
406 "host": "hello:world",
407 "password": "test_pass",
408 },
409 "schema": {
410 "store_user": "test",
411 "store_password": "schema_pass",
412 },
413 }
414 )
415
371 def test_db_manual_configs_used_partial(self):416 def test_db_manual_configs_used_partial(self):
372 """417 """
373 Test that if some of the manual configs are provided, the rest are418 Test that if some of the manual configs are provided, the rest are

Subscribers

People subscribed via source and target branches

to all changes: