Skip to content

Commit 402c9a2

Browse files
committed
Do not require port argument when updating floating IP
When setting floating ip other properties, port argument is force to use. The patch modifies the command, when setting floating ip other properties, like tags, no need port argument. Change-Id: I908712c8913f32d3dd5fdfefe7347277d72f66de Story: 1751431 Task: 13865
1 parent f7e4d31 commit 402c9a2

3 files changed

Lines changed: 60 additions & 14 deletions

File tree

doc/source/cli/command-objects/floating-ip.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Set floating IP properties
198198
.. code:: bash
199199
200200
openstack floating ip set
201-
--port <port>
201+
[--port <port>]
202202
[--fixed-ip-address <ip-address>]
203203
[--qos-policy <qos-policy> | --no-qos-policy]
204204
[--tag <tag>] [--no-tag]
@@ -257,8 +257,8 @@ Unset floating IP Properties
257257
.. code:: bash
258258
259259
openstack floating ip unset
260-
--port
261-
--qos-policy
260+
[--port]
261+
[--qos-policy]
262262
[--tag <tag> | --all-tag]
263263
<floating-ip>
264264

openstackclient/network/v2/floating_ip.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,10 @@ def get_parser(self, prog_name):
416416
parser.add_argument(
417417
'floating_ip',
418418
metavar='<floating-ip>',
419-
help=_("Floating IP to associate (IP address or ID)"))
419+
help=_("Floating IP to modify (IP address or ID)"))
420420
parser.add_argument(
421421
'--port',
422422
metavar='<port>',
423-
required=True,
424423
help=_("Associate the floating IP with port (name or ID)")),
425424
parser.add_argument(
426425
'--fixed-ip-address',
@@ -452,9 +451,11 @@ def take_action(self, parsed_args):
452451
parsed_args.floating_ip,
453452
ignore_missing=False,
454453
)
455-
port = client.find_port(parsed_args.port,
456-
ignore_missing=False)
457-
attrs['port_id'] = port.id
454+
if parsed_args.port:
455+
port = client.find_port(parsed_args.port,
456+
ignore_missing=False)
457+
attrs['port_id'] = port.id
458+
458459
if parsed_args.fixed_ip_address:
459460
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
460461

openstackclient/tests/unit/network/v2/test_floating_ip_network.py

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,31 @@ def test_fixed_ip_option(self):
747747
self.network.update_ip.assert_called_once_with(
748748
self.floating_ip, **attrs)
749749

750+
def test_qos_policy_option(self):
751+
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
752+
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
753+
arglist = [
754+
"--qos-policy", qos_policy.id,
755+
self.floating_ip.id,
756+
]
757+
verifylist = [
758+
('qos_policy', qos_policy.id),
759+
('floating_ip', self.floating_ip.id),
760+
]
761+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
762+
763+
self.cmd.take_action(parsed_args)
764+
765+
attrs = {
766+
'qos_policy_id': qos_policy.id,
767+
}
768+
self.network.find_ip.assert_called_once_with(
769+
self.floating_ip.id,
770+
ignore_missing=False,
771+
)
772+
self.network.update_ip.assert_called_once_with(
773+
self.floating_ip, **attrs)
774+
750775
def test_port_and_qos_policy_option(self):
751776
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
752777
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
@@ -775,6 +800,29 @@ def test_port_and_qos_policy_option(self):
775800
self.network.update_ip.assert_called_once_with(
776801
self.floating_ip, **attrs)
777802

803+
def test_no_qos_policy_option(self):
804+
arglist = [
805+
"--no-qos-policy",
806+
self.floating_ip.id,
807+
]
808+
verifylist = [
809+
('no_qos_policy', True),
810+
('floating_ip', self.floating_ip.id),
811+
]
812+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
813+
814+
self.cmd.take_action(parsed_args)
815+
816+
attrs = {
817+
'qos_policy_id': None,
818+
}
819+
self.network.find_ip.assert_called_once_with(
820+
self.floating_ip.id,
821+
ignore_missing=False,
822+
)
823+
self.network.update_ip.assert_called_once_with(
824+
self.floating_ip, **attrs)
825+
778826
def test_port_and_no_qos_policy_option(self):
779827
arglist = [
780828
"--no-qos-policy",
@@ -810,16 +858,13 @@ def _test_set_tags(self, with_tags=True):
810858
arglist = ['--no-tag']
811859
verifylist = [('no_tag', True)]
812860
expected_args = []
813-
arglist.extend(['--port', self.floating_ip.port_id,
814-
self.floating_ip.id])
815-
verifylist.extend([
816-
('port', self.floating_ip.port_id),
817-
('floating_ip', self.floating_ip.id)])
861+
arglist.extend([self.floating_ip.id])
862+
verifylist.extend([('floating_ip', self.floating_ip.id)])
818863

819864
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
820865
result = self.cmd.take_action(parsed_args)
821866

822-
self.assertTrue(self.network.update_ip.called)
867+
self.assertFalse(self.network.update_ip.called)
823868
self.network.set_tags.assert_called_once_with(
824869
self.floating_ip,
825870
tests_utils.CompareBySet(expected_args))

0 commit comments

Comments
 (0)