| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
# |
| 13 |
from unittest import mock |
| 14 |
|
| 15 |
from neutronclient.osc.v2.dynamic_routing import bgp_dragent |
| 16 |
from neutronclient.tests.unit.osc.v2.dynamic_routing import fakes |
| 17 |
|
| 18 |
|
| 19 |
class TestAddBgpSpeakerToDRAgent(fakes.TestNeutronDynamicRoutingOSCV2): |
| 20 |
_bgp_speaker = fakes.FakeBgpSpeaker.create_one_bgp_speaker() |
| 21 |
_bgp_dragent = fakes.FakeDRAgent.create_one_dragent() |
| 22 |
_bgp_speaker_id = _bgp_speaker['id'] |
| 23 |
_bgp_dragent_id = _bgp_dragent['id'] |
| 24 |
|
| 25 |
def setUp(self): |
| 26 |
super(TestAddBgpSpeakerToDRAgent, self).setUp() |
| 27 |
|
| 28 |
# Get the command object to test |
| 29 |
self.cmd = bgp_dragent.AddBgpSpeakerToDRAgent(self.app, self.namespace) |
| 30 |
|
| 31 |
def test_add_bgp_speaker_to_dragent(self): |
| 32 |
arglist = [ |
| 33 |
self._bgp_dragent_id, |
| 34 |
self._bgp_speaker_id, |
| 35 |
] |
| 36 |
verifylist = [ |
| 37 |
('dragent_id', self._bgp_dragent_id), |
| 38 |
('bgp_speaker', self._bgp_speaker_id), |
| 39 |
] |
| 40 |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 41 |
|
| 42 |
with mock.patch.object(self.networkclient, |
| 43 |
"add_bgp_speaker_to_dragent", |
| 44 |
return_value=None): |
| 45 |
|
| 46 |
result = self.cmd.take_action(parsed_args) |
| 47 |
self.networkclient.add_bgp_speaker_to_dragent.\ |
| 48 |
assert_called_once_with( |
| 49 |
self._bgp_dragent_id, self._bgp_speaker_id) |
| 50 |
self.assertIsNone(result) |
| 51 |
|
| 52 |
|
| 53 |
class TestRemoveBgpSpeakerFromDRAgent(fakes.TestNeutronDynamicRoutingOSCV2): |
| 54 |
_bgp_speaker = fakes.FakeBgpSpeaker.create_one_bgp_speaker() |
| 55 |
_bgp_dragent = fakes.FakeDRAgent.create_one_dragent() |
| 56 |
_bgp_speaker_id = _bgp_speaker['id'] |
| 57 |
_bgp_dragent_id = _bgp_dragent['id'] |
| 58 |
|
| 59 |
def setUp(self): |
| 60 |
super(TestRemoveBgpSpeakerFromDRAgent, self).setUp() |
| 61 |
|
| 62 |
# Get the command object to test |
| 63 |
self.cmd = bgp_dragent.RemoveBgpSpeakerFromDRAgent( |
| 64 |
self.app, self.namespace) |
| 65 |
|
| 66 |
def test_remove_bgp_speaker_from_dragent(self): |
| 67 |
arglist = [ |
| 68 |
self._bgp_dragent_id, |
| 69 |
self._bgp_speaker_id, |
| 70 |
] |
| 71 |
verifylist = [ |
| 72 |
('dragent_id', self._bgp_dragent_id), |
| 73 |
('bgp_speaker', self._bgp_speaker_id), |
| 74 |
] |
| 75 |
parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 76 |
|
| 77 |
with mock.patch.object(self.networkclient, |
| 78 |
"remove_bgp_speaker_from_dragent", |
| 79 |
return_value=None): |
| 80 |
result = self.cmd.take_action(parsed_args) |
| 81 |
self.networkclient.remove_bgp_speaker_from_dragent.\ |
| 82 |
assert_called_once_with(self._bgp_dragent_id, |
| 83 |
self._bgp_speaker_id) |
| 84 |
self.assertIsNone(result) |