Merge ~gavin.lin/cc-lab-manager:more-agent-config into cc-lab-manager:master

Proposed by Gavin Lin
Status: Merged
Merge reported by: Gavin Lin
Merged at revision: 30653bc3ecdc81f903cfa4ff81214b36111720c6
Proposed branch: ~gavin.lin/cc-lab-manager:more-agent-config
Merge into: cc-lab-manager:master
Diff against target: 75 lines (+33/-14)
1 file modified
cc_lab_manager/gen_config/gen_agent_tf_config.py (+33/-14)
Reviewer Review Type Date Requested Status
Devices Certification Bot Needs Fixing
Kevin Yeh Approve
Review via email: mp+423416@code.launchpad.net

Description of the change

Support configs for noprovision type.
Let's land this first and continue working on naming rule.

To post a comment you must log in.
Revision history for this message
Kevin Yeh (kevinyeh) wrote :

lgtm +1

review: Approve
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

I tried to merge it but there are some problems. Typically you want to merge or rebase and try again.

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cc_lab_manager/gen_config/gen_agent_tf_config.py b/cc_lab_manager/gen_config/gen_agent_tf_config.py
2index 00bc37f..e386440 100644
3--- a/cc_lab_manager/gen_config/gen_agent_tf_config.py
4+++ b/cc_lab_manager/gen_config/gen_agent_tf_config.py
5@@ -4,6 +4,8 @@ import yaml
6 import argparse
7 import re
8
9+from cc_lab_manager.cc_lab_manager_maptable import reboot_script_maptable
10+
11 agent_config = {"device_ip": None,
12 "secure_id": None,
13 "node_id": None,
14@@ -86,9 +88,11 @@ def close_db(db):
15 def read_data_from_db(cursor):
16
17 col_in_c3 = ["CID","Lab","IP","MAAS_Node_ID", "Provision",
18- "CanonicalLabel","SecureID", "Customized_agent_config", "CID"]
19+ "Power", "PDU_IP", "PDU_Outlet", "Controller_IP",
20+ "CanonicalLabel","SecureID", "Customized_agent_config",
21+ "CID"]
22
23- sqlcmd = 'select {},{},{},{},{},{},{},{} from lab_hw \
24+ sqlcmd = 'select {},{},{},{},{},{},{},{},{},{},{},{} from lab_hw \
25 where CID not like \'dummy-%\' \
26 order by {} ASC'.format(*col_in_c3)
27 cursor.execute(sqlcmd)
28@@ -125,20 +129,35 @@ def generate_agent_config(db_machine_list, cfg_path):
29 agent_conf["device_ip"] = ip
30 agent_conf["env"]["HEXR_DEVICE_SECURE_ID"] = secure_id
31 agent_conf["env"]["DEVICE_IP"] = ip
32+
33+ agent_conf["reboot_script"] = []
34+ power_template = {'PDU_IP' : machine["PDU_IP"],
35+ 'PDU_Outlet' : machine["PDU_Outlet"]}
36+ try:
37+ reboot_script_template = reboot_script_maptable[machine["Power"]]
38+
39+ for line in reboot_script_template:
40+ agent_conf["reboot_script"].append(line.format(**power_template))
41+ print(agent_conf["reboot_script"])
42+ except:
43+ print('No power template')
44+
45+
46+ try:
47+ provision = provision_type[machine["Provision"]]
48+ except:
49+ print("Unknown provision type for {}".format(machine['cid']))
50+ continue
51
52+ empty_keys = []
53+ for key in agent_conf:
54+ if agent_conf[key] == None:
55+ empty_keys.append(key)
56+ for key in empty_keys:
57+ agent_conf.pop(key)
58+
59 with open(os.path.join(cfg_path, 'data-' + machine['lab'].lower(), agent_name, 'default.yaml'), "w+") as f:
60- for key in agent_config:
61- if agent_conf[key] == None:
62- continue
63- if key == "env":
64- f.write(key+" :\n")
65- for env_key in agent_config["env"]:
66- # We are using the same set of APs currently, we will need this commented section if we need more sets
67- # if "SSID" in env_key:
68- # agent_conf["env"][env_key] += machine["lab"][-1]
69- f.write(" {key}: {value}\n".format(key=env_key,value=agent_conf["env"][env_key]))
70- else:
71- f.write("{key}: {value}\n".format(key=key,value=agent_conf[key]))
72+ yaml.dump(agent_conf, f, default_flow_style=False, encoding='utf-8', allow_unicode=True, sort_keys=False)
73
74
75 def generate_tf_config(db_machine_list, cfg_path):

Subscribers

People subscribed via source and target branches

to all changes: