def mess_up_mysql(self): """Ruin MySQL's ability to restart.""" self.fix_mysql() # kill files cmd = """ssh %s 'sudo cp /dev/null /var/lib/mysql/ib_logfile%d'""" for index in range(2): full_cmd = cmd % (self.instance_local_id, index) print("RUNNING COMMAND: %s" % full_cmd) util.process(full_cmd)
def check_status_of_instance(): status, err = process("sudo vzctl status %s | awk '{print $5}'" % str(instance_info.local_id)) if string_in_list(status, ["running"]): self.assertEqual("running", status.strip()) return True else: return False
def find_mysql_procid_on_instance(local_id): """Returns the process id of MySql on an instance if running, or None.""" cmd = "sudo vzctl exec2 %d ps aux | grep /usr/sbin/mysqld " "| awk '{print $2}'" % local_id stdout, stderr = process(cmd) try: return int(stdout) except ValueError: return None
def get_vz_ip_for_device(instance_id, device): """Get the IP of the device within openvz for the specified instance""" ip, err = process("""sudo vzctl exec %(instance_id)s ifconfig %(device)s""" """ | awk '/inet addr/{gsub(/addr:/,"");print $2}'""" % locals()) if err: assert_false(True, err) else: return ip.strip()
def find_mysql_procid_on_instance(local_id): """Returns the process id of MySql on an instance if running, or None.""" cmd = "sudo vzctl exec2 %d ps aux | grep /usr/sbin/mysqld " \ "| awk '{print $2}'" % local_id stdout, stderr = process(cmd) try: return int(stdout) except ValueError: return None
def get_vz_ip_for_device(instance_id, device): """Get the IP of the device within openvz for the specified instance""" ip, err = process( """sudo vzctl exec %(instance_id)s ifconfig %(device)s""" """ | awk '/inet addr/{gsub(/addr:/,"");print $2}'""" % locals() ) if err: assert_false(True, err) else: return ip.strip()
def check_database(instance_id, dbname): """Checks if the name appears in an instance's list of databases.""" default_db = re.compile("[\w\n]*%s[\w\n]*" % dbname) dblist, err = process("sudo vzctl exec %s \"mysql -e 'show databases';\"" % instance_id) if err: raise RuntimeError(err) if default_db.match(dblist): return True else: return False
def check_process_alive_via_local_ovz(self): init_re = ("[\w\W\|\-\s\d,]*nova-guest " "--flagfile=/etc/nova/nova.conf nova[\W\w\s]*") init_proc = re.compile(init_re) guest_re = ("[\w\W\|\-\s]*/usr/bin/nova-guest " "--flagfile=/etc/nova/nova.conf[\W\w\s]*") guest_proc = re.compile(guest_re) apt = re.compile("[\w\W\|\-\s]*apt-get[\w\W\|\-\s]*") while True: guest_process, err = process("pstree -ap %s | grep nova-guest" % instance_info.pid) if not string_in_list(guest_process, ["nova-guest"]): time.sleep(10) else: if apt.match(guest_process): time.sleep(10) else: init = init_proc.match(guest_process) guest = guest_proc.match(guest_process) if init and guest: assert_true(True, init.group()) else: assert_false(False, guest_process) break
def get_the_pid(): out, err = process("pgrep init | vzpid - | awk '/%s/{print $1}'" % str(instance_info.local_id)) instance_info.pid = out.strip() return len(instance_info.pid) > 0
def execute(self, cmd): exe_cmd = "sudo vzctl exec %s '%s'" % (self.instance_local_id, cmd) print("RUNNING COMMAND: %s" % exe_cmd) return util.process(exe_cmd)
def execute(self, cmd): exe_cmd = "%s %s '%s'" % (tests.SSH_CMD, self.ip_address, cmd) print("RUNNING COMMAND: %s" % exe_cmd) return util.process(exe_cmd)
def fix_mysql(self): """Fix MySQL's ability to restart.""" if not FAKE_MODE: cmd = "ssh %s 'sudo rm /var/lib/mysql/ib_logfile%d'" for index in range(2): util.process(cmd % (self.instance_local_id, index))