~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/tempest/api/network/admin/test_external_network_extension.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
2
#    not use this file except in compliance with the License. You may obtain
 
3
#    a copy of the License at
 
4
#
 
5
#         http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
7
#    Unless required by applicable law or agreed to in writing, software
 
8
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
9
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
10
#    License for the specific language governing permissions and limitations
 
11
#    under the License.
 
12
 
 
13
from tempest_lib.common.utils import data_utils
 
14
 
 
15
from neutron.tests.tempest.api.network import base
 
16
from neutron.tests.tempest import test
 
17
 
 
18
 
 
19
class ExternalNetworksTestJSON(base.BaseAdminNetworkTest):
 
20
 
 
21
    @classmethod
 
22
    def resource_setup(cls):
 
23
        super(ExternalNetworksTestJSON, cls).resource_setup()
 
24
        cls.network = cls.create_network()
 
25
 
 
26
    def _create_network(self, external=True):
 
27
        post_body = {'name': data_utils.rand_name('network-')}
 
28
        if external:
 
29
            post_body['router:external'] = external
 
30
        body = self.admin_client.create_network(**post_body)
 
31
        network = body['network']
 
32
        self.addCleanup(self.admin_client.delete_network, network['id'])
 
33
        return network
 
34
 
 
35
    @test.idempotent_id('462be770-b310-4df9-9c42-773217e4c8b1')
 
36
    def test_create_external_network(self):
 
37
        # Create a network as an admin user specifying the
 
38
        # external network extension attribute
 
39
        ext_network = self._create_network()
 
40
        # Verifies router:external parameter
 
41
        self.assertIsNotNone(ext_network['id'])
 
42
        self.assertTrue(ext_network['router:external'])
 
43
 
 
44
    @test.idempotent_id('4db5417a-e11c-474d-a361-af00ebef57c5')
 
45
    def test_update_external_network(self):
 
46
        # Update a network as an admin user specifying the
 
47
        # external network extension attribute
 
48
        network = self._create_network(external=False)
 
49
        self.assertFalse(network.get('router:external', False))
 
50
        update_body = {'router:external': True}
 
51
        body = self.admin_client.update_network(network['id'],
 
52
                                                **update_body)
 
53
        updated_network = body['network']
 
54
        # Verify that router:external parameter was updated
 
55
        self.assertTrue(updated_network['router:external'])
 
56
 
 
57
    @test.idempotent_id('39be4c9b-a57e-4ff9-b7c7-b218e209dfcc')
 
58
    def test_list_external_networks(self):
 
59
        # Create external_net
 
60
        external_network = self._create_network()
 
61
        # List networks as a normal user and confirm the external
 
62
        # network extension attribute is returned for those networks
 
63
        # that were created as external
 
64
        body = self.client.list_networks()
 
65
        networks_list = [net['id'] for net in body['networks']]
 
66
        self.assertIn(external_network['id'], networks_list)
 
67
        self.assertIn(self.network['id'], networks_list)
 
68
        for net in body['networks']:
 
69
            if net['id'] == self.network['id']:
 
70
                self.assertFalse(net['router:external'])
 
71
            elif net['id'] == external_network['id']:
 
72
                self.assertTrue(net['router:external'])
 
73
 
 
74
    @test.idempotent_id('2ac50ab2-7ebd-4e27-b3ce-a9e399faaea2')
 
75
    def test_show_external_networks_attribute(self):
 
76
        # Create external_net
 
77
        external_network = self._create_network()
 
78
        # Show an external network as a normal user and confirm the
 
79
        # external network extension attribute is returned.
 
80
        body = self.client.show_network(external_network['id'])
 
81
        show_ext_net = body['network']
 
82
        self.assertEqual(external_network['name'], show_ext_net['name'])
 
83
        self.assertEqual(external_network['id'], show_ext_net['id'])
 
84
        self.assertTrue(show_ext_net['router:external'])
 
85
        body = self.client.show_network(self.network['id'])
 
86
        show_net = body['network']
 
87
        # Verify with show that router:external is False for network
 
88
        self.assertEqual(self.network['name'], show_net['name'])
 
89
        self.assertEqual(self.network['id'], show_net['id'])
 
90
        self.assertFalse(show_net['router:external'])
 
91
 
 
92
    @test.idempotent_id('82068503-2cf2-4ed4-b3be-ecb89432e4bb')
 
93
    def test_delete_external_networks_with_floating_ip(self):
 
94
        """Verifies external network can be deleted while still holding
 
95
        (unassociated) floating IPs
 
96
 
 
97
        """
 
98
        # Set cls.client to admin to use base.create_subnet()
 
99
        client = self.admin_client
 
100
        body = client.create_network(**{'router:external': True})
 
101
        external_network = body['network']
 
102
        self.addCleanup(self._try_delete_resource,
 
103
                        client.delete_network,
 
104
                        external_network['id'])
 
105
        subnet = self.create_subnet(external_network, client=client,
 
106
                                    enable_dhcp=False)
 
107
        body = client.create_floatingip(
 
108
            floating_network_id=external_network['id'])
 
109
        created_floating_ip = body['floatingip']
 
110
        self.addCleanup(self._try_delete_resource,
 
111
                        client.delete_floatingip,
 
112
                        created_floating_ip['id'])
 
113
        floatingip_list = client.list_floatingips(
 
114
            network=external_network['id'])
 
115
        self.assertIn(created_floating_ip['id'],
 
116
                      (f['id'] for f in floatingip_list['floatingips']))
 
117
        client.delete_network(external_network['id'])
 
118
        # Verifies floating ip is deleted
 
119
        floatingip_list = client.list_floatingips()
 
120
        self.assertNotIn(created_floating_ip['id'],
 
121
                         (f['id'] for f in floatingip_list['floatingips']))
 
122
        # Verifies subnet is deleted
 
123
        subnet_list = client.list_subnets()
 
124
        self.assertNotIn(subnet['id'],
 
125
                         (s['id'] for s in subnet_list))
 
126
        # Removes subnet from the cleanup list
 
127
        self.subnets.remove(subnet)