Declarative when connected to management improvements

This commit is contained in:
Ned Wright 2024-02-14 16:31:44 +00:00
parent 8479ad58ed
commit 2fa866d1c5
3 changed files with 13 additions and 2 deletions

View File

@ -168,6 +168,10 @@ DeclarativePolicyUtils::getUpdate(CheckUpdateRequest &request)
auto maybe_new_version = getLocalPolicyChecksum(); auto maybe_new_version = getLocalPolicyChecksum();
if (!maybe_new_version.ok() || maybe_new_version == curr_version) { if (!maybe_new_version.ok() || maybe_new_version == curr_version) {
if (!policy_checksum.ok() || getPolicyChecksum() != policy_checksum.unpack()) {
dbgTrace(D_ORCHESTRATOR) << "Update policy checksum";
return getPolicyChecksum();
}
dbgDebug(D_ORCHESTRATOR) << "No new version is currently available"; dbgDebug(D_ORCHESTRATOR) << "No new version is currently available";
return ""; return "";
} }

View File

@ -100,8 +100,11 @@ FogCommunication::downloadAttributeFile(const GetResourceFile &resourse_file, co
string policy_mgmt_mode = getSettingWithDefault<string>("management", "profileManagedMode"); string policy_mgmt_mode = getSettingWithDefault<string>("management", "profileManagedMode");
if (policy_mgmt_mode == "declarative" && resourse_file.getFileName() =="policy") { if (policy_mgmt_mode == "declarative" && resourse_file.getFileName() =="policy") {
dbgDebug(D_ORCHESTRATOR) << "Download policy on declarative mode - returnig the local policy"; dbgDebug(D_ORCHESTRATOR) << "Download policy on declarative mode - returning the local policy";
return i_declarative_policy->getCurrPolicy(); string policy = i_declarative_policy->getCurrPolicy();
auto orchestration_tools = Singleton::Consume<I_OrchestrationTools>::by<FogCommunication>();
if (orchestration_tools->writeFile(policy, file_path)) return policy;
return genError("Failed to write policy to file: " + file_path);
} }
static const string file_attribute_str = "/api/v2/agents/resources/"; static const string file_attribute_str = "/api/v2/agents/resources/";

View File

@ -1417,6 +1417,10 @@ TEST_F(FogCommunicationTest, downloadFileDeclarativeMode)
mock_ot, mock_ot,
writeFile(encrypted_access_token, data_path + session_token_file_name, false)).WillOnce(Return(true) writeFile(encrypted_access_token, data_path + session_token_file_name, false)).WillOnce(Return(true)
); );
EXPECT_CALL(
mock_ot,
writeFile(_, "/tmp/orch_files/", false)).WillOnce(Return(true)
);
EXPECT_CALL(mock_ml, yield(A<chrono::microseconds>())).WillOnce( EXPECT_CALL(mock_ml, yield(A<chrono::microseconds>())).WillOnce(
Invoke( Invoke(
[] (chrono::microseconds microseconds) [] (chrono::microseconds microseconds)