Get rid of deprecated ec2 client
Change-Id: Ic9283c50ae1283056d8ea6ca851d5863da61af22
This commit is contained in:
parent
ad982b111a
commit
e3dd2878ee
@ -1,37 +0,0 @@
|
||||
# Copyright 2013: Mirantis Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.common import cfg
|
||||
|
||||
OPTS = {"openstack": [
|
||||
cfg.FloatOpt(
|
||||
"ec2_server_boot_prepoll_delay",
|
||||
default=1.0,
|
||||
deprecated_group="benchmark",
|
||||
help="Time to sleep after boot before polling for status"
|
||||
),
|
||||
cfg.FloatOpt(
|
||||
"ec2_server_boot_timeout",
|
||||
default=300.0,
|
||||
deprecated_group="benchmark",
|
||||
help="Server boot timeout"
|
||||
),
|
||||
cfg.FloatOpt(
|
||||
"ec2_server_boot_poll_interval",
|
||||
default=1.0,
|
||||
deprecated_group="benchmark",
|
||||
help="Server boot poll interval"
|
||||
)
|
||||
]}
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
from rally_openstack.cfg import cinder
|
||||
from rally_openstack.cfg import ec2
|
||||
from rally_openstack.cfg import glance
|
||||
from rally_openstack.cfg import heat
|
||||
from rally_openstack.cfg import ironic
|
||||
@ -46,7 +45,7 @@ from rally_openstack.embedcharts import osprofilerchart
|
||||
def list_opts():
|
||||
|
||||
opts = {}
|
||||
for l_opts in (cinder.OPTS, ec2.OPTS, heat.OPTS, ironic.OPTS, magnum.OPTS,
|
||||
for l_opts in (cinder.OPTS, heat.OPTS, ironic.OPTS, magnum.OPTS,
|
||||
manila.OPTS, mistral.OPTS, monasca.OPTS, murano.OPTS,
|
||||
nova.OPTS, osclients.OPTS, profiler.OPTS, sahara.OPTS,
|
||||
vm.OPTS, glance.OPTS, watcher.OPTS, tempest.OPTS,
|
||||
|
@ -194,46 +194,6 @@ class NovaAggregate(SynchronizedDeletion, base.ResourceManager):
|
||||
super(NovaAggregate, self).delete()
|
||||
|
||||
|
||||
# EC2
|
||||
|
||||
_ec2_order = get_order(250)
|
||||
|
||||
|
||||
class EC2Mixin(object):
|
||||
|
||||
def _manager(self):
|
||||
return getattr(self.user, self._service)()
|
||||
|
||||
|
||||
@base.resource("ec2", "servers", order=next(_ec2_order))
|
||||
class EC2Server(EC2Mixin, base.ResourceManager):
|
||||
|
||||
def is_deleted(self):
|
||||
from boto import exception as boto_exception
|
||||
|
||||
try:
|
||||
instances = self._manager().get_only_instances(
|
||||
instance_ids=[self.id()])
|
||||
except boto_exception.EC2ResponseError as e:
|
||||
# NOTE(wtakase): Nova EC2 API returns 'InvalidInstanceID.NotFound'
|
||||
# if instance not found. In this case, we consider
|
||||
# instance has already been deleted.
|
||||
return getattr(e, "error_code") == "InvalidInstanceID.NotFound"
|
||||
|
||||
# NOTE(wtakase): After instance deletion, instance can be 'terminated'
|
||||
# state. If all instance states are 'terminated', this
|
||||
# returns True. And if get_only_instances() returns an
|
||||
# empty list, this also returns True because we consider
|
||||
# instance has already been deleted.
|
||||
return all(map(lambda i: i.state == "terminated", instances))
|
||||
|
||||
def delete(self):
|
||||
self._manager().terminate_instances(instance_ids=[self.id()])
|
||||
|
||||
def list(self):
|
||||
return self._manager().get_only_instances()
|
||||
|
||||
|
||||
# NEUTRON
|
||||
|
||||
_neutron_order = get_order(300)
|
||||
|
@ -1,97 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.common import logging
|
||||
from rally.common import utils as rutils
|
||||
from rally.task import context
|
||||
|
||||
from rally_openstack.cleanup import manager as resource_manager
|
||||
from rally_openstack import consts
|
||||
from rally_openstack.scenarios.ec2 import utils as ec2_utils
|
||||
from rally_openstack import types
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@context.configure(name="ec2_servers", platform="openstack", order=460)
|
||||
class EC2ServerGenerator(context.Context):
|
||||
"""Creates specified amount of nova servers in each tenant uses ec2 API."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
"type": "object",
|
||||
"$schema": consts.JSON_SCHEMA,
|
||||
"properties": {
|
||||
"image": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": False
|
||||
},
|
||||
"flavor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": False
|
||||
},
|
||||
"servers_per_tenant": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
}
|
||||
},
|
||||
"required": ["image", "flavor", "servers_per_tenant"],
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
def setup(self):
|
||||
image = self.config["image"]
|
||||
flavor = self.config["flavor"]
|
||||
|
||||
image_id = types.EC2Image(self.context).pre_process(
|
||||
resource_spec=image, config={})
|
||||
|
||||
for user, tenant_id in rutils.iterate_per_tenants(
|
||||
self.context["users"]):
|
||||
LOG.debug("Booting servers for tenant %s " % user["tenant_id"])
|
||||
ec2_scenario = ec2_utils.EC2Scenario({
|
||||
"user": user,
|
||||
"task": self.context["task"],
|
||||
"owner_id": self.context["owner_id"]})
|
||||
|
||||
LOG.debug(
|
||||
"Calling _boot_servers with "
|
||||
"image_id=%(image_id)s flavor_name=%(flavor_name)s "
|
||||
"servers_per_tenant=%(servers_per_tenant)s"
|
||||
% {"image_id": image_id,
|
||||
"flavor_name": flavor["name"],
|
||||
"servers_per_tenant": self.config["servers_per_tenant"]})
|
||||
|
||||
servers = ec2_scenario._boot_servers(
|
||||
image_id, flavor["name"], self.config["servers_per_tenant"])
|
||||
|
||||
current_servers = [server.id for server in servers]
|
||||
|
||||
self.context["tenants"][tenant_id]["ec2_servers"] = current_servers
|
||||
|
||||
def cleanup(self):
|
||||
resource_manager.cleanup(names=["ec2.servers"],
|
||||
users=self.context.get("users", []),
|
||||
superclass=ec2_utils.EC2Scenario,
|
||||
task_id=self.get_owner_id())
|
@ -761,33 +761,6 @@ class Swift(OSClient):
|
||||
return client
|
||||
|
||||
|
||||
@configure("ec2")
|
||||
class EC2(OSClient):
|
||||
"""Wrapper for EC2Client which returns an authenticated native client.
|
||||
|
||||
"""
|
||||
|
||||
def create_client(self):
|
||||
"""Return ec2 client."""
|
||||
LOG.warning("rally.osclient.EC2 is deprecated since Rally 0.10.0.")
|
||||
|
||||
import boto
|
||||
|
||||
kc = self.keystone()
|
||||
|
||||
if kc.version != "v2.0":
|
||||
raise exceptions.RallyException(
|
||||
"Rally EC2 scenario supports only Keystone version 2")
|
||||
ec2_credential = kc.ec2.create(user_id=kc.auth_user_id,
|
||||
tenant_id=kc.auth_tenant_id)
|
||||
client = boto.connect_ec2_endpoint(
|
||||
url=self._get_endpoint(),
|
||||
aws_access_key_id=ec2_credential.access,
|
||||
aws_secret_access_key=ec2_credential.secret,
|
||||
is_secure=self.credential.https_insecure)
|
||||
return client
|
||||
|
||||
|
||||
@configure("monasca", default_version="2_0",
|
||||
default_service_type="monitoring", supported_versions=["2_0"])
|
||||
class Monasca(OSClient):
|
||||
|
@ -1,60 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.task import types
|
||||
from rally.task import validation
|
||||
|
||||
from rally_openstack import consts
|
||||
from rally_openstack import scenario
|
||||
from rally_openstack.scenarios.ec2 import utils
|
||||
|
||||
|
||||
"""Scenarios for servers using EC2."""
|
||||
|
||||
|
||||
@validation.add("required_services", services=[consts.Service.EC2])
|
||||
@validation.add("required_platform", platform="openstack", users=True)
|
||||
@scenario.configure(context={"cleanup@openstack": ["ec2"]},
|
||||
name="EC2Servers.list_servers", platform="openstack")
|
||||
class ListServers(utils.EC2Scenario):
|
||||
|
||||
def run(self):
|
||||
"""List all servers.
|
||||
|
||||
This simple scenario tests the EC2 API list function by listing
|
||||
all the servers.
|
||||
"""
|
||||
self._list_servers()
|
||||
|
||||
|
||||
@types.convert(image={"type": "ec2_image"},
|
||||
flavor={"type": "ec2_flavor"})
|
||||
@validation.add("image_valid_on_flavor", flavor_param="flavor",
|
||||
image_param="image")
|
||||
@validation.add("required_services", services=[consts.Service.EC2])
|
||||
@validation.add("required_platform", platform="openstack", users=True)
|
||||
@scenario.configure(context={"cleanup@openstack": ["ec2"]},
|
||||
name="EC2Servers.boot_server", platform="openstack")
|
||||
class BootServer(utils.EC2Scenario):
|
||||
|
||||
def run(self, image, flavor, **kwargs):
|
||||
"""Boot a server.
|
||||
|
||||
Assumes that cleanup is done elsewhere.
|
||||
|
||||
:param image: image to be used to boot an instance
|
||||
:param flavor: flavor to be used to boot an instance
|
||||
:param kwargs: optional additional arguments for server creation
|
||||
"""
|
||||
self._boot_servers(image, flavor, **kwargs)
|
@ -1,69 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from rally.common import cfg
|
||||
from rally.task import atomic
|
||||
from rally.task import utils
|
||||
|
||||
from rally_openstack import scenario
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class EC2Scenario(scenario.OpenStackScenario):
|
||||
"""Base class for EC2 scenarios with basic atomic actions."""
|
||||
|
||||
@atomic.action_timer("ec2.list_servers")
|
||||
def _list_servers(self):
|
||||
"""Returns user servers list."""
|
||||
return self.clients("ec2").get_only_instances()
|
||||
|
||||
@atomic.action_timer("ec2.boot_servers")
|
||||
def _boot_servers(self, image_id, flavor_name,
|
||||
instance_num=1, **kwargs):
|
||||
"""Boot multiple servers.
|
||||
|
||||
Returns when all the servers are actually booted and are in the
|
||||
"Running" state.
|
||||
|
||||
:param image_id: ID of the image to be used for server creation
|
||||
:param flavor_name: Name of the flavor to be used for server creation
|
||||
:param instance_num: Number of instances to boot
|
||||
:param kwargs: Other optional parameters to boot servers
|
||||
|
||||
:returns: List of created server objects
|
||||
"""
|
||||
reservation = self.clients("ec2").run_instances(
|
||||
image_id=image_id,
|
||||
instance_type=flavor_name,
|
||||
min_count=instance_num,
|
||||
max_count=instance_num,
|
||||
**kwargs)
|
||||
servers = [instance for instance in reservation.instances]
|
||||
|
||||
self.sleep_between(CONF.openstack.ec2_server_boot_prepoll_delay)
|
||||
servers = [utils.wait_for_status(
|
||||
server,
|
||||
ready_statuses=["RUNNING"],
|
||||
update_resource=self._update_resource,
|
||||
timeout=CONF.openstack.ec2_server_boot_timeout,
|
||||
check_interval=CONF.openstack.ec2_server_boot_poll_interval
|
||||
) for server in servers]
|
||||
return servers
|
||||
|
||||
def _update_resource(self, resource):
|
||||
resource.update()
|
||||
return resource
|
@ -171,22 +171,6 @@ class Flavor(DeprecatedBehaviourMixin, OpenStackResourceType):
|
||||
return resource_id
|
||||
|
||||
|
||||
@plugin.configure(name="ec2_flavor")
|
||||
class EC2Flavor(DeprecatedBehaviourMixin, OpenStackResourceType):
|
||||
"""Find Nova's flavor Name by it's ID or regexp."""
|
||||
|
||||
def pre_process(self, resource_spec, config):
|
||||
resource_name = resource_spec.get("name")
|
||||
if not resource_name:
|
||||
# NOTE(wtakase): gets resource name from OpenStack id
|
||||
novaclient = self._clients.nova()
|
||||
resource_name = types._name_from_id(
|
||||
resource_config=resource_spec,
|
||||
resources=novaclient.flavors.list(),
|
||||
typename="flavor")
|
||||
return resource_name
|
||||
|
||||
|
||||
@plugin.configure(name="glance_image")
|
||||
class GlanceImage(DeprecatedBehaviourMixin, OpenStackResourceType):
|
||||
"""Find Glance's image ID by name or regexp."""
|
||||
|
@ -7,7 +7,6 @@ requests>=2.14.2 # Apache License, Version
|
||||
rally>=0.11.0 # Apache License, Version 2.0
|
||||
|
||||
# OpenStack related
|
||||
boto>=2.32.1 # MIT
|
||||
gnocchiclient>=3.3.1 # Apache Software License
|
||||
keystoneauth1>=3.3.0 # Apache Software License
|
||||
kubernetes>=11.0.0 # Apache License Version 2.0
|
||||
|
@ -1,29 +0,0 @@
|
||||
{
|
||||
"Dummy.openstack": [
|
||||
{
|
||||
"args": {
|
||||
"sleep": 0.1
|
||||
},
|
||||
"runner": {
|
||||
"type": "constant",
|
||||
"times": 4,
|
||||
"concurrency": 2
|
||||
},
|
||||
"context": {
|
||||
"users": {
|
||||
"tenants": 1,
|
||||
"users_per_tenant": 2
|
||||
},
|
||||
"ec2_servers": {
|
||||
"flavor": {
|
||||
"name": "m1.tiny"
|
||||
},
|
||||
"image": {
|
||||
"name": "^cirros.*-disk$"
|
||||
},
|
||||
"servers_per_tenant": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
---
|
||||
Dummy.openstack:
|
||||
-
|
||||
args:
|
||||
sleep: 0.1
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 4
|
||||
concurrency: 2
|
||||
context:
|
||||
users:
|
||||
tenants: 1
|
||||
users_per_tenant: 2
|
||||
ec2_servers:
|
||||
flavor:
|
||||
name: "m1.tiny"
|
||||
image:
|
||||
name: "^cirros.*-disk$"
|
||||
servers_per_tenant: 2
|
@ -1,31 +0,0 @@
|
||||
{% set flavor_name = flavor_name or "m1.tiny" %}
|
||||
{
|
||||
"EC2Servers.boot_server": [
|
||||
{
|
||||
"args": {
|
||||
"flavor": {
|
||||
"name": "{{flavor_name}}"
|
||||
},
|
||||
"image": {
|
||||
"name": "^cirros.*-disk$"
|
||||
}
|
||||
},
|
||||
"runner": {
|
||||
"type": "constant",
|
||||
"times": 10,
|
||||
"concurrency": 2
|
||||
},
|
||||
"context": {
|
||||
"users": {
|
||||
"tenants": 3,
|
||||
"users_per_tenant": 2
|
||||
}
|
||||
},
|
||||
"sla": {
|
||||
"failure_rate": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
{% set flavor_name = flavor_name or "m1.tiny" %}
|
||||
---
|
||||
EC2Servers.boot_server:
|
||||
-
|
||||
args:
|
||||
flavor:
|
||||
name: "{{flavor_name}}"
|
||||
image:
|
||||
name: "^cirros.*-disk$"
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 10
|
||||
concurrency: 2
|
||||
context:
|
||||
users:
|
||||
tenants: 3
|
||||
users_per_tenant: 2
|
||||
sla:
|
||||
failure_rate:
|
||||
max: 0
|
@ -1,31 +0,0 @@
|
||||
{
|
||||
"EC2Servers.list_servers": [
|
||||
{
|
||||
"runner": {
|
||||
"type": "constant",
|
||||
"times": 1,
|
||||
"concurrency": 1
|
||||
},
|
||||
"context": {
|
||||
"users": {
|
||||
"tenants": 1,
|
||||
"users_per_tenant": 1
|
||||
},
|
||||
"ec2_servers": {
|
||||
"flavor": {
|
||||
"name": "m1.tiny"
|
||||
},
|
||||
"image": {
|
||||
"name": "^cirros.*-disk$"
|
||||
},
|
||||
"servers_per_tenant": 2
|
||||
}
|
||||
},
|
||||
"sla": {
|
||||
"failure_rate": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
---
|
||||
EC2Servers.list_servers:
|
||||
-
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 1
|
||||
concurrency: 1
|
||||
context:
|
||||
users:
|
||||
tenants: 1
|
||||
users_per_tenant: 1
|
||||
ec2_servers:
|
||||
flavor:
|
||||
name: "m1.tiny"
|
||||
image:
|
||||
name: "^cirros.*-disk$"
|
||||
servers_per_tenant: 2
|
||||
sla:
|
||||
failure_rate:
|
||||
max: 0
|
@ -107,14 +107,6 @@ class Keystone(ResourceManager):
|
||||
def list_roles(self):
|
||||
return self.client.roles.list()
|
||||
|
||||
def list_ec2credentials(self):
|
||||
users = self.list_users()
|
||||
ec2_list = []
|
||||
for user in users:
|
||||
ec2_list.extend(
|
||||
self.client.ec2.list(user.id))
|
||||
return ec2_list
|
||||
|
||||
|
||||
class Magnum(ResourceManager):
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
import copy
|
||||
from unittest import mock
|
||||
|
||||
from boto import exception as boto_exception
|
||||
import ddt
|
||||
from neutronclient.common import exceptions as neutron_exceptions
|
||||
from novaclient import exceptions as nova_exc
|
||||
@ -138,74 +137,6 @@ class NovaServerGroupsTestCase(test.TestCase):
|
||||
self.assertEqual(server_groups, resources.NovaServerGroups().list())
|
||||
|
||||
|
||||
class EC2MixinTestCase(test.TestCase):
|
||||
|
||||
def get_ec2_mixin(self):
|
||||
ec2 = resources.EC2Mixin()
|
||||
ec2._service = "ec2"
|
||||
return ec2
|
||||
|
||||
def test__manager(self):
|
||||
ec2 = self.get_ec2_mixin()
|
||||
ec2.user = mock.MagicMock()
|
||||
self.assertEqual(ec2.user.ec2.return_value, ec2._manager())
|
||||
|
||||
|
||||
class EC2ServerTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_is_deleted(self, mock_ec2_server__manager):
|
||||
raw_res1 = mock.MagicMock(state="terminated")
|
||||
raw_res2 = mock.MagicMock(state="terminated")
|
||||
resource = mock.MagicMock(id="test_id")
|
||||
manager = resources.EC2Server(resource=resource)
|
||||
|
||||
mock_ec2_server__manager().get_only_instances.return_value = [raw_res1]
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
raw_res1.state = "running"
|
||||
self.assertFalse(manager.is_deleted())
|
||||
|
||||
mock_ec2_server__manager().get_only_instances.return_value = [
|
||||
raw_res1, raw_res2]
|
||||
self.assertFalse(manager.is_deleted())
|
||||
|
||||
raw_res1.state = "terminated"
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
mock_ec2_server__manager().get_only_instances.return_value = []
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_is_deleted_exceptions(self, mock_ec2_server__manager):
|
||||
mock_ec2_server__manager.side_effect = [
|
||||
boto_exception.EC2ResponseError(
|
||||
status="fake", reason="fake",
|
||||
body={"Error": {"Code": "fake_code"}}),
|
||||
boto_exception.EC2ResponseError(
|
||||
status="fake", reason="fake",
|
||||
body={"Error": {"Code": "InvalidInstanceID.NotFound"}})
|
||||
]
|
||||
manager = resources.EC2Server(resource=mock.MagicMock())
|
||||
self.assertFalse(manager.is_deleted())
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_delete(self, mock_ec2_server__manager):
|
||||
resource = mock.MagicMock(id="test_id")
|
||||
manager = resources.EC2Server(resource=resource)
|
||||
manager.delete()
|
||||
mock_ec2_server__manager().terminate_instances.assert_called_once_with(
|
||||
instance_ids=["test_id"])
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_list(self, mock_ec2_server__manager):
|
||||
manager = resources.EC2Server()
|
||||
mock_ec2_server__manager().get_only_instances.return_value = [
|
||||
"a", "b", "c"]
|
||||
self.assertEqual(["a", "b", "c"], manager.list())
|
||||
|
||||
|
||||
class NeutronMixinTestCase(test.TestCase):
|
||||
|
||||
def get_neutron_mixin(self):
|
||||
|
@ -1,109 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
from unittest import mock
|
||||
|
||||
from rally_openstack.contexts.ec2 import servers
|
||||
from rally_openstack.scenarios.ec2 import utils as ec2_utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally_openstack.contexts.ec2"
|
||||
SCN = "rally_openstack.scenarios"
|
||||
TYP = "rally_openstack.types"
|
||||
|
||||
|
||||
class EC2ServerGeneratorTestCase(test.TestCase):
|
||||
|
||||
def _gen_tenants_and_users(self, tenants_count, users_per_tenant):
|
||||
tenants = {}
|
||||
for id in range(tenants_count):
|
||||
tenants[str(id)] = dict(name=str(id))
|
||||
|
||||
users = []
|
||||
for tenant_id in tenants.keys():
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": tenant_id,
|
||||
"credential": mock.MagicMock()})
|
||||
return tenants, users
|
||||
|
||||
def _get_context(self, users, tenants):
|
||||
return {
|
||||
"config": {
|
||||
"users": {
|
||||
"tenants": 2,
|
||||
"users_per_tenant": 5,
|
||||
"concurrent": 10},
|
||||
"ec2_servers": {
|
||||
"servers_per_tenant": 5,
|
||||
"image": {"name": "foo_image"},
|
||||
"flavor": {"name": "foo_flavor"}
|
||||
}
|
||||
},
|
||||
"admin": {"credential": mock.MagicMock()},
|
||||
"task": mock.MagicMock(),
|
||||
"owner_id": "foo_uuid",
|
||||
"users": users,
|
||||
"tenants": tenants
|
||||
}
|
||||
|
||||
@mock.patch("%s.ec2.utils.EC2Scenario._boot_servers" % SCN,
|
||||
return_value=[fakes.FakeServer(id=str(i)) for i in range(5)])
|
||||
@mock.patch("%s.EC2Image" % TYP)
|
||||
def test_setup(self, mock_ec2_image, mock_ec2_scenario__boot_servers):
|
||||
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
servers_per_tenant = 5
|
||||
|
||||
tenants, users = self._gen_tenants_and_users(tenants_count,
|
||||
users_per_tenant)
|
||||
|
||||
real_context = self._get_context(users, tenants)
|
||||
|
||||
new_context = copy.deepcopy(real_context)
|
||||
for tenant_id in new_context["tenants"]:
|
||||
new_context["tenants"][tenant_id].setdefault("ec2_servers", [])
|
||||
for i in range(servers_per_tenant):
|
||||
new_context["tenants"][tenant_id]["ec2_servers"].append(str(i))
|
||||
|
||||
servers_ctx = servers.EC2ServerGenerator(real_context)
|
||||
servers_ctx.setup()
|
||||
self.assertEqual(new_context, servers_ctx.context)
|
||||
|
||||
@mock.patch("%s.servers.resource_manager.cleanup" % CTX)
|
||||
def test_cleanup(self, mock_cleanup):
|
||||
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
servers_per_tenant = 5
|
||||
|
||||
tenants, users = self._gen_tenants_and_users(tenants_count,
|
||||
users_per_tenant)
|
||||
for tenant_id in tenants.keys():
|
||||
tenants[tenant_id].setdefault("ec2_servers", [])
|
||||
for i in range(servers_per_tenant):
|
||||
tenants[tenant_id]["ec2_servers"].append(str(i))
|
||||
|
||||
context = self._get_context(users, tenants)
|
||||
|
||||
servers_ctx = servers.EC2ServerGenerator(context)
|
||||
servers_ctx.cleanup()
|
||||
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["ec2.servers"],
|
||||
users=context["users"],
|
||||
superclass=ec2_utils.EC2Scenario,
|
||||
task_id="foo_uuid")
|
@ -1,34 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from rally_openstack.scenarios.ec2 import servers
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
class EC2ServersTestCase(test.ScenarioTestCase):
|
||||
|
||||
def test_list_servers(self):
|
||||
scenario = servers.ListServers(self.context)
|
||||
scenario._list_servers = mock.MagicMock()
|
||||
scenario.run()
|
||||
scenario._list_servers.assert_called_once_with()
|
||||
|
||||
def test_boot_server(self):
|
||||
scenario = servers.BootServer(self.context)
|
||||
scenario._boot_servers = mock.Mock()
|
||||
scenario.run("foo_image", "foo_flavor", foo="bar")
|
||||
scenario._boot_servers.assert_called_once_with(
|
||||
"foo_image", "foo_flavor", foo="bar")
|
@ -1,72 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from rally.common import cfg
|
||||
|
||||
from rally_openstack.scenarios.ec2 import utils
|
||||
from tests.unit import test
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class EC2ScenarioTestCase(test.ScenarioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(EC2ScenarioTestCase, self).setUp()
|
||||
self.server1 = mock.MagicMock()
|
||||
self.server2 = mock.MagicMock()
|
||||
self.reservations = mock.MagicMock(instances=[self.server1,
|
||||
self.server2])
|
||||
|
||||
def test__list_servers(self):
|
||||
servers_list = []
|
||||
self.clients("ec2").get_only_instances.return_value = servers_list
|
||||
ec2_scenario = utils.EC2Scenario()
|
||||
return_servers_list = ec2_scenario._list_servers()
|
||||
self.assertEqual(servers_list, return_servers_list)
|
||||
self._test_atomic_action_timer(ec2_scenario.atomic_actions(),
|
||||
"ec2.list_servers")
|
||||
|
||||
def test__update_resource(self):
|
||||
resource = mock.MagicMock()
|
||||
scenario = utils.EC2Scenario(self.context)
|
||||
self.assertEqual(scenario._update_resource(resource), resource)
|
||||
resource.update.assert_called_once_with()
|
||||
|
||||
def test__boot_servers(self):
|
||||
self.clients("ec2").run_instances.return_value = self.reservations
|
||||
ec2_scenario = utils.EC2Scenario(context={})
|
||||
ec2_scenario._update_resource = mock.Mock()
|
||||
ec2_scenario._boot_servers("image", "flavor", 2)
|
||||
expected = [
|
||||
mock.call(
|
||||
self.server1,
|
||||
ready_statuses=["RUNNING"],
|
||||
update_resource=ec2_scenario._update_resource,
|
||||
check_interval=CONF.openstack.ec2_server_boot_poll_interval,
|
||||
timeout=CONF.openstack.ec2_server_boot_timeout
|
||||
),
|
||||
mock.call(
|
||||
self.server2,
|
||||
ready_statuses=["RUNNING"],
|
||||
update_resource=ec2_scenario._update_resource,
|
||||
check_interval=CONF.openstack.ec2_server_boot_poll_interval,
|
||||
timeout=CONF.openstack.ec2_server_boot_timeout
|
||||
)
|
||||
]
|
||||
self.mock_wait_for_status.mock.assert_has_calls(expected)
|
||||
self._test_atomic_action_timer(ec2_scenario.atomic_actions(),
|
||||
"ec2.boot_servers")
|
@ -874,30 +874,6 @@ class OSClientsTestCase(test.TestCase):
|
||||
mock_swift.client.Connection.assert_called_once_with(**kw)
|
||||
self.assertEqual(fake_swift, self.clients.cache["swift"])
|
||||
|
||||
@mock.patch("%s.EC2._get_endpoint" % PATH)
|
||||
def test_ec2(self, mock_ec2__get_endpoint):
|
||||
mock_boto = mock.Mock()
|
||||
self.fake_keystone.ec2 = mock.Mock()
|
||||
self.fake_keystone.ec2.create.return_value = mock.Mock(
|
||||
access="fake_access", secret="fake_secret")
|
||||
mock_ec2__get_endpoint.return_value = "http://fake.to:1/fake"
|
||||
fake_ec2 = fakes.FakeEC2Client()
|
||||
mock_boto.connect_ec2_endpoint.return_value = fake_ec2
|
||||
|
||||
self.assertNotIn("ec2", self.clients.cache)
|
||||
with mock.patch.dict("sys.modules", {"boto": mock_boto}):
|
||||
client = self.clients.ec2()
|
||||
|
||||
self.assertEqual(fake_ec2, client)
|
||||
kw = {
|
||||
"url": "http://fake.to:1/fake",
|
||||
"aws_access_key_id": "fake_access",
|
||||
"aws_secret_access_key": "fake_secret",
|
||||
"is_secure": self.credential.https_insecure,
|
||||
}
|
||||
mock_boto.connect_ec2_endpoint.assert_called_once_with(**kw)
|
||||
self.assertEqual(fake_ec2, self.clients.cache["ec2"])
|
||||
|
||||
@mock.patch("%s.Keystone.service_catalog" % PATH)
|
||||
def test_services(self, mock_keystone_service_catalog):
|
||||
available_services = {consts.ServiceType.IDENTITY: {},
|
||||
|
@ -172,42 +172,6 @@ class FlavorTestCase(test.TestCase):
|
||||
resource_spec=resource_spec, config={})
|
||||
|
||||
|
||||
class EC2FlavorTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(EC2FlavorTestCase, 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"))
|
||||
self.type_cls = types.EC2Flavor(
|
||||
context={"admin": {"credential": mock.Mock()}})
|
||||
self.type_cls._clients = self.clients
|
||||
|
||||
def test_preprocess_by_name(self):
|
||||
resource_spec = {"name": "m1.nano"}
|
||||
flavor_name = self.type_cls.pre_process(
|
||||
resource_spec=resource_spec, config={})
|
||||
self.assertEqual("m1.nano", flavor_name)
|
||||
|
||||
def test_preprocess_by_id(self):
|
||||
resource_spec = {"id": "2"}
|
||||
flavor_name = self.type_cls.pre_process(
|
||||
resource_spec=resource_spec, config={})
|
||||
self.assertEqual("m1.nano", flavor_name)
|
||||
|
||||
def test_preprocess_by_id_no_match(self):
|
||||
resource_spec = {"id": "4"}
|
||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
||||
self.type_cls.pre_process,
|
||||
resource_spec=resource_spec, config={})
|
||||
|
||||
|
||||
class GlanceImageTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -5,7 +5,6 @@ argparse===1.2.1
|
||||
asn1crypto===0.24.0
|
||||
Babel===2.6.0
|
||||
bcrypt===3.1.4
|
||||
boto===2.49.0
|
||||
cachetools===2.1.0
|
||||
certifi===2018.8.24
|
||||
cffi===1.11.5
|
||||
|
Loading…
Reference in New Issue
Block a user