Browse Source

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
changes/74/164274/3
Sergey Reshetnyak 7 years ago
parent
commit
a8e8963b68
  1. 14
      sahara/service/validations/base.py
  2. 18
      sahara/tests/unit/service/validation/utils.py
  3. 11
      sahara/tests/unit/utils/test_cinder.py
  4. 13
      sahara/utils/openstack/cinder.py

14
sahara/service/validations/base.py

@ -29,7 +29,6 @@ import sahara.service.api as api
from sahara.utils import general as g
import sahara.utils.openstack.cinder as cinder
import sahara.utils.openstack.heat as heat
import sahara.utils.openstack.keystone as keystone
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'])
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'):
check_volume_availability_zone_exist(
ng['volumes_availability_zone'])
@ -387,15 +388,6 @@ def check_add_node_groups(cluster, add_node_groups):
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

18
sahara/tests/unit/service/validation/utils.py

@ -130,9 +130,10 @@ def start_patch(patch_templates=True):
get_cl_template_p = mock.patch(
"sahara.service.api.get_cluster_template")
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")
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 = get_image_p.start()
@ -146,7 +147,6 @@ def start_patch(patch_templates=True):
get_cl_template_p.start()
nova = nova_p.start()
keystone = keystone_p.start()
if patch_templates:
get_cl_templates.return_value = []
@ -164,15 +164,8 @@ def start_patch(patch_templates=True):
cinder = cinder_p.start()
cinder().availability_zones.list.side_effect = _get_availability_zone_list
class Service(object):
@property
def name(self):
return 'cinder'
def _services_list():
return [Service()]
keystone().services.list.side_effect = _services_list
cinder_exists = cinder_exists_p.start()
cinder_exists.return_value = True
class Image(object):
def __init__(self, name='test'):
@ -232,7 +225,8 @@ def start_patch(patch_templates=True):
get_ng_template.side_effect = _get_ng_template
# request data to validate
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:
patchers.extend([get_ng_template_p, get_ng_templates_p,
get_cl_template_p, get_cl_templates_p])

11
sahara/tests/unit/utils/test_cinder.py

@ -17,6 +17,7 @@
import mock
from oslo_config import cfg
from sahara import exceptions as ex
from sahara import main
from sahara.tests.unit import base as test_base
from sahara.utils.openstack import cinder
@ -71,6 +72,16 @@ class TestCinder(test_base.SaharaTestCase):
# Check bad version falls back to latest supported 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):
def __init__(self, api_version):

13
sahara/utils/openstack/cinder.py

@ -21,6 +21,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from sahara import context
from sahara import exceptions as ex
from sahara.i18n import _LW
from sahara.utils.openstack import base
@ -83,6 +84,18 @@ def client():
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():
return [volume.id for volume in client().volumes.list()]

Loading…
Cancel
Save