You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/08/13 18:29:17 UTC
[trafficserver] 02/03: Runroot: add new option to specify layout
during creating
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 7899e8e34ede26adb77aa65d1872254d70ddbda0
Author: Xavier Chi <ch...@gmail.com>
AuthorDate: Tue Jul 10 16:04:18 2018 -0500
Runroot: add new option to specify layout during creating
(cherry picked from commit 5ca1665f6928f347af16b1e193e791d7a6a2ce7f)
---
doc/appendices/command-line/traffic_layout.en.rst | 4 ++
lib/records/RecConfigParse.cc | 17 ++++++++
lib/ts/runroot.cc | 6 +++
lib/ts/runroot.h | 3 ++
src/traffic_layout/engine.cc | 48 +++++++++++++++++++----
src/traffic_layout/engine.h | 7 +++-
src/traffic_layout/file_system.cc | 2 +-
src/traffic_layout/traffic_layout.cc | 2 -
tests/gold_tests/runroot/runroot_init.test.py | 9 +++--
9 files changed, 81 insertions(+), 17 deletions(-)
diff --git a/doc/appendices/command-line/traffic_layout.en.rst b/doc/appendices/command-line/traffic_layout.en.rst
index c236816..a56c7a0 100644
--- a/doc/appendices/command-line/traffic_layout.en.rst
+++ b/doc/appendices/command-line/traffic_layout.en.rst
@@ -103,6 +103,10 @@ Options
Specify the way of copying executables when creating runroot
+.. option:: --layout=[<YAML file>]
+
+ Use specific layout (providing YAML file) to create runroot
+
========
Examples
========
diff --git a/lib/records/RecConfigParse.cc b/lib/records/RecConfigParse.cc
index 3042b0e..81fecad 100644
--- a/lib/records/RecConfigParse.cc
+++ b/lib/records/RecConfigParse.cc
@@ -28,6 +28,7 @@
#include "ts/Tokenizer.h"
#include "ts/ink_defs.h"
#include "ts/ink_string.h"
+#include "ts/runroot.h"
#include "P_RecFile.h"
#include "P_RecUtils.h"
@@ -83,6 +84,20 @@ RecFileImport_Xmalloc(const char *file, char **file_buf, int *file_size)
}
//-------------------------------------------------------------------------
+// RecConfigOverrideFromRunroot
+//-------------------------------------------------------------------------
+bool
+RecConfigOverrideFromRunroot(const char *name)
+{
+ if (use_runroot()) {
+ if (!strcmp(name, "proxy.config.bin_path") || !strcmp(name, "proxy.config.local_state_dir") ||
+ !strcmp(name, "proxy.config.log.logfile_dir") || !strcmp(name, "proxy.config.plugin.plugin_dir"))
+ return true;
+ }
+ return false;
+}
+
+//-------------------------------------------------------------------------
// RecConfigOverrideFromEnvironment
//-------------------------------------------------------------------------
const char *
@@ -106,6 +121,8 @@ RecConfigOverrideFromEnvironment(const char *name, const char *value)
envval = getenv((const char *)envname);
if (envval) {
return envval;
+ } else if (RecConfigOverrideFromRunroot(name)) {
+ return nullptr;
}
return value;
diff --git a/lib/ts/runroot.cc b/lib/ts/runroot.cc
index 119cd56..38edaa4 100644
--- a/lib/ts/runroot.cc
+++ b/lib/ts/runroot.cc
@@ -246,3 +246,9 @@ check_runroot()
}
return runroot_map(using_runroot);
}
+
+bool
+use_runroot()
+{
+ return !using_runroot.empty();
+}
diff --git a/lib/ts/runroot.h b/lib/ts/runroot.h
index 4256cfc..a06636f 100644
--- a/lib/ts/runroot.h
+++ b/lib/ts/runroot.h
@@ -61,3 +61,6 @@ RunrootMapType runroot_map(const std::string &prefix);
// help check runroot for layout
RunrootMapType check_runroot();
+
+// helper method for records config to check using runroot or not
+bool use_runroot();
diff --git a/src/traffic_layout/engine.cc b/src/traffic_layout/engine.cc
index b6af4f6..764514d 100644
--- a/src/traffic_layout/engine.cc
+++ b/src/traffic_layout/engine.cc
@@ -44,7 +44,7 @@
#include <yaml-cpp/yaml.h>
// for nftw check_directory
-std::string directory_check = "";
+std::string directory_check;
// check if we can create the runroot using path
// return true if the path is good to use
@@ -149,6 +149,7 @@ RunrootEngine::runroot_help_message(const bool runflag, const bool cleanflag, co
"--absolute Produce absolute path in the yaml file\n"
"--run-root(=/path) Using specified TS_RUNROOT as sandbox\n"
"--copy-style=[STYLE] Specify style (FULL, HARD, SOFT) when copying executable\n"
+ "--layout=[/path] Use specific layout (providing yaml file) to create runroot\n"
<< std::endl;
}
if (cleanflag) {
@@ -192,7 +193,7 @@ RunrootEngine::runroot_parse()
abs_flag = true;
continue;
}
- if (argument.substr(0, RUNROOT_WORD_LENGTH) == "--run-root") {
+ if (argument.substr(0, RUNROOT_WORD.size()) == RUNROOT_WORD) {
continue;
}
// set init flag
@@ -218,8 +219,8 @@ RunrootEngine::runroot_parse()
fix_flag = true;
continue;
}
- if (argument.substr(0, COPYSTYLE_WORD_LENGTH) == "--copy-style") {
- std::string style = argument.substr(COPYSTYLE_WORD_LENGTH + 1);
+ if (argument.substr(0, COPYSTYLE_WORD.size()) == COPYSTYLE_WORD) {
+ std::string style = argument.substr(COPYSTYLE_WORD.size() + 1);
transform(style.begin(), style.end(), style.begin(), ::tolower);
if (style == "full") {
copy_style = FULL;
@@ -230,6 +231,14 @@ RunrootEngine::runroot_parse()
}
continue;
}
+ if (argument.substr(0, LAYOUT_WORD.size()) == LAYOUT_WORD) {
+ if (argument.size() <= LAYOUT_WORD.size() + 1) {
+ layout_file = "";
+ } else {
+ layout_file = argument.substr(LAYOUT_WORD.size() + 1);
+ }
+ continue;
+ }
if (argument == "--path") {
if (i + 1 >= _argv.size() || _argv[i + 1][0] == '-') {
// invalid path
@@ -454,6 +463,29 @@ RunrootEngine::copy_runroot(const std::string &original_root, const std::string
original_map[LAYOUT_INFODIR] = TS_BUILD_INFODIR;
original_map[LAYOUT_CACHEDIR] = TS_BUILD_CACHEDIR;
+ RunrootMapType new_map = original_map;
+ // use the user provided layout: layout_file
+ if (layout_file.size() != 0) {
+ try {
+ YAML::Node yamlfile = YAML::LoadFile(layout_file);
+ for (auto it : yamlfile) {
+ std::string key = it.first.as<std::string>();
+ std::string value = it.second.as<std::string>();
+ auto iter = new_map.find(key);
+ if (iter != new_map.end()) {
+ iter->second = value;
+ } else {
+ if (key != "prefix") {
+ ink_warning("Unknown item from %s: '%s'", layout_file.c_str(), key.c_str());
+ }
+ }
+ }
+ } catch (YAML::Exception &e) {
+ ink_warning("Unable to read provided YAML file '%s': %s", layout_file.c_str(), e.what());
+ ink_notice("Continuing with default value");
+ }
+ }
+
// copy each directory to the runroot path
// symlink the executables
// set up path_map for yaml to emit key-value pairs
@@ -465,15 +497,15 @@ RunrootEngine::copy_runroot(const std::string &original_root, const std::string
} else {
join_path = it.second;
}
+ std::string new_join_path = new_map[it.first];
std::string old_path = Layout::relative_to(original_root, join_path);
- std::string new_path = Layout::relative_to(ts_runroot, join_path);
+ std::string new_path = Layout::relative_to(ts_runroot, new_join_path);
if (abs_flag) {
- path_map[it.first] = Layout::relative_to(ts_runroot, join_path);
+ path_map[it.first] = Layout::relative_to(ts_runroot, new_join_path);
} else {
- path_map[it.first] = Layout::relative_to(".", join_path);
+ path_map[it.first] = Layout::relative_to(".", new_join_path);
}
-
// don't copy the prefix, mandir, localstatedir and infodir
if (it.first != LAYOUT_EXEC_PREFIX && it.first != LAYOUT_LOCALSTATEDIR && it.first != LAYOUT_MANDIR &&
it.first != LAYOUT_INFODIR) {
diff --git a/src/traffic_layout/engine.h b/src/traffic_layout/engine.h
index f83339b..857877d 100644
--- a/src/traffic_layout/engine.h
+++ b/src/traffic_layout/engine.h
@@ -29,8 +29,9 @@
#include <string>
#include <unordered_map>
-#define RUNROOT_WORD_LENGTH 10
-#define COPYSTYLE_WORD_LENGTH 12
+static const std::string_view RUNROOT_WORD{"--run-root"};
+static const std::string_view COPYSTYLE_WORD{"--copy-style"};
+static const std::string_view LAYOUT_WORD{"--layout"};
typedef std::unordered_map<std::string, std::string> RunrootMapType;
@@ -74,6 +75,8 @@ struct RunrootEngine {
// for parsing
int command_num = 0;
+ std::string layout_file;
+
CopyStyle copy_style = HARD;
// the path for create & remove
diff --git a/src/traffic_layout/file_system.cc b/src/traffic_layout/file_system.cc
index 681038e..02c6c5d 100644
--- a/src/traffic_layout/file_system.cc
+++ b/src/traffic_layout/file_system.cc
@@ -191,7 +191,7 @@ ts_copy_function(const char *src_path, const struct stat *sb, int flag)
std::string full_src_path = src_path;
if (full_src_path == src_root) {
if (!create_directory(dst_root)) {
- ink_fatal("create directory failed during copy");
+ ink_fatal("create directory '%s' failed during copy", dst_root.c_str());
}
return 0;
}
diff --git a/src/traffic_layout/traffic_layout.cc b/src/traffic_layout/traffic_layout.cc
index c77e40c..51b0762 100644
--- a/src/traffic_layout/traffic_layout.cc
+++ b/src/traffic_layout/traffic_layout.cc
@@ -46,7 +46,6 @@ struct subcommand {
// Command line arguments (parsing)
struct CommandLineArgs {
- int layout;
int features;
int json;
};
@@ -54,7 +53,6 @@ struct CommandLineArgs {
static CommandLineArgs cl;
const ArgumentDescription argument_descriptions[] = {
- {"layout", 'l', "Show the layout (this is the default with no options given)", "T", &cl.layout, nullptr, nullptr},
{"features", 'f', "Show the compiled features", "T", &cl.features, nullptr, nullptr},
{"json", 'j', "Produce output in JSON format (when supported)", "T", &cl.json, nullptr, nullptr},
VERSION_ARGUMENT_DESCRIPTION(),
diff --git a/tests/gold_tests/runroot/runroot_init.test.py b/tests/gold_tests/runroot/runroot_init.test.py
index fbb5117..7d5e105 100644
--- a/tests/gold_tests/runroot/runroot_init.test.py
+++ b/tests/gold_tests/runroot/runroot_init.test.py
@@ -66,7 +66,8 @@ tr.Processes.Default.Streams.All = Testers.ContainsExpression("Forcing creating
path5 = os.path.join(ts_root, "runroot5")
junk1 = os.path.join(path1, "bin/junk1")
junk2 = os.path.join(path1, "lib/junk2")
-junk3 = os.path.join(path1, "include/junk3")
+junk3 = os.path.join(path1, "var/junk3")
+
tr = Test.AddTestRun("Test traffic_layout init #5")
# create the junk files in runroot1 and create(init and copy) runroot5 from runroot 1
tr.Processes.Default.Command = "touch " + junk1 + ";" + "touch " + junk2 + ";" + \
@@ -77,13 +78,13 @@ f.Exists = True
# check if the junk file is created and not copied to the new runroot
f = tr.Disk.File(junk1)
f.Exists = True
-f = tr.Disk.File(os.path.join(path5, "bin/junk"))
+f = tr.Disk.File(os.path.join(path5, "bin/junk1"))
f.Exists = False
f = tr.Disk.File(junk2)
f.Exists = True
-f = tr.Disk.File(os.path.join(path5, "lib/junk"))
+f = tr.Disk.File(os.path.join(path5, "lib/junk2"))
f.Exists = False
f = tr.Disk.File(junk3)
f.Exists = True
-f = tr.Disk.File(os.path.join(path5, "include/junk"))
+f = tr.Disk.File(os.path.join(path5, "var/junk3"))
f.Exists = False