Merge "Move functional test to dsvm and remove pifpaf"

This commit is contained in:
Zuul 2024-01-30 15:54:17 +00:00 committed by Gerrit Code Review
commit 11c37391ea
7 changed files with 123 additions and 24 deletions

View File

@ -1,3 +1,3 @@
[DEFAULT]
test_path=./aodhclient/tests
test_path=./aodhclient/tests/unit
top_dir=./

View File

@ -1,5 +1,38 @@
- job:
name: aodhclient-dsvm-functional
parent: devstack-tox-functional
description: |
Devstack-based functional tests for aodhclient.
required-projects:
- openstack/python-aodhclient
- openstack/aodh
# We neeed ceilometer's devstack plugin to install gnocchi
- openstack/ceilometer
- gnocchixyz/gnocchi
timeout: 4200
vars:
devstack_localrc:
USE_PYTHON3: True
GLOBAL_VENV: False
CEILOMETER_BACKENDS: "gnocchi"
devstack_plugins:
aodh: https://opendev.org/openstack/aodh
ceilometer: https://opendev.org/openstack/ceilometer
- project:
templates:
- openstack-python3-jobs
- publish-openstack-docs-pti
- openstackclient-plugin-jobs
check:
jobs:
- aodhclient-dsvm-functional:
irrelevant-files: &ac-irrelevant-files
- ^(test-|)requirements.txt$
- ^setup.cfg$
- ^.*\.rst$
- ^releasenotes/.*$
gate:
jobs:
- aodhclient-dsvm-functional:
irrelevant-files: *ac-irrelevant-files

View File

@ -13,6 +13,7 @@
import os
import time
import os_client_config
from oslo_utils import uuidutils
from tempest.lib.cli import base
from tempest.lib import exceptions
@ -27,18 +28,28 @@ class AodhClient(object):
def __init__(self):
self.cli_dir = os.environ.get('AODH_CLIENT_EXEC_DIR')
self.endpoint = os.environ.get('AODH_ENDPOINT')
self.cloud = os.environ.get('OS_ADMIN_CLOUD', 'devstack-admin')
self.user_id = uuidutils.generate_uuid()
self.project_id = uuidutils.generate_uuid()
def aodh(self, action, flags='', params='',
fail_ok=False, merge_stderr=False):
creds = ("--os-auth-plugin aodh-noauth "
"--user-id %s --project-id %s "
"--aodh-endpoint %s") % (self.user_id,
self.project_id,
self.endpoint)
auth_args = []
if self.cloud is None:
auth_args.append("--os-auth-type none")
elif self.cloud != '':
conf = os_client_config.OpenStackConfig()
creds = conf.get_one_cloud(cloud=self.cloud).get_auth_args()
auth_args.append(f"--os-auth-url {creds['auth_url']}")
auth_args.append(f"--os-username {creds['username']}")
auth_args.append(f"--os-password {creds['password']}")
auth_args.append(f"--os-project-name {creds['project_name']}")
auth_args.append(f"--os-user-domain-id {creds['user_domain_id']}")
auth_args.append("--os-project-domain-id "
f"{creds['project_domain_id']}")
endpoint_arg = "--aodh-endpoint %s" % self.endpoint
flags = creds + ' ' + flags
flags = " ".join(auth_args + [endpoint_arg] + [flags])
return base.execute("aodh", action, flags, params, fail_ok,
merge_stderr, self.cli_dir)
@ -66,6 +77,15 @@ class ClientTestBase(base.ClientTestBase):
def aodh(self, *args, **kwargs):
return self.clients.aodh(*args, **kwargs)
def get_token(self):
cloud = os.environ.get('OS_ADMIN_CLOUD', 'devstack-admin')
if cloud is not None and cloud != "":
conf = os_client_config.OpenStackConfig()
region_conf = conf.get_one_cloud(cloud=cloud)
return region_conf.get_auth().get_token(region_conf.get_session())
else:
return ""
def details_multiple(self, output_lines, with_label=False):
"""Return list of dicts with item details from cli output tables.

View File

@ -391,7 +391,7 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
req = requests.post(
os.environ.get("GNOCCHI_ENDPOINT") + "/v1/resource/generic",
auth=requests.auth.HTTPBasicAuth('admin', ''),
headers={"X-Auth-Token": self.get_token()},
json={
"id": RESOURCE_ID,
})
@ -573,8 +573,6 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
def test_gnocchi_aggr_by_resources_scenario(self):
PROJECT_ID = uuidutils.generate_uuid()
# CREATE
result = self.aodh(
u'alarm',
@ -585,8 +583,7 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
"--query "
'\'{"=": {"creator": "cr3at0r"}}\' '
"--resource-type generic "
"--aggregation-method mean "
"--project-id %s" % PROJECT_ID))
"--aggregation-method mean "))
alarm = self.details_multiple(result)[0]
ALARM_ID = alarm['alarm_id']
self.assertEqual('alarm1', alarm['name'])
@ -608,8 +605,7 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
"--query "
'\'{"=": {"creator": "cr3at0r"}}\' '
"--resource-type generic "
"--aggregation-method mean "
"--project-id %s" % PROJECT_ID))
"--aggregation-method mean "))
# UPDATE
result = self.aodh(
@ -625,7 +621,6 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
'alarm', params="show %s" % ALARM_ID)
alarm_show = self.details_multiple(result)[0]
self.assertEqual(ALARM_ID, alarm_show["alarm_id"])
self.assertEqual(PROJECT_ID, alarm_show["project_id"])
self.assertEqual('alarm1', alarm_show['name'])
self.assertEqual('cpu', alarm_show['metric'])
self.assertEqual('90.0', alarm_show['threshold'])

1
test-requirements.txt Normal file
View File

@ -0,0 +1 @@
os-client-config>=1.28.0 # Apache-2.0

41
tools/fix_ca_bundle.sh Normal file
View File

@ -0,0 +1,41 @@
# File taken from python-glanceclient
# When the functional tests are run in a devstack environment, we
# need to make sure that the python-requests module installed by
# tox in the test environment can find the distro-specific CA store
# where the devstack certs have been installed.
#
# assumptions:
# - devstack is running
# - the devstack tls-proxy service is running
# - the environment var OS_TESTENV_NAME is set in tox.ini (defaults
# to 'functional'
#
# This code based on a function in devstack lib/tls
function set_ca_bundle {
local python_cmd=".tox/${OS_TESTENV_NAME:-functional}/bin/python"
local capath=$($python_cmd -c $'try:\n from requests import certs\n print (certs.where())\nexcept ImportError: pass')
# of course, each distro keeps the CA store in a different location
local fedora_CA='/etc/pki/tls/certs/ca-bundle.crt'
local ubuntu_CA='/etc/ssl/certs/ca-certificates.crt'
local suse_CA='/etc/ssl/ca-bundle.pem'
# the distro CA is rooted in /etc, so if ours isn't, we need to
# change it
if [[ ! $capath == "" && ! $capath =~ ^/etc/.* && ! -L $capath ]]; then
if [[ -e $fedora_CA ]]; then
rm -f $capath
ln -s $fedora_CA $capath
elif [[ -e $ubuntu_CA ]]; then
rm -f $capath
ln -s $ubuntu_CA $capath
elif [[ -e $suse_CA ]]; then
rm -f $capath
ln -s $suse_CA $capath
else
echo "can't set CA bundle, expect tests to fail"
fi
fi
}
set_ca_bundle

27
tox.ini
View File

@ -9,8 +9,6 @@ usedevelop = True
setenv =
VIRTUAL_ENV={envdir}
AODH_CLIENT_EXEC_DIR={envdir}/bin
AODH_ENDPOINT=http://localhost:8042
GNOCCHI_ENDPOINT=http://localhost:8041
passenv =
GNOCCHI_*
AODH_*
@ -20,14 +18,25 @@ passenv =
OS_LOG_CAPTURE
# NOTE(tonyb): This project has chosen to *NOT* consume upper-constraints.txt
# NOTE(jd): the -e is on its own line so it is passed a separate argument to pip
# NOTE(mmagr): Recent compatibility fixes for gnocchi (werkzeug 2.x vs. 3.x)
# are not included in any release yet. Remove gnocchi dep override
# once above is not true.
deps =
.[test]
git+https://github.com/gnocchixyz/gnocchi.git
http://tarballs.openstack.org/aodh/aodh-master.tar.gz#egg=aodh[mysql]
commands = pifpaf run aodh -- stestr run --slowest {posargs}
commands = stestr run --slowest {posargs}
[testenv:functional]
setenv =
OS_TEST_PATH = ./aodhclient/tests/functional
OS_TESTENV_NAME = {envname}
AODH_CLIENT_EXEC_DIR={envdir}/bin
AODH_ENDPOINT=http://localhost:8042
GNOCCHI_ENDPOINT=http://localhost/metric/
allowlist_externals =
bash
deps = .[test]
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
bash tools/fix_ca_bundle.sh
stestr --test-path {env:OS_TEST_PATH} run --slowest {posargs}
[testenv:pep8]
deps = hacking<3.1.0,>=3.0
@ -67,7 +76,7 @@ commands =
allowlist_externals = rm
[testenv:debug]
commands = pifpaf --debug run aodh -- oslo_debug_helper {posargs}
commands = oslo_debug_helper {posargs}
[flake8]
show-source = True