diff options
Diffstat (limited to 'openstackclient/tests/unit/network')
5 files changed, 73 insertions, 26 deletions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index 3df4042c..2db83d3b 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -642,7 +642,7 @@ class FakePort(object): 'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex, 'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex, 'tags': [], - 'uplink_status_propagation': False, + 'propagate_uplink_status': False, } # Overwrite default attributes. @@ -662,8 +662,8 @@ class FakePort(object): port.project_id = port_attrs['tenant_id'] port.security_group_ids = port_attrs['security_group_ids'] port.qos_policy_id = port_attrs['qos_policy_id'] - port.uplink_status_propagation = port_attrs[ - 'uplink_status_propagation'] + port.propagate_uplink_status = port_attrs[ + 'propagate_uplink_status'] return port @@ -1591,6 +1591,8 @@ class FakeNetworkMeterRule(object): 'excluded': False, 'metering_label_id': 'meter-label-id-' + uuid.uuid4().hex, 'remote_ip_prefix': '10.0.0.0/24', + 'source_ip_prefix': '8.8.8.8/32', + 'destination_ip_prefix': '10.0.0.0/24', 'tenant_id': 'project-id-' + uuid.uuid4().hex, } diff --git a/openstackclient/tests/unit/network/v2/test_network_meter_rule.py b/openstackclient/tests/unit/network/v2/test_network_meter_rule.py index 8f8922c0..e9224fa6 100644 --- a/openstackclient/tests/unit/network/v2/test_network_meter_rule.py +++ b/openstackclient/tests/unit/network/v2/test_network_meter_rule.py @@ -42,20 +42,24 @@ class TestCreateMeterRule(TestMeterRule): ) columns = ( + 'destination_ip_prefix', 'direction', 'excluded', 'id', 'metering_label_id', 'project_id', 'remote_ip_prefix', + 'source_ip_prefix', ) data = ( + new_rule.destination_ip_prefix, new_rule.direction, new_rule.excluded, new_rule.id, new_rule.metering_label_id, new_rule.project_id, new_rule.remote_ip_prefix, + new_rule.source_ip_prefix, ) def setUp(self): @@ -228,6 +232,8 @@ class TestListMeterRule(TestMeterRule): 'Excluded', 'Direction', 'Remote IP Prefix', + 'Source IP Prefix', + 'Destination IP Prefix' ) data = [] @@ -238,6 +244,8 @@ class TestListMeterRule(TestMeterRule): rule.excluded, rule.direction, rule.remote_ip_prefix, + rule.source_ip_prefix, + rule.destination_ip_prefix )) def setUp(self): @@ -270,21 +278,25 @@ class TestShowMeterRule(TestMeterRule): ) columns = ( + 'destination_ip_prefix', 'direction', 'excluded', 'id', 'metering_label_id', 'project_id', 'remote_ip_prefix', + 'source_ip_prefix', ) data = ( + new_rule.destination_ip_prefix, new_rule.direction, new_rule.excluded, new_rule.id, new_rule.metering_label_id, new_rule.project_id, new_rule.remote_ip_prefix, + new_rule.source_ip_prefix, ) def setUp(self): diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index 70fa063d..d8889ae5 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -62,12 +62,12 @@ class TestPort(network_fakes.TestNetworkV2): 'numa_affinity_policy', 'port_security_enabled', 'project_id', + 'propagate_uplink_status', 'qos_network_policy_id', 'qos_policy_id', 'security_group_ids', 'status', 'tags', - 'uplink_status_propagation', ) data = ( @@ -94,12 +94,12 @@ class TestPort(network_fakes.TestNetworkV2): fake_port.numa_affinity_policy, fake_port.port_security_enabled, fake_port.project_id, + fake_port.propagate_uplink_status, fake_port.qos_network_policy_id, fake_port.qos_policy_id, format_columns.ListColumn(fake_port.security_group_ids), fake_port.status, format_columns.ListColumn(fake_port.tags), - fake_port.uplink_status_propagation, ) return columns, data @@ -121,6 +121,7 @@ class TestCreatePort(TestPort): self.network.find_network = mock.Mock(return_value=fake_net) self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet() self.network.find_subnet = mock.Mock(return_value=self.fake_subnet) + self.network.find_extension = mock.Mock(return_value=[]) # Get the command object to test self.cmd = port.CreatePort(self.app, self.namespace) @@ -536,7 +537,7 @@ class TestCreatePort(TestPort): 'name': 'test-port', }) - def _test_create_with_tag(self, add_tags=True): + def _test_create_with_tag(self, add_tags=True, add_tags_in_post=True): arglist = [ '--network', self._port.network_id, 'test-port', @@ -555,28 +556,59 @@ class TestCreatePort(TestPort): else: verifylist.append(('no_tag', True)) + self.network.find_extension = mock.Mock(return_value=add_tags_in_post) + 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, - name='test-port' - ) - if add_tags: - self.network.set_tags.assert_called_once_with( - self._port, - tests_utils.CompareBySet(['red', 'blue'])) + args = { + 'admin_state_up': True, + 'network_id': self._port.network_id, + 'name': 'test-port', + } + if add_tags_in_post: + if add_tags: + args['tags'] = sorted(['red', 'blue']) + else: + args['tags'] = [] + self.network.create_port.assert_called_once() + # Now we need to verify if arguments to call create_port are as + # expected, + # But we can't simply use assert_called_once_with() method because + # duplicates from 'tags' are removed with + # list(set(parsed_args.tags)) and that don't quarantee order of + # tags list which is used to call create_port(). + create_port_call_kwargs = self.network.create_port.call_args[1] + create_port_call_kwargs['tags'] = sorted( + create_port_call_kwargs['tags']) + self.assertDictEqual(args, create_port_call_kwargs) else: - self.assertFalse(self.network.set_tags.called) + self.network.create_port.assert_called_once_with( + admin_state_up=True, + network_id=self._port.network_id, + name='test-port' + ) + if add_tags: + self.network.set_tags.assert_called_once_with( + self._port, + tests_utils.CompareBySet(['red', 'blue'])) + else: + self.assertFalse(self.network.set_tags.called) + self.assertEqual(self.columns, columns) self.assertItemEqual(self.data, data) def test_create_with_tags(self): - self._test_create_with_tag(add_tags=True) + self._test_create_with_tag(add_tags=True, add_tags_in_post=True) def test_create_with_no_tag(self): - self._test_create_with_tag(add_tags=False) + self._test_create_with_tag(add_tags=False, add_tags_in_post=True) + + def test_create_with_tags_using_put(self): + self._test_create_with_tag(add_tags=True, add_tags_in_post=False) + + def test_create_with_no_tag_using_put(self): + self._test_create_with_tag(add_tags=False, add_tags_in_post=False) def _test_create_with_uplink_status_propagation(self, enable=True): arglist = [ diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py index 5720e305..b7e38afb 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py @@ -362,6 +362,7 @@ class TestListSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): 'Ethertype', 'IP Range', 'Port Range', + 'Direction', 'Remote Security Group', ) expected_columns_no_group = \ diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py index 0a9522b0..01411611 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py +++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py @@ -870,7 +870,7 @@ class TestListSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): _security_group_rules = [_security_group_rule_tcp, _security_group_rule_icmp] - expected_columns_with_group_and_long = ( + expected_columns_with_group = ( 'ID', 'IP Protocol', 'Ethertype', @@ -885,14 +885,15 @@ class TestListSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): 'Ethertype', 'IP Range', 'Port Range', + 'Direction', 'Remote Security Group', 'Security Group', ) - expected_data_with_group_and_long = [] + expected_data_with_group = [] expected_data_no_group = [] for _security_group_rule in _security_group_rules: - expected_data_with_group_and_long.append(( + expected_data_with_group.append(( _security_group_rule.id, _security_group_rule.protocol, _security_group_rule.ether_type, @@ -909,6 +910,7 @@ class TestListSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): _security_group_rule.remote_ip_prefix, security_group_rule._format_network_port_range( _security_group_rule), + _security_group_rule.direction, _security_group_rule.remote_group_id, _security_group_rule.security_group_id, )) @@ -935,14 +937,12 @@ class TestListSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): self.assertEqual(self.expected_columns_no_group, columns) self.assertEqual(self.expected_data_no_group, list(data)) - def test_list_with_group_and_long(self): + def test_list_with_group(self): self._security_group_rule_tcp.port_range_min = 80 arglist = [ - '--long', self._security_group.id, ] verifylist = [ - ('long', True), ('group', self._security_group.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -952,8 +952,8 @@ class TestListSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): self.network.security_group_rules.assert_called_once_with(**{ 'security_group_id': self._security_group.id, }) - self.assertEqual(self.expected_columns_with_group_and_long, columns) - self.assertEqual(self.expected_data_with_group_and_long, list(data)) + self.assertEqual(self.expected_columns_with_group, columns) + self.assertEqual(self.expected_data_with_group, list(data)) def test_list_with_ignored_options(self): self._security_group_rule_tcp.port_range_min = 80 |
