def run_test(self): """ Start test, Creat a cgroup to create snapshot. """ modules = utils_cgroup.CgroupModules(self.cgroup_dir) modules.init(['cpuset']) self.cgroup = utils_cgroup.Cgroup('cpuset', None) self.cgroup.initialize(modules) self.cgroup_index = self.cgroup.mk_cgroup(cgroup=self.cgroup_name) # Before use the cpu, set it to be enable if self.cpu_status < 1: utils_misc.set_cpu_status(self.cpu_num, True) self.cgroup.set_property("cpuset.cpus", self.cpu_num, self.cgroup_index, check=False) self.cgroup.set_property("cpuset.mems", 0, self.cgroup_index, check=False) self.td0 = threading.Thread(target=self.cgroup.cgexec, args=(self.cgroup_name, "virsh", "dump %s %s" % (self.vm_name, self.dump_file))) self.td1 = None if self.twice_execute: self.td1 = threading.Thread(target=self.cgroup.cgexec, args=(self.cgroup_name, "virsh", "dump %s %s" % (self.vm_name, self.dump_file1))) self.td1.start() self.td0.start()
def recover(self, params=None): """ Recover test environment """ cpu_enable = True if self.cpu_status else False utils_misc.set_cpu_status(self.cpu_num, cpu_enable) tmp_c_file = params.get("tmp_c_file", "/tmp/test.c") tmp_exe_file = params.get("tmp_exe_file", "/tmp/test") if os.path.exists(tmp_c_file): os.remove(tmp_c_file) if os.path.exists(tmp_exe_file): os.remove(tmp_exe_file) if params.has_key('memory_pid'): pid = int(params.get('memory_pid')) utils_misc.safe_kill(pid, signal.SIGKILL) utils.run("swapon -a") if params.has_key('cpu_pid'): pid = int(params.get('cpu_pid')) utils_misc.safe_kill(pid, signal.SIGKILL) tmp_sh_file = params.get("tmp_sh_file") if os.path.exists(tmp_sh_file): os.remove(tmp_sh_file) virsh.destroy(self.vm_name) if len(self.snp_list) < len(self.current_snp_list): self.diff_snp_list = list(set(self.current_snp_list) - set(self.snp_list)) for item in self.diff_snp_list: virsh.snapshot_delete(self.vm_name, item) remove_machine_cgroup()
def recover(self, params=None): """ Recover test environment """ cpu_enable = True if self.cpu_status else False utils_misc.set_cpu_status(self.cpu_num, cpu_enable) tmp_c_file = params.get("tmp_c_file", "/tmp/test.c") tmp_exe_file = params.get("tmp_exe_file", "/tmp/test") if os.path.exists(tmp_c_file): os.remove(tmp_c_file) if os.path.exists(tmp_exe_file): os.remove(tmp_exe_file) if 'memory_pid' in params: pid = int(params.get('memory_pid')) utils_misc.safe_kill(pid, signal.SIGKILL) process.run("swapon -a", shell=True) if 'cpu_pid' in params: pid = int(params.get('cpu_pid')) utils_misc.safe_kill(pid, signal.SIGKILL) tmp_sh_file = params.get("tmp_sh_file") if os.path.exists(tmp_sh_file): os.remove(tmp_sh_file) virsh.destroy(self.vm_name) if len(self.snp_list) < len(self.current_snp_list): self.diff_snp_list = list(set(self.current_snp_list) - set(self.snp_list)) for item in self.diff_snp_list: virsh.snapshot_delete(self.vm_name, item) remove_machine_cgroup()
def cpu_lack(params): """ Disable assigned cpu. """ cpu_num = int(params.get("cpu_num", "0")) if not utils_misc.set_cpu_status(cpu_num, False): raise error.TestError("Set cpu '%s' failed!" % cpu_num)
def cpu_lack(test, params): """ Disable assigned cpu. """ cpu_num = int(params.get("cpu_num", "0")) if not utils_misc.set_cpu_status(cpu_num, False): test.error("Set cpu '%s' failed!" % cpu_num)
def recover(self, params): """ Recover test environment """ abnormal_type = params.get("abnormal_type") cpu_enable = True if self.cpu_status else False utils_misc.set_cpu_status(self.cpu_num, cpu_enable) if virsh.domain_exists(self.vm_new_name): virsh.remove_domain(self.vm_new_name) if os.path.exists(self.new_image_file): os.remove(self.new_image_file) if self.twice_execute: if virsh.domain_exists(self.vm_new_name1): virsh.remove_domain(self.vm_new_name1) if os.path.exists(self.new_image_file1): os.remove(self.new_image_file1) if abnormal_type == "memory_lack": if params.has_key('memory_pid'): pid = params.get('memory_pid') if isinstance(pid,str): pid = int(pid) utils_misc.safe_kill(pid, signal.SIGKILL) utils.run("swapon -a") tmp_c_file = params.get("tmp_c_file", "/tmp/test.c") tmp_exe_file = params.get("tmp_exe_file", "/tmp/test") if os.path.exists(tmp_c_file): os.remove(tmp_c_file) if os.path.exists(tmp_exe_file): os.remove(tmp_exe_file) elif abnormal_type in ["disk_lack", ""]: if self.selinux_enforcing: utils_selinux.set_status("enforcing") tmp_file = os.path.join(self.mount_dir, "tmp") if os.path.exists(tmp_file): os.remove(tmp_file) # Sometimes one umount action is not enough utils_misc.wait_for(lambda: utils_misc.umount(self.partition, self.mount_dir, self.fs_type), 120) if self.iscsi_dev: self.iscsi_dev.cleanup() os.rmdir(self.mount_dir) elif abnormal_type == "cpu_lack": os.system("cat /sys/fs/cgroup/cpuset/cpuset.cpus > /sys/fs/cgroup/cpuset/machine.slice/cpuset.cpus") remove_machine_cgroup()
def recover(self, params=None): """ Recover test environment """ cpu_enable = True if self.cpu_status else False utils_misc.set_cpu_status(self.cpu_num, cpu_enable) virsh.destroy(self.vm_name) if params.has_key('cpu_pid'): pid = int(params.get('cpu_pid')) utils_misc.safe_kill(pid, signal.SIGKILL) tmp_sh_file = params.get("tmp_sh_file") if os.path.exists(tmp_sh_file): os.remove(tmp_sh_file) if os.path.exists(self.dump_file): os.remove(self.dump_file) if os.path.exists(self.dump_file1): os.remove(self.dump_file1) remove_machine_cgroup()
def recover(self, params=None): """ Recover test environment """ cpu_enable = True if self.cpu_status else False utils_misc.set_cpu_status(self.cpu_num, cpu_enable) virsh.destroy(self.vm_name) if 'cpu_pid' in params: pid = int(params.get('cpu_pid')) utils_misc.safe_kill(pid, signal.SIGKILL) tmp_sh_file = params.get("tmp_sh_file") if os.path.exists(tmp_sh_file): os.remove(tmp_sh_file) if os.path.exists(self.dump_file): os.remove(self.dump_file) if os.path.exists(self.dump_file1): os.remove(self.dump_file1) remove_machine_cgroup()
def run_test(self): """ Start test, clone a guest in a cgroup """ if virsh.domain_exists(self.vm_new_name): raise error.TestNAError("'%s' already exists! Please" " select another domain name!" % self.vm_new_name) if os.path.exists(self.new_image_file): os.remove(self.new_image_file) modules = utils_cgroup.CgroupModules(self.cgroup_dir) modules.init(['cpuset']) self.cgroup = utils_cgroup.Cgroup('cpuset', None) self.cgroup.initialize(modules) self.cgroup_index = self.cgroup.mk_cgroup(cgroup=self.cgroup_name) # Before use the cpu, set it to be enable if self.cpu_status < 1: utils_misc.set_cpu_status(self.cpu_num, True) self.cgroup.set_property("cpuset.cpus", self.cpu_num, self.cgroup_index, check=False) self.cgroup.set_property("cpuset.mems", 0, self.cgroup_index, check=False) self.td0 = threading.Thread( target=self.cgroup.cgexec, args=(self.cgroup_name, "virt-clone", "-o %s -n %s --force --file %s" % (self.vm_name, self.vm_new_name, self.new_image_file))) self.td1 = None if self.twice_execute: self.vm_new_name1 = self.vm_new_name + "1" self.new_image_file1 = self.new_image_file + "1" self.td1 = threading.Thread( target=self.cgroup.cgexec, args=(self.cgroup_name, "virt-clone", "-o %s -n %s --force --file %s" % (self.vm_name, self.vm_new_name1, self.new_image_file1))) self.td1.start() self.td0.start() # Wait for virt-clone has been started time.sleep(30)
def recover(self, params): """ Recover test environment """ abnormal_type = params.get("abnormal_type") cpu_enable = True if self.cpu_status else False utils_misc.set_cpu_status(self.cpu_num, cpu_enable) if virsh.domain_exists(self.vm_new_name): virsh.remove_domain(self.vm_new_name) if os.path.exists(self.new_image_file): os.remove(self.new_image_file) if self.twice_execute: if virsh.domain_exists(self.vm_new_name1): virsh.remove_domain(self.vm_new_name1) if os.path.exists(self.new_image_file1): os.remove(self.new_image_file1) if abnormal_type == "memory_lack": if 'memory_pid' in params: pid = params.get('memory_pid') utils_misc.safe_kill(pid, signal.SIGKILL) process.run("swapon -a", shell=True) tmp_c_file = params.get("tmp_c_file", "/tmp/test.c") tmp_exe_file = params.get("tmp_exe_file", "/tmp/test") if os.path.exists(tmp_c_file): os.remove(tmp_c_file) if os.path.exists(tmp_exe_file): os.remove(tmp_exe_file) elif abnormal_type in ["disk_lack", ""]: if self.selinux_enforcing: utils_selinux.set_status("enforcing") tmp_file = os.path.join(self.mount_dir, "tmp") if os.path.exists(tmp_file): os.remove(tmp_file) # Sometimes one umount action is not enough utils_misc.wait_for(lambda: utils_misc.umount(self.partition, self.mount_dir, self.fs_type), 120) if self.iscsi_dev: self.iscsi_dev.cleanup() os.rmdir(self.mount_dir) remove_machine_cgroup()
def run_test(self): """ Start test, clone a guest in a cgroup """ if virsh.domain_exists(self.vm_new_name): self.test.cancel("'%s' already exists! Please" " select another domain name!" % self.vm_new_name) if os.path.exists(self.new_image_file): os.remove(self.new_image_file) modules = utils_cgroup.CgroupModules(self.cgroup_dir) modules.init(['cpuset']) self.cgroup = utils_cgroup.Cgroup('cpuset', None) self.cgroup.initialize(modules) self.cgroup_index = self.cgroup.mk_cgroup(cgroup=self.cgroup_name) # Before use the cpu, set it to be enable if self.cpu_status < 1: utils_misc.set_cpu_status(self.cpu_num, True) self.cgroup.set_property("cpuset.cpus", self.cpu_num, self.cgroup_index, check=False) self.cgroup.set_property("cpuset.mems", 0, self.cgroup_index, check=False) self.td0 = threading.Thread(target=self.cgroup.cgexec, args=(self.cgroup_name, "virt-clone", "-o %s -n %s --force --file %s" % (self.vm_name, self.vm_new_name, self.new_image_file))) self.td1 = None if self.twice_execute: self.vm_new_name1 = self.vm_new_name + "1" self.new_image_file1 = self.new_image_file + "1" self.td1 = threading.Thread(target=self.cgroup.cgexec, args=(self.cgroup_name, "virt-clone", "-o %s -n %s --force --file %s" % (self.vm_name, self.vm_new_name1, self.new_image_file1))) self.td1.start() self.td0.start() # Wait for virt-clone has been started time.sleep(30)