Merge "Fix nested atomic action in VMTask scenario"

This commit is contained in:
Jenkins 2015-10-12 22:58:29 +00:00 committed by Gerrit Code Review
commit 11ba63cec7
4 changed files with 55 additions and 20 deletions

View File

@ -551,37 +551,56 @@ class NovaScenario(scenario.OpenStackScenario):
) for server in servers]
return servers
@atomic.action_timer("nova.associate_floating_ip")
def _associate_floating_ip(self, server, address, fixed_address=None):
def _associate_floating_ip(self, server, address, fixed_address=None,
atomic_action=True):
"""Add floating IP to an instance
:param server: The :class:`Server` to add an IP to.
:param address: The ip address or FloatingIP to add to the instance
:param fixed_address: The fixedIP address the FloatingIP is to be
associated with (optional)
:param atomic_action: True if this is an atomic action (optional)
"""
server.add_floating_ip(address, fixed_address=fixed_address)
utils.wait_for(
server,
is_ready=self.check_ip_address(address),
update_resource=utils.get_from_manager()
)
if atomic_action:
with atomic.ActionTimer(self, "nova.associate_floating_ip"):
server.add_floating_ip(address, fixed_address=fixed_address)
utils.wait_for(
server,
is_ready=self.check_ip_address(address),
update_resource=utils.get_from_manager()
)
else:
server.add_floating_ip(address, fixed_address=fixed_address)
utils.wait_for(
server,
is_ready=self.check_ip_address(address),
update_resource=utils.get_from_manager()
)
# Update server data
server.addresses = server.manager.get(server.id).addresses
@atomic.action_timer("nova.dissociate_floating_ip")
def _dissociate_floating_ip(self, server, address):
def _dissociate_floating_ip(self, server, address, atomic_action=True):
"""Remove floating IP from an instance
:param server: The :class:`Server` to add an IP to.
:param address: The ip address or FloatingIP to remove
:param atomic_action: True if this is an atomic action (optional)
"""
server.remove_floating_ip(address)
utils.wait_for(
server,
is_ready=self.check_ip_address(address, must_exist=False),
update_resource=utils.get_from_manager()
)
if atomic_action:
with atomic.ActionTimer(self, "nova.dissociate_floating_ip"):
server.remove_floating_ip(address)
utils.wait_for(
server,
is_ready=self.check_ip_address(address, must_exist=False),
update_resource=utils.get_from_manager()
)
else:
server.remove_floating_ip(address)
utils.wait_for(
server,
is_ready=self.check_ip_address(address, must_exist=False),
update_resource=utils.get_from_manager()
)
# Update server data
server.addresses = server.manager.get(server.id).addresses

View File

@ -133,7 +133,8 @@ class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario):
ext_network=floating_network,
tenant_id=server.tenant_id, fixed_ip=fixed_ip)
self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip)
self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip,
atomic_action=False)
return fip
@ -142,7 +143,8 @@ class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario):
with logging.ExceptionLogger(
LOG, _("Unable to delete IP: %s") % fip["ip"]):
if self.check_ip_address(fip["ip"])(server):
self._dissociate_floating_ip(server, fip["ip"])
self._dissociate_floating_ip(server, fip["ip"],
atomic_action=False)
network_wrapper.wrap(
self.clients, self.context["task"]).delete_floating_ip(
fip["id"],

View File

@ -499,6 +499,13 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.associate_floating_ip")
def test__associate_floating_ip_with_no_atomic_action(self):
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario._associate_floating_ip(self.server, self.floating_ip,
atomic_action=False)
self.server.add_floating_ip.assert_called_once_with(self.floating_ip,
fixed_address=None)
def test__dissociate_floating_ip(self):
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario._dissociate_floating_ip(self.server, self.floating_ip)
@ -507,6 +514,13 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.dissociate_floating_ip")
def test__dissociate_floating_ip_with_no_atomic_action(self):
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario._dissociate_floating_ip(self.server, self.floating_ip,
atomic_action=False)
self.server.remove_floating_ip.assert_called_once_with(
self.floating_ip)
def test__check_ip_address(self):
nova_scenario = utils.NovaScenario(context=self.context)
fake_server = fakes.FakeServerManager().create("test_server",

View File

@ -288,7 +288,7 @@ class VMScenarioTestCase(test.ScenarioTestCase):
tenant_id="foo_tenant", fixed_ip="foo_ip")
scenario._associate_floating_ip.assert_called_once_with(
server, "foo_ip", fixed_address="foo_ip")
server, "foo_ip", fixed_address="foo_ip", atomic_action=False)
@mock.patch(VMTASKS_UTILS + ".network_wrapper.wrap")
def test__delete_floating_ip(self, mock_wrap):
@ -305,7 +305,7 @@ class VMScenarioTestCase(test.ScenarioTestCase):
"foo_ip")
_check_addr.assert_called_once_with(server)
scenario._dissociate_floating_ip.assert_called_once_with(
server, "foo_ip")
server, "foo_ip", atomic_action=False)
mock_wrap.assert_called_once_with(scenario.clients,
self.context["task"])
mock_wrap.return_value.delete_floating_ip.assert_called_once_with(