def run_test(self): """ Start test, Create 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 not self.cpu_status: cpu.online(self.cpu_num) 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 """ if self.cpu_status: cpu.offline(self.cpu_num) else: cpu.online(self.cpu_num) 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 recover(self, params): """ Recover test environment """ abnormal_type = params.get("abnormal_type") if self.cpu_status: cpu.offline(self.cpu_num) else: cpu.online(self.cpu_num) 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 not self.cpu_status: cpu.online(self.cpu_num) 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=None): """ Recover test environment """ if self.cpu_status: cpu.offline(self.cpu_num) else: cpu.online(self.cpu_num) 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()