Add test for compute server external event API

Adding test as well as the service client for the compute
server external event API
- https://docs.openstack.org/api-ref/compute/?expanded=run-events-detail#run-events

Change-Id: I1c9a99d036de760a15a5725db87ca4e9d6f2263d
This commit is contained in:
Ghanshyam Mann 2022-11-17 21:16:58 -06:00 committed by Ghanshyam
parent 2c6da1db39
commit 81bd0e9e19
7 changed files with 196 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
The ``server_external_events`` tempest client for compute
Server External Events API is implemented in this release.

View File

@ -0,0 +1,37 @@
# Copyright 2022 NEC Corporation. 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.api.compute import base
from tempest.lib import decorators
class ServerExternalEventsTest(base.BaseV2ComputeAdminTest):
"""Test server external events test"""
@decorators.idempotent_id('6bbf4723-61d2-4372-af55-7ba27f1c9ba6')
def test_create_server_external_events(self):
"""Test create a server and add some external events"""
server_id = self.create_test_server(wait_until='ACTIVE')['id']
events = [
{
"name": "network-changed",
"server_uuid": server_id,
}
]
client = self.os_admin.server_external_events_client
events_resp = client.create_server_external_events(
events=events)['events'][0]
self.assertEqual(server_id, events_resp['server_uuid'])
self.assertEqual('network-changed', events_resp['name'])
self.assertEqual(200, events_resp['code'])

View File

@ -144,6 +144,8 @@ class Manager(clients.ServiceClients):
self.tenant_networks_client = self.compute.TenantNetworksClient() self.tenant_networks_client = self.compute.TenantNetworksClient()
self.assisted_volume_snapshots_client = ( self.assisted_volume_snapshots_client = (
self.compute.AssistedVolumeSnapshotsClient()) self.compute.AssistedVolumeSnapshotsClient())
self.server_external_events_client = (
self.compute.ServerExternalEventsClient())
# NOTE: The following client needs special timeout values because # NOTE: The following client needs special timeout values because
# the API is a proxy for the other component. # the API is a proxy for the other component.

View File

@ -0,0 +1,55 @@
# Copyright 2022 NEC Corporation. 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.
create = {
'status_code': [200],
'response_body': {
'type': 'object',
'properties': {
'events': {
'type': 'array', 'minItems': 1,
'items': {
'type': 'object',
'properties': {
'server_uuid': {
'type': 'string', 'format': 'uuid'
},
'name': {
'type': 'string',
'enum': [
'network-changed',
'network-vif-plugged',
'network-vif-unplugged',
'network-vif-deleted'
],
},
'status': {
'type': 'string',
'enum': ['failed', 'completed', 'in-progress'],
},
'tag': {
'type': 'string', 'maxLength': 255,
},
'code': {'type': 'integer'},
},
'required': [
'server_uuid', 'name', 'code'],
'additionalProperties': False,
},
},
},
'required': ['events'],
'additionalProperties': False,
}
}

View File

@ -52,6 +52,8 @@ from tempest.lib.services.compute.security_group_rules_client import \
SecurityGroupRulesClient SecurityGroupRulesClient
from tempest.lib.services.compute.security_groups_client import \ from tempest.lib.services.compute.security_groups_client import \
SecurityGroupsClient SecurityGroupsClient
from tempest.lib.services.compute.server_external_events_client \
import ServerExternalEventsClient
from tempest.lib.services.compute.server_groups_client import \ from tempest.lib.services.compute.server_groups_client import \
ServerGroupsClient ServerGroupsClient
from tempest.lib.services.compute.servers_client import ServersClient from tempest.lib.services.compute.servers_client import ServersClient
@ -75,6 +77,6 @@ __all__ = ['AgentsClient', 'AggregatesClient', 'AssistedVolumeSnapshotsClient',
'MigrationsClient', 'NetworksClient', 'QuotaClassesClient', 'MigrationsClient', 'NetworksClient', 'QuotaClassesClient',
'QuotasClient', 'SecurityGroupDefaultRulesClient', 'QuotasClient', 'SecurityGroupDefaultRulesClient',
'SecurityGroupRulesClient', 'SecurityGroupsClient', 'SecurityGroupRulesClient', 'SecurityGroupsClient',
'ServerGroupsClient', 'ServersClient', 'ServicesClient', 'ServerExternalEventsClient', 'ServerGroupsClient', 'ServersClient',
'SnapshotsClient', 'TenantNetworksClient', 'TenantUsagesClient', 'ServicesClient', 'SnapshotsClient', 'TenantNetworksClient',
'VersionsClient', 'VolumesClient'] 'TenantUsagesClient', 'VersionsClient', 'VolumesClient']

View File

@ -0,0 +1,36 @@
# Copyright 2022 NEC Corporation. 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 oslo_serialization import jsonutils as json
from tempest.lib.api_schema.response.compute.v2_1 import \
server_external_events as schema
from tempest.lib.common import rest_client
from tempest.lib.services.compute import base_compute_client
class ServerExternalEventsClient(base_compute_client.BaseComputeClient):
def create_server_external_events(self, events):
"""Create Server External Events.
For a full list of available parameters, please refer to the official
API reference:
https://docs.openstack.org/api-ref/compute/#run-events
"""
post_body = json.dumps({'events': events})
resp, body = self.post("os-server-external-events", post_body)
body = json.loads(body)
self.validate_response(schema.create, resp, body)
return rest_client.ResponseBody(resp, body)

View File

@ -0,0 +1,56 @@
# Copyright 2022 NEC Corporation. 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.lib.services.compute import server_external_events_client
from tempest.tests.lib import fake_auth_provider
from tempest.tests.lib.services import base
class TestServerExternalEventsClient(base.BaseServiceTest):
events = [
{
"code": 200,
"name": "network-changed",
"server_uuid": "ff1df7b2-6772-45fd-9326-c0a3b05591c2",
"status": "completed",
"tag": "foo"
}
]
events_req = [
{
"name": "network-changed",
"server_uuid": "ff1df7b2-6772-45fd-9326-c0a3b05591c2",
}
]
def setUp(self):
super(TestServerExternalEventsClient, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
self.client = server_external_events_client.ServerExternalEventsClient(
fake_auth, 'compute', 'regionOne')
def _test_create_server_external_events(self, bytes_body=False):
expected = {"events": self.events}
self.check_service_client_function(
self.client.create_server_external_events,
'tempest.lib.common.rest_client.RestClient.post', expected,
bytes_body, events=self.events_req)
def test_create_server_external_events_str_body(self):
self._test_create_server_external_events(bytes_body=False)
def test_create_server_external_events_byte_body(self):
self._test_create_server_external_events(bytes_body=True)