Merge "Fix upgrade instance test"

This commit is contained in:
Zuul 2020-06-05 02:57:09 +00:00 committed by Gerrit Code Review
commit 8458a64489
7 changed files with 74 additions and 31 deletions

View File

@ -60,6 +60,16 @@ class TroveClient(rest_client.RestClient):
else:
raise
def force_delete_instance(self, id):
headers = {"Content-Type": "application/json"}
body = {"reset_status": {}}
resp, _ = self.post(f'/instances/{id}/action', json.dumps(body),
headers=headers)
self.expected_success(202, resp.status)
resp, _ = self.delete(f'/instances/{id}')
self.expected_success(202, resp.status)
def create_resource(self, obj, req_body, extra_headers={},
expected_status_code=200):
headers = {"Content-Type": "application/json"}

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_log import log as logging
from oslo_service import loopingcall
from oslo_utils import netutils
from oslo_utils import uuidutils
import tenacity
@ -258,9 +259,6 @@ class BaseTroveTest(test.BaseTestCase):
def wait_for_instance_status(cls, id,
expected_status=["HEALTHY", "ACTIVE"],
need_delete=False):
if type(expected_status) != list:
expected_status = [expected_status]
def _wait():
try:
res = cls.client.get_resource("instances", id)
@ -284,8 +282,11 @@ class BaseTroveTest(test.BaseTestCase):
message=message)
raise exceptions.UnexpectedResponseCode(message)
if type(expected_status) != list:
expected_status = [expected_status]
if need_delete:
cls.client.delete_resource("instances", id, ignore_notfound=True)
cls.admin_client.force_delete_instance(id)
timer = loopingcall.FixedIntervalWithTimeoutLoopingCall(_wait)
try:
@ -299,3 +300,27 @@ class BaseTroveTest(test.BaseTestCase):
message = '({caller}) {message}'.format(caller=caller,
message=message)
raise exceptions.TimeoutException(message)
def get_instance_ip(self, instance=None):
if not instance:
instance = self.client.get_resource(
"instances", self.instance_id)['instance']
# TODO(lxkong): IPv6 needs to be tested.
v4_ip = None
if 'addresses' in instance:
for addr_info in instance['addresses']:
if addr_info['type'] == 'private':
v4_ip = addr_info['address']
if addr_info['type'] == 'public':
v4_ip = addr_info['address']
break
else:
ips = instance.get('ip', [])
for ip in ips:
if netutils.is_valid_ipv4(ip):
v4_ip = ip
self.assertIsNotNone(v4_ip)
return v4_ip

View File

@ -1,4 +1,4 @@
# Copyright 2019 Catalyst Cloud Ltd.
# Copyright 2020 Catalyst Cloud
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -17,10 +17,23 @@ from oslo_log import log as logging
from tempest.lib import decorators
from trove_tempest_plugin.tests import base as trove_base
from trove_tempest_plugin.tests import utils
LOG = logging.getLogger(__name__)
def get_db_version(ip, username='test_user', password='password'):
db_engine = utils.LocalSqlClient.init_engine(ip, username, password)
db_client = utils.LocalSqlClient(db_engine)
LOG.info('Trying to access the database %s', ip)
with db_client:
cmd = "SELECT @@GLOBAL.innodb_version;"
ret = db_client.execute(cmd)
return ret.first()[0]
class TestInstanceActionsBase(trove_base.BaseTroveTest):
@decorators.idempotent_id("be6dd514-27d6-11ea-a56a-98f2b3cc23a0")
def test_instance_upgrade(self):
@ -45,3 +58,9 @@ class TestInstanceActionsBase(trove_base.BaseTroveTest):
time.sleep(3)
self.wait_for_instance_status(self.instance_id)
ip = self.get_instance_ip(res["instance"])
time.sleep(3)
actual = get_db_version(ip)
self.assertEqual(actual, new_version)

View File

@ -14,7 +14,6 @@
import time
from oslo_log import log as logging
from oslo_utils import netutils
from tempest.lib import decorators
from trove_tempest_plugin.tests import base as trove_base
@ -36,25 +35,6 @@ class TestInstanceBasicMySQLBase(trove_base.BaseTroveTest):
@decorators.idempotent_id("40cf38ce-cfbf-11e9-8760-1458d058cfb2")
def test_database_access(self):
instance = self.client.get_resource(
"instances", self.instance_id)['instance']
# TODO(lxkong): IPv6 needs to be tested.
v4_ip = None
if 'addresses' in instance:
for addr_info in instance['addresses']:
if addr_info['type'] == 'private':
v4_ip = addr_info['address']
if addr_info['type'] == 'public':
v4_ip = addr_info['address']
break
else:
ips = instance.get('ip', [])
for ip in ips:
if netutils.is_valid_ipv4(ip):
v4_ip = ip
self.assertIsNotNone(v4_ip)
v4_ip = self.get_instance_ip()
time.sleep(5)
self._access_db(v4_ip)

View File

@ -1,4 +1,4 @@
# Copyright 2019 Catalyst Cloud Ltd.
# Copyright 2020 Catalyst Cloud
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -11,8 +11,13 @@
# 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 trove_tempest_plugin.tests.api import base
from trove_tempest_plugin.tests.scenario import base_actions
class TestInstanceActionsMySQL(base.TestInstanceActionsBase):
class TestInstanceActionsMySQL(base_actions.TestInstanceActionsBase):
datastore = 'mysql'
class TestInstanceActionsMariaDB(base_actions.TestInstanceActionsBase):
datastore = 'mariadb'

View File

@ -11,8 +11,12 @@
# 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 trove_tempest_plugin.tests.scenario import base
from trove_tempest_plugin.tests.scenario import base_basic
class TestInstanceBasicMySQL(base.TestInstanceBasicMySQLBase):
class TestInstanceBasicMySQL(base_basic.TestInstanceBasicMySQLBase):
datastore = 'mysql'
class TestInstanceBasicMariaDB(base_basic.TestInstanceBasicMySQLBase):
datastore = 'mariadb'