Merge "create a test adapter for entering an instance and executing a cmd"

This commit is contained in:
Jenkins 2013-01-21 20:28:44 +00:00 committed by Gerrit Code Review
commit b97fd392c8
3 changed files with 70 additions and 20 deletions

View File

@ -31,6 +31,7 @@ from reddwarf.tests.api.instances import GROUP_START
from reddwarf.tests.api.instances import instance_info
from reddwarf.tests.api.instances import assert_unprocessable
from reddwarf.tests import util
from reddwarf.tests.util.server_connection import create_server_connection
from reddwarf.tests.util import poll_until
from reddwarf.tests.config import CONFIG
from reddwarf.tests.util import LocalSqlClient
@ -142,7 +143,14 @@ class ActionTestBase(object):
check.equal(instance.status, "ACTIVE")
def find_mysql_proc_on_instance(self):
return util.find_mysql_procid_on_instance(self.instance_address)
server = create_server_connection(self.instance_id)
cmd = "ps aux | grep /usr/sbin/mysqld " \
"| awk '{print $2}'"
stdout, stderr = server.execute(cmd)
try:
return int(stdout)
except ValueError:
return None
def log_current_users(self):
users = self.dbaas.users.list(self.instance_id)
@ -211,20 +219,18 @@ class RebootTestBase(ActionTestBase):
def mess_up_mysql(self):
"""Ruin MySQL's ability to restart."""
self.fix_mysql() # kill files
cmd = """%s %s 'sudo cp /dev/null /var/lib/mysql/ib_logfile%d'"""
server = create_server_connection(self.instance_id)
cmd = "sudo cp /dev/null /var/lib/mysql/ib_logfile%d"
for index in range(2):
full_cmd = cmd % (tests.SSH_CMD, self.instance_address, index)
print("RUNNING COMMAND: %s" % full_cmd)
util.process(full_cmd)
server.execute(cmd % index)
def fix_mysql(self):
"""Fix MySQL's ability to restart."""
if not FAKE_MODE:
cmd = "%s %s 'sudo rm /var/lib/mysql/ib_logfile%d'"
server = create_server_connection(self.instance_id)
cmd = "sudo rm /var/lib/mysql/ib_logfile%d"
for index in range(2):
util.process(cmd % (tests.SSH_CMD,
self.instance_address,
index))
server.execute(cmd % index)
def wait_for_failure_status(self):
"""Wait until status becomes running."""

View File

@ -231,17 +231,6 @@ def mysql_connection():
return import_object(cls)()
def find_mysql_procid_on_instance(ip_address):
"""Returns the process id of MySql on an instance if running, or None."""
cmd = "%s %s ps aux | grep /usr/sbin/mysqld " \
"| awk '{print $2}'" % (tests.SSH_CMD, ip_address)
stdout, stderr = process(cmd)
try:
return int(stdout)
except ValueError:
return None
class MySqlConnection(object):
def assert_fails(self, user_name, password, ip):

View File

@ -0,0 +1,55 @@
# Copyright 2013 OpenStack LLC.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from reddwarf import tests
from reddwarf.tests.config import CONFIG
from reddwarf.tests import util
from reddwarf.tests.util.users import Requirements
def create_server_connection(instance_id):
if util.test_config.use_local_ovz:
return OpenVZServerConnection(instance_id)
return ServerSSHConnection(instance_id)
class ServerSSHConnection(object):
def __init__(self, instance_id):
self.instance_id = instance_id
req_admin = Requirements(is_admin=True)
self.user = util.test_config.users.find_user(req_admin)
self.dbaas_admin = util.create_dbaas_client(self.user)
self.instance = self.dbaas_admin.management.show(self.instance_id)
self.ip_address = self.instance.ip[0]
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)
class OpenVZServerConnection(object):
def __init__(self, instance_id):
self.instance_id = instance_id
req_admin = Requirements(is_admin=True)
self.user = util.test_config.users.find_user(req_admin)
self.dbaas_admin = util.create_dbaas_client(self.user)
self.instance = self.dbaas_admin.management.show(self.instance_id)
self.instance_local_id = self.instance.server["local_id"]
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)