Changing method for verifying existence of cinder
Sahara uses keystone admin client for checking existence of cinder. This patch change method for checking existence of cinder Change-Id: I082c2392742476eb7fa1e74d2443d10c89d6f707 Partial-bug: #1300246
This commit is contained in:
parent
75c1431797
commit
a8e8963b68
|
@ -29,7 +29,6 @@ import sahara.service.api as api
|
||||||
from sahara.utils import general as g
|
from sahara.utils import general as g
|
||||||
import sahara.utils.openstack.cinder as cinder
|
import sahara.utils.openstack.cinder as cinder
|
||||||
import sahara.utils.openstack.heat as heat
|
import sahara.utils.openstack.heat as heat
|
||||||
import sahara.utils.openstack.keystone as keystone
|
|
||||||
import sahara.utils.openstack.nova as nova
|
import sahara.utils.openstack.nova as nova
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,7 +141,9 @@ def check_node_group_basic_fields(plugin_name, hadoop_version, ng,
|
||||||
check_image_registered(ng['image_id'])
|
check_image_registered(ng['image_id'])
|
||||||
|
|
||||||
if ng.get('volumes_per_node'):
|
if ng.get('volumes_per_node'):
|
||||||
check_cinder_exists()
|
if not cinder.check_cinder_exists():
|
||||||
|
raise ex.InvalidReferenceException(_("Cinder is not supported"))
|
||||||
|
|
||||||
if ng.get('volumes_availability_zone'):
|
if ng.get('volumes_availability_zone'):
|
||||||
check_volume_availability_zone_exist(
|
check_volume_availability_zone_exist(
|
||||||
ng['volumes_availability_zone'])
|
ng['volumes_availability_zone'])
|
||||||
|
@ -387,15 +388,6 @@ def check_add_node_groups(cluster, add_node_groups):
|
||||||
cluster.hadoop_version, ng, pl_confs)
|
cluster.hadoop_version, ng, pl_confs)
|
||||||
|
|
||||||
|
|
||||||
# Cinder
|
|
||||||
|
|
||||||
def check_cinder_exists():
|
|
||||||
services = [service.name for service in
|
|
||||||
keystone.client_for_admin().services.list()]
|
|
||||||
if 'cinder' not in services:
|
|
||||||
raise ex.InvalidReferenceException(_("Cinder is not supported"))
|
|
||||||
|
|
||||||
|
|
||||||
# Tags
|
# Tags
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,9 +130,10 @@ def start_patch(patch_templates=True):
|
||||||
get_cl_template_p = mock.patch(
|
get_cl_template_p = mock.patch(
|
||||||
"sahara.service.api.get_cluster_template")
|
"sahara.service.api.get_cluster_template")
|
||||||
nova_p = mock.patch("sahara.utils.openstack.nova.client")
|
nova_p = mock.patch("sahara.utils.openstack.nova.client")
|
||||||
keystone_p = mock.patch("sahara.utils.openstack.keystone._client")
|
|
||||||
heat_p = mock.patch("sahara.utils.openstack.heat.client")
|
heat_p = mock.patch("sahara.utils.openstack.heat.client")
|
||||||
cinder_p = mock.patch("sahara.utils.openstack.cinder.client")
|
cinder_p = mock.patch("sahara.utils.openstack.cinder.client")
|
||||||
|
cinder_exists_p = mock.patch(
|
||||||
|
"sahara.utils.openstack.cinder.check_cinder_exists")
|
||||||
get_image_p = mock.patch("sahara.service.api.get_image")
|
get_image_p = mock.patch("sahara.service.api.get_image")
|
||||||
|
|
||||||
get_image = get_image_p.start()
|
get_image = get_image_p.start()
|
||||||
|
@ -146,7 +147,6 @@ def start_patch(patch_templates=True):
|
||||||
get_cl_template_p.start()
|
get_cl_template_p.start()
|
||||||
|
|
||||||
nova = nova_p.start()
|
nova = nova_p.start()
|
||||||
keystone = keystone_p.start()
|
|
||||||
|
|
||||||
if patch_templates:
|
if patch_templates:
|
||||||
get_cl_templates.return_value = []
|
get_cl_templates.return_value = []
|
||||||
|
@ -164,15 +164,8 @@ def start_patch(patch_templates=True):
|
||||||
cinder = cinder_p.start()
|
cinder = cinder_p.start()
|
||||||
cinder().availability_zones.list.side_effect = _get_availability_zone_list
|
cinder().availability_zones.list.side_effect = _get_availability_zone_list
|
||||||
|
|
||||||
class Service(object):
|
cinder_exists = cinder_exists_p.start()
|
||||||
@property
|
cinder_exists.return_value = True
|
||||||
def name(self):
|
|
||||||
return 'cinder'
|
|
||||||
|
|
||||||
def _services_list():
|
|
||||||
return [Service()]
|
|
||||||
|
|
||||||
keystone().services.list.side_effect = _services_list
|
|
||||||
|
|
||||||
class Image(object):
|
class Image(object):
|
||||||
def __init__(self, name='test'):
|
def __init__(self, name='test'):
|
||||||
|
@ -232,7 +225,8 @@ def start_patch(patch_templates=True):
|
||||||
get_ng_template.side_effect = _get_ng_template
|
get_ng_template.side_effect = _get_ng_template
|
||||||
# request data to validate
|
# request data to validate
|
||||||
patchers = [get_clusters_p, get_cluster_p,
|
patchers = [get_clusters_p, get_cluster_p,
|
||||||
nova_p, keystone_p, get_image_p, heat_p, cinder_p]
|
nova_p, get_image_p, heat_p, cinder_p,
|
||||||
|
cinder_exists_p]
|
||||||
if patch_templates:
|
if patch_templates:
|
||||||
patchers.extend([get_ng_template_p, get_ng_templates_p,
|
patchers.extend([get_ng_template_p, get_ng_templates_p,
|
||||||
get_cl_template_p, get_cl_templates_p])
|
get_cl_template_p, get_cl_templates_p])
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
from sahara import exceptions as ex
|
||||||
from sahara import main
|
from sahara import main
|
||||||
from sahara.tests.unit import base as test_base
|
from sahara.tests.unit import base as test_base
|
||||||
from sahara.utils.openstack import cinder
|
from sahara.utils.openstack import cinder
|
||||||
|
@ -71,6 +72,16 @@ class TestCinder(test_base.SaharaTestCase):
|
||||||
# Check bad version falls back to latest supported version
|
# Check bad version falls back to latest supported version
|
||||||
self.assertEqual(2, main.CONF.cinder.api_version)
|
self.assertEqual(2, main.CONF.cinder.api_version)
|
||||||
|
|
||||||
|
@mock.patch('sahara.utils.openstack.base.url_for')
|
||||||
|
def test_check_cinder_exists(self, mock_url_for):
|
||||||
|
mock_url_for.return_value = None
|
||||||
|
self.assertTrue(cinder.check_cinder_exists())
|
||||||
|
|
||||||
|
mock_url_for.reset_mock()
|
||||||
|
|
||||||
|
mock_url_for.side_effect = ex.SystemError("BANANA")
|
||||||
|
self.assertFalse(cinder.check_cinder_exists())
|
||||||
|
|
||||||
|
|
||||||
class FakeCinderClient(object):
|
class FakeCinderClient(object):
|
||||||
def __init__(self, api_version):
|
def __init__(self, api_version):
|
||||||
|
|
|
@ -21,6 +21,7 @@ from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from sahara import context
|
from sahara import context
|
||||||
|
from sahara import exceptions as ex
|
||||||
from sahara.i18n import _LW
|
from sahara.i18n import _LW
|
||||||
from sahara.utils.openstack import base
|
from sahara.utils.openstack import base
|
||||||
|
|
||||||
|
@ -83,6 +84,18 @@ def client():
|
||||||
return cinder
|
return cinder
|
||||||
|
|
||||||
|
|
||||||
|
def check_cinder_exists():
|
||||||
|
if CONF.cinder.api_version == 1:
|
||||||
|
service_type = 'volume'
|
||||||
|
else:
|
||||||
|
service_type = 'volumev2'
|
||||||
|
try:
|
||||||
|
base.url_for(context.current().service_catalog, service_type)
|
||||||
|
return True
|
||||||
|
except ex.SystemError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_volumes():
|
def get_volumes():
|
||||||
return [volume.id for volume in client().volumes.list()]
|
return [volume.id for volume in client().volumes.list()]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue