canonical / opensearch-operator

OpenSearch operator
Apache License 2.0
12 stars 7 forks source link

[DPE-5468][test_charm.py] ensure deployment_desc available at post start #453

Closed phvalguima closed 1 month ago

phvalguima commented 2 months ago

Due to LP#2076599

The relation databags may be empty if we are running a single unit cluster and we hit "remove-application".

In this case, if we had a post start running, then this method will fail as it tries to check for the deployment description.

Closes #444

phvalguima commented 2 months ago

After adding fix for #444, it fails then on:

2024-09-22T11:07:10.9372749Z Traceback (most recent call last):
2024-09-22T11:07:10.9373176Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/./src/charm.py", line 213, in <module>
2024-09-22T11:07:10.9373321Z     main(OpenSearchOperatorCharm)
2024-09-22T11:07:10.9373732Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/main.py", line 551, in main
2024-09-22T11:07:10.9373846Z     manager.run()
2024-09-22T11:07:10.9374435Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/main.py", line 530, in run
2024-09-22T11:07:10.9374553Z     self._emit()
2024-09-22T11:07:10.9374963Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/main.py", line 519, in _emit
2024-09-22T11:07:10.9375184Z     _emit_charm_event(self.charm, self.dispatcher.event_name)
2024-09-22T11:07:10.9375671Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/main.py", line 147, in _emit_charm_event
2024-09-22T11:07:10.9375809Z     event_to_emit.emit(*args, **kwargs)
2024-09-22T11:07:10.9376364Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/framework.py", line 348, in emit
2024-09-22T11:07:10.9376500Z     framework._emit(event)
2024-09-22T11:07:10.9376960Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/framework.py", line 860, in _emit
2024-09-22T11:07:10.9377094Z     self._reemit(event_path)
2024-09-22T11:07:10.9377545Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/framework.py", line 950, in _reemit
2024-09-22T11:07:10.9377669Z     custom_handler(event)
2024-09-22T11:07:10.9378427Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/lib/charms/opensearch/v0/opensearch_base_charm.py", line 561, in _on_opensearch_data_storage_detaching
2024-09-22T11:07:10.9378555Z     self._stop_opensearch()
2024-09-22T11:07:10.9379221Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/lib/charms/opensearch/v0/opensearch_base_charm.py", line 1110, in _stop_opensearch
2024-09-22T11:07:10.9379348Z     nodes = self._get_nodes(True)
2024-09-22T11:07:10.9379971Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/lib/charms/opensearch/v0/opensearch_base_charm.py", line 1341, in _get_nodes
2024-09-22T11:07:10.9380299Z     if self.opensearch_peer_cm.deployment_desc().start == StartMode.WITH_PROVIDED_ROLES:
2024-09-22T11:07:10.9380704Z AttributeError: 'NoneType' object has no attribute 'start'
phvalguima commented 2 months ago

Moved the check added here to the early step before at _start_opensearch as we are not covering the following error yet:

2024-09-22T18:50:02.9692933Z Traceback (most recent call last):
2024-09-22T18:50:02.9693348Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/./src/charm.py", line 213, in <module>
2024-09-22T18:50:02.9693489Z     main(OpenSearchOperatorCharm)
2024-09-22T18:50:02.9693878Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/main.py", line 551, in main
2024-09-22T18:50:02.9693984Z     manager.run()
2024-09-22T18:50:02.9694369Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/main.py", line 530, in run
2024-09-22T18:50:02.9694478Z     self._emit()
2024-09-22T18:50:02.9694880Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/main.py", line 516, in _emit
2024-09-22T18:50:02.9695006Z     self.framework.reemit()
2024-09-22T18:50:02.9695436Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/framework.py", line 870, in reemit
2024-09-22T18:50:02.9695671Z     self._reemit()
2024-09-22T18:50:02.9696117Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/venv/ops/framework.py", line 950, in _reemit
2024-09-22T18:50:02.9696230Z     custom_handler(event)
2024-09-22T18:50:02.9697003Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/lib/charms/opensearch/v0/opensearch_base_charm.py", line 872, in _start_opensearch
2024-09-22T18:50:02.9697134Z     self._post_start_init(event)
2024-09-22T18:50:02.9697781Z   File "/var/lib/juju/agents/unit-opensearch-0/charm/lib/charms/opensearch/v0/opensearch_base_charm.py", line 973, in _post_start_init
2024-09-22T18:50:02.9698024Z     "data" in self.opensearch_peer_cm.deployment_desc().config.roles
2024-09-22T18:50:02.9698410Z AttributeError: 'NoneType' object has no attribute 'config'