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

« back to all changes in this revision

Viewing changes to neutron/tests/tempest/api/network/test_allowed_address_pair.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
# Copyright 2014 OpenStack Foundation
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
import netaddr
 
17
 
 
18
from neutron.tests.tempest.api.network import base
 
19
from neutron.tests.tempest import config
 
20
from neutron.tests.tempest import test
 
21
 
 
22
CONF = config.CONF
 
23
 
 
24
 
 
25
class AllowedAddressPairTestJSON(base.BaseNetworkTest):
 
26
 
 
27
    """
 
28
    Tests the Neutron Allowed Address Pair API extension using the Tempest
 
29
    ReST client. The following API operations are tested with this extension:
 
30
 
 
31
        create port
 
32
        list ports
 
33
        update port
 
34
        show port
 
35
 
 
36
    v2.0 of the Neutron API is assumed. It is also assumed that the following
 
37
    options are defined in the [network-feature-enabled] section of
 
38
    etc/tempest.conf
 
39
 
 
40
        api_extensions
 
41
    """
 
42
 
 
43
    @classmethod
 
44
    def resource_setup(cls):
 
45
        super(AllowedAddressPairTestJSON, cls).resource_setup()
 
46
        if not test.is_extension_enabled('allowed-address-pairs', 'network'):
 
47
            msg = "Allowed Address Pairs extension not enabled."
 
48
            raise cls.skipException(msg)
 
49
        cls.network = cls.create_network()
 
50
        cls.create_subnet(cls.network)
 
51
        port = cls.create_port(cls.network)
 
52
        cls.ip_address = port['fixed_ips'][0]['ip_address']
 
53
        cls.mac_address = port['mac_address']
 
54
 
 
55
    @test.attr(type='smoke')
 
56
    @test.idempotent_id('86c3529b-1231-40de-803c-00e40882f043')
 
57
    def test_create_list_port_with_address_pair(self):
 
58
        # Create port with allowed address pair attribute
 
59
        allowed_address_pairs = [{'ip_address': self.ip_address,
 
60
                                  'mac_address': self.mac_address}]
 
61
        body = self.client.create_port(
 
62
            network_id=self.network['id'],
 
63
            allowed_address_pairs=allowed_address_pairs)
 
64
        port_id = body['port']['id']
 
65
        self.addCleanup(self.client.delete_port, port_id)
 
66
 
 
67
        # Confirm port was created with allowed address pair attribute
 
68
        body = self.client.list_ports()
 
69
        ports = body['ports']
 
70
        port = [p for p in ports if p['id'] == port_id]
 
71
        msg = 'Created port not found in list of ports returned by Neutron'
 
72
        self.assertTrue(port, msg)
 
73
        self._confirm_allowed_address_pair(port[0], self.ip_address)
 
74
 
 
75
    @test.attr(type='smoke')
 
76
    def _update_port_with_address(self, address, mac_address=None, **kwargs):
 
77
        # Create a port without allowed address pair
 
78
        body = self.client.create_port(network_id=self.network['id'])
 
79
        port_id = body['port']['id']
 
80
        self.addCleanup(self.client.delete_port, port_id)
 
81
        if mac_address is None:
 
82
            mac_address = self.mac_address
 
83
 
 
84
        # Update allowed address pair attribute of port
 
85
        allowed_address_pairs = [{'ip_address': address,
 
86
                                  'mac_address': mac_address}]
 
87
        if kwargs:
 
88
            allowed_address_pairs.append(kwargs['allowed_address_pairs'])
 
89
        body = self.client.update_port(
 
90
            port_id, allowed_address_pairs=allowed_address_pairs)
 
91
        allowed_address_pair = body['port']['allowed_address_pairs']
 
92
        self.assertEqual(allowed_address_pair, allowed_address_pairs)
 
93
 
 
94
    @test.attr(type='smoke')
 
95
    @test.idempotent_id('9599b337-272c-47fd-b3cf-509414414ac4')
 
96
    def test_update_port_with_address_pair(self):
 
97
        # Update port with allowed address pair
 
98
        self._update_port_with_address(self.ip_address)
 
99
 
 
100
    @test.attr(type='smoke')
 
101
    @test.idempotent_id('4d6d178f-34f6-4bff-a01c-0a2f8fe909e4')
 
102
    def test_update_port_with_cidr_address_pair(self):
 
103
        # Update allowed address pair with cidr
 
104
        cidr = str(netaddr.IPNetwork(CONF.network.tenant_network_cidr))
 
105
        self._update_port_with_address(cidr)
 
106
 
 
107
    @test.attr(type='smoke')
 
108
    @test.idempotent_id('b3f20091-6cd5-472b-8487-3516137df933')
 
109
    def test_update_port_with_multiple_ip_mac_address_pair(self):
 
110
        # Create an ip _address and mac_address through port create
 
111
        resp = self.client.create_port(network_id=self.network['id'])
 
112
        newportid = resp['port']['id']
 
113
        self.addCleanup(self.client.delete_port, newportid)
 
114
        ipaddress = resp['port']['fixed_ips'][0]['ip_address']
 
115
        macaddress = resp['port']['mac_address']
 
116
 
 
117
        # Update allowed address pair port with multiple ip and  mac
 
118
        allowed_address_pairs = {'ip_address': ipaddress,
 
119
                                 'mac_address': macaddress}
 
120
        self._update_port_with_address(
 
121
            self.ip_address, self.mac_address,
 
122
            allowed_address_pairs=allowed_address_pairs)
 
123
 
 
124
    def _confirm_allowed_address_pair(self, port, ip):
 
125
        msg = 'Port allowed address pairs should not be empty'
 
126
        self.assertTrue(port['allowed_address_pairs'], msg)
 
127
        ip_address = port['allowed_address_pairs'][0]['ip_address']
 
128
        mac_address = port['allowed_address_pairs'][0]['mac_address']
 
129
        self.assertEqual(ip_address, ip)
 
130
        self.assertEqual(mac_address, self.mac_address)
 
131
 
 
132
 
 
133
class AllowedAddressPairIpV6TestJSON(AllowedAddressPairTestJSON):
 
134
    _ip_version = 6