diff --git a/neutronclient/osc/utils.py b/neutronclient/osc/utils.py index 413ad607c..39b17b640 100644 --- a/neutronclient/osc/utils.py +++ b/neutronclient/osc/utils.py @@ -118,3 +118,13 @@ def _find_identity_resource(identity_client_manager, name_or_id, # The above are borrowed from openstackclient.identity.common. # DO NOT ADD original methods in neutronclient repo to the above area. + + +def _get_columns(item): + column_map = {} + hidden_columns = ['location', 'tenant_id'] + return utils.get_osc_show_columns_for_sdk_resource( + item, + column_map, + hidden_columns + ) diff --git a/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py b/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py index 025022996..4af2008fe 100644 --- a/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py +++ b/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py @@ -15,7 +15,6 @@ from osc_lib.command import command from osc_lib import utils from neutronclient._i18n import _ -from neutronclient.osc.v2.dynamic_routing import constants def _format_alive_state(item): @@ -45,11 +44,9 @@ class AddBgpSpeakerToDRAgent(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - client.add_bgp_speaker_to_dragent( - parsed_args.dragent_id, {'bgp_speaker_id': speaker_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id + client.add_bgp_speaker_to_dragent(parsed_args.dragent_id, speaker_id) class RemoveBgpSpeakerFromDRAgent(command.Command): @@ -62,9 +59,8 @@ class RemoveBgpSpeakerFromDRAgent(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id client.remove_bgp_speaker_from_dragent(parsed_args.dragent_id, speaker_id) @@ -92,18 +88,30 @@ class ListDRAgentsHostingBgpSpeaker(command.Lister): return parser def take_action(self, parsed_args): - search_opts = {} - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - search_opts['bgp_speaker'] = speaker_id - data = client.list_dragents_hosting_bgp_speaker(**search_opts) - headers = ('ID', 'Host', 'State', 'Alive') - columns = ('id', 'host', 'admin_state_up', 'alive') - return (headers, - (utils.get_dict_properties( - s, columns, formatters=_formatters, - ) for s in data['agents'])) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id + data = client.get_bgp_dragents_hosting_speaker(speaker_id) + columns = ( + 'id', + 'agent_type', + 'host', + 'availability_zone', + 'is_alive', + 'is_admin_state_up', + 'binary' + ) + column_headers = ( + 'ID', + 'Agent Type', + 'Host', + 'Availability Zone', + 'Alive', + 'State', + 'Binary' + ) + return (column_headers, + (utils.get_item_properties( + s, columns,) for s in data)) class ListDRAgent(command.Lister): @@ -123,20 +131,31 @@ class ListDRAgent(command.Lister): return parser def take_action(self, parsed_args): - search_opts = {} - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network if parsed_args.bgp_speaker is not None: - search_opts = {} - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - search_opts['bgp_speaker'] = speaker_id - data = client.list_dragents_hosting_bgp_speaker(**search_opts) + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id + data = client.get_bgp_dragents_hosting_speaker(speaker_id) else: attrs = {'agent_type': 'BGP dynamic routing agent'} - data = client.list_agents(**attrs) - headers = ('ID', 'Host', 'State', 'Alive') - columns = ('id', 'host', 'admin_state_up', 'alive') - return (headers, - (utils.get_dict_properties( - s, columns, formatters=_formatters, - ) for s in data['agents'])) + data = client.agents(**attrs) + columns = ( + 'id', + 'agent_type', + 'host', + 'availability_zone', + 'is_alive', + 'is_admin_state_up', + 'binary' + ) + column_headers = ( + 'ID', + 'Agent Type', + 'Host', + 'Availability Zone', + 'Alive', + 'State', + 'Binary' + ) + return (column_headers, + (utils.get_item_properties( + s, columns,) for s in data)) diff --git a/neutronclient/osc/v2/dynamic_routing/bgp_peer.py b/neutronclient/osc/v2/dynamic_routing/bgp_peer.py index c8e602ebb..0610a3ac0 100644 --- a/neutronclient/osc/v2/dynamic_routing/bgp_peer.py +++ b/neutronclient/osc/v2/dynamic_routing/bgp_peer.py @@ -13,7 +13,6 @@ from osc_lib.command import command from osc_lib import utils -from osc_lib.utils import columns as column_util from neutronclient._i18n import _ from neutronclient.common import exceptions @@ -96,11 +95,10 @@ class CreateBgpPeer(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {constants.BGP_PEER: attrs} - obj = client.create_bgp_peer(body)[constants.BGP_PEER] - columns, display_columns = column_util.get_columns(obj) + obj = client.create_bgp_peer(**attrs) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data @@ -118,9 +116,8 @@ class DeleteBgpPeer(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] + client = self.app.client_manager.network + id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] client.delete_bgp_peer(id) @@ -128,13 +125,11 @@ class ListBgpPeer(command.Lister): _description = _("List BGP peers") def take_action(self, parsed_args): - data = self.app.client_manager.neutronclient.list_bgp_peers() + data = self.app.client_manager.network.bgp_peers(retrieve_all=True) headers = ('ID', 'Name', 'Peer IP', 'Remote AS') columns = ('id', 'name', 'peer_ip', 'remote_as') return (headers, - (utils.get_dict_properties( - s, columns, - ) for s in data[constants.BGP_PEERS])) + (utils.get_dict_properties(s, columns,) for s in data)) class SetBgpPeer(command.Command): @@ -158,13 +153,10 @@ class SetBgpPeer(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] + client = self.app.client_manager.network + id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {} - body[constants.BGP_PEER] = attrs - client.update_bgp_peer(id, body) + client.update_bgp_peer(id, **attrs) class ShowBgpPeer(command.ShowOne): @@ -180,10 +172,10 @@ class ShowBgpPeer(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] - obj = client.show_bgp_peer(id)[constants.BGP_PEER] - columns, display_columns = column_util.get_columns(obj) + client = self.app.client_manager.network + id = client.find_bgp_peer(parsed_args.bgp_peer, + ignore_missing=False).id + obj = client.get_bgp_peer(id) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data diff --git a/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py b/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py index 171d7f45f..76d8340b9 100644 --- a/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py +++ b/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py @@ -13,7 +13,6 @@ from osc_lib.command import command from osc_lib import utils -from osc_lib.utils import columns as column_util from neutronclient._i18n import _ from neutronclient.osc import utils as nc_osc_utils @@ -87,12 +86,12 @@ class AddNetworkToSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - net_id = client.find_resource('network', - parsed_args.network)['id'] - client.add_network_to_bgp_speaker(speaker_id, {'network_id': net_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker, + ignore_missing=False).id + net_id = client.find_network(parsed_args.network, + ignore_missing=False).id + client.add_gateway_network_to_speaker(speaker_id, net_id) class AddPeerToSpeaker(command.Command): @@ -111,12 +110,10 @@ class AddPeerToSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - peer_id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] - client.add_peer_to_bgp_speaker(speaker_id, {'bgp_peer_id': peer_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + peer_id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] + client.add_bgp_peer_to_speaker(speaker_id, peer_id) class CreateBgpSpeaker(command.ShowOne): @@ -145,12 +142,10 @@ class CreateBgpSpeaker(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {} - body[constants.BGP_SPEAKER] = attrs - obj = client.create_bgp_speaker(body)[constants.BGP_SPEAKER] - columns, display_columns = column_util.get_columns(obj) + obj = client.create_bgp_speaker(**attrs) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data @@ -168,9 +163,8 @@ class DeleteBgpSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] + client = self.app.client_manager.network + id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] client.delete_bgp_speaker(id) @@ -186,16 +180,16 @@ class ListBgpSpeaker(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network if parsed_args.agent is not None: - data = client.list_bgp_speaker_on_dragent(parsed_args.agent) + data = client.get_bgp_speakers_hosted_by_dragent(parsed_args.agent) else: - data = client.list_bgp_speakers() + data = client.bgp_speakers(retrieve_all=True) headers = ('ID', 'Name', 'Local AS', 'IP Version') columns = ('id', 'name', 'local_as', 'ip_version') return (headers, (utils.get_dict_properties(s, columns) - for s in data[constants.BGP_SPEAKERS])) + for s in data)) class ListRoutesAdvertisedBySpeaker(command.Lister): @@ -211,10 +205,9 @@ class ListRoutesAdvertisedBySpeaker(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - data = client.list_route_advertised_from_bgp_speaker(speaker_id) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + data = client.get_advertised_routes_of_speaker(speaker_id) headers = ('Destination', 'Nexthop') columns = ('destination', 'next_hop') return (headers, (utils.get_dict_properties(s, columns) @@ -237,13 +230,10 @@ class RemoveNetworkFromSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - net_id = client.find_resource('network', - parsed_args.network)['id'] - client.remove_network_from_bgp_speaker(speaker_id, - {'network_id': net_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + net_id = client.find_network(parsed_args.network)['id'] + client.remove_gateway_network_from_speaker(speaker_id, net_id) class RemovePeerFromSpeaker(command.Command): @@ -262,13 +252,10 @@ class RemovePeerFromSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - peer_id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] - client.remove_peer_from_bgp_speaker(speaker_id, - {'bgp_peer_id': peer_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + peer_id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] + client.remove_bgp_peer_from_speaker(speaker_id, peer_id) class SetBgpSpeaker(command.Command): @@ -290,13 +277,10 @@ class SetBgpSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] + client = self.app.client_manager.network + id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {} - body[constants.BGP_SPEAKER] = attrs - client.update_bgp_speaker(id, body) + client.update_bgp_speaker(id, **attrs) class ShowBgpSpeaker(command.ShowOne): @@ -312,10 +296,10 @@ class ShowBgpSpeaker(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - obj = client.show_bgp_speaker(id)[constants.BGP_SPEAKER] - columns, display_columns = column_util.get_columns(obj) + client = self.app.client_manager.network + id = client.find_bgp_speaker(parsed_args.bgp_speaker, + ignore_missing=False).id + obj = client.get_bgp_speaker(id) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data diff --git a/neutronclient/tests/unit/osc/v2/dynamic_routing/fakes.py b/neutronclient/tests/unit/osc/v2/dynamic_routing/fakes.py index c496a3f66..188f06871 100644 --- a/neutronclient/tests/unit/osc/v2/dynamic_routing/fakes.py +++ b/neutronclient/tests/unit/osc/v2/dynamic_routing/fakes.py @@ -10,10 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. -import copy from unittest import mock import uuid +from openstack.network.v2 import agent as _agent +from openstack.network.v2 import bgp_peer as _bgp_peer +from openstack.network.v2 import bgp_speaker as _bgp_speaker from neutronclient.tests.unit.osc.v2 import fakes @@ -26,6 +28,17 @@ class TestNeutronDynamicRoutingOSCV2(fakes.TestNeutronClientOSCV2): cmd_resource=None, parent_id=None, fields=None: {'id': name_or_id}) + self.networkclient.find_bgp_speaker = mock.Mock( + side_effect=lambda name_or_id, project_id=None, + cmd_resource=None, parent_id=None, fields=None, + ignore_missing=False: + _bgp_speaker.BgpSpeaker(id=name_or_id)) + self.networkclient.find_bgp_peer = mock.Mock( + side_effect=lambda name_or_id, project_id=None, + cmd_resource=None, parent_id=None, fields=None, + ignore_missing=False: + _bgp_peer.BgpPeer(id=name_or_id)) + class FakeBgpSpeaker(object): """Fake one or more bgp speakers.""" @@ -48,8 +61,9 @@ class FakeBgpSpeaker(object): # Overwrite default attributes. bgp_speaker_attrs.update(attrs) + ret_bgp_speaker = _bgp_speaker.BgpSpeaker(**bgp_speaker_attrs) - return copy.deepcopy(bgp_speaker_attrs) + return ret_bgp_speaker @staticmethod def create_bgp_speakers(attrs=None, count=1): @@ -61,7 +75,7 @@ class FakeBgpSpeaker(object): bgp_speaker = FakeBgpSpeaker.create_one_bgp_speaker(attrs) bgp_speakers.append(bgp_speaker) - return {'bgp_speakers': bgp_speakers} + return bgp_speakers class FakeBgpPeer(object): @@ -82,8 +96,9 @@ class FakeBgpPeer(object): # Overwrite default attributes. bgp_peer_attrs.update(attrs) + ret_bgp_peer = _bgp_peer.BgpPeer(**bgp_peer_attrs) - return copy.deepcopy(bgp_peer_attrs) + return ret_bgp_peer @staticmethod def create_bgp_peers(attrs=None, count=1): @@ -93,7 +108,7 @@ class FakeBgpPeer(object): bgp_peer = FakeBgpPeer.create_one_bgp_peer(attrs) bgp_peers.append(bgp_peer) - return {'bgp_peers': bgp_peers} + return bgp_peers class FakeDRAgent(object): @@ -106,6 +121,7 @@ class FakeDRAgent(object): dragent_attrs = { 'binary': 'neutron-bgp-dragent', 'admin_state_up': True, + 'availability_zone': None, 'alive': True, 'topic': 'bgp_dragent', 'host': 'network-' + uuid.uuid4().hex, @@ -116,8 +132,7 @@ class FakeDRAgent(object): # Overwrite default attributes. dragent_attrs.update(attrs) - - return copy.deepcopy(dragent_attrs) + return _agent.Agent(**dragent_attrs) @staticmethod def create_dragents(attrs=None, count=1): @@ -127,4 +142,4 @@ class FakeDRAgent(object): agent = FakeDRAgent.create_one_dragent(attrs) agents.append(agent) - return {'agents': agents} + return agents diff --git a/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_dragent.py b/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_dragent.py index 7a94b323a..89ba20d93 100644 --- a/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_dragent.py +++ b/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_dragent.py @@ -39,15 +39,14 @@ class TestAddBgpSpeakerToDRAgent(fakes.TestNeutronDynamicRoutingOSCV2): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - with mock.patch.object(self.neutronclient, + with mock.patch.object(self.networkclient, "add_bgp_speaker_to_dragent", return_value=None): result = self.cmd.take_action(parsed_args) - self.neutronclient.add_bgp_speaker_to_dragent.\ + self.networkclient.add_bgp_speaker_to_dragent.\ assert_called_once_with( - self._bgp_dragent_id, - {'bgp_speaker_id': self._bgp_speaker_id}) + self._bgp_dragent_id, self._bgp_speaker_id) self.assertIsNone(result) @@ -75,11 +74,11 @@ class TestRemoveBgpSpeakerFromDRAgent(fakes.TestNeutronDynamicRoutingOSCV2): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - with mock.patch.object(self.neutronclient, + with mock.patch.object(self.networkclient, "remove_bgp_speaker_from_dragent", return_value=None): result = self.cmd.take_action(parsed_args) - self.neutronclient.remove_bgp_speaker_from_dragent.\ + self.networkclient.remove_bgp_speaker_from_dragent.\ assert_called_once_with(self._bgp_dragent_id, self._bgp_speaker_id) self.assertIsNone(result) @@ -90,12 +89,16 @@ class TestListDRAgentsHostingBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): _bgp_speaker_id = _bgp_speaker['id'] attrs = {'bgp_speaker_id': _bgp_speaker_id} _bgp_dragents = fakes.FakeDRAgent.create_dragents(attrs) - columns = ('ID', 'Host', 'State', 'Alive') + columns = ('ID', 'Agent Type', 'Host', 'Availability Zone', + 'Alive', 'State', 'Binary') data = [(_bgp_dragent['id'], + _bgp_dragent['agent_type'], _bgp_dragent['host'], + _bgp_dragent['availability_zone'], _bgp_dragent['admin_state_up'], - ':-)' if _bgp_dragent['alive'] else 'XXX') - for _bgp_dragent in _bgp_dragents['agents']] + _bgp_dragent['alive'], + _bgp_dragent['binary'],) + for _bgp_dragent in _bgp_dragents] def setUp(self): super(TestListDRAgentsHostingBgpSpeaker, self).setUp() @@ -112,12 +115,11 @@ class TestListDRAgentsHostingBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - with mock.patch.object(self.neutronclient, - "list_dragents_hosting_bgp_speaker", + with mock.patch.object(self.networkclient, + "get_bgp_dragents_hosting_speaker", return_value=self._bgp_dragents): columns, data = self.cmd.take_action(parsed_args) - attrs = {'bgp_speaker': self._bgp_speaker_id} - self.neutronclient.list_dragents_hosting_bgp_speaker.\ - assert_called_once_with(**attrs) + self.networkclient.get_bgp_dragents_hosting_speaker.\ + assert_called_once_with(self._bgp_speaker_id) self.assertEqual(self.columns, columns) self.assertListEqual(self.data, list(data)) diff --git a/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_peer.py b/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_peer.py index 506c86d93..73b6bf7ab 100644 --- a/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_peer.py +++ b/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_peer.py @@ -20,7 +20,7 @@ class TestListBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): _bgp_peers = fakes.FakeBgpPeer.create_bgp_peers(count=1) columns = ('ID', 'Name', 'Peer IP', 'Remote AS') data = [] - for _bgp_peer in _bgp_peers['bgp_peers']: + for _bgp_peer in _bgp_peers: data.append(( _bgp_peer['id'], _bgp_peer['name'], @@ -30,7 +30,7 @@ class TestListBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): def setUp(self): super(TestListBgpPeer, self).setUp() - self.neutronclient.list_bgp_peers = mock.Mock( + self.networkclient.bgp_peers = mock.Mock( return_value=self._bgp_peers ) @@ -41,7 +41,8 @@ class TestListBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): parsed_args = self.check_parser(self.cmd, [], []) columns, data = self.cmd.take_action(parsed_args) - self.neutronclient.list_bgp_peers.assert_called_once_with() + self.networkclient.bgp_peers.assert_called_once_with( + retrieve_all=True) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) @@ -53,7 +54,7 @@ class TestDeleteBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): def setUp(self): super(TestDeleteBgpPeer, self).setUp() - self.neutronclient.delete_bgp_peer = mock.Mock(return_value=None) + self.networkclient.delete_bgp_peer = mock.Mock(return_value=None) self.cmd = bgp_peer.DeleteBgpPeer(self.app, self.namespace) @@ -68,7 +69,7 @@ class TestDeleteBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): result = self.cmd.take_action(parsed_args) - self.neutronclient.delete_bgp_peer.assert_called_once_with( + self.networkclient.delete_bgp_peer.assert_called_once_with( self._bgp_peer['name']) self.assertIsNone(result) @@ -80,31 +81,30 @@ class TestShowBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): _one_bgp_peer['id'], _one_bgp_peer['name'], _one_bgp_peer['peer_ip'], + _one_bgp_peer['tenant_id'], _one_bgp_peer['remote_as'], - _one_bgp_peer['tenant_id'] ) - _bgp_peer = {'bgp_peer': _one_bgp_peer} + _bgp_peer = _one_bgp_peer _bgp_peer_name = _one_bgp_peer['name'] columns = ( 'auth_type', 'id', 'name', 'peer_ip', + 'project_id', 'remote_as', - 'tenant_id' ) def setUp(self): super(TestShowBgpPeer, self).setUp() - self.neutronclient.show_bgp_peer = mock.Mock( + self.networkclient.get_bgp_peer = mock.Mock( return_value=self._bgp_peer ) - bgp_peer.get_bgp_peer_id = mock.Mock(return_value=self._bgp_peer_name) # Get the command object to test self.cmd = bgp_peer.ShowBgpPeer(self.app, self.namespace) - def test_bgp_peer_list(self): + def test_bgp_peer_show(self): arglist = [ self._bgp_peer_name, ] @@ -114,7 +114,7 @@ class TestShowBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): parsed_args = self.check_parser(self.cmd, arglist, verifylist) data = self.cmd.take_action(parsed_args) - self.neutronclient.show_bgp_peer.assert_called_once_with( + self.networkclient.get_bgp_peer.assert_called_once_with( self._bgp_peer_name) self.assertEqual(self.columns, data[0]) self.assertEqual(self.data, data[1]) @@ -126,7 +126,7 @@ class TestSetBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): def setUp(self): super(TestSetBgpPeer, self).setUp() - self.neutronclient.update_bgp_peer = mock.Mock(return_value=None) + self.networkclient.update_bgp_peer = mock.Mock(return_value=None) bgp_peer.get_bgp_peer_id = mock.Mock(return_value=self._bgp_peer_name) self.cmd = bgp_peer.SetBgpPeer(self.app, self.namespace) @@ -144,10 +144,7 @@ class TestSetBgpPeer(fakes.TestNeutronDynamicRoutingOSCV2): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - attrs = {'bgp_peer': { - 'name': 'noob', - 'password': None} - } - self.neutronclient.update_bgp_peer.assert_called_once_with( - self._bgp_peer_name, attrs) + attrs = {'name': 'noob', 'password': None} + self.networkclient.update_bgp_peer.assert_called_once_with( + self._bgp_peer_name, **attrs) self.assertIsNone(result) diff --git a/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_speaker.py b/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_speaker.py index 159746875..c5e42e588 100644 --- a/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_speaker.py +++ b/neutronclient/tests/unit/osc/v2/dynamic_routing/test_bgp_speaker.py @@ -20,7 +20,7 @@ class TestListBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): _bgp_speakers = fakes.FakeBgpSpeaker.create_bgp_speakers() columns = ('ID', 'Name', 'Local AS', 'IP Version') data = [] - for _bgp_speaker in _bgp_speakers['bgp_speakers']: + for _bgp_speaker in _bgp_speakers: data.append(( _bgp_speaker['id'], _bgp_speaker['name'], @@ -30,7 +30,7 @@ class TestListBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): def setUp(self): super(TestListBgpSpeaker, self).setUp() - self.neutronclient.list_bgp_speakers = mock.Mock( + self.networkclient.bgp_speakers = mock.Mock( return_value=self._bgp_speakers ) @@ -41,7 +41,9 @@ class TestListBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): parsed_args = self.check_parser(self.cmd, [], []) columns, data = self.cmd.take_action(parsed_args) - self.neutronclient.list_bgp_speakers.assert_called_once_with() + self.networkclient.bgp_speakers.assert_called_once_with( + retrieve_all=True) + self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) @@ -53,7 +55,7 @@ class TestDeleteBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): def setUp(self): super(TestDeleteBgpSpeaker, self).setUp() - self.neutronclient.delete_bgp_speaker = mock.Mock(return_value=None) + self.networkclient.delete_bgp_speaker = mock.Mock(return_value=None) self.cmd = bgp_speaker.DeleteBgpSpeaker(self.app, self.namespace) @@ -68,7 +70,7 @@ class TestDeleteBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): result = self.cmd.take_action(parsed_args) - self.neutronclient.delete_bgp_speaker.assert_called_once_with( + self.networkclient.delete_bgp_speaker.assert_called_once_with( self._bgp_speaker['name']) self.assertIsNone(result) @@ -86,7 +88,7 @@ class TestShowBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): _one_bgp_speaker['peers'], _one_bgp_speaker['tenant_id'] ) - _bgp_speaker = {'bgp_speaker': _one_bgp_speaker} + _bgp_speaker = _one_bgp_speaker _bgp_speaker_name = _one_bgp_speaker['name'] columns = ( 'advertise_floating_ip_host_routes', @@ -97,13 +99,13 @@ class TestShowBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): 'name', 'networks', 'peers', - 'tenant_id' + 'project_id' ) def setUp(self): super(TestShowBgpSpeaker, self).setUp() - self.neutronclient.show_bgp_speaker = mock.Mock( + self.networkclient.get_bgp_speaker = mock.Mock( return_value=self._bgp_speaker ) # Get the command object to test @@ -119,7 +121,7 @@ class TestShowBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): parsed_args = self.check_parser(self.cmd, arglist, verifylist) data = self.cmd.take_action(parsed_args) - self.neutronclient.show_bgp_speaker.assert_called_once_with( + self.networkclient.get_bgp_speaker.assert_called_once_with( self._bgp_speaker_name) self.assertEqual(self.columns, data[0]) self.assertEqual(self.data, data[1]) @@ -131,7 +133,7 @@ class TestSetBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): def setUp(self): super(TestSetBgpSpeaker, self).setUp() - self.neutronclient.update_bgp_speaker = mock.Mock( + self.networkclient.update_bgp_speaker = mock.Mock( return_value=None) self.cmd = bgp_speaker.SetBgpSpeaker(self.app, self.namespace) @@ -149,9 +151,7 @@ class TestSetBgpSpeaker(fakes.TestNeutronDynamicRoutingOSCV2): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - attrs = {'bgp_speaker': { - 'name': 'noob'} - } - self.neutronclient.update_bgp_speaker.assert_called_once_with( - self._bgp_speaker_name, attrs) + attrs = {'name': 'noob'} + self.networkclient.update_bgp_speaker.assert_called_once_with( + self._bgp_speaker_name, **attrs) self.assertIsNone(result) diff --git a/neutronclient/tests/unit/osc/v2/fakes.py b/neutronclient/tests/unit/osc/v2/fakes.py index c7876b645..7fec7347c 100644 --- a/neutronclient/tests/unit/osc/v2/fakes.py +++ b/neutronclient/tests/unit/osc/v2/fakes.py @@ -26,6 +26,10 @@ class TestNeutronClientOSCV2(utils.TestCommand): self.app.client_manager.session = mock.Mock() self.app.client_manager.neutronclient = mock.Mock() self.neutronclient = self.app.client_manager.neutronclient + + self.app.client_manager.network = mock.Mock() + self.networkclient = self.app.client_manager.network + self.addCleanup(mock.patch.stopall) # TODO(amotoki): Move this to osc_lib diff --git a/requirements.txt b/requirements.txt index b85e6b69a..2e9e22d08 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ cliff>=3.4.0 # Apache-2.0 debtcollector>=1.2.0 # Apache-2.0 iso8601>=0.1.11 # MIT netaddr>=0.7.18 # BSD +openstacksdk>=1.0.0 # Apache-2.0 osc-lib>=1.12.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0