Skip to content

Commit 5b321dd

Browse files
authored
feat(config): tests implemented (#612)
feat(config): tests implemented Reviewed-by: Anton Sidelnikov
1 parent bcc22ad commit 5b321dd

File tree

12 files changed

+247
-0
lines changed

12 files changed

+247
-0
lines changed

doc/source/sdk/guides/apig.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,3 +1462,23 @@ with a given SSL certificate.
14621462

14631463
.. literalinclude:: ../examples/apig/list_domain_for_cert.py
14641464
:lines: 16-22
1465+
1466+
Config
1467+
------
1468+
1469+
Querying Configurations
1470+
^^^^^^^^^^^^^^^^^^^^^^^
1471+
1472+
This example demonstrates how to query configurations.
1473+
1474+
.. literalinclude:: ../examples/apig/list_configs.py
1475+
:lines: 16-21
1476+
1477+
Querying Configurations for Gateway
1478+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1479+
1480+
This example demonstrates how to query configurations of a
1481+
specific gateway.
1482+
1483+
.. literalinclude:: ../examples/apig/list_configs_for_gateway.py
1484+
:lines: 16-22

doc/source/sdk/proxies/apig.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,9 @@ SSL Certificate Operations
201201
update_ssl_certificate, delete_ssl_certificate, bind_domain_to_certificate,
202202
unbind_domain_from_certificate, domains_for_certificate,
203203
bind_ssl_certificates_for_domain, unbind_ssl_certificates_for_domain
204+
205+
Configuration Operations
206+
^^^^^^^^^^^^^^^^^^^^^^^^
207+
.. autoclass:: otcextensions.sdk.apig.v2._proxy.Proxy
208+
:noindex:
209+
:members: configs, configs_for_gateway

doc/source/sdk/resources/apig/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ ApiGateway Resources
3636
v2/tag
3737
v2/ssl_certificate
3838
v2/ssl_domain
39+
v2/config
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
otcextensions.sdk.apig.v2.config
2+
================================
3+
4+
.. automodule:: otcextensions.sdk.apig.v2.config
5+
6+
The Config Class
7+
----------------
8+
9+
The ``Config`` class inherits from
10+
:class:`~otcextensions.sdk.sdk_resource.Resource`.
11+
12+
.. autoclass:: otcextensions.sdk.apig.v2.config.Config
13+
:members:

examples/apig/list_configs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
"""
14+
List Configs
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
configs = list(conn.apig.configs())
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
"""
14+
List Configs for Gateway
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
configs = list(conn.apig.configs_for_gateway(
22+
gateway_id="gateway_id"))

otcextensions/sdk/apig/v2/_proxy.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from otcextensions.sdk.apig.v2 import ssl_certificate as _ssl_certificate
4747
from otcextensions.sdk.apig.v2 import ssl_domain as _ssl_domain
4848
from otcextensions.sdk.apig.v2 import tag as _tag
49+
from otcextensions.sdk.apig.v2 import config as _config
4950

5051

5152
class Proxy(proxy.Proxy):
@@ -3433,3 +3434,38 @@ def unbind_ssl_certificates_for_domain(self, ssl_certificate, **attrs):
34333434
certificate_id=ssl_certificate.id,
34343435
**attrs
34353436
)
3437+
3438+
# ======== Configuration Management Methods ========
3439+
3440+
def configs(self, **attrs):
3441+
"""List all configuration items
3442+
3443+
This method retrieves all configuration items for the API Gateway
3444+
instance.
3445+
3446+
:param attrs: Optional query parameters for filtering the list,
3447+
such as limit, offset, or specific config attributes
3448+
3449+
:returns: A generator of
3450+
:class:`~otcextensions.sdk.apig.v2.config.Config` instances
3451+
"""
3452+
return self._list(
3453+
_config.Config,
3454+
paginated=False,
3455+
**attrs
3456+
)
3457+
3458+
def configs_for_gateway(self, gateway_id, **attrs):
3459+
"""Get configuration items for a specific gateway.
3460+
3461+
:param gateway_id: The ID of the gateway.
3462+
:param attrs: Additional parameters to be passed to the
3463+
underlying `Session.get` method.
3464+
:returns: A generator of configuration items.
3465+
"""
3466+
base_path = f'/apigw/instances/{gateway_id}/project/configs'
3467+
return self._list(
3468+
_config.Config,
3469+
paginated=False,
3470+
base_path=base_path,
3471+
**attrs,)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
from openstack import resource
13+
14+
15+
class Config(resource.Resource):
16+
base_path = '/apigw/instance/configs'
17+
resources_key = 'configs'
18+
allow_list = True
19+
20+
# Properties
21+
22+
#: The ID of the configuration item.
23+
config_id = resource.Body('config_id')
24+
#: The name of the configuration item.
25+
config_name = resource.Body('config_name')
26+
#: The value of the configuration item.
27+
config_value = resource.Body('config_value')
28+
#: The time when the configuration item was created.
29+
config_time = resource.Body('config_time')
30+
#: The time when the configuration item was last updated.
31+
remark = resource.Body('remark')
32+
#: Used quota of the gateway.
33+
used = resource.Body('used')
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
from otcextensions.tests.functional.sdk.apig import TestApiG
13+
14+
15+
class TestConfig(TestApiG):
16+
gateway_id = "560de602c9f74969a05ff01d401a53ed"
17+
18+
def setUp(self):
19+
super(TestConfig, self).setUp()
20+
21+
def test_list_config(self):
22+
configs = list(self.client.configs())
23+
self.assertGreater(len(configs), 0)
24+
25+
def test_list_config_for_gateway(self):
26+
configs = list(self.client.configs_for_gateway(
27+
gateway_id=TestConfig.gateway_id))
28+
self.assertGreater(len(configs), 0)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstack.tests.unit import base
14+
from otcextensions.sdk.apig.v2 import config
15+
16+
EXAMPLE_CONFIG = {
17+
'config_id': 'conf-123',
18+
'config_name': 'flow_control',
19+
'config_value': '1000',
20+
'config_time': '2025-01-01T12:00:00Z',
21+
'remark': 'Maximum requests per second',
22+
'used': '350'
23+
}
24+
25+
26+
class TestConfig(base.TestCase):
27+
28+
def test_basic(self):
29+
sot = config.Config()
30+
self.assertEqual('/apigw/instance/configs', sot.base_path)
31+
self.assertTrue(sot.allow_list)
32+
self.assertEqual('configs', sot.resources_key)
33+
34+
def test_make_it(self):
35+
sot = config.Config(**EXAMPLE_CONFIG)
36+
self.assertEqual('conf-123', sot.config_id)
37+
self.assertEqual('flow_control', sot.config_name)
38+
self.assertEqual('1000', sot.config_value)
39+
self.assertEqual('2025-01-01T12:00:00Z', sot.config_time)
40+
self.assertEqual('Maximum requests per second', sot.remark)
41+
self.assertEqual('350', sot.used)

0 commit comments

Comments
 (0)