Add exception handling to EBS driver initialization
Change-Id: I8913429303a32ab9e310ce23858e74ddef6a9f8d
This commit is contained in:
parent
08f70678a5
commit
ccbbe69a8b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
*.pyc
|
||||
*~
|
||||
*venv
|
||||
.idea
|
||||
|
@ -17,9 +17,9 @@ from cinder import context
|
||||
from cinder import test
|
||||
from cinder.exception import APITimeout, NotFound, VolumeNotFound
|
||||
from cinder.volume.drivers.aws import ebs
|
||||
from cinder.volume.drivers.aws.exception import AvailabilityZoneNotFound
|
||||
from moto import mock_ec2
|
||||
|
||||
import boto
|
||||
|
||||
class EBSVolumeTestCase(test.TestCase):
|
||||
|
||||
@ -61,6 +61,14 @@ class EBSVolumeTestCase(test.TestCase):
|
||||
ss['display_name'] = kwargs.get('display_name', 'snapshot_007')
|
||||
return ss
|
||||
|
||||
@mock_ec2
|
||||
def test_availability_zone_config(self):
|
||||
ebs.CONF.AWS.az = 'hgkjhgkd'
|
||||
driver = ebs.EBSDriver()
|
||||
ctxt = context.get_admin_context()
|
||||
self.assertRaises(AvailabilityZoneNotFound, driver.do_setup, ctxt)
|
||||
ebs.CONF.AWS.az = 'us-east-1a'
|
||||
|
||||
@mock_ec2
|
||||
def test_volume_create_success(self):
|
||||
self.assertIsNone(self._driver.create_volume(self._stub_volume()))
|
||||
@ -129,4 +137,4 @@ class EBSVolumeTestCase(test.TestCase):
|
||||
@mock_ec2
|
||||
def test_volume_from_non_existing_snapshot(self):
|
||||
self.assertRaises(NotFound, self._driver.create_volume_from_snapshot,
|
||||
self._stub_volume(), self._stub_snapshot())
|
||||
self._stub_volume(), self._stub_snapshot())
|
||||
|
@ -22,6 +22,7 @@ from cinder.i18n import _LE
|
||||
from cinder.exception import VolumeNotFound, NotFound, APITimeout, InvalidConfigurationValue
|
||||
from cinder.volume.driver import BaseVD
|
||||
|
||||
from exception import AvailabilityZoneNotFound
|
||||
|
||||
aws_group = cfg.OptGroup(name='AWS', title='Options to connect to an AWS environment')
|
||||
aws_opts = [
|
||||
@ -56,19 +57,6 @@ class EBSDriver(BaseVD):
|
||||
self.VERSION = '1.0.0'
|
||||
self._wait_time_sec = 60 * (CONF.AWS.wait_time_min)
|
||||
|
||||
self._check_config()
|
||||
region_name = CONF.AWS.region_name
|
||||
endpoint = '.'.join(['ec2', region_name, 'amazonaws.com'])
|
||||
region = RegionInfo(name=region_name, endpoint=endpoint)
|
||||
self._conn = ec2.EC2Connection(aws_access_key_id=CONF.AWS.access_key,
|
||||
aws_secret_access_key=CONF.AWS.secret_key,
|
||||
region=region)
|
||||
# resort to first AZ for now. TODO: expose this through API
|
||||
az = CONF.AWS.az
|
||||
self._zone = filter(lambda z: z.name == az,
|
||||
self._conn.get_all_zones())[0]
|
||||
self.set_initialized()
|
||||
|
||||
def _check_config(self):
|
||||
tbl = dict([(n, eval(n)) for n in ['CONF.AWS.access_key',
|
||||
'CONF.AWS.secret_key',
|
||||
@ -79,7 +67,24 @@ class EBSDriver(BaseVD):
|
||||
raise InvalidConfigurationValue(value=None, option=k)
|
||||
|
||||
def do_setup(self, context):
|
||||
pass
|
||||
self._check_config()
|
||||
region_name = CONF.AWS.region_name
|
||||
endpoint = '.'.join(['ec2', region_name, 'amazonaws.com'])
|
||||
region = RegionInfo(name=region_name, endpoint=endpoint)
|
||||
self._conn = ec2.EC2Connection(aws_access_key_id=CONF.AWS.access_key,
|
||||
aws_secret_access_key=CONF.AWS.secret_key,
|
||||
region=region)
|
||||
# resort to first AZ for now. TODO: expose this through API
|
||||
az = CONF.AWS.az
|
||||
|
||||
try:
|
||||
self._zone = filter(lambda z: z.name == az,
|
||||
self._conn.get_all_zones())[0]
|
||||
except IndexError:
|
||||
raise AvailabilityZoneNotFound(az=az)
|
||||
|
||||
self.set_initialized()
|
||||
|
||||
|
||||
def _wait_for_create(self, id, final_state):
|
||||
def _wait_for_status(start_time):
|
||||
|
19
cinder/volume/drivers/aws/exception.py
Normal file
19
cinder/volume/drivers/aws/exception.py
Normal file
@ -0,0 +1,19 @@
|
||||
"""
|
||||
Copyright 2017 Platform9 Systems Inc.(http://www.platform9.com)
|
||||
|
||||
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 cinder.exception import CinderException
|
||||
from cinder.i18n import _
|
||||
|
||||
class AvailabilityZoneNotFound(CinderException):
|
||||
message = _("Availability Zone %(az)s was not found")
|
Loading…
x
Reference in New Issue
Block a user