New volume availability zone resource, new functional and unit tests
Change-Id: I1863095c2c6d6d3e10ef19a5afe00e1526d52c43
This commit is contained in:
parent
cc7369c743
commit
c3ce787389
|
@ -11,6 +11,7 @@
|
|||
# under the License.
|
||||
|
||||
from openstack.block_storage import _base_proxy
|
||||
from openstack.block_storage.v3 import availability_zone
|
||||
from openstack.block_storage.v3 import backup as _backup
|
||||
from openstack.block_storage.v3 import snapshot as _snapshot
|
||||
from openstack.block_storage.v3 import stats as _stats
|
||||
|
@ -479,6 +480,16 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
|||
backup = self._get_resource(_backup.Backup, backup)
|
||||
return backup.restore(self, volume_id=volume_id, name=name)
|
||||
|
||||
def availability_zones(self):
|
||||
"""Return a generator of availability zones
|
||||
|
||||
:returns: A generator of availability zone
|
||||
:rtype: :class:`~openstack.block_storage.v3.availability_zone.\
|
||||
AvailabilityZone`
|
||||
"""
|
||||
|
||||
return self._list(availability_zone.AvailabilityZone)
|
||||
|
||||
def wait_for_status(self, res, status='ACTIVE', failures=None,
|
||||
interval=2, wait=120):
|
||||
"""Wait for a resource to be in a particular status.
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# 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 AvailabilityZone(resource.Resource):
|
||||
resource_key = ""
|
||||
resources_key = "availabilityZoneInfo"
|
||||
base_path = "/os-availability-zone"
|
||||
|
||||
# capabilities
|
||||
allow_list = True
|
||||
|
||||
#: Properties
|
||||
#: Name of availability zone
|
||||
name = resource.Body("zoneName", type=str)
|
||||
#: State of availability zone, "available" is usual key
|
||||
state = resource.Body("zoneState", type=dict)
|
|
@ -0,0 +1,25 @@
|
|||
# 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.functional import base
|
||||
|
||||
|
||||
class TestAvailabilityZone(base.BaseFunctionalTest):
|
||||
|
||||
def test_list(self):
|
||||
availability_zones = list(self.conn.block_storage.availability_zones())
|
||||
self.assertGreater(len(availability_zones), 0)
|
||||
|
||||
for az in availability_zones:
|
||||
self.assertIsInstance(az.name, str)
|
||||
self.assertIsInstance(az.state, dict)
|
|
@ -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.block_storage.v3 import availability_zone as az
|
||||
|
||||
from openstack.tests.unit import base
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
EXAMPLE = {
|
||||
"id": IDENTIFIER,
|
||||
"zoneState": {
|
||||
"available": True
|
||||
},
|
||||
"zoneName": "zone1"
|
||||
}
|
||||
|
||||
|
||||
class TestAvailabilityZone(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = az.AvailabilityZone()
|
||||
self.assertEqual('availabilityZoneInfo', sot.resources_key)
|
||||
self.assertEqual('/os-availability-zone', sot.base_path)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = az.AvailabilityZone(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['id'], sot.id)
|
||||
self.assertEqual(EXAMPLE['zoneState'], sot.state)
|
||||
self.assertEqual(EXAMPLE['zoneName'], sot.name)
|
Loading…
Reference in New Issue