This repository was archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove test repo meta from test/test_data/repo, generate data from test code using aktualizr-repo Signed-off-by: cheng.xiang <ext-cheng.xiang@here.com>
- Loading branch information
1 parent
3c26e78
commit cfcede4
Showing
33 changed files
with
216 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#ifndef METAFAKE_H_ | ||
#define METAFAKE_H_ | ||
|
||
#include <boost/filesystem.hpp> | ||
#include <chrono> | ||
#include <fstream> | ||
#include <string> | ||
|
||
#include "logging/logging.h" | ||
#include "utilities/utils.h" | ||
|
||
#define SHELL_CMD(cmd) if (system(cmd)) {LOG_ERROR << "system command failed: " << cmd;} | ||
|
||
class MetaFake { | ||
public: | ||
MetaFake(const boost::filesystem::path &meta_dir_in): meta_dir(meta_dir_in) { | ||
// generate original repo data | ||
cmd_head = "build/src/aktualizr_repo/aktualizr-repo --path " + meta_dir.string() + " --command "; | ||
repo_cmd = cmd_head + "generate --keytype RSA2048 --expires 2021-07-04T16:33:27Z --correlationid id0"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
backup(); | ||
create_image(); | ||
create_testData(); | ||
} | ||
|
||
private: | ||
void create_testData(void) { | ||
// add image for "has update" meta | ||
std::string image_head = cmd_head + "image --filename " + meta_dir.string() + "/"; | ||
repo_cmd = image_head + "dummy_firmware.txt --targetname dummy_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = image_head + "primary_firmware.txt --targetname primary_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = image_head + "secondary_firmware.txt --targetname secondary_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
std::string addtarget_head = cmd_head + "addtarget --hwid "; | ||
repo_cmd = addtarget_head + "primary_hw --serial CA:FE:A6:D2:84:9D --targetname primary_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = addtarget_head + "secondary_hw --serial secondary_ecu_serial --targetname secondary_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = cmd_head + "signtargets"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
rename("_hasupdates"); | ||
restore(); | ||
|
||
// add image for "no update" meta | ||
image_head = cmd_head + "image --filename " + meta_dir.string() + "/"; | ||
repo_cmd = image_head + "dummy_firmware.txt --targetname dummy_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = cmd_head + "signtargets"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
rename("_noupdates"); | ||
restore(); | ||
|
||
// add image for "multi secondary ecu" meta | ||
image_head = cmd_head + "image --filename " + meta_dir.string() + "/"; | ||
repo_cmd = image_head + "dummy_firmware.txt --targetname dummy_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = image_head + "secondary_firmware.txt --targetname secondary_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = image_head + "secondary_firmware2.txt --targetname secondary_firmware2.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
addtarget_head = cmd_head + "addtarget --hwid "; | ||
repo_cmd = addtarget_head + "sec_hwid1 --serial sec_serial1 --targetname secondary_firmware.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = addtarget_head + "sec_hwid2 --serial sec_serial2 --targetname secondary_firmware2.txt"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
repo_cmd = cmd_head + "signtargets"; | ||
SHELL_CMD(repo_cmd.c_str()); | ||
|
||
rename("_multisec"); | ||
delete_backup(); | ||
} | ||
|
||
void create_image(void) { | ||
std::string content = "Just to increment timestamp, ignore it\n"; | ||
Utils::writeFile(meta_dir / "dummy_firmware.txt", content); | ||
content = "This is a dummy firmware file (should never be downloaded)\n"; | ||
Utils::writeFile(meta_dir / "primary_firmware.txt", content); | ||
content = "This is content"; | ||
Utils::writeFile(meta_dir / "secondary_firmware.txt", content); | ||
content = "This is more content\n"; | ||
Utils::writeFile(meta_dir / "secondary_firmware2.txt", content); | ||
} | ||
|
||
void backup(void) { | ||
director_targets_path = meta_dir / "repo/director/targets.json"; | ||
director_targets = Utils::readFile(director_targets_path, false); | ||
image_snapshot_path = meta_dir / "repo/image/snapshot.json"; | ||
image_snapshot = Utils::readFile(image_snapshot_path, false); | ||
image_targets_path = meta_dir / "repo/image/targets.json"; | ||
image_targets = Utils::readFile(image_targets_path, false); | ||
image_timestamp_path = meta_dir / "repo/image/timestamp.json"; | ||
image_timestamp = Utils::readFile(image_timestamp_path, false); | ||
} | ||
|
||
void restore(void) { | ||
Utils::writeFile(director_targets_path, director_targets); | ||
Utils::writeFile(image_snapshot_path, image_snapshot); | ||
Utils::writeFile(image_targets_path, image_targets); | ||
Utils::writeFile(image_timestamp_path, image_timestamp); | ||
} | ||
|
||
void delete_backup(void) { | ||
boost::filesystem::remove(director_targets_path); | ||
boost::filesystem::remove(image_snapshot_path); | ||
boost::filesystem::remove(image_targets_path); | ||
boost::filesystem::remove(image_timestamp_path); | ||
} | ||
|
||
void rename(const std::string &appendix) { | ||
boost::filesystem::rename(director_targets_path, | ||
(director_targets_path.parent_path() / director_targets_path.stem()).string() + appendix + ".json"); | ||
boost::filesystem::rename(image_snapshot_path, | ||
(image_snapshot_path.parent_path() / image_snapshot_path.stem()).string() + appendix + ".json"); | ||
boost::filesystem::rename(image_targets_path, | ||
(image_targets_path.parent_path() / image_targets_path.stem()).string() + appendix + ".json"); | ||
boost::filesystem::rename(image_timestamp_path, | ||
(image_timestamp_path.parent_path() / image_timestamp_path.stem()).string() + appendix + ".json"); | ||
} | ||
|
||
private: | ||
boost::filesystem::path meta_dir; | ||
boost::filesystem::path director_targets_path; | ||
std::string director_targets; | ||
boost::filesystem::path image_snapshot_path; | ||
std::string image_snapshot; | ||
boost::filesystem::path image_targets_path; | ||
std::string image_targets; | ||
boost::filesystem::path image_timestamp_path; | ||
std::string image_timestamp; | ||
std::string cmd_head; | ||
std::string repo_cmd; | ||
}; | ||
|
||
#endif // METAFAKE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../src/libaktualizr/campaign/test/campaigns_sample.json |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.