'Test trunk creation and subport transition to ACTIVE status.
This is a basic test for the trunk extension to ensure that we
can create a trunk, attach it to a server, add/remove subports,
while ensuring the status transitions as appropriate.
This test does not assert any dataplane behavior for the subports.
It\'s just a high-level check to ensure the agents claim to have
wired the port correctly and that the trunk port itself maintains
connectivity.'

@decorators.idempotent_id('bb13fe28-f152-4000-8131-37890a40c79e')
def test_trunk_subport_lifecycle(self):

    server1 = self._create_server_with_trunk_port()
    server2 = self._create_server_with_trunk_port()
    for server in (server1, server2):
        self._wait_for_server(server)
    (trunk1_id, trunk2_id) = (server1['trunk']['id'], server2['trunk']['id'])
    utils.wait_until_true((lambda : self._is_trunk_active(trunk1_id)), exception=RuntimeError(('Timed    out    waiting    for    trunk    %s    to    transition    to    ACTIVE.' % trunk1_id)))
    utils.wait_until_true((lambda : self._is_trunk_active(trunk2_id)), exception=RuntimeError(('Timed    out    waiting    for    trunk    %s    to    transition    to    ACTIVE.' % trunk2_id)))
    subports = [{'port_id': self.create_port(self.create_network())['id'], 'segmentation_type': 'vlan', 'segmentation_id': seg_id} for seg_id in range(3, 7)]
    self.client.add_subports(trunk1_id, subports)
    utils.wait_until_true((lambda : self._is_trunk_active(trunk1_id)), exception=RuntimeError(('Timed    out    waiting    for    trunk    %s    to    transition    to    ACTIVE.' % trunk1_id)))
    for s in subports:
        utils.wait_until_true((lambda : self._is_port_active(s['port_id'])))
    self.check_connectivity(server1['fip']['floating_ip_address'], CONF.validation.image_ssh_user, self.keypair['private_key'])
    self.client.remove_subports(trunk1_id, subports)
    for s in subports:
        utils.wait_until_true((lambda : self._is_port_down(s['port_id'])), exception=RuntimeError(('Timed    out    waiting    for    subport    %s    to    transition    to    DOWN.' % s['port_id'])))
    self.client.add_subports(trunk2_id, subports)
    utils.wait_until_true((lambda : self._is_trunk_active(trunk1_id)), exception=RuntimeError(('Timed    out    waiting    for    trunk    %s    to    transition    to    ACTIVE.' % trunk1_id)))
    utils.wait_until_true((lambda : self._is_trunk_active(trunk2_id)), exception=RuntimeError(('Timed    out    waiting    for    trunk    %s    to    transition    to    ACTIVE.' % trunk2_id)))
    for s in subports:
        utils.wait_until_true((lambda : self._is_port_active(s['port_id'])), exception=RuntimeError(('Timed    out    waiting    for    subport    %s    to    transition    to    ACTIVE.' % s['port_id'])))
    self.check_connectivity(server1['fip']['floating_ip_address'], CONF.validation.image_ssh_user, self.keypair['private_key'])
    self.check_connectivity(server2['fip']['floating_ip_address'], CONF.validation.image_ssh_user, self.keypair['private_key'])
