'Test life-cycle of a fake VM with trunk port.
This test uses 4 fake machines:
- vlan_aware_vm (A) that is at the beginning connected to a trunk
network and a vlan1 network.
- trunk_network_vm (B) that is connected to the trunk network.
- vlan1_network_vm (C) that is connected to the vlan1 network.
- vlan2_network_vm (D) that is connected to a vlan2 network.
Scenario steps:
- all the vms from above are created
- A can talk with B (over the trunk network)
- A can talk with C (over the vlan1 network)
- A can not talk with D (no leg on the vlan2 network)
- subport from the vlan2 network is added to A
- A can now talk with D (over the vlan2 network)
- subport from the vlan1 network is removed from A
- A can talk with B (over the trunk network)
- A can not talk with C (no leg on the vlan1 network)
- A can talk with D (over the vlan2 network)
- A is deleted which leads to removal of trunk bridge
- no leftovers like patch ports to the trunk bridge should remain on
an integration bridge'

def test_trunk_lifecycle(self):

    vlan_aware_vm = self.create_vlan_aware_vm(self.trunk_network, [self.vlan1_network])
    trunk_id = vlan_aware_vm.trunk['id']
    trunk_network_vm = self.create_vm_in_network(self.trunk_network)
    vlan1_network_vm = self.create_vm_in_network(self.vlan1_network)
    vlan2_network_vm = self.create_vm_in_network(self.vlan2_network)
    for vm in (trunk_network_vm, vlan1_network_vm, vlan2_network_vm):
        vm.block_until_boot()
    vlan_aware_vm.block_until_ping(trunk_network_vm.ip)
    vlan_aware_vm.block_until_ping(vlan1_network_vm.ip)
    vlan_aware_vm.block_until_no_ping(vlan2_network_vm.ip)
    self.add_subport_to_vm(vlan_aware_vm, self.vlan2_network)
    vlan_aware_vm.block_until_ping(vlan2_network_vm.ip)
    self.safe_client.trunk_remove_subports(self.tenant_id, trunk_id, [vlan_aware_vm.trunk['sub_ports'][0]])
    vlan_aware_vm.block_until_no_ping(vlan1_network_vm.ip)
    vlan_aware_vm.block_until_ping(trunk_network_vm.ip)
    vlan_aware_vm.block_until_ping(vlan2_network_vm.ip)
    vlan_aware_vm.destroy()
    bridge_doesnt_exist_predicate = functools.partial(trunk_bridge_does_not_exist, trunk_id)
    utils.wait_until_true(bridge_doesnt_exist_predicate, exception=TrunkTestException(('Trunk    bridge    with    ID    %s    has    not    been    removed' % trunk_id)))
    integration_bridge = self.host.get_bridge(None)
    no_patch_ports_predicate = functools.partial((lambda bridge: (not ovsdb_handler.bridge_has_service_port(bridge))), integration_bridge)
    try:
        utils.wait_until_true(no_patch_ports_predicate)
    except utils.WaitTimeout:
        raise TrunkTestException(('Integration    bridge    %s    still    has    following    ports    while    some    of    them    are    patch    ports    for    trunk    that    were    supposed    to    be    removed:    %s' % (integration_bridge.br_name, integration_bridge.get_iface_name_list())))
