def cgconfig_file_modify(cgconfig_file, controller_list, dic_cgroup_property, cgroup_cls): """ Modify /etc/cgconfig.conf file to control cgroup configuration """ controllers = ','.join(controller_list) cmd = "vi %s" % cgconfig_file try: session = pexpect.spawn(cmd) time.sleep(1) session.send('i') time.sleep(1) # hierarchy part session.sendline('mount {') for controller in controller_list: session.sendline("""%s = "%s";""" % (controller, cgroup_cls.root)) time.sleep(1) session.sendline('}') time.sleep(1) session.send('\x1b') time.sleep(1) session.send('o') time.sleep(1) # cgroup part for cgroup in dic_cgroup_property: session.sendline('group %s {' % cgroup) time.sleep(1) dic_controller_property = dic_cgroup_property.get(cgroup) for controller in dic_controller_property: session.sendline('%s {' % controller) time.sleep(1) dic_property = dic_controller_property.get(controller) if dic_property is None or dic_property == '': session.sendline('}') time.sleep(1) continue for property in dic_property: session.sendline("""%s = "%s";""" % (property, dic_property.get(property))) time.sleep(1) session.sendline('}') time.sleep(1) session.sendline('}') session.send('\x1b') time.sleep(1) session.send('ZZ') time.sleep(1) session.close() except Exception, detail: raise error.TestFail("Edit cgconfig file failed!\n%s" % detail)
def check_host(host, console_binary): """Check hosts for common errors and return the status. Args: host: string, the console host identifier console_binary: string, location of the conmux console binary Returns: int, 0: Machine state is good int, 1: Machine state is bad int, 2: Machine state is unknown """ RESPONSES = [ host + ' login:'******'ENOENT entry not found', 'login:'******'Connection refused', '<<<NOT CONNECTED>>>', 'Authentication failure', 'Give root password for maintenance', ] cmd = '%s %s' % (console_binary, host) shell = pexpect.spawn(cmd) shell.send('\r\n') shell.send('\r\n') shell.send('\r\n') try: # May need to increase the timeout but good so far response = shell.expect(RESPONSES, 1) except pexpect.TIMEOUT: shell.sendline('~$') shell.expect('>') shell.sendline('quit') return 1 except pexpect.EOF: # unknown error shell.sendline('~$') shell.expect('>') shell.sendline('quit') return 2 # TODO: Change actions based on what server returned if response == 0: # OK response return 0 else: return 1
def check_host(host, console_binary): """Check hosts for common errors and return the status. Args: host: string, the console host identifier console_binary: string, location of the conmux console binary Returns: int, 0: Machine state is good int, 1: Machine state is bad int, 2: Machine state is unknown """ RESPONSES = [host + ' login:'******'ENOENT entry not found', 'login:'******'Connection refused', '<<<NOT CONNECTED>>>', 'Authentication failure', 'Give root password for maintenance', ] cmd = '%s %s' % (console_binary, host) shell = pexpect.spawn(cmd) shell.send('\r\n') shell.send('\r\n') shell.send('\r\n') try: # May need to increase the timeout but good so far response = shell.expect(RESPONSES, 1) except pexpect.TIMEOUT: shell.sendline('~$') shell.expect('>') shell.sendline('quit') return 1 except pexpect.EOF: # unknown error shell.sendline('~$') shell.expect('>') shell.sendline('quit') return 2 # TODO: Change actions based on what server returned if response == 0: # OK response return 0 else: return 1