Module: check_mk
Branch: master
Commit: 024e4ec52aa7c88116e0edde772ea6156ca9993a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=024e4ec52aa7c8…
Author: Sergey Kipnis <sk(a)mathias-kettner.de>
Date: Thu May 2 14:14:17 2019 +0200
[CMK-1971] - installation fix and lesser refactoring corresponding APU with enum class
Change-Id: Id60329e9afc896b960f25df2351f88f0a5b43efe
---
agents/wnx/src/engine/install_api.cpp | 46 ++++++++++++++++----------------
agents/wnx/src/engine/install_api.h | 19 ++++++-------
agents/wnx/src/main/check_mk_service.cpp | 10 +++----
agents/wnx/watest/test-install-auto.cpp | 14 +++++-----
4 files changed, 46 insertions(+), 43 deletions(-)
diff --git a/agents/wnx/src/engine/install_api.cpp
b/agents/wnx/src/engine/install_api.cpp
index cd478b2..2fca605 100644
--- a/agents/wnx/src/engine/install_api.cpp
+++ b/agents/wnx/src/engine/install_api.cpp
@@ -3,22 +3,21 @@
#include "stdafx.h"
+#include "install_api.h"
+
#include <filesystem>
#include <string>
-#include "common/wtools.h" // converts
-#include "tools/_process.h" // start process
-
#include "cfg.h"
+#include "common/wtools.h" // converts
#include "logger.h"
-
-#include "install_api.h"
+#include "tools/_process.h" // start process
namespace cma {
namespace install {
-std::filesystem::path MakeTempFileNameInTempPath(const std::wstring& Name) {
+std::filesystem::path MakeTempFileNameInTempPath(std::wstring_view Name) {
namespace fs = std::filesystem;
// Find Temporary Folder
fs::path temp_folder = cma::tools::win::GetTempFolder();
@@ -136,10 +135,9 @@ bool NeedInstall(const std::filesystem::path& IncomingFile,
// check that update exists and exec it
// returns true when update found and ready to exec
-bool CheckForUpdateFile(const std::wstring& Name,
- const std::wstring& DirWithMsi, UpdateType Update,
- bool StartUpdateProcess,
- const std::wstring& BackupPath) {
+bool CheckForUpdateFile(std::wstring_view Name, std::wstring_view DirWithMsi,
+ UpdateType Update, UpdateProcess StartUpdateProcess,
+ std::wstring_view BackupPath) {
namespace fs = std::filesystem;
// find path to msiexec, in Windows it is in System32 folder
@@ -153,11 +151,11 @@ bool CheckForUpdateFile(const std::wstring& Name,
if (!fs::exists(msi_base, ec)) return false; // this is ok
switch (Update) {
- case kMsiExec:
- case kMsiExecQuiet:
+ case UpdateType::exec_normal:
+ case UpdateType::exec_quiet:
break;
- default:
- XLOG::l("Invalid Option {}", Update);
+ default: // safety, MSVC give us no warning
+ XLOG::l("Invalid Option '{}'",
static_cast<int>(Update));
return false;
}
@@ -176,20 +174,22 @@ bool CheckForUpdateFile(const std::wstring& Name,
BackupFile(msi_to_install, BackupPath);
// Prepare Command
- std::wstring command = exe + L" ";
- // original line includes also command REINSTALL=ALL
- // this doesn't work well when you have more than one FEATURE(new agent)
- // and no defined REINSTALL in the MSI
- command =
- command + L" /i " + msi_to_install.wstring() + L"
REINSTALLMODE=amus ";
- if (Update == kMsiExecQuiet) // this is only normal method
- command += L" /quiet"; // but MS doesn't care at all :)
+ std::wstring command = exe;
+
+ // msiexecs' parameters below are not fixed unfortunately
+ // documentation is scarce and method of installation in MK
+ // is not a special standard
+ command += L" /i " + msi_to_install.wstring() +
+ L" REINSTALL=ALL REINSTALLMODE=amus ";
+
+ if (Update == UpdateType::exec_quiet) // this is only normal method
+ command += L" /quiet"; // but MS doesn't care at all
:)
XLOG::l.i("File '{}' exists\n Command is '{}'",
msi_to_install.u8string(),
wtools::ConvertToUTF8(command.c_str()));
- if (!StartUpdateProcess) {
+ if (StartUpdateProcess == UpdateProcess::skip) {
XLOG::l.i("Actual Updating is disabled");
return true;
}
diff --git a/agents/wnx/src/engine/install_api.h b/agents/wnx/src/engine/install_api.h
index e25b52f..7e3146d 100644
--- a/agents/wnx/src/engine/install_api.h
+++ b/agents/wnx/src/engine/install_api.h
@@ -7,23 +7,24 @@
#include <filesystem>
#include <string>
+#include <string_view>
namespace cma {
namespace install {
-enum UpdateType { kMsiExec, kMsiExecQuiet };
-constexpr const wchar_t* const kDefaultMsiFileName = L"check_mk_agent.msi";
+enum class UpdateType { exec_normal, exec_quiet };
+enum class UpdateProcess { execute, skip };
+constexpr const std::wstring_view kDefaultMsiFileName = L"check_mk_agent.msi";
// TEST(InstallAuto, TopLevel)
-// StartUpdateProcess == false when we only testing functionality
+// set StartUpdateProcess to 'skip' to test functionality
// BackupPath may be empty, normally points out on the install folder
// DirWithMsi is update dir in ProgramData
-bool CheckForUpdateFile(const std::wstring& Name,
- const std::wstring& DirWithMsi, UpdateType Update,
- bool StartUpdateProcess,
- const std::wstring& BackupPath = L"");
+bool CheckForUpdateFile(std::wstring_view Name, std::wstring_view DirWithMsi,
+ UpdateType Update, UpdateProcess StartUpdateProcess,
+ std::wstring_view BackupPath = L"");
-std::filesystem::path MakeTempFileNameInTempPath(const std::wstring& Name);
+std::filesystem::path MakeTempFileNameInTempPath(std::wstring_view Name);
// internal API with diag published to simplify testing or for later use
// ****************************************
@@ -41,7 +42,7 @@ bool MvFile(const std::filesystem::path& Old,
void BackupFile(const std::filesystem::path& File,
const std::filesystem::path& Dir) noexcept;
-// noexcept check whther incoming file is newer
+// noexcept check whether incoming file is newer
bool NeedInstall(const std::filesystem::path& IncomingFile,
const std::filesystem::path& BackupDir) noexcept;
// ****************************************
diff --git a/agents/wnx/src/main/check_mk_service.cpp
b/agents/wnx/src/main/check_mk_service.cpp
index ba94357..fd61e4a 100644
--- a/agents/wnx/src/main/check_mk_service.cpp
+++ b/agents/wnx/src/main/check_mk_service.cpp
@@ -197,11 +197,11 @@ int MainFunction(int argc, wchar_t const *Argv[]) {
// this part of code have to be tested manually
// scripting is possible but complicated
CheckForUpdateFile(
- kDefaultMsiFileName, // file we are looking for
- GetUpdateDir(), // dir where file we're searching
- UpdateType::kMsiExecQuiet, // quiet for production
- true, // start update when file found
- GetMsiBackupDir()); // dir where file to backup
+ kDefaultMsiFileName, // file we are looking for
+ GetUpdateDir(), // dir where file we're searching
+ UpdateType::exec_quiet, // quiet for production
+ UpdateProcess::execute, // start update when file found
+ GetMsiBackupDir()); // dir where file to backup
return true;
});
}
diff --git a/agents/wnx/watest/test-install-auto.cpp
b/agents/wnx/watest/test-install-auto.cpp
index 0d06c39..f2e332c 100644
--- a/agents/wnx/watest/test-install-auto.cpp
+++ b/agents/wnx/watest/test-install-auto.cpp
@@ -7,10 +7,8 @@
#include <fstream>
#include "common/wtools.h"
-
#include "install_api.h"
#include "service_processor.h"
-
#include "test-tools.h"
TEST(InstallAuto, LowLevel) {
@@ -86,16 +84,20 @@ TEST(InstallAuto, TopLevel) {
auto to_install = MakeTempFileNameInTempPath(name);
EXPECT_TRUE(!to_install.empty());
{
- auto result = CheckForUpdateFile(name, in, (UpdateType)535, false);
+ auto result = CheckForUpdateFile(name, in.wstring(), (UpdateType)535,
+ UpdateProcess::skip);
EXPECT_FALSE(result);
- result = CheckForUpdateFile(name, L"", kMsiExecQuiet, false);
+ result = CheckForUpdateFile(name, L"", UpdateType::exec_quiet,
+ UpdateProcess::skip);
EXPECT_FALSE(result);
- result = CheckForUpdateFile(L"invalidname", L"",
kMsiExecQuiet, false);
+ result = CheckForUpdateFile(L"invalidname", L"",
UpdateType::exec_quiet,
+ UpdateProcess::skip);
EXPECT_FALSE(result);
- result = CheckForUpdateFile(name, in, kMsiExecQuiet, false, out);
+ result = CheckForUpdateFile(name, in.wstring(), UpdateType::exec_quiet,
+ UpdateProcess::skip, out.wstring());
EXPECT_TRUE(result);
EXPECT_TRUE(fs::exists(to_install, ec));