summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-04-15 16:30:48 +0000
committerGerrit Code Review <review@openstack.org>2016-04-15 16:30:48 +0000
commitf66f989d83cdd067acb811e9c9a3f9923483ba35 (patch)
tree03a2105e5d045a010ce931559f5aabb935344b00 /openstackclient
parent881c8360303d80c390110bcd39348b64f0543b2c (diff)
parentc92ac9d9110524ffb4c672a5b1c3cdc08e38e717 (diff)
downloadpython-openstackclient-f66f989d83cdd067acb811e9c9a3f9923483ba35.tar.gz
Merge "Append existing information during port set"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/port.py20
-rw-r--r--openstackclient/tests/network/v2/test_port.py21
2 files changed, 34 insertions, 7 deletions
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 820f2ac2..c54cb257 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -30,6 +30,7 @@ LOG = logging.getLogger(__name__)
def _format_admin_state(state):
return 'UP' if state else 'DOWN'
+
_formatters = {
'admin_state_up': _format_admin_state,
'allowed_address_pairs': utils.format_list_of_dicts,
@@ -383,17 +384,24 @@ class SetPort(command.Command):
_prepare_fixed_ips(self.app.client_manager, parsed_args)
attrs = _get_attrs(self.app.client_manager, parsed_args)
-
- if parsed_args.no_fixed_ip:
- attrs['fixed_ips'] = []
- if parsed_args.no_binding_profile:
+ obj = client.find_port(parsed_args.port, ignore_missing=False)
+ if 'binding:profile' in attrs:
+ attrs['binding:profile'].update(obj.binding_profile)
+ elif parsed_args.no_binding_profile:
attrs['binding:profile'] = {}
+ if 'fixed_ips' in attrs:
+ # When user unsets the fixed_ips, obj.fixed_ips = [{}].
+ # Adding the obj.fixed_ips list to attrs['fixed_ips']
+ # would therefore add an empty dictionary, while we need
+ # to append the attrs['fixed_ips'] iff there is some info
+ # in the obj.fixed_ips. Therefore I have opted for this `for` loop
+ attrs['fixed_ips'] += [ip for ip in obj.fixed_ips if ip]
+ elif parsed_args.no_fixed_ip:
+ attrs['fixed_ips'] = []
if attrs == {}:
msg = "Nothing specified to be set"
raise exceptions.CommandError(msg)
-
- obj = client.find_port(parsed_args.port, ignore_missing=False)
client.update_port(obj, **attrs)
diff --git a/openstackclient/tests/network/v2/test_port.py b/openstackclient/tests/network/v2/test_port.py
index 3b1a641a..f2aa26cf 100644
--- a/openstackclient/tests/network/v2/test_port.py
+++ b/openstackclient/tests/network/v2/test_port.py
@@ -268,7 +268,6 @@ class TestSetPort(TestPort):
def setUp(self):
super(TestSetPort, self).setUp()
-
self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet()
self.network.find_subnet = mock.Mock(return_value=self.fake_subnet)
self.network.find_port = mock.Mock(return_value=self._port)
@@ -295,6 +294,26 @@ class TestSetPort(TestPort):
self.network.update_port.assert_called_once_with(self._port, **attrs)
self.assertIsNone(result)
+ def test_append_fixed_ip(self):
+ _testport = network_fakes.FakePort.create_one_port(
+ {'fixed_ips': [{'ip_address': '0.0.0.1'}]})
+ self.network.find_port = mock.Mock(return_value=_testport)
+ arglist = [
+ '--fixed-ip', 'ip-address=10.0.0.12',
+ _testport.name,
+ ]
+ verifylist = [
+ ('fixed_ip', [{'ip-address': '10.0.0.12'}]),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+ attrs = {
+ 'fixed_ips': [
+ {'ip_address': '10.0.0.12'}, {'ip_address': '0.0.0.1'}],
+ }
+ self.network.update_port.assert_called_once_with(_testport, **attrs)
+ self.assertIsNone(result)
+
def test_set_this(self):
arglist = [
'--disable',