Jan_31_2024-Dev

This commit is contained in:
Ned Wright
2024-01-31 17:34:53 +00:00
parent 752a5785f0
commit 6d67818a94
376 changed files with 8101 additions and 7064 deletions

View File

@@ -13,6 +13,8 @@
#include "manifest_controller.h"
#include <algorithm>
#include "config.h"
#include "debug.h"
#include "environment.h"
@@ -80,9 +82,8 @@ private:
bool
handlePackage(
const Package &updated_package,
const pair<Package, string> &package_downloaded_file,
map<string, Package> &current_packages,
const map<string, Package> &new_packages,
map<string, Package> &corrupted_packages
);
@@ -179,6 +180,34 @@ ManifestController::Impl::updateIgnoreListForNSaaS()
return true;
}
static vector<pair<Package, string>>::const_iterator
findPackage(const vector<pair<Package, string>> &packages, const string &name)
{
using Pair = pair<Package, string>;
return find_if(packages.begin(), packages.end(), [&] (const Pair &pair) { return pair.first.getName() == name; });
}
static vector<pair<Package, string>>
sortByInstallationQueue(
const vector<pair<Package, string>> &downloaded_files,
const vector<Package> &installation_queue)
{
vector<pair<Package, string>> sorted_queue;
for (auto &package_file : installation_queue) {
if (package_file.getName() == "accessControlApp" || package_file.getName() == "accessControlKernel") continue;
auto package_it = findPackage(downloaded_files, package_file.getName());
if (package_it != downloaded_files.end()) sorted_queue.push_back(*package_it);
}
auto ac_app_it = findPackage(downloaded_files, "accessControlApp");
auto ac_kernel_it = findPackage(downloaded_files, "accessControlKernel");
if (ac_app_it != downloaded_files.end()) sorted_queue.push_back(*ac_app_it);
if (ac_kernel_it != downloaded_files.end()) sorted_queue.push_back(*ac_kernel_it);
return sorted_queue;
}
bool
ManifestController::Impl::updateManifest(const string &new_manifest_file)
{
@@ -220,6 +249,7 @@ ManifestController::Impl::updateManifest(const string &new_manifest_file)
}
map<string, Package> new_packages = parsed_manifest.unpack();
map<string, Package> all_packages = parsed_manifest.unpack();
map<string, Package> current_packages;
parsed_manifest = orchestration_tools->loadPackagesFromJson(manifest_file_path);
@@ -256,13 +286,14 @@ ManifestController::Impl::updateManifest(const string &new_manifest_file)
auto packages_to_remove = manifest_diff_calc.filterUntrackedPackages(current_packages, new_packages);
for (auto remove_package = packages_to_remove.begin(); remove_package != packages_to_remove.end();) {
bool uninstall_response = true;
if (remove_package->second.isInstallable().ok()) {
if (remove_package->second.isInstallable()) {
uninstall_response = manifest_handler.uninstallPackage(remove_package->second);
}
if (!uninstall_response) {
dbgWarning(D_ORCHESTRATOR)
<< "Failed to uninstall package. Package: " << remove_package->second.getName();
<< "Failed to uninstall package. Package: "
<< remove_package->second.getName();
all_cleaned = false;
remove_package++;
} else {
@@ -284,42 +315,40 @@ ManifestController::Impl::updateManifest(const string &new_manifest_file)
bool no_change = new_packages.size() == 0;
// Both new_packages & corrupted_packages will be updated based on updated manifest
bool no_corrupted_package = manifest_diff_calc.filterCorruptedPackages(new_packages, corrupted_packages);
auto orchestration_service = new_packages.find("orchestration");
if (orchestration_service != new_packages.end()) {
// Orchestration needs special handling as manifest should be backup differently
return handlePackage(
orchestration_service->second,
current_packages,
new_packages,
corrupted_packages
);
const auto &download_packages_res = manifest_handler.downloadPackages(new_packages);
if (!download_packages_res.ok()) {
dbgWarning(D_ORCHESTRATOR)
<< "Failed to download required packages. Error: "
<< download_packages_res.getErr();
return false;
}
auto wlp_standalone_service = new_packages.find("wlpStandalone");
if (wlp_standalone_service != new_packages.end()) {
// wlpStandalone needs special handling as manifest should be backup differently
return handlePackage(
wlp_standalone_service->second,
const vector<pair<Package, string>> &downloaded_files = download_packages_res.unpack();
const auto &installation_queue_res = manifest_diff_calc.buildInstallationQueue(
current_packages,
new_packages,
corrupted_packages
);
new_packages
);
if (!installation_queue_res.ok()) {
dbgWarning(D_ORCHESTRATOR)
<< "Failed building installation queue. Error: "
<< installation_queue_res.getErr();
return false;
}
const vector<Package> &installation_queue = installation_queue_res.unpack();
const auto &sortd_downloaded_files = sortByInstallationQueue(downloaded_files, installation_queue);
bool all_installed = true;
bool any_installed = false;
dbgDebug(D_ORCHESTRATOR) << "Starting to handle " << new_packages.size() <<" new packages";
for (auto &new_package : new_packages) {
if (new_package.second.getType() != Package::PackageType::Service) continue;
dbgDebug(D_ORCHESTRATOR) << "Starting to handle " << downloaded_files.size() << " new packages";
for (auto &package : sortd_downloaded_files) {
if (package.first.getType() != Package::PackageType::Service) continue;
size_t prev_size = corrupted_packages.size();
bool handling_response = handlePackage(
new_package.second,
package,
current_packages,
new_packages,
corrupted_packages
);
@@ -331,7 +360,10 @@ ManifestController::Impl::updateManifest(const string &new_manifest_file)
}
// Orchestration needs special handling as manifest should be backup differently
if (new_package.first.compare(orch_service_name) == 0) {
if (package.first.getName().compare(orch_service_name) == 0) {
return handling_response;
}
if (package.first.getName().compare("wlpStandalone") == 0) {
return handling_response;
}
@@ -341,14 +373,22 @@ ManifestController::Impl::updateManifest(const string &new_manifest_file)
bool manifest_file_update = true;
if (all_installed && (any_installed || no_change) && no_corrupted_package) {
if (all_installed && (any_installed || no_change)) {
manifest_file_update = changeManifestFile(new_manifest_file);
// In NSaaS - set ignore packages to any
ignore_packages_update = updateIgnoreListForNSaaS();
} else if (any_installed) {
manifest_file_update = orchestration_tools->packagesToJsonFile(current_packages, manifest_file_path);
}
return all_installed && manifest_file_update && no_corrupted_package && all_cleaned;
if (all_installed) {
auto orchestration_downloader = Singleton::Consume<I_Downloader>::by<ManifestHandler>();
for (auto &package : all_packages) {
dbgDebug(D_ORCHESTRATOR)
<< "Removing temp Download file after successfull installation : " << package.second.getName();
orchestration_downloader->removeDownloadFile(package.second.getName());
}
}
return all_installed && manifest_file_update && all_cleaned;
}
// Orchestration package needs a special handling. Old service will die during the upgrade
@@ -425,35 +465,26 @@ ManifestController::Impl::changeManifestFile(const string &new_manifest_file)
bool
ManifestController::Impl::handlePackage(
const Package &package,
const pair<Package, string> &package_downloaded_file,
map<string, Package> &current_packages,
const map<string, Package> &new_packages,
map<string, Package> &corrupted_packages)
{
auto &package = package_downloaded_file.first;
auto i_env = Singleton::Consume<I_Environment>::by<ManifestController>();
auto span_scope = i_env->startNewSpanScope(Span::ContextType::CHILD_OF);
dbgDebug(D_ORCHESTRATOR) << "Handling package. Package: " << package.getName();
if (!package.isInstallable().ok()) {
if (!package.isInstallable()) {
string report_msg =
"Skipping installation of package: " + package.getName() + ". Reason: " + package.isInstallable().getErr();
"Skipping installation of package: " + package.getName() + ". Reason: " + package.getErrorMessage();
dbgWarning(D_ORCHESTRATOR) << report_msg;
LogGen(report_msg, Audience::SECURITY, Severity::CRITICAL, Priority::HIGH, Tags::ORCHESTRATOR);
current_packages.insert(make_pair(package.getName(), package));
return true;
}
vector<Package> installation_queue;
if (!manifest_diff_calc.buildInstallationQueue(package, installation_queue, current_packages, new_packages)) {
dbgWarning(D_ORCHESTRATOR) << "Failed building installation queue. Package: " << package.getName();
return false;
}
vector<pair<Package, string>> downloaded_files;
if (!manifest_handler.downloadPackages(installation_queue, downloaded_files)) return false;
if (!manifest_handler.installPackages(downloaded_files, current_packages, corrupted_packages)) {
if (!manifest_handler.installPackage(package_downloaded_file, current_packages, corrupted_packages)) {
LogGen(
"Failed to install package: " + package.getName(),
Audience::SECURITY,

View File

@@ -91,6 +91,16 @@ public:
archive_in(ret);
}
void checkIfFileExistsCall(const Package &package)
{
Maybe<string> checksum_validation(
genError("File /tmp/orchestration_downloads/" + package.getName() + ".download does not exist.")
);
EXPECT_CALL(
mock_downloader,
checkIfFileExists(package)).WillRepeatedly(Return(checksum_validation));
}
string manifest_file_path;
string corrupted_file_list;
string temp_ext;
@@ -171,6 +181,10 @@ TEST_F(ManifestControllerTest, createNewManifest)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
//mock_downloader
EXPECT_CALL(
mock_downloader,
@@ -187,6 +201,8 @@ TEST_F(ManifestControllerTest, createNewManifest)
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
load(manifest, new_services);
@@ -237,6 +253,10 @@ TEST_F(ManifestControllerTest, badChecksum)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
//mock_downloader
Maybe<string> err(genError("Empty"));
EXPECT_CALL(
@@ -300,6 +320,11 @@ TEST_F(ManifestControllerTest, updateManifest)
" }"
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
//mock_downloader
EXPECT_CALL(
mock_downloader,
@@ -316,6 +341,8 @@ TEST_F(ManifestControllerTest, updateManifest)
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("my")).Times(2);
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration")).Times(2);
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
load(manifest, new_services);
@@ -366,6 +393,9 @@ TEST_F(ManifestControllerTest, updateManifest)
" ]"
"}";
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -412,6 +442,10 @@ TEST_F(ManifestControllerTest, selfUpdate)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -491,63 +525,6 @@ TEST_F(ManifestControllerTest, successLoadAfteSelfUpdate)
EXPECT_TRUE(i_manifest_controller->loadAfterSelfUpdate());
}
TEST_F(ManifestControllerTest, updateWhileErrorPackageExist)
{
new_services.clear();
old_services.clear();
string manifest =
"{"
" \"packages\": ["
" {"
" \"name\": \"my\","
" \"version\": \"c\","
" \"download-path\": \"http://172.23.92.135/my.sh\","
" \"relative-path\": \"\","
" \"checksum-type\": \"sha1sum\","
" \"checksum\": \"a58bbab8020b0e6d08568714b5e582a3adf9c805\","
" \"package-type\": \"service\","
" \"require\": []"
" },"
" {"
" \"name\": \"orchestration\","
" \"version\": \"c\","
" \"download-path\": \"http://172.23.92.135/my.sh\","
" \"relative-path\": \"\","
" \"checksum-type\": \"sha1sum\","
" \"checksum\": \"a58bbab8020b0e6d08568714b5e582a3adf9c805\","
" \"package-type\": \"service\","
" \"require\": []"
" }"
" ]"
"}";
string corrupted_packages_manifest =
"{"
" \"packages\": ["
" {"
" \"name\": \"my\","
" \"version\": \"c\","
" \"download-path\": \"http://172.23.92.135/my.sh\","
" \"relative-path\": \"\","
" \"checksum-type\": \"sha1sum\","
" \"checksum\": \"a58bbab8020b0e6d08568714b5e582a3adf9c805\","
" \"package-type\": \"service\","
" \"require\": []"
" }"
" ]"
"}";
load(manifest, new_services);
load(old_manifest, old_services);
load(corrupted_packages_manifest, corrupted_packages);
EXPECT_CALL(mock_orchestration_tools,
loadPackagesFromJson(corrupted_file_list)).WillOnce(Return(corrupted_packages));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(file_name)).WillOnce(Return(new_services));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(manifest_file_path)).WillOnce(Return(old_services));
EXPECT_FALSE(i_manifest_controller->updateManifest(file_name));
}
TEST_F(ManifestControllerTest, removeCurrentErrorPackage)
{
new_services.clear();
@@ -598,6 +575,8 @@ TEST_F(ManifestControllerTest, removeCurrentErrorPackage)
load(old_manifest, old_services);
load(corrupted_packages_manifest, corrupted_packages);
checkIfFileExistsCall(new_services.at("my"));
//mock_downloader
EXPECT_CALL(
mock_downloader,
@@ -613,6 +592,8 @@ TEST_F(ManifestControllerTest, removeCurrentErrorPackage)
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(file_name)).WillOnce(Return(new_services));
@@ -629,8 +610,6 @@ TEST_F(ManifestControllerTest, removeCurrentErrorPackage)
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
corrupted_packages.clear();
EXPECT_CALL(mock_orchestration_tools, packagesToJsonFile(corrupted_packages,
corrupted_file_list)).WillOnce(Return(true));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
}
@@ -656,6 +635,10 @@ TEST_F(ManifestControllerTest, selfUpdateWithOldCopy)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -710,6 +693,10 @@ TEST_F(ManifestControllerTest, selfUpdateWithOldCopyWithError)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -775,6 +762,10 @@ TEST_F(ManifestControllerTest, installAndRemove)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
//mock_downloader
EXPECT_CALL(
mock_downloader,
@@ -791,6 +782,8 @@ TEST_F(ManifestControllerTest, installAndRemove)
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
load(manifest, new_services);
@@ -839,6 +832,9 @@ TEST_F(ManifestControllerTest, installAndRemove)
" ]"
"}";
load(new_manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my1"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -854,6 +850,8 @@ TEST_F(ManifestControllerTest, installAndRemove)
EXPECT_CALL(mock_package_handler, preInstallPackage("my1", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my1", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my1", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("my1"));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my1", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, packagesToJsonFile(old_services, manifest_file_path)).WillOnce(Return(true));
@@ -900,6 +898,10 @@ TEST_F(ManifestControllerTest, badInstall)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
//mock_downloader
EXPECT_CALL(
mock_downloader,
@@ -979,6 +981,10 @@ TEST_F(ManifestControllerTest, failToDownloadWithselfUpdate)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration"));
Maybe<string> err(genError("Empty"));
EXPECT_CALL(
mock_downloader,
@@ -1019,7 +1025,7 @@ TEST_F(ManifestControllerTest, requireUpdate)
"{"
" \"packages\": ["
" {"
" \"name\": \"orchestration\","
" \"name\": \"orchestration1\","
" \"version\": \"c\","
" \"download-path\": \"http://172.23.92.135/my.sh\","
" \"relative-path\": \"\","
@@ -1040,16 +1046,22 @@ TEST_F(ManifestControllerTest, requireUpdate)
" }"
" ]"
"}";
EXPECT_CALL(mock_status, writeStatusToFile());
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration1"));
checkIfFileExistsCall(manifest_services.at("pre_orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
"http://172.23.92.135/my.sh",
"a58bbab8020b0e6d08568714b5e582a3adf9c805",
Package::ChecksumTypes::SHA1,
"orchestration"
"orchestration1"
)
).WillOnce(Return(string("/tmp/temp_file1")));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -1059,10 +1071,16 @@ TEST_F(ManifestControllerTest, requireUpdate)
"pre_orchestration"
)
).WillOnce(Return(string("/tmp/temp_file2")));
string temp_orc_file = "/etc/cp/packages/orchestration/orchestration_temp";
EXPECT_CALL(mock_package_handler, preInstallPackage(orch_service_name, temp_orc_file))
EXPECT_CALL(mock_package_handler, preInstallPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage(orch_service_name, temp_orc_file, _))
EXPECT_CALL(mock_package_handler, installPackage("orchestration1", "/tmp/temp_file1", _))
.WillOnce(Return(true));
EXPECT_CALL(
mock_package_handler,
shouldInstallPackage("orchestration1", "/tmp/temp_file1")
).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(
@@ -1075,8 +1093,12 @@ TEST_F(ManifestControllerTest, requireUpdate)
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("pre_orchestration", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("pre_orchestration"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("pre_orchestration", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration1"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(corrupted_file_list))
@@ -1088,20 +1110,24 @@ TEST_F(ManifestControllerTest, requireUpdate)
.WillOnce(Return(new_services));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(manifest_file_path))
.WillOnce(Return(old_services));
string temp_manifest_path = manifest_file_path + temp_ext;
EXPECT_CALL(mock_orchestration_tools, packagesToJsonFile(new_services, temp_manifest_path))
EXPECT_CALL(mock_orchestration_tools, doesFileExist(manifest_file_path))
.WillOnce(Return(true));
string path = packages_dir + "/" + orch_service_name + "/" +
orch_service_name;
string temp_manifest_path = manifest_file_path + temp_ext;
string path = packages_dir + "/orchestration1/" + "orchestration1";
EXPECT_CALL(mock_orchestration_tools, doesFileExist(path)).Times(2).WillOnce(Return(false));
EXPECT_CALL(
mock_orchestration_tools,
doesFileExist("/etc/cp/packages/pre_orchestration/pre_orchestration")
).Times(2).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, copyFile("/tmp/temp_file1", path + temp_ext))
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, copyFile(manifest_file_path, "/etc/cp/conf/manifest.json.bk"))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile("new_manifest.json")).WillOnce(Return(true));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
}
@@ -1141,6 +1167,11 @@ TEST_F(ManifestControllerTest, sharedObjectNotInstalled)
EXPECT_CALL(mock_orchestration_tools,
loadPackagesFromJson(corrupted_file_list)).WillOnce(Return(corrupted_packages));
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration"));
checkIfFileExistsCall(manifest_services.at("pre_orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -1151,6 +1182,16 @@ TEST_F(ManifestControllerTest, sharedObjectNotInstalled)
)
).WillOnce(Return(string("/tmp/temp_file1")));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
"http://172.23.92.135/my.sh",
"a58bbab8020b0e6d08568714b5e582a3adf9c806",
Package::ChecksumTypes::SHA1,
"pre_orchestration"
)
).WillOnce(Return(string("/tmp/temp_file2")));
string temp_manifest_path = manifest_file_path + temp_ext;
string writen_manifest =
"{"
@@ -1181,7 +1222,10 @@ TEST_F(ManifestControllerTest, sharedObjectNotInstalled)
string path = packages_dir + "/" + orch_service_name + "/" +
orch_service_name;
EXPECT_CALL(mock_orchestration_tools, doesFileExist(path)).Times(2).WillOnce(Return(false));
EXPECT_CALL(
mock_orchestration_tools,
doesFileExist("/etc/cp/packages/pre_orchestration/pre_orchestration")
).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, copyFile("/tmp/temp_file1", path +
temp_ext)).WillOnce(Return(true));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
@@ -1195,7 +1239,7 @@ TEST_F(ManifestControllerTest, requireSharedObjectUpdate)
"{"
" \"packages\": ["
" {"
" \"name\": \"orchestration\","
" \"name\": \"orchestration1\","
" \"version\": \"c\","
" \"download-path\": \"http://172.23.92.135/my.sh\","
" \"relative-path\": \"\","
@@ -1211,21 +1255,27 @@ TEST_F(ManifestControllerTest, requireSharedObjectUpdate)
" \"relative-path\": \"\","
" \"checksum-type\": \"sha1sum\","
" \"checksum\": \"a58bbab8020b0e6d08568714b5e582a3adf9c806\","
" \"package-type\": \"shared objects\","
" \"package-type\": \"service\","
" \"require\": []"
" }"
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration1"));
checkIfFileExistsCall(manifest_services.at("pre_orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
"http://172.23.92.135/my.sh",
"a58bbab8020b0e6d08568714b5e582a3adf9c805",
Package::ChecksumTypes::SHA1,
"orchestration"
"orchestration1"
)
).WillOnce(Return(string("/tmp/temp_file1")));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -1235,15 +1285,26 @@ TEST_F(ManifestControllerTest, requireSharedObjectUpdate)
"pre_orchestration"
)
).WillOnce(Return(string("/tmp/temp_file2")));
EXPECT_CALL(mock_status, writeStatusToFile());
string temp_orc_file = "/etc/cp/packages/orchestration/orchestration_temp";
string temp_orc_file = "/etc/cp/packages/orchestration1/orchestration_temp";
EXPECT_CALL(mock_package_handler, shouldInstallPackage(_, _)).WillRepeatedly(Return(true));
EXPECT_CALL(mock_package_handler, preInstallPackage(orch_service_name,
temp_orc_file)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage(orch_service_name,
temp_orc_file, _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("orchestration1", "/tmp/temp_file1", _))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("pre_orchestration",
"/tmp/temp_file2", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, preInstallPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration1"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, preInstallPackage("pre_orchestration", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("pre_orchestration", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("pre_orchestration"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("pre_orchestration", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools,
loadPackagesFromJson(corrupted_file_list)).WillOnce(Return(corrupted_packages));
@@ -1252,18 +1313,22 @@ TEST_F(ManifestControllerTest, requireSharedObjectUpdate)
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(file_name)).WillOnce(Return(new_services));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(manifest_file_path)).WillOnce(Return(old_services));
string temp_manifest_path = manifest_file_path + temp_ext;
EXPECT_CALL(mock_orchestration_tools, packagesToJsonFile(new_services, temp_manifest_path)).WillOnce(Return(true));
string path = packages_dir + "/" + orch_service_name + "/" +
orch_service_name;
string path = packages_dir + "/" + "orchestration1" + "/" + "orchestration1";
EXPECT_CALL(mock_orchestration_tools, doesFileExist(path)).Times(2).WillOnce(Return(false));
EXPECT_CALL(mock_orchestration_tools, doesFileExist("/etc/cp/conf/manifest.json"))
.WillOnce(Return(false));
EXPECT_CALL(
mock_orchestration_tools,
doesFileExist("/etc/cp/packages/pre_orchestration/pre_orchestration")
).Times(2).WillOnce(Return(false));
EXPECT_CALL(mock_orchestration_tools, copyFile("/tmp/temp_file1", path +
temp_ext)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, copyFile("new_manifest.json", "/etc/cp/conf/manifest.json"))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile("/etc/cp/conf/manifest.json"))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile("new_manifest.json"))
.WillOnce(Return(true));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
}
@@ -1297,6 +1362,21 @@ TEST_F(ManifestControllerTest, failureOnDownloadSharedObject)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration"));
checkIfFileExistsCall(manifest_services.at("pre_orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
"http://172.23.92.135/my.sh",
"a58bbab8020b0e6d08568714b5e582a3adf9c805",
Package::ChecksumTypes::SHA1,
"orchestration"
)
).WillOnce(Return(string("/tmp/temp_file1")));
Maybe<string> err = genError("error");
EXPECT_CALL(
mock_downloader,
@@ -1314,11 +1394,16 @@ TEST_F(ManifestControllerTest, failureOnDownloadSharedObject)
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(file_name)).WillOnce(Return(new_services));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(manifest_file_path)).WillOnce(Return(old_services));
EXPECT_CALL(
mock_orchestration_tools,
doesFileExist("/etc/cp/packages/orchestration/orchestration")
).WillOnce(Return(false));
EXPECT_CALL(
mock_orchestration_tools,
doesFileExist("/etc/cp/packages/pre_orchestration/pre_orchestration")
).WillOnce(Return(false));
EXPECT_CALL(mock_details_resolver, getHostname()).WillOnce(Return(string("hostname")));
EXPECT_CALL(mock_orchestration_tools, removeFile("/tmp/temp_file1")).WillOnce(Return(true));
EXPECT_CALL(
mock_status,
setFieldStatus(OrchestrationStatusFieldType::MANIFEST, OrchestrationStatusResult::FAILED, _)
@@ -1337,7 +1422,7 @@ TEST_F(ManifestControllerTest, multiRequireUpdate)
"{"
" \"packages\": ["
" {"
" \"name\": \"orchestration\","
" \"name\": \"orchestration1\","
" \"version\": \"c\","
" \"download-path\": \"http://172.23.92.135/my.sh\","
" \"relative-path\": \"\","
@@ -1353,7 +1438,7 @@ TEST_F(ManifestControllerTest, multiRequireUpdate)
" \"relative-path\": \"\","
" \"checksum-type\": \"sha1sum\","
" \"checksum\": \"a58bbab8020b0e6d08568714b5e582a3adf9c806\","
" \"package-type\": \"shared objects\","
" \"package-type\": \"service\","
" \"require\": []"
" },"
" {"
@@ -1363,19 +1448,25 @@ TEST_F(ManifestControllerTest, multiRequireUpdate)
" \"relative-path\": \"\","
" \"checksum-type\": \"sha1sum\","
" \"checksum\": \"a58bbab8020b0e6d08568714b5e582a3adf9c807\","
" \"package-type\": \"shared objects\","
" \"package-type\": \"service\","
" \"require\": [ \"pre_orchestration001\" ]"
" }"
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("orchestration1"));
checkIfFileExistsCall(manifest_services.at("pre_orchestration001"));
checkIfFileExistsCall(manifest_services.at("pre_orchestration002"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
"http://172.23.92.135/my.sh",
"a58bbab8020b0e6d08568714b5e582a3adf9c805",
Package::ChecksumTypes::SHA1,
"orchestration"
"orchestration1"
)
).WillOnce(Return(string("/tmp/temp_file1")));
EXPECT_CALL(
@@ -1396,13 +1487,9 @@ TEST_F(ManifestControllerTest, multiRequireUpdate)
"pre_orchestration002"
)
).WillOnce(Return(string("/tmp/temp_file3")));
EXPECT_CALL(mock_status, writeStatusToFile());
string temp_orc_file = "/etc/cp/packages/orchestration/orchestration_temp";
EXPECT_CALL(mock_package_handler, shouldInstallPackage(_, _)).WillRepeatedly(Return(true));
EXPECT_CALL(mock_package_handler, preInstallPackage(orch_service_name,
temp_orc_file)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage(orch_service_name,
temp_orc_file, _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("orchestration1",
"/tmp/temp_file1", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("pre_orchestration001",
"/tmp/temp_file2", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("pre_orchestration002",
@@ -1410,15 +1497,37 @@ TEST_F(ManifestControllerTest, multiRequireUpdate)
EXPECT_CALL(mock_orchestration_tools,
loadPackagesFromJson(corrupted_file_list)).WillOnce(Return(corrupted_packages));
EXPECT_CALL(mock_package_handler, preInstallPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, preInstallPackage("pre_orchestration001", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, preInstallPackage("pre_orchestration002", "/tmp/temp_file3"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("pre_orchestration001", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("pre_orchestration002", "/tmp/temp_file3"))
.WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration1"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("orchestration1", "/tmp/temp_file1"))
.WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("pre_orchestration001"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("pre_orchestration001", "/tmp/temp_file2"))
.WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("pre_orchestration002"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("pre_orchestration002", "/tmp/temp_file3"))
.WillOnce(Return(true));
load(manifest, new_services);
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(file_name)).WillOnce(Return(new_services));
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson(manifest_file_path)).WillOnce(Return(old_services));
string temp_manifest_path = manifest_file_path + temp_ext;
EXPECT_CALL(mock_orchestration_tools, packagesToJsonFile(new_services, temp_manifest_path)).WillOnce(Return(true));
string path = packages_dir + "/" + orch_service_name + "/" +
orch_service_name;
string path = packages_dir + "/" + "orchestration1" + "/" + "orchestration1";
EXPECT_CALL(mock_orchestration_tools, doesFileExist(path)).Times(2).WillOnce(Return(false));
EXPECT_CALL(
mock_orchestration_tools,
@@ -1429,8 +1538,14 @@ TEST_F(ManifestControllerTest, multiRequireUpdate)
doesFileExist("/etc/cp/packages/pre_orchestration002/pre_orchestration002")
).Times(2).WillOnce(Return(false));
EXPECT_CALL(mock_orchestration_tools, copyFile("/tmp/temp_file1", path +
temp_ext)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, doesFileExist("/etc/cp/conf/manifest.json"))
.WillOnce(Return(false));
EXPECT_CALL(mock_orchestration_tools, copyFile("new_manifest.json", "/etc/cp/conf/manifest.json"))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile("/etc/cp/conf/manifest.json"))
.WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile("new_manifest.json"))
.WillOnce(Return(true));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
}
@@ -1476,6 +1591,10 @@ TEST_F(ManifestControllerTest, createNewManifestWithUninstallablePackage)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
//mock_downloader
EXPECT_CALL(
mock_downloader,
@@ -1492,6 +1611,9 @@ TEST_F(ManifestControllerTest, createNewManifestWithUninstallablePackage)
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("waap"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
load(manifest, new_services);
@@ -1552,15 +1674,17 @@ TEST_F(ManifestControllerTest, updateUninstallPackage)
EXPECT_CALL(mock_orchestration_tools,
loadPackagesFromJson(corrupted_file_list)).Times(2).WillRepeatedly(Return(corrupted_packages));
EXPECT_CALL(mock_orchestration_tools, doesFileExist(manifest_file_path)).Times(2).WillRepeatedly(Return(true));
EXPECT_CALL(mock_orchestration_tools, doesFileExist(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools,
copyFile(manifest_file_path, "/etc/cp/conf/manifest.json.bk")).Times(2).WillRepeatedly(Return(true));
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path))
copyFile(manifest_file_path, "/etc/cp/conf/manifest.json.bk")).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, doesFileExist("/etc/cp/packages/my/my"))
.Times(2).WillRepeatedly(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).Times(2).WillRepeatedly(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).Times(2).WillRepeatedly(Return(true));
EXPECT_CALL(mock_orchestration_tools, doesFileExist("/etc/cp/packages/my/my")).Times(2).WillOnce(Return(true));
string hostname = "hostname";
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
@@ -1590,6 +1714,10 @@ TEST_F(ManifestControllerTest, updateUninstallPackage)
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -1605,6 +1733,8 @@ TEST_F(ManifestControllerTest, updateUninstallPackage)
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
//mock_orchestration_tools
@@ -1673,6 +1803,16 @@ public:
archive_in(ret);
}
void checkIfFileExistsCall(const Package &package)
{
Maybe<string> checksum_validation(
genError("File /tmp/orchestration_downloads/" + package.getName() + ".download does not exist.")
);
EXPECT_CALL(
mock_downloader,
checkIfFileExists(package)).WillRepeatedly(Return(checksum_validation));
}
string manifest_file_path;
string corrupted_file_list;
string temp_ext;
@@ -1801,6 +1941,9 @@ TEST_F(ManifestControllerIgnorePakckgeTest, addAndUpdateIgnorePackage)
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("dummy_service"));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
@@ -1855,11 +1998,13 @@ TEST_F(ManifestControllerIgnorePakckgeTest, addAndUpdateIgnorePackage)
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("dummy_service"));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
}
TEST_F(ManifestControllerIgnorePakckgeTest, addIgnorePackageAndUpdateNormal)
{
init();
@@ -1916,6 +2061,9 @@ TEST_F(ManifestControllerIgnorePakckgeTest, addIgnorePackageAndUpdateNormal)
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("dummy_service"));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
@@ -1958,6 +2106,7 @@ TEST_F(ManifestControllerIgnorePakckgeTest, addIgnorePackageAndUpdateNormal)
//mock_orchestration_tools
load(manifest, new_services);
checkIfFileExistsCall(new_services.at("my"));
//mock_downloader
EXPECT_CALL(
@@ -1975,6 +2124,9 @@ TEST_F(ManifestControllerIgnorePakckgeTest, addIgnorePackageAndUpdateNormal)
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("dummy_service"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
load(manifest, new_services);
@@ -2050,6 +2202,9 @@ TEST_F(ManifestControllerIgnorePakckgeTest, removeIgnoredPackage)
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("dummy_service"));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
@@ -2094,6 +2249,8 @@ TEST_F(ManifestControllerIgnorePakckgeTest, removeIgnoredPackage)
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
}
@@ -2147,6 +2304,8 @@ TEST_F(ManifestControllerIgnorePakckgeTest, freezeIgnoredPackage)
EXPECT_CALL(mock_orchestration_tools, copyFile(file_name, manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, isNonEmptyFile(manifest_file_path)).WillOnce(Return(true));
EXPECT_CALL(mock_orchestration_tools, removeFile(file_name)).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_TRUE(i_manifest_controller->updateManifest(file_name));
@@ -2210,6 +2369,10 @@ TEST_F(ManifestControllerIgnorePakckgeTest, overrideIgnoredPackageFromProfileSet
" ]"
"}";
map<string, Package> manifest_services;
load(manifest, manifest_services);
checkIfFileExistsCall(manifest_services.at("my"));
//mock_downloader
EXPECT_CALL(
mock_downloader,
@@ -2226,6 +2389,8 @@ TEST_F(ManifestControllerIgnorePakckgeTest, overrideIgnoredPackageFromProfileSet
EXPECT_CALL(mock_package_handler, preInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, installPackage("my", "/tmp/temp_file", _)).WillOnce(Return(true));
EXPECT_CALL(mock_package_handler, postInstallPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
EXPECT_CALL(mock_downloader, removeDownloadFile("my"));
EXPECT_CALL(mock_downloader, removeDownloadFile("orchestration"));
EXPECT_CALL(mock_package_handler, updateSavedPackage("my", "/tmp/temp_file")).WillOnce(Return(true));
load(manifest, new_services);
@@ -2270,6 +2435,17 @@ public:
manifest_controller.init();
}
void checkIfFileExistsCall(const Package &package)
{
Maybe<string> checksum_validation(
genError("File /tmp/orchestration_downloads/" + package.getName() + ".download does not exist.")
);
EXPECT_CALL(
mock_downloader,
checkIfFileExists(package)).WillRepeatedly(Return(checksum_validation));
}
::Environment env;
ConfigComponent config;
@@ -2335,6 +2511,9 @@ TEST_F(ManifestDownloadTest, download_relative_path)
EXPECT_CALL(mock_orchestration_tools, loadPackagesFromJson("/etc/cp/conf/corrupted_packages.json"))
.WillOnce(Return(corrupted_packages));
EXPECT_CALL(agent_details, getFogDomain()).WillOnce(Return(fog_domain));
checkIfFileExistsCall(new_packages.at("orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(
@@ -2413,6 +2592,8 @@ TEST_F(ManifestDownloadTest, download_relative_path_no_fog_domain)
string not_error;
EXPECT_CALL(mock_status, getManifestError()).WillOnce(ReturnRef(not_error));
checkIfFileExistsCall(new_packages.at("orchestration"));
EXPECT_CALL(
mock_downloader,
downloadFileFromURL(

View File

@@ -13,6 +13,8 @@
#include "manifest_diff_calculator.h"
#include <algorithm>
#include "debug.h"
#include "config.h"
@@ -59,6 +61,8 @@ ManifestDiffCalculator::filterUntrackedPackages(
return packages_to_remove;
}
// LCOV_EXCL_START Reason: temp disabling corrupted packages mechanism
// If one of the new packages is already known as corrupted, new_packages map is
// updated accordingly.
// Otherwise, corrupted_packages is updated and old corrupted package is deleted.
@@ -102,38 +106,71 @@ ManifestDiffCalculator::filterCorruptedPackages(
}
return no_corrupted_package_exist;
}
// LCOV_EXCL_STOP
// This function build the installation queue recursively and return true if succeeded, false otherwise
// At the beginning, installation_queue is empty and will be filled according package dependences
bool
ManifestDiffCalculator::buildInstallationQueue(
const Package &updated_package,
Maybe<void>
ManifestDiffCalculator::buildRecInstallationQueue(
const Package &package,
vector<Package> &installation_queue,
const map<string, Package> &current_packages,
const map<string, Package> &new_packages)
{
vector<string> requires = updated_package.getRequire();
const vector<string> &requires = package.getRequire();
for (size_t i = 0; i < requires.size(); i++) {
auto installed_package = current_packages.find(requires[i]);
auto new_package = new_packages.find(requires[i]);
for (const auto &require : requires) {
auto installed_package = current_packages.find(require);
auto new_package = new_packages.find(require);
if (installed_package == current_packages.end() ||
(new_package != new_packages.end() && *installed_package != *new_package)) {
if(!buildInstallationQueue(new_package->second,
installation_queue,
current_packages,
new_packages)) {
return false;
}
auto rec_res = buildRecInstallationQueue(
new_package->second,
installation_queue,
current_packages,
new_packages
);
if (!rec_res.ok()) return rec_res.passErr();
} else if (installed_package != current_packages.end()) {
dbgDebug(D_ORCHESTRATOR) << "Package is already installed. Package: " << installed_package->first;
dbgDebug(D_ORCHESTRATOR) << "Package is already in the queue. Package: " << installed_package->first;
} else if (new_package == new_packages.end()) {
dbgWarning(D_ORCHESTRATOR) << "One of the requested dependencies is corrupted or doesn't exist."
<< " Package: "<< requires[i];
return false;
return genError(
"One of the requested dependencies is corrupted or doesn't exist. Package: " + require
);
}
}
installation_queue.push_back(updated_package);
return true;
if (find(installation_queue.begin(), installation_queue.end(), package) == installation_queue.end()) {
installation_queue.push_back(package);
}
return Maybe<void>();
}
// This function build the installation queue recursively and return true if succeeded, false otherwise
// At the beginning, installation_queue is empty and will be filled according package dependences
Maybe<vector<Package>>
ManifestDiffCalculator::buildInstallationQueue(
const map<string, Package> &current_packages,
const map<string, Package> &new_packages)
{
vector<Package> installation_queue;
installation_queue.reserve(new_packages.size());
auto orchestration_it = new_packages.find("orchestration");
if (orchestration_it != new_packages.end()) {
installation_queue.push_back(orchestration_it->second);
}
auto wlp_standalone_it = new_packages.find("wlpStandalone");
if (wlp_standalone_it != new_packages.end()){
installation_queue.push_back(wlp_standalone_it->second);
}
for (auto &package_pair : new_packages) {
auto build_queue_res = buildRecInstallationQueue(
package_pair.second,
installation_queue,
current_packages,
new_packages
);
if (!build_queue_res.ok()) return build_queue_res.passErr();
}
return installation_queue;
}

View File

@@ -13,6 +13,8 @@
#include "manifest_handler.h"
#include <algorithm>
#include "debug.h"
#include "config.h"
#include "agent_details.h"
@@ -57,6 +59,10 @@ ManifestHandler::downloadPackage(const Package &package, bool is_clean_installat
fog_domain = Singleton::Consume<I_AgentDetails>::by<ManifestHandler>()->getFogDomain();
}
auto orchestration_downloader = Singleton::Consume<I_Downloader>::by<ManifestHandler>();
auto maybe_package_exists = orchestration_downloader->checkIfFileExists(package);
if (maybe_package_exists.ok()) return maybe_package_exists;
if (!is_clean_installation) {
I_MainLoop *i_mainloop = Singleton::Consume<I_MainLoop>::by<ManifestHandler>();
auto pending_time_frame_seconds = getConfigurationWithDefault<int>(
@@ -76,11 +82,10 @@ ManifestHandler::downloadPackage(const Package &package, bool is_clean_installat
dbgTrace(D_ORCHESTRATOR) << "Proceeding to package downloading. Package name " << package.getName();
}
auto orchestration_downloader = Singleton::Consume<I_Downloader>::by<ManifestHandler>();
if (!package.getRelativeDownloadPath().empty() && fog_domain.ok()) {
string download_path =
"<JWT>https://" + fog_domain.unpack() + "/download" + package.getRelativeDownloadPath();
package_download_file= orchestration_downloader->downloadFileFromURL(
package_download_file = orchestration_downloader->downloadFileFromURL(
download_path,
package.getChecksum(),
package.getChecksumType(),
@@ -99,15 +104,22 @@ ManifestHandler::downloadPackage(const Package &package, bool is_clean_installat
return package_download_file;
}
bool
ManifestHandler::downloadPackages(
const vector<Package> &packages_to_download,
vector<pair<Package, packageFilePath>> &downloaded_packages)
Maybe<vector<pair<Package, packageFilePath>>>
ManifestHandler::downloadPackages(const map<string, Package> &new_packages_to_download)
{
auto i_env = Singleton::Consume<I_Environment>::by<ManifestHandler>();
auto i_orch_tools = Singleton::Consume<I_OrchestrationTools>::by<ManifestHandler>();
auto span_scope = i_env->startNewSpanScope(Span::ContextType::CHILD_OF);
for (auto &package : packages_to_download) {
vector<pair<Package, packageFilePath>> downloaded_packages;
for (auto &package_pair : new_packages_to_download) {
const Package &package = package_pair.second;
if (!package.isInstallable()) {
dbgTrace(D_ORCHESTRATOR)
<< "Skipping package download, package isn't installable. Package: "
<< package.getName() << ". Reason: " << package.getErrorMessage();
continue;
}
dbgInfo(D_ORCHESTRATOR) << "Downloading package file." << " Package: " << package.getName();
string packages_dir = getConfigurationWithDefault<string>(
@@ -170,133 +182,42 @@ ManifestHandler::downloadPackages(
install_error
);
}
return false;
return genError(
"Failed to download installation package. Package: " +
package.getName() +
", Error: " + package_download_file.getErr());
}
}
return true;
return downloaded_packages;
}
bool
ManifestHandler::installPackages(
const vector<pair<Package, packageFilePath>> &downloaded_package_files,
ManifestHandler::installPackage(
const pair<Package, string> &package_downloaded_file,
map<packageFilePath, Package> &current_packages,
map<packageFilePath, Package> &corrupted_packages)
{
auto i_env = Singleton::Consume<I_Environment>::by<ManifestHandler>();
auto span_scope = i_env->startNewSpanScope(Span::ContextType::CHILD_OF);
// Patch - reorder packages so that accessControlApp is installed before accessControlKernel
vector<pair<Package, packageFilePath>> patched_downloaded_package_files;
patched_downloaded_package_files.reserve(downloaded_package_files.size());
int ac_kernel_package_idx = -1;
int ac_app_package_idx = -1;
int i = 0;
for (auto &downloaded_package : downloaded_package_files) {
if (downloaded_package.first.getName() == "accessControlApp") {
ac_app_package_idx = i;
} else if (downloaded_package.first.getName() == "accessControlKernel") {
ac_kernel_package_idx = i;
} else {
patched_downloaded_package_files.push_back(downloaded_package);
}
i++;
}
if (ac_app_package_idx != -1) {
patched_downloaded_package_files.push_back(downloaded_package_files.at(ac_app_package_idx));
}
if (ac_kernel_package_idx != -1) {
patched_downloaded_package_files.push_back(downloaded_package_files.at(ac_kernel_package_idx));
}
auto orchestration_status = Singleton::Consume<I_OrchestrationStatus>::by<ManifestHandler>();
for (auto &downloaded_package : patched_downloaded_package_files) {
auto package = downloaded_package.first;
auto package_name = package.getName();
auto package_handler_path = downloaded_package.second;
dbgInfo(D_ORCHESTRATOR) << "Handling package installation. Package: " << package_name;
auto &package = package_downloaded_file.first;
auto &package_name = package.getName();
auto &package_handler_path = package_downloaded_file.second;
if (package_name.compare(orch_service_name) == 0) {
orchestration_status->writeStatusToFile();
bool self_update_status = selfUpdate(package, current_packages, package_handler_path);
if (!self_update_status) {
auto details = Singleton::Consume<I_AgentDetails>::by<ManifestHandler>();
auto hostname = Singleton::Consume<I_DetailsResolver>::by<ManifestHandler>()->getHostname();
string err_hostname = (hostname.ok() ? "on host '" + *hostname : "'" + details->getAgentId()) + "'";
string install_error =
"Warning: Agent/Gateway " +
err_hostname +
" software update failed. Agent is running previous software. Contact Check Point support.";
if (orchestration_status->getManifestError().find("Gateway was not fully deployed") == string::npos) {
orchestration_status->setFieldStatus(
OrchestrationStatusFieldType::MANIFEST,
OrchestrationStatusResult::FAILED,
install_error
);
}
}
dbgInfo(D_ORCHESTRATOR) << "Handling package installation. Package: " << package_name;
return self_update_status;
}
string packages_dir = getConfigurationWithDefault<string>(
"/etc/cp/packages",
"orchestration",
"Packages directory"
);
string current_installation_file = packages_dir + "/" + package_name + "/" + package_name;
auto orchestration_tools = Singleton::Consume<I_OrchestrationTools>::by<ManifestHandler>();
bool is_clean_installation = !orchestration_tools->doesFileExist(current_installation_file);
auto package_handler = Singleton::Consume<I_PackageHandler>::by<ManifestHandler>();
if (!package_handler->shouldInstallPackage(package_name, package_handler_path)) {
current_packages.insert(make_pair(package_name, package));
dbgInfo(D_ORCHESTRATOR)
<< "Skipping installation of new package with the same version as current. Package: "
<< package_name;
continue;
}
bool current_result = true;
bool is_service = package.getType() == Package::PackageType::Service;
if (is_service) {
current_result = package_handler->preInstallPackage(package_name, package_handler_path);
}
current_result = current_result && package_handler->installPackage(
package_name,
package_handler_path,
false
);
if (current_result && is_service) {
current_result = package_handler->postInstallPackage(package_name, package_handler_path);
}
if (current_result && is_service) {
current_result = package_handler->updateSavedPackage(package_name, package_handler_path);
}
if (!current_result) {
auto agent_details = Singleton::Consume<I_AgentDetails>::by<ManifestHandler>();
if (package_name.compare(orch_service_name) == 0) {
orchestration_status->writeStatusToFile();
bool self_update_status = selfUpdate(package, current_packages, package_handler_path);
if (!self_update_status) {
auto details = Singleton::Consume<I_AgentDetails>::by<ManifestHandler>();
auto hostname = Singleton::Consume<I_DetailsResolver>::by<ManifestHandler>()->getHostname();
string err_hostname = (hostname.ok() ? "on host '" + *hostname : "'" +agent_details->getAgentId()) + "'";
string install_error;
if (is_clean_installation) {
install_error =
"Critical Error: Agent/Gateway was not fully deployed " +
err_hostname +
" and is not enforcing a security policy. Retry installation or contact Check Point support.";
} else {
install_error =
"Warning: Agent/Gateway " +
err_hostname +
" software update failed. Agent is running previous software. Contact Check Point support.";
}
corrupted_packages.insert(make_pair(package_name, package));
dbgWarning(D_ORCHESTRATOR) << "Failed to install package. Package: " << package_name;
auto orchestration_status = Singleton::Consume<I_OrchestrationStatus>::by<ManifestHandler>();
string err_hostname = (hostname.ok() ? "on host '" + *hostname : "'" + details->getAgentId()) + "'";
string install_error =
"Warning: Agent/Gateway " +
err_hostname +
" software update failed. Agent is running previous software. Contact Check Point support.";
if (orchestration_status->getManifestError().find("Gateway was not fully deployed") == string::npos) {
orchestration_status->setFieldStatus(
OrchestrationStatusFieldType::MANIFEST,
@@ -304,11 +225,80 @@ ManifestHandler::installPackages(
install_error
);
}
return false;
}
current_packages.insert(make_pair(package_name, package));
return self_update_status;
}
string packages_dir = getConfigurationWithDefault<string>(
"/etc/cp/packages",
"orchestration",
"Packages directory"
);
auto package_handler = Singleton::Consume<I_PackageHandler>::by<ManifestHandler>();
if (!package_handler->shouldInstallPackage(package_name, package_handler_path)) {
current_packages.insert(make_pair(package_name, package));
dbgInfo(D_ORCHESTRATOR)
<< "Skipping installation of new package with the same version as current. Package: "
<< package_name;
return true;
}
string current_installation_file = packages_dir + "/" + package_name + "/" + package_name;
auto orchestration_tools = Singleton::Consume<I_OrchestrationTools>::by<ManifestHandler>();
bool is_clean_installation = !orchestration_tools->doesFileExist(current_installation_file);
bool current_result = true;
bool is_service = package.getType() == Package::PackageType::Service;
if (is_service) {
current_result = package_handler->preInstallPackage(package_name, package_handler_path);
}
current_result = current_result && package_handler->installPackage(
package_name,
package_handler_path,
false
);
if (current_result && is_service) {
current_result = package_handler->postInstallPackage(package_name, package_handler_path);
}
if (current_result && is_service) {
current_result = package_handler->updateSavedPackage(package_name, package_handler_path);
}
if (!current_result) {
auto agent_details = Singleton::Consume<I_AgentDetails>::by<ManifestHandler>();
auto hostname = Singleton::Consume<I_DetailsResolver>::by<ManifestHandler>()->getHostname();
string err_hostname = (hostname.ok() ? "on host '" + *hostname : "'" +agent_details->getAgentId()) + "'";
string install_error;
if (is_clean_installation) {
install_error =
"Critical Error: Agent/Gateway was not fully deployed " +
err_hostname +
" and is not enforcing a security policy. Retry installation or contact Check Point support.";
} else {
install_error =
"Warning: Agent/Gateway " +
err_hostname +
" software update failed. Agent is running previous software. Contact Check Point support.";
}
corrupted_packages.insert(make_pair(package_name, package));
dbgWarning(D_ORCHESTRATOR) << "Failed to install package. Package: " << package_name;
auto orchestration_status = Singleton::Consume<I_OrchestrationStatus>::by<ManifestHandler>();
if (orchestration_status->getManifestError().find("Gateway was not fully deployed") == string::npos) {
orchestration_status->setFieldStatus(
OrchestrationStatusFieldType::MANIFEST,
OrchestrationStatusResult::FAILED,
install_error
);
}
return false;
}
current_packages.insert(make_pair(package_name, package));
return true;
}