11 exec_cmd = common.exec_cmd
15 class ConfigureSettings(object):
17 def __init__(self, yaml_config_dir, env_id):
18 self.yaml_config_dir = yaml_config_dir
21 def download_settings(self):
22 exec_cmd('fuel --env %s settings --download' % self.env_id)
24 def upload_settings(self):
25 exec_cmd('fuel --env %s settings --upload' % self.env_id)
28 def config_settings(self):
29 self.download_settings()
30 self.modify_settings()
31 self.upload_settings()
34 def fix_console_speed(data):
35 # First remove all console= from the kernel cmdline
36 cmdline = data["editable"]["kernel_params"]["kernel"]["value"]
37 pat = re.compile(r"console=[\w,]+\s+")
40 cmdline, repl = pat.subn("", cmdline)
42 # Then add the console info we want
43 cmdline = re.sub(r"^", "console=tty0 console=ttyS0,115200 ", cmdline)
44 data["editable"]["kernel_params"]["kernel"]["value"] = cmdline
46 # Initialize kernel audit
47 def initialize_kernel_audit(data):
48 cmdline = data["editable"]["kernel_params"]["kernel"]["value"]
49 cmdline = "audit=1 " + cmdline
50 data["editable"]["kernel_params"]["kernel"]["value"] = cmdline
52 # Add crashkernel parameter to boot parameters. W/o this we can't
53 # make crash dumps after initial deploy. Standard grub setup will add
54 # crashkernel= options - with bad values but that is another issue - but
55 # that only enables crash dumps after first reboot
56 def add_crashkernel_support(data):
57 cmdline = data["editable"]["kernel_params"]["kernel"]["value"]
58 cmdline += " crashkernel=256M"
59 data["editable"]["kernel_params"]["kernel"]["value"] = cmdline
62 def modify_settings(self):
64 filename = "%s/settings_%d.yaml" % (self.yaml_config_dir, self.env_id)
65 if not os.path.isfile(filename):
66 err("Failed to find %s\n" % filename)
68 with io.open(filename) as stream:
69 data = yaml.load(stream)
71 self.fix_console_speed(data)
73 self.initialize_kernel_audit(data)
75 self.add_crashkernel_support(data)
77 # Make sure we have the correct libvirt type
78 data["editable"]["common"]["libvirt_type"]["value"] = "kvm"
81 # Save the settings into the file from which we loaded them
82 with io.open(filename, "w") as stream:
83 yaml.dump(data, stream, default_flow_style=False)