Commit 28bfeb70 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin

Merge branch 'issue/143' into 'development'

SCRUM#143 - Test agent - windows 7 64 bits

See merge request !105
parents 66066015 4ceaf334
Pipeline #12973 passed with stages
in 32 minutes and 29 seconds
......@@ -10,6 +10,8 @@
#include <agent/get.h>
#include <json/json.h>
namespace fs = boost::filesystem;
/**
* @file connection.h
* @brief This file has Curl class and the purpose is to make a get or post request to web service and download the agent zip file
......
......@@ -44,10 +44,11 @@ bool Connection::downloadAgent(std::string url, Agent* agent, bool option) {
* Create a tmp directory on linux (I don't think it's the same on windows)
* /tmp/Agent%%%% ....
*/
boost::filesystem::path tmp_dir_agent(boost::filesystem::unique_path(
boost::filesystem::temp_directory_path(ec) / "Agent%%%%-%%%%-%%%%"));
if (!boost::filesystem::create_directory(tmp_dir_agent, ec) || ec) {
fs::path tmp_dir_agent(fs::unique_path(fs::temp_directory_path(ec)
/ "Agent%%%%-%%%%-%%%%"));
if (!fs::create_directory(tmp_dir_agent, ec) || ec) {
agent->logFile << __DATE__ + std::string(" - ERROR: Failed to create ")
+ std::string("a temporary directory.") << std::endl;
return false;
......@@ -60,12 +61,12 @@ bool Connection::downloadAgent(std::string url, Agent* agent, bool option) {
#endif
/* Create the agent tmp (.run) or (.exe) file into tmp_dir_agent */
boost::filesystem::path file_installer(tmp_dir_agent / agent->getInstallerName()); // NOLINT [whitespace/line_length]
fs::path file_installer(tmp_dir_agent / agent->getInstallerName()); // NOLINT [whitespace/line_length]
#ifdef __unix__
FILE* fp = fopen(file_installer.c_str(), "wb");
#elif _WIN32
FILE* fp = fopen((const char*)file_installer.c_str(), "wb");
FILE* fp = fopen((const char*)(file_installer.string()).c_str(), "wb");
#endif
if (!fp) {
......@@ -101,7 +102,7 @@ bool Connection::downloadAgent(std::string url, Agent* agent, bool option) {
}
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
response = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
......@@ -119,6 +120,12 @@ bool Connection::downloadAgent(std::string url, Agent* agent, bool option) {
return false;
}
if (httpCode == 404) {
agent->logFile << __DATE__ + std::string(" - ERROR: Agent installer") +
std::string(" not found at web service.") << std::endl;
return false;
}
fclose(fp);
// run agent.run on linux
......
......@@ -39,10 +39,11 @@ int check_update(Agent* agent) {
std::string web_service = agent->getConf()->getWebService() +
std::string("/api/agent/version");
if (!agent->getConnection()->getVersion(agent, &version,
web_service, 0)) {
agent->logFile << __DATE__ << " - ERROR: Couldn't get current " <<
"version from simmc web service without pŕoxy." << std::endl;
"version from simmc web service without proxy." << std::endl;
option = true;
if (!agent->getConnection()->getVersion(agent, &version,
web_service, 1)) {
......@@ -56,28 +57,6 @@ int check_update(Agent* agent) {
boost::regex re("(\")|(\n)");
version = boost::regex_replace(version, re, "");
if (agent->getConf()->getVersion() == "0.0.0" && version != "") {
// open version.json file and update to current version
Json::Value config;
Json::Reader reader;
std::string path = agent->getPathConfigFile();
std::ifstream version_file(path.c_str(), std::ofstream::binary);
if (version_file.is_open()) {
reader.parse(version_file, config , false);
version_file.close();
config["version"] = version;
std::string idPoint = config["idPoint"].asString();
std::string proxyConf = config["proxyConf"].asString();
std::string webService = config["webService"].asString();
std::ofstream file(agent->getPathConfigFile(),
std::ios::trunc);
if (file.is_open()) {
file << config;
file.close();
}
}
}
/* Case version are different, then make the download */
if (compare_version(agent, version)) {
/* Case not download, return false */
......@@ -87,6 +66,29 @@ int check_update(Agent* agent) {
agent->logFile << __DATE__ << " - SUCCESS: Update process " <<
"terminated successfully." << std::endl;
agent->logFile.close();
if (agent->getConf()->getVersion() == "0.0.0" && version != "") { // NOLINT [whitespace/line_length]
// open version.json file and update to current version
Json::Value config;
Json::Reader reader;
std::string path = agent->getPathConfigFile();
std::ifstream version_file(path.c_str(),
std::ofstream::binary);
if (version_file.is_open()) {
reader.parse(version_file, config , false);
version_file.close();
config["version"] = version;
std::string idPoint = config["idPoint"].asString();
std::string proxyConf = config["proxyConf"].asString();
std::string webService = config["webService"].asString(); // NOLINT [whitespace/line_length]
std::ofstream file(agent->getPathConfigFile(),
std::ios::trunc);
if (file.is_open()) {
file << config;
file.close();
}
}
}
return true;
}
}
......@@ -145,7 +147,6 @@ bool get_agent_installer_name(Agent* agent, std::string* filename, bool opt) {
else
status_code = agent->getConnection()->getInstallerName(ws, agent, filename, opt); // NOLINT [whitespace/line_length]
if (status_code == 200) {
reader.parse(*filename, filename_json, false);
*filename = fastWriter.write(filename_json["filename"]);
......
......@@ -78,11 +78,6 @@ bool Proxy::proxyFileIsSet() const {
*/
bool set_proxy_object(Agent* agent, std::map<std::string,
std::string>* content) {
if (content->count("HOST") == 0 ||
content->count("PORT") == 0 ||
content->count("USR") == 0 ||
content->count("PASSWORD") == 0)
return false;
agent->getProxy()->setHost((*content)["HOST"]);
agent->getProxy()->setPort((*content)["PORT"]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment