summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasyl Saienko <vsaienko@mirantis.com>2016-07-21 09:49:29 -0400
committerHarald Jensås <hjensas@redhat.com>2019-02-13 18:22:50 +0100
commite8a6d447f803c115ed57064e6fada3e9d6f30794 (patch)
tree905358ea39d7ccd121a95b8689a1599f9bcc3f0c
parentd15877f0fb2f629821c138a1742ff762595e8381 (diff)
downloadpython-ironicclient-e8a6d447f803c115ed57064e6fada3e9d6f30794.tar.gz
Add Events support
Adds support to POST events to the /v1/events API endpoint. Updates LAST_KNOWN_API_VERSION to 51. Co-Authored-By: Harald Jensås <hjensas@redhat.com> Story: 1304673 Task: 22149 Depends-On: https://review.openstack.org/631946 Change-Id: I6bc2d711687350ee3000b6898b68c3d05db62260
-rw-r--r--ironicclient/common/http.py2
-rw-r--r--ironicclient/tests/unit/v1/test_events.py58
-rw-r--r--ironicclient/v1/client.py2
-rw-r--r--ironicclient/v1/events.py29
-rw-r--r--releasenotes/notes/add-events-support-53c461d28abf010b.yaml12
5 files changed, 102 insertions, 1 deletions
diff --git a/ironicclient/common/http.py b/ironicclient/common/http.py
index 735cebc..57652bb 100644
--- a/ironicclient/common/http.py
+++ b/ironicclient/common/http.py
@@ -43,7 +43,7 @@ from ironicclient import exc
# http://specs.openstack.org/openstack/ironic-specs/specs/kilo/api-microversions.html # noqa
# for full details.
DEFAULT_VER = '1.9'
-LAST_KNOWN_API_VERSION = 50
+LAST_KNOWN_API_VERSION = 54
LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION)
LOG = logging.getLogger(__name__)
diff --git a/ironicclient/tests/unit/v1/test_events.py b/ironicclient/tests/unit/v1/test_events.py
new file mode 100644
index 0000000..c706932
--- /dev/null
+++ b/ironicclient/tests/unit/v1/test_events.py
@@ -0,0 +1,58 @@
+# 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 testtools
+
+from ironicclient.tests.unit import utils
+from ironicclient.v1 import events
+
+FAKE_EVENT = {"event": "type.event"}
+FAKE_NETWORK_PORT_EVENT = {
+ 'event': "network.bind_port",
+ 'port_id': '11111111-aaaa-bbbb-cccc-555555555555',
+ 'mac_address': 'de:ad:ca:fe:ba:be',
+ 'status': 'ACTIVE',
+ 'device_id': '22222222-aaaa-bbbb-cccc-555555555555',
+ 'binding:host_id': '22222222-aaaa-bbbb-cccc-555555555555',
+ 'binding:vnic_type': 'baremetal',
+}
+FAKE_EVENTS = {'events': [FAKE_EVENT]}
+FAKE_NETWORK_PORT_EVENTS = {'events': [FAKE_NETWORK_PORT_EVENT]}
+
+fake_responses = {
+ '/v1/events':
+ {
+ 'POST': (
+ {},
+ None
+ )
+ }
+}
+
+
+class EventManagerTest(testtools.TestCase):
+ def setUp(self):
+ super(EventManagerTest, self).setUp()
+ self.api = utils.FakeAPI(fake_responses)
+ self.mgr = events.EventManager(self.api)
+
+ def test_event(self):
+ evts = self.mgr.create(**FAKE_EVENTS)
+ expect = [('POST', '/v1/events', {}, FAKE_EVENTS)]
+ self.assertEqual(expect, self.api.calls)
+ self.assertIsNone(evts)
+
+ def test_network_port_event(self):
+ evts = self.mgr.create(**FAKE_NETWORK_PORT_EVENTS)
+ expect = [('POST', '/v1/events', {}, FAKE_NETWORK_PORT_EVENTS)]
+ self.assertEqual(expect, self.api.calls)
+ self.assertIsNone(evts)
diff --git a/ironicclient/v1/client.py b/ironicclient/v1/client.py
index 81f73d4..dc54804 100644
--- a/ironicclient/v1/client.py
+++ b/ironicclient/v1/client.py
@@ -23,6 +23,7 @@ from ironicclient import exc
from ironicclient.v1 import chassis
from ironicclient.v1 import conductor
from ironicclient.v1 import driver
+from ironicclient.v1 import events
from ironicclient.v1 import node
from ironicclient.v1 import port
from ironicclient.v1 import portgroup
@@ -99,6 +100,7 @@ class Client(object):
self.driver = driver.DriverManager(self.http_client)
self.portgroup = portgroup.PortgroupManager(self.http_client)
self.conductor = conductor.ConductorManager(self.http_client)
+ self.events = events.EventManager(self.http_client)
@property
def current_api_version(self):
diff --git a/ironicclient/v1/events.py b/ironicclient/v1/events.py
new file mode 100644
index 0000000..8c7b2f7
--- /dev/null
+++ b/ironicclient/v1/events.py
@@ -0,0 +1,29 @@
+#
+# Copyright 2016 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 ironicclient.common import base
+
+
+class Event(base.Resource):
+ def __repr__(self):
+ return "<Event: %s>" % self.name
+
+
+class EventManager(base.CreateManager):
+ resource_class = Event
+ _creation_attributes = ['events']
+ _resource_name = 'events'
diff --git a/releasenotes/notes/add-events-support-53c461d28abf010b.yaml b/releasenotes/notes/add-events-support-53c461d28abf010b.yaml
new file mode 100644
index 0000000..9cdeee4
--- /dev/null
+++ b/releasenotes/notes/add-events-support-53c461d28abf010b.yaml
@@ -0,0 +1,12 @@
+---
+features:
+ - |
+ Added ``Event`` resource , used to notify Ironic of external events.
+
+ .. Note:: Events are not intended for end-user usage. (Internal use only.)
+ - |
+ Added the ``client.events.create`` Python SDK method to support publishing
+ events to Ironic using the /v1/events API endpoint.
+ (available starting with API version 1.54).
+
+ .. Note:: Events are not intended for end-user usage. (Internal use only.)