Load OpenStack clients only if those are used
* Move imports of clients to appropriate methods in osclients. The purpose is to speed up Rally loading. * Fix unit tests for moved imports. * Fix nova exception import. Implements: blueprint lazy-imports Change-Id: Ib6423c3b7597f6a44540871a7c40f2f39c1f8670
This commit is contained in:
parent
bcb891086c
commit
859f2abf7c
@ -13,6 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
@ -81,7 +83,7 @@ class FlavorsGenerator(base.Context):
|
||||
flavor_config = FlavorConfig(**flavor_config)
|
||||
try:
|
||||
flavor = clients.nova().flavors.create(**flavor_config)
|
||||
except osclients.nova.exceptions.Conflict as e:
|
||||
except nova_exceptions.Conflict as e:
|
||||
LOG.warning("Using already existing flavor %s" %
|
||||
flavor_config["name"])
|
||||
if logging.is_debug():
|
||||
|
@ -15,23 +15,11 @@
|
||||
|
||||
import os
|
||||
|
||||
from ceilometerclient import client as ceilometer
|
||||
from cinderclient import client as cinder
|
||||
from designateclient import v1 as designate
|
||||
import glanceclient as glance
|
||||
from heatclient import client as heat
|
||||
from ironicclient import client as ironic
|
||||
from keystoneclient import discover as keystone_discover
|
||||
from keystoneclient import exceptions as keystone_exceptions
|
||||
from keystoneclient.v2_0 import client as keystone_v2
|
||||
from keystoneclient.v3 import client as keystone_v3
|
||||
from neutronclient.neutron import client as neutron
|
||||
from novaclient import client as nova
|
||||
from oslo_config import cfg
|
||||
from saharaclient import client as sahara
|
||||
from swiftclient import client as swift
|
||||
from troveclient import client as trove
|
||||
from zaqarclient.queues import client as zaqar
|
||||
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
@ -53,10 +41,6 @@ OSCLIENTS_OPTS = [
|
||||
CONF.register_opts(OSCLIENTS_OPTS)
|
||||
|
||||
|
||||
# NOTE(boris-42): super dirty hack to fix nova python client 2.17 thread safe
|
||||
nova._adapter_pool = lambda x: nova.adapters.HTTPAdapter()
|
||||
|
||||
|
||||
def cached(func):
|
||||
"""Cache client handles."""
|
||||
|
||||
@ -143,6 +127,7 @@ class Clients(object):
|
||||
@cached
|
||||
def nova(self, version="2"):
|
||||
"""Return nova client."""
|
||||
from novaclient import client as nova
|
||||
kc = self.keystone()
|
||||
compute_api_url = kc.service_catalog.url_for(
|
||||
service_type="compute",
|
||||
@ -160,6 +145,7 @@ class Clients(object):
|
||||
@cached
|
||||
def neutron(self, version="2.0"):
|
||||
"""Return neutron client."""
|
||||
from neutronclient.neutron import client as neutron
|
||||
kc = self.keystone()
|
||||
network_api_url = kc.service_catalog.url_for(
|
||||
service_type="network",
|
||||
@ -176,6 +162,7 @@ class Clients(object):
|
||||
@cached
|
||||
def glance(self, version="1"):
|
||||
"""Return glance client."""
|
||||
import glanceclient as glance
|
||||
kc = self.keystone()
|
||||
image_api_url = kc.service_catalog.url_for(
|
||||
service_type="image",
|
||||
@ -192,6 +179,7 @@ class Clients(object):
|
||||
@cached
|
||||
def heat(self, version="1"):
|
||||
"""Return heat client."""
|
||||
from heatclient import client as heat
|
||||
kc = self.keystone()
|
||||
orchestration_api_url = kc.service_catalog.url_for(
|
||||
service_type="orchestration",
|
||||
@ -208,6 +196,7 @@ class Clients(object):
|
||||
@cached
|
||||
def cinder(self, version="1"):
|
||||
"""Return cinder client."""
|
||||
from cinderclient import client as cinder
|
||||
client = cinder.Client(version, None, None,
|
||||
http_log_debug=logging.is_debug(),
|
||||
timeout=CONF.openstack_client_http_timeout,
|
||||
@ -225,6 +214,7 @@ class Clients(object):
|
||||
@cached
|
||||
def ceilometer(self, version="2"):
|
||||
"""Return ceilometer client."""
|
||||
from ceilometerclient import client as ceilometer
|
||||
kc = self.keystone()
|
||||
metering_api_url = kc.service_catalog.url_for(
|
||||
service_type="metering",
|
||||
@ -247,6 +237,7 @@ class Clients(object):
|
||||
@cached
|
||||
def ironic(self, version="1.0"):
|
||||
"""Return Ironic client."""
|
||||
from ironicclient import client as ironic
|
||||
kc = self.keystone()
|
||||
baremetal_api_url = kc.service_catalog.url_for(
|
||||
service_type="baremetal",
|
||||
@ -263,6 +254,7 @@ class Clients(object):
|
||||
@cached
|
||||
def sahara(self, version="1.1"):
|
||||
"""Return Sahara client."""
|
||||
from saharaclient import client as sahara
|
||||
client = sahara.Client(version,
|
||||
username=self.endpoint.username,
|
||||
api_key=self.endpoint.password,
|
||||
@ -274,6 +266,7 @@ class Clients(object):
|
||||
@cached
|
||||
def zaqar(self, version=1.1):
|
||||
"""Return Zaqar client."""
|
||||
from zaqarclient.queues import client as zaqar
|
||||
kc = self.keystone()
|
||||
messaging_api_url = kc.service_catalog.url_for(
|
||||
service_type="messaging",
|
||||
@ -311,6 +304,7 @@ class Clients(object):
|
||||
@cached
|
||||
def designate(self):
|
||||
"""Return designate client."""
|
||||
from designateclient import v1 as designate
|
||||
kc = self.keystone()
|
||||
dns_api_url = kc.service_catalog.url_for(
|
||||
service_type="dns",
|
||||
@ -325,6 +319,7 @@ class Clients(object):
|
||||
@cached
|
||||
def trove(self, version="1.0"):
|
||||
"""Returns trove client."""
|
||||
from troveclient import client as trove
|
||||
client = trove.Client(version,
|
||||
username=self.endpoint.username,
|
||||
api_key=self.endpoint.password,
|
||||
@ -355,6 +350,7 @@ class Clients(object):
|
||||
@cached
|
||||
def swift(self):
|
||||
"""Return swift client."""
|
||||
from swiftclient import client as swift
|
||||
kc = self.keystone()
|
||||
object_api_url = kc.service_catalog.url_for(
|
||||
service_type="object-store",
|
||||
|
@ -16,9 +16,9 @@
|
||||
import copy
|
||||
|
||||
import mock
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
|
||||
from rally.benchmark.context import flavors
|
||||
from rally import osclients
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally.benchmark.context"
|
||||
@ -78,7 +78,7 @@ class FlavorsGeneratorTestCase(test.TestCase):
|
||||
|
||||
mock_flavor_create = mock_osclients().nova().flavors.create
|
||||
|
||||
exception = osclients.nova.exceptions.Conflict("conflict")
|
||||
exception = nova_exceptions.Conflict("conflict")
|
||||
mock_flavor_create.side_effect = exception
|
||||
|
||||
# Run
|
||||
|
@ -95,17 +95,18 @@ class OSClientsTestCase(test.TestCase):
|
||||
self.clients.verified_keystone)
|
||||
|
||||
def test_nova(self):
|
||||
with mock.patch("rally.osclients.nova") as mock_nova:
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
mock_nova.Client = mock.MagicMock(return_value=fake_nova)
|
||||
self.assertNotIn("nova", self.clients.cache)
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
mock_nova = mock.MagicMock()
|
||||
mock_nova.client.Client.return_value = fake_nova
|
||||
self.assertNotIn("nova", self.clients.cache)
|
||||
with mock.patch.dict("sys.modules", {"novaclient": mock_nova}):
|
||||
client = self.clients.nova()
|
||||
self.assertEqual(fake_nova, client)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="compute",
|
||||
endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
mock_nova.Client.assert_called_once_with(
|
||||
mock_nova.client.Client.assert_called_once_with(
|
||||
"2",
|
||||
auth_token=self.fake_keystone.auth_token,
|
||||
http_log_debug=False,
|
||||
@ -115,30 +116,34 @@ class OSClientsTestCase(test.TestCase):
|
||||
self.service_catalog.url_for.return_value)
|
||||
self.assertEqual(fake_nova, self.clients.cache["nova"])
|
||||
|
||||
@mock.patch("rally.osclients.neutron")
|
||||
def test_neutron(self, mock_neutron):
|
||||
def test_neutron(self):
|
||||
fake_neutron = fakes.FakeNeutronClient()
|
||||
mock_neutron.Client = mock.MagicMock(return_value=fake_neutron)
|
||||
mock_neutron = mock.MagicMock()
|
||||
mock_neutron.client.Client.return_value = fake_neutron
|
||||
self.assertNotIn("neutron", self.clients.cache)
|
||||
client = self.clients.neutron()
|
||||
self.assertEqual(fake_neutron, client)
|
||||
kw = {
|
||||
"token": self.fake_keystone.auth_token,
|
||||
"endpoint_url": self.service_catalog.url_for.return_value,
|
||||
"timeout": cfg.CONF.openstack_client_http_timeout,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
"ca_cert": cfg.CONF.https_cacert
|
||||
}
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="network", endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
mock_neutron.Client.assert_called_once_with("2.0", **kw)
|
||||
self.assertEqual(fake_neutron, self.clients.cache["neutron"])
|
||||
with mock.patch.dict("sys.modules", {"neutronclient.neutron":
|
||||
mock_neutron}):
|
||||
client = self.clients.neutron()
|
||||
self.assertEqual(fake_neutron, client)
|
||||
kw = {
|
||||
"token": self.fake_keystone.auth_token,
|
||||
"endpoint_url": self.service_catalog.url_for.return_value,
|
||||
"timeout": cfg.CONF.openstack_client_http_timeout,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
"ca_cert": cfg.CONF.https_cacert
|
||||
}
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="network",
|
||||
endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
mock_neutron.client.Client.assert_called_once_with("2.0", **kw)
|
||||
self.assertEqual(fake_neutron, self.clients.cache["neutron"])
|
||||
|
||||
def test_glance(self):
|
||||
with mock.patch("rally.osclients.glance") as mock_glance:
|
||||
fake_glance = fakes.FakeGlanceClient()
|
||||
mock_glance.Client = mock.MagicMock(return_value=fake_glance)
|
||||
fake_glance = fakes.FakeGlanceClient()
|
||||
mock_glance = mock.MagicMock()
|
||||
mock_glance.Client = mock.MagicMock(return_value=fake_glance)
|
||||
with mock.patch.dict("sys.modules", {"glanceclient": mock_glance}):
|
||||
self.assertNotIn("glance", self.clients.cache)
|
||||
client = self.clients.glance()
|
||||
self.assertEqual(fake_glance, client)
|
||||
@ -154,18 +159,18 @@ class OSClientsTestCase(test.TestCase):
|
||||
self.assertEqual(fake_glance, self.clients.cache["glance"])
|
||||
|
||||
def test_cinder(self):
|
||||
with mock.patch("rally.osclients.cinder") as mock_cinder:
|
||||
fake_cinder = fakes.FakeCinderClient()
|
||||
fake_cinder.client = mock.MagicMock()
|
||||
mock_cinder.Client = mock.MagicMock(return_value=fake_cinder)
|
||||
self.assertNotIn("cinder", self.clients.cache)
|
||||
fake_cinder = mock.MagicMock(client=fakes.FakeCinderClient())
|
||||
mock_cinder = mock.MagicMock()
|
||||
mock_cinder.client.Client.return_value = fake_cinder
|
||||
self.assertNotIn("cinder", self.clients.cache)
|
||||
with mock.patch.dict("sys.modules", {"cinderclient": mock_cinder}):
|
||||
client = self.clients.cinder()
|
||||
self.assertEqual(fake_cinder, client)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="volume",
|
||||
endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
mock_cinder.Client.assert_called_once_with(
|
||||
mock_cinder.client.Client.assert_called_once_with(
|
||||
"1", None, None, http_log_debug=False,
|
||||
timeout=cfg.CONF.openstack_client_http_timeout,
|
||||
insecure=False, cacert=None)
|
||||
@ -176,11 +181,13 @@ class OSClientsTestCase(test.TestCase):
|
||||
self.assertEqual(fake_cinder, self.clients.cache["cinder"])
|
||||
|
||||
def test_ceilometer(self):
|
||||
with mock.patch("rally.osclients.ceilometer") as mock_ceilometer:
|
||||
fake_ceilometer = fakes.FakeCeilometerClient()
|
||||
mock_ceilometer.get_client = mock.MagicMock(
|
||||
return_value=fake_ceilometer)
|
||||
self.assertNotIn("ceilometer", self.clients.cache)
|
||||
fake_ceilometer = fakes.FakeCeilometerClient()
|
||||
mock_ceilometer = mock.MagicMock()
|
||||
mock_ceilometer.client.get_client = mock.MagicMock(
|
||||
return_value=fake_ceilometer)
|
||||
self.assertNotIn("ceilometer", self.clients.cache)
|
||||
with mock.patch.dict("sys.modules",
|
||||
{"ceilometerclient": mock_ceilometer}):
|
||||
client = self.clients.ceilometer()
|
||||
self.assertEqual(fake_ceilometer, client)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
@ -191,91 +198,97 @@ class OSClientsTestCase(test.TestCase):
|
||||
"token": self.fake_keystone.auth_token,
|
||||
"timeout": cfg.CONF.openstack_client_http_timeout,
|
||||
"insecure": False, "cacert": None}
|
||||
mock_ceilometer.get_client.assert_called_once_with("2", **kw)
|
||||
mock_ceilometer.client.get_client.assert_called_once_with("2",
|
||||
**kw)
|
||||
self.assertEqual(fake_ceilometer,
|
||||
self.clients.cache["ceilometer"])
|
||||
|
||||
@mock.patch("rally.osclients.ironic")
|
||||
def test_ironic(self, mock_ironic):
|
||||
def test_ironic(self):
|
||||
fake_ironic = fakes.FakeIronicClient()
|
||||
mock_ironic.get_client = mock.MagicMock(return_value=fake_ironic)
|
||||
mock_ironic = mock.MagicMock()
|
||||
mock_ironic.client.get_client = mock.MagicMock(
|
||||
return_value=fake_ironic)
|
||||
self.assertNotIn("ironic", self.clients.cache)
|
||||
client = self.clients.ironic()
|
||||
self.assertEqual(fake_ironic, client)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="baremetal",
|
||||
endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
kw = {
|
||||
"os_auth_token": self.fake_keystone.auth_token,
|
||||
"ironic_url": self.service_catalog.url_for.return_value,
|
||||
"timeout": cfg.CONF.openstack_client_http_timeout,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
"cacert": cfg.CONF.https_cacert
|
||||
}
|
||||
mock_ironic.get_client.assert_called_once_with("1.0", **kw)
|
||||
self.assertEqual(fake_ironic, self.clients.cache["ironic"])
|
||||
with mock.patch.dict("sys.modules", {"ironicclient": mock_ironic}):
|
||||
client = self.clients.ironic()
|
||||
self.assertEqual(fake_ironic, client)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="baremetal",
|
||||
endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
kw = {
|
||||
"os_auth_token": self.fake_keystone.auth_token,
|
||||
"ironic_url": self.service_catalog.url_for.return_value,
|
||||
"timeout": cfg.CONF.openstack_client_http_timeout,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
"cacert": cfg.CONF.https_cacert
|
||||
}
|
||||
mock_ironic.client.get_client.assert_called_once_with("1.0", **kw)
|
||||
self.assertEqual(fake_ironic, self.clients.cache["ironic"])
|
||||
|
||||
@mock.patch("rally.osclients.sahara")
|
||||
def test_sahara(self, mock_sahara):
|
||||
def test_sahara(self):
|
||||
fake_sahara = fakes.FakeSaharaClient()
|
||||
mock_sahara.Client = mock.MagicMock(return_value=fake_sahara)
|
||||
mock_sahara = mock.MagicMock()
|
||||
mock_sahara.client.Client = mock.MagicMock(return_value=fake_sahara)
|
||||
self.assertNotIn("sahara", self.clients.cache)
|
||||
client = self.clients.sahara()
|
||||
self.assertEqual(fake_sahara, client)
|
||||
kw = {
|
||||
"username": self.endpoint.username,
|
||||
"api_key": self.endpoint.password,
|
||||
"project_name": self.endpoint.tenant_name,
|
||||
"auth_url": self.endpoint.auth_url
|
||||
}
|
||||
mock_sahara.Client.assert_called_once_with("1.1", **kw)
|
||||
self.assertEqual(fake_sahara, self.clients.cache["sahara"])
|
||||
with mock.patch.dict("sys.modules", {"saharaclient": mock_sahara}):
|
||||
client = self.clients.sahara()
|
||||
self.assertEqual(fake_sahara, client)
|
||||
kw = {
|
||||
"username": self.endpoint.username,
|
||||
"api_key": self.endpoint.password,
|
||||
"project_name": self.endpoint.tenant_name,
|
||||
"auth_url": self.endpoint.auth_url
|
||||
}
|
||||
mock_sahara.client.Client.assert_called_once_with("1.1", **kw)
|
||||
self.assertEqual(fake_sahara, self.clients.cache["sahara"])
|
||||
|
||||
@mock.patch("rally.osclients.zaqar")
|
||||
def test_zaqar(self, mock_zaqar):
|
||||
def test_zaqar(self):
|
||||
fake_zaqar = fakes.FakeZaqarClient()
|
||||
mock_zaqar.Client = mock.MagicMock(return_value=fake_zaqar)
|
||||
mock_zaqar = mock.MagicMock()
|
||||
mock_zaqar.client.Client = mock.MagicMock(return_value=fake_zaqar)
|
||||
self.assertNotIn("zaqar", self.clients.cache)
|
||||
client = self.clients.zaqar()
|
||||
self.assertEqual(fake_zaqar, client)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="messaging",
|
||||
endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
fake_zaqar_url = self.service_catalog.url_for.return_value
|
||||
conf = {"auth_opts": {"backend": "keystone", "options": {
|
||||
"os_username": self.endpoint.username,
|
||||
"os_password": self.endpoint.password,
|
||||
"os_project_name": self.endpoint.tenant_name,
|
||||
"os_project_id": self.fake_keystone.auth_tenant_id,
|
||||
"os_auth_url": self.endpoint.auth_url,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
}}}
|
||||
mock_zaqar.Client.assert_called_once_with(url=fake_zaqar_url,
|
||||
version=1.1,
|
||||
conf=conf)
|
||||
self.assertEqual(fake_zaqar, self.clients.cache["zaqar"])
|
||||
with mock.patch.dict("sys.modules", {"zaqarclient.queues":
|
||||
mock_zaqar}):
|
||||
client = self.clients.zaqar()
|
||||
self.assertEqual(fake_zaqar, client)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
service_type="messaging",
|
||||
endpoint_type=consts.EndpointType.PUBLIC,
|
||||
region_name=self.endpoint.region_name)
|
||||
fake_zaqar_url = self.service_catalog.url_for.return_value
|
||||
conf = {"auth_opts": {"backend": "keystone", "options": {
|
||||
"os_username": self.endpoint.username,
|
||||
"os_password": self.endpoint.password,
|
||||
"os_project_name": self.endpoint.tenant_name,
|
||||
"os_project_id": self.fake_keystone.auth_tenant_id,
|
||||
"os_auth_url": self.endpoint.auth_url,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
}}}
|
||||
mock_zaqar.client.Client.assert_called_once_with(
|
||||
url=fake_zaqar_url, version=1.1, conf=conf)
|
||||
self.assertEqual(fake_zaqar, self.clients.cache["zaqar"])
|
||||
|
||||
@mock.patch("rally.osclients.trove")
|
||||
def test_trove(self, mock_trove):
|
||||
def test_trove(self):
|
||||
fake_trove = fakes.FakeTroveClient()
|
||||
mock_trove.Client = mock.MagicMock(return_value=fake_trove)
|
||||
mock_trove = mock.MagicMock()
|
||||
mock_trove.client.Client = mock.MagicMock(return_value=fake_trove)
|
||||
self.assertNotIn("trove", self.clients.cache)
|
||||
client = self.clients.trove()
|
||||
self.assertEqual(fake_trove, client)
|
||||
kw = {
|
||||
"username": self.endpoint.username,
|
||||
"api_key": self.endpoint.password,
|
||||
"project_id": self.endpoint.tenant_name,
|
||||
"auth_url": self.endpoint.auth_url,
|
||||
"region_name": self.endpoint.region_name,
|
||||
"timeout": cfg.CONF.openstack_client_http_timeout,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
"cacert": cfg.CONF.https_cacert
|
||||
}
|
||||
mock_trove.Client.assert_called_once_with("1.0", **kw)
|
||||
self.assertEqual(fake_trove, self.clients.cache["trove"])
|
||||
with mock.patch.dict("sys.modules", {"troveclient": mock_trove}):
|
||||
client = self.clients.trove()
|
||||
self.assertEqual(fake_trove, client)
|
||||
kw = {
|
||||
"username": self.endpoint.username,
|
||||
"api_key": self.endpoint.password,
|
||||
"project_id": self.endpoint.tenant_name,
|
||||
"auth_url": self.endpoint.auth_url,
|
||||
"region_name": self.endpoint.region_name,
|
||||
"timeout": cfg.CONF.openstack_client_http_timeout,
|
||||
"insecure": cfg.CONF.https_insecure,
|
||||
"cacert": cfg.CONF.https_cacert
|
||||
}
|
||||
mock_trove.client.Client.assert_called_once_with("1.0", **kw)
|
||||
self.assertEqual(fake_trove, self.clients.cache["trove"])
|
||||
|
||||
def test_mistral(self):
|
||||
fake_mistral = fakes.FakeMistralClient()
|
||||
@ -302,10 +315,11 @@ class OSClientsTestCase(test.TestCase):
|
||||
self.assertEqual(fake_mistral, self.clients.cache["mistral"])
|
||||
|
||||
def test_swift(self):
|
||||
with mock.patch("rally.osclients.swift") as mock_swift:
|
||||
fake_swift = fakes.FakeSwiftClient()
|
||||
mock_swift.Connection = mock.MagicMock(return_value=fake_swift)
|
||||
self.assertNotIn("swift", self.clients.cache)
|
||||
fake_swift = fakes.FakeSwiftClient()
|
||||
mock_swift = mock.MagicMock()
|
||||
mock_swift.client.Connection = mock.MagicMock(return_value=fake_swift)
|
||||
self.assertNotIn("swift", self.clients.cache)
|
||||
with mock.patch.dict("sys.modules", {"swiftclient": mock_swift}):
|
||||
client = self.clients.swift()
|
||||
self.assertEqual(client, fake_swift)
|
||||
self.service_catalog.url_for.assert_called_once_with(
|
||||
@ -317,7 +331,7 @@ class OSClientsTestCase(test.TestCase):
|
||||
"preauthtoken": self.fake_keystone.auth_token,
|
||||
"insecure": False,
|
||||
"cacert": None}
|
||||
mock_swift.Connection.assert_called_once_with(**kw)
|
||||
mock_swift.client.Connection.assert_called_once_with(**kw)
|
||||
self.assertEqual(self.clients.cache["swift"], fake_swift)
|
||||
|
||||
def test_ec2(self):
|
||||
|
@ -122,77 +122,87 @@ class ConfigTestCase(test.TestCase):
|
||||
self.conf_generator.conf.items("compute-admin"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
|
||||
@mock.patch("rally.osclients.nova")
|
||||
def test__set_compute_flavors(self, mock_nova):
|
||||
def test__set_compute_flavors(self):
|
||||
mock_novaclient = mock.MagicMock()
|
||||
mock_novaclient.flavors.list.return_value = [
|
||||
fakes.FakeFlavor(id="id1"), fakes.FakeFlavor(id="id2")]
|
||||
mock_nova.Client.return_value = mock_novaclient
|
||||
self.conf_generator._set_compute_flavors()
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "flavor_ref"),
|
||||
self.conf_generator.conf.get("compute", "flavor_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
mock_nova = mock.MagicMock()
|
||||
mock_nova.client.Client.return_value = mock_novaclient
|
||||
with mock.patch.dict("sys.modules", {"novaclient": mock_nova}):
|
||||
self.conf_generator._set_compute_flavors()
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "flavor_ref"),
|
||||
self.conf_generator.conf.get("compute",
|
||||
"flavor_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
|
||||
@mock.patch("rally.osclients.nova")
|
||||
def test__set_compute_flavors_create(self, mock_nova):
|
||||
def test__set_compute_flavors_create(self):
|
||||
mock_novaclient = mock.MagicMock()
|
||||
mock_novaclient.flavors.list.return_value = []
|
||||
mock_novaclient.flavors.create.side_effect = [
|
||||
fakes.FakeFlavor(id="id1"), fakes.FakeFlavor(id="id2")]
|
||||
mock_nova.Client.return_value = mock_novaclient
|
||||
self.conf_generator._set_compute_flavors()
|
||||
self.assertEqual(mock_novaclient.flavors.create.call_count, 2)
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "flavor_ref"),
|
||||
self.conf_generator.conf.get("compute", "flavor_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
mock_nova = mock.MagicMock()
|
||||
mock_nova.client.Client.return_value = mock_novaclient
|
||||
with mock.patch.dict("sys.modules", {"novaclient": mock_nova}):
|
||||
self.conf_generator._set_compute_flavors()
|
||||
self.assertEqual(mock_novaclient.flavors.create.call_count, 2)
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "flavor_ref"),
|
||||
self.conf_generator.conf.get("compute",
|
||||
"flavor_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
|
||||
@mock.patch("rally.osclients.nova")
|
||||
def test__set_compute_flavors_create_fails(self, mock_nova):
|
||||
def test__set_compute_flavors_create_fails(self):
|
||||
mock_novaclient = mock.MagicMock()
|
||||
mock_novaclient.flavors.list.return_value = []
|
||||
mock_novaclient.flavors.create.side_effect = Exception()
|
||||
mock_nova.Client.return_value = mock_novaclient
|
||||
self.assertRaises(config.TempestConfigCreationFailure,
|
||||
self.conf_generator._set_compute_flavors)
|
||||
mock_nova = mock.MagicMock()
|
||||
mock_nova.client.Client.return_value = mock_novaclient
|
||||
with mock.patch.dict("sys.modules", {"novaclient": mock_nova}):
|
||||
self.assertRaises(config.TempestConfigCreationFailure,
|
||||
self.conf_generator._set_compute_flavors)
|
||||
|
||||
@mock.patch("rally.osclients.glance")
|
||||
def test__set_compute_images(self, mock_glance):
|
||||
def test__set_compute_images(self):
|
||||
mock_glanceclient = mock.MagicMock()
|
||||
mock_glanceclient.images.list.return_value = [
|
||||
fakes.FakeImage(id="id1", name="cirros1"),
|
||||
fakes.FakeImage(id="id2", name="cirros2")]
|
||||
mock_glance = mock.MagicMock()
|
||||
mock_glance.Client.return_value = mock_glanceclient
|
||||
self.conf_generator._set_compute_images()
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "image_ref"),
|
||||
self.conf_generator.conf.get("compute", "image_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
with mock.patch.dict("sys.modules", {"glanceclient": mock_glance}):
|
||||
self.conf_generator._set_compute_images()
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "image_ref"),
|
||||
self.conf_generator.conf.get("compute",
|
||||
"image_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
|
||||
@mock.patch("rally.osclients.glance")
|
||||
@mock.patch("six.moves.builtins.open")
|
||||
def test__set_compute_images_create(self, mock_open, mock_glance):
|
||||
def test__set_compute_images_create(self, mock_open):
|
||||
mock_glanceclient = mock.MagicMock()
|
||||
mock_glanceclient.images.list.return_value = []
|
||||
mock_glanceclient.images.create.side_effect = [
|
||||
fakes.FakeImage(id="id1"), fakes.FakeImage(id="id2")]
|
||||
mock_glance = mock.MagicMock()
|
||||
mock_glance.Client.return_value = mock_glanceclient
|
||||
self.conf_generator._set_compute_images()
|
||||
self.assertEqual(mock_glanceclient.images.create.call_count, 2)
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "image_ref"),
|
||||
self.conf_generator.conf.get("compute", "image_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
with mock.patch.dict("sys.modules", {"glanceclient": mock_glance}):
|
||||
self.conf_generator._set_compute_images()
|
||||
self.assertEqual(mock_glanceclient.images.create.call_count, 2)
|
||||
expected = ("id1", "id2")
|
||||
results = (self.conf_generator.conf.get("compute", "image_ref"),
|
||||
self.conf_generator.conf.get("compute",
|
||||
"image_ref_alt"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
|
||||
@mock.patch("rally.osclients.glance")
|
||||
def test__set_compute_images_create_fails(self, mock_glance):
|
||||
def test__set_compute_images_create_fails(self):
|
||||
mock_glanceclient = mock.MagicMock()
|
||||
mock_glanceclient.images.list.return_value = []
|
||||
mock_glanceclient.images.create.side_effect = Exception()
|
||||
mock_glance = mock.MagicMock()
|
||||
mock_glance.Client.return_value = mock_glanceclient
|
||||
self.assertRaises(config.TempestConfigCreationFailure,
|
||||
self.conf_generator._set_compute_images)
|
||||
with mock.patch.dict("sys.modules", {"glanceclient": mock_glance}):
|
||||
self.assertRaises(config.TempestConfigCreationFailure,
|
||||
self.conf_generator._set_compute_images)
|
||||
|
||||
def test__set_compute_ssh_connect_method_if_neutron(self):
|
||||
self.conf_generator._set_compute_ssh_connect_method()
|
||||
@ -235,8 +245,7 @@ class ConfigTestCase(test.TestCase):
|
||||
self.conf_generator.conf.items("identity"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
|
||||
@mock.patch("rally.osclients.neutron")
|
||||
def test__set_network_if_neutron(self, mock_neutron):
|
||||
def test__set_network_if_neutron(self):
|
||||
fake_neutronclient = mock.MagicMock()
|
||||
fake_neutronclient.list_networks.return_value = {"networks": [
|
||||
{"status": "ACTIVE",
|
||||
@ -248,30 +257,34 @@ class ConfigTestCase(test.TestCase):
|
||||
fake_neutronclient.list_subnets.return_value = {"subnets": [
|
||||
{"cidr":
|
||||
"10.0.0.0/24"}]}
|
||||
mock_neutron.Client.return_value = fake_neutronclient
|
||||
self.conf_generator.available_services = ["neutron"]
|
||||
self.conf_generator._set_network()
|
||||
expected = (("default_network", "10.0.0.0/24"),
|
||||
("tenant_networks_reachable", "false"),
|
||||
("api_version", "2.0"),
|
||||
("public_network_id", "test_id"),
|
||||
("public_router_id", "test_router"))
|
||||
results = self._remove_default_section(
|
||||
self.conf_generator.conf.items("network"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
mock_neutron = mock.MagicMock()
|
||||
mock_neutron.client.Client.return_value = fake_neutronclient
|
||||
with mock.patch.dict("sys.modules", {"neutronclient.neutron":
|
||||
mock_neutron}):
|
||||
self.conf_generator.available_services = ["neutron"]
|
||||
self.conf_generator._set_network()
|
||||
expected = (("default_network", "10.0.0.0/24"),
|
||||
("tenant_networks_reachable", "false"),
|
||||
("api_version", "2.0"),
|
||||
("public_network_id", "test_id"),
|
||||
("public_router_id", "test_router"))
|
||||
results = self._remove_default_section(
|
||||
self.conf_generator.conf.items("network"))
|
||||
self.assertEqual(sorted(expected), sorted(results))
|
||||
|
||||
@mock.patch("rally.osclients.nova")
|
||||
def test__set_network_if_nova(self, mock_nova):
|
||||
def test__set_network_if_nova(self):
|
||||
network = "10.0.0.0/24"
|
||||
mock_novaclient = mock.MagicMock()
|
||||
mock_network = mock.MagicMock()
|
||||
mock_network.cidr = network
|
||||
mock_novaclient.networks.list.return_value = [mock_network]
|
||||
mock_nova.Client.return_value = mock_novaclient
|
||||
self.conf_generator._set_network()
|
||||
self.assertEqual(network,
|
||||
self.conf_generator.conf.get("network",
|
||||
"default_network"))
|
||||
mock_nova = mock.MagicMock()
|
||||
mock_nova.client.Client.return_value = mock_novaclient
|
||||
with mock.patch.dict("sys.modules", {"novaclient": mock_nova}):
|
||||
self.conf_generator._set_network()
|
||||
self.assertEqual(network,
|
||||
self.conf_generator.conf.get("network",
|
||||
"default_network"))
|
||||
|
||||
@mock.patch("rally.verification.tempest.config.requests")
|
||||
def test__set_service_available(self, mock_requests):
|
||||
|
Loading…
x
Reference in New Issue
Block a user