johnsca / juju-relation-mysql

Other
2 stars 5 forks source link

`server-relation-broken` handler raise exception #3

Closed ycliuhw closed 6 years ago

ycliuhw commented 6 years ago

hi @johnsca I found an error raised from uniter hook runner when I ran juju remove-relation.

The root cause is self.conversation is not accessible for event server-relation-broken because in RelationBase.conversation method, the scope var will be None when the relation class scope set to non GLOBAL - JUJU_REMOTE_UNIT="" in this case.

the logs as below ->

2018-04-18 05:57:22 DEBUG juju.worker.uniter.operation executor.go:60 running operation run relation-broken (3) hook
2018-04-18 05:57:22 DEBUG juju.worker.uniter uniter.go:641 acquire lock "machine-lock" for uniter hook execution
2018-04-18 05:57:22 DEBUG juju.worker.uniter uniter.go:646 lock "machine-lock" acquired
2018-04-18 05:57:22 DEBUG juju.worker.uniter.operation executor.go:91 preparing operation "run relation-broken (3) hook"
2018-04-18 05:57:22 DEBUG juju.worker.uniter.operation executor.go:91 executing operation "run relation-broken (3) hook"
2018-04-18 05:57:22 DEBUG juju.worker.uniter agent.go:17 [AGENT-STATUS] executing: running server-relation-broken hook
2018-04-18 05:57:23 DEBUG worker.uniter.jujuc server.go:181 running hook tool "config-get"
2018-04-18 05:57:23 DEBUG worker.uniter.jujuc server.go:181 running hook tool "juju-log"
2018-04-18 05:57:23 INFO juju-log server:3: Reactive main running for hook server-relation-broken
2018-04-18 05:57:23 DEBUG worker.uniter.jujuc server.go:181 running hook tool "juju-log"
2018-04-18 05:57:23 INFO juju-log server:3: Invoking reactive handler: ../../application-mysql/charm/hooks/relations/mysql/provides.py:42:departed
2018-04-18 05:57:23 DEBUG worker.uniter.jujuc server.go:181 running hook tool "juju-log"
2018-04-18 05:57:23 ERROR juju-log server:3: Hook error:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/__init__.py", line 72, in main
    bus.dispatch(restricted=restricted_mode)
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 367, in dispatch
    _invoke(hook_handlers)
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 351, in _invoke
    handler.invoke()
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 173, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/application-mysql/charm/hooks/relations/mysql/provides.py", line 44, in departed
    conversation = self.conversation()
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/relations.py", line 434, in conversation
    raise ValueError('Unable to determine default scope: no current hook or global scope')
ValueError: Unable to determine default scope: no current hook or global scope

2018-04-18 05:57:23 DEBUG server-relation-broken self.scope ---->  service {'JUJU_MODEL_UUID': '9a37894d-61ee-4bca-8596-edf821b14e71', 'JUJU_METER_INFO': 'not set', 'JUJU_SLA': 'unsupported', 'no_proxy': '127.0.0.1,::1,localhost', 'JUJU_REMOTE_UNIT': '', 'JUJU_CHARM_DIR': '/var/lib/juju/agents/unit-mysql-0/charm', 'JUJU_MACHINE_ID': '', 'APT_LISTCHANGES_FRONTEND': 'none', 'NO_PROXY': '127.0.0.1,::1,localhost', 'JUJU_AVAILABILITY_ZONE': '', 'JUJU_CONTEXT_ID': 'mysql/0-server-relation-broken-4129177037886487361', 'JUJU_UNIT_NAME': 'mysql/0', 'JUJU_METER_STATUS': 'AMBER', 'CHARM_DIR': '/var/lib/juju/agents/unit-mysql-0/charm', 'JUJU_RELATION_ID': 'server:3', 'JUJU_PRINCIPAL_UNIT': '', 'JUJU_MODEL_NAME': 'testcaas7', 'JUJU_VERSION': '2.4-beta1', 'PATH': '/var/lib/juju/tools/unit-mysql-0:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'JUJU_AGENT_SOCKET': '@/var/lib/juju/agents/unit-mysql-0/agent.socket', 'JUJU_RELATION': 'server', 'JUJU_API_ADDRESSES': '10.10.145.220:17070', 'DEBIAN_FRONTEND': 'noninteractive', 'JUJU_HOOK_NAME': 'server-relation-broken'}
2018-04-18 05:57:23 DEBUG server-relation-broken self._convers ->  {'units': [''], 'namespace': 'server:3', 'scope': None}
2018-04-18 05:57:23 DEBUG server-relation-broken hookenv ---->   <class 'str'> --->  None
2018-04-18 05:57:23 DEBUG server-relation-broken Traceback (most recent call last):
2018-04-18 05:57:23 DEBUG server-relation-broken   File "/var/lib/juju/agents/unit-mysql-0/charm/hooks/server-relation-broken", line 18, in <module>
2018-04-18 05:57:23 DEBUG server-relation-broken     main()
2018-04-18 05:57:23 DEBUG server-relation-broken   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/__init__.py", line 72, in main
2018-04-18 05:57:23 DEBUG server-relation-broken     bus.dispatch(restricted=restricted_mode)
2018-04-18 05:57:23 DEBUG server-relation-broken   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 367, in dispatch
2018-04-18 05:57:23 DEBUG server-relation-broken     _invoke(hook_handlers)
2018-04-18 05:57:23 DEBUG server-relation-broken   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 351, in _invoke
2018-04-18 05:57:23 DEBUG server-relation-broken     handler.invoke()
2018-04-18 05:57:23 DEBUG server-relation-broken   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 173, in invoke
2018-04-18 05:57:23 DEBUG server-relation-broken     self._action(*args)
2018-04-18 05:57:23 DEBUG server-relation-broken   File "/var/lib/juju/agents/application-mysql/charm/hooks/relations/mysql/provides.py", line 44, in departed
2018-04-18 05:57:23 DEBUG server-relation-broken     conversation = self.conversation()
2018-04-18 05:57:23 DEBUG server-relation-broken   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/relations.py", line 434, in conversation
2018-04-18 05:57:23 DEBUG server-relation-broken     raise ValueError('Unable to determine default scope: no current hook or global scope')
2018-04-18 05:57:23 DEBUG server-relation-broken ValueError: Unable to determine default scope: no current hook or global scope
2018-04-18 05:57:23 ERROR juju.worker.uniter.operation runhook.go:114 hook "server-relation-broken" failed: exit status 1

I am thinking there are two ways to solve this:

would you mind to give some advise?

Thank you very much. Kelvin

johnsca commented 6 years ago

The -broken hook handling with RelationBase-based interface layers is known to be pretty broken, and is a little non-obvious how to work around (you can't use -broken, obviously, and -departed is called for every departing unit). This is part of why the alternative Endpoint was created. TBH, it would be easier to convert to that than to try to fix the RelationBase implementation. Let me take a look at it.

ycliuhw commented 6 years ago

understood. Thanks for responding for this, @johnsca . I will take a look Endpoint as well.

johnsca commented 6 years ago

@ycliuhw Please see the referenced PR for the conversion to Endpoints, if you haven't already.

ycliuhw commented 6 years ago

@johnsca thank you very much for the PR which is looking great. Just one minor docstring thing.