Merge "Assisted snapshot: use Keystone Session with Nova Client"
This commit is contained in:
commit
f60df10699
|
@ -16,7 +16,8 @@
|
|||
Handles all requests to Nova.
|
||||
"""
|
||||
|
||||
|
||||
import keystoneauth1.loading
|
||||
import keystoneauth1.session
|
||||
from novaclient import client as nova_client
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
from novaclient import service_catalog
|
||||
|
@ -134,11 +135,17 @@ def novaclient(context, admin_endpoint=False, privileged_user=False,
|
|||
|
||||
LOG.debug('Nova client connection created using URL: %s', url)
|
||||
|
||||
# Now that we have the correct auth_url, username, password and
|
||||
# project_name, let's build a Keystone session.
|
||||
loader = keystoneauth1.loading.get_plugin_loader('password')
|
||||
auth = loader.load_from_options(auth_url=url,
|
||||
username=context.user_id,
|
||||
password=context.auth_token,
|
||||
project_name=context.project_name)
|
||||
keystone_session = keystoneauth1.session.Session(auth=auth)
|
||||
|
||||
c = nova_client.Client(NOVA_API_VERSION,
|
||||
context.user_id,
|
||||
context.auth_token,
|
||||
context.project_name,
|
||||
auth_url=url,
|
||||
session=keystone_session,
|
||||
insecure=CONF.nova_api_insecure,
|
||||
timeout=timeout,
|
||||
region_name=CONF.os_region_name,
|
||||
|
|
|
@ -39,55 +39,86 @@ class NovaClientTestCase(test.TestCase):
|
|||
self.override_config('os_privileged_user_password', 'strongpassword')
|
||||
|
||||
@mock.patch('novaclient.client.Client')
|
||||
def test_nova_client_regular(self, p_client):
|
||||
@mock.patch('keystoneauth1.loading.get_plugin_loader')
|
||||
@mock.patch('keystoneauth1.session.Session')
|
||||
def test_nova_client_regular(self, p_session, p_plugin_loader, p_client):
|
||||
nova.novaclient(self.ctx)
|
||||
p_plugin_loader.return_value.load_from_options.assert_called_once_with(
|
||||
auth_url='http://novahost:8774/v2/e3f0833dc08b4cea',
|
||||
password='token', project_name=None, username='regularuser'
|
||||
)
|
||||
|
||||
p_client.assert_called_once_with(
|
||||
nova.NOVA_API_VERSION,
|
||||
'regularuser', 'token', None, region_name=None,
|
||||
auth_url='http://novahost:8774/v2/e3f0833dc08b4cea',
|
||||
session=p_session.return_value, region_name=None,
|
||||
insecure=False, endpoint_type='publicURL', cacert=None,
|
||||
timeout=None, extensions=nova.nova_extensions)
|
||||
|
||||
@mock.patch('novaclient.client.Client')
|
||||
def test_nova_client_admin_endpoint(self, p_client):
|
||||
@mock.patch('keystoneauth1.loading.get_plugin_loader')
|
||||
@mock.patch('keystoneauth1.session.Session')
|
||||
def test_nova_client_admin_endpoint(self, p_session, p_plugin_loader,
|
||||
p_client):
|
||||
nova.novaclient(self.ctx, admin_endpoint=True)
|
||||
p_plugin_loader.return_value.load_from_options.assert_called_once_with(
|
||||
auth_url='http://novaadmhost:4778/v2/e3f0833dc08b4cea',
|
||||
password='token', project_name=None, username='regularuser'
|
||||
)
|
||||
p_client.assert_called_once_with(
|
||||
nova.NOVA_API_VERSION,
|
||||
'regularuser', 'token', None, region_name=None,
|
||||
auth_url='http://novaadmhost:4778/v2/e3f0833dc08b4cea',
|
||||
session=p_session.return_value, region_name=None,
|
||||
insecure=False, endpoint_type='adminURL', cacert=None,
|
||||
timeout=None, extensions=nova.nova_extensions)
|
||||
|
||||
@mock.patch('novaclient.client.Client')
|
||||
def test_nova_client_privileged_user(self, p_client):
|
||||
@mock.patch('keystoneauth1.loading.get_plugin_loader')
|
||||
@mock.patch('keystoneauth1.session.Session')
|
||||
def test_nova_client_privileged_user(self, p_session, p_plugin_loader,
|
||||
p_client):
|
||||
nova.novaclient(self.ctx, privileged_user=True)
|
||||
p_plugin_loader.return_value.load_from_options.assert_called_once_with(
|
||||
auth_url='http://keystonehost:5000/v2.0',
|
||||
password='strongpassword', project_name=None, username='adminuser'
|
||||
)
|
||||
p_client.assert_called_once_with(
|
||||
nova.NOVA_API_VERSION,
|
||||
'adminuser', 'strongpassword', None, region_name=None,
|
||||
auth_url='http://keystonehost:5000/v2.0',
|
||||
session=p_session.return_value, region_name=None,
|
||||
insecure=False, endpoint_type='publicURL', cacert=None,
|
||||
timeout=None, extensions=nova.nova_extensions)
|
||||
|
||||
@mock.patch('novaclient.client.Client')
|
||||
def test_nova_client_privileged_user_custom_auth_url(self, p_client):
|
||||
@mock.patch('keystoneauth1.loading.get_plugin_loader')
|
||||
@mock.patch('keystoneauth1.session.Session')
|
||||
def test_nova_client_privileged_user_custom_auth_url(self, p_session,
|
||||
p_plugin_loader,
|
||||
p_client):
|
||||
self.override_config('os_privileged_user_auth_url',
|
||||
'http://privatekeystonehost:5000/v2.0')
|
||||
nova.novaclient(self.ctx, privileged_user=True)
|
||||
p_plugin_loader.return_value.load_from_options.assert_called_once_with(
|
||||
auth_url='http://privatekeystonehost:5000/v2.0',
|
||||
password='strongpassword', project_name=None, username='adminuser'
|
||||
)
|
||||
p_client.assert_called_once_with(
|
||||
nova.NOVA_API_VERSION,
|
||||
'adminuser', 'strongpassword', None, region_name=None,
|
||||
auth_url='http://privatekeystonehost:5000/v2.0',
|
||||
session=p_session.return_value, region_name=None,
|
||||
insecure=False, endpoint_type='publicURL', cacert=None,
|
||||
timeout=None, extensions=nova.nova_extensions)
|
||||
|
||||
@mock.patch('novaclient.client.Client')
|
||||
def test_nova_client_custom_region(self, p_client):
|
||||
@mock.patch('keystoneauth1.loading.get_plugin_loader')
|
||||
@mock.patch('keystoneauth1.session.Session')
|
||||
def test_nova_client_custom_region(self, p_session, p_plugin_loader,
|
||||
p_client):
|
||||
self.override_config('os_region_name', 'farfaraway')
|
||||
nova.novaclient(self.ctx)
|
||||
p_plugin_loader.return_value.load_from_options.assert_called_once_with(
|
||||
auth_url='http://novahost:8774/v2/e3f0833dc08b4cea',
|
||||
password='token', project_name=None, username='regularuser'
|
||||
)
|
||||
p_client.assert_called_once_with(
|
||||
nova.NOVA_API_VERSION,
|
||||
'regularuser', 'token', None, region_name='farfaraway',
|
||||
auth_url='http://novahost:8774/v2/e3f0833dc08b4cea',
|
||||
session=p_session.return_value, region_name='farfaraway',
|
||||
insecure=False, endpoint_type='publicURL', cacert=None,
|
||||
timeout=None, extensions=nova.nova_extensions)
|
||||
|
||||
|
|
|
@ -996,13 +996,11 @@ class InstanceLocalityFilterTestCase(HostFiltersTestCase):
|
|||
filter_properties = {'context': self.context, 'size': 100}
|
||||
self.assertTrue(filt_cls.host_passes(host, filter_properties))
|
||||
|
||||
@mock.patch('novaclient.client.discover_extensions')
|
||||
@mock.patch('requests.request')
|
||||
def test_nova_timeout(self, _mock_request, fake_extensions):
|
||||
@mock.patch('cinder.compute.nova.novaclient')
|
||||
def test_nova_timeout(self, mock_novaclient):
|
||||
# Simulate a HTTP timeout
|
||||
_mock_request.side_effect = request_exceptions.Timeout
|
||||
fake_extensions.return_value = (
|
||||
fakes.FakeNovaClient().list_extensions.show_all())
|
||||
mock_show_all = mock_novaclient.return_value.list_extensions.show_all
|
||||
mock_show_all.side_effect = request_exceptions.Timeout
|
||||
|
||||
filt_cls = self.class_map['InstanceLocalityFilter']()
|
||||
host = fakes.FakeHostState('host1', {})
|
||||
|
|
Loading…
Reference in New Issue