From: Jose Perez Carranza <jose.perez.carra...@linux.intel.com> Add action “setup” to do a different actions on the exiting Testopia DB, also add validation for the specific option used on this new action, sub-option “-clone-templates” implemented to help on the setup for new release and cloning form the same bran or form one branch to another.
Signed-off-by: Jose Perez Carranza <jose.perez.carra...@linux.intel.com> --- testopia_update.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/testopia_update.py b/testopia_update.py index b3e900d..fa8d10c 100755 --- a/testopia_update.py +++ b/testopia_update.py @@ -5,7 +5,6 @@ import sys import argparse import logging import ConfigParser -import types from external.testopia import Testopia from testopia_update.product import get_products, get_product_class @@ -13,8 +12,9 @@ from testopia_update.product import get_products, get_product_class DEFAULT_CONFIG_FILE = "testopia_update.config" DEFAULT_STORE_LOCATION = "/tmp/testopia_update" -ACTIONS = ('create', 'update') -BRANCHES = ('master', 'jethro', 'dizzy', 'daisy', 'noexists', 'morty', "pyro") +ACTIONS = ('create', 'update', 'setup') +BRANCHES = ('master', 'jethro', 'dizzy', 'daisy', 'noexists', 'morty', "krogoth", + "pyro") CATEGORIES = ('AUTO', 'MANUAL') @@ -41,16 +41,28 @@ def load_results(results_log): def load_opts(args, opts_list, opts): + + invalid_opts = ['old_project_version', 'clone_templates', 'new_branch'] + + if args.action == "create" or args.action == "update": + for invarg in invalid_opts: + if getattr(args, invarg): + logger.error("option %s not availabe for %s action " + % (invarg, args.action)) + sys.exit(1) + for to in opts_list: if to in vars(args): arg = getattr(args, to) if arg: setattr(opts, to, arg) + if not hasattr(opts, to): logger.error("%s: Requires testopia %s in arguments or config." % \ (sys.argv[0], to)) + if args.action == "update": - logger.warn('for action create you can use only --testrun-id ' + + logger.warn('for action update you can use only --testrun-id ' + 'and --results-log if test run was already created') sys.exit(1) @@ -59,7 +71,8 @@ def connect_to_testopia(): config = None opts = Options() - testopia_config = ['url', 'username', 'password', 'store_location'] + #testopia_config = ['url', 'username', 'password', 'store_location'] + testopia_config = ['url', 'username', 'password'] if not args.config and os.path.exists(DEFAULT_CONFIG_FILE): args.config = DEFAULT_CONFIG_FILE @@ -73,8 +86,8 @@ def connect_to_testopia(): load_opts(args, testopia_config, opts) - if not os.path.exists(opts.store_location): - os.makedirs(opts.store_location) + if not os.path.exists(DEFAULT_STORE_LOCATION): + os.makedirs(DEFAULT_STORE_LOCATION) return opts, config @@ -99,7 +112,7 @@ def get_args(): parser.add_argument('-a', '--action', required=False, dest='action', choices=ACTIONS, - help='Action to execute can be create or update.') + help='Action to execute can be create, update or setup') parser.add_argument('-p', '--product', required=False, dest="product_name", help='Product to create or update.') parser.add_argument('-c', '--category', required=False, @@ -131,6 +144,16 @@ def get_args(): parser.add_argument('--results-log', required=False, dest="results_log", help='Results log.') + parser.add_argument('--old-project-version', required=False, + dest="old_project_version", help='Version of the project to clone from') + + parser.add_argument('--clone-templates', required=False, + dest="clone_templates", help='clone templates from one brnach to \ + another or same branch (only avaibale) \ + with setup action', const='Y', nargs='?') + parser.add_argument('--new-branch', required=False, + dest="new_branch", help='New branch to clone the Templates') + parser.add_argument('--verbose', required=False, action="store_true", dest="verbose", default=False, help='Enable verbose mode.') parser.add_argument('--debug', required=False, action="store_true", @@ -172,6 +195,32 @@ if __name__ == '__main__': print("%s\n" % p.name) sys.exit(0) + if args.action == 'setup': + setup_opts = ['clone_templates', 'project_version','branch_name', + 'old_project_version', 'product_name'] + + load_opts(args, setup_opts, opts) + + product = get_product_class(args.product_name, products) + test_plan = product.get_test_plan(args.branch_name) + temp_summary = 'TRTEMP_' + args.old_project_version + temp_list = product.get_test_run_list(test_plan,temp_summary) + if not temp_list: + logger.error("%s: No templates found with %s string on %s" + % (sys.argv[0], temp_summary, args.branch_name)) + + for tr in temp_list: + if args.new_branch and args.new_branch != args.branch_name: + kwargs['new_branch'] = args.new_branch + + new_template = product.clone_template(tr, args.old_project_version, + args.project_version, **kwargs) + logger.info("%s: Template was created with (%d), Summary (%s)" + % (sys.argv[0], new_template['run_id'], + new_template['summary'])) + sys.exit(0) + + if args.action == 'update' and args.trun_id: args.product_name = 'Dummy' product = get_product_class(args.product_name, products) -- 2.11.0 -- _______________________________________________ yocto mailing list yocto@yoctoproject.org https://lists.yoctoproject.org/listinfo/yocto