Add instance_ha service
This patch targets to support instance_ha service for masakari by openstacksdk. Change-Id: I9b2d140065390d94dda532c39777cf691775e21e
This commit is contained in:
parent
ed6526b17e
commit
ad545ef35c
|
@ -0,0 +1,26 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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 service_filter
|
||||
|
||||
|
||||
class InstanceHaService(service_filter.ServiceFilter):
|
||||
"""The HA service."""
|
||||
|
||||
valid_versions = [service_filter.ValidVersion('v1')]
|
||||
|
||||
def __init__(self, version=None):
|
||||
"""Create an ha service."""
|
||||
super(InstanceHaService, self).__init__(service_type='ha',
|
||||
version=version)
|
|
@ -0,0 +1,216 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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 exceptions
|
||||
from openstack.instance_ha.v1 import host as _host
|
||||
from openstack.instance_ha.v1 import notification as _notification
|
||||
from openstack.instance_ha.v1 import segment as _segment
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Proxy(proxy.Proxy):
|
||||
"""Proxy class for ha resource handling.
|
||||
|
||||
Create method for each action of each API.
|
||||
"""
|
||||
|
||||
def notifications(self, **query):
|
||||
"""Return a generator of notifications.
|
||||
|
||||
:param kwargs \*\*query: Optional query parameters to be sent to
|
||||
limit the notifications being returned.
|
||||
:returns: A generator of notifications
|
||||
"""
|
||||
return self._list(_notification.Notification, paginated=False, **query)
|
||||
|
||||
def get_notification(self, notification):
|
||||
"""Get a single notification.
|
||||
|
||||
:param notification: The value can be the ID of a notification or a
|
||||
:class:
|
||||
`~masakariclient.sdk.ha.v1
|
||||
.notification.Notification` instance.
|
||||
:returns: One :class:`~masakariclient.sdk.ha.v1
|
||||
.notification.Notification`
|
||||
:raises: :class:`~openstack.exceptions.ResourceNotFound`
|
||||
when no resource can be found.
|
||||
"""
|
||||
return self._get(_notification.Notification, notification)
|
||||
|
||||
def create_notification(self, **attrs):
|
||||
"""Create a new notification.
|
||||
|
||||
:param dict attrs: Keyword arguments which will be used to create
|
||||
a :class:
|
||||
`masakariclient.sdk.ha.v1
|
||||
.notification.Notification`,
|
||||
comprised of the propoerties on the Notification
|
||||
class.
|
||||
:returns: The result of notification creation
|
||||
:rtype: :class: `masakariclient.sdk.ha.v1
|
||||
.notification.Notification`
|
||||
"""
|
||||
return self._create(_notification.Notification, **attrs)
|
||||
|
||||
def segments(self, **query):
|
||||
"""Return a generator of segments.
|
||||
|
||||
:param kwargs \*\*query: Optional query parameters to be sent to
|
||||
limit the segments being returned.
|
||||
:returns: A generator of segments
|
||||
"""
|
||||
return self._list(_segment.Segment, paginated=False, **query)
|
||||
|
||||
def get_segment(self, segment):
|
||||
"""Get a single segment.
|
||||
|
||||
:param segment: The value can be the ID of a segment or a
|
||||
:class:
|
||||
`~masakariclient.sdk.ha.v1.segment.Segment` instance.
|
||||
:returns: One :class:`~masakariclient.sdk.ha.v1.segment.Segment`
|
||||
:raises: :class:`~openstack.exceptions.ResourceNotFound`
|
||||
when no resource can be found.
|
||||
"""
|
||||
return self._get(_segment.Segment, segment)
|
||||
|
||||
def create_segment(self, **attrs):
|
||||
"""Create a new segment.
|
||||
|
||||
:param dict attrs: Keyword arguments which will be used to create
|
||||
a :class:
|
||||
`masakariclient.sdk.ha.v1.segment.Segment`,
|
||||
comprised of the propoerties on the Segment class.
|
||||
:returns: The result of segment creation
|
||||
:rtype: :class: `masakariclient.sdk.ha.v1.segment.Segment`
|
||||
"""
|
||||
return self._create(_segment.Segment, **attrs)
|
||||
|
||||
def update_segment(self, segment, **attrs):
|
||||
"""Update a segment.
|
||||
|
||||
:param segment: The value can be the ID of a segment or a
|
||||
:class:
|
||||
`~masakariclient.sdk.ha.v1.segment.Segment` instance.
|
||||
:param dict attrs: Keyword arguments which will be used to update
|
||||
a :class:
|
||||
`masakariclient.sdk.ha.v1.segment.Segment`,
|
||||
comprised of the propoerties on the Segment class.
|
||||
:returns: The updated segment.
|
||||
:rtype: :class: `masakariclient.sdk.ha.v1.segment.Segment`
|
||||
"""
|
||||
return self._update(_segment.Segment, segment, **attrs)
|
||||
|
||||
def delete_segment(self, segment, ignore_missing=True):
|
||||
"""Delete a segment.
|
||||
|
||||
:param segment:
|
||||
The value can be either the ID of a segment or a
|
||||
:class:`~masakariclient.sdk.ha.v1.segment.Segment` instance.
|
||||
:param bool ignore_missing: When set to ``False``
|
||||
:class:`~openstack.exceptions.ResourceNotFound` will be
|
||||
raised when the segment does not exist.
|
||||
When set to ``True``, no exception will be set when
|
||||
attempting to delete a nonexistent segment.
|
||||
:returns: ``None``
|
||||
"""
|
||||
return self._delete(_segment.Segment, segment,
|
||||
ignore_missing=ignore_missing)
|
||||
|
||||
def hosts(self, segment_id, **query):
|
||||
"""Return a generator of hosts.
|
||||
|
||||
:param segment_id: The ID of a failover segment.
|
||||
:param kwargs \*\*query: Optional query parameters to be sent to
|
||||
limit the hosts being returned.
|
||||
|
||||
:returns: A generator of hosts
|
||||
"""
|
||||
return self._list(_host.Host, segment_id=segment_id, paginated=False,
|
||||
**query)
|
||||
|
||||
def create_host(self, segment_id, **attrs):
|
||||
"""Create a new host.
|
||||
|
||||
:param segment_id: The ID of a failover segment.
|
||||
:param dict attrs: Keyword arguments which will be used to create
|
||||
a :class: `masakariclient.sdk.ha.v1.host.Host`,
|
||||
comprised of the propoerties on the Host class.
|
||||
|
||||
:returns: The results of host creation
|
||||
"""
|
||||
return self._create(_host.Host, segment_id=segment_id, **attrs)
|
||||
|
||||
def get_host(self, host, segment_id=None):
|
||||
"""Get a single host.
|
||||
|
||||
:param segment_id: The ID of a failover segment.
|
||||
:param host: The value can be the ID of a host or a :class:
|
||||
`~masakariclient.sdk.ha.v1.host.Host` instance.
|
||||
|
||||
:returns: One :class:`~masakariclient.sdk.ha.v1.host.Host`
|
||||
:raises: :class:`~openstack.exceptions.ResourceNotFound`
|
||||
when no resource can be found.
|
||||
:raises: :class:`~openstack.exceptions.InvalidRequest`
|
||||
when segment_id is None.
|
||||
"""
|
||||
if segment_id is None:
|
||||
raise exceptions.InvalidRequest("'segment_id' must be specified.")
|
||||
|
||||
host_id = resource.Resource._get_id(host)
|
||||
return self._get(_host.Host, host_id, segment_id=segment_id)
|
||||
|
||||
def update_host(self, host, segment_id, **attrs):
|
||||
"""Update the host.
|
||||
|
||||
:param segment_id: The ID of a failover segment.
|
||||
:param host: The value can be the ID of a host or a :class:
|
||||
`~masakariclient.sdk.ha.v1.host.Host` instance.
|
||||
:param dict attrs: The attributes to update on the host represented.
|
||||
|
||||
:returns: The updated host
|
||||
:raises: :class:`~openstack.exceptions.ResourceNotFound`
|
||||
when no resource can be found.
|
||||
:raises: :class:`~openstack.exceptions.InvalidRequest`
|
||||
when segment_id is None.
|
||||
"""
|
||||
host_id = resource.Resource._get_id(host)
|
||||
return self._update(_host.Host, host_id, segment_id=segment_id,
|
||||
**attrs)
|
||||
|
||||
def delete_host(self, host, segment_id=None, ignore_missing=True):
|
||||
"""Delete the host.
|
||||
|
||||
:param segment_id: The ID of a failover segment.
|
||||
:param host: The value can be the ID of a host or a :class:
|
||||
`~masakariclient.sdk.ha.v1.host.Host` instance.
|
||||
:param bool ignore_missing: When set to ``False``
|
||||
:class:`~openstack.exceptions.ResourceNotFound` will be
|
||||
raised when the host does not exist.
|
||||
When set to ``True``, no exception will be set when
|
||||
attempting to delete a nonexistent host.
|
||||
|
||||
:returns: ``None``
|
||||
:raises: :class:`~openstack.exceptions.ResourceNotFound`
|
||||
when no resource can be found.
|
||||
:raises: :class:`~openstack.exceptions.InvalidRequest`
|
||||
when segment_id is None.
|
||||
|
||||
"""
|
||||
if segment_id is None:
|
||||
raise exceptions.InvalidRequest("'segment_id' must be specified.")
|
||||
|
||||
host_id = resource.Resource._get_id(host)
|
||||
return self._delete(_host.Host, host_id, segment_id=segment_id,
|
||||
ignore_missing=ignore_missing)
|
|
@ -0,0 +1,67 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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.instance_ha import instance_ha_service
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Host(resource.Resource):
|
||||
resource_key = "host"
|
||||
resources_key = "hosts"
|
||||
base_path = "/segments/%(segment_id)s/hosts"
|
||||
service = instance_ha_service.InstanceHaService()
|
||||
|
||||
# capabilities
|
||||
# 1] GET /v1/segments/<segment_uuid>/hosts
|
||||
# 2] GET /v1/segments/<segment_uuid>/hosts/<host_uuid>
|
||||
# 3] POST /v1/segments/<segment_uuid>/hosts
|
||||
# 4] PUT /v1/segments/<segment_uuid>/hosts
|
||||
# 5] DELETE /v1/segments/<segment_uuid>/hosts
|
||||
allow_list = True
|
||||
allow_get = True
|
||||
allow_create = True
|
||||
allow_update = True
|
||||
allow_delete = True
|
||||
|
||||
# Properties
|
||||
# Refer "https://github.com/openstack/masakari/blob/
|
||||
# master/masakari/api/openstack/ha/schemas/hosts.py"
|
||||
# for properties of host API
|
||||
|
||||
#: A ID of representing this host
|
||||
id = resource.URI("id")
|
||||
#: A Uuid of representing this host
|
||||
uuid = resource.Body("uuid")
|
||||
#: A failover segment ID of this host(in URI)
|
||||
segment_id = resource.URI("segment_id")
|
||||
#: A created time of this host
|
||||
created_at = resource.Body("created_at")
|
||||
#: A latest updated time of this host
|
||||
updated_at = resource.Body("updated_at")
|
||||
#: A name of this host
|
||||
name = resource.Body("name")
|
||||
#: A type of this host
|
||||
type = resource.Body("type")
|
||||
#: A control attributes of this host
|
||||
control_attributes = resource.Body("control_attributes")
|
||||
#: A maintenance status of this host
|
||||
on_maintenance = resource.Body("on_maintenance")
|
||||
#: A reservation status of this host
|
||||
reserved = resource.Body("reserved")
|
||||
#: A failover segment ID of this host(in Body)
|
||||
failover_segment_id = resource.Body("failover_segment_id")
|
||||
|
||||
_query_mapping = resource.QueryParameters(
|
||||
"sort_key", "sort_dir", failover_segment_id="failover_segment_id",
|
||||
type="type", on_maintenance="on_maintenance", reserved="reserved")
|
|
@ -0,0 +1,64 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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.instance_ha import instance_ha_service
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Notification(resource.Resource):
|
||||
resource_key = "notification"
|
||||
resources_key = "notifications"
|
||||
base_path = "/notifications"
|
||||
service = instance_ha_service.InstanceHaService()
|
||||
|
||||
# capabilities
|
||||
# 1] GET /v1/notifications
|
||||
# 2] GET /v1/notifications/<notification_uuid>
|
||||
# 3] POST /v1/notifications
|
||||
allow_list = True
|
||||
allow_get = True
|
||||
allow_create = True
|
||||
allow_update = False
|
||||
allow_delete = False
|
||||
|
||||
# Properties
|
||||
# Refer "https://github.com/openstack/masakari/tree/
|
||||
# master/masakari/api/openstack/ha/schemas/notificaions.py"
|
||||
# for properties of notifications API
|
||||
|
||||
#: A ID of representing this notification.
|
||||
id = resource.Body("id")
|
||||
#: A Uuid of representing this notification.
|
||||
notification_uuid = resource.Body("notification_uuid")
|
||||
#: A created time of representing this notification.
|
||||
created_at = resource.Body("created_at")
|
||||
#: A latest updated time of representing this notification.
|
||||
updated_at = resource.Body("updated_at")
|
||||
#: The type of failure. Valuse values include ''COMPUTE_HOST'',
|
||||
#: ''VM'', ''PROCESS''
|
||||
type = resource.Body("type")
|
||||
#: The hostname of this notification.
|
||||
hostname = resource.Body("hostname")
|
||||
#: The status for this notitication.
|
||||
status = resource.Body("status")
|
||||
#: The generated_time for this notitication.
|
||||
generated_time = resource.Body("generated_time")
|
||||
#: The payload of this notification.
|
||||
payload = resource.Body("payload")
|
||||
#: The source host uuid of this notification.
|
||||
source_host_uuid = resource.Body("source_host_uuid")
|
||||
|
||||
_query_mapping = resource.QueryParameters(
|
||||
"sort_key", "sort_dir", source_host_uuid="source_host_uuid",
|
||||
type="type", status="status", generated_since="generated-since")
|
|
@ -0,0 +1,61 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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.instance_ha import instance_ha_service
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Segment(resource.Resource):
|
||||
resource_key = "segment"
|
||||
resources_key = "segments"
|
||||
base_path = "/segments"
|
||||
service = instance_ha_service.InstanceHaService()
|
||||
|
||||
# capabilities
|
||||
# 1] GET /v1/segments
|
||||
# 2] GET /v1/segments/<segment_uuid>
|
||||
# 3] POST /v1/segments
|
||||
# 4] PUT /v1/segments/<segment_uuid>
|
||||
# 5] DELETE /v1/segments/<segment_uuid>
|
||||
allow_list = True
|
||||
allow_get = True
|
||||
allow_create = True
|
||||
allow_update = True
|
||||
allow_delete = True
|
||||
|
||||
# Properties
|
||||
# Refer "https://github.com/openstack/masakari/tree/
|
||||
# master/masakari/api/openstack/ha/schemas"
|
||||
# for properties of each API
|
||||
|
||||
#: A ID of representing this segment.
|
||||
id = resource.Body("id")
|
||||
#: A Uuid of representing this segment.
|
||||
uuid = resource.Body("uuid")
|
||||
#: A created time of representing this segment.
|
||||
created_at = resource.Body("created_at")
|
||||
#: A latest updated time of representing this segment.
|
||||
updated_at = resource.Body("updated_at")
|
||||
#: The name of this segment.
|
||||
name = resource.Body("name")
|
||||
#: The description of this segment.
|
||||
description = resource.Body("description")
|
||||
#: The recovery method of this segment.
|
||||
recovery_method = resource.Body("recovery_method")
|
||||
#: The service type of this segment.
|
||||
service_type = resource.Body("service_type")
|
||||
|
||||
_query_mapping = resource.QueryParameters(
|
||||
"sort_key", "sort_dir", recovery_method="recovery_method",
|
||||
service_type="service_type")
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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 openstack.instance_ha import instance_ha_service
|
||||
|
||||
|
||||
class TestInstanceHaService(base.TestCase):
|
||||
|
||||
def test_service(self):
|
||||
sot = instance_ha_service.InstanceHaService()
|
||||
self.assertEqual("ha", sot.service_type)
|
||||
self.assertEqual("public", sot.interface)
|
||||
self.assertIsNone(sot.region)
|
||||
self.assertIsNone(sot.service_name)
|
||||
self.assertEqual(1, len(sot.valid_versions))
|
||||
self.assertEqual("v1", sot.valid_versions[0].module)
|
||||
self.assertEqual("v1", sot.valid_versions[0].path)
|
|
@ -0,0 +1,76 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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.instance_ha.v1 import host
|
||||
from openstack.tests.unit import base
|
||||
|
||||
FAKE_ID = "1c2f1795-ce78-4d4c-afd0-ce141fdb3952"
|
||||
FAKE_UUID = "11f7597f-87d2-4057-b754-ba611f989807"
|
||||
FAKE_HOST_ID = "c27dec16-ed4d-4ebe-8e77-f1e28ec32417"
|
||||
FAKE_CONTROL_ATTRIBUTES = {
|
||||
"mcastaddr": "239.255.1.1",
|
||||
"mcastport": "5405"
|
||||
}
|
||||
HOST = {
|
||||
"id": FAKE_ID,
|
||||
"uuid": FAKE_UUID,
|
||||
"segment_id": FAKE_HOST_ID,
|
||||
"created_at": "2018-03-22T00:00:00.000000",
|
||||
"updated_at": "2018-03-23T00:00:00.000000",
|
||||
"name": "my_host",
|
||||
"type": "pacemaker",
|
||||
"control_attributes": FAKE_CONTROL_ATTRIBUTES,
|
||||
"on_maintenance": False,
|
||||
"reserved": False,
|
||||
"failover_segment_id": FAKE_HOST_ID
|
||||
}
|
||||
|
||||
|
||||
class TestHost(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = host.Host(HOST)
|
||||
self.assertEqual("host", sot.resource_key)
|
||||
self.assertEqual("hosts", sot.resources_key)
|
||||
self.assertEqual("/segments/%(segment_id)s/hosts", sot.base_path)
|
||||
self.assertEqual("ha", sot.service.service_type)
|
||||
self.assertTrue(sot.allow_list)
|
||||
self.assertTrue(sot.allow_get)
|
||||
self.assertTrue(sot.allow_create)
|
||||
self.assertTrue(sot.allow_update)
|
||||
self.assertTrue(sot.allow_delete)
|
||||
|
||||
self.assertDictEqual({"failover_segment_id": "failover_segment_id",
|
||||
"limit": "limit",
|
||||
"marker": "marker",
|
||||
"on_maintenance": "on_maintenance",
|
||||
"reserved": "reserved",
|
||||
"sort_dir": "sort_dir",
|
||||
"sort_key": "sort_key",
|
||||
"type": "type"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_create(self):
|
||||
sot = host.Host(**HOST)
|
||||
self.assertEqual(HOST["id"], sot.id)
|
||||
self.assertEqual(HOST["uuid"], sot.uuid)
|
||||
self.assertEqual(HOST["segment_id"], sot.segment_id)
|
||||
self.assertEqual(HOST["created_at"], sot.created_at)
|
||||
self.assertEqual(HOST["updated_at"], sot.updated_at)
|
||||
self.assertEqual(HOST["name"], sot.name)
|
||||
self.assertEqual(HOST["type"], sot.type)
|
||||
self.assertEqual(HOST["control_attributes"], sot.control_attributes)
|
||||
self.assertEqual(HOST["on_maintenance"], sot.on_maintenance)
|
||||
self.assertEqual(HOST["reserved"], sot.reserved)
|
||||
self.assertEqual(HOST["failover_segment_id"], sot.failover_segment_id)
|
|
@ -0,0 +1,77 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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.instance_ha.v1 import notification
|
||||
from openstack.tests.unit import base
|
||||
|
||||
FAKE_ID = "569429e9-7f14-41be-a38e-920277e637db"
|
||||
FAKE_UUID = "a0e70d3a-b3a2-4616-b65d-a7c03a2c85fc"
|
||||
FAKE_HOST_UUID = "cad9ff01-c354-4414-ba3c-31b925be67f1"
|
||||
PAYLOAD = {
|
||||
"instance_uuid": "4032bc1d-d723-47f6-b5ac-b9b3e6dbb795",
|
||||
"vir_domain_event": "STOPPED_FAILED",
|
||||
"event": "LIFECYCLE"
|
||||
}
|
||||
NOTIFICATION = {
|
||||
"id": FAKE_ID,
|
||||
"notification_uuid": FAKE_UUID,
|
||||
"created_at": "2018-03-22T00:00:00.000000",
|
||||
"updated_at": "2018-03-23T00:00:00.000000",
|
||||
"type": "pacemaker",
|
||||
"hostname": "fake_host",
|
||||
"status": "new",
|
||||
"generated_time": "2018-03-21T00:00:00.000000",
|
||||
"payload": PAYLOAD,
|
||||
"source_host_uuid": FAKE_HOST_UUID
|
||||
}
|
||||
|
||||
|
||||
class TestNotification(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = notification.Notification(NOTIFICATION)
|
||||
self.assertEqual("notification", sot.resource_key)
|
||||
self.assertEqual("notifications", sot.resources_key)
|
||||
self.assertEqual("/notifications", sot.base_path)
|
||||
self.assertEqual("ha", sot.service.service_type)
|
||||
self.assertTrue(sot.allow_list)
|
||||
self.assertTrue(sot.allow_get)
|
||||
self.assertTrue(sot.allow_create)
|
||||
self.assertFalse(sot.allow_update)
|
||||
self.assertFalse(sot.allow_delete)
|
||||
|
||||
self.assertDictEqual({"generated_since": "generated-since",
|
||||
"limit": "limit",
|
||||
"marker": "marker",
|
||||
"sort_dir": "sort_dir",
|
||||
"sort_key": "sort_key",
|
||||
"source_host_uuid": "source_host_uuid",
|
||||
"status": "status",
|
||||
"type": "type"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_create(self):
|
||||
sot = notification.Notification(**NOTIFICATION)
|
||||
self.assertEqual(NOTIFICATION["id"], sot.id)
|
||||
self.assertEqual(
|
||||
NOTIFICATION["notification_uuid"], sot.notification_uuid)
|
||||
self.assertEqual(NOTIFICATION["created_at"], sot.created_at)
|
||||
self.assertEqual(NOTIFICATION["updated_at"], sot.updated_at)
|
||||
self.assertEqual(NOTIFICATION["type"], sot.type)
|
||||
self.assertEqual(NOTIFICATION["hostname"], sot.hostname)
|
||||
self.assertEqual(NOTIFICATION["status"], sot.status)
|
||||
self.assertEqual(NOTIFICATION["generated_time"], sot.generated_time)
|
||||
self.assertEqual(NOTIFICATION["payload"], sot.payload)
|
||||
self.assertEqual(
|
||||
NOTIFICATION["source_host_uuid"], sot.source_host_uuid)
|
|
@ -0,0 +1,86 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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.instance_ha.v1 import _proxy
|
||||
from openstack.instance_ha.v1 import host
|
||||
from openstack.instance_ha.v1 import notification
|
||||
from openstack.instance_ha.v1 import segment
|
||||
from openstack.tests.unit import test_proxy_base
|
||||
|
||||
SEGMENT_ID = "c50b96eb-2a66-40f8-bca8-c5fa90d595c0"
|
||||
HOST_ID = "52d05e43-d08e-42b8-ae33-e47c8ea2ad47"
|
||||
|
||||
|
||||
class TestInstanceHaProxy(test_proxy_base.TestProxyBase):
|
||||
def setUp(self):
|
||||
super(TestInstanceHaProxy, self).setUp()
|
||||
self.proxy = _proxy.Proxy(self.session)
|
||||
|
||||
def test_hosts(self):
|
||||
self.verify_list(self.proxy.hosts,
|
||||
host.Host,
|
||||
method_args=[SEGMENT_ID],
|
||||
expected_kwargs={"segment_id": SEGMENT_ID})
|
||||
|
||||
def test_host_get(self):
|
||||
self.verify_get(self.proxy.get_host,
|
||||
host.Host,
|
||||
value=[HOST_ID],
|
||||
method_kwargs={"segment_id": SEGMENT_ID},
|
||||
expected_kwargs={"segment_id": SEGMENT_ID})
|
||||
|
||||
def test_host_create(self):
|
||||
self.verify_create(self.proxy.create_host,
|
||||
host.Host,
|
||||
method_args=[SEGMENT_ID],
|
||||
method_kwargs={},
|
||||
expected_kwargs={"segment_id": SEGMENT_ID})
|
||||
|
||||
def test_host_update(self):
|
||||
self.verify_update(self.proxy.update_host,
|
||||
host.Host,
|
||||
method_kwargs={"segment_id": SEGMENT_ID})
|
||||
|
||||
def test_host_delete(self):
|
||||
self.verify_delete(self.proxy.delete_host,
|
||||
host.Host,
|
||||
True,
|
||||
method_kwargs={"segment_id": SEGMENT_ID},
|
||||
expected_kwargs={"segment_id": SEGMENT_ID})
|
||||
|
||||
def test_notifications(self):
|
||||
self.verify_list(self.proxy.notifications, notification.Notification)
|
||||
|
||||
def test_notification_get(self):
|
||||
self.verify_get(self.proxy.get_notification,
|
||||
notification.Notification)
|
||||
|
||||
def test_notification_create(self):
|
||||
self.verify_create(self.proxy.create_notification,
|
||||
notification.Notification)
|
||||
|
||||
def test_segments(self):
|
||||
self.verify_list(self.proxy.segments, segment.Segment)
|
||||
|
||||
def test_segment_get(self):
|
||||
self.verify_get(self.proxy.get_segment, segment.Segment)
|
||||
|
||||
def test_segment_create(self):
|
||||
self.verify_create(self.proxy.create_segment, segment.Segment)
|
||||
|
||||
def test_segment_update(self):
|
||||
self.verify_update(self.proxy.update_segment, segment.Segment)
|
||||
|
||||
def test_segment_delete(self):
|
||||
self.verify_delete(self.proxy.delete_segment, segment.Segment, True)
|
|
@ -0,0 +1,63 @@
|
|||
# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
|
||||
#
|
||||
# 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.instance_ha.v1 import segment
|
||||
from openstack.tests.unit import base
|
||||
|
||||
FAKE_ID = "1c2f1795-ce78-4d4c-afd0-ce141fdb3952"
|
||||
FAKE_UUID = "11f7597f-87d2-4057-b754-ba611f989807"
|
||||
SEGMENT = {
|
||||
"id": FAKE_ID,
|
||||
"uuid": FAKE_UUID,
|
||||
"created_at": "2018-03-22T00:00:00.000000",
|
||||
"updated_at": "2018-03-23T00:00:00.000000",
|
||||
"name": "my_segment",
|
||||
"description": "something",
|
||||
"recovery_method": "auto",
|
||||
"service_type": "COMPUTE_HOST"
|
||||
}
|
||||
|
||||
|
||||
class TestSegment(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = segment.Segment(SEGMENT)
|
||||
self.assertEqual("segment", sot.resource_key)
|
||||
self.assertEqual("segments", sot.resources_key)
|
||||
self.assertEqual("/segments", sot.base_path)
|
||||
self.assertEqual("ha", sot.service.service_type)
|
||||
self.assertTrue(sot.allow_list)
|
||||
self.assertTrue(sot.allow_get)
|
||||
self.assertTrue(sot.allow_create)
|
||||
self.assertTrue(sot.allow_update)
|
||||
self.assertTrue(sot.allow_delete)
|
||||
|
||||
self.assertDictEqual({"limit": "limit",
|
||||
"marker": "marker",
|
||||
"recovery_method": "recovery_method",
|
||||
"service_type": "service_type",
|
||||
"sort_dir": "sort_dir",
|
||||
"sort_key": "sort_key"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_create(self):
|
||||
sot = segment.Segment(**SEGMENT)
|
||||
self.assertEqual(SEGMENT["id"], sot.id)
|
||||
self.assertEqual(SEGMENT["uuid"], sot.uuid)
|
||||
self.assertEqual(SEGMENT["created_at"], sot.created_at)
|
||||
self.assertEqual(SEGMENT["updated_at"], sot.updated_at)
|
||||
self.assertEqual(SEGMENT["name"], sot.name)
|
||||
self.assertEqual(SEGMENT["description"], sot.description)
|
||||
self.assertEqual(SEGMENT["recovery_method"], sot.recovery_method)
|
||||
self.assertEqual(SEGMENT["service_type"], sot.service_type)
|
|
@ -212,7 +212,8 @@ class TestProxyBase(base.TestCase):
|
|||
mock_method="openstack.proxy.Proxy._update",
|
||||
expected_result="result", path_args=None, **kwargs):
|
||||
method_args = value or ["resource_or_id"]
|
||||
method_kwargs = {"x": 1, "y": 2, "z": 3}
|
||||
method_kwargs = kwargs.pop("method_kwargs", {})
|
||||
method_kwargs.update({"x": 1, "y": 2, "z": 3})
|
||||
expected_args = kwargs.pop("expected_args", ["resource_or_id"])
|
||||
expected_kwargs = method_kwargs.copy()
|
||||
|
||||
|
|
Loading…
Reference in New Issue