diff --git a/hooks/hooks.py b/hooks/hooks.py index c988a45..df3610b 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -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: diff --git a/unit_tests/test_hacluster_hooks.py b/unit_tests/test_hacluster_hooks.py index 6c43d61..f99b875 100644 --- a/unit_tests/test_hacluster_hooks.py +++ b/unit_tests/test_hacluster_hooks.py @@ -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')