diff options
| author | yanpuqing <yanpq@awcloud.com> | 2018-06-13 05:21:53 -0400 |
|---|---|---|
| committer | yanpuqing <yanpq@awcloud.com> | 2018-06-13 23:05:30 -0400 |
| commit | 402c9a21b347509520be206e28ee7d0ef4004b92 (patch) | |
| tree | b517f5c35ed85ec8761dcfcebe82414c94592cf4 | |
| parent | f7e4d31820e797e0d374e7dfde1142373245ea87 (diff) | |
| download | python-openstackclient-402c9a21b347509520be206e28ee7d0ef4004b92.tar.gz | |
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
| -rw-r--r-- | doc/source/cli/command-objects/floating-ip.rst | 6 | ||||
| -rw-r--r-- | openstackclient/network/v2/floating_ip.py | 11 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_floating_ip_network.py | 57 |
3 files changed, 60 insertions, 14 deletions
diff --git a/doc/source/cli/command-objects/floating-ip.rst b/doc/source/cli/command-objects/floating-ip.rst index c0ba7ebf..e3e50adc 100644 --- a/doc/source/cli/command-objects/floating-ip.rst +++ b/doc/source/cli/command-objects/floating-ip.rst @@ -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> diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index f51baed5..2f0e7403 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -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 diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py index 65d87377..822d3ae8 100644 --- a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py +++ b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py @@ -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)) |
