Merge ~ballot/charm-k8s-mm-pd-bot/+git/charm-k8s-mm-pd-bot:cleaning into charm-k8s-mm-pd-bot:master

Proposed by Benjamin Allot
Status: Merged
Approved by: Benjamin Allot
Approved revision: 322984e5e540f97def85887ab98230b1a5e9b3ba
Merged at revision: a081974526fc33356f335fb4b70bd6b0548683c3
Proposed branch: ~ballot/charm-k8s-mm-pd-bot/+git/charm-k8s-mm-pd-bot:cleaning
Merge into: charm-k8s-mm-pd-bot:master
Diff against target: 508 lines (+128/-62)
7 files modified
.gitignore (+4/-1)
Makefile (+20/-9)
config.yaml (+1/-0)
src/charm.py (+10/-20)
tests/unit/scenario.py (+68/-21)
tests/unit/test_charm.py (+24/-10)
tox.ini (+1/-1)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+390713@code.launchpad.net

Commit message

Cleaning some leftovers

* Cleaner interaction with the Makefile
* Juju like behavior for settings
* More tests

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
Tom Haddon (mthaddon) wrote :

A few comments inline (nothing major).

It seems `make test` doesn't include lint, which was somewhat unexpected. `make lint` also fails as follows:

https://paste.ubuntu.com/p/P5FPFH9vh3/

Also, you're missing a commit message for this MP.

review: Needs Fixing
Revision history for this message
Benjamin Allot (ballot) wrote :

Comment about the ops_mail stuff inline

Revision history for this message
Benjamin Allot (ballot) wrote :

> A few comments inline (nothing major).
>
> It seems `make test` doesn't include lint, which was somewhat unexpected.
> `make lint` also fails as follows:
>
> https://paste.ubuntu.com/p/P5FPFH9vh3/
>
> Also, you're missing a commit message for this MP.

Ack, will fix.
I separated "lint" and "test" on purpose by habit but I can put them back together.

Revision history for this message
Tom Haddon (mthaddon) wrote :

Two small comments inline

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thx

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision a081974526fc33356f335fb4b70bd6b0548683c3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index 1ce05c5..b2d8d5e 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1,8 +1,11 @@
6 *.swp
7+/.coverage
8 /.tox
9 /build
10+/charm
11 /mm-pd-bot.charm
12 __pycache__
13+
14+# Keep this order to whitelist the example
15 bot.cfg
16 !/examples/bot.cfg
17-/.coverage
18diff --git a/Makefile b/Makefile
19index 2dceafc..ee2da42 100644
20--- a/Makefile
21+++ b/Makefile
22@@ -1,3 +1,17 @@
23+PROJECTPATH = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
24+PROJECT := mm-pd-bot
25+CHARM ?= $(PROJECT).charm
26+CHARM_FILE := $(PROJECTPATH)/$(CHARM)
27+
28+SOURCES := $(shell find $(PROJECTPATH)/src -name "*.py")
29+TESTS := $(shell find $(PROJECTPATH)/tests -name "*.py" -o -name "requirements.txt")
30+
31+# Rebuild the charm each time we have an update in the sources or tests
32+$(CHARM_FILE): $(SOURCES) $(TESTS) $(PROJECTPATH)/requirements.txt
33+ charmcraft build -f $(PROJECTPATH)
34+
35+all: test
36+
37 blacken:
38 @echo "Normalising python layout with black."
39 @tox -e black
40@@ -6,19 +20,16 @@ lint: blacken
41 @echo "Running flake8"
42 @tox -e lint
43
44-# We actually use the build directory created by charmcraft,
45-# but the .charm file makes a much more convenient sentinel.
46-
47-unittest: mm-pd-bot.charm
48+unittest: $(CHARM_FILE)
49 @tox -e unit
50
51 test: lint unittest
52
53 clean:
54 @echo "Cleaning files"
55- @git clean -fXd
56-
57-mm-pd-bot.charm: src/*.py requirements.txt
58- charmcraft build
59+ @find $(PROJECTPATH) -name "*.pyc" -exec rm -f {} +
60+ @find $(PROJECTPATH) -name "__pycache__" -type d -exec rm -rf {} +
61+ @rm -f $(CHARM_FILE)
62+ @rm -rf $(PROJECTPATH)/{build,charm} # Delete the build directory
63
64-.PHONY: lint test unittest clean
65+.PHONY: all lint test unittest clean
66diff --git a/config.yaml b/config.yaml
67index 48ac478..1e1e3e8 100644
68--- a/config.yaml
69+++ b/config.yaml
70@@ -22,6 +22,7 @@ options:
71 The whole configuration file of the bot is passed as content to this setting.
72
73 This setting is required.
74+ default: ''
75 tls_secret_name:
76 type: string
77 description: |
78diff --git a/src/charm.py b/src/charm.py
79index 4de6b21..b17ced0 100755
80--- a/src/charm.py
81+++ b/src/charm.py
82@@ -13,7 +13,6 @@ from ops.main import main
83 from ops.model import (
84 ActiveStatus,
85 BlockedStatus,
86- MaintenanceStatus,
87 )
88
89
90@@ -36,8 +35,6 @@ BOT_CFG_SECTION = 'MattermostBot'
91 class MmPdBotK8sCharmConfigError(Exception):
92 """Exception when configuration is bad."""
93
94- pass
95-
96
97 class MmPdBotK8sCharm(CharmBase):
98 def __init__(self, *args) -> None:
99@@ -74,7 +71,7 @@ class MmPdBotK8sCharm(CharmBase):
100 """
101 errors = []
102 for required in REQUIRED_JUJU_SETTINGS:
103- if required not in self.model.config:
104+ if not self.model.config[required]:
105 logger.error("Required setting empty: %s", required)
106 errors.append(required)
107 if errors:
108@@ -117,9 +114,8 @@ class MmPdBotK8sCharm(CharmBase):
109 def _load_mm_pd_bot_configuration(self, configuration: str) -> configparser.ConfigParser:
110 """Load the bot configuration
111
112- :param str configuration: The configuration of the bot.
113+ :param configuration: The configuration of the bot.
114 :returns: Returns a configparser.ConfigParser object with the configuration.
115- :rtype: configparser.ConfigParser
116 :raises: MmPdBotK8sCharmConfigError if the configuration is invalid.
117 """
118 config = configparser.ConfigParser(allow_no_value=True)
119@@ -132,11 +128,7 @@ class MmPdBotK8sCharm(CharmBase):
120 return config
121
122 def _validate_mm_pd_bot_configuration(self) -> None:
123- """Check the configuration part related to mm_pd_bot configuration.
124-
125- :returns: List of errors detected
126- :rtype: list
127- """
128+ """Check the configuration part related to mm_pd_bot configuration."""
129 self.bot_config = self._load_mm_pd_bot_configuration(self.model.config['mm_pd_bot_cfg'])
130 self._validate_mm_pd_bot_configuration_content()
131 self._validate_bot_creds()
132@@ -153,7 +145,6 @@ class MmPdBotK8sCharm(CharmBase):
133 """Return an envConfig with some core configuration.
134
135 :returns: A dictionary used for envConfig in podspec
136- :rtype: dict
137 """
138 config = self.model.config
139 pod_config = {
140@@ -165,7 +156,7 @@ class MmPdBotK8sCharm(CharmBase):
141 def _update_pod_spec_for_k8s_ingress(self, pod_spec: dict) -> None:
142 """Add resources to pod_spec configuring site ingress, if needed.
143
144- :param dict pod_spec: pod spec v3 as defined by juju.
145+ :param pod_spec: pod spec v3 as defined by juju.
146 """
147
148 hostname = self.bot_config.get('httpd', 'hostname')
149@@ -202,7 +193,7 @@ class MmPdBotK8sCharm(CharmBase):
150 }
151 if tls_secret_name:
152 ingress['spec']['tls'] = [
153- {'hosts': [bot_listening_url_parsed.hostname], 'secretName': tls_secret_name,},
154+ {'hosts': [bot_listening_url_parsed.hostname], 'secretName': tls_secret_name},
155 ]
156 else:
157 annotations['nginx.ingress.kubernetes.io/ssl-redirect'] = 'false'
158@@ -221,7 +212,7 @@ class MmPdBotK8sCharm(CharmBase):
159 pod_spec['kubernetesResources'] = resources
160
161 def _make_pod_spec(self) -> None:
162- """Return a pod spec with some core configuration."""
163+ """Create a pod spec with some core configuration."""
164
165 config = self.model.config
166 container_port = self.bot_config.getint('httpd', 'listen-port')
167@@ -258,7 +249,7 @@ class MmPdBotK8sCharm(CharmBase):
168 def configure_pod(self, event: ops.framework.EventBase) -> None:
169 """Assemble the pod spec and apply it, if possible.
170
171- :param ops.framework.EventBase event: Event that triggered the method.
172+ :param event: Event that triggered the method.
173 """
174
175 if not self.unit.is_leader():
176@@ -270,14 +261,13 @@ class MmPdBotK8sCharm(CharmBase):
177 self.unit.status = BlockedStatus(str(exc))
178 return
179
180- self.unit.status = MaintenanceStatus('Assembling pod spec')
181+ logger.info('Assembling pod spec')
182 pod_spec = self._make_pod_spec()
183 self._update_pod_spec_for_k8s_ingress(pod_spec)
184-
185- self.unit.status = MaintenanceStatus('Setting pod spec')
186+ logger.info('Setting pod spec')
187 self.model.pod.set_spec(pod_spec)
188 self.unit.status = ActiveStatus()
189
190
191-if __name__ == '__main__':
192+if __name__ == '__main__': # pragma: no cover
193 main(MmPdBotK8sCharm, use_juju_for_storage=True)
194diff --git a/tests/unit/scenario.py b/tests/unit/scenario.py
195index 4c83a52..9c62641 100644
196--- a/tests/unit/scenario.py
197+++ b/tests/unit/scenario.py
198@@ -39,7 +39,7 @@ def get_cfg_content(configuration='good_configuration') -> str:
199 sys.exit(1)
200
201
202-def get_juju_settings() -> list:
203+def get_juju_settings_default_value() -> list:
204 """Return the list of juju settings as defined in config.yaml."""
205
206 dir_path = os.path.dirname(os.path.realpath(__file__))
207@@ -47,24 +47,27 @@ def get_juju_settings() -> list:
208 with open(config_yaml, 'r') as config:
209 loaded_config = yaml.safe_load(config.read())
210
211- return list(loaded_config['options'].keys())
212+ # Load the dict with the default values
213+ default_values = {config: value['default'] for (config, value) in loaded_config['options'].items()}
214+
215+ return default_values
216
217
218 # List of all juju settings. Used to clear them between tests
219-JUJU_SETTINGS = get_juju_settings()
220+JUJU_SETTINGS_DEFAULT = get_juju_settings_default_value()
221
222 TEST_JUJU_SETTINGS = {
223- 'missing_image_path': {
224+ 'empty_image_path': {
225 'config': {'mm_pd_bot_cfg': 'dummy'},
226 'logger': ["ERROR:root:Required setting empty: image_path"],
227 'expected': 'Required setting(s) empty: image_path',
228 },
229- 'missing_mm_pd_bot_cfg': {
230+ 'empty_mm_pd_bot_cfg': {
231 'config': {'image_path': 'mm_pd_bot:devel'},
232 'logger': ["ERROR:root:Required setting empty: mm_pd_bot_cfg"],
233 'expected': 'Required setting(s) empty: mm_pd_bot_cfg',
234 },
235- 'missing_all_settings': {
236+ 'empty_all_settings': {
237 'config': {},
238 'logger': ["ERROR:root:Required setting empty: image_path", "ERROR:root:Required setting empty: mm_pd_bot_cfg"],
239 'expected': 'Required setting(s) empty: image_path, mm_pd_bot_cfg',
240@@ -74,17 +77,17 @@ TEST_JUJU_SETTINGS = {
241
242 VALIDATE_MM_PD_BOT_CFG = {
243 'good_configuration': {
244- 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content("good_configuration"),},
245+ 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content("good_configuration")},
246 'expected': True,
247 'logger': [],
248 },
249 'bad_formatted_configuration': {
250- 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': "[PagerDuty",},
251+ 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': "[PagerDuty"},
252 'expected': "Error while parsing mm_pd_bot_cfg setting",
253 'logger': ["ERROR:root:Error while parsing mm_pd_bot_cfg setting"],
254 },
255 'missing_sections': {
256- 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('missing_sections'),},
257+ 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('missing_sections')},
258 'expected': "Required section(s) missing in bot configuration file: "
259 "MattermostBot, Prometheus, httpd, nickname to email",
260 'logger': [
261@@ -95,7 +98,7 @@ VALIDATE_MM_PD_BOT_CFG = {
262 ],
263 },
264 'missing_options': {
265- 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('missing_options'),},
266+ 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('missing_options')},
267 'expected': "Required option(s) missing in section MattermostBot: bot_team, bot_url, "
268 "Required option(s) missing in section PagerDuty: api-token, "
269 "Required option(s) missing in section httpd: hostname, listen-ip, listen-port, magic-uuid",
270@@ -110,12 +113,12 @@ VALIDATE_MM_PD_BOT_CFG = {
271 ],
272 },
273 'no_valid_authentication': {
274- 'config': {'mm_pd_bot_cfg': get_cfg_content('no_valid_authentication'),},
275+ 'config': {'mm_pd_bot_cfg': get_cfg_content('no_valid_authentication')},
276 'expected': "bot_token or bot_login/bot_password in MattermostBot section required",
277 'logger': ["ERROR:root:bot_token or bot_login/bot_password in MattermostBot section required"],
278 },
279 'both_authentication_method': {
280- 'config': {'mm_pd_bot_cfg': get_cfg_content('both_authentication_method'),},
281+ 'config': {'mm_pd_bot_cfg': get_cfg_content('both_authentication_method')},
282 'expected': "bot_token and bot_login are both set. Pick one of them",
283 'logger': ["ERROR:root:bot_token and bot_login are both set. Pick one of them"],
284 },
285@@ -123,13 +126,15 @@ VALIDATE_MM_PD_BOT_CFG = {
286
287 VALIDATE_POD_SPEC = {
288 'basic': {
289- 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('good_configuration'),},
290+ 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('good_configuration')},
291 'pod_spec': {
292 'version': 3, # otherwise resources are ignored
293 'containers': [
294 {
295 'name': 'mm-pd-bot',
296- 'imageDetails': {'imagePath': 'mm_pd_bot:devel',},
297+ 'imageDetails': {
298+ 'imagePath': 'mm_pd_bot:devel',
299+ },
300 'imagePullPolicy': 'Always',
301 'ports': [{'containerPort': 2160, 'protocol': 'TCP'}],
302 'envConfig': {'MM_PD_BOT_CFG': get_cfg_content('good_configuration')},
303@@ -149,7 +154,7 @@ VALIDATE_POD_SPEC = {
304 'containers': [
305 {
306 'name': 'mm-pd-bot',
307- 'imageDetails': {'imagePath': 'mm_pd_bot:devel', 'username': 'rockity', 'password': 'rock',},
308+ 'imageDetails': {'imagePath': 'mm_pd_bot:devel', 'username': 'rockity', 'password': 'rock'},
309 'imagePullPolicy': 'Always',
310 'ports': [{'containerPort': 2160, 'protocol': 'TCP'}],
311 'envConfig': {'MM_PD_BOT_CFG': get_cfg_content('good_configuration')},
312@@ -162,13 +167,13 @@ VALIDATE_POD_SPEC = {
313
314 VALIDATE_POD_SPEC_AND_INGRESS = {
315 'basic': {
316- 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('good_configuration'),},
317+ 'config': {'image_path': 'mm_pd_bot:devel', 'mm_pd_bot_cfg': get_cfg_content('good_configuration')},
318 'pod_spec': {
319 'version': 3, # otherwise resources are ignored
320 'containers': [
321 {
322 'name': 'mm-pd-bot',
323- 'imageDetails': {'imagePath': 'mm_pd_bot:devel',},
324+ 'imageDetails': {'imagePath': 'mm_pd_bot:devel'},
325 'imagePullPolicy': 'Always',
326 'ports': [{'containerPort': 2160, 'protocol': 'TCP'}],
327 'envConfig': {'MM_PD_BOT_CFG': get_cfg_content('good_configuration')},
328@@ -193,7 +198,7 @@ VALIDATE_POD_SPEC_AND_INGRESS = {
329 },
330 ],
331 },
332- 'annotations': {'nginx.ingress.kubernetes.io/ssl-redirect': 'false',},
333+ 'annotations': {'nginx.ingress.kubernetes.io/ssl-redirect': 'false'},
334 },
335 ],
336 },
337@@ -211,7 +216,50 @@ VALIDATE_POD_SPEC_AND_INGRESS = {
338 'containers': [
339 {
340 'name': 'mm-pd-bot',
341- 'imageDetails': {'imagePath': 'mm_pd_bot:devel',},
342+ 'imageDetails': {'imagePath': 'mm_pd_bot:devel'},
343+ 'imagePullPolicy': 'Always',
344+ 'ports': [{'containerPort': 2160, 'protocol': 'TCP'}],
345+ 'envConfig': {'MM_PD_BOT_CFG': get_cfg_content('ssl_configuration')},
346+ }
347+ ],
348+ 'kubernetesResources': {
349+ 'ingressResources': [
350+ {
351+ 'name': 'mm-pd-bot-ingress',
352+ 'spec': {
353+ 'rules': [
354+ {
355+ 'host': 'mm-pd-bot.example.com',
356+ 'http': {
357+ 'paths': [
358+ {
359+ 'path': '/bdddcacb-ab42-40ac-9106-4275c1db1519/',
360+ 'backend': {'serviceName': 'mm-pd-bot', 'servicePort': 2160},
361+ },
362+ ],
363+ },
364+ },
365+ ],
366+ 'tls': [{'hosts': ['mm-pd-bot.example.com'], 'secretName': 'mm_pd_bot_secret'}],
367+ },
368+ 'annotations': {'nginx.ingress.kubernetes.io/whitelist-source-range': '10.0.69.0/24'},
369+ },
370+ ],
371+ },
372+ },
373+ },
374+ 'ssl_without_whitelist': {
375+ 'config': {
376+ 'image_path': 'mm_pd_bot:devel',
377+ 'mm_pd_bot_cfg': get_cfg_content('ssl_configuration'),
378+ 'tls_secret_name': 'mm_pd_bot_secret',
379+ },
380+ 'pod_spec': {
381+ 'version': 3, # otherwise resources are ignored
382+ 'containers': [
383+ {
384+ 'name': 'mm-pd-bot',
385+ 'imageDetails': {'imagePath': 'mm_pd_bot:devel'},
386 'imagePullPolicy': 'Always',
387 'ports': [{'containerPort': 2160, 'protocol': 'TCP'}],
388 'envConfig': {'MM_PD_BOT_CFG': get_cfg_content('ssl_configuration')},
389@@ -235,9 +283,8 @@ VALIDATE_POD_SPEC_AND_INGRESS = {
390 },
391 },
392 ],
393- 'tls': [{'hosts': ['mm-pd-bot.example.com'], 'secretName': 'mm_pd_bot_secret',},],
394+ 'tls': [{'hosts': ['mm-pd-bot.example.com'], 'secretName': 'mm_pd_bot_secret'}],
395 },
396- 'annotations': {'nginx.ingress.kubernetes.io/whitelist-source-range': '10.0.69.0/24',},
397 },
398 ],
399 },
400diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
401index 30a474f..27bbaf3 100755
402--- a/tests/unit/test_charm.py
403+++ b/tests/unit/test_charm.py
404@@ -18,7 +18,7 @@ from ops.model import (
405 )
406
407 from scenario import (
408- JUJU_SETTINGS,
409+ JUJU_SETTINGS_DEFAULT,
410 TEST_JUJU_SETTINGS,
411 VALIDATE_MM_PD_BOT_CFG,
412 VALIDATE_POD_SPEC,
413@@ -53,14 +53,12 @@ class TestMmPdBotK8sCharmBlockedStatus(unittest.TestCase):
414 with self.subTest(scenario=scenario):
415 with self.assertLogs(level='ERROR') as logger:
416 with self.assertRaises(MmPdBotK8sCharmConfigError) as exc:
417+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # Load the default values
418 self.harness.update_config(values['config'])
419 self.harness.charm._check_juju_settings()
420 self.assertEqual(sorted(logger.output), sorted(values['logger']))
421 self.assertEqual(str(exc.exception), values['expected'])
422- # You need to clean the config after each run
423- # See https://github.com/canonical/operator/blob/master/ops/testing.py#L415
424- # The second argument is the list of key to reset
425- self.harness.update_config({}, JUJU_SETTINGS)
426+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # You need to clean the config after each run
427
428 def test_validate_mm_pd_bot_configuration(self):
429 """Check the MM_PD_BOT_CFG string is a valid INI."""
430@@ -75,7 +73,7 @@ class TestMmPdBotK8sCharmBlockedStatus(unittest.TestCase):
431 self.harness.charm._validate_mm_pd_bot_configuration()
432 self.assertEqual(str(exc.exception), values['expected'])
433 self.assertEqual(sorted(logger.output), sorted(values['logger']))
434- self.harness.update_config({}, JUJU_SETTINGS) # You need to clean the config after each run
435+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # You need to clean the config after each run
436
437 def test_load_mm_pd_bot_configuration(self):
438 """Test the loading of the configuration for the bot."""
439@@ -92,20 +90,36 @@ class TestMmPdBotK8sCharmBlockedStatus(unittest.TestCase):
440 """Test the pod configuration."""
441 mock_event = MagicMock()
442
443+ # Good configuration but not leader
444 self.harness.update_config(VALIDATE_MM_PD_BOT_CFG['good_configuration']['config'])
445 self.harness.set_leader(False)
446 self.harness.charm.unit.status = BlockedStatus("Testing")
447 self.harness.charm.configure_pod(mock_event)
448 self.assertEqual(self.harness.charm.unit.status, ActiveStatus())
449- self.harness.update_config({}, JUJU_SETTINGS) # You need to clean the config after each run
450+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # You need to clean the config after each run
451
452+ # Good configuration and leader
453+ self.harness.update_config(VALIDATE_MM_PD_BOT_CFG['good_configuration']['config'])
454+ self.harness.set_leader(True)
455+ self.harness.charm.unit.status = BlockedStatus("Testing")
456+ self.harness.charm.configure_pod(mock_event)
457+ with self.assertLogs(level='INFO') as logger:
458+ self.harness.charm.configure_pod(mock_event)
459+ self.assertEqual(
460+ sorted(logger.output),
461+ ["INFO:root:Assembling pod spec", "INFO:root:Setting pod spec"],
462+ )
463+ self.assertEqual(self.harness.charm.unit.status, ActiveStatus())
464+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # You need to clean the config after each run
465+
466+ # Bad configuration and leader
467 config = VALIDATE_MM_PD_BOT_CFG['bad_formatted_configuration']['config']
468 expected = VALIDATE_MM_PD_BOT_CFG['bad_formatted_configuration']['expected']
469 self.harness.update_config(config)
470 self.harness.set_leader(True)
471 self.harness.charm.configure_pod(mock_event)
472 self.assertEqual(self.harness.charm.unit.status, BlockedStatus(expected))
473- self.harness.update_config({}, JUJU_SETTINGS) # You need to clean the config after each run
474+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # You need to clean the config after each run
475
476 def test_make_pod_spec(self):
477 """Check the crafting of the pod spec."""
478@@ -116,7 +130,7 @@ class TestMmPdBotK8sCharmBlockedStatus(unittest.TestCase):
479 values['config']['mm_pd_bot_cfg']
480 )
481 self.assertEqual(self.harness.charm._make_pod_spec(), values['pod_spec'])
482- self.harness.update_config({}, JUJU_SETTINGS) # You need to clean the config after each run
483+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # You need to clean the config after each run
484
485 def test_update_pod_spec_for_k8s_ingress(self):
486 """Check the crafting of the ingress part of the pod spec."""
487@@ -129,7 +143,7 @@ class TestMmPdBotK8sCharmBlockedStatus(unittest.TestCase):
488 pod_spec = self.harness.charm._make_pod_spec()
489 self.harness.charm._update_pod_spec_for_k8s_ingress(pod_spec)
490 self.assertEqual(pod_spec, values['pod_spec'])
491- self.harness.update_config({}, JUJU_SETTINGS) # You need to clean the config after each run
492+ self.harness.update_config(JUJU_SETTINGS_DEFAULT) # You need to clean the config after each run
493
494
495 if __name__ == '__main__':
496diff --git a/tox.ini b/tox.ini
497index 77c821d..7e09302 100644
498--- a/tox.ini
499+++ b/tox.ini
500@@ -28,7 +28,7 @@ deps = -r{toxinidir}/tests/functional/requirements.txt
501 -r{toxinidir}/requirements.txt
502
503 [testenv:black]
504-commands = black --skip-string-normalization --line-length=120 src/ tests/
505+commands = black src/ tests/
506 deps = black
507
508 [testenv:lint]

Subscribers

People subscribed via source and target branches