Unit tests fail for KeyError in MagicMock of CompareOpenStackReleases

Bug #2066281 reported by Jadon Naas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Designate-Bind Charm
Status tracked in Trunk
2024.1
Fix Committed
Undecided
Unassigned
Trunk
Fix Committed
Undecided
Jadon Naas

Bug Description

When running unit tests against the master branch of the OpenStack Designate Bind charm the 13 tests fail with errors like the following:

unit_tests.test_lib_charm_openstack_designate_bind.TestOpenStackDesignateBind.test_get_sync_time
------------------------------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "./charm-designate-bind/unit_tests/test_lib_charm_openstack_designate_bind.py", line 112, in test_get_sync_time
    designate_bind.DesignateBindCharm.singleton,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "./charm-designate-bind/.tox/py3/lib/python3.11/site-packages/charms_openstack/charm/core.py", line 386, in singleton
    _singleton = get_charm_instance(release=release,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "./charm-designate-bind/.tox/py3/lib/python3.11/site-packages/charms_openstack/charm/core.py", line 199, in get_charm_instance
    return (_get_charm_instance_function or default_get_charm_instance)(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "./charm-designate-bind/.tox/py3/lib/python3.11/site-packages/charms_openstack/charm/core.py", line 163, in default_get_charm_instance
    cls = _releases[known_releases[-1]][package_type]
          ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^

    KeyError: "<MagicMock name='mock.contrib.openstack.utils.CompareOpenStackReleases()' id='135987910273104'>"

This failure is related to this change in charms.openstack - https://github.com/openstack/charms.openstack/commit/760f1257ef11a53e2491fda91ebf6454c1182ad3 - that added support for wrapped release names in OpenStack. That change in charms.openstack changed how obtaining OpenStack release names behaves, and the Designate Bind charm's mocking is incompatible with that change.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to charm-designate-bind (master)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to charm-designate-bind (master)

Reviewed: https://review.opendev.org/c/openstack/charm-designate-bind/+/920108
Committed: https://opendev.org/openstack/charm-designate-bind/commit/456a418ba4daf1feb6a7425e254774d7301ef3fc
Submitter: "Zuul (22348)"
Branch: master

commit 456a418ba4daf1feb6a7425e254774d7301ef3fc
Author: Jadon Naas <email address hidden>
Date: Tue May 21 11:13:39 2024 -0400

    Fix mocking for wrapped OpenStack releases

    A recent change in charms.openstack to support wrapped
    OpenStack releases caused unit tests to fail.
    The unit tests failed because mocking was incompatible
    with the change. This commit mocks the default_get_charm
    instance where the charms.openstack change was breaking
    unit tests.

    Closes-Bug: 2066281
    Change-Id: I87263ac24e5e4061757e5fb8bb167a43b2e85f93

Changed in charm-designate-bind:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to charm-designate-bind (stable/2024.1)

Fix proposed to branch: stable/2024.1
Review: https://review.opendev.org/c/openstack/charm-designate-bind/+/921990

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to charm-designate-bind (stable/2024.1)

Reviewed: https://review.opendev.org/c/openstack/charm-designate-bind/+/921990
Committed: https://opendev.org/openstack/charm-designate-bind/commit/0534df65a634dd343e5d00e2254013296d7bb8fd
Submitter: "Zuul (22348)"
Branch: stable/2024.1

commit 0534df65a634dd343e5d00e2254013296d7bb8fd
Author: Jadon Naas <email address hidden>
Date: Tue May 21 11:13:39 2024 -0400

    Fix mocking for wrapped OpenStack releases

    A recent change in charms.openstack to support wrapped
    OpenStack releases caused unit tests to fail.
    The unit tests failed because mocking was incompatible
    with the change. This commit mocks the default_get_charm
    instance where the charms.openstack change was breaking
    unit tests.

    Closes-Bug: 2066281
    Change-Id: I87263ac24e5e4061757e5fb8bb167a43b2e85f93
    (cherry picked from commit 456a418ba4daf1feb6a7425e254774d7301ef3fc)

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.