Re: [yocto] [qa-tools][PATCH] testopia_update: Improvements on update action functionality

2017-03-08 Thread Aníbal Limón


On 03/08/2017 09:56 AM, jose.perez.carra...@linux.intel.com wrote:
> From: Jose Perez Carranza 
> 
> Some improvements were applied when using option
> action=create :
> 
>- Create a new option to update test runs by ID
>- Create functions to load results and check missing test cases
>- Add warning to use –testrun-id
>- Improvements to update_test_run using exiting data of test run
>- Create function get test run details by ID
>- Create Dummy product to use on cases when specific product is not
>  relevant
> 
> Signed-off-by: Jose Perez Carranza 
> ---
>  testopia_update.py  | 60 
> +
>  testopia_update/product/__init__.py | 17 +--
>  2 files changed, 61 insertions(+), 16 deletions(-)
> 
> diff --git a/testopia_update.py b/testopia_update.py
> index 044074a..9cd9ad1 100755
> --- a/testopia_update.py
> +++ b/testopia_update.py
> @@ -17,6 +17,29 @@ ACTIONS = ('create', 'update')
>  BRANCHES = ('master', 'jethro', 'dizzy', 'daisy', 'noexists')
>  CATEGORIES = ('AUTO', 'MANUAL')
>  
> +
> +def check_missing_tc(env, build, test_run, results):
> +missing = product.update_test_run(test_run, results)
> +for tcid in missing:
> +logger.warn("%s: Test run %d, Case %d wasn't updated" %
> +(sys.argv[0], test_run['run_id'], tcid))

Only one comment, change the check_missing_tc to something like
update_test_run because the first time i read the function name, i
thought that do other thing.

alimon

> +
> +
> +def load_results(results_log):
> +if not results_log:
> +logger.error("%s: For action update --results-log needs to be 
> specified"
> + % (sys.argv[0]))
> +sys.exit(1)
> +if not os.path.exists(args.results_log):
> +logger.error("%s: Results log (%s) doesn't exists."
> + % (sys.argv[0], results_log))
> +sys.exit(1)
> +
> +res = product.parse_results_log(args.results_log)
> +
> +return res
> +
> +
>  def load_opts(args, opts_list, opts):
>  for to in opts_list:
>  if to in vars(args):
> @@ -26,6 +49,9 @@ def load_opts(args, opts_list, opts):
>  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 
> ' +
> +'and --results-log if test run was already 
> created')
>  sys.exit(1)
>  
>  class Options(object):
> @@ -73,6 +99,9 @@ def get_args():
>  parser.add_argument('--test-plan', required=False,
>  dest="plan_name", help='Name of the test plan of the product, used 
> when \
>  test plan name is different from product 
> name.')
> +parser.add_argument('--testrun-id', required=False,
> +dest="trun_id", help='Number of the test run to be updated, this \
> +  option should be used along with update 
> action.')
>  
>  parser.add_argument('--results-log', required=False,
>  dest="results_log", help='Results log.')
> @@ -131,6 +160,21 @@ if __name__ == '__main__':
>  print("%s\n" % p.name)
>  sys.exit(0)
>  
> +if args.action == 'update' and args.trun_id:
> +args.product_name = 'Dummy'
> +product = get_product_class(args.product_name, products)
> +try:
> +tr = product.get_existing_test_run(int(args.trun_id))
> +except Exception as e:
> +logger.error("%s: Problem found with Test Run %s: \n==>%s"
> + % (sys.argv[0], args.trun_id, e))
> +sys.exit(1)
> +
> +results = load_results(args.results_log)
> +check_missing_tc(tr['environment_id'], tr['build_id'], tr, results)
> +
> +sys.exit(0)
> +
>  load_opts(args, testopia_opts, opts)
>  
>  params = ['action', 'product_name', 'branch_name', 'env_name']
> @@ -205,16 +249,8 @@ if __name__ == '__main__':
>  " and ID (%s)." % (sys.argv[0], template_test_run['run_id'],
>  test_run['summary'], test_run['run_id']))
>  elif args.action == "update":
> -if not args.results_log:
> -logger.error("%s: For update --results-log needs to be 
> specified." \
> -% (sys.argv[0]))
> -sys.exit(1)
> -if not os.path.exists(args.results_log):
> -logger.error("%s: Results log (%s) don't exists." \
> -% (sys.argv[0], args.results_log))
> -sys.exit(1)
> +results = load_results(args.results_log)
>  
> -results = product.parse_results_log(args.results_log)
>  test_run = product.get_test_run(test_plan, env, build, 
> args.project_date,
>  

[yocto] [qa-tools][PATCH] testopia_update: Improvements on update action functionality

2017-03-08 Thread jose . perez . carranza
From: Jose Perez Carranza 

Some improvements were applied when using option
action=create :

   - Create a new option to update test runs by ID
   - Create functions to load results and check missing test cases
   - Add warning to use –testrun-id
   - Improvements to update_test_run using exiting data of test run
   - Create function get test run details by ID
   - Create Dummy product to use on cases when specific product is not
 relevant

Signed-off-by: Jose Perez Carranza 
---
 testopia_update.py  | 60 +
 testopia_update/product/__init__.py | 17 +--
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/testopia_update.py b/testopia_update.py
index 044074a..9cd9ad1 100755
--- a/testopia_update.py
+++ b/testopia_update.py
@@ -17,6 +17,29 @@ ACTIONS = ('create', 'update')
 BRANCHES = ('master', 'jethro', 'dizzy', 'daisy', 'noexists')
 CATEGORIES = ('AUTO', 'MANUAL')
 
+
+def check_missing_tc(env, build, test_run, results):
+missing = product.update_test_run(test_run, results)
+for tcid in missing:
+logger.warn("%s: Test run %d, Case %d wasn't updated" %
+(sys.argv[0], test_run['run_id'], tcid))
+
+
+def load_results(results_log):
+if not results_log:
+logger.error("%s: For action update --results-log needs to be 
specified"
+ % (sys.argv[0]))
+sys.exit(1)
+if not os.path.exists(args.results_log):
+logger.error("%s: Results log (%s) doesn't exists."
+ % (sys.argv[0], results_log))
+sys.exit(1)
+
+res = product.parse_results_log(args.results_log)
+
+return res
+
+
 def load_opts(args, opts_list, opts):
 for to in opts_list:
 if to in vars(args):
@@ -26,6 +49,9 @@ def load_opts(args, opts_list, opts):
 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 ' 
+
+'and --results-log if test run was already 
created')
 sys.exit(1)
 
 class Options(object):
@@ -73,6 +99,9 @@ def get_args():
 parser.add_argument('--test-plan', required=False,
 dest="plan_name", help='Name of the test plan of the product, used 
when \
 test plan name is different from product 
name.')
+parser.add_argument('--testrun-id', required=False,
+dest="trun_id", help='Number of the test run to be updated, this \
+  option should be used along with update action.')
 
 parser.add_argument('--results-log', required=False,
 dest="results_log", help='Results log.')
@@ -131,6 +160,21 @@ if __name__ == '__main__':
 print("%s\n" % p.name)
 sys.exit(0)
 
+if args.action == 'update' and args.trun_id:
+args.product_name = 'Dummy'
+product = get_product_class(args.product_name, products)
+try:
+tr = product.get_existing_test_run(int(args.trun_id))
+except Exception as e:
+logger.error("%s: Problem found with Test Run %s: \n==>%s"
+ % (sys.argv[0], args.trun_id, e))
+sys.exit(1)
+
+results = load_results(args.results_log)
+check_missing_tc(tr['environment_id'], tr['build_id'], tr, results)
+
+sys.exit(0)
+
 load_opts(args, testopia_opts, opts)
 
 params = ['action', 'product_name', 'branch_name', 'env_name']
@@ -205,16 +249,8 @@ if __name__ == '__main__':
 " and ID (%s)." % (sys.argv[0], template_test_run['run_id'],
 test_run['summary'], test_run['run_id']))
 elif args.action == "update":
-if not args.results_log:
-logger.error("%s: For update --results-log needs to be specified." 
\
-% (sys.argv[0]))
-sys.exit(1)
-if not os.path.exists(args.results_log):
-logger.error("%s: Results log (%s) don't exists." \
-% (sys.argv[0], args.results_log))
-sys.exit(1)
+results = load_results(args.results_log)
 
-results = product.parse_results_log(args.results_log)
 test_run = product.get_test_run(test_plan, env, build, 
args.project_date,
 args.project_version, args.category_name, args.optional)
 if not test_run:
@@ -224,8 +260,6 @@ if __name__ == '__main__':
 args.optional))
 sys.exit(1)
 
-missing = product.update_test_run(env, build, test_run, results)
-for tcid in missing:
-logger.warn("%s: Product %s, Test run %d, Case %d wasn't updated" 
%\
-(sys.argv[0], args.product_name, test_run['run_id'], tcid))
+check_missing_tc(env,