Add default to --report CLI option 31/51731/5
authorEddie Arrage <eddie.arrage@huawei.com>
Mon, 5 Feb 2018 22:11:25 +0000 (14:11 -0800)
committerEddie Arrage <eddie.arrage@huawei.com>
Tue, 6 Feb 2018 04:12:22 +0000 (20:12 -0800)
- Try new license header to deal with anteater failure

- Ability to specify 'default' as argument to --report, which
fetches host IP automatically and forms URL with 8000 as testapi
port
- This should not break the previous behavior of report option,
if default option not specified

Change-Id: I1e05bb52cf4fc211c59796d4e763e2e04177b406
Signed-off-by: Eddie Arrage <eddie.arrage@huawei.com>
dovetail/run.py

index e5154ad..8b29fba 100755 (executable)
@@ -1,11 +1,13 @@
 #!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2017 grakiss.wanglei@huawei.com and others.
 #
-# grakiss.wanglei@huawei.com
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Apache License, Version 2.0
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
-#
+##############################################################################
 
 
 import click
@@ -123,10 +125,11 @@ def validate_input(input_dict, check_dict, logger):
     # for 'report' option
     report = input_dict['report']
     if report:
-        if not (report.startswith("http") or report == "file"):
-            logger.error("Report type can't be {}, valid types are 'file' "
-                         "and 'http'.".format(input_dict['report']))
-            raise SystemExit(1)
+        if report != "default":
+            if not (report.startswith("http") or report == "file"):
+                logger.error("Report type can't be {}, valid types are 'file' "
+                             "and 'http'.".format(input_dict['report']))
+                raise SystemExit(1)
 
 
 def filter_config(input_dict, logger):
@@ -273,6 +276,10 @@ def main(*args, **kwargs):
     if kwargs['report']:
         if(kwargs['report'].endswith('/')):
             kwargs['report'] = kwargs['report'][0:kwargs['report'].rfind('/')]
+        if(kwargs['report'] == "default"):
+            host_ip = os.popen(
+                "/sbin/ip route|awk '/default/ { print $3 }'").read().rstrip()
+            kwargs['report'] = "http://" + host_ip + ":8000/api/v1/results"
         dt_cfg.dovetail_config['report_dest'] = kwargs['report']
         dt_cfg.update_cmds()