Remove all calls to network interface via Nova

Nova team removed all network interface from novaclient, forces to use
neutronclient. That is why we need to remove a bunch of scenarios and
utils.

Change-Id: Idafbdedaf01c9ed77cf5ec269b0ccf0c90183566
This commit is contained in:
Andrey Kurilin 2017-05-15 22:12:05 -07:00
parent c943cbf496
commit 63b39e9df1
12 changed files with 50 additions and 835 deletions

View File

@ -836,119 +836,6 @@
failure_rate: failure_rate:
max: 0 max: 0
NovaSecGroup.create_and_delete_secgroups:
-
args:
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: 4
concurrency: 4
context:
users:
tenants: 3
users_per_tenant: 2
quotas:
neutron:
security_group: -1
security_group_rule: -1
sla:
failure_rate:
max: 0
NovaSecGroup.create_and_update_secgroups:
-
args:
security_group_count: 5
runner:
type: "constant"
times: 4
concurrency: 4
context:
users:
tenants: 3
users_per_tenant: 2
quotas:
neutron:
security_group: -1
sla:
failure_rate:
max: 0
NovaSecGroup.create_and_list_secgroups:
-
args:
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: 4
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
user_choice_method: "round_robin"
quotas:
neutron:
security_group: -1
security_group_rule: -1
sla:
failure_rate:
max: 0
NovaSecGroup.boot_and_delete_server_with_secgroups:
-
args:
flavor:
name: {{flavor_name}}
image:
name: {{image_name}}
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: 2
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
network:
start_cidr: "10.2.0.0/24"
quotas:
neutron:
security_group: -1
security_group_rule: -1
NovaSecGroup.boot_server_and_add_secgroups:
-
args:
flavor:
name: {{flavor_name}}
image:
name: {{image_name}}
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: 2
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
network:
start_cidr: "10.2.0.0/24"
quotas:
neutron:
security_group: -1
security_group_rule: -1
sla:
failure_rate:
max: 0
NovaKeypair.create_and_delete_keypair: NovaKeypair.create_and_delete_keypair:
- -
runner: runner:

View File

@ -301,113 +301,3 @@
sla: sla:
failure_rate: failure_rate:
max: 0 max: 0
NovaSecGroup.create_and_delete_secgroups:
-
args:
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 4}}
sla:
failure_rate:
max: 0
NovaSecGroup.create_and_list_secgroups:
-
args:
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 4}}
sla:
failure_rate:
max: 0
VMTasks.boot_runcommand_delete:
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
command:
script_file: "~/.rally/extra/instance_test.sh"
interpreter: "/bin/sh"
username: "cirros"
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 2}}
context:
network: {}
sla:
failure_rate:
max: 0
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
command:
script_file: "~/.rally/extra/instance_test.sh"
interpreter: "/bin/sh"
username: "cirros"
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 2}}
context:
network: {}
sla:
failure_rate:
max: 0
-
args:
command:
remote_path: "./dd_test.sh"
flavor:
name: "m1.tiny"
username: "cirros"
runner:
type: "constant"
times: 1
concurrency: 1
context:
image_command_customizer:
command:
local_path: "/home/jenkins/.rally/extra/install_benchmark.sh"
remote_path: "./install_benchmark.sh"
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
username: "cirros"
network: {}
VMTasks.dd_load_test:
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
floating_network: "public"
force_delete: false
command:
interpreter: "/bin/sh"
username: "cirros"
runner:
type: "constant"
times: 2
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
network: {}

View File

@ -577,24 +577,6 @@
max: 0 max: 0
NovaServers.boot_and_delete_server: NovaServers.boot_and_delete_server:
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
runner:
type: "constant"
times: 1
concurrency: 1
context:
users:
tenants: 1
users_per_tenant: 1
sla:
failure_rate:
max: 0
- -
args: args:
auto_assign_nic: True auto_assign_nic: True
@ -619,175 +601,3 @@
sla: sla:
failure_rate: failure_rate:
max: 0 max: 0
NovaSecGroup.create_and_delete_secgroups:
-
args:
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 4}}
context:
users:
tenants: {{smoke or 2}}
users_per_tenant: {{smoke or 2}}
quotas:
neutron:
security_group: -1
security_group_rule: -1
sla:
failure_rate:
max: 0
NovaSecGroup.create_and_list_secgroups:
-
args:
security_group_count: 5
rules_per_security_group: 5
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 4}}
context:
users:
tenants: {{smoke or 2}}
users_per_tenant: {{smoke or 2}}
quotas:
neutron:
security_group: -1
security_group_rule: -1
sla:
failure_rate:
max: 0
VMTasks.boot_runcommand_delete:
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
command:
script_file: "~/.rally/extra/instance_test.sh"
interpreter: "/bin/sh"
username: "cirros"
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 2}}
context:
users:
tenants: {{smoke or 2}}
users_per_tenant: {{smoke or 2}}
network: {}
sla:
failure_rate:
max: 0
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
command:
script_file: "~/.rally/extra/instance_test.sh"
interpreter: "/bin/sh"
username: "cirros"
volume_args:
size: 2
runner:
type: "constant"
times: {{smoke or 4}}
concurrency: {{smoke or 2}}
context:
users:
tenants: {{smoke or 2}}
users_per_tenant: {{smoke or 2}}
network: {}
sla:
failure_rate:
max: 0
-
args:
flavor:
name: {{flavor_name}}
image:
name: {{image_name}}
floating_network: "public"
command:
script_inline: |
time_seconds(){ (time -p $1 ) 2>&1 |awk '/real/{print $2}'; }
file=/tmp/test.img
c=100 #100M
write_seq=$(time_seconds "dd if=/dev/zero of=$file bs=1M count=$c")
read_seq=$(time_seconds "dd if=$file of=/dev/null bs=1M count=$c")
[ -f $file ] && rm $file
echo "{
\"write_seq\": $write_seq,
\"read_seq\": $read_seq
}"
interpreter: "/bin/sh"
username: "cirros"
runner:
type: "constant"
times: 2
concurrency: 2
context:
users:
tenants: 1
users_per_tenant: 1
network: {}
sla:
failure_rate:
max: 0
-
args:
command:
remote_path: "./dd_test.sh"
flavor:
name: "m1.tiny"
username: "cirros"
runner:
type: "constant"
times: 1
concurrency: 1
context:
image_command_customizer:
command:
local_path: "/home/jenkins/.rally/extra/install_benchmark.sh"
remote_path: "./install_benchmark.sh"
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
username: "cirros"
users:
tenants: 1
users_per_tenant: 1
network:
dns_nameservers: []
VMTasks.dd_load_test:
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
floating_network: "public"
force_delete: false
command:
interpreter: "/bin/sh"
username: "cirros"
runner:
type: "constant"
times: 2
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
network: {}

View File

@ -167,27 +167,11 @@ class NovaServerGroups(base.ResourceManager):
pass pass
@base.resource("nova", "floating_ips", order=next(_nova_order))
class NovaFloatingIPs(SynchronizedDeletion, base.ResourceManager):
def name(self):
return self.raw_resource.pool
@base.resource("nova", "keypairs", order=next(_nova_order)) @base.resource("nova", "keypairs", order=next(_nova_order))
class NovaKeypair(SynchronizedDeletion, base.ResourceManager): class NovaKeypair(SynchronizedDeletion, base.ResourceManager):
pass pass
@base.resource("nova", "security_groups", order=next(_nova_order),
tenant_resource=True)
class NovaSecurityGroup(SynchronizedDeletion, base.ResourceManager):
def list(self):
return filter(lambda x: x.name != "default",
super(NovaSecurityGroup, self).list())
@base.resource("nova", "quotas", order=next(_nova_order), @base.resource("nova", "quotas", order=next(_nova_order),
admin_required=True, tenant_resource=True) admin_required=True, tenant_resource=True)
class NovaQuotas(QuotaMixin): class NovaQuotas(QuotaMixin):
@ -208,25 +192,6 @@ class NovaFlavors(base.ResourceManager):
return False return False
@base.resource("nova", "floating_ips_bulk", order=next(_nova_order),
admin_required=True)
class NovaFloatingIpsBulk(SynchronizedDeletion, base.ResourceManager):
def id(self):
return self.raw_resource.address
def name(self):
return None
@base.resource("nova", "networks", order=next(_nova_order),
admin_required=True, tenant_resource=True)
class NovaNetworks(SynchronizedDeletion, base.ResourceManager):
def name(self):
return self.raw_resource.label
@base.resource("nova", "aggregates", order=next(_nova_order), @base.resource("nova", "aggregates", order=next(_nova_order),
admin_required=True, perform_for_admin_only=True) admin_required=True, perform_for_admin_only=True)
class NovaAggregate(SynchronizedDeletion, base.ResourceManager): class NovaAggregate(SynchronizedDeletion, base.ResourceManager):

View File

@ -29,7 +29,6 @@ from rally.plugins.openstack import credential
from rally.plugins.openstack.services.identity import identity from rally.plugins.openstack.services.identity import identity
from rally.plugins.openstack.wrappers import network from rally.plugins.openstack.wrappers import network
from rally.task import context from rally.task import context
from rally.task import utils
from rally.task import validation from rally.task import validation
from rally.common import opts from rally.common import opts
@ -124,32 +123,11 @@ class UserGenerator(context.Context):
with logging.ExceptionLogger( with logging.ExceptionLogger(
LOG, _("Unable to delete default security group")): LOG, _("Unable to delete default security group")):
uclients = osclients.Clients(user["credential"]) uclients = osclients.Clients(user["credential"])
sg = uclients.nova().security_groups.find(name="default") security_groups = uclients.neutron().list_security_groups()
clients.neutron().delete_security_group(sg.id) default = [sg for sg in security_groups["security_groups"]
if sg["name"] == "default"]
def _remove_associated_networks(self): if default:
"""Delete associated Nova networks from tenants.""" clients.neutron().delete_security_group(default[0]["id"])
# NOTE(rmk): Ugly hack to deal with the fact that Nova Network
# networks can only be disassociated in an admin context. Discussed
# with boris-42 before taking this approach [LP-Bug #1350517].
clients = osclients.Clients(self.credential)
if consts.Service.NOVA not in clients.services().values():
return
nova_admin = clients.nova()
if not utils.check_service_status(nova_admin, "nova-network"):
return
for net in nova_admin.networks.list():
network_tenant_id = nova_admin.networks.get(net).project_id
if network_tenant_id in self.context["tenants"]:
try:
nova_admin.networks.disassociate(net)
except Exception as ex:
LOG.warning("Failed disassociate net: %(tenant_id)s. "
"Exception: %(ex)s" %
{"tenant_id": network_tenant_id, "ex": ex})
def _create_tenants(self): def _create_tenants(self):
threads = self.config["resource_management_workers"] threads = self.config["resource_management_workers"]
@ -238,8 +216,6 @@ class UserGenerator(context.Context):
def _delete_tenants(self): def _delete_tenants(self):
threads = self.config["resource_management_workers"] threads = self.config["resource_management_workers"]
self._remove_associated_networks()
def publish(queue): def publish(queue):
for tenant_id in self.context["tenants"]: for tenant_id in self.context["tenants"]:
queue.append(tenant_id) queue.append(tenant_id)

View File

@ -36,13 +36,16 @@ def _prepare_open_secgroup(credential, secgroup_name):
:returns: dict with security group details :returns: dict with security group details
""" """
nova = osclients.Clients(credential).nova() neutron = osclients.Clients(credential).neutron()
security_groups = neutron.list_security_groups()["security_groups"]
if secgroup_name not in [sg.name for sg in nova.security_groups.list()]: rally_open = [sg for sg in security_groups if sg["name"] == secgroup_name]
if not rally_open:
descr = "Allow ssh access to VMs created by Rally for benchmarking" descr = "Allow ssh access to VMs created by Rally for benchmarking"
rally_open = nova.security_groups.create(secgroup_name, descr) rally_open = neutron.create_security_groups(
{"security_group": {"name": secgroup_name,
rally_open = nova.security_groups.find(name=secgroup_name) "description": descr}})
else:
rally_open = rally_open[0]
rules_to_add = [ rules_to_add = [
{ {
@ -71,15 +74,17 @@ def _prepare_open_secgroup(credential, secgroup_name):
for new_rule in rules_to_add: for new_rule in rules_to_add:
if not any(rule_match(new_rule, existing_rule) for existing_rule if not any(rule_match(new_rule, existing_rule) for existing_rule
in rally_open.rules): in rally_open["security_group_rules"]):
nova.security_group_rules.create( neutron.create_security_group_rules(
rally_open.id, {"security_group_rule": {
from_port=new_rule["from_port"], "security_group_id": rally_open["id"],
to_port=new_rule["to_port"], "port_range_min": new_rule["from_port"],
ip_protocol=new_rule["ip_protocol"], "port_range_max": new_rule["to_port"],
cidr=new_rule["ip_range"]["cidr"]) "protocol": new_rule["ip_protocol"],
"ethertype": new_rule["ip_range"]["cidr"]
}})
return rally_open.to_dict() return rally_open
@validation.add("required_platform", platform="openstack", users=True) @validation.add("required_platform", platform="openstack", users=True)
@ -113,5 +118,4 @@ class AllowSSH(context.Context):
LOG, _("Unable to delete secgroup: %s.") % LOG, _("Unable to delete secgroup: %s.") %
user["secgroup"]["name"]): user["secgroup"]["name"]):
clients = osclients.Clients(user["credential"]) clients = osclients.Clients(user["credential"])
clients.nova().security_groups.get( clients.neutron().delete_security_group(user["secgroup"]["id"])
user["secgroup"]["id"]).delete()

View File

@ -613,11 +613,6 @@ class NovaScenario(scenario.OpenStackScenario):
return not must_exist return not must_exist
return _check_addr return _check_addr
@atomic.action_timer("nova.list_networks")
def _list_networks(self):
"""Return user networks list."""
return self.clients("nova").networks.list()
@atomic.action_timer("nova.resize") @atomic.action_timer("nova.resize")
def _resize(self, server, flavor): def _resize(self, server, flavor):
server.resize(flavor) server.resize(flavor)
@ -774,63 +769,6 @@ class NovaScenario(scenario.OpenStackScenario):
"Migration complete but instance did not change host: %s" % "Migration complete but instance did not change host: %s" %
host_pre_migrate) host_pre_migrate)
def _create_security_groups(self, security_group_count):
security_groups = []
with atomic.ActionTimer(self, "nova.create_%s_security_groups" %
security_group_count):
for i in range(security_group_count):
sg_name = self.generate_random_name()
sg = self.clients("nova").security_groups.create(sg_name,
sg_name)
security_groups.append(sg)
return security_groups
def _create_rules_for_security_group(self, security_groups,
rules_per_security_group,
ip_protocol="tcp", cidr="0.0.0.0/0"):
action_name = ("nova.create_%s_rules" % (rules_per_security_group *
len(security_groups)))
creation_status = True
with atomic.ActionTimer(self, action_name):
for i, security_group in enumerate(security_groups):
result = True
for j in range(rules_per_security_group):
result = self.clients("nova").security_group_rules.create(
security_group.id,
from_port=(i * rules_per_security_group + j + 1),
to_port=(i * rules_per_security_group + j + 1),
ip_protocol=ip_protocol,
cidr=cidr)
if not result:
creation_status = False
return creation_status
def _update_security_groups(self, security_groups):
"""Update a list of security groups
:param security_groups: list, security_groups that are to be updated
"""
with atomic.ActionTimer(self, "nova.update_%s_security_groups" %
len(security_groups)):
for sec_group in security_groups:
sg_new_name = self.generate_random_name()
sg_new_desc = self.generate_random_name()
self.clients("nova").security_groups.update(sec_group.id,
sg_new_name,
sg_new_desc)
def _delete_security_groups(self, security_group):
with atomic.ActionTimer(self, "nova.delete_%s_security_groups" %
len(security_group)):
for sg in security_group:
self.clients("nova").security_groups.delete(sg.id)
def _list_security_groups(self):
"""Return security groups list."""
with atomic.ActionTimer(self, "nova.list_security_groups"):
return self.clients("nova").security_groups.list()
@atomic.optional_action_timer("nova.add_server_secgroups") @atomic.optional_action_timer("nova.add_server_secgroups")
def _add_server_secgroups(self, server, security_group, def _add_server_secgroups(self, server, security_group,
atomic_action=False): atomic_action=False):
@ -846,16 +784,6 @@ class NovaScenario(scenario.OpenStackScenario):
return self.clients("nova").servers.add_security_group(server, return self.clients("nova").servers.add_security_group(server,
security_group) security_group)
@atomic.action_timer("nova.list_floating_ips_bulk")
def _list_floating_ips_bulk(self):
"""List all floating IPs."""
return self.admin_clients("nova").floating_ips_bulk.list()
@atomic.action_timer("nova.delete_floating_ips_bulk")
def _delete_floating_ips_bulk(self, ip_range):
"""Delete floating IPs by range."""
return self.admin_clients("nova").floating_ips_bulk.delete(ip_range)
@atomic.action_timer("nova.list_hypervisors") @atomic.action_timer("nova.list_hypervisors")
def _list_hypervisors(self, detailed=True): def _list_hypervisors(self, detailed=True):
"""List hypervisors.""" """List hypervisors."""

View File

@ -164,16 +164,6 @@ class Nova(ResourceManager):
def list_flavors(self): def list_flavors(self):
return self.client.flavors.list() return self.client.flavors.list()
def list_floating_ip_pools(self):
return self.client.floating_ip_pools.list()
@skip_if_service(consts.Service.NEUTRON)
def list_floating_ips(self):
return self.client.floating_ips.list()
def list_floating_ips_bulk(self):
return self.client.floating_ips_bulk.list()
def list_aggregates(self): def list_aggregates(self):
return self.client.aggregates.list() return self.client.aggregates.list()
@ -189,15 +179,6 @@ class Nova(ResourceManager):
def list_keypairs(self): def list_keypairs(self):
return self.client.keypairs.list() return self.client.keypairs.list()
@skip_if_service(consts.Service.NEUTRON)
def list_networks(self):
return self.client.networks.list()
@skip_if_service(consts.Service.NEUTRON)
def list_security_groups(self):
return self.client.security_groups.list(
search_opts={"all_tenants": True})
def list_servers(self): def list_servers(self):
return self.client.servers.list( return self.client.servers.list(
search_opts={"all_tenants": True}) search_opts={"all_tenants": True})

View File

@ -105,14 +105,6 @@ class NovaServerTestCase(test.TestCase):
server.raw_resource.id) server.raw_resource.id)
class NovaFloatingIPsTestCase(test.TestCase):
def test_name(self):
fips = resources.NovaFloatingIPs()
fips.raw_resource = mock.MagicMock()
self.assertTrue(fips.name())
class NovaFlavorsTestCase(test.TestCase): class NovaFlavorsTestCase(test.TestCase):
@mock.patch("%s.base.ResourceManager._manager" % BASE) @mock.patch("%s.base.ResourceManager._manager" % BASE)
@ -145,41 +137,6 @@ class NovaServerGroupsTestCase(test.TestCase):
self.assertEqual(server_groups, resources.NovaServerGroups().list()) self.assertEqual(server_groups, resources.NovaServerGroups().list())
class NovaSecurityGroupTestCase(test.TestCase):
@mock.patch("%s.base.ResourceManager._manager" % BASE)
def test_list(self, mock_resource_manager__manager):
secgroups = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
secgroups[0].name = "a"
secgroups[1].name = "b"
secgroups[2].name = "default"
mock_resource_manager__manager().list.return_value = secgroups
self.assertSequenceEqual(secgroups[:2],
resources.NovaSecurityGroup().list())
class NovaFloatingIpsBulkTestCase(test.TestCase):
def test_id(self):
ip_range = resources.NovaFloatingIpsBulk()
ip_range.raw_resource = mock.MagicMock()
self.assertEqual(ip_range.raw_resource.address, ip_range.id())
def test_name(self):
fips = resources.NovaFloatingIpsBulk()
fips.raw_resource = mock.MagicMock()
self.assertIsNone(fips.name())
class NovaNetworksTestCase(test.TestCase):
def test_name(self):
network = resources.NovaNetworks()
network.raw_resource = mock.MagicMock()
self.assertEqual(network.raw_resource.label, network.name())
class EC2MixinTestCase(test.TestCase): class EC2MixinTestCase(test.TestCase):
def get_ec2_mixin(self): def get_ec2_mixin(self):

View File

@ -98,7 +98,15 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
admin_clients.services.return_value = { admin_clients.services.return_value = {
"compute": consts.Service.NOVA, "compute": consts.Service.NOVA,
"neutron": consts.Service.NEUTRON} "neutron": consts.Service.NEUTRON}
user_clients = [mock.Mock(), mock.Mock()] user1 = mock.Mock()
user1.neutron.return_value.list_security_groups.return_value = {
"security_groups": [{"id": "id-1", "name": "default"},
{"id": "id-2", "name": "not-default"}]}
user2 = mock.Mock()
user2.neutron.return_value.list_security_groups.return_value = {
"security_groups": [{"id": "id-3", "name": "default"},
{"id": "id-4", "name": "not-default"}]}
user_clients = [user1, user2]
self.osclients.Clients.side_effect = [admin_clients] + user_clients self.osclients.Clients.side_effect = [admin_clients] + user_clients
mock_iterate_per_tenants.return_value = [ mock_iterate_per_tenants.return_value = [
@ -117,69 +125,14 @@ class UserGeneratorTestCase(test.ScenarioTestCase):
for u, t in mock_iterate_per_tenants.return_value] for u, t in mock_iterate_per_tenants.return_value]
self.osclients.Clients.assert_has_calls(expected, any_order=True) self.osclients.Clients.assert_has_calls(expected, any_order=True)
expected_deletes = [] user_net = user1.neutron.return_value
for clients in user_clients: user_net.list_security_groups.assert_called_once_with()
user_nova = clients.nova.return_value user_net = user2.neutron.return_value
user_nova.security_groups.find.assert_called_once_with( user_net.list_security_groups.assert_called_once_with()
name="default") admin_neutron = admin_clients.neutron.return_value
expected_deletes.append( self.assertEqual(
mock.call(user_nova.security_groups.find.return_value.id)) [mock.call("id-1"), mock.call("id-3")],
admin_neutron.delete_security_group.call_args_list)
nova_admin = admin_clients.neutron.return_value
nova_admin.delete_security_group.assert_has_calls(expected_deletes,
any_order=True)
@mock.patch("rally.task.utils.check_service_status",
return_value=True)
def test__remove_associated_networks(self, mock_check_service_status):
def fake_get_network(req_network):
for network in networks:
if network.project_id == req_network.project_id:
return network
networks = [mock.MagicMock(project_id="t1"),
mock.MagicMock(project_id="t4")]
nova_admin = mock.MagicMock()
clients = mock.MagicMock()
self.osclients.Clients.return_value = clients
clients.services.return_value = {"compute": "nova"}
clients.nova.return_value = nova_admin
nova_admin.networks.list.return_value = networks
nova_admin.networks.get = fake_get_network
user_generator = users.UserGenerator(self.context)
user_generator.context["tenants"] = {"t1": {"id": "t1", "name": "t1"},
"t2": {"id": "t2", "name": "t2"}}
user_generator._remove_associated_networks()
mock_check_service_status.assert_called_once_with(mock.ANY,
"nova-network")
nova_admin.networks.disassociate.assert_called_once_with(networks[0])
@mock.patch("rally.task.utils.check_service_status",
return_value=True)
def test__remove_associated_networks_failure(self,
mock_check_service_status):
def fake_get_network(req_network):
for network in networks:
if network.project_id == req_network.project_id:
return network
networks = [mock.MagicMock(project_id="t1"),
mock.MagicMock(project_id="t4")]
nova_admin = mock.MagicMock()
clients = mock.MagicMock()
self.osclients.Clients.return_value = clients
clients.services.return_value = {"compute": "nova"}
clients.nova.return_value = nova_admin
nova_admin.networks.list.return_value = networks
nova_admin.networks.get = fake_get_network
nova_admin.networks.disassociate.side_effect = Exception()
user_generator = users.UserGenerator(self.context)
user_generator.context["tenants"] = {"t1": {"id": "t1", "name": "t1"},
"t2": {"id": "t2", "name": "t2"}}
user_generator._remove_associated_networks()
mock_check_service_status.assert_called_once_with(mock.ANY,
"nova-network")
nova_admin.networks.disassociate.assert_called_once_with(networks[0])
@mock.patch("%s.identity" % CTX) @mock.patch("%s.identity" % CTX)
def test__create_tenants(self, mock_identity): def test__create_tenants(self, mock_identity):

View File

@ -16,7 +16,6 @@
import mock import mock
from rally.plugins.openstack.context.network import allow_ssh from rally.plugins.openstack.context.network import allow_ssh
from tests.unit import fakes
from tests.unit import test from tests.unit import test
@ -52,47 +51,15 @@ class AllowSSHContextTestCase(test.TestCase):
"tenants": {"uuid1": {"id": "uuid1", "name": "uuid1"}}, "tenants": {"uuid1": {"id": "uuid1", "name": "uuid1"}},
}) })
@mock.patch("%s.osclients.Clients" % CTX)
def test__prepare_open_secgroup(self, mock_clients):
fake_nova = fakes.FakeNovaClient()
self.assertEqual(len(fake_nova.security_groups.list()), 1)
mock_cl = mock.MagicMock()
mock_cl.nova.return_value = fake_nova
mock_clients.return_value = mock_cl
ret = allow_ssh._prepare_open_secgroup("credential",
self.secgroup_name)
self.assertEqual(self.secgroup_name, ret["name"])
self.assertEqual(2, len(fake_nova.security_groups.list()))
self.assertIn(
self.secgroup_name,
[sg.name for sg in fake_nova.security_groups.list()])
# run prep again, check that another security group is not created
allow_ssh._prepare_open_secgroup("credential", self.secgroup_name)
self.assertEqual(2, len(fake_nova.security_groups.list()))
@mock.patch("%s.osclients.Clients" % CTX) @mock.patch("%s.osclients.Clients" % CTX)
def test__prepare_open_secgroup_rules(self, mock_clients): def test__prepare_open_secgroup_rules(self, mock_clients):
fake_nova = fakes.FakeNovaClient() fake_neutron = mock_clients.return_value.neutron.return_value
fake_neutron.list_security_groups.return_value = {
# NOTE(hughsaunders) Default security group is precreated "security_groups": [{"id": "id", "name": "foo",
self.assertEqual(1, len(fake_nova.security_groups.list())) "security_group_rules": []}]}
mock_cl = mock.MagicMock()
mock_cl.nova.return_value = fake_nova
mock_clients.return_value = mock_cl
allow_ssh._prepare_open_secgroup("credential", self.secgroup_name) allow_ssh._prepare_open_secgroup("credential", self.secgroup_name)
allow_ssh._prepare_open_secgroup("credential", "foo")
self.assertEqual(2, len(fake_nova.security_groups.list()))
rally_open = fake_nova.security_groups.find(self.secgroup_name)
self.assertEqual(3, len(rally_open.rules))
# run prep again, check that extra rules are not created
allow_ssh._prepare_open_secgroup("credential", self.secgroup_name)
rally_open = fake_nova.security_groups.find(self.secgroup_name)
self.assertEqual(3, len(rally_open.rules))
@mock.patch("%s.osclients.Clients" % CTX) @mock.patch("%s.osclients.Clients" % CTX)
@mock.patch("%s._prepare_open_secgroup" % CTX) @mock.patch("%s._prepare_open_secgroup" % CTX)
@ -101,8 +68,7 @@ class AllowSSHContextTestCase(test.TestCase):
self, mock_network_wrap, mock__prepare_open_secgroup, self, mock_network_wrap, mock__prepare_open_secgroup,
mock_clients): mock_clients):
mock_network_wrapper = mock.MagicMock() mock_network_wrapper = mock.MagicMock()
mock_network_wrapper.supports_extension.return_value = ( mock_network_wrapper.supports_extension.return_value = (True, "")
True, "")
mock_network_wrap.return_value = mock_network_wrapper mock_network_wrap.return_value = mock_network_wrapper
mock__prepare_open_secgroup.return_value = { mock__prepare_open_secgroup.return_value = {
"name": "secgroup", "name": "secgroup",
@ -118,9 +84,8 @@ class AllowSSHContextTestCase(test.TestCase):
[ [
mock.call("admin_credential"), mock.call("admin_credential"),
mock.call("credential"), mock.call("credential"),
mock.call().nova(), mock.call().neutron(),
mock.call().nova().security_groups.get("secgroup_id"), mock.call().neutron().delete_security_group("secgroup_id")
mock.call().nova().security_groups.get().delete()
], ],
mock_clients.mock_calls) mock_clients.mock_calls)

View File

@ -554,15 +554,6 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
nova_scenario.check_ip_address(floating_ip, must_exist=False) nova_scenario.check_ip_address(floating_ip, must_exist=False)
(fake_server)) (fake_server))
def test__list_networks(self):
network_list = []
self.clients("nova").networks.list.return_value = network_list
nova_scenario = utils.NovaScenario(context=self.context)
return_network_list = nova_scenario._list_networks()
self.assertEqual(network_list, return_network_list)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.list_networks")
def test__resize(self): def test__resize(self):
nova_scenario = utils.NovaScenario(context=self.context) nova_scenario = utils.NovaScenario(context=self.context)
to_flavor = mock.Mock() to_flavor = mock.Mock()
@ -704,79 +695,6 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
nova_scenario._migrate, nova_scenario._migrate,
fake_server, skip_host_check=False) fake_server, skip_host_check=False)
def test__create_security_groups(self):
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario.generate_random_name = mock.MagicMock()
security_group_count = 5
sec_groups = nova_scenario._create_security_groups(
security_group_count)
self.assertEqual(security_group_count, len(sec_groups))
self.assertEqual(security_group_count,
nova_scenario.generate_random_name.call_count)
self.assertEqual(
security_group_count,
self.clients("nova").security_groups.create.call_count)
self._test_atomic_action_timer(
nova_scenario.atomic_actions(),
"nova.create_%s_security_groups" % security_group_count)
def test__create_rules_for_security_group(self):
nova_scenario = utils.NovaScenario(context=self.context)
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
rules_per_security_group = 10
nova_scenario._create_rules_for_security_group(
fake_secgroups, rules_per_security_group)
self.assertEqual(
len(fake_secgroups) * rules_per_security_group,
self.clients("nova").security_group_rules.create.call_count)
self._test_atomic_action_timer(
nova_scenario.atomic_actions(),
"nova.create_%s_rules" %
(rules_per_security_group * len(fake_secgroups)))
def test__update_security_groups(self):
nova_scenario = utils.NovaScenario(context=self.context)
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
nova_scenario._update_security_groups(fake_secgroups)
self.assertEqual(
len(fake_secgroups),
self.clients("nova").security_groups.update.call_count)
self._test_atomic_action_timer(
nova_scenario.atomic_actions(),
"nova.update_%s_security_groups" % len(fake_secgroups))
def test__delete_security_groups(self):
nova_scenario = utils.NovaScenario(context=self.context)
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
nova_scenario._delete_security_groups(fake_secgroups)
self.assertSequenceEqual(
map(lambda x: mock.call(x.id), fake_secgroups),
self.clients("nova").security_groups.delete.call_args_list)
self._test_atomic_action_timer(
nova_scenario.atomic_actions(),
"nova.delete_%s_security_groups" % len(fake_secgroups))
def test__list_security_groups(self):
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario._list_security_groups()
self.clients("nova").security_groups.list.assert_called_once_with()
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.list_security_groups")
def test__add_server_secgroups(self): def test__add_server_secgroups(self):
server = mock.Mock() server = mock.Mock()
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1")] fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1")]
@ -869,25 +787,6 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(nova_scenario.atomic_actions(), self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.get_keypair") "nova.get_keypair")
def test__list_floating_ips_bulk(self):
floating_ips_bulk_list = ["foo_floating_ips_bulk"]
self.admin_clients("nova").floating_ips_bulk.list.return_value = (
floating_ips_bulk_list)
nova_scenario = utils.NovaScenario(context=self.context)
return_floating_ips_bulk_list = nova_scenario._list_floating_ips_bulk()
self.assertEqual(floating_ips_bulk_list, return_floating_ips_bulk_list)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.list_floating_ips_bulk")
def test__delete_floating_ips_bulk(self):
fake_cidr = "10.2.0.0/24"
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario._delete_floating_ips_bulk(fake_cidr)
self.admin_clients(
"nova").floating_ips_bulk.delete.assert_called_once_with(fake_cidr)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.delete_floating_ips_bulk")
def test__list_hypervisors(self): def test__list_hypervisors(self):
nova_scenario = utils.NovaScenario() nova_scenario = utils.NovaScenario()
result = nova_scenario._list_hypervisors(detailed=False) result = nova_scenario._list_hypervisors(detailed=False)