summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwhoami-rajat <rajatdhasmana@gmail.com>2022-03-15 14:21:13 +0530
committerwhoami-rajat <rajatdhasmana@gmail.com>2022-03-22 14:18:18 +0530
commit77919e15d281e908de7b687e2af927b59d3dc8a8 (patch)
treea78bd10219bd08a360eb44bb9bb6a9b6792a8627
parent3666d2d2e4be4524c47ba2531e39984e260c8ce8 (diff)
downloadglance_store-77919e15d281e908de7b687e2af927b59d3dc8a8.tar.gz
Add coverage for get_cinderclient and _check_context
This patch adds coverage for some parts in get_cinderclient method like ``cinder_endpoint_template`` option and keystone exception case when catalog info for cinder could not be found. Also it adds tests for complete coverage of _check_context method. Change-Id: I18b1e5e8fd818824a2dda2ad14d9456190fe9ff4
-rw-r--r--glance_store/tests/unit/test_cinder_base.py51
-rw-r--r--glance_store/tests/unit/test_cinder_store.py6
-rw-r--r--glance_store/tests/unit/test_multistore_cinder.py7
3 files changed, 64 insertions, 0 deletions
diff --git a/glance_store/tests/unit/test_cinder_base.py b/glance_store/tests/unit/test_cinder_base.py
index 69539fa..0fd8294 100644
--- a/glance_store/tests/unit/test_cinder_base.py
+++ b/glance_store/tests/unit/test_cinder_base.py
@@ -26,6 +26,7 @@ import tempfile
import time
import uuid
+from keystoneauth1 import exceptions as keystone_exc
from os_brick.initiator import connector
from oslo_concurrency import processutils
from oslo_utils.secretutils import md5
@@ -101,6 +102,49 @@ class TestCinderStoreBase(object):
fake_session.assert_called_once_with(
auth=fake_auth, verify=fake_cert_path)
+ def _test_get_cinderclient_cinder_endpoint_template(self,
+ group='glance_store'):
+ fake_endpoint = 'http://cinder.openstack.example.com/v2/fake_project'
+ self.config(cinder_endpoint_template=fake_endpoint, group=group)
+ with mock.patch.object(
+ cinder.ksa_token_endpoint, 'Token') as fake_token:
+ self.store.get_cinderclient(self.context)
+ fake_token.assert_called_once_with(endpoint=fake_endpoint,
+ token=self.context.auth_token)
+
+ def test_get_cinderclient_endpoint_exception(self):
+ with mock.patch.object(cinder.ksa_session, 'Session'), \
+ mock.patch.object(cinder.ksa_identity, 'V3Password'), \
+ mock.patch.object(
+ cinder.Store, 'is_user_overriden', return_value=False), \
+ mock.patch.object(
+ cinder.keystone_sc, 'ServiceCatalogV2') as service_catalog:
+ service_catalog.side_effect = keystone_exc.EndpointNotFound
+ self.assertRaises(
+ exceptions.BadStoreConfiguration, self.store.get_cinderclient,
+ self.context)
+
+ def test__check_context(self):
+ with mock.patch.object(cinder.Store, 'is_user_overriden',
+ return_value=True) as fake_overriden:
+ self.store._check_context(self.context)
+ fake_overriden.assert_called_once()
+
+ def test__check_context_no_context(self):
+ with mock.patch.object(
+ cinder.Store, 'is_user_overriden', return_value=False):
+ self.assertRaises(
+ exceptions.BadStoreConfiguration, self.store._check_context,
+ None)
+
+ def test__check_context_no_service_catalog(self):
+ with mock.patch.object(
+ cinder.Store, 'is_user_overriden', return_value=False):
+ fake_context = mock.MagicMock(service_catalog=None)
+ self.assertRaises(
+ exceptions.BadStoreConfiguration, self.store._check_context,
+ fake_context)
+
def test_temporary_chown(self):
fake_stat = mock.MagicMock(st_uid=1)
@@ -526,3 +570,10 @@ class TestCinderStoreBase(object):
def _test_parse_uri_invalid(self, uri):
self.assertRaises(
exceptions.BadStoreUri, self.location.parse_uri, uri)
+
+ def _test_get_root_helper(self, group='glance_store'):
+ fake_rootwrap = 'fake_rootwrap'
+ expected = 'sudo glance-rootwrap %s' % fake_rootwrap
+ self.config(rootwrap_config=fake_rootwrap, group=group)
+ res = self.store.get_root_helper()
+ self.assertEqual(expected, res)
diff --git a/glance_store/tests/unit/test_cinder_store.py b/glance_store/tests/unit/test_cinder_store.py
index 1abd75c..60fba6f 100644
--- a/glance_store/tests/unit/test_cinder_store.py
+++ b/glance_store/tests/unit/test_cinder_store.py
@@ -184,3 +184,9 @@ class TestCinderStore(base.StoreBaseTest,
def test_parse_uri_invalid(self):
uri = 'cinder://%s' % 'fake_volume'
self._test_parse_uri_invalid(uri)
+
+ def test_get_root_helper(self):
+ self._test_get_root_helper()
+
+ def test_get_cinderclient_cinder_endpoint_template(self):
+ self._test_get_cinderclient_cinder_endpoint_template()
diff --git a/glance_store/tests/unit/test_multistore_cinder.py b/glance_store/tests/unit/test_multistore_cinder.py
index 6d7a037..e92f86c 100644
--- a/glance_store/tests/unit/test_multistore_cinder.py
+++ b/glance_store/tests/unit/test_multistore_cinder.py
@@ -313,3 +313,10 @@ class TestMultiCinderStore(base.MultiStoreBaseTest,
def test_parse_uri_invalid(self):
uri = 'cinder://cinder1/%s' % 'fake_volume'
self._test_parse_uri_invalid(uri)
+
+ def test_get_root_helper(self):
+ self._test_get_root_helper(group='cinder1')
+
+ def test_get_cinderclient_cinder_endpoint_template(self):
+ self._test_get_cinderclient_cinder_endpoint_template(
+ group='cinder1')