From 90d241f19c0ff2d28aaeddd89c3d1cc26334d17c Mon Sep 17 00:00:00 2001 From: Yuki Nishiwaki Date: Mon, 12 Oct 2015 14:25:23 +0900 Subject: [PATCH] Fix nested atomic action in VMTask scenario In VMTask scenario, There are nested atomic actions. - vm.attach_floating_ip - nova.associate_floating_ip - vm.delete_floating_ip - nova.dissociate_floating_ip But atomic actions should be removed. So This patch fixed for nested atomic actions by disabling atomic aciton in nova.XX_floating_ip. Change-Id: I3c0e31c77c3181d8403c1a5570c78d2c7e9e5cf9 Closes-Bug: #1505074 --- .../plugins/openstack/scenarios/nova/utils.py | 51 +++++++++++++------ rally/plugins/openstack/scenarios/vm/utils.py | 6 ++- .../openstack/scenarios/nova/test_utils.py | 14 +++++ .../openstack/scenarios/vm/test_utils.py | 4 +- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index 5b774919..3b881cc7 100644 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -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 diff --git a/rally/plugins/openstack/scenarios/vm/utils.py b/rally/plugins/openstack/scenarios/vm/utils.py index d18c56fa..4eda1496 100644 --- a/rally/plugins/openstack/scenarios/vm/utils.py +++ b/rally/plugins/openstack/scenarios/vm/utils.py @@ -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"], diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py index 49cc8a78..97421725 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_utils.py @@ -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", diff --git a/tests/unit/plugins/openstack/scenarios/vm/test_utils.py b/tests/unit/plugins/openstack/scenarios/vm/test_utils.py index 0c9ad691..f57861c4 100644 --- a/tests/unit/plugins/openstack/scenarios/vm/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/vm/test_utils.py @@ -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(