diff options
author | whoami-rajat <rajatdhasmana@gmail.com> | 2022-03-14 14:35:53 +0530 |
---|---|---|
committer | whoami-rajat <rajatdhasmana@gmail.com> | 2022-03-17 14:29:46 +0530 |
commit | 3666d2d2e4be4524c47ba2531e39984e260c8ce8 (patch) | |
tree | b2a8b5f3d5744c4d8c87479ea093e21cad6f07c1 | |
parent | c0c4969a4a6ce77c61f84fcb37b3efdac71d6418 (diff) | |
download | glance_store-3666d2d2e4be4524c47ba2531e39984e260c8ce8.tar.gz |
Add coverage for StoreLocation
This patch adds code coverage (UTs) for methods in StoreLocation class:
1) process_specs
2) get_uri
3) parse_uri
It also adds a missing method (_set_url_prefix) coverage in
Multistore cinder tests (test_multistore_cinder).
Change-Id: I8ced5af11669fb131c665ce53be57143f2c7b518
-rw-r--r-- | glance_store/tests/unit/test_cinder_base.py | 13 | ||||
-rw-r--r-- | glance_store/tests/unit/test_cinder_store.py | 16 | ||||
-rw-r--r-- | glance_store/tests/unit/test_multistore_cinder.py | 20 |
3 files changed, 49 insertions, 0 deletions
diff --git a/glance_store/tests/unit/test_cinder_base.py b/glance_store/tests/unit/test_cinder_base.py index 0d73347..69539fa 100644 --- a/glance_store/tests/unit/test_cinder_base.py +++ b/glance_store/tests/unit/test_cinder_base.py @@ -513,3 +513,16 @@ class TestCinderStoreBase(object): exceptions.BackendException, cinder.Store._wait_resize_device, fake_vol, fake_file) + + def test_process_specs(self): + self.location.process_specs() + self.assertEqual('cinder', self.location.scheme) + self.assertEqual(self.volume_id, self.location.volume_id) + + def _test_get_uri(self, expected_uri): + uri = self.location.get_uri() + self.assertEqual(expected_uri, uri) + + def _test_parse_uri_invalid(self, uri): + self.assertRaises( + exceptions.BadStoreUri, self.location.parse_uri, uri) diff --git a/glance_store/tests/unit/test_cinder_store.py b/glance_store/tests/unit/test_cinder_store.py index 5387aaf..1abd75c 100644 --- a/glance_store/tests/unit/test_cinder_store.py +++ b/glance_store/tests/unit/test_cinder_store.py @@ -55,6 +55,10 @@ class TestCinderStore(base.StoreBaseTest, self.hash_algo = 'sha256' cinder._reset_cinder_session() self.config(cinder_mount_point_base=None) + self.volume_id = str(uuid.uuid4()) + specs = {'scheme': 'cinder', + 'volume_id': self.volume_id} + self.location = cinder.StoreLocation(specs, self.conf) def test_get_cinderclient_with_user_overriden(self): self._test_get_cinderclient_with_user_overriden() @@ -168,3 +172,15 @@ class TestCinderStore(base.StoreBaseTest, # warning self.config(cinder_volume_type='some_random_type') self._test_configure_add_invalid_type() + + def test_get_uri(self): + expected_uri = 'cinder://%s' % self.volume_id + self._test_get_uri(expected_uri) + + def test_parse_uri_valid(self): + expected_uri = 'cinder://%s' % self.volume_id + self.location.parse_uri(expected_uri) + + def test_parse_uri_invalid(self): + uri = 'cinder://%s' % 'fake_volume' + self._test_parse_uri_invalid(uri) diff --git a/glance_store/tests/unit/test_multistore_cinder.py b/glance_store/tests/unit/test_multistore_cinder.py index 931b332..6d7a037 100644 --- a/glance_store/tests/unit/test_multistore_cinder.py +++ b/glance_store/tests/unit/test_multistore_cinder.py @@ -89,6 +89,11 @@ class TestMultiCinderStore(base.MultiStoreBaseTest, project_id='admin_project') cinder._reset_cinder_session() self.config(cinder_mount_point_base=None, group='cinder1') + self.volume_id = str(uuid.uuid4()) + specs = {'scheme': 'cinder', + 'volume_id': self.volume_id} + self.location = cinder.StoreLocation(specs, self.conf, + backend_group='cinder1') def test_location_url_prefix_is_set(self): self.assertEqual("cinder://cinder1", self.store.url_prefix) @@ -293,3 +298,18 @@ class TestMultiCinderStore(base.MultiStoreBaseTest, conf=self.conf) self.store.delete(loc, context=self.context) fake_volumes.delete.assert_called_once_with(fake_volume_uuid) + + def test_set_url_prefix(self): + self.assertEqual('cinder://cinder1', self.store._url_prefix) + + def test_get_uri(self): + expected_uri = 'cinder://cinder1/%s' % self.volume_id + self._test_get_uri(expected_uri) + + def test_parse_uri_valid(self): + expected_uri = 'cinder://cinder1/%s' % self.volume_id + self.location.parse_uri(expected_uri) + + def test_parse_uri_invalid(self): + uri = 'cinder://cinder1/%s' % 'fake_volume' + self._test_parse_uri_invalid(uri) |