charm-ironic-conductor/unit_tests/test_actions.py
Corey Bryant 9f221f1087 Fix exception in set-temp-url-secret action
There are two issues fixed in this bug. The first is that the
keystone_session exception block does not return on failure. The
second, and the reason that create_keystone_session is failing,
is due to the use of setuptools 60.9.0+ with the
importlib-metadata in wheelhouse.txt that is pinned to <3.0.0.
For more details see: https://github.com/pypa/setuptools/issues/3452

Closes-Bug: #2018018
Change-Id: I266c1fb92d531aded2f3253766de0a79accd9577
2023-04-28 15:58:43 -04:00

47 lines
1.6 KiB
Python

import src.actions.actions as actions
import unit_tests.test_utils
import reactive.ironic_handlers as handlers
import charm.openstack.ironic.api_utils as api_utils
import charmhelpers.core as ch_core
import charms.leadership as leadership
import mock
class TestActions(unit_tests.test_utils.CharmTestCase):
def setUp(self):
super(TestActions, self).setUp()
self.patches = []
self.patch_all()
self.ironic_charm = mock.MagicMock()
self.patch_object(handlers.charm, 'provide_charm_instance',
new=mock.MagicMock())
self.provide_charm_instance().__enter__.return_value = \
self.ironic_charm
self.provide_charm_instance().__exit__.return_value = None
def test_set_temp_url_secret_keystone_session_successful(self):
self.patch_object(ch_core.hookenv, 'action_fail')
self.patch_object(leadership, 'leader_get')
actions.set_temp_url_secret()
self.leader_get.assert_called_with('temp_url_secret')
def test_set_temp_url_secret_keystone_session_exception(self):
self.patch_object(api_utils, 'create_keystone_session')
self.patch_object(ch_core.hookenv, 'action_fail')
self.patch_object(leadership, 'leader_get')
def raise_exception(*args):
raise Exception("doh!")
self.create_keystone_session.side_effect = raise_exception
actions.set_temp_url_secret()
self.action_fail.assert_called_with(
'Failed to create keystone session ("doh!")')
self.leader_get.assert_not_called()