specify region on creating cinderclient

If cinder_store_{user_name,password,project_name} are provided,
cinder client will be created without region information.
It may cause wrong region access on some multi-region setup.

This fixes the issue by always passing `cinder_os_region_name`
value to cinderclient.

Change-Id: I835b2f0da03f29245c26c9c531b04de737d8ef5b
Closes-Bug: #1764200
This commit is contained in:
Tomoki Sekiyama 2018-07-09 15:42:10 +00:00
parent 92114fb679
commit d50ab63e13
2 changed files with 13 additions and 0 deletions

View File

@ -352,6 +352,7 @@ def get_cinderclient(conf, context=None):
password,
project,
auth_url=url,
region_name=glance_store.cinder_os_region_name,
insecure=glance_store.cinder_api_insecure,
retries=glance_store.cinder_http_retries,
cacert=glance_store.cinder_ca_certificates_file)

View File

@ -24,6 +24,7 @@ import tempfile
import time
import uuid
from cinderclient.v2 import client as cinderclient
from os_brick.initiator import connector
from oslo_concurrency import processutils
from oslo_utils import units
@ -75,6 +76,17 @@ class TestCinderStore(base.StoreBaseTest,
self.assertIsNone(cc.client.auth_token)
self.assertEqual('test_address', cc.client.management_url)
def test_get_cinderclient_with_user_overriden_and_region(self):
self.config(cinder_os_region_name='test_region')
fake_client = FakeObject(client=FakeObject(auth_token=None))
with mock.patch.object(cinderclient, 'Client',
return_value=fake_client) as mock_client:
self.test_get_cinderclient_with_user_overriden()
mock_client.assert_called_once_with(
'test_user', 'test_password', 'test_project',
auth_url='test_address', cacert=None, insecure=False,
region_name='test_region', retries=3)
def test_temporary_chown(self):
class fake_stat(object):
st_uid = 1