Exemplo n.º 1
0
 def test_cleanup_on_vm_delete(self):
     with mock.patch.object(self.ovsdb_handler, 'handle_trunk_remove'):
         br_int = ovs_lib.OVSBridge(self.br_int)
         ports = self._fill_trunk_dict()
         self.setup_agent_and_ports(port_dicts=ports[:1])
         self.wait_until_ports_state(self.ports, up=True)
         self.trunk_br.delete_port(self.trunk_port_name)
         # We do not expect any instance port to show up on the trunk
         # bridge so we can set a much more aggressive timeout and
         # fail fast(er).
         self.ovsdb_handler.timeout = 1
         self.ovsdb_handler.handle_trunk_add(self.trunk_br.br_name)
         # Check no resources are left behind.
         self.assertFalse(self.trunk_br.exists())
         self.assertFalse(ovsdb_handler.bridge_has_service_port(br_int))
Exemplo n.º 2
0
    def test_trunk_lifecycle(self):
        """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
        """

        vlan_aware_vm = self.create_vlan_aware_vm(self.trunk_network, [self.vlan1_network])
        trunk_id = vlan_aware_vm.trunk["id"]

        # Create helper vms with different networks
        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()

        # Test connectivity to trunk and subport
        vlan_aware_vm.block_until_ping(trunk_network_vm.ip)
        vlan_aware_vm.block_until_ping(vlan1_network_vm.ip)

        # Subport for vlan2 hasn't been added yet
        vlan_aware_vm.block_until_no_ping(vlan2_network_vm.ip)

        # Add another subport and test
        self.add_subport_to_vm(vlan_aware_vm, self.vlan2_network)
        vlan_aware_vm.block_until_ping(vlan2_network_vm.ip)

        # Remove the first subport
        self.safe_client.trunk_remove_subports(self.tenant_id, trunk_id, [vlan_aware_vm.trunk["sub_ports"][0]])

        # vlan1_network_vm now shouldn't be able to talk to vlan_aware_vm
        vlan_aware_vm.block_until_no_ping(vlan1_network_vm.ip)

        # but trunk and vlan2 should be able to ping
        vlan_aware_vm.block_until_ping(trunk_network_vm.ip)
        vlan_aware_vm.block_until_ping(vlan2_network_vm.ip)

        # Delete vm and check that patch ports and trunk bridge are gone
        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:
            # Create exception object after timeout to provide up-to-date list
            # of interfaces
            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())
            )
Exemplo n.º 3
0
    def test_trunk_lifecycle(self):
        """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
        """

        vlan_aware_vm = self.create_vlan_aware_vm(self.trunk_network,
                                                  [self.vlan1_network])
        trunk_id = vlan_aware_vm.trunk['id']

        # Create helper vms with different networks
        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()

        # Test connectivity to trunk and subport
        vlan_aware_vm.block_until_ping(trunk_network_vm.ip)
        vlan_aware_vm.block_until_ping(vlan1_network_vm.ip)

        # Subport for vlan2 hasn't been added yet
        vlan_aware_vm.block_until_no_ping(vlan2_network_vm.ip)

        # Add another subport and test
        self.add_subport_to_vm(vlan_aware_vm, self.vlan2_network)
        vlan_aware_vm.block_until_ping(vlan2_network_vm.ip)

        # Remove the first subport
        self.safe_client.trunk_remove_subports(
            self.tenant_id, trunk_id, [vlan_aware_vm.trunk['sub_ports'][0]])

        # vlan1_network_vm now shouldn't be able to talk to vlan_aware_vm
        vlan_aware_vm.block_until_no_ping(vlan1_network_vm.ip)

        # but trunk and vlan2 should be able to ping
        vlan_aware_vm.block_until_ping(trunk_network_vm.ip)
        vlan_aware_vm.block_until_ping(vlan2_network_vm.ip)

        # Delete vm and check that patch ports and trunk bridge are gone
        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:
            # Create exception object after timeout to provide up-to-date list
            # of interfaces
            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()))