1
# Copyright 2014 OpenStack Foundation
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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
18
from neutron.tests.tempest.api.network import base
19
from neutron.tests.tempest import config
20
from neutron.tests.tempest import test
25
class AllowedAddressPairTestJSON(base.BaseNetworkTest):
28
Tests the Neutron Allowed Address Pair API extension using the Tempest
29
ReST client. The following API operations are tested with this extension:
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
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']
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)
67
# Confirm port was created with allowed address pair attribute
68
body = self.client.list_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)
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
84
# Update allowed address pair attribute of port
85
allowed_address_pairs = [{'ip_address': address,
86
'mac_address': mac_address}]
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)
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)
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)
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']
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)
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)
133
class AllowedAddressPairIpV6TestJSON(AllowedAddressPairTestJSON):