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
This commit is contained in:
Jadon Naas 2024-05-21 11:13:39 -04:00
parent 655f36440f
commit 456a418ba4

View File

@ -49,6 +49,9 @@ class Helper(test_utils.PatchHelper):
# simply the CompareHostReleases to just return then string for
# comparisons. (won't work for xenial/bionic)
self.ch_core_host.CompareHostReleases.side_effect = lambda x: x
charm = designate_bind.DesignateBindCharm(release='icehouse')
self.patch("charms_openstack.charm.core.default_get_charm_instance",
new=lambda *_, **__: charm)
self.patch('charms_openstack.charm.core._singleton', new=None)
@ -81,6 +84,9 @@ class TestOpenStackDesignateBind(Helper):
self.ch_core_host.lsb_release.return_value = {
"DISTRIB_CODENAME": "focal"
}
actual_charm = designate_bind.DesignateBindCharm(release='icehouse')
self.patch("charms_openstack.charm.core.default_get_charm_instance",
new=lambda *_, **__: actual_charm)
charm = designate_bind.DesignateBindCharm.singleton
self.assertEqual(charm.services, ["named"])
for v in charm.restart_map.values():