diff options
| author | Yan Xing'an <yanxingan@cmss.chinamobile.com> | 2016-10-19 02:21:41 -0700 |
|---|---|---|
| committer | Yan Xing'an <yanxingan@cmss.chinamobile.com> | 2017-02-07 19:00:52 -0800 |
| commit | e0e46bca093984926de11559e312d1f1fcade108 (patch) | |
| tree | 9795751911ba901e4089c010ec99336f44cf6cb0 /openstackclient/tests | |
| parent | e35c97a4fc323f9771908566656c172ba4bbd340 (diff) | |
| download | python-openstackclient-e0e46bca093984926de11559e312d1f1fcade108.tar.gz | |
Add --fixed-ip option to the port list command
Add support to allow filtering ports via --fixed-ip
option to the port list command.
Change-Id: I2f728368d3046b2e6feadd0848bf6f8680e31aba
Partial-bug: #1634799
Partially-Implements: blueprint network-commands-options
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/unit/network/v2/fakes.py | 3 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_port.py | 87 |
2 files changed, 89 insertions, 1 deletions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index eb965339..4b266efb 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -470,7 +470,8 @@ class FakePort(object): 'dns_assignment': [{}], 'dns_name': 'dns-name-' + uuid.uuid4().hex, 'extra_dhcp_opts': [{}], - 'fixed_ips': [{}], + 'fixed_ips': [{'ip_address': '10.0.0.3', + 'subnet_id': 'subnet-id-' + uuid.uuid4().hex}], 'id': 'port-id-' + uuid.uuid4().hex, 'mac_address': 'fa:16:3e:a9:4e:72', 'name': 'port-name-' + uuid.uuid4().hex, diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index fc626685..bfffc5c0 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -727,6 +727,92 @@ class TestListPort(TestPort): self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + def test_port_list_fixed_ip_opt_ip_address(self): + ip_address = self._ports[0].fixed_ips[0]['ip_address'] + arglist = [ + '--fixed-ip', "ip-address=%s" % ip_address, + ] + verifylist = [ + ('fixed_ip', [{'ip-address': ip_address}]) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['ip_address=%s' % ip_address]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_port_list_fixed_ip_opt_subnet_id(self): + subnet_id = self._ports[0].fixed_ips[0]['subnet_id'] + arglist = [ + '--fixed-ip', "subnet=%s" % subnet_id, + ] + verifylist = [ + ('fixed_ip', [{'subnet': subnet_id}]) + ] + + self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet( + {'id': subnet_id}) + self.network.find_subnet = mock.Mock(return_value=self.fake_subnet) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['subnet_id=%s' % subnet_id]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_port_list_fixed_ip_opts(self): + subnet_id = self._ports[0].fixed_ips[0]['subnet_id'] + ip_address = self._ports[0].fixed_ips[0]['ip_address'] + arglist = [ + '--fixed-ip', "subnet=%s,ip-address=%s" % (subnet_id, + ip_address) + ] + verifylist = [ + ('fixed_ip', [{'subnet': subnet_id, + 'ip-address': ip_address}]) + ] + + self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet( + {'id': subnet_id}) + self.network.find_subnet = mock.Mock(return_value=self.fake_subnet) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['subnet_id=%s' % subnet_id, + 'ip_address=%s' % ip_address]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_port_list_fixed_ips(self): + subnet_id = self._ports[0].fixed_ips[0]['subnet_id'] + ip_address = self._ports[0].fixed_ips[0]['ip_address'] + arglist = [ + '--fixed-ip', "subnet=%s" % subnet_id, + '--fixed-ip', "ip-address=%s" % ip_address, + ] + verifylist = [ + ('fixed_ip', [{'subnet': subnet_id}, + {'ip-address': ip_address}]) + ] + + self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet( + {'id': subnet_id}) + self.network.find_subnet = mock.Mock(return_value=self.fake_subnet) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['subnet_id=%s' % subnet_id, + 'ip_address=%s' % ip_address]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + def test_list_port_with_long(self): arglist = [ '--long', @@ -801,6 +887,7 @@ class TestSetPort(TestPort): arglist = [ '--fixed-ip', 'ip-address=10.0.0.11', self._port.name, + '--no-fixed-ip', ] verifylist = [ ('fixed_ip', [{'ip-address': '10.0.0.11'}]), |
