Delete depracated types stuff from Rally
Also replace old types style stuff to the new one. Change-Id: Id6e1d248278b2fb340109a33413e373d1061f7f7
This commit is contained in:
parent
e6df59923f
commit
1d7484a6b1
@ -19,8 +19,8 @@ from rally import consts
|
|||||||
from rally import osclients
|
from rally import osclients
|
||||||
from rally.plugins.openstack.cleanup import manager as resource_manager
|
from rally.plugins.openstack.cleanup import manager as resource_manager
|
||||||
from rally.plugins.openstack.scenarios.ec2 import utils as ec2_utils
|
from rally.plugins.openstack.scenarios.ec2 import utils as ec2_utils
|
||||||
|
from rally.plugins.openstack import types
|
||||||
from rally.task import context
|
from rally.task import context
|
||||||
from rally.task import types
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -68,8 +68,8 @@ class EC2ServerGenerator(context.Context):
|
|||||||
flavor = self.config["flavor"]
|
flavor = self.config["flavor"]
|
||||||
|
|
||||||
clients = osclients.Clients(self.context["users"][0]["credential"])
|
clients = osclients.Clients(self.context["users"][0]["credential"])
|
||||||
image_id = types.EC2ImageResourceType.transform(clients=clients,
|
image_id = types.EC2Image.transform(clients=clients,
|
||||||
resource_config=image)
|
resource_config=image)
|
||||||
|
|
||||||
for user, tenant_id in rutils.iterate_per_tenants(
|
for user, tenant_id in rutils.iterate_per_tenants(
|
||||||
self.context["users"]):
|
self.context["users"]):
|
||||||
|
@ -19,8 +19,8 @@ from rally import consts
|
|||||||
from rally import osclients
|
from rally import osclients
|
||||||
from rally.plugins.openstack.cleanup import manager as resource_manager
|
from rally.plugins.openstack.cleanup import manager as resource_manager
|
||||||
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||||
|
from rally.plugins.openstack import types
|
||||||
from rally.task import context
|
from rally.task import context
|
||||||
from rally.task import types
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -78,10 +78,10 @@ class ServerGenerator(context.Context):
|
|||||||
servers_per_tenant = self.config["servers_per_tenant"]
|
servers_per_tenant = self.config["servers_per_tenant"]
|
||||||
|
|
||||||
clients = osclients.Clients(self.context["users"][0]["credential"])
|
clients = osclients.Clients(self.context["users"][0]["credential"])
|
||||||
image_id = types.ImageResourceType.transform(clients=clients,
|
image_id = types.GlanceImage.transform(clients=clients,
|
||||||
resource_config=image)
|
resource_config=image)
|
||||||
flavor_id = types.FlavorResourceType.transform(clients=clients,
|
flavor_id = types.Flavor.transform(clients=clients,
|
||||||
resource_config=flavor)
|
resource_config=flavor)
|
||||||
|
|
||||||
for iter_, (user, tenant_id) in enumerate(rutils.iterate_per_tenants(
|
for iter_, (user, tenant_id) in enumerate(rutils.iterate_per_tenants(
|
||||||
self.context["users"])):
|
self.context["users"])):
|
||||||
|
@ -25,8 +25,8 @@ from rally import consts
|
|||||||
from rally import osclients
|
from rally import osclients
|
||||||
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||||
from rally.plugins.openstack.scenarios.vm import vmtasks
|
from rally.plugins.openstack.scenarios.vm import vmtasks
|
||||||
|
from rally.plugins.openstack import types
|
||||||
from rally.task import context
|
from rally.task import context
|
||||||
from rally.task import types
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -147,9 +147,9 @@ class BaseCustomImageGenerator(context.Context):
|
|||||||
|
|
||||||
clients = osclients.Clients(user["credential"])
|
clients = osclients.Clients(user["credential"])
|
||||||
|
|
||||||
image_id = types.ImageResourceType.transform(
|
image_id = types.GlanceImage.transform(
|
||||||
clients=clients, resource_config=self.config["image"])
|
clients=clients, resource_config=self.config["image"])
|
||||||
flavor_id = types.FlavorResourceType.transform(
|
flavor_id = types.Flavor.transform(
|
||||||
clients=clients, resource_config=self.config["flavor"])
|
clients=clients, resource_config=self.config["flavor"])
|
||||||
|
|
||||||
vm_scenario = vmtasks.VMTasks(self.context, clients=clients)
|
vm_scenario = vmtasks.VMTasks(self.context, clients=clients)
|
||||||
|
@ -16,35 +16,13 @@
|
|||||||
import abc
|
import abc
|
||||||
import copy
|
import copy
|
||||||
import operator
|
import operator
|
||||||
import os.path
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from rally.common.i18n import _
|
|
||||||
from rally.common import logging
|
|
||||||
from rally.common.plugin import plugin
|
from rally.common.plugin import plugin
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally import osclients
|
from rally import osclients
|
||||||
from rally.task import scenario
|
from rally.task import scenario
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@logging.log_deprecated("Use types.convert() instead", "0.3.2", once=True)
|
|
||||||
def set(**kwargs):
|
|
||||||
"""Decorator to define resource transformation(s) on scenario parameters.
|
|
||||||
|
|
||||||
The `kwargs` passed as arguments to the decorator are used to
|
|
||||||
map a key in the scenario config to the subclass of ResourceType
|
|
||||||
used to perform a transformation on the value of that key.
|
|
||||||
"""
|
|
||||||
def wrapper(func):
|
|
||||||
func._meta_setdefault("preprocessors", {})
|
|
||||||
func._meta_get("preprocessors").update(kwargs)
|
|
||||||
return func
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
def _get_preprocessor_loader(plugin_name):
|
def _get_preprocessor_loader(plugin_name):
|
||||||
"""Get a class that loads a preprocessor class.
|
"""Get a class that loads a preprocessor class.
|
||||||
@ -62,8 +40,6 @@ def _get_preprocessor_loader(plugin_name):
|
|||||||
we can be certain that all plugins have been loaded and finding
|
we can be certain that all plugins have been loaded and finding
|
||||||
them by name will work.
|
them by name will work.
|
||||||
"""
|
"""
|
||||||
# NOTE(stpierre): This technically doesn't work, because
|
|
||||||
# ResourceType subclasses aren't plugins (yet)
|
|
||||||
def transform(cls, *args, **kwargs):
|
def transform(cls, *args, **kwargs):
|
||||||
plug = ResourceType.get(plugin_name)
|
plug = ResourceType.get(plugin_name)
|
||||||
return plug.transform(*args, **kwargs)
|
return plug.transform(*args, **kwargs)
|
||||||
@ -139,20 +115,6 @@ class ResourceType(plugin.Plugin):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class DeprecatedResourceType(object):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@abc.abstractmethod
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Transform the resource.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: scenario config of resource
|
|
||||||
|
|
||||||
:returns: transformed value of resource
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def obj_from_name(resource_config, resources, typename):
|
def obj_from_name(resource_config, resources, typename):
|
||||||
"""Return the resource whose name matches the pattern.
|
"""Return the resource whose name matches the pattern.
|
||||||
|
|
||||||
@ -271,232 +233,3 @@ def _name_from_id(resource_config, resources, typename):
|
|||||||
:returns: resource name mapped to `id`
|
:returns: resource name mapped to `id`
|
||||||
"""
|
"""
|
||||||
return obj_from_id(resource_config, resources, typename).name
|
return obj_from_id(resource_config, resources, typename).name
|
||||||
|
|
||||||
|
|
||||||
def log_deprecated_resource_type(func):
|
|
||||||
"""Decorator that logs use of deprecated resource type classes.
|
|
||||||
|
|
||||||
This should only be used on the transform() function.
|
|
||||||
"""
|
|
||||||
def inner(cls, clients, resource_config):
|
|
||||||
LOG.warning(_("%s is deprecated in Rally v0.3.2; use the "
|
|
||||||
"equivalent resource plugin name instead") %
|
|
||||||
cls.__name__)
|
|
||||||
return func(cls, clients, resource_config)
|
|
||||||
|
|
||||||
return inner
|
|
||||||
|
|
||||||
|
|
||||||
class FlavorResourceType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Transform the resource config to id.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: scenario config with `id`, `name` or `regex`
|
|
||||||
|
|
||||||
:returns: id matching resource
|
|
||||||
"""
|
|
||||||
resource_id = resource_config.get("id")
|
|
||||||
if not resource_id:
|
|
||||||
novaclient = clients.nova()
|
|
||||||
resource_id = _id_from_name(resource_config=resource_config,
|
|
||||||
resources=novaclient.flavors.list(),
|
|
||||||
typename="flavor")
|
|
||||||
return resource_id
|
|
||||||
|
|
||||||
|
|
||||||
class EC2FlavorResourceType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Transform the resource config to name.
|
|
||||||
|
|
||||||
In the case of using EC2 API, flavor name is used for launching
|
|
||||||
servers.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: scenario config with `id`, `name` or `regex`
|
|
||||||
|
|
||||||
:returns: name matching resource
|
|
||||||
"""
|
|
||||||
resource_name = resource_config.get("name")
|
|
||||||
if not resource_name:
|
|
||||||
# NOTE(wtakase): gets resource name from OpenStack id
|
|
||||||
novaclient = clients.nova()
|
|
||||||
resource_name = _name_from_id(resource_config=resource_config,
|
|
||||||
resources=novaclient.flavors.list(),
|
|
||||||
typename="flavor")
|
|
||||||
return resource_name
|
|
||||||
|
|
||||||
|
|
||||||
class ImageResourceType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Transform the resource config to id.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: scenario config with `id`, `name` or `regex`
|
|
||||||
|
|
||||||
:returns: id matching resource
|
|
||||||
"""
|
|
||||||
resource_id = resource_config.get("id")
|
|
||||||
if not resource_id:
|
|
||||||
glanceclient = clients.glance()
|
|
||||||
resource_id = _id_from_name(resource_config=resource_config,
|
|
||||||
resources=list(
|
|
||||||
glanceclient.images.list()),
|
|
||||||
typename="image")
|
|
||||||
return resource_id
|
|
||||||
|
|
||||||
|
|
||||||
class EC2ImageResourceType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Transform the resource config to EC2 id.
|
|
||||||
|
|
||||||
If OpenStack resource id is given, this function gets resource name
|
|
||||||
from the id and then gets EC2 resource id from the name.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: scenario config with `id`, `name` or `regex`
|
|
||||||
|
|
||||||
:returns: EC2 id matching resource
|
|
||||||
"""
|
|
||||||
if "name" not in resource_config and "regex" not in resource_config:
|
|
||||||
# NOTE(wtakase): gets resource name from OpenStack id
|
|
||||||
glanceclient = clients.glance()
|
|
||||||
resource_name = _name_from_id(resource_config=resource_config,
|
|
||||||
resources=list(
|
|
||||||
glanceclient.images.list()),
|
|
||||||
typename="image")
|
|
||||||
resource_config["name"] = resource_name
|
|
||||||
|
|
||||||
# NOTE(wtakase): gets EC2 resource id from name or regex
|
|
||||||
ec2client = clients.ec2()
|
|
||||||
resource_ec2_id = _id_from_name(resource_config=resource_config,
|
|
||||||
resources=list(
|
|
||||||
ec2client.get_all_images()),
|
|
||||||
typename="ec2_image")
|
|
||||||
return resource_ec2_id
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeTypeResourceType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Transform the resource config to id.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: scenario config with `id`, `name` or `regex`
|
|
||||||
|
|
||||||
:returns: id matching resource
|
|
||||||
"""
|
|
||||||
resource_id = resource_config.get("id")
|
|
||||||
if not resource_id:
|
|
||||||
cinderclient = clients.cinder()
|
|
||||||
resource_id = _id_from_name(resource_config=resource_config,
|
|
||||||
resources=cinderclient.
|
|
||||||
volume_types.list(),
|
|
||||||
typename="volume_type")
|
|
||||||
return resource_id
|
|
||||||
|
|
||||||
|
|
||||||
class NeutronNetworkResourceType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Transform the resource config to id.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: scenario config with `id`, `name` or `regex`
|
|
||||||
|
|
||||||
:returns: id matching resource
|
|
||||||
"""
|
|
||||||
resource_id = resource_config.get("id")
|
|
||||||
if resource_id:
|
|
||||||
return resource_id
|
|
||||||
else:
|
|
||||||
neutronclient = clients.neutron()
|
|
||||||
for net in neutronclient.list_networks()["networks"]:
|
|
||||||
if net["name"] == resource_config.get("name"):
|
|
||||||
return net["id"]
|
|
||||||
|
|
||||||
raise exceptions.InvalidScenarioArgument(
|
|
||||||
"Neutron network with name '{name}' not found".format(
|
|
||||||
name=resource_config.get("name")))
|
|
||||||
|
|
||||||
|
|
||||||
class FilePathOrUrlType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Check whether file exists or url available.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: path or url
|
|
||||||
|
|
||||||
:returns: url or expanded file path
|
|
||||||
"""
|
|
||||||
|
|
||||||
path = os.path.expanduser(resource_config)
|
|
||||||
if os.path.isfile(path):
|
|
||||||
return path
|
|
||||||
try:
|
|
||||||
head = requests.head(path)
|
|
||||||
if head.status_code == 200:
|
|
||||||
return path
|
|
||||||
raise exceptions.InvalidScenarioArgument(
|
|
||||||
"Url %s unavailable (code %s)" % (path, head.status_code))
|
|
||||||
except Exception as ex:
|
|
||||||
raise exceptions.InvalidScenarioArgument(
|
|
||||||
"Url error %s (%s)" % (path, ex))
|
|
||||||
|
|
||||||
|
|
||||||
class FileType(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Return content of the file by its path.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: path to file
|
|
||||||
|
|
||||||
:returns: content of the file
|
|
||||||
"""
|
|
||||||
|
|
||||||
with open(os.path.expanduser(resource_config), "r") as f:
|
|
||||||
return f.read()
|
|
||||||
|
|
||||||
|
|
||||||
class FileTypeDict(DeprecatedResourceType):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@log_deprecated_resource_type
|
|
||||||
def transform(cls, clients, resource_config):
|
|
||||||
"""Return the dictionary of items with file path and file content.
|
|
||||||
|
|
||||||
:param clients: openstack admin client handles
|
|
||||||
:param resource_config: list of file paths
|
|
||||||
|
|
||||||
:returns: dictionary {file_path: file_content, ...}
|
|
||||||
"""
|
|
||||||
|
|
||||||
file_type_dict = {}
|
|
||||||
for file_path in resource_config:
|
|
||||||
file_path = os.path.expanduser(file_path)
|
|
||||||
with open(file_path, "r") as f:
|
|
||||||
file_type_dict[file_path] = f.read()
|
|
||||||
|
|
||||||
return file_type_dict
|
|
||||||
|
@ -28,6 +28,7 @@ from rally import consts
|
|||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally import osclients
|
from rally import osclients
|
||||||
from rally.plugins.openstack.context.nova import flavors as flavors_ctx
|
from rally.plugins.openstack.context.nova import flavors as flavors_ctx
|
||||||
|
from rally.plugins.openstack import types as openstack_types
|
||||||
from rally.task import types
|
from rally.task import types
|
||||||
from rally.verification.tempest import tempest
|
from rally.verification.tempest import tempest
|
||||||
|
|
||||||
@ -253,7 +254,7 @@ def _get_validated_image(config, clients, param_name):
|
|||||||
}
|
}
|
||||||
return (ValidationResult(True), image)
|
return (ValidationResult(True), image)
|
||||||
try:
|
try:
|
||||||
image_id = types.ImageResourceType.transform(
|
image_id = openstack_types.GlanceImage.transform(
|
||||||
clients=clients, resource_config=image_args)
|
clients=clients, resource_config=image_args)
|
||||||
image = clients.glance().images.get(image=image_id).to_dict()
|
image = clients.glance().images.get(image=image_id).to_dict()
|
||||||
if not image.get("size"):
|
if not image.get("size"):
|
||||||
@ -287,7 +288,7 @@ def _get_validated_flavor(config, clients, param_name):
|
|||||||
msg = "Parameter %s is not specified." % param_name
|
msg = "Parameter %s is not specified." % param_name
|
||||||
return (ValidationResult(False, msg), None)
|
return (ValidationResult(False, msg), None)
|
||||||
try:
|
try:
|
||||||
flavor_id = types.FlavorResourceType.transform(
|
flavor_id = openstack_types.Flavor.transform(
|
||||||
clients=clients, resource_config=flavor_value)
|
clients=clients, resource_config=flavor_value)
|
||||||
flavor = clients.nova().flavors.get(flavor=flavor_id)
|
flavor = clients.nova().flavors.get(flavor=flavor_id)
|
||||||
return (ValidationResult(True), flavor)
|
return (ValidationResult(True), flavor)
|
||||||
|
@ -22,7 +22,7 @@ from tests.unit import test
|
|||||||
|
|
||||||
CTX = "rally.plugins.openstack.context.ec2"
|
CTX = "rally.plugins.openstack.context.ec2"
|
||||||
SCN = "rally.plugins.openstack.scenarios"
|
SCN = "rally.plugins.openstack.scenarios"
|
||||||
TYP = "rally.task.types"
|
TYP = "rally.plugins.openstack.types"
|
||||||
|
|
||||||
|
|
||||||
class EC2ServerGeneratorTestCase(test.TestCase):
|
class EC2ServerGeneratorTestCase(test.TestCase):
|
||||||
@ -60,11 +60,10 @@ class EC2ServerGeneratorTestCase(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch("%s.ec2.utils.EC2Scenario._boot_servers" % SCN,
|
@mock.patch("%s.ec2.utils.EC2Scenario._boot_servers" % SCN,
|
||||||
return_value=[fakes.FakeServer(id=str(i)) for i in range(5)])
|
return_value=[fakes.FakeServer(id=str(i)) for i in range(5)])
|
||||||
@mock.patch("%s.EC2ImageResourceType.transform" % TYP,
|
@mock.patch("%s.EC2Image.transform" % TYP, return_value=mock.MagicMock())
|
||||||
return_value=mock.MagicMock())
|
|
||||||
@mock.patch("%s.servers.osclients" % CTX, return_value=fakes.FakeClients())
|
@mock.patch("%s.servers.osclients" % CTX, return_value=fakes.FakeClients())
|
||||||
def test_setup(self, mock_osclients,
|
def test_setup(self, mock_osclients,
|
||||||
mock_ec2_image_resource_type_transform,
|
mock_ec2_image_transform,
|
||||||
mock_ec2_scenario__boot_servers):
|
mock_ec2_scenario__boot_servers):
|
||||||
|
|
||||||
tenants_count = 2
|
tenants_count = 2
|
||||||
|
@ -23,7 +23,7 @@ from tests.unit import test
|
|||||||
|
|
||||||
CTX = "rally.plugins.openstack.context.nova"
|
CTX = "rally.plugins.openstack.context.nova"
|
||||||
SCN = "rally.plugins.openstack.scenarios"
|
SCN = "rally.plugins.openstack.scenarios"
|
||||||
TYP = "rally.task.types"
|
TYP = "rally.plugins.openstack.types"
|
||||||
|
|
||||||
|
|
||||||
class ServerGeneratorTestCase(test.ScenarioTestCase):
|
class ServerGeneratorTestCase(test.ScenarioTestCase):
|
||||||
@ -57,13 +57,12 @@ class ServerGeneratorTestCase(test.ScenarioTestCase):
|
|||||||
fakes.FakeServer(id="uuid"),
|
fakes.FakeServer(id="uuid"),
|
||||||
fakes.FakeServer(id="uuid")
|
fakes.FakeServer(id="uuid")
|
||||||
])
|
])
|
||||||
@mock.patch("%s.ImageResourceType.transform" % TYP,
|
@mock.patch("%s.GlanceImage.transform" % TYP,
|
||||||
return_value=mock.MagicMock())
|
|
||||||
@mock.patch("%s.FlavorResourceType.transform" % TYP,
|
|
||||||
return_value=mock.MagicMock())
|
return_value=mock.MagicMock())
|
||||||
|
@mock.patch("%s.Flavor.transform" % TYP, return_value=mock.MagicMock())
|
||||||
@mock.patch("%s.servers.osclients" % CTX, return_value=fakes.FakeClients())
|
@mock.patch("%s.servers.osclients" % CTX, return_value=fakes.FakeClients())
|
||||||
def test_setup(self, mock_osclients, mock_flavor_resource_type_transform,
|
def test_setup(self, mock_osclients, mock_flavor_transform,
|
||||||
mock_image_resource_type_transform,
|
mock_glance_image_transform,
|
||||||
mock_nova_scenario__boot_servers):
|
mock_nova_scenario__boot_servers):
|
||||||
|
|
||||||
tenants_count = 2
|
tenants_count = 2
|
||||||
@ -111,8 +110,8 @@ class ServerGeneratorTestCase(test.ScenarioTestCase):
|
|||||||
servers_ctx = servers.ServerGenerator(self.context)
|
servers_ctx = servers.ServerGenerator(self.context)
|
||||||
servers_ctx.setup()
|
servers_ctx.setup()
|
||||||
self.assertEqual(new_context, self.context)
|
self.assertEqual(new_context, self.context)
|
||||||
image_id = mock_image_resource_type_transform.return_value
|
image_id = mock_glance_image_transform.return_value
|
||||||
flavor_id = mock_flavor_resource_type_transform.return_value
|
flavor_id = mock_flavor_transform.return_value
|
||||||
servers_ctx_config = self.context["config"]["servers"]
|
servers_ctx_config = self.context["config"]["servers"]
|
||||||
expected_auto_nic = servers_ctx_config.get("auto_assign_nic", False)
|
expected_auto_nic = servers_ctx_config.get("auto_assign_nic", False)
|
||||||
expected_requests = servers_ctx_config.get("servers_per_tenant", False)
|
expected_requests = servers_ctx_config.get("servers_per_tenant", False)
|
||||||
|
@ -64,13 +64,11 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch("%s.vmtasks.VMTasks" % BASE)
|
@mock.patch("%s.vmtasks.VMTasks" % BASE)
|
||||||
@mock.patch("%s.osclients.Clients" % BASE)
|
@mock.patch("%s.osclients.Clients" % BASE)
|
||||||
@mock.patch("%s.types.ImageResourceType.transform" % BASE,
|
@mock.patch("%s.types.GlanceImage.transform" % BASE, return_value="image")
|
||||||
return_value="image")
|
@mock.patch("%s.types.Flavor.transform" % BASE, return_value="flavor")
|
||||||
@mock.patch("%s.types.FlavorResourceType.transform" % BASE,
|
|
||||||
return_value="flavor")
|
|
||||||
def test_create_one_image(
|
def test_create_one_image(
|
||||||
self, mock_flavor_resource_type_transform,
|
self, mock_flavor_transform, mock_glance_image_transform,
|
||||||
mock_image_resource_type_transform, mock_clients, mock_vm_tasks):
|
mock_clients, mock_vm_tasks):
|
||||||
ip = {"ip": "foo_ip", "id": "foo_id", "is_floating": True}
|
ip = {"ip": "foo_ip", "id": "foo_id", "is_floating": True}
|
||||||
fake_server = mock.Mock()
|
fake_server = mock.Mock()
|
||||||
|
|
||||||
@ -95,10 +93,10 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
|||||||
custom_image = generator_ctx.create_one_image(user,
|
custom_image = generator_ctx.create_one_image(user,
|
||||||
foo_arg="foo_value")
|
foo_arg="foo_value")
|
||||||
|
|
||||||
mock_flavor_resource_type_transform.assert_called_once_with(
|
mock_flavor_transform.assert_called_once_with(
|
||||||
clients=mock_clients.return_value,
|
clients=mock_clients.return_value,
|
||||||
resource_config={"name": "flavor"})
|
resource_config={"name": "flavor"})
|
||||||
mock_image_resource_type_transform.assert_called_once_with(
|
mock_glance_image_transform.assert_called_once_with(
|
||||||
clients=mock_clients.return_value,
|
clients=mock_clients.return_value,
|
||||||
resource_config={"name": "image"})
|
resource_config={"name": "image"})
|
||||||
mock_vm_tasks.assert_called_once_with(
|
mock_vm_tasks.assert_called_once_with(
|
||||||
@ -124,13 +122,14 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch("%s.vmtasks.VMTasks" % BASE)
|
@mock.patch("%s.vmtasks.VMTasks" % BASE)
|
||||||
@mock.patch("%s.osclients.Clients" % BASE)
|
@mock.patch("%s.osclients.Clients" % BASE)
|
||||||
@mock.patch("%s.types.ImageResourceType.transform" % BASE,
|
@mock.patch("%s.types.GlanceImage.transform" % BASE,
|
||||||
return_value="image")
|
return_value="image")
|
||||||
@mock.patch("%s.types.FlavorResourceType.transform" % BASE,
|
@mock.patch("%s.types.Flavor.transform" % BASE,
|
||||||
return_value="flavor")
|
return_value="flavor")
|
||||||
def test_create_one_image_cleanup(
|
def test_create_one_image_cleanup(
|
||||||
self, mock_flavor_resource_type_transform,
|
self, mock_flavor_transform,
|
||||||
mock_image_resource_type_transform, mock_clients, mock_vm_tasks):
|
mock_glance_image_transform, mock_clients,
|
||||||
|
mock_vm_tasks):
|
||||||
ip = {"ip": "foo_ip", "id": "foo_id", "is_floating": True}
|
ip = {"ip": "foo_ip", "id": "foo_id", "is_floating": True}
|
||||||
fake_server = mock.Mock()
|
fake_server = mock.Mock()
|
||||||
|
|
||||||
|
@ -15,10 +15,8 @@
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rally import exceptions
|
|
||||||
from rally.task import scenario
|
from rally.task import scenario
|
||||||
from rally.task import types
|
from rally.task import types
|
||||||
from tests.unit import fakes
|
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
|
|
||||||
@ -85,317 +83,6 @@ class ConvertTestCase(test.TestCase):
|
|||||||
"baz": loaders["test_baz"].transform.return_value})
|
"baz": loaders["test_baz"].transform.return_value})
|
||||||
|
|
||||||
|
|
||||||
class FlavorResourceTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(FlavorResourceTypeTestCase, self).setUp()
|
|
||||||
self.clients = fakes.FakeClients()
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.tiny",
|
|
||||||
id="1"))
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.nano",
|
|
||||||
id="42"))
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.large",
|
|
||||||
id="44"))
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.large",
|
|
||||||
id="45"))
|
|
||||||
|
|
||||||
def test_transform_by_id(self):
|
|
||||||
resource_config = {"id": "42"}
|
|
||||||
flavor_id = types.FlavorResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(flavor_id, "42")
|
|
||||||
|
|
||||||
def test_transform_by_id_from_base_class(self):
|
|
||||||
resource_config = {}
|
|
||||||
types.ResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_name(self):
|
|
||||||
resource_config = {"name": "m1.nano"}
|
|
||||||
flavor_id = types.FlavorResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(flavor_id, "42")
|
|
||||||
|
|
||||||
def test_transform_by_name_no_match(self):
|
|
||||||
resource_config = {"name": "m1.medium"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.FlavorResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_name_multiple_match(self):
|
|
||||||
resource_config = {"name": "m1.large"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.FlavorResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_regex(self):
|
|
||||||
resource_config = {"regex": "m(1|2)\.nano"}
|
|
||||||
flavor_id = types.FlavorResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(flavor_id, "42")
|
|
||||||
|
|
||||||
def test_transform_by_regex_multiple_match(self):
|
|
||||||
resource_config = {"regex": "^m1"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.FlavorResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_regex_no_match(self):
|
|
||||||
resource_config = {}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.FlavorResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
|
|
||||||
class EC2FlavorResourceTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(EC2FlavorResourceTypeTestCase, self).setUp()
|
|
||||||
self.clients = fakes.FakeClients()
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.tiny",
|
|
||||||
id="1"))
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.nano",
|
|
||||||
id="2"))
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.large",
|
|
||||||
id="3"))
|
|
||||||
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.xlarge",
|
|
||||||
id="3"))
|
|
||||||
|
|
||||||
def test_transform_by_name(self):
|
|
||||||
resource_config = {"name": "m1.nano"}
|
|
||||||
flavor_name = types.EC2FlavorResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(flavor_name, "m1.nano")
|
|
||||||
|
|
||||||
def test_transform_by_id(self):
|
|
||||||
resource_config = {"id": "2"}
|
|
||||||
flavor_name = types.EC2FlavorResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(flavor_name, "m1.nano")
|
|
||||||
|
|
||||||
def test_transform_by_id_no_match(self):
|
|
||||||
resource_config = {"id": "4"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.EC2FlavorResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_id_multiple_match(self):
|
|
||||||
resource_config = {"id": "3"}
|
|
||||||
self.assertRaises(exceptions.MultipleMatchesFound,
|
|
||||||
types.EC2FlavorResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
|
|
||||||
class ImageResourceTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(ImageResourceTypeTestCase, self).setUp()
|
|
||||||
self.clients = fakes.FakeClients()
|
|
||||||
image1 = fakes.FakeResource(name="cirros-0.3.4-uec", id="100")
|
|
||||||
self.clients.glance().images._cache(image1)
|
|
||||||
image2 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk", id="101")
|
|
||||||
self.clients.glance().images._cache(image2)
|
|
||||||
image3 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk-copy",
|
|
||||||
id="102")
|
|
||||||
self.clients.glance().images._cache(image3)
|
|
||||||
image4 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk-copy",
|
|
||||||
id="103")
|
|
||||||
self.clients.glance().images._cache(image4)
|
|
||||||
|
|
||||||
def test_transform_by_id(self):
|
|
||||||
resource_config = {"id": "100"}
|
|
||||||
image_id = types.ImageResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(image_id, "100")
|
|
||||||
|
|
||||||
def test_transform_by_name(self):
|
|
||||||
resource_config = {"name": "^cirros-0.3.4-uec$"}
|
|
||||||
image_id = types.ImageResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(image_id, "100")
|
|
||||||
|
|
||||||
def test_transform_by_name_no_match(self):
|
|
||||||
resource_config = {"name": "cirros-0.3.4-uec-boot"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_name_match_multiple(self):
|
|
||||||
resource_config = {"name": "cirros-0.3.4-uec-ramdisk-copy"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_regex(self):
|
|
||||||
resource_config = {"regex": "-uec$"}
|
|
||||||
image_id = types.ImageResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(image_id, "100")
|
|
||||||
|
|
||||||
def test_transform_by_regex_match_multiple(self):
|
|
||||||
resource_config = {"regex": "^cirros"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_regex_no_match(self):
|
|
||||||
resource_config = {"regex": "-boot$"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
|
|
||||||
class EC2ImageResourceTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(EC2ImageResourceTypeTestCase, self).setUp()
|
|
||||||
self.clients = fakes.FakeClients()
|
|
||||||
image1 = fakes.FakeResource(name="cirros-0.3.4-uec", id="100")
|
|
||||||
self.clients.glance().images._cache(image1)
|
|
||||||
image2 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk", id="102")
|
|
||||||
self.clients.glance().images._cache(image2)
|
|
||||||
image3 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk-copy",
|
|
||||||
id="102")
|
|
||||||
self.clients.glance().images._cache(image3)
|
|
||||||
image4 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk-copy",
|
|
||||||
id="103")
|
|
||||||
self.clients.glance().images._cache(image4)
|
|
||||||
|
|
||||||
ec2_image1 = fakes.FakeResource(name="cirros-0.3.4-uec", id="200")
|
|
||||||
ec2_image2 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk",
|
|
||||||
id="201")
|
|
||||||
ec2_image3 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk-copy",
|
|
||||||
id="202")
|
|
||||||
ec2_image4 = fakes.FakeResource(name="cirros-0.3.4-uec-ramdisk-copy",
|
|
||||||
id="203")
|
|
||||||
|
|
||||||
self.clients.ec2().get_all_images = mock.Mock(
|
|
||||||
return_value=[ec2_image1, ec2_image2, ec2_image3, ec2_image4])
|
|
||||||
|
|
||||||
def test_transform_by_name(self):
|
|
||||||
resource_config = {"name": "^cirros-0.3.4-uec$"}
|
|
||||||
ec2_image_id = types.EC2ImageResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(ec2_image_id, "200")
|
|
||||||
|
|
||||||
def test_transform_by_id(self):
|
|
||||||
resource_config = {"id": "100"}
|
|
||||||
ec2_image_id = types.EC2ImageResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(ec2_image_id, "200")
|
|
||||||
|
|
||||||
def test_transform_by_id_no_match(self):
|
|
||||||
resource_config = {"id": "101"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.EC2ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_id_match_multiple(self):
|
|
||||||
resource_config = {"id": "102"}
|
|
||||||
self.assertRaises(exceptions.MultipleMatchesFound,
|
|
||||||
types.EC2ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_name_no_match(self):
|
|
||||||
resource_config = {"name": "cirros-0.3.4-uec-boot"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.EC2ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_name_match_multiple(self):
|
|
||||||
resource_config = {"name": "cirros-0.3.4-uec-ramdisk-copy"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.EC2ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_regex(self):
|
|
||||||
resource_config = {"regex": "-uec$"}
|
|
||||||
ec2_image_id = types.EC2ImageResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(ec2_image_id, "200")
|
|
||||||
|
|
||||||
def test_transform_by_regex_match_multiple(self):
|
|
||||||
resource_config = {"regex": "^cirros"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.EC2ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_regex_no_match(self):
|
|
||||||
resource_config = {"regex": "-boot$"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.EC2ImageResourceType.transform, self.clients,
|
|
||||||
resource_config)
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeTypeResourceTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(VolumeTypeResourceTypeTestCase, self).setUp()
|
|
||||||
self.clients = fakes.FakeClients()
|
|
||||||
volume_type1 = fakes.FakeResource(name="lvmdriver-1", id=100)
|
|
||||||
self.clients.cinder().volume_types._cache(volume_type1)
|
|
||||||
|
|
||||||
def test_transform_by_id(self):
|
|
||||||
resource_config = {"id": 100}
|
|
||||||
volumetype_id = types.VolumeTypeResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(volumetype_id, 100)
|
|
||||||
|
|
||||||
def test_transform_by_name(self):
|
|
||||||
resource_config = {"name": "lvmdriver-1"}
|
|
||||||
volumetype_id = types.VolumeTypeResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(volumetype_id, 100)
|
|
||||||
|
|
||||||
def test_transform_by_name_no_match(self):
|
|
||||||
resource_config = {"name": "nomatch-1"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.VolumeTypeResourceType.transform,
|
|
||||||
self.clients, resource_config)
|
|
||||||
|
|
||||||
def test_transform_by_regex(self):
|
|
||||||
resource_config = {"regex": "^lvm.*-1"}
|
|
||||||
volumetype_id = types.VolumeTypeResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(volumetype_id, 100)
|
|
||||||
|
|
||||||
def test_transform_by_regex_no_match(self):
|
|
||||||
resource_config = {"regex": "dd"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.VolumeTypeResourceType.transform,
|
|
||||||
self.clients, resource_config)
|
|
||||||
|
|
||||||
|
|
||||||
class NeutronNetworkResourceTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(NeutronNetworkResourceTypeTestCase, self).setUp()
|
|
||||||
self.clients = fakes.FakeClients()
|
|
||||||
net1_data = {"network": {
|
|
||||||
"name": "net1"
|
|
||||||
}}
|
|
||||||
network1 = self.clients.neutron().create_network(net1_data)
|
|
||||||
self.net1_id = network1["network"]["id"]
|
|
||||||
|
|
||||||
def test_transform_by_id(self):
|
|
||||||
resource_config = {"id": self.net1_id}
|
|
||||||
network_id = types.NeutronNetworkResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(network_id, self.net1_id)
|
|
||||||
|
|
||||||
def test_transform_by_name(self):
|
|
||||||
resource_config = {"name": "net1"}
|
|
||||||
network_id = types.NeutronNetworkResourceType.transform(
|
|
||||||
clients=self.clients, resource_config=resource_config)
|
|
||||||
self.assertEqual(network_id, self.net1_id)
|
|
||||||
|
|
||||||
def test_transform_by_name_no_match(self):
|
|
||||||
resource_config = {"name": "nomatch-1"}
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.NeutronNetworkResourceType.transform,
|
|
||||||
self.clients, resource_config)
|
|
||||||
|
|
||||||
|
|
||||||
class PreprocessTestCase(test.TestCase):
|
class PreprocessTestCase(test.TestCase):
|
||||||
|
|
||||||
@mock.patch("rally.task.types.scenario.Scenario.get")
|
@mock.patch("rally.task.types.scenario.Scenario.get")
|
||||||
@ -428,70 +115,3 @@ class PreprocessTestCase(test.TestCase):
|
|||||||
mock_osclients.Clients.assert_called_once_with(
|
mock_osclients.Clients.assert_called_once_with(
|
||||||
context["admin"]["credential"])
|
context["admin"]["credential"])
|
||||||
self.assertEqual({"a": 20, "b": 20}, result)
|
self.assertEqual({"a": 20, "b": 20}, result)
|
||||||
|
|
||||||
|
|
||||||
class FilePathOrUrlTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
@mock.patch("rally.task.types.os.path.isfile")
|
|
||||||
@mock.patch("rally.task.types.requests")
|
|
||||||
def test_transform_file(self, mock_requests, mock_isfile):
|
|
||||||
mock_isfile.return_value = True
|
|
||||||
path = types.FilePathOrUrlType.transform(None, "fake_path")
|
|
||||||
self.assertEqual("fake_path", path)
|
|
||||||
mock_isfile.return_value = False
|
|
||||||
mock_requests.head.return_value = mock.Mock(status_code=500)
|
|
||||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
|
||||||
types.FilePathOrUrlType.transform,
|
|
||||||
None, "fake_path")
|
|
||||||
mock_requests.head.assert_called_once_with("fake_path")
|
|
||||||
|
|
||||||
@mock.patch("rally.task.types.os.path.isfile")
|
|
||||||
@mock.patch("rally.task.types.requests")
|
|
||||||
def test_transform_url(self, mock_requests, mock_isfile):
|
|
||||||
mock_isfile.return_value = False
|
|
||||||
mock_requests.head.return_value = mock.Mock(status_code=200)
|
|
||||||
path = types.FilePathOrUrlType.transform(None, "fake_url")
|
|
||||||
self.assertEqual("fake_url", path)
|
|
||||||
|
|
||||||
|
|
||||||
class FileTypeTestCase(test.TestCase):
|
|
||||||
|
|
||||||
@mock.patch("rally.task.types.open",
|
|
||||||
side_effect=mock.mock_open(read_data="file_context"),
|
|
||||||
create=True)
|
|
||||||
def test_transform_by_path(self, mock_open):
|
|
||||||
resource_config = "file.yaml"
|
|
||||||
file_context = types.FileType.transform(
|
|
||||||
clients=None, resource_config=resource_config)
|
|
||||||
self.assertEqual(file_context, "file_context")
|
|
||||||
|
|
||||||
@mock.patch("rally.task.types.open",
|
|
||||||
side_effect=IOError, create=True)
|
|
||||||
def test_transform_by_path_no_match(self, mock_open):
|
|
||||||
resource_config = "nonexistant.yaml"
|
|
||||||
self.assertRaises(IOError,
|
|
||||||
types.FileType.transform,
|
|
||||||
clients=None,
|
|
||||||
resource_config=resource_config)
|
|
||||||
|
|
||||||
|
|
||||||
class FileTypeDictTestCase(test.TestCase):
|
|
||||||
|
|
||||||
@mock.patch("rally.task.types.open",
|
|
||||||
side_effect=mock.mock_open(read_data="file_context"),
|
|
||||||
create=True)
|
|
||||||
def test_transform_by_path(self, mock_open):
|
|
||||||
resource_config = ["file.yaml"]
|
|
||||||
file_context = types.FileTypeDict.transform(
|
|
||||||
clients=None,
|
|
||||||
resource_config=resource_config)
|
|
||||||
self.assertEqual(file_context, {"file.yaml": "file_context"})
|
|
||||||
|
|
||||||
@mock.patch("rally.task.types.open",
|
|
||||||
side_effect=IOError, create=True)
|
|
||||||
def test_transform_by_path_no_match(self, mock_open):
|
|
||||||
resource_config = ["nonexistant.yaml"]
|
|
||||||
self.assertRaises(IOError,
|
|
||||||
types.FileTypeDict.transform,
|
|
||||||
clients=None,
|
|
||||||
resource_config=resource_config)
|
|
||||||
|
@ -252,9 +252,9 @@ class ValidatorsTestCase(test.TestCase):
|
|||||||
self.assertTrue(result[0].is_valid, result[0].msg)
|
self.assertTrue(result[0].is_valid, result[0].msg)
|
||||||
self.assertEqual(result[1], image)
|
self.assertEqual(result[1], image)
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.ImageResourceType.transform",
|
@mock.patch(MODULE + "openstack_types.GlanceImage.transform",
|
||||||
return_value="image_id")
|
return_value="image_id")
|
||||||
def test__get_validated_image(self, mock_image_resource_type_transform):
|
def test__get_validated_image(self, mock_glance_image_transform):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
clients.glance().images.get().to_dict.return_value = {
|
clients.glance().images.get().to_dict.return_value = {
|
||||||
"image": "image_id"}
|
"image": "image_id"}
|
||||||
@ -267,21 +267,21 @@ class ValidatorsTestCase(test.TestCase):
|
|||||||
self.assertEqual({"image": "image_id", "min_disk": 0,
|
self.assertEqual({"image": "image_id", "min_disk": 0,
|
||||||
"min_ram": 0, "size": 0},
|
"min_ram": 0, "size": 0},
|
||||||
result[1])
|
result[1])
|
||||||
mock_image_resource_type_transform.assert_called_once_with(
|
mock_glance_image_transform.assert_called_once_with(
|
||||||
clients=clients, resource_config="test")
|
clients=clients, resource_config="test")
|
||||||
clients.glance().images.get.assert_called_with(image="image_id")
|
clients.glance().images.get.assert_called_with(image="image_id")
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.ImageResourceType.transform",
|
@mock.patch(MODULE + "openstack_types.GlanceImage.transform",
|
||||||
side_effect=exceptions.InvalidScenarioArgument)
|
side_effect=exceptions.InvalidScenarioArgument)
|
||||||
def test__get_validated_image_transform_error(
|
def test__get_validated_image_transform_error(
|
||||||
self, mock_image_resource_type_transform):
|
self, mock_glance_image_transform):
|
||||||
result = validation._get_validated_image({"args": {"a": "test"}},
|
result = validation._get_validated_image({"args": {"a": "test"}},
|
||||||
None, "a")
|
None, "a")
|
||||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.ImageResourceType.transform")
|
@mock.patch(MODULE + "openstack_types.GlanceImage.transform")
|
||||||
def test__get_validated_image_not_found(
|
def test__get_validated_image_not_found(
|
||||||
self, mock_image_resource_type_transform):
|
self, mock_glance_image_transform):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
clients.glance().images.get().to_dict.side_effect = (
|
clients.glance().images.get().to_dict.side_effect = (
|
||||||
glance_exc.HTTPNotFound(""))
|
glance_exc.HTTPNotFound(""))
|
||||||
@ -293,10 +293,10 @@ class ValidatorsTestCase(test.TestCase):
|
|||||||
result = validation._get_validated_flavor({}, None, "non_existing")
|
result = validation._get_validated_flavor({}, None, "non_existing")
|
||||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.FlavorResourceType.transform",
|
@mock.patch(MODULE + "openstack_types.Flavor.transform",
|
||||||
return_value="flavor_id")
|
return_value="flavor_id")
|
||||||
def test__get_validated_flavor(
|
def test__get_validated_flavor(
|
||||||
self, mock_flavor_resource_type_transform):
|
self, mock_flavor_transform):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
clients.nova().flavors.get.return_value = "flavor"
|
clients.nova().flavors.get.return_value = "flavor"
|
||||||
|
|
||||||
@ -304,30 +304,30 @@ class ValidatorsTestCase(test.TestCase):
|
|||||||
clients, "a")
|
clients, "a")
|
||||||
self.assertTrue(result[0].is_valid, result[0].msg)
|
self.assertTrue(result[0].is_valid, result[0].msg)
|
||||||
self.assertEqual(result[1], "flavor")
|
self.assertEqual(result[1], "flavor")
|
||||||
mock_flavor_resource_type_transform.assert_called_once_with(
|
mock_flavor_transform.assert_called_once_with(
|
||||||
clients=clients, resource_config="test")
|
clients=clients, resource_config="test")
|
||||||
clients.nova().flavors.get.assert_called_once_with(flavor="flavor_id")
|
clients.nova().flavors.get.assert_called_once_with(flavor="flavor_id")
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.FlavorResourceType.transform",
|
@mock.patch(MODULE + "openstack_types.Flavor.transform",
|
||||||
side_effect=exceptions.InvalidScenarioArgument)
|
side_effect=exceptions.InvalidScenarioArgument)
|
||||||
def test__get_validated_flavor_transform_error(
|
def test__get_validated_flavor_transform_error(
|
||||||
self, mock_flavor_resource_type_transform):
|
self, mock_flavor_transform):
|
||||||
result = validation._get_validated_flavor({"args": {"a": "test"}},
|
result = validation._get_validated_flavor({"args": {"a": "test"}},
|
||||||
None, "a")
|
None, "a")
|
||||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
@mock.patch(MODULE + "openstack_types.Flavor.transform")
|
||||||
def test__get_validated_flavor_not_found(
|
def test__get_validated_flavor_not_found(
|
||||||
self, mock_flavor_resource_type_transform):
|
self, mock_flavor_transform):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||||
result = validation._get_validated_flavor({"args": {"a": "test"}},
|
result = validation._get_validated_flavor({"args": {"a": "test"}},
|
||||||
clients, "a")
|
clients, "a")
|
||||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
@mock.patch(MODULE + "openstack_types.Flavor.transform")
|
||||||
def test__get_validated_flavor_from_context(
|
def test__get_validated_flavor_from_context(
|
||||||
self, mock_flavor_resource_type_transform):
|
self, mock_flavor_transform):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||||
config = {
|
config = {
|
||||||
@ -342,9 +342,9 @@ class ValidatorsTestCase(test.TestCase):
|
|||||||
result = validation._get_validated_flavor(config, clients, "flavor")
|
result = validation._get_validated_flavor(config, clients, "flavor")
|
||||||
self.assertTrue(result[0].is_valid, result[0].msg)
|
self.assertTrue(result[0].is_valid, result[0].msg)
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
@mock.patch(MODULE + "openstack_types.Flavor.transform")
|
||||||
def test__get_validated_flavor_from_context_failed(
|
def test__get_validated_flavor_from_context_failed(
|
||||||
self, mock_flavor_resource_type_transform):
|
self, mock_flavor_transform):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||||
config = {
|
config = {
|
||||||
@ -449,11 +449,11 @@ class ValidatorsTestCase(test.TestCase):
|
|||||||
result = validator(None, None, None)
|
result = validator(None, None, None)
|
||||||
self.assertFalse(result.is_valid, result.msg)
|
self.assertFalse(result.is_valid, result.msg)
|
||||||
|
|
||||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
@mock.patch(MODULE + "openstack_types.Flavor.transform")
|
||||||
@mock.patch(MODULE + "_get_validated_image")
|
@mock.patch(MODULE + "_get_validated_image")
|
||||||
def test_image_valid_on_flavor_context(
|
def test_image_valid_on_flavor_context(
|
||||||
self, mock__get_validated_image,
|
self, mock__get_validated_image,
|
||||||
mock_flavor_resource_type_transform):
|
mock_flavor_transform):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user