From 32cd5fdb30d0920ff05c5997184b81f626781a4c Mon Sep 17 00:00:00 2001 From: anton-sidelnikov Date: Thu, 30 Jan 2025 14:06:05 +0100 Subject: [PATCH 1/4] [Feat.] FunctionGraph Test Events --- doc/source/sdk/guides/function_graph.rst | 54 +++++++++++ doc/source/sdk/proxies/function_graph.rst | 8 ++ .../sdk/resources/function_graph/index.rst | 1 + .../sdk/resources/function_graph/v2/event.rst | 13 +++ examples/function_graph/create_event.py | 39 ++++++++ examples/function_graph/delete_event.py | 40 ++++++++ examples/function_graph/get_event.py | 42 ++++++++ examples/function_graph/list_events.py | 24 +++++ examples/function_graph/update_event.py | 45 +++++++++ otcextensions/sdk/function_graph/v2/_proxy.py | 82 ++++++++++++++++ otcextensions/sdk/function_graph/v2/event.py | 51 ++++++++++ .../sdk/function_graph/v2/test_event.py | 96 ++++++++++++++++++ .../unit/sdk/function_graph/v2/test_event.py | 39 ++++++++ .../unit/sdk/function_graph/v2/test_proxy.py | 97 +++++++++++++++++++ 14 files changed, 631 insertions(+) create mode 100644 doc/source/sdk/resources/function_graph/v2/event.rst create mode 100644 examples/function_graph/create_event.py create mode 100644 examples/function_graph/delete_event.py create mode 100644 examples/function_graph/get_event.py create mode 100644 examples/function_graph/list_events.py create mode 100644 examples/function_graph/update_event.py create mode 100644 otcextensions/sdk/function_graph/v2/event.py create mode 100644 otcextensions/tests/functional/sdk/function_graph/v2/test_event.py create mode 100644 otcextensions/tests/unit/sdk/function_graph/v2/test_event.py diff --git a/doc/source/sdk/guides/function_graph.rst b/doc/source/sdk/guides/function_graph.rst index bf7966749..3cbf93850 100644 --- a/doc/source/sdk/guides/function_graph.rst +++ b/doc/source/sdk/guides/function_graph.rst @@ -17,6 +17,8 @@ It is the minimum unit that can run independently. A function can be triggered by triggers and automatically schedule required resources and environments to achieve expected results. +Function Lifecycle +------------------ Create Function ^^^^^^^^^^^^^^^ @@ -106,6 +108,9 @@ This API is used to update the maximum number of instances of a function. .. literalinclude:: ../examples/function_graph/update_function_metadata.py :lines: 16-23 +Function Invocation +------------------- + Function Execution Synchronously ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,6 +127,9 @@ This API is used to execute a function synchronously. .. literalinclude:: ../examples/function_graph/async_function_invocation.py :lines: 16-27 +Function Quotas +--------------- + Querying Tenant Quotas ^^^^^^^^^^^^^^^^^^^^^^ @@ -130,6 +138,9 @@ This API is used to query tenant quotas. .. literalinclude:: ../examples/function_graph/list_quotas.py :lines: 16-24 +Dependencies +------------ + Querying Dependencies ^^^^^^^^^^^^^^^^^^^^^ @@ -169,3 +180,46 @@ This API is used to delete a dependency version. .. literalinclude:: ../examples/function_graph/delete_dependency_version.py :lines: 16-31 + +Test Events +----------- + +Querying Test Events of a Function +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This API is used to query the test events of a function. + +.. literalinclude:: ../examples/function_graph/list_events.py + :lines: 16-24 + +Creating a Test Event +^^^^^^^^^^^^^^^^^^^^^ + +This API is used to query the test events of a function. + +.. literalinclude:: ../examples/function_graph/create_event.py + :lines: 16-39 + +Deleting a Test Event +^^^^^^^^^^^^^^^^^^^^^ + +This API is used to delete a test event. + +.. literalinclude:: ../examples/function_graph/delete_event.py + :lines: 16-40 + +Obtaining the Details of a Test Event +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This API is used to query the details of a test event. + +.. literalinclude:: ../examples/function_graph/get_event.py + :lines: 16-42 + +Updating a Test Event +^^^^^^^^^^^^^^^^^^^^^ + +This API is used to update a test event. + +.. literalinclude:: ../examples/function_graph/update_event.py + :lines: 16-45 diff --git a/doc/source/sdk/proxies/function_graph.rst b/doc/source/sdk/proxies/function_graph.rst index 770ac7e23..2acfd2034 100644 --- a/doc/source/sdk/proxies/function_graph.rst +++ b/doc/source/sdk/proxies/function_graph.rst @@ -42,3 +42,11 @@ Dependencies :noindex: :members: dependencies, create_dependency_version, delete_dependency_version, dependency_versions, get_dependency_version + +Events +^^^^^^ + +.. autoclass:: otcextensions.sdk.function_graph.v2._proxy.Proxy + :noindex: + :members: create_event, delete_event, events, + get_event, update_event diff --git a/doc/source/sdk/resources/function_graph/index.rst b/doc/source/sdk/resources/function_graph/index.rst index 3af9bc732..a0ac69002 100644 --- a/doc/source/sdk/resources/function_graph/index.rst +++ b/doc/source/sdk/resources/function_graph/index.rst @@ -8,3 +8,4 @@ FunctionGraph Resources v2/function_invocation v2/quota v2/dependency + v2/event diff --git a/doc/source/sdk/resources/function_graph/v2/event.rst b/doc/source/sdk/resources/function_graph/v2/event.rst new file mode 100644 index 000000000..4d59692b6 --- /dev/null +++ b/doc/source/sdk/resources/function_graph/v2/event.rst @@ -0,0 +1,13 @@ +otcextensions.sdk.function_graph.v2.event +========================================= + +.. automodule:: otcextensions.sdk.function_graph.v2.event + +The Event Class +--------------- + +The ``Event`` class inherits from +:class:`~otcextensions.sdk.sdk_resource.Resource`. + +.. autoclass:: otcextensions.sdk.function_graph.v2.event.Event + :members: diff --git a/examples/function_graph/create_event.py b/examples/function_graph/create_event.py new file mode 100644 index 000000000..d57811962 --- /dev/null +++ b/examples/function_graph/create_event.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# 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 new event +""" +import openstack +from otcextensions import sdk + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') +sdk.register_otc_extensions(conn) + +event_attrs = { + 'name': 'event-xx', + 'content': 'eyJrIjoidiJ9' +} +func_attrs = { + 'func_name': 'test-function', + 'package': 'default', + 'runtime': 'Python3.9', + 'handler': 'index.handler', + 'timeout': 30, + 'memory_size': 128, + 'code_type': 'inline', +} +fg = conn.functiongraph.create_function(**func_attrs) +ev = conn.functiongraph.create_event( + fg, **event_attrs +) diff --git a/examples/function_graph/delete_event.py b/examples/function_graph/delete_event.py new file mode 100644 index 000000000..984a4e1b2 --- /dev/null +++ b/examples/function_graph/delete_event.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# 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. +""" +Delete event +""" +import openstack +from otcextensions import sdk + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') +sdk.register_otc_extensions(conn) + +event_attrs = { + 'name': 'event-xx', + 'content': 'eyJrIjoidiJ9' +} +func_attrs = { + 'func_name': 'test-function', + 'package': 'default', + 'runtime': 'Python3.9', + 'handler': 'index.handler', + 'timeout': 30, + 'memory_size': 128, + 'code_type': 'inline', +} +fg = conn.functiongraph.create_function(**func_attrs) +ev = conn.functiongraph.create_event( + fg, **event_attrs +) +conn.functiongraph.delete_event(fg, ev) diff --git a/examples/function_graph/get_event.py b/examples/function_graph/get_event.py new file mode 100644 index 000000000..f29d7ca47 --- /dev/null +++ b/examples/function_graph/get_event.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# 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. +""" +Get event +""" +import openstack +from otcextensions import sdk + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') +sdk.register_otc_extensions(conn) + +event_attrs = { + 'name': 'event-xx', + 'content': 'eyJrIjoidiJ9' +} +func_attrs = { + 'func_name': 'test-function', + 'package': 'default', + 'runtime': 'Python3.9', + 'handler': 'index.handler', + 'timeout': 30, + 'memory_size': 128, + 'code_type': 'inline', +} +fg = conn.functiongraph.create_function(**func_attrs) +ev = conn.functiongraph.create_event( + fg, **event_attrs +) +e = conn.functiongraph.get_event( + fg, ev) +print(e) diff --git a/examples/function_graph/list_events.py b/examples/function_graph/list_events.py new file mode 100644 index 000000000..3300ecb4e --- /dev/null +++ b/examples/function_graph/list_events.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# 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. +""" +Get all functions +""" +import openstack +from otcextensions import sdk + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') +sdk.register_otc_extensions(conn) + +for fg in conn.functiongraph.events(func_urn='urn'): + print(fg) diff --git a/examples/function_graph/update_event.py b/examples/function_graph/update_event.py new file mode 100644 index 000000000..efc5080b3 --- /dev/null +++ b/examples/function_graph/update_event.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# 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. +""" +Update event +""" +import openstack +from otcextensions import sdk + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') +sdk.register_otc_extensions(conn) + +event_attrs = { + 'name': 'event-xx', + 'content': 'eyJrIjoidiJ9' +} +func_attrs = { + 'func_name': 'test-function', + 'package': 'default', + 'runtime': 'Python3.9', + 'handler': 'index.handler', + 'timeout': 30, + 'memory_size': 128, + 'code_type': 'inline', +} +fg = conn.functiongraph.create_function(**func_attrs) +ev = conn.functiongraph.create_event( + fg, **event_attrs +) +event_attrs = { + 'content': 'ewogICAgImJvZHkiOiAiIiwKICAgICJy' +} +updated = conn.functiongraph.update_event( + fg, ev, **event_attrs) +print(updated) diff --git a/otcextensions/sdk/function_graph/v2/_proxy.py b/otcextensions/sdk/function_graph/v2/_proxy.py index cd9fc1de8..a9e3a69db 100644 --- a/otcextensions/sdk/function_graph/v2/_proxy.py +++ b/otcextensions/sdk/function_graph/v2/_proxy.py @@ -16,6 +16,7 @@ from otcextensions.sdk.function_graph.v2 import function_invocation as _fi from otcextensions.sdk.function_graph.v2 import quota as _quota from otcextensions.sdk.function_graph.v2 import dependency as _d +from otcextensions.sdk.function_graph.v2 import event as _event class Proxy(proxy.Proxy): @@ -251,3 +252,84 @@ def get_dependency_version(self, dependency): base_path = (f"/fgs/dependencies/{dependency.dep_id}" f"/version/{dependency.version}") return self._get(_d.Dependency, base_path=base_path, requires_id=False) + + # ======== Test Events Methods ======== + + def create_event(self, function, **attrs): + """Create a new event from attributes. + + :param function: The URN or instance of the Function to create + event in. + :param dict attrs: Keyword arguments to create an Event. + :returns: The created Event instance. + :rtype: :class:`~otcextensions.sdk.function_graph.v2.event.Event` + """ + function = self._get_resource(_function.Function, function) + function_urn = function.func_urn.rpartition(":")[0] + return self._create( + _event.Event, function_urn=function_urn, **attrs + ) + + def delete_event(self, function, event, ignore_missing=True): + """Delete an event. + + :param function: The URN or instance of the Function to delete + event from. + :param ignore_missing: When False, + `openstack.exceptions.ResourceNotFound` + will be raised when the tag does not exist. + When True, no exception will be set when attempting + to delete a nonexistent event. + :param event: The instance of the Event to delete. + :returns: ``None`` + """ + function = self._get_resource(_function.Function, function) + function_urn = function.func_urn.rpartition(":")[0] + return self._delete( + _event.Event, event, + function_urn=function_urn, ignore_missing=ignore_missing + ) + + def events(self, func_urn): + """List all events. + + :param func_urn: The URN of the Function to fetch + events from. + :returns: A generator of Event instances. + """ + function_urn = func_urn.rpartition(":")[0] + return self._list(_event.Event, function_urn=function_urn) + + def get_event(self, function, event): + """Get one event by ID. + + :param event: key id or an instance of + :class:`~otcextensions.sdk.function_graph.v2.event.Event` + :param function: The value can be the ID of a function or + a :class:`~otcextensions.sdk.function_graph.v2.function.Function` + instance. + :returns: instance of + :class:`~otcextensions.sdk.function_graph.v2.event.Event` + """ + function = self._get_resource(_function.Function, function) + return self._get( + _event.Event, event, + function_urn=function.func_urn + ) + + def update_event(self, function, event, **attrs): + """Update an event from attributes. + + :param event: key id or an instance of + :class:`~otcextensions.sdk.function_graph.v2.event.Event` + :param function: The URN or instance of the Function to update + event in. + :param dict attrs: Keyword arguments to update an Event. + :returns: The updated Event instance. + :rtype: :class:`~otcextensions.sdk.function_graph.v2.event.Event` + """ + function = self._get_resource(_function.Function, function) + function_urn = function.func_urn.rpartition(":")[0] + return self._update( + _event.Event, event, function_urn=function_urn, **attrs + ) diff --git a/otcextensions/sdk/function_graph/v2/event.py b/otcextensions/sdk/function_graph/v2/event.py new file mode 100644 index 000000000..431550012 --- /dev/null +++ b/otcextensions/sdk/function_graph/v2/event.py @@ -0,0 +1,51 @@ +# 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 openstack import resource + + +class ListEvents(resource.Resource): + id = resource.Body('id', type=str) + last_modified = resource.Body('last_modified', type=int) + name = resource.Body('name', type=str) + + +class Event(resource.Resource): + base_path = '/fgs/functions/%(function_urn)s/events' + + # Capabilities + allow_create = True + allow_fetch = True + allow_delete = True + allow_list = True + allow_commit = True + + # Properties + function_urn = resource.URI('function_urn', type=str) + #: Test event name. Max. 25 of letters, digits, hyphens (-), + #: and underscores (_). Start with a letter, + #: and end with a letter or digit. + name = resource.Body('name', type=str) + #: Test event content, which is a Base64-encoded JSON character string. + content = resource.Body('content', type=str) + + # Attributes + #: Test event ID. + id = resource.Body('id', type=str) + #: Total number of test events. + count = resource.Body('count', type=int) + #: Total number of test events. + events = resource.Body('events', type=list, list_type=ListEvents) + #: Next read location. + next_marker = resource.Body('next_marker', type=int) + #: Last update time. + updated_at = resource.Body('last_modified', type=int) diff --git a/otcextensions/tests/functional/sdk/function_graph/v2/test_event.py b/otcextensions/tests/functional/sdk/function_graph/v2/test_event.py new file mode 100644 index 000000000..18c8e31cf --- /dev/null +++ b/otcextensions/tests/functional/sdk/function_graph/v2/test_event.py @@ -0,0 +1,96 @@ +# 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 uuid +from otcextensions.sdk.function_graph.v2 import function +from otcextensions.tests.functional import base + +from openstack import _log + +_logger = _log.setup_logging('openstack') + + +class TestFunctionEvent(base.BaseFunctionalTest): + ID = None + uuid = uuid.uuid4().hex[:8] + + def setUp(self): + super(TestFunctionEvent, self).setUp() + self.attrs = { + 'func_name': 'test-function-' + self.uuid, + 'package': 'default', + 'runtime': 'Python3.9', + 'handler': 'index.handler', + 'timeout': 30, + 'memory_size': 128, + 'code_type': 'inline', + 'func_code': { + 'file': 'CmltcG9ydCBqc29uCgpkZWYgaGFuZGxlcihldmVudCwgY29udGV4d' + 'Ck6CiAgICB0cnk6CiAgICAgICAgIyBQYXJzZSB0aGUgaW5wdXQgZX' + 'ZlbnQgKGRhdGEpCiAgICAgICAgaW5wdXRfZGF0YSA9IGpzb24ubG9' + 'hZHMoZXZlbnQpCiAgICAgICAgCiAgICAgICAgIyBQcmludCB0aGUg' + 'cHJvdmlkZWQgZGF0YQogICAgICAgIHByaW50KCJSZWNlaXZlZCBkY' + 'XRhOiIsIGlucHV0X2RhdGEpCiAgICAgICAgCiAgICAgICAgIyBSZX' + 'R1cm4gYSByZXNwb25zZQogICAgICAgIHJlc3BvbnNlID0gewogICA' + 'gICAgICAgICAic3RhdHVzQ29kZSI6IDIwMCwKICAgICAgICAgICAg' + 'ImJvZHkiOiBmIkRhdGEgcmVjZWl2ZWQ6IHtpbnB1dF9kYXRhfSIKI' + 'CAgICAgICB9CiAgICAgICAgcmV0dXJuIGpzb24uZHVtcHMocmVzcG' + '9uc2UpCgogICAgZXhjZXB0IEV4Y2VwdGlvbiBhcyBlOgogICAgICA' + 'gICMgSGFuZGxlIGVycm9ycwogICAgICAgIGVycm9yX3Jlc3BvbnNl' + 'ID0gewogICAgICAgICAgICAic3RhdHVzQ29kZSI6IDUwMCwKICAgI' + 'CAgICAgICAgImJvZHkiOiBmIkVycm9yOiB7c3RyKGUpfSIKICAgIC' + 'AgICB9CiAgICAgICAgcmV0dXJuIGpzb24uZHVtcHMoZXJyb3JfcmV' + 'zcG9uc2UpCg==' + } + } + + self.NAME = 'test-function-' + self.uuid + self.UPDATE_NAME = 'test-function-upd-' + self.uuid + self.function = self.conn.functiongraph.create_function(**self.attrs) + assert isinstance(self.function, function.Function) + self.assertEqual(self.NAME, self.function.func_name) + + self.event_attrs = { + 'name': 'event-xx', + 'content': 'eyJrIjoidiJ9' + } + self.event = self.conn.functiongraph.create_event( + self.function, **self.event_attrs + ) + self.ID = self.event.id + + self.addCleanup( + self.conn.functiongraph.delete_function, + self.function + ) + self.addCleanup( + self.conn.functiongraph.delete_event, + self.function, self.event + ) + + def test_function_events(self): + elist = list(self.conn.functiongraph.events( + func_urn=self.function.func_urn)) + self.assertIn(self.ID, elist[0].events[0].id) + + def test_get_function_event(self): + e = self.conn.functiongraph.get_event( + self.function, self.event) + self.assertIn(self.ID, e.id) + + def test_update_function_event(self): + event_attrs = { + 'content': 'ewogICAgImJvZHkiOiAiIiwKICAgICJy' + } + updated = self.conn.functiongraph.update_event( + self.function, self.event, **event_attrs) + self.assertIn(event_attrs['content'], updated.content) diff --git a/otcextensions/tests/unit/sdk/function_graph/v2/test_event.py b/otcextensions/tests/unit/sdk/function_graph/v2/test_event.py new file mode 100644 index 000000000..b90e71737 --- /dev/null +++ b/otcextensions/tests/unit/sdk/function_graph/v2/test_event.py @@ -0,0 +1,39 @@ +# 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 openstack.tests.unit import base + +from otcextensions.sdk.function_graph.v2 import event + + +EXAMPLE = { + 'name': 'event-xx', + 'content': 'eyJrIjoidiJ9' +} + + +class TestFunctionInvocation(base.TestCase): + + def test_basic(self): + sot = event.Event() + path = '/fgs/functions/%(function_urn)s/events' + self.assertEqual(path, sot.base_path) + self.assertTrue(sot.allow_create) + self.assertTrue(sot.allow_list) + self.assertTrue(sot.allow_delete) + self.assertTrue(sot.allow_fetch) + self.assertTrue(sot.allow_commit) + + def test_make_it(self): + sot = event.Event(**EXAMPLE) + self.assertEqual(EXAMPLE['name'], sot.name) + self.assertEqual(EXAMPLE['content'], sot.content) diff --git a/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py b/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py index b899729dd..d8577ab52 100644 --- a/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py +++ b/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py @@ -16,6 +16,7 @@ from otcextensions.sdk.function_graph.v2 import function_invocation as _fi from otcextensions.sdk.function_graph.v2 import dependency as _d from otcextensions.sdk.function_graph.v2 import quota as _q +from otcextensions.sdk.function_graph.v2 import event as _event from openstack.tests.unit import test_proxy_base @@ -256,3 +257,99 @@ def test_get_dependency_version(self): expected_args=[], expected_kwargs={"requires_id": False} ) + + +class TestFgEvents(TestFgProxy): + def test_events(self): + func_urn = ('urn:fss:eu-de:45c274f200d2498683982c8741fb76ac:' + 'function:default:access-mysql-js-1213-1737554083545:' + 'latest') + self.verify_list( + self.proxy.events, + _event.Event, + method_args=[func_urn], + expected_args=[], + expected_kwargs={ + 'function_urn': func_urn.rpartition(":")[0] + }, + ) + + def test_create_event(self): + func = _function.Function( + name='test', + func_urn='urn:fss:eu-de:45c274f200d2498683982c8741fb76ac:' + 'function:default:access-mysql-js-1213-1737554083545:' + 'latest' + ) + self.verify_create( + self.proxy.create_event, + _event.Event, + method_kwargs={ + 'function': func, + 'name': 'test_event' + }, + expected_kwargs={ + 'function_urn': func.func_urn.rpartition(":")[0], + 'name': 'test_event'} + ) + + def test_delete_event(self): + func = _function.Function( + name='test', + func_urn='urn:fss:eu-de:45c274f200d2498683982c8741fb76ac:' + 'function:default:access-mysql-js-1213-1737554083545:' + 'latest' + ) + event = _event.Event( + name='test', + ) + self.verify_delete( + self.proxy.delete_event, + _event.Event, + method_args=[func, event], + expected_args=[event], + expected_kwargs={'function_urn': func.func_urn.rpartition(":")[0]} + ) + + def test_update_event(self): + func = _function.Function( + name='test', + func_urn='urn:fss:eu-de:45c274f200d2498683982c8741fb76ac:' + 'function:default:access-mysql-js-1213-1737554083545:' + 'latest' + ) + event = _event.Event( + name='test', + ) + self.verify_update( + self.proxy.update_event, + _event.Event, + method_args=[func, event], + expected_args=[event], + expected_kwargs={ + 'function_urn': func.func_urn.rpartition(":")[0], + 'x': 1, + 'y': 2, + 'z': 3 + } + ) + + def test_get_event(self): + func = _function.Function( + name='test', + func_urn='urn:fss:eu-de:45c274f200d2498683982c8741fb76ac:' + 'function:default:access-mysql-js-1213-1737554083545:' + 'latest' + ) + event = _event.Event( + name='test', + ) + self.verify_get( + self.proxy.get_event, + _event.Event, + method_args=[func, event], + expected_args=[event], + expected_kwargs={ + 'function_urn': func.func_urn, + } + ) From 26f60c37ee74cf3bfe13622e883f8e89abaf6ceb Mon Sep 17 00:00:00 2001 From: anton-sidelnikov Date: Thu, 30 Jan 2025 14:08:30 +0100 Subject: [PATCH 2/4] [Style] rn --- releasenotes/notes/fg-events-2c91f9554d5e386c.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/fg-events-2c91f9554d5e386c.yaml diff --git a/releasenotes/notes/fg-events-2c91f9554d5e386c.yaml b/releasenotes/notes/fg-events-2c91f9554d5e386c.yaml new file mode 100644 index 000000000..cf63e512d --- /dev/null +++ b/releasenotes/notes/fg-events-2c91f9554d5e386c.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add FGS events support. \ No newline at end of file From 10a6d897d56ee720d196b618c61e1d53d9b33afa Mon Sep 17 00:00:00 2001 From: anton-sidelnikov Date: Thu, 30 Jan 2025 14:18:35 +0100 Subject: [PATCH 3/4] [Fix] pep --- .../tests/unit/sdk/function_graph/v2/test_proxy.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py b/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py index d8577ab52..28fa007a0 100644 --- a/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py +++ b/otcextensions/tests/unit/sdk/function_graph/v2/test_proxy.py @@ -318,9 +318,7 @@ def test_update_event(self): 'function:default:access-mysql-js-1213-1737554083545:' 'latest' ) - event = _event.Event( - name='test', - ) + event = _event.Event(name='test') self.verify_update( self.proxy.update_event, _event.Event, @@ -341,9 +339,7 @@ def test_get_event(self): 'function:default:access-mysql-js-1213-1737554083545:' 'latest' ) - event = _event.Event( - name='test', - ) + event = _event.Event(name='test') self.verify_get( self.proxy.get_event, _event.Event, From e2c5307413a66e79e43023c88a62f84a9edea6f7 Mon Sep 17 00:00:00 2001 From: anton-sidelnikov Date: Thu, 30 Jan 2025 15:03:19 +0100 Subject: [PATCH 4/4] [Fix] licence notice --- .../tests/functional/sdk/function_graph/v2/test_event.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/otcextensions/tests/functional/sdk/function_graph/v2/test_event.py b/otcextensions/tests/functional/sdk/function_graph/v2/test_event.py index 18c8e31cf..0c64d3d9a 100644 --- a/otcextensions/tests/functional/sdk/function_graph/v2/test_event.py +++ b/otcextensions/tests/functional/sdk/function_graph/v2/test_event.py @@ -1,11 +1,11 @@ -# Licensed under the Apache License, Version 2.0 (the 'License'); you may +# 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 +# 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.