Support to boot server with net name
it can not specify the net id while creating net in neturon, so we may be known the net name but not net id. Also, if we want to trend the reports, it is hard to keep the same net id. Change-Id: Ibeda5db86dcd0cb1c71569c1d7280227de1f8b95
This commit is contained in:
parent
13c21f2972
commit
b093524d6b
@ -47,7 +47,18 @@ class NovaScenario(scenario.OpenStackScenario):
|
||||
net_idx = self.context["iteration"] % len(nets)
|
||||
return [{"net-id": nets[net_idx]}]
|
||||
|
||||
@atomic.action_timer("nova.boot_server")
|
||||
def _get_network_id(self, net_name):
|
||||
networks = getattr(self, "existed_networks", [])
|
||||
if not networks:
|
||||
networks = self.clients("neutron").list_networks()["networks"]
|
||||
self.existed_networks = networks
|
||||
|
||||
for net in networks:
|
||||
if net["name"] == net_name:
|
||||
return net["id"]
|
||||
raise exceptions.NotFoundException(
|
||||
message="Network %s not found." % net_name)
|
||||
|
||||
def _boot_server(self, image, flavor,
|
||||
auto_assign_nic=False, **kwargs):
|
||||
"""Boot a server.
|
||||
@ -82,17 +93,22 @@ class NovaScenario(scenario.OpenStackScenario):
|
||||
kwargs["nics"] = [
|
||||
{"net-id": self.context["tenant"]["networks"][0]["id"]}]
|
||||
|
||||
server = self.clients("nova").servers.create(
|
||||
server_name, image, flavor, **kwargs)
|
||||
for nic in kwargs.get("nics", []):
|
||||
if not nic.get("net-id") and nic.get("net-name"):
|
||||
nic["net-id"] = self._get_network_id(nic["net-name"])
|
||||
|
||||
self.sleep_between(CONF.openstack.nova_server_boot_prepoll_delay)
|
||||
server = utils.wait_for_status(
|
||||
server,
|
||||
ready_statuses=["ACTIVE"],
|
||||
update_resource=utils.get_from_manager(),
|
||||
timeout=CONF.openstack.nova_server_boot_timeout,
|
||||
check_interval=CONF.openstack.nova_server_boot_poll_interval
|
||||
)
|
||||
with atomic.ActionTimer(self, "nova.boot_server"):
|
||||
server = self.clients("nova").servers.create(
|
||||
server_name, image, flavor, **kwargs)
|
||||
|
||||
self.sleep_between(CONF.openstack.nova_server_boot_prepoll_delay)
|
||||
server = utils.wait_for_status(
|
||||
server,
|
||||
ready_statuses=["ACTIVE"],
|
||||
update_resource=utils.get_from_manager(),
|
||||
timeout=CONF.openstack.nova_server_boot_timeout,
|
||||
check_interval=CONF.openstack.nova_server_boot_poll_interval
|
||||
)
|
||||
return server
|
||||
|
||||
def _do_server_reboot(self, server, reboottype):
|
||||
@ -557,7 +573,6 @@ class NovaScenario(scenario.OpenStackScenario):
|
||||
"""
|
||||
self.clients("nova").keypairs.delete(keypair_name)
|
||||
|
||||
@atomic.action_timer("nova.boot_servers")
|
||||
def _boot_servers(self, image_id, flavor_id, requests, instances_amount=1,
|
||||
auto_assign_nic=False, **kwargs):
|
||||
"""Boot multiple servers.
|
||||
@ -579,27 +594,33 @@ class NovaScenario(scenario.OpenStackScenario):
|
||||
if nic:
|
||||
kwargs["nics"] = nic
|
||||
|
||||
for nic in kwargs.get("nics", []):
|
||||
if not nic.get("net-id") and nic.get("net-name"):
|
||||
nic["net-id"] = self._get_network_id(nic["net-name"])
|
||||
|
||||
name_prefix = self.generate_random_name()
|
||||
for i in range(requests):
|
||||
self.clients("nova").servers.create("%s_%d" % (name_prefix, i),
|
||||
image_id, flavor_id,
|
||||
min_count=instances_amount,
|
||||
max_count=instances_amount,
|
||||
**kwargs)
|
||||
# NOTE(msdubov): Nova python client returns only one server even when
|
||||
# min_count > 1, so we have to rediscover all the
|
||||
# created servers manually.
|
||||
servers = [s for s in self.clients("nova").servers.list()
|
||||
if s.name.startswith(name_prefix)]
|
||||
self.sleep_between(CONF.openstack.nova_server_boot_prepoll_delay)
|
||||
servers = [utils.wait_for_status(
|
||||
server,
|
||||
ready_statuses=["ACTIVE"],
|
||||
update_resource=utils.
|
||||
get_from_manager(),
|
||||
timeout=CONF.openstack.nova_server_boot_timeout,
|
||||
check_interval=CONF.openstack.nova_server_boot_poll_interval
|
||||
) for server in servers]
|
||||
with atomic.ActionTimer(self, "nova.boot_servers"):
|
||||
for i in range(requests):
|
||||
self.clients("nova").servers.create(
|
||||
"%s_%d" % (name_prefix, i),
|
||||
image_id, flavor_id,
|
||||
min_count=instances_amount,
|
||||
max_count=instances_amount,
|
||||
**kwargs)
|
||||
# NOTE(msdubov): Nova python client returns only one server even
|
||||
# when min_count > 1, so we have to rediscover
|
||||
# all the created servers manually.
|
||||
servers = [s for s in self.clients("nova").servers.list()
|
||||
if s.name.startswith(name_prefix)]
|
||||
self.sleep_between(CONF.openstack.nova_server_boot_prepoll_delay)
|
||||
servers = [utils.wait_for_status(
|
||||
server,
|
||||
ready_statuses=["ACTIVE"],
|
||||
update_resource=utils.
|
||||
get_from_manager(),
|
||||
timeout=CONF.openstack.nova_server_boot_timeout,
|
||||
check_interval=CONF.openstack.nova_server_boot_poll_interval
|
||||
) for server in servers]
|
||||
return servers
|
||||
|
||||
@atomic.action_timer("nova.associate_floating_ip")
|
||||
|
@ -76,6 +76,17 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
||||
# balance again, get net 1
|
||||
self.assertEqual(nic3, [{"net-id": "net_id_1"}])
|
||||
|
||||
def test__get_network_id(self):
|
||||
networks = {"networks": [{"name": "foo1", "id": 1},
|
||||
{"name": "foo2", "id": 2}]}
|
||||
self.clients("neutron").list_networks.return_value = networks
|
||||
scenario = utils.NovaScenario(self.context)
|
||||
self.assertEqual(1, scenario._get_network_id("foo1"))
|
||||
self.assertEqual(2, scenario._get_network_id("foo2"))
|
||||
self.clients("neutron").list_networks.assert_called_once_with()
|
||||
self.assertRaises(rally_exceptions.NotFoundException,
|
||||
scenario._get_network_id, "foo")
|
||||
|
||||
@ddt.data(
|
||||
{},
|
||||
{"kwargs": {"auto_assign_nic": True}},
|
||||
@ -85,6 +96,8 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
||||
"kwargs": {"security_groups": ["test8"]}},
|
||||
{"context": {"user": {"secgroup": {"name": "test1"}}},
|
||||
"kwargs": {"security_groups": ["test1"]}},
|
||||
{"kwargs": {"auto_assign_nic": False,
|
||||
"nics": [{"net-name": "foo_name"}]}}
|
||||
)
|
||||
@ddt.unpack
|
||||
def test__boot_server(self, context=None, kwargs=None):
|
||||
@ -98,7 +111,10 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
||||
|
||||
nova_scenario = utils.NovaScenario(context=context)
|
||||
nova_scenario.generate_random_name = mock.Mock()
|
||||
nova_scenario._pick_random_nic = mock.Mock()
|
||||
nova_scenario._pick_random_nic = mock.Mock(
|
||||
return_value=[{"net-id": "foo"}])
|
||||
nova_scenario._get_network_id = mock.Mock(return_value="foo")
|
||||
|
||||
if kwargs is None:
|
||||
kwargs = {}
|
||||
kwargs["fakearg"] = "fakearg"
|
||||
@ -442,7 +458,8 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
||||
{"requests": 2, "instances_amount": 100, "auto_assign_nic": True,
|
||||
"fakearg": "fake"},
|
||||
{"auto_assign_nic": True, "nics": [{"net-id": "foo"}]},
|
||||
{"auto_assign_nic": False, "nics": [{"net-id": "foo"}]})
|
||||
{"auto_assign_nic": False, "nics": [{"net-id": "foo"}]},
|
||||
{"auto_assign_nic": False, "nics": [{"net-name": "foo_name"}]})
|
||||
@ddt.unpack
|
||||
def test__boot_servers(self, image_id="image", flavor_id="flavor",
|
||||
requests=1, instances_amount=1,
|
||||
@ -451,7 +468,9 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
||||
self.clients("nova").servers.list.return_value = servers
|
||||
scenario = utils.NovaScenario(context=self.context)
|
||||
scenario.generate_random_name = mock.Mock()
|
||||
scenario._pick_random_nic = mock.Mock()
|
||||
scenario._pick_random_nic = mock.Mock(
|
||||
return_value=[{"net-id": "foo"}])
|
||||
scenario._get_network_id = mock.Mock(return_value="foo")
|
||||
|
||||
scenario._boot_servers(image_id, flavor_id, requests,
|
||||
instances_amount=instances_amount,
|
||||
|
Loading…
x
Reference in New Issue
Block a user