From df5f12b135f273e3916e7bf300fa7688a180ea02 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Hoai Date: Fri, 12 Aug 2016 16:00:52 +0700 Subject: [PATCH] Add "dns-name" option to "os port create" and "os port set" This patch added a "dns-name" option to "os port create" and "os port set" command. Change-Id: I360e2c9a1970e64fe17e4561d7618f860b937373 Co-Authored-By: Ha Van Tu Partial-Bug: #1612136 Partially-Implements: blueprint network-commands-options --- doc/source/command-objects/port.rst | 12 +++++ openstackclient/network/v2/port.py | 8 +++ .../tests/unit/network/v2/test_port.py | 50 +++++++++++++++++++ .../notes/bug-1612136-63aac6377209db38.yaml | 5 ++ 4 files changed, 75 insertions(+) create mode 100644 releasenotes/notes/bug-1612136-63aac6377209db38.yaml diff --git a/doc/source/command-objects/port.rst b/doc/source/command-objects/port.rst index 3aff2f77b..73c53290b 100644 --- a/doc/source/command-objects/port.rst +++ b/doc/source/command-objects/port.rst @@ -28,6 +28,7 @@ Create new port [--enable | --disable] [--mac-address ] [--security-group | --no-security-group] + [--dns-name ] [--project [--project-domain ]] [--enable-port-security | --disable-port-security] @@ -91,6 +92,11 @@ Create new port Associate no security groups with this port +.. option:: --dns-name + + Set DNS name to this port + (requires DNS integration extension) + .. option:: --project Owner's project (name or ID) @@ -192,6 +198,7 @@ Set port properties [--security-group ] [--no-security-group] [--enable-port-security | --disable-port-security] + [--dns-name ] .. option:: --description @@ -269,6 +276,11 @@ Set port properties Disable port security for this port +.. option:: --dns-name + + Set DNS name to this port + (requires DNS integration extension) + .. _port_set-port: .. describe:: diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 6cae87ee1..c960ba252 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -128,6 +128,8 @@ def _get_attrs(client_manager, parsed_args): if parsed_args.host: attrs['binding:host_id'] = parsed_args.host + if parsed_args.dns_name is not None: + attrs['dns_name'] = parsed_args.dns_name # It is possible that name is not updated during 'port set' if parsed_args.name is not None: attrs['name'] = str(parsed_args.name) @@ -233,6 +235,12 @@ def _add_updatable_args(parser): metavar='', help=argparse.SUPPRESS, ) + parser.add_argument( + '--dns-name', + metavar='dns-name', + help=_("Set DNS name to this port " + "(requires DNS integration extension)") + ) class CreatePort(command.ShowOne): diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index 9312a8976..aeb9884a4 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -140,6 +140,7 @@ class TestCreatePort(TestPort): '--binding-profile', 'foo=bar', '--binding-profile', 'foo2=bar2', '--network', self._port.network_id, + '--dns-name', '8.8.8.8', 'test-port', ] @@ -156,6 +157,7 @@ class TestCreatePort(TestPort): ('vnic_type', 'macvtap'), ('binding_profile', {'foo': 'bar', 'foo2': 'bar2'}), ('network', self._port.network_id), + ('dns_name', '8.8.8.8'), ('name', 'test-port'), ] @@ -174,6 +176,7 @@ class TestCreatePort(TestPort): 'binding:vnic_type': 'macvtap', 'binding:profile': {'foo': 'bar', 'foo2': 'bar2'}, 'network_id': self._port.network_id, + 'dns_name': '8.8.8.8', 'name': 'test-port', }) @@ -241,6 +244,7 @@ class TestCreatePort(TestPort): '--security-group', secgroup.id, 'test-port', ] + verifylist = [ ('network', self._port.network_id,), ('enable', True), @@ -262,6 +266,33 @@ class TestCreatePort(TestPort): self.assertEqual(ref_columns, columns) self.assertEqual(ref_data, data) + def test_create_port_with_dns_name(self): + arglist = [ + '--network', self._port.network_id, + '--dns-name', '8.8.8.8', + 'test-port', + ] + verifylist = [ + ('network', self._port.network_id,), + ('enable', True), + ('dns_name', '8.8.8.8'), + ('name', 'test-port'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = (self.cmd.take_action(parsed_args)) + + self.network.create_port.assert_called_once_with(**{ + 'admin_state_up': True, + 'network_id': self._port.network_id, + 'dns_name': '8.8.8.8', + 'name': 'test-port', + }) + + ref_columns, ref_data = self._get_common_cols_data(self._port) + self.assertEqual(ref_columns, columns) + self.assertEqual(ref_data, data) + def test_create_with_security_groups(self): sg_1 = network_fakes.FakeSecurityGroup.create_one_security_group() sg_2 = network_fakes.FakeSecurityGroup.create_one_security_group() @@ -676,6 +707,25 @@ class TestSetPort(TestPort): self.network.update_port.assert_called_once_with(self._port, **attrs) self.assertIsNone(result) + def test_set_dns_name(self): + arglist = [ + '--dns-name', '8.8.8.8', + self._port.name, + ] + verifylist = [ + ('dns_name', '8.8.8.8'), + ('port', self._port.name), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + attrs = { + 'dns_name': '8.8.8.8', + } + 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'}]}) diff --git a/releasenotes/notes/bug-1612136-63aac6377209db38.yaml b/releasenotes/notes/bug-1612136-63aac6377209db38.yaml new file mode 100644 index 000000000..51eaa76dd --- /dev/null +++ b/releasenotes/notes/bug-1612136-63aac6377209db38.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--dns-name`` option to ``os port create`` and ``os port set`` commands. + [Bug `1612136 `_]