def test_check_remove_conf_dir_failure2(caplog): temp_dir = tempfile.mkdtemp() conf_dir = os.path.join(temp_dir, "ok") fake_exception = Exception('fake') with patch('intel.config.Config', MagicMock(side_effect=fake_exception)): with pytest.raises(SystemExit): uninstall.check_remove_conf_dir(conf_dir) caplog_tuple = caplog.record_tuples exp_err = "Aborting uninstall: Unable to read the CMK configuration " \ "directory at \"{}\": {}.".format(conf_dir, fake_exception) assert caplog_tuple[-1][2] == exp_err
def test_check_remove_conf_dir_failure(monkeypatch, caplog): temp_dir = tempfile.mkdtemp() conf_dir = os.path.join(temp_dir, "ok") helpers.execute("cp", ["-r", helpers.conf_dir("ok"), "{}".format(conf_dir)]) # Pid in below path is present in cmk conf dir monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok_1_running")) with pytest.raises(SystemExit): uninstall.check_remove_conf_dir(conf_dir) helpers.execute("stat", ["{}".format(conf_dir)]) caplog_tuple = caplog.record_tuples exp_str = "Aborting uninstall: Exception when removing \"{}\": There " \ "are running tasks, check pools in \"{}\"."\ .format(conf_dir, conf_dir) assert caplog_tuple[-1][2] == exp_str
def test_check_remove_lock_file_success(monkeypatch, caplog): temp_dir = tempfile.mkdtemp() conf_dir = os.path.join(temp_dir, "ok") helpers.execute("cp", ["-r", helpers.conf_dir("ok"), "{}".format(conf_dir)]) # Pid in below path is not in cmk conf dir monkeypatch.setenv(proc.ENV_PROC_FS, helpers.procfs_dir("ok")) uninstall.check_remove_conf_dir(conf_dir) caplog_tuple = caplog.record_tuples lock_file = os.path.join(conf_dir, "lock") with pytest.raises(Exception): helpers.execute("stat", ["{}".format(lock_file)]) assert caplog_tuple[-1][2] == "\"{}\" removed".format(lock_file)