Add a tuskar-load-seed command

This command is essentially the tuskar-load-roles functionality broken
out specifically to handle just the master seed (and the required
resource registry). Example usage:

$ tuskar-load-seed --config-file etc/tuskar/tuskar.conf --master-seed
~/tripleo-heat-templates/overcloud-without-mergepy.yaml --resource-registry
~/tripleo-heat-templates/overcloud-resource-registry-puppet.yaml

Subsequent runs will update the templates which is the same behavior as
the tuskar-load-roles command.

Change-Id: I07450edebd0dacd86bd0b28665eb1aaa3ea30ecb
This commit is contained in:
Jeff Peeler 2015-03-17 22:54:50 -04:00
parent 097920e78f
commit 9fe1c3a893
4 changed files with 101 additions and 0 deletions

View File

@ -26,6 +26,7 @@ console_scripts =
tuskar-api = tuskar.cmd.api:main
tuskar-dbsync = tuskar.cmd.dbsync:main
tuskar-load-roles = tuskar.cmd.load_roles:main
tuskar-load-seed = tuskar.cmd.load_seed:main
[build_sphinx]
all_files = 1

60
tuskar/cmd/load_seed.py Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function
import sys
from oslo.config import cfg
from tuskar.common import service
from tuskar.storage.load_roles import load_seed
def _print_names(message, names):
print("{0}: \n {1}".format(message, '\n '.join(names)))
seed_help = ('Full path to the template that should be loaded '
'as the master seed')
resource_registry_help = ('Path to the Heat environment file which maps the'
'custom resource types to template paths.')
cfg.CONF.register_cli_opt(cfg.StrOpt('master-seed', dest='master_seed',
help=seed_help))
cfg.CONF.register_cli_opt(cfg.StrOpt('resource-registry',
dest='resource_registry',
help=resource_registry_help))
def main(argv=None):
if argv is None:
argv = sys.argv
service.prepare_service(argv)
if not cfg.CONF.master_seed or not cfg.CONF.resource_registry:
sys.stderr.write("You must specify both `master-seed` and "
"`resource-registry`.")
sys.exit(1)
created, updated = load_seed(
seed_file=cfg.CONF.master_seed,
resource_registry_path=cfg.CONF.resource_registry)
if len(created):
_print_names("Created", created)
if len(updated):
_print_names("Updated", updated)

View File

@ -36,6 +36,17 @@ def role_name_from_path(role_path):
return path.splitext(path.basename(role_path))[0]
def load_seed(seed_file, resource_registry_path):
# enforced in CLI
assert seed_file is not None
assert resource_registry_path is not None
all_roles, created, updated = load_roles([], seed_file,
resource_registry_path)
return created, updated
def load_roles(roles, seed_file=None, resource_registry_path=None,
role_extra=None):
"""Given a list of roles files import them into the

View File

@ -16,6 +16,7 @@ from mock import call
from mock import patch
from tuskar.cmd import load_roles
from tuskar.cmd import load_seed
from tuskar.tests.base import TestCase
@ -27,6 +28,11 @@ class LoadRoleTests(TestCase):
ROLE_EXTRA = """ --role-extra /path/metadata/compute_data.yaml
-re /path/metadata/common_data.yaml """
ENV_DATA = """
resource_registry:
OS::TripleO::Another: required_file.yaml
"""
@patch('tuskar.storage.load_utils.load_file', return_value="YAML")
@patch('tuskar.cmd.load_roles._print_names')
def test_main(self, mock_print, mock_read):
@ -41,3 +47,26 @@ class LoadRoleTests(TestCase):
# verify
self.assertEqual([call('Created', expected_res)],
mock_print.call_args_list)
def test_load_seed_invalid_args(self):
main_args = "tuskar-load-seed"
self.assertRaises(SystemExit, load_seed.main, main_args.split())
main_args = "tuskar-load-seed --master-seed=seed.yaml"
self.assertRaises(SystemExit, load_seed.main, main_args.split())
main_args = "tuskar-load-seed --resource-registry=registry.yaml"
self.assertRaises(SystemExit, load_seed.main, main_args.split())
@patch('tuskar.storage.load_utils.load_file', return_value="YAML")
@patch('tuskar.storage.load_roles.load_file', return_value=ENV_DATA)
@patch('tuskar.cmd.load_seed._print_names')
def test_load_seed(self, mock_print, mock_read, mock_read2):
main_args = ("tuskar-load-seed --master-seed=seed.yaml"
" --resource-registry=registry.yaml")
expected_created = ['_master_seed', '_registry', 'required_file.yaml']
load_seed.main(argv=(main_args).split())
self.assertEqual([call('Created', expected_created)],
mock_print.call_args_list)