Merge "Add log resource client"
diff --git a/releasenotes/notes/log-resource-client-20e58a295f729902.yaml b/releasenotes/notes/log-resource-client-20e58a295f729902.yaml
new file mode 100644
index 0000000..405fc5f
--- /dev/null
+++ b/releasenotes/notes/log-resource-client-20e58a295f729902.yaml
@@ -0,0 +1,5 @@
+---
+features:
+ - |
+ Add a new client to lists, creates, shows information for,
+ and updates neutron log resource.
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index b6bf369..260ba74 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -84,6 +84,7 @@
cls.network_versions_client = cls.os_primary.network_versions_client
cls.service_providers_client = cls.os_primary.service_providers_client
cls.tags_client = cls.os_primary.tags_client
+ cls.log_resource_client = cls.os_primary.log_resource_client
@classmethod
def resource_setup(cls):
diff --git a/tempest/clients.py b/tempest/clients.py
index 6080f01..ebf2540 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -73,6 +73,7 @@
self.qos_min_bw_client = self.network.QosMinimumBandwidthRulesClient()
self.segments_client = self.network.SegmentsClient()
self.trunks_client = self.network.TrunksClient()
+ self.log_resource_client = self.network.LogResourceClient()
def _set_image_clients(self):
if CONF.service_available.glance:
diff --git a/tempest/lib/services/network/__init__.py b/tempest/lib/services/network/__init__.py
index 7e57499..fc85140 100644
--- a/tempest/lib/services/network/__init__.py
+++ b/tempest/lib/services/network/__init__.py
@@ -15,6 +15,7 @@
from tempest.lib.services.network.agents_client import AgentsClient
from tempest.lib.services.network.extensions_client import ExtensionsClient
from tempest.lib.services.network.floating_ips_client import FloatingIPsClient
+from tempest.lib.services.network.log_resource_client import LogResourceClient
from tempest.lib.services.network.metering_label_rules_client import \
MeteringLabelRulesClient
from tempest.lib.services.network.metering_labels_client import \
@@ -45,4 +46,4 @@
'QosClient', 'QosMinimumBandwidthRulesClient', 'QuotasClient',
'RoutersClient', 'SecurityGroupRulesClient', 'SecurityGroupsClient',
'SegmentsClient', 'ServiceProvidersClient', 'SubnetpoolsClient',
- 'SubnetsClient', 'TagsClient', 'TrunksClient']
+ 'SubnetsClient', 'TagsClient', 'TrunksClient', 'LogResourceClient']
diff --git a/tempest/lib/services/network/log_resource_client.py b/tempest/lib/services/network/log_resource_client.py
new file mode 100644
index 0000000..727b138
--- /dev/null
+++ b/tempest/lib/services/network/log_resource_client.py
@@ -0,0 +1,74 @@
+# Copyright 2021 Red Hat, 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.lib.services.network import base
+
+
+class LogResourceClient(base.BaseNetworkClient):
+
+ def create_log(self, **kwargs):
+ """Creates a log resource.
+
+ Creates a log resource by using the configuration that you define in
+ the request object.
+
+ For a full list of available parameters, please refer to the official
+ API reference:
+ https://docs.openstack.org/api-ref/network/v2/index.html#create-log
+ """
+ uri = '/log/logs/'
+ post_data = {'log': kwargs}
+ return self.create_resource(uri, post_data)
+
+ def update_log(self, log_id, **kwargs):
+ """Updates a log resource.
+
+ For a full list of available parameters, please refer to the official
+ API reference:
+ https://docs.openstack.org/api-ref/network/v2/index.html#update-log
+ """
+ uri = '/log/logs/%s' % log_id
+ post_data = {'log': kwargs}
+ return self.update_resource(uri, post_data)
+
+ def show_log(self, log_id, **fields):
+ """Shows details for a log id.
+
+ For a full list of available parameters, please refer to the official
+ API reference:
+ https://docs.openstack.org/api-ref/network/v2/index.html#show-log
+ """
+ uri = '/log/logs/%s' % log_id
+ return self.show_resource(uri, **fields)
+
+ def delete_log(self, log_id):
+ """Deletes a log resource.
+
+ For a full list of available parameters, please refer to the official
+ API reference:
+ https://docs.openstack.org/api-ref/network/v2/index.html#delete-log
+ """
+ uri = '/log/logs/%s' % log_id
+ return self.delete_resource(uri)
+
+ def list_logs(self, **filters):
+ """Lists Logs.
+
+ For a full list of available parameters, please refer to the official
+ API reference:
+ https://docs.openstack.org/api-ref/network/v2/index.html#list-logs
+ """
+ uri = '/log/logs'
+ return self.list_resources(uri, **filters)
diff --git a/tempest/tests/lib/services/network/test_log_resource_client.py b/tempest/tests/lib/services/network/test_log_resource_client.py
new file mode 100644
index 0000000..ef502bc
--- /dev/null
+++ b/tempest/tests/lib/services/network/test_log_resource_client.py
@@ -0,0 +1,145 @@
+# Copyright 2021 Red Hat, 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.
+
+import copy
+
+from tempest.lib.services.network import log_resource_client
+from tempest.tests.lib import fake_auth_provider
+from tempest.tests.lib.services import base
+
+
+class TestLogResourceClient(base.BaseServiceTest):
+
+ FAKE_LOGS = {
+ "logs": [
+ {
+ "name": "security group log1",
+ "description": "Log for test demo.",
+ "id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7",
+ "project_id": "92a5a4f4245a4abbafacb7ca73b027b0",
+ "tenant_id": "92a5a4f4245a4abbafacb7ca73b027b0",
+ "created_at": "2018-04-03T21:03:04Z",
+ "updated_at": "2018-04-03T21:03:04Z",
+ "enabled": True,
+ "revision_number": 1,
+ "resource_type": "security_group",
+ "resource_id": None,
+ "target_id": None,
+ "event": "ALL"
+ },
+ {
+ "name": "security group log2",
+ "description": "Log for test demo.",
+ "id": "46ebaec1-0570-43ac-82f6-60d2b03168c4",
+ "project_id": "82a5a4f4245a4abbafacb7ca73b027b0",
+ "tenant_id": "82a5a4f4245a4abbafacb7ca73b027b0",
+ "created_at": "2018-04-03T21:04:04Z",
+ "updated_at": "2018-04-03T21:04:04Z",
+ "enabled": True,
+ "revision_number": 2,
+ "resource_type": "security_group",
+ "resource_id": None,
+ "target_id": None,
+ "event": "ALL"
+ }
+ ]
+ }
+
+ FAKE_LOG_ID = "2f245a7b-796b-4f26-9cf9-9e82d248fda7"
+
+ def setUp(self):
+ super(TestLogResourceClient, self).setUp()
+ fake_auth = fake_auth_provider.FakeAuthProvider()
+ self.log_resource_client = log_resource_client.LogResourceClient(
+ fake_auth, "network", "regionOne")
+
+ def _test_list_logs(self, bytes_body=False):
+ self.check_service_client_function(
+ self.log_resource_client.list_logs,
+ "tempest.lib.common.rest_client.RestClient.get",
+ self.FAKE_LOGS,
+ bytes_body,
+ 200)
+
+ def _test_show_log(self, bytes_body=False):
+ self.check_service_client_function(
+ self.log_resource_client.show_log,
+ "tempest.lib.common.rest_client.RestClient.get",
+ {"log": self.FAKE_LOGS["logs"][0]},
+ bytes_body,
+ 200,
+ log_id=self.FAKE_LOG_ID)
+
+ def _test_create_log(self, bytes_body=False):
+ self.check_service_client_function(
+ self.log_resource_client.create_log,
+ "tempest.lib.common.rest_client.RestClient.post",
+ {"logs": self.FAKE_LOGS["logs"][1]},
+ bytes_body,
+ 201,
+ log_id="2f245a7b-796b-4f26-9cf9-9e82d248fda7")
+
+ def _test_update_log(self, bytes_body=False):
+ update_kwargs = {
+ "tenant_id": "83a5a4f4245a4abbafacb7ca73b027b0"
+ }
+
+ resp_body = {
+ "logs": copy.deepcopy(
+ self.FAKE_LOGS["logs"][0]
+ )
+ }
+ resp_body["logs"].update(update_kwargs)
+
+ self.check_service_client_function(
+ self.log_resource_client.update_log,
+ "tempest.lib.common.rest_client.RestClient.put",
+ resp_body,
+ bytes_body,
+ 200,
+ log_id=self.FAKE_LOG_ID,
+ **update_kwargs)
+
+ def test_list_logs_with_str_body(self):
+ self._test_list_logs()
+
+ def test_list_logs_with_bytes_body(self):
+ self._test_list_logs(bytes_body=True)
+
+ def test_create_log_with_str_body(self):
+ self._test_create_log()
+
+ def test_create_log_with_bytes_body(self):
+ self._test_create_log(bytes_body=True)
+
+ def test_show_log_with_str_body(self):
+ self._test_show_log()
+
+ def test_show_log_with_bytes_body(self):
+ self._test_show_log(bytes_body=True)
+
+ def test_update_log_with_str_body(self):
+ self._test_update_log()
+
+ def test_update_log_with_bytes_body(self):
+ self._test_update_log(bytes_body=True)
+
+ def test_delete_log(self):
+ self.check_service_client_function(
+ self.log_resource_client.delete_log,
+ 'tempest.lib.common.rest_client.RestClient.delete',
+ {},
+ status=204,
+ log_id=self.FAKE_LOG_ID)