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
This commit is contained in:
yanpuqing 2018-06-13 05:21:53 -04:00
parent f7e4d31820
commit 402c9a21b3
3 changed files with 60 additions and 14 deletions

View File

@ -198,7 +198,7 @@ Set floating IP properties
.. code:: bash
openstack floating ip set
--port <port>
[--port <port>]
[--fixed-ip-address <ip-address>]
[--qos-policy <qos-policy> | --no-qos-policy]
[--tag <tag>] [--no-tag]
@ -257,8 +257,8 @@ Unset floating IP Properties
.. code:: bash
openstack floating ip unset
--port
--qos-policy
[--port]
[--qos-policy]
[--tag <tag> | --all-tag]
<floating-ip>

View File

@ -416,11 +416,10 @@ class SetFloatingIP(command.Command):
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP to associate (IP address or ID)"))
help=_("Floating IP to modify (IP address or ID)"))
parser.add_argument(
'--port',
metavar='<port>',
required=True,
help=_("Associate the floating IP with port (name or ID)")),
parser.add_argument(
'--fixed-ip-address',
@ -452,9 +451,11 @@ class SetFloatingIP(command.Command):
parsed_args.floating_ip,
ignore_missing=False,
)
port = client.find_port(parsed_args.port,
ignore_missing=False)
attrs['port_id'] = port.id
if parsed_args.port:
port = client.find_port(parsed_args.port,
ignore_missing=False)
attrs['port_id'] = port.id
if parsed_args.fixed_ip_address:
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address

View File

@ -747,6 +747,31 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
self.network.update_ip.assert_called_once_with(
self.floating_ip, **attrs)
def test_qos_policy_option(self):
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
arglist = [
"--qos-policy", qos_policy.id,
self.floating_ip.id,
]
verifylist = [
('qos_policy', qos_policy.id),
('floating_ip', self.floating_ip.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
attrs = {
'qos_policy_id': qos_policy.id,
}
self.network.find_ip.assert_called_once_with(
self.floating_ip.id,
ignore_missing=False,
)
self.network.update_ip.assert_called_once_with(
self.floating_ip, **attrs)
def test_port_and_qos_policy_option(self):
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
@ -775,6 +800,29 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
self.network.update_ip.assert_called_once_with(
self.floating_ip, **attrs)
def test_no_qos_policy_option(self):
arglist = [
"--no-qos-policy",
self.floating_ip.id,
]
verifylist = [
('no_qos_policy', True),
('floating_ip', self.floating_ip.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
attrs = {
'qos_policy_id': None,
}
self.network.find_ip.assert_called_once_with(
self.floating_ip.id,
ignore_missing=False,
)
self.network.update_ip.assert_called_once_with(
self.floating_ip, **attrs)
def test_port_and_no_qos_policy_option(self):
arglist = [
"--no-qos-policy",
@ -810,16 +858,13 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
arglist = ['--no-tag']
verifylist = [('no_tag', True)]
expected_args = []
arglist.extend(['--port', self.floating_ip.port_id,
self.floating_ip.id])
verifylist.extend([
('port', self.floating_ip.port_id),
('floating_ip', self.floating_ip.id)])
arglist.extend([self.floating_ip.id])
verifylist.extend([('floating_ip', self.floating_ip.id)])
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertTrue(self.network.update_ip.called)
self.assertFalse(self.network.update_ip.called)
self.network.set_tags.assert_called_once_with(
self.floating_ip,
tests_utils.CompareBySet(expected_args))