Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cert_handler lib assumes peer relation named peers exists for upgrade_charm event handler #93

Closed
shayancanonical opened this issue Jun 3, 2024 · 1 comment · Fixed by #97

Comments

@shayancanonical
Copy link

Bug Description

The cert_handler.py charm lib assumes here that a peer relation named peers exists in the charm that uses it. This assumption is not correct in database charms (as it is named database-peers in the mysql charms). This leads to an error in Juju 2.9.X where the peers relation is not found in the upgrade_charm event handler

To Reproduce

  1. clone the mysql vm charm
  2. git checkout 6817e0a
  3. pack charm and deploy it
  4. juju refresh mysql --path ./path-to-packed-charm.charm

Environment

ubuntu: 22.04.4
juju: 2.9.46
lxd: 5.21.1-2d13beb

Relevant log output

unit-mysql-1: 19:53:41 ERROR unit.mysql/1.juju-log Uncaught exception while in charm code:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-mysql-1/charm/./src/charm.py", line 898, in <module>
    main(MySQLOperatorCharm)
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/main.py", line 436, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/main.py", line 144, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/framework.py", line 351, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/framework.py", line 853, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/framework.py", line 942, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-mysql-1/charm/lib/charms/observability_libs/v1/cert_handler.py", line 352, in _on_upgrade_charm
    has_privkey = self.vault.get_value("private-key")
  File "/var/lib/juju/agents/unit-mysql-1/charm/lib/charms/observability_libs/v1/cert_handler.py", line 255, in get_value
    return self._backend.get_value(key)
  File "/var/lib/juju/agents/unit-mysql-1/charm/lib/charms/observability_libs/v1/cert_handler.py", line 179, in get_value
    return self._read().get(key)
  File "/var/lib/juju/agents/unit-mysql-1/charm/lib/charms/observability_libs/v1/cert_handler.py", line 155, in _read
    value = self._databag.get(self._NEST_UNDER)
  File "/var/lib/juju/agents/unit-mysql-1/charm/lib/charms/observability_libs/v1/cert_handler.py", line 150, in _databag
    self._check_ready()
  File "/var/lib/juju/agents/unit-mysql-1/charm/lib/charms/observability_libs/v1/cert_handler.py", line 136, in _check_ready
    relation = self.charm.model.get_relation(self.relation_name)
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/model.py", line 237, in get_relation
    return self.relations._get_unique(relation_name, relation_id)
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/model.py", line 853, in _get_unique
    relations = self[relation_name]
  File "/var/lib/juju/agents/unit-mysql-1/charm/venv/ops/model.py", line 821, in __getitem__
    relation_list: Optional[List[Relation]] = self._data[relation_name]
KeyError: 'peers'

Additional context

No response

@PietroPasotti
Copy link
Contributor

the "peers" relation name is hardcoded in the certhandler, we can fix that easily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants