diff --git a/rally/plugins/openstack/credential.py b/rally/plugins/openstack/credential.py index 1a34bf8f..85c6055c 100644 --- a/rally/plugins/openstack/credential.py +++ b/rally/plugins/openstack/credential.py @@ -13,11 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. - +from rally.common import logging from rally import consts from rally.deployment import credential +from rally import exceptions from rally import osclients +LOG = logging.getLogger(__file__) + @credential.configure("openstack") class OpenStackCredential(credential.Credential): @@ -49,11 +52,15 @@ class OpenStackCredential(credential.Credential): # backward compatibility @property def insecure(self): + LOG.warning("Property 'insecure' is deprecated since Rally 0.10.0. " + "Use 'https_insecure' instead.") return self.https_insecure # backward compatibility @property def cacert(self): + LOG.warning("Property 'cacert' is deprecated since Rally 0.10.0. " + "Use 'https_cacert' instead.") return self.https_cacert def to_dict(self): @@ -72,13 +79,23 @@ class OpenStackCredential(credential.Credential): "permission": self.permission} def verify_connection(self): - if self.permission == consts.EndpointPermission.ADMIN: - self.clients().verified_keystone() - else: - self.clients().keystone() + from keystoneclient import exceptions as keystone_exceptions + + try: + if self.permission == consts.EndpointPermission.ADMIN: + self.clients().verified_keystone() + else: + self.clients().keystone() + except keystone_exceptions.ConnectionRefused as e: + if logging.is_debug(): + LOG.exception(e) + raise exceptions.RallyException("Unable to connect %s." % + self.auth_url) def list_services(self): - return self.clients().services() + return sorted([{"type": stype, "name": sname} + for stype, sname in self.clients().services().items()], + key=lambda s: s["name"]) def clients(self, api_info=None): return osclients.Clients(self, api_info=api_info, diff --git a/tests/unit/plugins/openstack/test_credential.py b/tests/unit/plugins/openstack/test_credential.py index 28e0d7f4..bd58e4fe 100644 --- a/tests/unit/plugins/openstack/test_credential.py +++ b/tests/unit/plugins/openstack/test_credential.py @@ -63,11 +63,14 @@ class OpenStackCredentialTestCase(test.TestCase): @mock.patch("rally.osclients.Clients") def test_list_services(self, mock_clients): + mock_clients.return_value.services.return_value = {"compute": "nova", + "volume": "cinder"} result = self.credential.list_services() mock_clients.assert_called_once_with( self.credential, api_info=None, cache={}) mock_clients.return_value.services.assert_called_once_with() - self.assertIs(mock_clients.return_value.services.return_value, result) + self.assertEqual([{"name": "cinder", "type": "volume"}, + {"name": "nova", "type": "compute"}], result) @mock.patch("rally.osclients.Clients") def test_clients(self, mock_clients):