diff --git a/openstackclient/network/v2/network_agent.py b/openstackclient/network/v2/network_agent.py index ed4970a488..ba2a2633ba 100644 --- a/openstackclient/network/v2/network_agent.py +++ b/openstackclient/network/v2/network_agent.py @@ -134,8 +134,7 @@ class DeleteNetworkAgent(command.Command): for agent in parsed_args.network_agent: try: - obj = client.get_agent(agent, ignore_missing=False) - client.delete_agent(obj) + client.delete_agent(agent, ignore_missing=False) except Exception as e: result += 1 LOG.error(_("Failed to delete network agent with " diff --git a/openstackclient/tests/unit/network/v2/test_network_agent.py b/openstackclient/tests/unit/network/v2/test_network_agent.py index 12e40cdbc8..709fb1c6cd 100644 --- a/openstackclient/tests/unit/network/v2/test_network_agent.py +++ b/openstackclient/tests/unit/network/v2/test_network_agent.py @@ -121,10 +121,6 @@ class TestDeleteNetworkAgent(TestNetworkAgent): def setUp(self): super(TestDeleteNetworkAgent, self).setUp() self.network.delete_agent = mock.Mock(return_value=None) - self.network.get_agent = ( - network_fakes.FakeNetworkAgent.get_network_agents( - agents=self.network_agents) - ) # Get the command object to test self.cmd = network_agent.DeleteNetworkAgent(self.app, self.namespace) @@ -140,10 +136,8 @@ class TestDeleteNetworkAgent(TestNetworkAgent): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.network.get_agent.assert_called_once_with( - self.network_agents[0].id, ignore_missing=False) self.network.delete_agent.assert_called_once_with( - self.network_agents[0]) + self.network_agents[0].id, ignore_missing=False) self.assertIsNone(result) def test_multi_network_agents_delete(self): @@ -160,7 +154,7 @@ class TestDeleteNetworkAgent(TestNetworkAgent): calls = [] for n in self.network_agents: - calls.append(call(n)) + calls.append(call(n.id, ignore_missing=False)) self.network.delete_agent.assert_has_calls(calls) self.assertIsNone(result) @@ -175,9 +169,9 @@ class TestDeleteNetworkAgent(TestNetworkAgent): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - find_mock_result = [self.network_agents[0], exceptions.CommandError] - self.network.get_agent = ( - mock.Mock(side_effect=find_mock_result) + delete_mock_result = [True, exceptions.CommandError] + self.network.delete_agent = ( + mock.Mock(side_effect=delete_mock_result) ) try: @@ -186,13 +180,10 @@ class TestDeleteNetworkAgent(TestNetworkAgent): except exceptions.CommandError as e: self.assertEqual('1 of 2 network agents failed to delete.', str(e)) - self.network.get_agent.assert_any_call( + self.network.delete_agent.assert_any_call( self.network_agents[0].id, ignore_missing=False) - self.network.get_agent.assert_any_call( + self.network.delete_agent.assert_any_call( 'unexist_network_agent', ignore_missing=False) - self.network.delete_agent.assert_called_once_with( - self.network_agents[0] - ) class TestListNetworkAgent(TestNetworkAgent):