Do not assume networks should be assigned

There are several places within the Nova benchark scenarios where we
are assuming networks should be assigned. This breaks a variety of
different deployments. Instead of always assigning a network, do so
based on whether a new scenario argument of auto_assign_nic=True.

Change-Id: I4e2dd58629f3c07b9928a95879056a79382fcf8b
Closes-Bug: #1353622
This commit is contained in:
Rafi Khardalian
2014-08-09 13:41:13 -07:00
parent 70a90e01c9
commit 103d7cc346
5 changed files with 38 additions and 66 deletions

View File

@@ -790,6 +790,7 @@
name: "m1.tiny"
image:
name: "cirros-0.3.2-x86_64-uec"
auto_assign_nics: false
runner:
type: "constant"
times: 4

View File

@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import random
import jsonschema
from rally.benchmark.scenarios import base
@@ -142,33 +140,24 @@ class NovaServers(utils.NovaScenario,
@validation.add(validation.image_valid_on_flavor("flavor", "image"))
@base.scenario(context={"cleanup": ["nova"]})
@validation.required_services(consts.Service.NOVA)
def boot_server(self, image, flavor, **kwargs):
def boot_server(self, image, flavor, auto_assign_nic=False, **kwargs):
"""Test VM boot - assumed clean-up is done elsewhere."""
if 'nics' not in kwargs:
nets = self.clients("nova").networks.list()
if nets:
random_nic = random.choice(nets)
kwargs['nics'] = [{'net-id': random_nic.id}]
self._boot_server(
self._generate_random_name(), image, flavor, **kwargs)
server_name = self._generate_random_name()
self._boot_server(server_name, image, flavor, auto_assign_nic,
**kwargs)
@types.set(image=types.ImageResourceType,
flavor=types.FlavorResourceType)
@validation.add(validation.image_valid_on_flavor("flavor", "image"))
@base.scenario(context={"cleanup": ["nova", "cinder"]})
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
def boot_server_from_volume(self, image, flavor,
volume_size, **kwargs):
def boot_server_from_volume(self, image, flavor, volume_size,
auto_assign_nic=False, **kwargs):
"""Test VM boot from volume - assumed clean-up is done elsewhere."""
if 'nics' not in kwargs:
nets = self.clients("nova").networks.list()
if nets:
random_nic = random.choice(nets)
kwargs['nics'] = [{'net-id': random_nic.id}]
volume = self._create_volume(volume_size, imageRef=image)
block_device_mapping = {'vda': '%s:::1' % volume.id}
self._boot_server(self._generate_random_name(),
image, flavor,
image, flavor, auto_assign_nic,
block_device_mapping=block_device_mapping,
**kwargs)

View File

@@ -74,7 +74,8 @@ class NovaScenario(base.Scenario):
return self.clients("nova").servers.list(detailed)
@base.atomic_action_timer('nova.boot_server')
def _boot_server(self, server_name, image_id, flavor_id, **kwargs):
def _boot_server(self, server_name, image_id, flavor_id,
auto_assign_nic=False, **kwargs):
"""Boots one server.
Returns when the server is actually booted and is in the "Active"
@@ -86,6 +87,7 @@ class NovaScenario(base.Scenario):
:param server_name: String used to name the server
:param image_id: ID of the image to be used for server creation
:param flavor_id: ID of the flavor to be used for server creation
:param auto_assign_nic: Boolean for whether or not to assign NICs
:param **kwargs: Other optional parameters to initialize the server
:returns: Created server object
@@ -97,15 +99,19 @@ class NovaScenario(base.Scenario):
elif allow_ssh_secgroup not in kwargs['security_groups']:
kwargs['security_groups'].append(allow_ssh_secgroup)
nets = self.clients("nova").networks.list()
fip_pool = [
pool.name
for pool in self.clients("nova").floating_ip_pools.list()
]
for net in nets:
if net.label not in fip_pool:
kwargs['nics'] = [{'net-id': net.id}]
break
nics = kwargs.get('nics', False)
if auto_assign_nic and nics is False:
nets = self.clients("nova").networks.list()
fip_pool = [
pool.name
for pool in
self.clients("nova").floating_ip_pools.list()
]
for net in nets:
if net.label not in fip_pool:
kwargs['nics'] = [{'net-id': net.id}]
break
server = self.clients("nova").servers.create(server_name, image_id,
flavor_id, **kwargs)

View File

@@ -215,8 +215,7 @@ class NovaServersTestCase(test.TestCase):
scenario.sleep_between.assert_called_once_with(10, 20)
scenario._delete_server.assert_called_once_with(fake_server)
def _prepare_boot(self, mock_osclients, mock_choice=None, nic=None,
assert_nic=False):
def _prepare_boot(self, mock_osclients, nic=None, assert_nic=False):
fake_server = mock.MagicMock()
fc = fakes.FakeClients()
@@ -239,7 +238,6 @@ class NovaServersTestCase(test.TestCase):
kwargs['nics'] = nic
if assert_nic:
nova.networks.create('net-1')
mock_choice.return_value = nova.networks.create('net-2')
expected_kwargs['nics'] = nic or [{'net-id': 'net-2'}]
print(kwargs)
@@ -247,16 +245,13 @@ class NovaServersTestCase(test.TestCase):
return scenario, kwargs, expected_kwargs
@mock.patch("rally.benchmark.scenarios.nova.servers.random.choice")
def _verify_boot_server(self, mock_choice, mock_osclients, nic=None,
assert_nic=False):
def _verify_boot_server(self, mock_osclients, nic=None, assert_nic=False):
scenario, kwargs, expected_kwargs = self._prepare_boot(
mock_osclients=mock_osclients,
mock_choice=mock_choice,
nic=nic, assert_nic=assert_nic)
scenario.boot_server("img", 0, **kwargs)
scenario._boot_server.assert_called_once_with("name", "img", 0,
scenario._boot_server.assert_called_once_with("name", "img", 0, False,
**expected_kwargs)
@mock.patch("rally.benchmark.scenarios.nova.servers.NovaServers.clients")
@@ -271,35 +266,6 @@ class NovaServersTestCase(test.TestCase):
self._verify_boot_server(mock_osclients=mock_osclients,
nic=[{'net-id': 'net-1'}], assert_nic=True)
@mock.patch("rally.benchmark.scenarios.nova.servers.NovaServers.clients")
@mock.patch("rally.benchmark.runners.base.osclients")
def test_boot_server_random_nic(self, mock_osclients, mock_nova_clients):
self._verify_boot_server(mock_osclients=mock_osclients, nic=None,
assert_nic=True)
@mock.patch("rally.benchmark.scenarios.nova.servers.NovaServers.clients")
@mock.patch("rally.benchmark.runners.base.osclients")
@mock.patch("rally.benchmark.scenarios.nova.servers.random.choice")
def test_boot_server_from_volume_random_nic(self, mock_choice,
mock_osclients,
mock_nova_clients):
scenario, kwargs, expected_kwargs = self._prepare_boot(
mock_osclients=mock_osclients,
mock_choice=mock_choice,
nic=None, assert_nic=True)
fake_volume = fakes.FakeVolumeManager().create()
fake_volume.id = "volume_id"
scenario._create_volume = mock.MagicMock(return_value=fake_volume)
scenario.boot_server_from_volume("img", 0, 5, **kwargs)
scenario._create_volume.assert_called_once_with(5, imageRef="img")
scenario._boot_server.assert_called_once_with(
"name", "img", 0,
block_device_mapping={"vda": "volume_id:::1"},
**expected_kwargs)
def test_snapshot_server(self):
fake_server = object()
fake_image = fakes.FakeImageManager()._create()

View File

@@ -126,7 +126,8 @@ class NovaScenarioTestCase(test.TestCase):
mock_clients("nova").networks.list.return_value = networks
nova_scenario = utils.NovaScenario(context={})
return_server = nova_scenario._boot_server('server_name', 'image_id',
'flavor_id')
'flavor_id',
auto_assign_nic=True)
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval,
@@ -136,6 +137,15 @@ class NovaScenarioTestCase(test.TestCase):
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.boot_server')
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
def test__boot_server_with_network_exception(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server
mock_clients("nova").networks.list.return_value = None
nova_scenario = utils.NovaScenario(context={})
self.assertRaises(TypeError, nova_scenario._boot_server,
'server_name', 'image_id', 'flavor_id',
auto_assign_nic=True)
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
def test__boot_server_with_ssh(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server