Reactive charms fail with "ImportError: cannot import name 'defaults'" on trusty/mitaka test scenarios due to charms_openstack.charm import

Bug #1788610 reported by Pedro Guimarães
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
charms.openstack
Fix Released
Undecided
Pedro Guimarães

Bug Description

I am getting errors on trusty-mitaka functional testing for Designate charm.
Both Designate's and Designate-Bind's hook install fails with following traceback:

2018-08-23 12:18:18 ERROR juju-log Hook error:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms/reactive/__init__.py", line 70, in main
    bus.discover()
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms/reactive/bus.py", line 416, in discover
    _register_handlers_from_file(search_path, filepath)
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms/reactive/bus.py", line 446, in _register_handlers_from_file
    _load_module(root, filepath)
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms/reactive/bus.py", line 434, in _load_module
    return importlib.import_module(package + module)
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/var/lib/juju/agents/unit-designate-bind-14/charm/reactive/layer_openstack.py", line 3, in <module>
    import charms_openstack.charm as charm
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms_openstack/charm/__init__.py", line 19, in <module>
    from charms_openstack.charm.defaults import use_defaults
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms_openstack/charm/defaults.py", line 5, in <module>
    from charms_openstack.charm.classes import OpenStackCharm
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms_openstack/charm/classes.py", line 19, in <module>
    from charms_openstack.charm.core import (
  File "/var/lib/juju/agents/unit-designate-bind-14/.venv/lib/python3.4/site-packages/charms_openstack/charm/core.py", line 24, in <module>
    from charms_openstack.charm import defaults as os_defaults
ImportError: cannot import name 'defaults'

Trusty is running Python version: 3.4.3

Both Designate and Designate-Bind are charm.reactive.
Other charms in same functional test pass hook "install": https://pastebin.canonical.com/p/2rzYVz4StY/

Revision history for this message
Pedro Guimarães (pguimaraes) wrote :

Could simulate this bug by running tests/gate-basic-trusty-mitaka on designate charm.

Module "defaults" is only called once on core.py: https://github.com/openstack/charms.openstack/blob/master/charms_openstack/charm/core.py#L908

Moving the import inside function "upgrade_if_available" solves this issue and all tests finish with OK

Btw, gate-basic-bionic-queens pass for Designate charm with no issues:
https://review.openstack.org/#/c/593607/

Also tried with xenial version and hook install worked correctly.
Xenial runs Python 3.5.2. Therefore, I guess it is a python 3.4 -> 3.5 issue.

Changed in charms.openstack:
assignee: nobody → Pedro Guimarães (pguimaraes)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to charms.openstack (master)

Fix proposed to branch: master
Review: https://review.openstack.org/595880

Changed in charms.openstack:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to charms.openstack (master)

Reviewed: https://review.openstack.org/595880
Committed: https://git.openstack.org/cgit/openstack/charms.openstack/commit/?id=194a2d65a9562056614ad16e9aeb7a20597a26f8
Submitter: Zuul
Branch: master

commit 194a2d65a9562056614ad16e9aeb7a20597a26f8
Author: Pedro <email address hidden>
Date: Thu Aug 23 22:04:55 2018 +0200

    Import statement removed on core.py

    from charms_openstack.charm import defaults was removed
    to allow Trusty's python 3.4 to run.
    Two variables that were present on defaults.py were
    migrated to core.py to allow removal.

    Change-Id: I90d3aae867a21417b701e0fd40a75a57d827eb52
    Closes-Bug: #1788610

Changed in charms.openstack:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.