Catch FileExistsError when creating /etc/corosync dir.
Hooks are expected to be idempotent, if the install hook for whatever
reason needs to be re-run and the /etc/corosync directory already exists,
because for example it was created in a previous run, the exception
FileExistsError will be raised, this change captures the exception and
moves on.
Change-Id: If43a5c95bb59c9cca7f1a975214a9f013ad6f4d6
Closes-Bug: #1971762
(cherry picked from commit 715d31e09f
)
This commit is contained in:
parent
23444d888d
commit
4661d9c4aa
|
@ -153,7 +153,10 @@ DEPRECATED_TRANSPORT_VALUES = {"multicast": "udp", "unicast": "udpu"}
|
|||
def install():
|
||||
# LP:1874719 Configure a corosync.conf file to avoid a spurious node1 to
|
||||
# be created in the cluster.
|
||||
os.mkdir('/etc/corosync', mode=0o755)
|
||||
try:
|
||||
os.mkdir('/etc/corosync', mode=0o755)
|
||||
except FileExistsError:
|
||||
pass
|
||||
if emit_corosync_conf():
|
||||
log('Installed initial corosync.conf file', level=INFO)
|
||||
else:
|
||||
|
|
|
@ -402,6 +402,15 @@ class TestHooks(test_utils.CharmTestCase):
|
|||
apt_install.assert_called_once_with(expected_pkgs, fatal=True)
|
||||
setup_ocf_files.assert_called_once_with()
|
||||
|
||||
mkdir.reset_mock()
|
||||
|
||||
def raise_():
|
||||
raise FileExistsError()
|
||||
|
||||
mkdir.side_effect = lambda p, mode: raise_()
|
||||
hooks.install()
|
||||
mkdir.assert_called_once_with('/etc/corosync', mode=0o755)
|
||||
|
||||
@mock.patch('pcmk.set_property')
|
||||
@mock.patch.object(hooks, 'is_stonith_configured')
|
||||
@mock.patch.object(hooks, 'configure_stonith')
|
||||
|
|
Loading…
Reference in New Issue