summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Dong <michael.dong@rackspace.com>2018-12-10 14:46:10 -0600
committerMichael Dong <michael.dong@rackspace.com>2018-12-10 16:03:19 -0600
commit8930d98a26ff325fea3e5cb68333b925425eb5bc (patch)
treefd656eef10c0b12ba6ccbcdfecd2b0ec5891e3e2
parent6cf7bdab872b057f207453920b6a4ceae3eb6efc (diff)
Custom root configuration optionHEADmaster
Instead of syntribos taking in ``--custom_install_root` during init and ``--syntribos-custom_root`` during run, which sometimes led to the custom root option not being set correctly, the redundant config options have been deprecated. Change-Id: I95f4d345fe8a8608ff6d1daaf06ff49912917a3f
Notes
Notes (review): Code-Review+2: Charles Neill <charles.neill@rackspace.com> Workflow+1: Charles Neill <charles.neill@rackspace.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 10 Dec 2018 22:29:39 +0000 Reviewed-on: https://review.openstack.org/624196 Project: openstack/syntribos Branch: refs/heads/master
-rw-r--r--README.rst13
-rw-r--r--doc/source/installation.rst9
-rw-r--r--doc/source/running.rst4
-rw-r--r--syntribos/config.py18
-rw-r--r--syntribos/runner.py8
-rw-r--r--syntribos/utils/env.py31
6 files changed, 54 insertions, 29 deletions
diff --git a/README.rst b/README.rst
index cdddf53..fc9fd26 100644
--- a/README.rst
+++ b/README.rst
@@ -249,23 +249,24 @@ This can be done manually, or with the ``init`` command.
249 ``syntribos download --payloads`` at any time. 249 ``syntribos download --payloads`` at any time.
250 250
251To specify a custom root for syntribos to be installed in, 251To specify a custom root for syntribos to be installed in,
252specify the ``--custom_install_root`` flag after ``init``. This will skip 252specify the ``--custom_root`` flag. This will skip
253prompts for information from the terminal, which can be handy for 253prompts for information from the terminal, which can be handy for
254Jenkins jobs and other situations where user input cannot be retrieved. 254Jenkins jobs and other situations where user input cannot be retrieved.
255 255
256If you've already run the ``init`` command but want to start over with a fresh 256If you've already run the ``init`` command but want to start over with a fresh
257environment, you can specify the ``--force`` flag to overwrite existing files. 257environment, you can specify the ``--force`` flag to overwrite existing files.
258The ``--custom_install_root`` and ``--force`` flags can be combined to 258The ``--custom_root`` and ``--force`` flags can be combined to
259overwrite files in a custom install root. 259overwrite files in a custom install root.
260 260
261Note: if you install syntribos to a custom install root, you must supply the 261Note: if you install syntribos to a custom install root, you must supply the
262``--custom_install_root`` flag when running syntribos. 262``--custom_root`` flag when running syntribos.
263 263
264**Example:** 264**Example:**
265 265
266:: 266::
267 267
268 $ syntribos init --custom_install_root /your/custom/path --force 268 $ syntribos --custom_root /your/custom/path init --force
269 $ syntribos --custom_root /your/custom/path run
269 270
270 271
271 272
@@ -528,8 +529,8 @@ Specifying a custom root directory
528~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 529~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
529 530
530If you set up the syntribos environment with a custom root (i.e. with 531If you set up the syntribos environment with a custom root (i.e. with
531``syntribos init --custom_install_root``), you can point to it with the 532``syntribos --custom_root init``), you can point to it with the
532``--syntribos-custom_root`` configuration option. Syntribos will look for a 533``--custom_root`` configuration option. Syntribos will look for a
533``syntribos.conf`` file inside this directory, and will read further 534``syntribos.conf`` file inside this directory, and will read further
534configuration information from there. 535configuration information from there.
535 536
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
index 23deb17..2a33508 100644
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -40,22 +40,23 @@ This can be done manually, or with the ``init`` command.
40 ``syntribos download --payloads`` at any time. 40 ``syntribos download --payloads`` at any time.
41 41
42To specify a custom root for syntribos to be installed in, 42To specify a custom root for syntribos to be installed in,
43specify the ``--custom_install_root`` flag after ``init``. This will skip 43specify the ``--custom_root`` flag. This will skip
44prompts for information from the terminal, which can be handy for 44prompts for information from the terminal, which can be handy for
45Jenkins jobs and other situations where user input cannot be retrieved. 45Jenkins jobs and other situations where user input cannot be retrieved.
46 46
47If you've already run the ``init`` command but want to start over with a fresh 47If you've already run the ``init`` command but want to start over with a fresh
48environment, you can specify the ``--force`` flag to overwrite existing files. 48environment, you can specify the ``--force`` flag to overwrite existing files.
49The ``--custom_install_root`` and ``--force`` flags can be combined to 49The ``--custom_root`` and ``--force`` flags can be combined to
50overwrite files in a custom install root. 50overwrite files in a custom install root.
51 51
52Note: if you install syntribos to a custom install root, you must supply the 52Note: if you install syntribos to a custom install root, you must supply the
53``--custom_install_root`` flag when running syntribos. 53``--custom_root`` flag when running syntribos.
54 54
55**Example:** 55**Example:**
56 56
57:: 57::
58 58
59 $ syntribos init --custom_install_root /your/custom/path --force 59 $ syntribos --custom_root /your/custom/path init --force
60 $ syntribos --custom_root /your/custom/path run
60 61
61 62
diff --git a/doc/source/running.rst b/doc/source/running.rst
index b7b1518..7f9f539 100644
--- a/doc/source/running.rst
+++ b/doc/source/running.rst
@@ -34,7 +34,7 @@ Specifying a custom root directory
34~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 34~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 35
36If you set up the syntribos environment with a custom root (i.e. with 36If you set up the syntribos environment with a custom root (i.e. with
37``syntribos init --custom_install_root``), you can point to it with the 37``syntribos --custom_root init``), you can point to it with the
38``--syntribos-custom_root`` configuration option. Syntribos will look for a 38``--custom_root`` configuration option. Syntribos will look for a
39``syntribos.conf`` file inside this directory, and will read further 39``syntribos.conf`` file inside this directory, and will read further
40configuration information from there. 40configuration information from there.
diff --git a/syntribos/config.py b/syntribos/config.py
index 4afdffd..b3b0074 100644
--- a/syntribos/config.py
+++ b/syntribos/config.py
@@ -71,14 +71,14 @@ def sub_commands(sub_parser):
71 help=_( 71 help=_(
72 "Skip prompts for configurable options, force initialization " 72 "Skip prompts for configurable options, force initialization "
73 "even if syntribos believes it has already been initialized. If " 73 "even if syntribos believes it has already been initialized. If "
74 "--custom_install_root isn't specified, we will use the default " 74 "--custom_root isn't specified, we will use the default "
75 "options. WARNING: This is potentially destructive! Use with " 75 "options. WARNING: This is potentially destructive! Use with "
76 "caution.")) 76 "caution."))
77 init_parser.add_argument( 77 init_parser.add_argument(
78 "--custom_install_root", dest="custom_install_root", 78 "--custom_install_root", dest="custom_install_root",
79 help=_("Skip prompts for configurable options, and initialize " 79 help=_("(DEPRECATED) Skip prompts for configurable options, and "
80 "syntribos in the specified directory. Can be combined " 80 "initialize syntribos in the specified directory. Can be "
81 "with --force to overwrite existing files.")) 81 "combined with --force to overwrite existing files."))
82 init_parser.add_argument( 82 init_parser.add_argument(
83 "--no_downloads", dest="no_downloads", action="store_true", 83 "--no_downloads", dest="no_downloads", action="store_true",
84 help=_("Disable the downloading of payload files as part of the " 84 help=_("Disable the downloading of payload files as part of the "
@@ -184,6 +184,13 @@ def list_cli_opts():
184 cfg.BoolOpt("stacktrace", dest="stacktrace", default=True, 184 cfg.BoolOpt("stacktrace", dest="stacktrace", default=True,
185 help=_("Select if Syntribos outputs a stacktrace " 185 help=_("Select if Syntribos outputs a stacktrace "
186 " if an exception is raised")), 186 " if an exception is raised")),
187 cfg.StrOpt(
188 "custom_root", dest="custom_root",
189 help=_("Filesystem location for syntribos root directory, "
190 "containing logs, templates, payloads, config files. "
191 "Creates directories and skips interactive prompts when "
192 "used with 'syntribos init'"),
193 deprecated_group="init", deprecated_name="custom_install_root")
187 ] 194 ]
188 195
189 196
@@ -231,7 +238,8 @@ def list_syntribos_opts():
231 help=_( 238 help=_(
232 "The root directory where the subfolders that make up" 239 "The root directory where the subfolders that make up"
233 " syntribos' environment (logs, templates, payloads, " 240 " syntribos' environment (logs, templates, payloads, "
234 "configuration files, etc.)")), 241 "configuration files, etc.)"),
242 deprecated_for_removal=True),
235 cfg.StrOpt("meta_vars", sample_default="/path/to/meta.json", 243 cfg.StrOpt("meta_vars", sample_default="/path/to/meta.json",
236 help=_( 244 help=_(
237 "The path to a meta variable definitions file, which " 245 "The path to a meta variable definitions file, which "
diff --git a/syntribos/runner.py b/syntribos/runner.py
index 4bbfaef..f44198c 100644
--- a/syntribos/runner.py
+++ b/syntribos/runner.py
@@ -139,6 +139,9 @@ class Runner(object):
139 try: 139 try:
140 syntribos.config.register_opts() 140 syntribos.config.register_opts()
141 if use_file: 141 if use_file:
142 # Parsing the args first in case a custom_install_root
143 # was specified.
144 CONF(argv, default_config_files=[])
142 CONF(argv, default_config_files=[ENV.get_default_conf_file()]) 145 CONF(argv, default_config_files=[ENV.get_default_conf_file()])
143 else: 146 else:
144 CONF(argv, default_config_files=[]) 147 CONF(argv, default_config_files=[])
@@ -287,8 +290,9 @@ class Runner(object):
287 print( 290 print(
288 "\n" 291 "\n"
289 "*** The JSON parser raised an exception when parsing " 292 "*** The JSON parser raised an exception when parsing "
290 "{}. Check that the file contains correctly formatted " 293 "{}. Check that the file contains "
291 "JSON data. *** \n".format(_full_path) 294 "correctly formatted JSON data. ***\n".format(
295 _full_path)
292 ) 296 )
293 for file_path, req_str in templates_dir: 297 for file_path, req_str in templates_dir:
294 if "meta.json" in file_path: 298 if "meta.json" in file_path:
diff --git a/syntribos/utils/env.py b/syntribos/utils/env.py
index f06540e..f8f9b2d 100644
--- a/syntribos/utils/env.py
+++ b/syntribos/utils/env.py
@@ -72,12 +72,13 @@ def get_syntribos_root():
72 """This determines the proper path to use as syntribos' root directory.""" 72 """This determines the proper path to use as syntribos' root directory."""
73 path = "" 73 path = ""
74 try: 74 try:
75 custom_root = CONF.syntribos.custom_root 75 custom_root = (
76 CONF.syntribos.custom_root or CONF.custom_root or ""
77 )
76 if custom_root: 78 if custom_root:
77 return expand_path(custom_root) 79 return expand_path(custom_root)
78 except Exception: 80 except Exception:
79 pass 81 raise
80
81 home_root = get_user_home_root() 82 home_root = get_user_home_root()
82 83
83 # Virtualenv detection 84 # Virtualenv detection
@@ -110,6 +111,7 @@ def get_log_dir_name(log_path=""):
110 111
111 112
112def safe_makedirs(path, force=False): 113def safe_makedirs(path, force=False):
114 path = os.path.abspath(path)
113 if not os.path.exists(path): 115 if not os.path.exists(path):
114 try: 116 try:
115 os.makedirs(path) 117 os.makedirs(path)
@@ -142,7 +144,8 @@ def create_env_dirs(root_dir, force=False):
142 log_dir = os.path.join(root_dir, "logs") 144 log_dir = os.path.join(root_dir, "logs")
143 safe_makedirs(log_dir, force) 145 safe_makedirs(log_dir, force)
144 146
145 return (root_dir, payloads, templates, log_dir) 147 return tuple(os.path.abspath(x)
148 for x in (root_dir, payloads, templates, log_dir))
146 149
147 150
148def create_conf_file(created_folders=None, remote_path=None): 151def create_conf_file(created_folders=None, remote_path=None):
@@ -151,17 +154,25 @@ def create_conf_file(created_folders=None, remote_path=None):
151 conf_file = os.path.join(root, FILE) 154 conf_file = os.path.join(root, FILE)
152 # Create default configuration file 155 # Create default configuration file
153 with open(conf_file, "w") as f: 156 with open(conf_file, "w") as f:
154 custom_root = CONF.sub_command.custom_install_root or "" 157 custom_root = (
158 CONF.syntribos.custom_root or CONF.custom_root or ""
159 )
155 if custom_root: 160 if custom_root:
156 custom_root = "custom_root={0}".format(custom_root) 161 custom_root = (
162 "# Any changes in the [DEFAULT] section will overwrite all "
163 "command line options\n"
164 "# [DEFAULT]\n"
165 "# custom_root={0}"
166 "# force=true\n\n"
167 ).format(custom_root)
157 template = ( 168 template = (
158 "# syntribos barebones configuration file\n" 169 "# syntribos barebones configuration file\n"
159 "# You should update this with your desired options!\n" 170 "# You should update this with your desired options!\n\n"
171 "{custom_root}"
160 "[syntribos]\n" 172 "[syntribos]\n"
161 "endpoint=http://127.0.0.1:8080\n" 173 "endpoint=http://127.0.0.1:8080\n"
162 "payloads={payloads}\n" 174 "payloads={payloads}\n"
163 "templates={templates}\n" 175 "templates={templates}\n\n"
164 "{custom_root}\n\n"
165 "[logging]\n" 176 "[logging]\n"
166 "log_dir={logs}\n" 177 "log_dir={logs}\n"
167 ).format( 178 ).format(
@@ -196,7 +207,7 @@ def initialize_syntribos_env():
196 root_dir = get_venv_root() if is_venv() else get_user_home_root() 207 root_dir = get_venv_root() if is_venv() else get_user_home_root()
197 208
198 force = CONF.sub_command.force 209 force = CONF.sub_command.force
199 custom_root = CONF.sub_command.custom_install_root or "" 210 custom_root = CONF.syntribos.custom_root or CONF.custom_root or ""
200 if custom_root: 211 if custom_root:
201 root_dir = custom_root 212 root_dir = custom_root
202 elif CONF.sub_command.force: 213 elif CONF.sub_command.force: