Add allowed-address-pairs to port-update

--allowed-address-pair and --no-allowed-address-pairs have been
 newly defined to port-create and port-update.
If you would like to disable allowed-address-pairs, you can use
--no-address-pairs option.

Change-Id: I4811bd1f8d48c34b6d3f20347e4d45625586ac86
Closes-Bug: #1485182
This commit is contained in:
Hideki Saito 2015-08-29 15:39:07 +09:00
parent 61c187d8ef
commit 3b1c1c2395
3 changed files with 154 additions and 4 deletions

View File

@ -28,7 +28,7 @@ fi
echo "NOTE: User should be admin in order to perform all operations."
sleep 3
FORMAT=" --request-format xml"
FORMAT=" --request-format json"
# test the CRUD of network
network=$net_name
@ -78,9 +78,30 @@ port_id=`neutron port-list $FORMAT -- --name $port --fields id | tail -n 2 | hea
echo "ID of port with name $port is $port_id"
neutron port-show $FORMAT $port || die "fail to show port $port"
neutron port-show $FORMAT $port_id || die "fail to show port $port_id"
neutron port-update $FORMAT $port --device_id deviceid1 || die "fail to update port $port"
neutron port-update $FORMAT $port_id --device_id deviceid2 || die "fail to update port $port_id"
neutron port-update $FORMAT $port_id --allowed-address-pair ip_address=1.1.1.11,mac_address=10:00:00:00:00:00 --allowed-address-pair ip_address=1.1.1.12,mac_address=10:00:00:00:00:01 || die "fail to update port $port_id --allowed-address-pair"
neutron port-show $FORMAT $port || die "fail to show port $port"
neutron port-show $FORMAT $port_id || die "fail to show port $port_id"
neutron port-update $FORMAT $port_id --no-allowed-address-pairs || die "fail to update port $port_id --no-allowed-address-pairs"
neutron port-show $FORMAT $port || die "fail to show port $port"
neutron port-show $FORMAT $port_id || die "fail to show port $port_id"
neutron port-delete $port_id
# test the create port with allowed-address-pairs
port=$port_name
neutron port-create $FORMAT $NOAUTH $network --name $port -- --allowed-address-pairs type=dict list=true ip_address=1.1.1.11,mac_address=10:00:00:00:00:00 ip_address=1.1.1.12,mac_address=10:00:00:00:00:01 || die "fail to create port $port"
tempport=`neutron port-list $FORMAT -- --name $port --fields id | wc -l`
echo $tempport
if [ $tempport -ne 5 ]; then
die "ports with name $port is not unique or found"
fi
port_id=`neutron port-list $FORMAT -- --name $port --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2`
echo "ID of port with name $port is $port_id"
neutron port-show $FORMAT $port || die "fail to show port $port"
neutron port-show $FORMAT $port_id || die "fail to show port $port_id"
neutron port-update $FORMAT $port_id --no-allowed-address-pairs || die "fail to update port $port_id --no-allowed-address-pairs"
neutron port-show $port_id
# test quota commands RUD
DEFAULT_NETWORKS=10

View File

@ -193,8 +193,35 @@ class UpdateExtraDhcpOptMixin(object):
port['extra_dhcp_opts'] = ops
class UpdatePortAllowedAddressPair(object):
"""Update Port for allowed_address_pairs"""
def add_arguments_allowedaddresspairs(self, parser):
group_aap = parser.add_mutually_exclusive_group()
group_aap.add_argument(
'--allowed-address-pair',
metavar='ip_address=IP_ADDR[,mac_address=MAC_ADDR]',
default=[],
action='append',
dest='allowed_address_pairs',
type=utils.str2dict,
help=_('Allowed address pair associated with the port.'
'You can repeat this option.'))
group_aap.add_argument(
'--no-allowed-address-pairs',
action='store_true',
help=_('Associate no allowed address pairs with the port.'))
def args2body_allowedaddresspairs(self, parsed_args, port):
if parsed_args.allowed_address_pairs:
port['allowed_address_pairs'] = parsed_args.allowed_address_pairs
elif parsed_args.no_allowed_address_pairs:
port['allowed_address_pairs'] = []
class CreatePort(neutronV20.CreateCommand, UpdatePortSecGroupMixin,
UpdateExtraDhcpOptMixin, qos_policy.CreateQosPolicyMixin):
UpdateExtraDhcpOptMixin, qos_policy.CreateQosPolicyMixin,
UpdatePortAllowedAddressPair):
"""Create a port for a given tenant."""
resource = 'port'
@ -232,6 +259,7 @@ class CreatePort(neutronV20.CreateCommand, UpdatePortSecGroupMixin,
self.add_arguments_secgroup(parser)
self.add_arguments_extradhcpopt(parser)
self.add_arguments_qos_policy(parser)
self.add_arguments_allowedaddresspairs(parser)
parser.add_argument(
'network_id', metavar='NETWORK',
@ -257,6 +285,7 @@ class CreatePort(neutronV20.CreateCommand, UpdatePortSecGroupMixin,
self.args2body_secgroup(parsed_args, body)
self.args2body_extradhcpopt(parsed_args, body)
self.args2body_qos_policy(parsed_args, body)
self.args2body_allowedaddresspairs(parsed_args, body)
return {'port': body}
@ -268,7 +297,8 @@ class DeletePort(neutronV20.DeleteCommand):
class UpdatePort(neutronV20.UpdateCommand, UpdatePortSecGroupMixin,
UpdateExtraDhcpOptMixin, qos_policy.UpdateQosPolicyMixin):
UpdateExtraDhcpOptMixin, qos_policy.UpdateQosPolicyMixin,
UpdatePortAllowedAddressPair):
"""Update port's information."""
resource = 'port'
@ -286,6 +316,7 @@ class UpdatePort(neutronV20.UpdateCommand, UpdatePortSecGroupMixin,
self.add_arguments_secgroup(parser)
self.add_arguments_extradhcpopt(parser)
self.add_arguments_qos_policy(parser)
self.add_arguments_allowedaddresspairs(parser)
def args2body(self, parsed_args):
body = {}
@ -297,5 +328,6 @@ class UpdatePort(neutronV20.UpdateCommand, UpdatePortSecGroupMixin,
self.args2body_secgroup(parsed_args, body)
self.args2body_extradhcpopt(parsed_args, body)
self.args2body_qos_policy(parsed_args, body)
self.args2body_allowedaddresspairs(parsed_args, body)
return {'port': body}

View File

@ -302,6 +302,54 @@ class CLITestV20PortJSON(test_cli20.CLITestV20Base):
self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values)
def test_create_port_with_allowed_address_pair_ipaddr(self):
"""Create port:
--allowed-address-pair ip_address=addr0
--allowed-address-pair ip_address=addr1
"""
resource = 'port'
cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
pairs = [{'ip_address': '123.123.123.123'},
{'ip_address': '123.123.123.45'}]
args = [netid,
'--allowed-address-pair',
'ip_address=123.123.123.123',
'--allowed-address-pair',
'ip_address=123.123.123.45']
position_names = ['network_id', 'allowed_address_pairs']
position_values = [netid, pairs]
position_values.extend([netid])
self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values)
def test_create_port_with_allowed_address_pair(self):
"""Create port:
--allowed-address-pair ip_address=addr0,mac_address=mac0
--allowed-address-pair ip_address=addr1,mac_address=mac1
"""
resource = 'port'
cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
myid = 'myid'
netid = 'netid'
pairs = [{'ip_address': '123.123.123.123',
'mac_address': '10:00:00:00:00:00'},
{'ip_address': '123.123.123.45',
'mac_address': '10:00:00:00:00:01'}]
args = [netid,
'--allowed-address-pair',
'ip_address=123.123.123.123,mac_address=10:00:00:00:00:00',
'--allowed-address-pair',
'ip_address=123.123.123.45,mac_address=10:00:00:00:00:01']
position_names = ['network_id', 'allowed_address_pairs']
position_values = [netid, pairs]
position_values.extend([netid])
self._test_create_resource(resource, cmd, name, myid, args,
position_names, position_values)
def test_list_ports(self):
"""List ports: -D."""
resources = "ports"
@ -599,6 +647,55 @@ class CLITestV20PortJSON(test_cli20.CLITestV20Base):
['--no-security-groups', 'myid'],
{'security_groups': []})
def test_update_port_allowed_address_pair_ipaddr(self):
"""Update port(ip_address only):
--allowed-address-pairs ip_address=addr0
--allowed-address-pairs ip_address=addr1
"""
import sys
resource = 'port'
cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
myid = 'myid'
pairs = [{'ip_address': '123.123.123.123'},
{'ip_address': '123.123.123.45'}]
args = [myid,
'--allowed-address-pair',
'ip_address=123.123.123.123',
'--allowed-address-pair',
'ip_address=123.123.123.45']
updatefields = {'allowed_address_pairs': pairs}
self._test_update_resource(resource, cmd, myid, args, updatefields)
def test_update_port_allowed_address_pair(self):
"""Update port:
--allowed-address-pair
ip_address=addr0,mac_address=mac0
--allowed-address-pair
ip_address_addr1,mac_address=mac1
"""
resource = 'port'
cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
myid = 'myid'
pairs = [{'ip_address': '123.123.123.123',
'mac_address': '10:00:00:00:00:00'},
{'ip_address': '123.123.123.45',
'mac_address': '10:00:00:00:00:01'}]
args = [myid,
'--allowed-address-pair',
'ip_address=123.123.123.123,mac_address=10:00:00:00:00:00',
'--allowed-address-pair',
'ip_address=123.123.123.45,mac_address=10:00:00:00:00:01']
updatefields = {'allowed_address_pairs': pairs}
self._test_update_resource(resource, cmd, myid, args, updatefields)
def test_update_port_allowed_address_pairs_off(self):
"""Update port: --no-allowed-address-pairs."""
resource = 'port'
cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
self._test_update_resource(resource, cmd, 'myid',
['--no-allowed-address-pairs', 'myid'],
{'allowed_address_pairs': []})
def test_show_port(self):
"""Show port: --fields id --fields name myid."""
resource = 'port'