Reduce hardcode to OpenStack

* fix rally deployment check command

Change-Id: Ib337a19575e2fc21decd1aa6b3ff9fac076931e4
This commit is contained in:
Andrey Kurilin
2017-03-30 20:26:31 +03:00
parent 367e2b58b3
commit 95c83e4a51
2 changed files with 27 additions and 7 deletions

View File

@@ -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,

View File

@@ -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):