Refactored existing tempest API tests
We must set up Tempest for Watcher (http://docs.openstack.org/developer/tempest/configuration.html) to run integration tests inside devstack environment. This patchset is a refactoring of the stale Tempest tests to now use the latest Tempest coding standards (like using plugins and credentials factory). This commit will have an effect on the doc as we need to integrate Tempest in the Watcher documentation. DocImpact Partially Implements: blueprint tempest-basic-set-up Change-Id: I7600ff8a28d524b56c7dd4903ac4d203634ae412
This commit is contained in:
committed by
Jean-Emile DARTOIS
parent
8832ad78e2
commit
595b13a622
@@ -1,31 +0,0 @@
|
||||
..
|
||||
Except where otherwise noted, this document is licensed under Creative
|
||||
Commons Attribution 3.0 License. You can view the license at:
|
||||
|
||||
https://creativecommons.org/licenses/by/3.0/
|
||||
|
||||
Tempest Field Guide to Infrastructure Optimization API tests
|
||||
============================================================
|
||||
|
||||
|
||||
What are these tests?
|
||||
---------------------
|
||||
|
||||
These tests stress the OpenStack Infrastructure Optimization API provided by
|
||||
Watcher.
|
||||
|
||||
|
||||
Why are these tests in tempest?
|
||||
------------------------------
|
||||
|
||||
The purpose of these tests is to exercise the various APIs provided by Watcher
|
||||
for optimizing the infrastructure.
|
||||
|
||||
|
||||
Scope of these tests
|
||||
--------------------
|
||||
|
||||
The Infrastructure Optimization API test perform basic CRUD operations on the Watcher node
|
||||
inventory. They do not actually perform placement or migration of virtual resources. It is important
|
||||
to note that all Watcher API actions are admin operations meant to be used
|
||||
either by cloud operators.
|
||||
@@ -1,130 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import functools
|
||||
|
||||
from tempest_lib.common.utils import data_utils
|
||||
from tempest_lib import exceptions as lib_exc
|
||||
|
||||
from tempest import clients_infra_optim as clients
|
||||
from tempest.common import credentials
|
||||
from tempest import config
|
||||
from tempest import test
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
# Resources must be deleted in a specific order, this list
|
||||
# defines the resource types to clean up, and the correct order.
|
||||
RESOURCE_TYPES = ['audit_template']
|
||||
# RESOURCE_TYPES = ['action', 'action_plan', 'audit', 'audit_template']
|
||||
|
||||
|
||||
def creates(resource):
|
||||
"""Decorator that adds resources to the appropriate cleanup list."""
|
||||
|
||||
def decorator(f):
|
||||
@functools.wraps(f)
|
||||
def wrapper(cls, *args, **kwargs):
|
||||
resp, body = f(cls, *args, **kwargs)
|
||||
|
||||
if 'uuid' in body:
|
||||
cls.created_objects[resource].add(body['uuid'])
|
||||
|
||||
return resp, body
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
|
||||
class BaseInfraOptimTest(test.BaseTestCase):
|
||||
"""Base class for Infrastructure Optimization API tests."""
|
||||
|
||||
@classmethod
|
||||
# def skip_checks(cls):
|
||||
# super(BaseInfraOptimTest, cls).skip_checks()
|
||||
# if not CONF.service_available.watcher:
|
||||
# skip_msg = \
|
||||
# ('%s skipped as Watcher is not available' % cls.__name__)
|
||||
# raise cls.skipException(skip_msg)
|
||||
@classmethod
|
||||
def setup_credentials(cls):
|
||||
super(BaseInfraOptimTest, cls).setup_credentials()
|
||||
if (not hasattr(cls, 'isolated_creds') or
|
||||
not cls.isolated_creds.name == cls.__name__):
|
||||
cls.isolated_creds = credentials.get_isolated_credentials(
|
||||
name=cls.__name__, network_resources=cls.network_resources)
|
||||
cls.mgr = clients.Manager(cls.isolated_creds.get_admin_creds())
|
||||
|
||||
@classmethod
|
||||
def setup_clients(cls):
|
||||
super(BaseInfraOptimTest, cls).setup_clients()
|
||||
cls.client = cls.mgr.io_client
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(BaseInfraOptimTest, cls).resource_setup()
|
||||
|
||||
cls.created_objects = {}
|
||||
for resource in RESOURCE_TYPES:
|
||||
cls.created_objects[resource] = set()
|
||||
|
||||
@classmethod
|
||||
def resource_cleanup(cls):
|
||||
"""Ensure that all created objects get destroyed."""
|
||||
|
||||
try:
|
||||
for resource in RESOURCE_TYPES:
|
||||
uuids = cls.created_objects[resource]
|
||||
delete_method = getattr(cls.client, 'delete_%s' % resource)
|
||||
for u in uuids:
|
||||
delete_method(u, ignore_errors=lib_exc.NotFound)
|
||||
finally:
|
||||
super(BaseInfraOptimTest, cls).resource_cleanup()
|
||||
|
||||
@classmethod
|
||||
@creates('audit_template')
|
||||
def create_audit_template(cls, description=None, expect_errors=False):
|
||||
"""Wrapper utility for creating test audit_template.
|
||||
|
||||
:param description: A description of the audit template.
|
||||
if not supplied, a random value will be generated.
|
||||
:return: Created audit template.
|
||||
"""
|
||||
|
||||
description = description or data_utils.rand_name(
|
||||
'test-audit_template')
|
||||
resp, body = cls.client.create_audit_template(description=description)
|
||||
return resp, body
|
||||
|
||||
@classmethod
|
||||
def delete_audit_template(cls, audit_template_id):
|
||||
"""Deletes a audit_template having the specified UUID.
|
||||
|
||||
:param uuid: The unique identifier of the audit_template.
|
||||
:return: Server response.
|
||||
"""
|
||||
|
||||
resp, body = cls.client.delete_audit_template(audit_template_id)
|
||||
|
||||
if audit_template_id in cls.created_objects['audit_template']:
|
||||
cls.created_objects['audit_template'].remove(audit_template_id)
|
||||
|
||||
return resp
|
||||
|
||||
def validate_self_link(self, resource, uuid, link):
|
||||
"""Check whether the given self link formatted correctly."""
|
||||
expected_link = "{base}/{pref}/{res}/{uuid}".format(
|
||||
base=self.client.base_url,
|
||||
pref=self.client.uri_prefix,
|
||||
res=resource,
|
||||
uuid=uuid)
|
||||
self.assertEqual(expected_link, link)
|
||||
@@ -1,42 +0,0 @@
|
||||
# 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 tempest.api.infra_optim.admin import base
|
||||
from tempest import test
|
||||
|
||||
|
||||
class TestApiDiscovery(base.BaseInfraOptimTest):
|
||||
"""Tests for API discovery features."""
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_api_versions(self):
|
||||
_, descr = self.client.get_api_description()
|
||||
expected_versions = ('v1',)
|
||||
versions = [version['id'] for version in descr['versions']]
|
||||
|
||||
for v in expected_versions:
|
||||
self.assertIn(v, versions)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_default_version(self):
|
||||
_, descr = self.client.get_api_description()
|
||||
default_version = descr['default_version']
|
||||
self.assertEqual(default_version['id'], 'v1')
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_version_1_resources(self):
|
||||
_, descr = self.client.get_version_description(version='v1')
|
||||
expected_resources = ('audit_templates', 'audits', 'action_plans',
|
||||
'actions', 'links', 'media_types')
|
||||
|
||||
for res in expected_resources:
|
||||
self.assertIn(res, descr)
|
||||
@@ -1,237 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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 tempest_lib import exceptions as lib_exc
|
||||
|
||||
from tempest.api.infra_optim.admin import base
|
||||
from tempest import test
|
||||
|
||||
|
||||
class TestAuditTemplate(base.BaseInfraOptimTest):
|
||||
"""Tests for audit_template."""
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestAuditTemplate, cls).resource_setup()
|
||||
_, cls.audit_template = cls.create_audit_template()
|
||||
|
||||
def _assertExpected(self, expected, actual):
|
||||
# Check if not expected keys/values exists in actual response body
|
||||
for key, value in expected.items():
|
||||
if key not in ('created_at', 'updated_at', 'deleted_at'):
|
||||
self.assertIn(key, actual)
|
||||
self.assertEqual(value, actual[key])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_create_audit_template(self):
|
||||
params = {'name': 'my at name',
|
||||
'description': 'my at description',
|
||||
'host_aggregate': 12,
|
||||
'goal': 'A GOAL',
|
||||
'extra': {'str': 'value', 'int': 123, 'float': 0.123,
|
||||
'bool': True, 'list': [1, 2, 3],
|
||||
'dict': {'foo': 'bar'}}}
|
||||
|
||||
_, body = self.create_audit_template(**params)
|
||||
self._assertExpected(params, body['properties'])
|
||||
|
||||
_, audit_template = self.client.show_audit_template(body['uuid'])
|
||||
self._assertExpected(audit_template, body)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_create_audit_template_unicode_description(self):
|
||||
# Use a unicode string for testing:
|
||||
params = {'name': 'my at name',
|
||||
'description': 'my àt déscrïptïôn',
|
||||
'host_aggregate': 12,
|
||||
'goal': 'A GOAL',
|
||||
'extra': {'foo': 'bar'}}
|
||||
|
||||
_, body = self.create_audit_template(**params)
|
||||
self._assertExpected(params, body['properties'])
|
||||
|
||||
_, audit_template = self.client.show_audit_template(body['uuid'])
|
||||
self._assertExpected(audit_template, body)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_show_audit_template(self):
|
||||
_, audit_template = self.client.show_audit_template(
|
||||
self.audit_template['uuid'])
|
||||
self._assertExpected(self.audit_template, audit_template)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_show_audit_template_by_goal(self):
|
||||
_, audit_template = self.client.\
|
||||
show_audit_template_by_goal(self.audit_template['goal'])
|
||||
self._assertExpected(self.audit_template,
|
||||
audit_template['audit_templates'][0])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_show_audit_template_by_host_aggregate(self):
|
||||
_, audit_template = self.client.\
|
||||
show_audit_template_by_host_aggregate(
|
||||
self.audit_template['host_aggregate'])
|
||||
self._assertExpected(self.audit_template,
|
||||
audit_template['audit_templates'][0])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_show_audit_template_with_links(self):
|
||||
_, audit_template = self.client.show_audit_template(
|
||||
self.audit_template['uuid'])
|
||||
self.assertIn('links', audit_template.keys())
|
||||
self.assertEqual(2, len(audit_template['links']))
|
||||
self.assertIn(audit_template['uuid'],
|
||||
audit_template['links'][0]['href'])
|
||||
|
||||
@test.attr(type="smoke")
|
||||
def test_list_audit_templates(self):
|
||||
_, body = self.client.list_audit_templates()
|
||||
self.assertIn(self.audit_template['uuid'],
|
||||
[i['uuid'] for i in body['audit_templates']])
|
||||
# Verify self links.
|
||||
for audit_template in body['audit_templates']:
|
||||
self.validate_self_link('audit_templates', audit_template['uuid'],
|
||||
audit_template['links'][0]['href'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_list_with_limit(self):
|
||||
_, body = self.client.list_audit_templates(limit=3)
|
||||
|
||||
next_marker = body['audit_templates'][-1]['uuid']
|
||||
self.assertIn(next_marker, body['next'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_delete_audit_template(self):
|
||||
_, body = self.create_audit_template()
|
||||
uuid = body['uuid']
|
||||
|
||||
self.delete_audit_template(uuid)
|
||||
self.assertRaises(lib_exc.NotFound, self.client.show_audit_template,
|
||||
uuid)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_update_audit_template_replace(self):
|
||||
params = {'name': 'my at name',
|
||||
'description': 'my at description',
|
||||
'host_aggregate': 12,
|
||||
'goal': 'A GOAL',
|
||||
'extra': {'key1': 'value1', 'key2': 'value2'}}
|
||||
|
||||
_, body = self.create_audit_template(**params)
|
||||
|
||||
new_name = 'my at new name'
|
||||
new_description = 'my new at description'
|
||||
new_host_aggregate = 10
|
||||
new_goal = 'A NEW GOAL'
|
||||
new_extra = {'key1': 'new-value1', 'key2': 'new-value2'}
|
||||
|
||||
patch = [{'path': '/name',
|
||||
'op': 'replace',
|
||||
'value': new_name},
|
||||
{'path': '/description',
|
||||
'op': 'replace',
|
||||
'value': new_description},
|
||||
{'path': '/host_aggregate',
|
||||
'op': 'replace',
|
||||
'value': new_host_aggregate},
|
||||
{'path': '/goal',
|
||||
'op': 'replace',
|
||||
'value': new_goal},
|
||||
{'path': '/extra/key1',
|
||||
'op': 'replace',
|
||||
'value': new_extra['key1']},
|
||||
{'path': '/extra/key2',
|
||||
'op': 'replace',
|
||||
'value': new_extra['key2']}]
|
||||
|
||||
self.client.update_audit_template(body['uuid'], patch)
|
||||
|
||||
_, body = self.client.show_audit_template(body['uuid'])
|
||||
self.assertEqual(new_name, body['name'])
|
||||
self.assertEqual(new_description, body['description'])
|
||||
self.assertEqual(new_host_aggregate, body['host_aggregate'])
|
||||
self.assertEqual(new_goal, body['goal'])
|
||||
self.assertEqual(new_extra, body['extra'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_update_audit_template_remove(self):
|
||||
extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
|
||||
description = 'my at description'
|
||||
goal = 'A GOAL'
|
||||
name = 'my at name'
|
||||
params = {'name': name,
|
||||
'description': description,
|
||||
'host_aggregate': 12,
|
||||
'goal': goal,
|
||||
'extra': extra}
|
||||
|
||||
_, audit_template = self.create_audit_template(**params)
|
||||
|
||||
# Removing one item from the collection
|
||||
self.client.update_audit_template(
|
||||
audit_template['uuid'],
|
||||
[{'path': '/extra/key2', 'op': 'remove'}])
|
||||
|
||||
extra.pop('key2')
|
||||
_, body = self.client.show_audit_template(audit_template['uuid'])
|
||||
self.assertEqual(extra, body['extra'])
|
||||
|
||||
# Removing the collection
|
||||
self.client.update_audit_template(
|
||||
audit_template['uuid'],
|
||||
[{'path': '/extra', 'op': 'remove'}])
|
||||
_, body = self.client.show_audit_template(audit_template['uuid'])
|
||||
self.assertEqual({}, body['extra'])
|
||||
|
||||
# Removing the Host Aggregate ID
|
||||
self.client.update_audit_template(
|
||||
audit_template['uuid'],
|
||||
[{'path': '/host_aggregate', 'op': 'remove'}])
|
||||
_, body = self.client.show_audit_template(audit_template['uuid'])
|
||||
self.assertEqual('', body['extra'])
|
||||
|
||||
# Assert nothing else was changed
|
||||
self.assertEqual(name, body['name'])
|
||||
self.assertEqual(description, body['description'])
|
||||
self.assertEqual(goal, body['goal'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_update_audit_template_add(self):
|
||||
params = {'name': 'my at name',
|
||||
'description': 'my at description',
|
||||
'host_aggregate': 12,
|
||||
'goal': 'A GOAL'}
|
||||
|
||||
_, body = self.create_audit_template(**params)
|
||||
|
||||
extra = {'key1': 'value1', 'key2': 'value2'}
|
||||
|
||||
patch = [{'path': '/extra/key1',
|
||||
'op': 'add',
|
||||
'value': extra['key1']},
|
||||
{'path': '/extra/key2',
|
||||
'op': 'add',
|
||||
'value': extra['key2']}]
|
||||
|
||||
self.client.update_audit_template(body['uuid'], patch)
|
||||
|
||||
_, body = self.client.show_audit_template(body['uuid'])
|
||||
self.assertEqual(extra, body['extra'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_audit_template_audit_list(self):
|
||||
_, audit = self.create_audit(self.audit_template['uuid'])
|
||||
_, body = self.client.list_audit_template_audits(
|
||||
self.audit_template['uuid'])
|
||||
self.assertIn(audit['uuid'], [n['uuid'] for n in body['audits']])
|
||||
@@ -1,56 +0,0 @@
|
||||
..
|
||||
Except where otherwise noted, this document is licensed under Creative
|
||||
Commons Attribution 3.0 License. You can view the license at:
|
||||
|
||||
https://creativecommons.org/licenses/by/3.0/
|
||||
|
||||
.. _cli_field_guide:
|
||||
|
||||
Tempest Field Guide to CLI tests
|
||||
================================
|
||||
|
||||
|
||||
What are these tests?
|
||||
---------------------
|
||||
The cli tests test the various OpenStack command line interface tools
|
||||
to ensure that they minimally function. The current scope is read only
|
||||
operations on a cloud that are hard to test via unit tests.
|
||||
|
||||
|
||||
Why are these tests in tempest?
|
||||
-------------------------------
|
||||
These tests exist here because it is extremely difficult to build a
|
||||
functional enough environment in the python-\*client unit tests to
|
||||
provide this kind of testing. Because we already put up a cloud in the
|
||||
gate with devstack + tempest it was decided it was better to have
|
||||
these as a side tree in tempest instead of another QA effort which
|
||||
would split review time.
|
||||
|
||||
|
||||
Scope of these tests
|
||||
--------------------
|
||||
This should stay limited to the scope of testing the cli. Functional
|
||||
testing of the cloud should be elsewhere, this is about exercising the
|
||||
cli code.
|
||||
|
||||
|
||||
Example of a good test
|
||||
----------------------
|
||||
Tests should be isolated to a single command in one of the python
|
||||
clients.
|
||||
|
||||
Tests should not modify the cloud.
|
||||
|
||||
If a test is validating the cli for bad data, it should do it with
|
||||
assertRaises.
|
||||
|
||||
A reasonable example of an existing test is as follows::
|
||||
|
||||
def test_admin_list(self):
|
||||
self.nova('list')
|
||||
self.nova('list', params='--all-tenants 1')
|
||||
self.nova('list', params='--all-tenants 0')
|
||||
self.assertRaises(subprocess.CalledProcessError,
|
||||
self.nova,
|
||||
'list',
|
||||
params='--all-tenants bad')
|
||||
@@ -1,126 +0,0 @@
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
# 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.
|
||||
|
||||
import functools
|
||||
|
||||
from tempest_lib.cli import base
|
||||
from tempest_lib.cli import output_parser
|
||||
import testtools
|
||||
|
||||
from tempest.common import credentials
|
||||
from tempest import config
|
||||
from tempest import exceptions
|
||||
from tempest.openstack.common import versionutils
|
||||
from tempest import test
|
||||
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
def check_client_version(client, version):
|
||||
"""Checks if the client's version is compatible with the given version
|
||||
|
||||
@param client: The client to check.
|
||||
@param version: The version to compare against.
|
||||
@return: True if the client version is compatible with the given version
|
||||
parameter, False otherwise.
|
||||
"""
|
||||
current_version = base.execute(client, '', params='--version',
|
||||
merge_stderr=True, cli_dir=CONF.cli.cli_dir)
|
||||
|
||||
if not current_version.strip():
|
||||
raise exceptions.TempestException('"%s --version" output was empty' %
|
||||
client)
|
||||
|
||||
return versionutils.is_compatible(version, current_version,
|
||||
same_major=False)
|
||||
|
||||
|
||||
def min_client_version(*args, **kwargs):
|
||||
"""A decorator to skip tests if the client used isn't of the right version.
|
||||
|
||||
@param client: The client command to run. For python-novaclient, this is
|
||||
'nova', for python-cinderclient this is 'cinder', etc.
|
||||
@param version: The minimum version required to run the CLI test.
|
||||
"""
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*func_args, **func_kwargs):
|
||||
if not check_client_version(kwargs['client'], kwargs['version']):
|
||||
msg = "requires %s client version >= %s" % (kwargs['client'],
|
||||
kwargs['version'])
|
||||
raise testtools.TestCase.skipException(msg)
|
||||
return func(*func_args, **func_kwargs)
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
|
||||
class ClientTestBase(test.BaseTestCase):
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
super(ClientTestBase, cls).skip_checks()
|
||||
if not CONF.identity_feature_enabled.api_v2:
|
||||
raise cls.skipException("CLI clients rely on identity v2 API, "
|
||||
"which is configured as not available")
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
if not CONF.cli.enabled:
|
||||
msg = "cli testing disabled"
|
||||
raise cls.skipException(msg)
|
||||
super(ClientTestBase, cls).resource_setup()
|
||||
cls.isolated_creds = credentials.get_isolated_credentials(cls.__name__)
|
||||
cls.creds = cls.isolated_creds.get_admin_creds()
|
||||
|
||||
def _get_clients(self):
|
||||
clients = base.CLIClient(self.creds.username,
|
||||
self.creds.password,
|
||||
self.creds.tenant_name,
|
||||
CONF.identity.uri, CONF.cli.cli_dir)
|
||||
return clients
|
||||
|
||||
# TODO(mtreinish): The following code is basically copied from tempest-lib.
|
||||
# The base cli test class in tempest-lib 0.0.1 doesn't work as a mixin like
|
||||
# is needed here. The code below should be removed when tempest-lib
|
||||
# provides a way to provide this functionality
|
||||
def setUp(self):
|
||||
super(ClientTestBase, self).setUp()
|
||||
self.clients = self._get_clients()
|
||||
self.parser = output_parser
|
||||
|
||||
def assertTableStruct(self, items, field_names):
|
||||
"""Verify that all items has keys listed in field_names.
|
||||
|
||||
:param items: items to assert are field names in the output table
|
||||
:type items: list
|
||||
:param field_names: field names from the output table of the cmd
|
||||
:type field_names: list
|
||||
"""
|
||||
for item in items:
|
||||
for field in field_names:
|
||||
self.assertIn(field, item)
|
||||
|
||||
def assertFirstLineStartsWith(self, lines, beginning):
|
||||
"""Verify that the first line starts with a string
|
||||
|
||||
:param lines: strings for each line of output
|
||||
:type lines: list
|
||||
:param beginning: verify this is at the beginning of the first line
|
||||
:type beginning: string
|
||||
"""
|
||||
self.assertTrue(lines[0].startswith(beginning),
|
||||
msg=('Beginning of first line has invalid content: %s'
|
||||
% lines[:3]))
|
||||
@@ -1 +0,0 @@
|
||||
This directory consists of simple read only python client tests.
|
||||
@@ -1,220 +0,0 @@
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
# 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.
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
from tempest_lib import exceptions
|
||||
import testtools
|
||||
|
||||
from tempest import cli
|
||||
from tempest import clients
|
||||
from tempest import config
|
||||
from tempest import test
|
||||
|
||||
|
||||
CONF = config.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SimpleReadOnlyCinderClientTest(cli.ClientTestBase):
|
||||
"""Basic, read-only tests for Cinder CLI client.
|
||||
|
||||
Checks return values and output of read-only commands.
|
||||
These tests do not presume any content, nor do they create
|
||||
their own. They only verify the structure of output if present.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
# if not CONF.service_available.cinder:
|
||||
# msg = ("%s skipped as Cinder is not available" % cls.__name__)
|
||||
# raise cls.skipException(msg)
|
||||
super(SimpleReadOnlyCinderClientTest, cls).resource_setup()
|
||||
id_cl = clients.AdminManager().identity_client
|
||||
tenant = id_cl.get_tenant_by_name(CONF.identity.admin_tenant_name)
|
||||
cls.admin_tenant_id = tenant['id']
|
||||
|
||||
def cinder(self, *args, **kwargs):
|
||||
return self.clients.cinder(*args,
|
||||
endpoint_type=CONF.volume.endpoint_type,
|
||||
**kwargs)
|
||||
|
||||
@test.idempotent_id('229bc6dc-d804-4668-b753-b590caf63061')
|
||||
def test_cinder_fake_action(self):
|
||||
self.assertRaises(exceptions.CommandFailed,
|
||||
self.cinder,
|
||||
'this-does-not-exist')
|
||||
|
||||
@test.idempotent_id('77140216-14db-4fc5-a246-e2a587e9e99b')
|
||||
def test_cinder_absolute_limit_list(self):
|
||||
roles = self.parser.listing(self.cinder('absolute-limits'))
|
||||
self.assertTableStruct(roles, ['Name', 'Value'])
|
||||
|
||||
@test.idempotent_id('2206b9ce-1a36-4a0a-a129-e5afc7cee1dd')
|
||||
def test_cinder_backup_list(self):
|
||||
backup_list = self.parser.listing(self.cinder('backup-list'))
|
||||
self.assertTableStruct(backup_list, ['ID', 'Volume ID', 'Status',
|
||||
'Name', 'Size', 'Object Count',
|
||||
'Container'])
|
||||
|
||||
@test.idempotent_id('c7f50346-cd99-4e0b-953f-796ff5f47295')
|
||||
def test_cinder_extra_specs_list(self):
|
||||
extra_specs_list = self.parser.listing(self.cinder('extra-specs-list'))
|
||||
self.assertTableStruct(extra_specs_list, ['ID', 'Name', 'extra_specs'])
|
||||
|
||||
@test.idempotent_id('9de694cb-b40b-442c-a30c-5f9873e144f7')
|
||||
def test_cinder_volumes_list(self):
|
||||
list = self.parser.listing(self.cinder('list'))
|
||||
self.assertTableStruct(list, ['ID', 'Status', 'Name', 'Size',
|
||||
'Volume Type', 'Bootable',
|
||||
'Attached to'])
|
||||
self.cinder('list', params='--all-tenants 1')
|
||||
self.cinder('list', params='--all-tenants 0')
|
||||
self.assertRaises(exceptions.CommandFailed,
|
||||
self.cinder,
|
||||
'list',
|
||||
params='--all-tenants bad')
|
||||
|
||||
@test.idempotent_id('56f7c15c-ee82-4f23-bbe8-ce99b66da493')
|
||||
def test_cinder_quota_class_show(self):
|
||||
"""This CLI can accept and string as param."""
|
||||
roles = self.parser.listing(self.cinder('quota-class-show',
|
||||
params='abc'))
|
||||
self.assertTableStruct(roles, ['Property', 'Value'])
|
||||
|
||||
@test.idempotent_id('a919a811-b7f0-47a7-b4e5-f3eb674dd200')
|
||||
def test_cinder_quota_defaults(self):
|
||||
"""This CLI can accept and string as param."""
|
||||
roles = self.parser.listing(self.cinder('quota-defaults',
|
||||
params=self.admin_tenant_id))
|
||||
self.assertTableStruct(roles, ['Property', 'Value'])
|
||||
|
||||
@test.idempotent_id('18166673-ffa8-4df3-b60c-6375532288bc')
|
||||
def test_cinder_quota_show(self):
|
||||
"""This CLI can accept and string as param."""
|
||||
roles = self.parser.listing(self.cinder('quota-show',
|
||||
params=self.admin_tenant_id))
|
||||
self.assertTableStruct(roles, ['Property', 'Value'])
|
||||
|
||||
@test.idempotent_id('b2c66ed9-ca96-4dc4-94cc-8083e664e516')
|
||||
def test_cinder_rate_limits(self):
|
||||
rate_limits = self.parser.listing(self.cinder('rate-limits'))
|
||||
self.assertTableStruct(rate_limits, ['Verb', 'URI', 'Value', 'Remain',
|
||||
'Unit', 'Next_Available'])
|
||||
|
||||
@test.idempotent_id('7a19955b-807c-481a-a2ee-9d76733eac28')
|
||||
@testtools.skipUnless(CONF.volume_feature_enabled.snapshot,
|
||||
'Volume snapshot not available.')
|
||||
def test_cinder_snapshot_list(self):
|
||||
snapshot_list = self.parser.listing(self.cinder('snapshot-list'))
|
||||
self.assertTableStruct(snapshot_list, ['ID', 'Volume ID', 'Status',
|
||||
'Name', 'Size'])
|
||||
|
||||
@test.idempotent_id('6e54ecd9-7ba9-490d-8e3b-294b67139e73')
|
||||
def test_cinder_type_list(self):
|
||||
type_list = self.parser.listing(self.cinder('type-list'))
|
||||
self.assertTableStruct(type_list, ['ID', 'Name'])
|
||||
|
||||
@test.idempotent_id('2c363583-24a0-4980-b9cb-b50c0d241e82')
|
||||
def test_cinder_list_extensions(self):
|
||||
roles = self.parser.listing(self.cinder('list-extensions'))
|
||||
self.assertTableStruct(roles, ['Name', 'Summary', 'Alias', 'Updated'])
|
||||
|
||||
@test.idempotent_id('691bd6df-30ad-4be7-927b-a02d62aaa38a')
|
||||
def test_cinder_credentials(self):
|
||||
credentials = self.parser.listing(self.cinder('credentials'))
|
||||
self.assertTableStruct(credentials, ['User Credentials', 'Value'])
|
||||
|
||||
@test.idempotent_id('5c6d71a3-4904-4a3a-aec9-7fd4aa830e95')
|
||||
def test_cinder_availability_zone_list(self):
|
||||
zone_list = self.parser.listing(self.cinder('availability-zone-list'))
|
||||
self.assertTableStruct(zone_list, ['Name', 'Status'])
|
||||
|
||||
@test.idempotent_id('9b0fd5a6-f955-42b9-a42f-6f542a80b9a3')
|
||||
def test_cinder_endpoints(self):
|
||||
out = self.cinder('endpoints')
|
||||
tables = self.parser.tables(out)
|
||||
for table in tables:
|
||||
headers = table['headers']
|
||||
self.assertTrue(2 >= len(headers))
|
||||
self.assertEqual('Value', headers[1])
|
||||
|
||||
@test.idempotent_id('301b5ae1-9591-4e9f-999c-d525a9bdf822')
|
||||
def test_cinder_service_list(self):
|
||||
service_list = self.parser.listing(self.cinder('service-list'))
|
||||
self.assertTableStruct(service_list, ['Binary', 'Host', 'Zone',
|
||||
'Status', 'State', 'Updated_at'])
|
||||
|
||||
@test.idempotent_id('7260ae52-b462-461e-9048-36d0bccf92c6')
|
||||
def test_cinder_transfer_list(self):
|
||||
transfer_list = self.parser.listing(self.cinder('transfer-list'))
|
||||
self.assertTableStruct(transfer_list, ['ID', 'Volume ID', 'Name'])
|
||||
|
||||
@test.idempotent_id('0976dea8-14f3-45a9-8495-3617fc4fbb13')
|
||||
def test_cinder_bash_completion(self):
|
||||
self.cinder('bash-completion')
|
||||
|
||||
@test.idempotent_id('b7c00361-be80-4512-8735-5f98fc54f2a9')
|
||||
def test_cinder_qos_list(self):
|
||||
qos_list = self.parser.listing(self.cinder('qos-list'))
|
||||
self.assertTableStruct(qos_list, ['ID', 'Name', 'Consumer', 'specs'])
|
||||
|
||||
@test.idempotent_id('2e92dc6e-22b5-4d94-abfc-b543b0c50a89')
|
||||
def test_cinder_encryption_type_list(self):
|
||||
encrypt_list = self.parser.listing(self.cinder('encryption-type-list'))
|
||||
self.assertTableStruct(encrypt_list, ['Volume Type ID', 'Provider',
|
||||
'Cipher', 'Key Size',
|
||||
'Control Location'])
|
||||
|
||||
@test.idempotent_id('0ee6cb4c-8de6-4811-a7be-7f4bb75b80cc')
|
||||
def test_admin_help(self):
|
||||
help_text = self.cinder('help')
|
||||
lines = help_text.split('\n')
|
||||
self.assertFirstLineStartsWith(lines, 'usage: cinder')
|
||||
|
||||
commands = []
|
||||
cmds_start = lines.index('Positional arguments:')
|
||||
cmds_end = lines.index('Optional arguments:')
|
||||
command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)')
|
||||
for line in lines[cmds_start:cmds_end]:
|
||||
match = command_pattern.match(line)
|
||||
if match:
|
||||
commands.append(match.group(1))
|
||||
commands = set(commands)
|
||||
wanted_commands = set(('absolute-limits', 'list', 'help',
|
||||
'quota-show', 'type-list', 'snapshot-list'))
|
||||
self.assertFalse(wanted_commands - commands)
|
||||
|
||||
# Optional arguments:
|
||||
|
||||
@test.idempotent_id('2fd6f530-183c-4bda-8918-1e59e36c26b9')
|
||||
def test_cinder_version(self):
|
||||
self.cinder('', flags='--version')
|
||||
|
||||
@test.idempotent_id('306bac51-c443-4426-a6cf-583a953fcd68')
|
||||
def test_cinder_debug_list(self):
|
||||
self.cinder('list', flags='--debug')
|
||||
|
||||
@test.idempotent_id('6d97fcd2-5dd1-429d-af70-030c949d86cd')
|
||||
def test_cinder_retries_list(self):
|
||||
self.cinder('list', flags='--retries 3')
|
||||
|
||||
@test.idempotent_id('95a2850c-35b4-4159-bb93-51647a5ad232')
|
||||
def test_cinder_region_list(self):
|
||||
region = CONF.volume.region
|
||||
if not region:
|
||||
region = CONF.identity.region
|
||||
self.cinder('list', flags='--os-region-name ' + region)
|
||||
@@ -1,42 +0,0 @@
|
||||
# Copyright 2014 Mirantis Inc.
|
||||
# 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 tempest import clients
|
||||
from tempest.common import cred_provider
|
||||
from tempest import config
|
||||
from tempest.services.infra_optim.v1.json import infra_optim_client as ioc
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class Manager(clients.Manager):
|
||||
def __init__(self, credentials=None, service=None):
|
||||
super(Manager, self).__init__(credentials, service)
|
||||
self.io_client = ioc.InfraOptimClientJSON(self.auth_provider,
|
||||
'infra-optim',
|
||||
CONF.identity.region)
|
||||
|
||||
|
||||
class AltManager(Manager):
|
||||
def __init__(self, service=None):
|
||||
super(AltManager, self).__init__(
|
||||
cred_provider.get_configured_credentials('alt_user'), service)
|
||||
|
||||
|
||||
class AdminManager(Manager):
|
||||
def __init__(self, service=None):
|
||||
super(AdminManager, self).__init__(
|
||||
cred_provider.get_configured_credentials('identity_admin'),
|
||||
service)
|
||||
@@ -1,45 +0,0 @@
|
||||
# Copyright 2014 Mirantis Inc.
|
||||
# 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 __future__ import print_function
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from tempest import config # noqa
|
||||
|
||||
service_available_group = cfg.OptGroup(name="service_available",
|
||||
title="Available OpenStack Services")
|
||||
|
||||
ServiceAvailableGroup = [
|
||||
cfg.BoolOpt("watcher",
|
||||
default=True,
|
||||
help="Whether or not watcher is expected to be available"),
|
||||
]
|
||||
|
||||
|
||||
class TempestConfigProxyWatcher(object):
|
||||
"""Wrapper over standard Tempest config that sets Watcher opts."""
|
||||
|
||||
def __init__(self):
|
||||
self._config = config.CONF
|
||||
config.register_opt_group(
|
||||
cfg.CONF, service_available_group, ServiceAvailableGroup)
|
||||
self._config.share = cfg.CONF.share
|
||||
|
||||
def __getattr__(self, attr):
|
||||
return getattr(self._config, attr)
|
||||
|
||||
|
||||
CONF = TempestConfigProxyWatcher()
|
||||
@@ -1,205 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import functools
|
||||
import json
|
||||
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from tempest.common import service_client
|
||||
|
||||
|
||||
def handle_errors(f):
|
||||
"""A decorator that allows to ignore certain types of errors."""
|
||||
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
param_name = 'ignore_errors'
|
||||
ignored_errors = kwargs.get(param_name, tuple())
|
||||
|
||||
if param_name in kwargs:
|
||||
del kwargs[param_name]
|
||||
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except ignored_errors:
|
||||
# Silently ignore errors
|
||||
pass
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
class InfraOptimClient(service_client.ServiceClient):
|
||||
"""Base Tempest REST client for Watcher API."""
|
||||
|
||||
uri_prefix = ''
|
||||
|
||||
def serialize(self, object_dict):
|
||||
"""Serialize an Watcher object."""
|
||||
|
||||
return json.dumps(object_dict)
|
||||
|
||||
def deserialize(self, object_str):
|
||||
"""Deserialize an Watcher object."""
|
||||
|
||||
return json.loads(object_str)
|
||||
|
||||
def _get_uri(self, resource_name, uuid=None, permanent=False):
|
||||
"""Get URI for a specific resource or object.
|
||||
|
||||
:param resource_name: The name of the REST resource, e.g., 'audits'.
|
||||
:param uuid: The unique identifier of an object in UUID format.
|
||||
:return: Relative URI for the resource or object.
|
||||
"""
|
||||
|
||||
prefix = self.uri_prefix if not permanent else ''
|
||||
|
||||
return '{pref}/{res}{uuid}'.format(pref=prefix,
|
||||
res=resource_name,
|
||||
uuid='/%s' % uuid if uuid else '')
|
||||
|
||||
def _make_patch(self, allowed_attributes, **kw):
|
||||
"""Create a JSON patch according to RFC 6902.
|
||||
|
||||
:param allowed_attributes: An iterable object that contains a set of
|
||||
allowed attributes for an object.
|
||||
:param **kw: Attributes and new values for them.
|
||||
:return: A JSON path that sets values of the specified attributes to
|
||||
the new ones.
|
||||
"""
|
||||
|
||||
def get_change(kw, path='/'):
|
||||
for name, value in kw.items():
|
||||
if isinstance(value, dict):
|
||||
for ch in get_change(value, path + '%s/' % name):
|
||||
yield ch
|
||||
else:
|
||||
if value is None:
|
||||
yield {'path': path + name,
|
||||
'op': 'remove'}
|
||||
else:
|
||||
yield {'path': path + name,
|
||||
'value': value,
|
||||
'op': 'replace'}
|
||||
|
||||
patch = [ch for ch in get_change(kw)
|
||||
if ch['path'].lstrip('/') in allowed_attributes]
|
||||
|
||||
return patch
|
||||
|
||||
def _list_request(self, resource, permanent=False, **kwargs):
|
||||
"""Get the list of objects of the specified type.
|
||||
|
||||
:param resource: The name of the REST resource, e.g., 'audits'.
|
||||
"param **kw: Parameters for the request.
|
||||
:return: A tuple with the server response and deserialized JSON list
|
||||
of objects
|
||||
"""
|
||||
|
||||
uri = self._get_uri(resource, permanent=permanent)
|
||||
if kwargs:
|
||||
uri += "?%s" % urlparse.urlencode(kwargs)
|
||||
|
||||
resp, body = self.get(uri)
|
||||
self.expected_success(200, resp['status'])
|
||||
|
||||
return resp, self.deserialize(body)
|
||||
|
||||
def _show_request(self, resource, uuid, permanent=False, **kwargs):
|
||||
"""Gets a specific object of the specified type.
|
||||
|
||||
:param uuid: Unique identifier of the object in UUID format.
|
||||
:return: Serialized object as a dictionary.
|
||||
"""
|
||||
|
||||
if 'uri' in kwargs:
|
||||
uri = kwargs['uri']
|
||||
else:
|
||||
uri = self._get_uri(resource, uuid=uuid, permanent=permanent)
|
||||
resp, body = self.get(uri)
|
||||
self.expected_success(200, resp['status'])
|
||||
|
||||
return resp, self.deserialize(body)
|
||||
|
||||
def _create_request(self, resource, object_dict):
|
||||
"""Create an object of the specified type.
|
||||
|
||||
:param resource: The name of the REST resource, e.g., 'audits'.
|
||||
:param object_dict: A Python dict that represents an object of the
|
||||
specified type.
|
||||
:return: A tuple with the server response and the deserialized created
|
||||
object.
|
||||
"""
|
||||
|
||||
body = self.serialize(object_dict)
|
||||
uri = self._get_uri(resource)
|
||||
|
||||
resp, body = self.post(uri, body=body)
|
||||
self.expected_success(201, resp['status'])
|
||||
|
||||
return resp, self.deserialize(body)
|
||||
|
||||
def _delete_request(self, resource, uuid):
|
||||
"""Delete specified object.
|
||||
|
||||
:param resource: The name of the REST resource, e.g., 'audits'.
|
||||
:param uuid: The unique identifier of an object in UUID format.
|
||||
:return: A tuple with the server response and the response body.
|
||||
"""
|
||||
|
||||
uri = self._get_uri(resource, uuid)
|
||||
|
||||
resp, body = self.delete(uri)
|
||||
self.expected_success(204, resp['status'])
|
||||
return resp, body
|
||||
|
||||
def _patch_request(self, resource, uuid, patch_object):
|
||||
"""Update specified object with JSON-patch.
|
||||
|
||||
:param resource: The name of the REST resource, e.g., 'audits'.
|
||||
:param uuid: The unique identifier of an object in UUID format.
|
||||
:return: A tuple with the server response and the serialized patched
|
||||
object.
|
||||
"""
|
||||
|
||||
uri = self._get_uri(resource, uuid)
|
||||
patch_body = json.dumps(patch_object)
|
||||
|
||||
resp, body = self.patch(uri, body=patch_body)
|
||||
self.expected_success(200, resp['status'])
|
||||
return resp, self.deserialize(body)
|
||||
|
||||
@handle_errors
|
||||
def get_api_description(self):
|
||||
"""Retrieves all versions of the Watcher API."""
|
||||
|
||||
return self._list_request('', permanent=True)
|
||||
|
||||
@handle_errors
|
||||
def get_version_description(self, version='v1'):
|
||||
"""Retrieves the description of the API.
|
||||
|
||||
:param version: The version of the API. Default: 'v1'.
|
||||
:return: Serialized description of API resources.
|
||||
"""
|
||||
|
||||
return self._list_request(version, permanent=True)
|
||||
|
||||
def _put_request(self, resource, put_object):
|
||||
"""Update specified object with JSON-patch."""
|
||||
|
||||
uri = self._get_uri(resource)
|
||||
put_body = json.dumps(put_object)
|
||||
|
||||
resp, body = self.put(uri, body=put_body)
|
||||
self.expected_success(202, resp['status'])
|
||||
return resp, body
|
||||
@@ -1,142 +0,0 @@
|
||||
# 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 tempest.services.infra_optim import base
|
||||
|
||||
|
||||
class InfraOptimClientJSON(base.InfraOptimClient):
|
||||
"""Base Tempest REST client for Watcher API v1."""
|
||||
version = '1'
|
||||
uri_prefix = 'v1'
|
||||
|
||||
# Audit Template
|
||||
|
||||
@base.handle_errors
|
||||
def list_audit_templates(self, **kwargs):
|
||||
"""List all existing audit templates."""
|
||||
return self._list_request('audit_templates', **kwargs)
|
||||
|
||||
@base.handle_errors
|
||||
def list_audit_template_audits(self, audit_template_uuid):
|
||||
"""Lists all audits associated with a audit template."""
|
||||
return self._list_request(
|
||||
'/audit_templates/%s/audits' % audit_template_uuid)
|
||||
|
||||
@base.handle_errors
|
||||
def list_audit_templates_detail(self, **kwargs):
|
||||
"""Lists details of all existing audit templates."""
|
||||
return self._list_request('/audit_templates/detail', **kwargs)
|
||||
|
||||
@base.handle_errors
|
||||
def show_audit_template(self, uuid):
|
||||
"""Gets a specific audit template.
|
||||
|
||||
:param uuid: Unique identifier of the audit template in UUID format.
|
||||
:return: Serialized audit template as a dictionary.
|
||||
"""
|
||||
|
||||
return self._show_request('audit_templates', uuid)
|
||||
|
||||
@base.handle_errors
|
||||
def show_audit_template_by_host_agregate(self, host_agregate_id):
|
||||
"""Gets an audit template associated with given host agregate ID.
|
||||
|
||||
:param uuid: Unique identifier of the audit_template in UUID format.
|
||||
:return: Serialized audit_template as a dictionary.
|
||||
"""
|
||||
|
||||
uri = '/audit_templates/detail?host_agregate=%s' % host_agregate_id
|
||||
|
||||
return self._show_request('audit_templates', uuid=None, uri=uri)
|
||||
|
||||
@base.handle_errors
|
||||
def show_audit_template_by_goal(self, goal):
|
||||
"""Gets an audit template associated with given goal.
|
||||
|
||||
:param uuid: Unique identifier of the audit_template in UUID format.
|
||||
:return: Serialized audit_template as a dictionary.
|
||||
"""
|
||||
|
||||
uri = '/audit_templates/detail?goal=%s' % goal
|
||||
|
||||
return self._show_request('audit_templates', uuid=None, uri=uri)
|
||||
|
||||
@base.handle_errors
|
||||
def create_audit_template(self, **kwargs):
|
||||
"""Creates an audit template with the specified parameters.
|
||||
|
||||
:param name: The name of the audit template. Default: My Audit Template
|
||||
:param description: The description of the audit template.
|
||||
Default: AT Description
|
||||
:param goal: The goal associated within the audit template.
|
||||
Default: SERVERS_CONSOLIDATION
|
||||
:param host_aggregate: ID of the host aggregate targeted by
|
||||
this audit template. Default: 1
|
||||
:param extra: IMetadata associated to this audit template.
|
||||
Default: {}
|
||||
:return: A tuple with the server response and the created audit
|
||||
template.
|
||||
"""
|
||||
|
||||
audit_template = {
|
||||
'name': kwargs.get('name', 'My Audit Template'),
|
||||
'description': kwargs.get('description', 'AT Description'),
|
||||
'goal': kwargs.get('goal', 'SERVERS_CONSOLIDATION'),
|
||||
'host_aggregate': kwargs.get('host_aggregate', 1),
|
||||
'extra': kwargs.get('extra', {}),
|
||||
}
|
||||
|
||||
return self._create_request('audit_templates', audit_template)
|
||||
|
||||
# @base.handle_errors
|
||||
# def create_audit(self, audit_template_id=None, **kwargs):
|
||||
# """
|
||||
# Create a infra_optim audit with the specified parameters.
|
||||
|
||||
# :param cpu_arch: CPU architecture of the audit. Default: x86_64.
|
||||
# :param cpus: Number of CPUs. Default: 8.
|
||||
# :param local_gb: Disk size. Default: 1024.
|
||||
# :param memory_mb: Available RAM. Default: 4096.
|
||||
# :param driver: Driver name. Default: "fake"
|
||||
# :return: A tuple with the server response and the created audit.
|
||||
|
||||
# """
|
||||
# audit = {'audit_template_uuid': audit_template_id,
|
||||
# 'properties': {'cpu_arch': kwargs.get('cpu_arch', 'x86_64'),
|
||||
# 'cpus': kwargs.get('cpus', 8),
|
||||
# 'local_gb': kwargs.get('local_gb', 1024),
|
||||
# 'memory_mb': kwargs.get('memory_mb', 4096)},
|
||||
# 'driver': kwargs.get('driver', 'fake')}
|
||||
|
||||
# return self._create_request('audits', audit)
|
||||
|
||||
@base.handle_errors
|
||||
def delete_audit_template(self, uuid):
|
||||
"""Deletes an audit template having the specified UUID.
|
||||
|
||||
:param uuid: The unique identifier of the audit template.
|
||||
:return: A tuple with the server response and the response body.
|
||||
"""
|
||||
|
||||
return self._delete_request('audit_templates', uuid)
|
||||
|
||||
@base.handle_errors
|
||||
def update_audit_template(self, uuid, patch):
|
||||
"""Update the specified audit template.
|
||||
|
||||
:param uuid: The unique identifier of the audit template.
|
||||
:param patch: List of dicts representing json patches.
|
||||
:return: A tuple with the server response and the updated audit
|
||||
template.
|
||||
"""
|
||||
|
||||
return self._patch_request('audit_templates', uuid, patch)
|
||||
Reference in New Issue
Block a user