-
-
Save rmk40/2e5c56cddce1c6ed3bbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/rally/benchmark/scenarios/nova/servers.py b/rally/benchmark/scenarios/nova/servers.py | |
index f4dbcb9..14b64bc 100644 | |
--- a/rally/benchmark/scenarios/nova/servers.py | |
+++ b/rally/benchmark/scenarios/nova/servers.py | |
@@ -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 as scenario_base | |
@@ -142,33 +140,24 @@ class NovaServers(utils.NovaScenario, | |
@validation.add(validation.image_valid_on_flavor("flavor", "image")) | |
@scenario_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")) | |
@scenario_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) | |
diff --git a/rally/benchmark/scenarios/nova/utils.py b/rally/benchmark/scenarios/nova/utils.py | |
index c2e83ad..cd2c6ab 100644 | |
--- a/rally/benchmark/scenarios/nova/utils.py | |
+++ b/rally/benchmark/scenarios/nova/utils.py | |
@@ -74,7 +74,8 @@ class NovaScenario(scenario_base.Scenario): | |
return self.clients("nova").servers.list(detailed) | |
@scenario_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" | |
@@ -97,15 +98,19 @@ class NovaScenario(scenario_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) | |
diff --git a/tests/benchmark/scenarios/nova/test_servers.py b/tests/benchmark/scenarios/nova/test_servers.py | |
index 74fb866..4f575c9 100644 | |
--- a/tests/benchmark/scenarios/nova/test_servers.py | |
+++ b/tests/benchmark/scenarios/nova/test_servers.py | |
@@ -14,6 +14,7 @@ | |
# under the License. | |
import mock | |
+import random | |
from rally.benchmark.scenarios.nova import servers | |
from rally import exceptions as rally_exceptions | |
@@ -247,7 +248,7 @@ class NovaServersTestCase(test.TestCase): | |
return scenario, kwargs, expected_kwargs | |
- @mock.patch("rally.benchmark.scenarios.nova.servers.random.choice") | |
+ @mock.patch("random.choice") | |
def _verify_boot_server(self, mock_choice, mock_osclients, nic=None, | |
assert_nic=False): | |
scenario, kwargs, expected_kwargs = self._prepare_boot( | |
@@ -256,7 +257,7 @@ class NovaServersTestCase(test.TestCase): | |
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 +272,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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment