Remove RefreshQuotaUsages

This feature was replaced upstream in OSP 12 (nova 16.0.0) [1] and the
test no longer works. The test would not make sense against the new
feature so simply remove it.

We are able to remove some utility methods that were only used by this
test. These are not used by anything else and should really be rewritten
if we introduce new tests that require these in the future.

[1] https://review.openstack.org/#/c/446243/

Change-Id: I1e6fa04503677db60d1b5e2c284ea03b834144fa
This commit is contained in:
Stephen Finucane 2018-01-10 17:23:12 +00:00 committed by Gerrit Code Review
parent 05b1c38c69
commit 5cc3c664b4
2 changed files with 3 additions and 161 deletions

View File

@ -17,18 +17,17 @@ try:
from shlex import quote
except ImportError:
from pipes import quote
import urlparse
from tempest import config
from tempest.lib.common import ssh
from tempest.lib import exceptions as lib_exc
CONF = config.CONF
class SSHClient(object):
"""A client to execute remote commands, based on tempest.lib.common.ssh."""
_prefix_command = '/bin/bash -c'
def __init__(self):
@ -80,6 +79,8 @@ class SSHClient(object):
class VirshXMLClient(SSHClient):
"""A client to obtain libvirt XML from a remote host."""
def __init__(self, hostname=None):
super(VirshXMLClient, self).__init__()
self.host = hostname
@ -92,61 +93,3 @@ class VirshXMLClient(SSHClient):
with ctx:
command = "virsh dumpxml {}".format(domain)
return self.execute(self.host, command)
class MySQLClient(SSHClient):
def __init__(self):
super(MySQLClient, self).__init__()
# the nova conf file may contain a private IP.
# let's just assume the db is available on the same node.
self.host = CONF.whitebox.target_controller
# discover db connection params by accessing nova.conf remotely
ssh_client = SSHClient()
if CONF.whitebox.containers:
ctx = ssh_client.container_command('nova_api')
else:
ctx = ssh_client.sudo_command()
with ctx:
cmd = """python -c "import nova.conf;
nova.conf.CONF(['--config-file', '/etc/nova/nova.conf']);
print(nova.conf.CONF.database.connection)"
"""
connection = ssh_client.execute(self.host, cmd).strip()
p = urlparse.urlparse(connection)
self.username = p.username
self.password = p.password
self.database_host = p.hostname
self.database = p.path.lstrip('/')
# if using a deployment with cells, we can safely assume that there's
# only a single cell. nova_cell0 is a special "cell" database used by
# the super-conductor so we select the first real cell
# Refer to https://docs.openstack.org/nova/latest/user/cells.html for
# more information.
if self.database == 'nova_cell0':
self.database = 'nova_cell1'
def execute_command(self, command):
sql_cmd = "mysql -u{} -p{} -h{} -e '{}' {}".format(
self.username,
self.password,
self.database_host,
command,
self.database)
return self.execute(self.host, sql_cmd)
class NovaManageClient(SSHClient):
def __init__(self):
super(NovaManageClient, self).__init__()
self.hostname = CONF.whitebox.target_controller
def execute_command(self, command):
if CONF.whitebox.containers:
ctx = self.container_command('nova_api')
else:
ctx = self.sudo_command()
with ctx:
nova_cmd = "nova-manage {}".format(command)
return self.execute(self.hostname, nova_cmd)

View File

@ -1,101 +0,0 @@
# Copyright 2016 Red Hat
# 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.
#
# Parameters required in etc/tempest.conf
# [whitebox]
# target_controller=
# target_ssh_user=
# target_private_key_path=
from oslo_log import log as logging
from tempest.common import utils
from tempest import config
from whitebox_tempest_plugin.services import clients
from whitebox_tempest_plugin.tests.scenario import base
CONF = config.CONF
LOG = logging.getLogger(__name__)
class RefreshQuotaUsages(base.BaseTest):
@classmethod
def resource_setup(cls):
super(RefreshQuotaUsages, cls).resource_setup()
cls.dbclient = clients.MySQLClient()
cls.nova_manage_client = clients.NovaManageClient()
def _compare_resource_count(self, source1, source2):
for quota in source1.split("\n"):
if quota not in source2:
LOG.info('Quota %r not found in %r', quota, source2)
return False
return True
def _verify_refresh_quota_usages(self, server_id):
# Retrieve user-id and project-id for instances created
dbcommand = """
SELECT user_id,project_id
FROM instances
WHERE uuid = "{}"
""".format(server_id)
data = self.dbclient.execute_command(dbcommand)
# Parsing the output of the mysql cli. Not pretty.
user_id, project_id = data.split('\n')[1].split("\t")
# Retrieve the resource count from quota usages table
dbcommand_select = """
SELECT resource,in_use
FROM quota_usages
WHERE project_id = "{}"
""".format(project_id)
data_orig = self.dbclient.execute_command(dbcommand_select)
# Update quota usage table to fake values to mimic out of
# sync scenario
dbcommand_update = """
UPDATE quota_usages
SET in_use=99
WHERE project_id = "{}"
""".format(project_id)
data = self.dbclient.execute_command(dbcommand_update)
# Verify that update work and quota usage table is different
# from original state
data_fake = self.dbclient.execute_command(dbcommand_select)
compare = self._compare_resource_count(data_orig, data_fake)
self.assertFalse(compare, 'Quota usage table was not updated')
# Trigger quota refresh using nova-manage command.
cmd = ('project quota_usage_refresh --project %s --user %s' %
(project_id, user_id))
self.nova_manage_client.execute_command(cmd)
# Retrieve resource usage count from quota usage table
data_synced = self.dbclient.execute_command(dbcommand_select)
# Verify that resource usage is in sync now
compare = self._compare_resource_count(data_orig, data_synced)
self.assertTrue(compare, 'Error in refreshing via nova quota_usages')
@utils.services('compute')
def test_refresh_quota_usages(self):
for _ in range(2):
server = self.create_server()
self._verify_refresh_quota_usages(server['id'])