summaryrefslogtreecommitdiffstats
path: root/deploy/config_parse.py
diff options
context:
space:
mode:
authormeimei <meimei@huawei.com>2016-11-29 18:05:01 +0800
committermeimei <meimei@huawei.com>2016-11-29 18:09:16 +0800
commit6b2eccf0350f7f053e18ea2ac190489b00960809 (patch)
tree8968b2871c4bfc23bfa7077e857dae4d151e53d2 /deploy/config_parse.py
parentfcd0eefae931bb7bed0380574c1c7acaa31ffa28 (diff)
Improve compass ci verification, clear all the warnnings
JIRA: COMPASS-494 MODIFY BY HAOJINGBO Change-Id: I2b95d84157c860254b3b3f68f7b2a54393caf8f4 Signed-off-by: meimei <meimei@huawei.com>
Diffstat (limited to 'deploy/config_parse.py')
-rw-r--r--deploy/config_parse.py38
1 files changed, 32 insertions, 6 deletions
diff --git a/deploy/config_parse.py b/deploy/config_parse.py
index ba677ade..1c384c34 100644
--- a/deploy/config_parse.py
+++ b/deploy/config_parse.py
@@ -3,10 +3,12 @@ import yaml
import sys
from Cheetah.Template import Template
+
def init(file):
with open(file) as fd:
return yaml.load(fd)
+
def decorator(func):
def wrapter(s, seq):
host_list = s.get('hosts', [])
@@ -14,7 +16,7 @@ def decorator(func):
for host in host_list:
s = func(s, seq, host)
if not s:
- continue
+ continue
result.append(s)
if len(result) == 0:
return ""
@@ -22,18 +24,22 @@ def decorator(func):
return "\"" + seq.join(result) + "\""
return wrapter
+
@decorator
def hostnames(s, seq, host=None):
return host.get('name', '')
+
@decorator
def hostroles(s, seq, host=None):
return "%s=%s" % (host.get('name', ''), ','.join(host.get('roles', [])))
+
@decorator
def hostmacs(s, seq, host=None):
return host.get('mac', '')
+
def export_dha_file(s, dha_file, conf_dir, ofile):
env = {}
env.update(s)
@@ -54,18 +60,27 @@ def export_dha_file(s, dha_file, conf_dir, ofile):
for k, v in env.items():
os.system("echo 'export %s=${%s:-%s}' >> %s" % (k, k, v, ofile))
+
def export_reset_file(s, tmpl_dir, output_dir, output_file):
tmpl_file_name = s.get('POWER_TOOL', '')
if not tmpl_file_name:
return
- tmpl = Template(file=os.path.join(tmpl_dir,'power', tmpl_file_name + '.tmpl'), searchList=s)
+ tmpl = Template(
+ file=os.path.join(
+ tmpl_dir,
+ 'power',
+ tmpl_file_name +
+ '.tmpl'),
+ searchList=s)
reset_file_name = os.path.join(output_dir, tmpl_file_name + '.sh')
with open(reset_file_name, 'w') as f:
f.write(tmpl.respond())
- os.system("echo 'export POWER_MANAGE=%s' >> %s" % (reset_file_name, output_file))
+ os.system(
+ "echo 'export POWER_MANAGE=%s' >> %s" %
+ (reset_file_name, output_file))
if __name__ == "__main__":
if len(sys.argv) != 6:
@@ -80,8 +95,19 @@ if __name__ == "__main__":
data = init(dha_file)
- export_dha_file(data, dha_file, conf_dir, os.path.join(output_dir, output_file))
- export_reset_file(data, tmpl_dir, output_dir, os.path.join(output_dir, output_file))
+ export_dha_file(
+ data,
+ dha_file,
+ conf_dir,
+ os.path.join(
+ output_dir,
+ output_file))
+ export_reset_file(
+ data,
+ tmpl_dir,
+ output_dir,
+ os.path.join(
+ output_dir,
+ output_file))
sys.exit(0)
-