Add API to update hosts info about SUT 23/35923/7
authorrexlee8776 <limingjiang@huawei.com>
Mon, 5 Jun 2017 20:31:02 +0000 (20:31 +0000)
committerrexlee8776 <limingjiang@huawei.com>
Sun, 25 Jun 2017 13:59:54 +0000 (13:59 +0000)
JIRA: YARDSTICK-674

For some SUT which use domain name as endpoint and AUTH_URL, yardstick
restAPI should support to add "ip domain_name" info into /etc/hosts so
that it can use the ip_address to access the SUT.

api: /yardstick/env/action
description: update hosts info for domain name
method: POST

parameters:
{
    "action": "update_hosts",
    "args": {"opnfv.org": "1.1.1.1",
             "openstack.org": "2.2.2.2"
            }
}

Change-Id: Iaca9c846f02b1d53e2408d6a21f9201b599717d4
Signed-off-by: rexlee8776 <limingjiang@huawei.com>
api/resources/env_action.py
yardstick/common/constants.py

index 3536559..62ec786 100644 (file)
@@ -362,3 +362,16 @@ def upload_pod_file(args):
     logger.info('Writing finished')
 
     return result_handler(consts.API_SUCCESS, {'pod_info': data})
+
+
+def update_hosts(hosts_ip):
+    if not isinstance(hosts_ip, dict):
+        return result_handler(consts.API_ERROR, 'Error, args should be a dict')
+    logger.info('Writing hosts: Writing')
+    hosts_list = ['\n{} {}'.format(ip, host_name)
+                  for host_name, ip in hosts_ip.items()]
+    logger.debug('Writing: %s', hosts_list)
+    with open(consts.ETC_HOSTS, 'a') as f:
+        f.writelines(hosts_list)
+    logger.info('Writing hosts: Done')
+    return result_handler(consts.API_SUCCESS, 'success')
index 47a5199..f192a1b 100644 (file)
@@ -42,6 +42,7 @@ TESTSUITE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_suites/')
 
 # file
 OPENRC = get_param('file.openrc', '/etc/yardstick/openstack.creds')
+ETC_HOSTS = get_param('file.etc_hosts', '/etc/hosts')
 CONF_FILE = join(CONF_DIR, 'yardstick.conf')
 POD_FILE = join(CONF_DIR, 'pod.yaml')
 CONF_SAMPLE_FILE = join(CONF_SAMPLE_DIR, 'yardstick.conf.sample')