/
opt
/
imh-python
/
lib
/
python3.9
/
site-packages
/
openstack
/
tests
/
unit
/
cloud
/
/opt/imh-python/lib/python3.9/site-packages/openstack/tests/unit/cloud
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
test_accelerator.py
11346
0644
edit
dl
rm
test_aggregate.py
7153
0644
edit
dl
rm
test_availability_zones.py
2308
0644
edit
dl
rm
test_baremetal_node.py
68958
0644
edit
dl
rm
test_baremetal_ports.py
4356
0644
edit
dl
rm
test_caching.py
25060
0644
edit
dl
rm
test_clustering.py
25641
0644
edit
dl
rm
test_cluster_templates.py
9946
0644
edit
dl
rm
test_coe_clusters.py
6118
0644
edit
dl
rm
test_coe_clusters_certificate.py
2565
0644
edit
dl
rm
test_create_server.py
39514
0644
edit
dl
rm
test_create_volume_snapshot.py
5571
0644
edit
dl
rm
test_delete_server.py
10622
0644
edit
dl
rm
test_delete_volume_snapshot.py
4040
0644
edit
dl
rm
test_domains.py
9858
0644
edit
dl
rm
test_domain_params.py
2903
0644
edit
dl
rm
test_endpoints.py
16035
0644
edit
dl
rm
test_flavors.py
11861
0644
edit
dl
rm
test_floating_ip_common.py
8270
0644
edit
dl
rm
test_floating_ip_neutron.py
48972
0644
edit
dl
rm
test_floating_ip_nova.py
11122
0644
edit
dl
rm
test_floating_ip_pool.py
2886
0644
edit
dl
rm
test_fwaas.py
52343
0644
edit
dl
rm
test_groups.py
3886
0644
edit
dl
rm
test_identity_roles.py
12236
0644
edit
dl
rm
test_image.py
60601
0644
edit
dl
rm
test_image_snapshot.py
4171
0644
edit
dl
rm
test_inventory.py
5826
0644
edit
dl
rm
test_keypair.py
4910
0644
edit
dl
rm
test_limits.py
3929
0644
edit
dl
rm
test_magnum_services.py
1378
0644
edit
dl
rm
test_meta.py
43155
0644
edit
dl
rm
test_network.py
14095
0644
edit
dl
rm
test_normalize.py
58339
0644
edit
dl
rm
test_object.py
51327
0644
edit
dl
rm
test_operator.py
6488
0644
edit
dl
rm
test_operator_noauth.py
8188
0644
edit
dl
rm
test_port.py
14285
0644
edit
dl
rm
test_project.py
11156
0644
edit
dl
rm
test_qos_bandwidth_limit_rule.py
17327
0644
edit
dl
rm
test_qos_dscp_marking_rule.py
12224
0644
edit
dl
rm
test_qos_minimum_bandwidth_rule.py
12399
0644
edit
dl
rm
test_qos_policy.py
13244
0644
edit
dl
rm
test_qos_rule_type.py
5648
0644
edit
dl
rm
test_quotas.py
9388
0644
edit
dl
rm
test_rebuild_server.py
9479
0644
edit
dl
rm
test_recordset.py
14767
0644
edit
dl
rm
test_role_assignment.py
150282
0644
edit
dl
rm
test_router.py
17107
0644
edit
dl
rm
test_security_groups.py
32570
0644
edit
dl
rm
test_server_console.py
2846
0644
edit
dl
rm
test_server_delete_metadata.py
2691
0644
edit
dl
rm
test_server_group.py
2366
0644
edit
dl
rm
test_server_set_metadata.py
2784
0644
edit
dl
rm
test_services.py
11700
0644
edit
dl
rm
test_shade.py
27060
0644
edit
dl
rm
test_shade_operator.py
743
0644
edit
dl
rm
test_stack.py
26453
0644
edit
dl
rm
test_subnet.py
18581
0644
edit
dl
rm
test_update_server.py
3339
0644
edit
dl
rm
test_usage.py
2595
0644
edit
dl
rm
test_users.py
9044
0644
edit
dl
rm
test_volume.py
23505
0644
edit
dl
rm
test_volume_access.py
8556
0644
edit
dl
rm
test_volume_backups.py
8947
0644
edit
dl
rm
test_zone.py
7635
0644
edit
dl
rm
test__utils.py
13857
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
Edit:
/opt/imh-python/lib/python3.9/site-packages/openstack/tests/unit/cloud/test_subnet.py
(18581B)
# Copyright 2017 OVH SAS # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import copy import testtools from openstack.cloud import exc from openstack.tests.unit import base class TestSubnet(base.TestCase): network_name = 'network_name' subnet_name = 'subnet_name' subnet_id = '1f1696eb-7f47-47f6-835c-4889bff88604' subnet_cidr = '192.168.199.0/24' subnetpool_cidr = '172.16.0.0/28' prefix_length = 28 mock_network_rep = { 'id': '881d1bb7-a663-44c0-8f9f-ee2765b74486', 'name': network_name, } mock_subnet_rep = { 'allocation_pools': [{ 'start': u'192.168.199.2', 'end': u'192.168.199.254' }], 'cidr': subnet_cidr, 'created_at': '2017-04-24T20:22:23Z', 'description': '', 'dns_nameservers': [], 'enable_dhcp': False, 'gateway_ip': '192.168.199.1', 'host_routes': [], 'id': subnet_id, 'ip_version': 4, 'ipv6_address_mode': None, 'ipv6_ra_mode': None, 'name': subnet_name, 'network_id': mock_network_rep['id'], 'project_id': '861808a93da0484ea1767967c4df8a23', 'revision_number': 2, 'service_types': [], 'subnetpool_id': None, 'tags': [] } mock_subnetpool_rep = { 'id': 'f49a1319-423a-4ee6-ba54-1d95a4f6cc68', 'prefixes': [ '172.16.0.0/16' ] } def test_get_subnet(self): self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': [self.mock_subnet_rep]}) ]) r = self.cloud.get_subnet(self.subnet_name) self.assertIsNotNone(r) self.assertDictEqual(self.mock_subnet_rep, r) self.assert_calls() def test_get_subnet_by_id(self): self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets', self.subnet_id]), json={'subnet': self.mock_subnet_rep}) ]) r = self.cloud.get_subnet_by_id(self.subnet_id) self.assertIsNotNone(r) self.assertDictEqual(self.mock_subnet_rep, r) self.assert_calls() def test_create_subnet(self): pool = [{'start': '192.168.199.2', 'end': '192.168.199.254'}] dns = ['8.8.8.8'] routes = [{"destination": "0.0.0.0/0", "nexthop": "123.456.78.9"}] mock_subnet_rep = copy.copy(self.mock_subnet_rep) mock_subnet_rep['allocation_pools'] = pool mock_subnet_rep['dns_nameservers'] = dns mock_subnet_rep['host_routes'] = routes self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}), dict(method='POST', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnet': mock_subnet_rep}, validate=dict( json={'subnet': { 'cidr': self.subnet_cidr, 'enable_dhcp': False, 'ip_version': 4, 'network_id': self.mock_network_rep['id'], 'allocation_pools': pool, 'dns_nameservers': dns, 'host_routes': routes}})) ]) subnet = self.cloud.create_subnet(self.network_name, self.subnet_cidr, allocation_pools=pool, dns_nameservers=dns, host_routes=routes) self.assertDictEqual(mock_subnet_rep, subnet) self.assert_calls() def test_create_subnet_string_ip_version(self): '''Allow ip_version as a string''' self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}), dict(method='POST', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnet': self.mock_subnet_rep}, validate=dict( json={'subnet': { 'cidr': self.subnet_cidr, 'enable_dhcp': False, 'ip_version': 4, 'network_id': self.mock_network_rep['id']}})) ]) subnet = self.cloud.create_subnet( self.network_name, self.subnet_cidr, ip_version='4') self.assertDictEqual(self.mock_subnet_rep, subnet) self.assert_calls() def test_create_subnet_bad_ip_version(self): '''String ip_versions must be convertable to int''' self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}) ]) with testtools.ExpectedException( exc.OpenStackCloudException, "ip_version must be an integer" ): self.cloud.create_subnet( self.network_name, self.subnet_cidr, ip_version='4x') self.assert_calls() def test_create_subnet_without_gateway_ip(self): pool = [{'start': '192.168.199.2', 'end': '192.168.199.254'}] dns = ['8.8.8.8'] mock_subnet_rep = copy.copy(self.mock_subnet_rep) mock_subnet_rep['allocation_pools'] = pool mock_subnet_rep['dns_nameservers'] = dns mock_subnet_rep['gateway_ip'] = None self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}), dict(method='POST', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnet': mock_subnet_rep}, validate=dict( json={'subnet': { 'cidr': self.subnet_cidr, 'enable_dhcp': False, 'ip_version': 4, 'network_id': self.mock_network_rep['id'], 'allocation_pools': pool, 'gateway_ip': None, 'dns_nameservers': dns}})) ]) subnet = self.cloud.create_subnet(self.network_name, self.subnet_cidr, allocation_pools=pool, dns_nameservers=dns, disable_gateway_ip=True) self.assertDictEqual(mock_subnet_rep, subnet) self.assert_calls() def test_create_subnet_with_gateway_ip(self): pool = [{'start': '192.168.199.8', 'end': '192.168.199.254'}] gateway = '192.168.199.2' dns = ['8.8.8.8'] mock_subnet_rep = copy.copy(self.mock_subnet_rep) mock_subnet_rep['allocation_pools'] = pool mock_subnet_rep['dns_nameservers'] = dns mock_subnet_rep['gateway_ip'] = gateway self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}), dict(method='POST', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnet': mock_subnet_rep}, validate=dict( json={'subnet': { 'cidr': self.subnet_cidr, 'enable_dhcp': False, 'ip_version': 4, 'network_id': self.mock_network_rep['id'], 'allocation_pools': pool, 'gateway_ip': gateway, 'dns_nameservers': dns}})) ]) subnet = self.cloud.create_subnet(self.network_name, self.subnet_cidr, allocation_pools=pool, dns_nameservers=dns, gateway_ip=gateway) self.assertDictEqual(mock_subnet_rep, subnet) self.assert_calls() def test_create_subnet_conflict_gw_ops(self): self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}) ]) gateway = '192.168.200.3' self.assertRaises(exc.OpenStackCloudException, self.cloud.create_subnet, 'kooky', self.subnet_cidr, gateway_ip=gateway, disable_gateway_ip=True) self.assert_calls() def test_create_subnet_bad_network(self): self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}) ]) self.assertRaises(exc.OpenStackCloudException, self.cloud.create_subnet, 'duck', self.subnet_cidr) self.assert_calls() def test_create_subnet_non_unique_network(self): net1 = dict(id='123', name=self.network_name) net2 = dict(id='456', name=self.network_name) self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [net1, net2]}) ]) self.assertRaises(exc.OpenStackCloudException, self.cloud.create_subnet, self.network_name, self.subnet_cidr) self.assert_calls() def test_create_subnet_from_subnetpool_with_prefixlen(self): pool = [{'start': '172.16.0.2', 'end': '172.16.0.15'}] id = '143296eb-7f47-4755-835c-488123475604' gateway = '172.16.0.1' dns = ['8.8.8.8'] routes = [{"destination": "0.0.0.0/0", "nexthop": "123.456.78.9"}] mock_subnet_rep = copy.copy(self.mock_subnet_rep) mock_subnet_rep['allocation_pools'] = pool mock_subnet_rep['dns_nameservers'] = dns mock_subnet_rep['host_routes'] = routes mock_subnet_rep['gateway_ip'] = gateway mock_subnet_rep['subnetpool_id'] = self.mock_subnetpool_rep['id'] mock_subnet_rep['cidr'] = self.subnetpool_cidr mock_subnet_rep['id'] = id self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'networks.json']), json={'networks': [self.mock_network_rep]}), dict(method='POST', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnet': mock_subnet_rep}, validate=dict( json={'subnet': { 'enable_dhcp': False, 'ip_version': 4, 'network_id': self.mock_network_rep['id'], 'allocation_pools': pool, 'dns_nameservers': dns, 'use_default_subnetpool': True, 'prefixlen': self.prefix_length, 'host_routes': routes}})) ]) subnet = self.cloud.create_subnet(self.network_name, allocation_pools=pool, dns_nameservers=dns, use_default_subnetpool=True, prefixlen=self.prefix_length, host_routes=routes) self.assertDictEqual(mock_subnet_rep, subnet) self.assert_calls() def test_delete_subnet(self): self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': [self.mock_subnet_rep]}), dict(method='DELETE', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets', '%s.json' % self.subnet_id]), json={}) ]) self.assertTrue(self.cloud.delete_subnet(self.subnet_name)) self.assert_calls() def test_delete_subnet_not_found(self): self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': []}) ]) self.assertFalse(self.cloud.delete_subnet('goofy')) self.assert_calls() def test_delete_subnet_multiple_found(self): subnet1 = dict(id='123', name=self.subnet_name) subnet2 = dict(id='456', name=self.subnet_name) self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': [subnet1, subnet2]}) ]) self.assertRaises(exc.OpenStackCloudException, self.cloud.delete_subnet, self.subnet_name) self.assert_calls() def test_delete_subnet_multiple_using_id(self): subnet1 = dict(id='123', name=self.subnet_name) subnet2 = dict(id='456', name=self.subnet_name) self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': [subnet1, subnet2]}), dict(method='DELETE', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets', '%s.json' % subnet1['id']]), json={}) ]) self.assertTrue(self.cloud.delete_subnet(subnet1['id'])) self.assert_calls() def test_update_subnet(self): expected_subnet = copy.copy(self.mock_subnet_rep) expected_subnet['name'] = 'goofy' self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': [self.mock_subnet_rep]}), dict(method='PUT', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets', '%s.json' % self.subnet_id]), json={'subnet': expected_subnet}, validate=dict( json={'subnet': {'name': 'goofy'}})) ]) subnet = self.cloud.update_subnet(self.subnet_id, subnet_name='goofy') self.assertDictEqual(expected_subnet, subnet) self.assert_calls() def test_update_subnet_gateway_ip(self): expected_subnet = copy.copy(self.mock_subnet_rep) gateway = '192.168.199.3' expected_subnet['gateway_ip'] = gateway self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': [self.mock_subnet_rep]}), dict(method='PUT', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets', '%s.json' % self.subnet_id]), json={'subnet': expected_subnet}, validate=dict( json={'subnet': {'gateway_ip': gateway}})) ]) subnet = self.cloud.update_subnet(self.subnet_id, gateway_ip=gateway) self.assertDictEqual(expected_subnet, subnet) self.assert_calls() def test_update_subnet_disable_gateway_ip(self): expected_subnet = copy.copy(self.mock_subnet_rep) expected_subnet['gateway_ip'] = None self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets.json']), json={'subnets': [self.mock_subnet_rep]}), dict(method='PUT', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'subnets', '%s.json' % self.subnet_id]), json={'subnet': expected_subnet}, validate=dict( json={'subnet': {'gateway_ip': None}})) ]) subnet = self.cloud.update_subnet(self.subnet_id, disable_gateway_ip=True) self.assertDictEqual(expected_subnet, subnet) self.assert_calls() def test_update_subnet_conflict_gw_ops(self): self.assertRaises(exc.OpenStackCloudException, self.cloud.update_subnet, self.subnet_id, gateway_ip="192.168.199.3", disable_gateway_ip=True)
Save
cmd:
run