summaryrefslogtreecommitdiff
path: root/glance_store/tests
diff options
context:
space:
mode:
authorArnaud Morin <arnaud.morin@ovhcloud.com>2022-08-12 20:45:27 +0200
committerArnaud Morin <arnaud.morin@ovhcloud.com>2022-12-02 11:46:46 +0100
commit2ad4a73e7f4278fe961e8c75f7f9bdbf51382b64 (patch)
tree689e08e092e3f3bb6482841cf31b35b5a768d29f /glance_store/tests
parent052c5cc4b4ed494600612018da4482213f4edc5f (diff)
downloadglance_store-2ad4a73e7f4278fe961e8c75f7f9bdbf51382b64.tar.gz
Add region_name option to s3 store
Add an option to let the operator choose a proper region_name. Some operator are not using S3 from amazon but from other provider. In such case, the get_s3_location cannot give good region_name. Adding an option from config seems a better option that relying on hardcoded stuff in the code. Signed-off-by: Arnaud Morin <arnaud.morin@ovhcloud.com> Change-Id: I71352e75f6415494709d8fb62c8b13f3ea7c6016
Diffstat (limited to 'glance_store/tests')
-rw-r--r--glance_store/tests/unit/test_multistore_s3.py17
-rw-r--r--glance_store/tests/unit/test_opts.py1
-rw-r--r--glance_store/tests/unit/test_s3_store.py24
3 files changed, 42 insertions, 0 deletions
diff --git a/glance_store/tests/unit/test_multistore_s3.py b/glance_store/tests/unit/test_multistore_s3.py
index 60c5e80..b35dca5 100644
--- a/glance_store/tests/unit/test_multistore_s3.py
+++ b/glance_store/tests/unit/test_multistore_s3.py
@@ -90,6 +90,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest,
s3_store_access_key='user',
s3_store_secret_key='key',
s3_store_host='https://s3-region1.com',
+ s3_store_region_name='custom_region_name',
s3_store_bucket='glance',
s3_store_large_object_size=S3_CONF[
's3_store_large_object_size'
@@ -132,6 +133,22 @@ class TestMultiS3Store(base.MultiStoreBaseTest,
self.assertRaises(boto_exceptions.InvalidDNSNameError,
self.store.get, loc)
+ @mock.patch('glance_store.location.Location')
+ @mock.patch.object(boto3.session.Session, "client")
+ def test_client_custom_region_name(self, mock_client, mock_loc):
+ """Test a custom s3_store_region_name in config"""
+ mock_loc.accesskey = 'abcd'
+ mock_loc.secretkey = 'efgh'
+ mock_loc.bucket = 'bucket1'
+ self.store._create_s3_client(mock_loc)
+ mock_client.assert_called_with(
+ config=mock.ANY,
+ endpoint_url='https://s3-region1.com',
+ region_name='custom_region_name',
+ service_name='s3',
+ use_ssl=False,
+ )
+
@mock.patch.object(boto3.session.Session, "client")
def test_get(self, mock_client):
"""Test a "normal" retrieval of an image in chunks."""
diff --git a/glance_store/tests/unit/test_opts.py b/glance_store/tests/unit/test_opts.py
index 5928d4f..bfb9bce 100644
--- a/glance_store/tests/unit/test_opts.py
+++ b/glance_store/tests/unit/test_opts.py
@@ -106,6 +106,7 @@ class OptsTestCase(base.StoreBaseTest):
's3_store_bucket_url_format',
's3_store_create_bucket_on_put',
's3_store_host',
+ 's3_store_region_name',
's3_store_secret_key',
's3_store_large_object_size',
's3_store_large_object_chunk_size',
diff --git a/glance_store/tests/unit/test_s3_store.py b/glance_store/tests/unit/test_s3_store.py
index 7fa7a13..583535f 100644
--- a/glance_store/tests/unit/test_s3_store.py
+++ b/glance_store/tests/unit/test_s3_store.py
@@ -41,6 +41,7 @@ FIVE_KB = 5 * units.Ki
S3_CONF = {
's3_store_access_key': 'user',
's3_store_secret_key': 'key',
+ 's3_store_region_name': '',
's3_store_host': 'localhost',
's3_store_bucket': 'glance',
's3_store_large_object_size': 9, # over 9MB is large
@@ -84,6 +85,29 @@ class TestStore(base.StoreBaseTest,
self.assertRaises(boto_exceptions.InvalidDNSNameError,
self.store.get, loc)
+ @mock.patch('glance_store.location.Location')
+ @mock.patch.object(boto3.session.Session, "client")
+ def test_client_custom_region_name(self, mock_client, mock_loc):
+ """Test a custom s3_store_region_name in config"""
+ self.config(s3_store_host='http://example.com')
+ self.config(s3_store_region_name='regionOne')
+ self.config(s3_store_bucket_url_format='path')
+ self.store.configure()
+
+ mock_loc.accesskey = 'abcd'
+ mock_loc.secretkey = 'efgh'
+ mock_loc.bucket = 'bucket1'
+
+ self.store._create_s3_client(mock_loc)
+
+ mock_client.assert_called_with(
+ config=mock.ANY,
+ endpoint_url='http://example.com',
+ region_name='regionOne',
+ service_name='s3',
+ use_ssl=False,
+ )
+
@mock.patch.object(boto3.session.Session, "client")
def test_get(self, mock_client):
"""Test a "normal" retrieval of an image in chunks."""