def run_once(self):
     self._server = None
     self._server_ip = None
     self._ethernet_pair = None
     self._shill_proxy = shill_proxy.ShillProxy()
     try:
         # TODO(zqiu): enable DHCPv6 for peer interface, either by restarting
         # shill with appropriate command line options or via a new DBUS
         # command.
         self._ethernet_pair = virtual_ethernet_pair.VirtualEthernetPair(
                 interface_ip=None,
                 peer_interface_name='pseudoethernet0',
                 peer_interface_ip=None,
                 interface_ipv6=dhcpv6_test_server.DHCPV6_SERVER_ADDRESS)
         self._ethernet_pair.setup()
         if not self._ethernet_pair.is_healthy:
             raise error.TestFail('Could not create virtual ethernet pair.')
         self._server_ip = self._ethernet_pair.interface_ip
         self._server = dhcpv6_test_server.Dhcpv6TestServer(
                 self._ethernet_pair.interface_name)
         self._server.start()
         self.test_body()
     except (error.TestFail, error.TestNAError):
         # Pass these through without modification.
         raise
     except Exception as e:
         logging.error('Caught exception: %s.', str(e))
         logging.error('Trace: %s', traceback.format_exc())
         raise error.TestFail('Caught exception: %s.' % str(e))
     finally:
         if self._server is not None:
             self._server.stop()
         if self._ethernet_pair is not None:
             self._ethernet_pair.teardown()
Exemple #2
0
    def run_vpn_test(self, vpn_type):
        """Run a vpn test of |vpn_type|.

        @param vpn_type string type of VPN test to run.

        """
        manager = self._shill_proxy.manager
        server_address_and_prefix = '%s/%d' % (self.SERVER_ADDRESS,
                                               self.NETWORK_PREFIX)
        client_address_and_prefix = '%s/%d' % (self.CLIENT_ADDRESS,
                                               self.NETWORK_PREFIX)
        self._vpn_type = vpn_type
        self._expect_success = 'incorrect' not in vpn_type

        with shill_temporary_profile.ShillTemporaryProfile(
                manager, profile_name=self.TEST_PROFILE_NAME):
            with virtual_ethernet_pair.VirtualEthernetPair(
                    interface_name=self.SERVER_INTERFACE_NAME,
                    peer_interface_name=self.CLIENT_INTERFACE_NAME,
                    peer_interface_ip=client_address_and_prefix,
                    interface_ip=server_address_and_prefix,
                    ignore_shutdown_errors=True) as ethernet_pair:
                if not ethernet_pair.is_healthy:
                    raise error.TestFail('Virtual ethernet pair failed.')

                # When shill finds this ethernet interface, it will reset
                # its IP address and start a DHCP client.  We must configure
                # the static IP address through shill.
                self.configure_static_ip(self.CLIENT_INTERFACE_NAME,
                                         self.CLIENT_ADDRESS,
                                         self.NETWORK_PREFIX)

                with self.get_vpn_server() as server:
                    self.connect_vpn()
                    site_utils.ping(server.SERVER_IP_ADDRESS, tries=3)
 def run_once(self):
     self._server = None
     self._server_ip = None
     self._ethernet_pair = None
     self._server = None
     self._shill_proxy = shill_proxy.ShillProxy()
     try:
         self._ethernet_pair = virtual_ethernet_pair.VirtualEthernetPair(
                 peer_interface_name='pseudoethernet0',
                 peer_interface_ip=None)
         self._ethernet_pair.setup()
         if not self._ethernet_pair.is_healthy:
             raise error.TestFail('Could not create virtual ethernet pair.')
         self._server_ip = self._ethernet_pair.interface_ip
         self._server = dhcp_test_server.DhcpTestServer(
                 self._ethernet_pair.interface_name)
         self._server.start()
         if not self._server.is_healthy:
             raise error.TestFail('Could not start DHCP test server.')
         self._subnet_mask = self._ethernet_pair.interface_subnet_mask
         self.test_body()
     except (error.TestFail, error.TestNAError):
         # Pass these through without modification.
         raise
     except Exception as e:
         logging.error('Caught exception: %s.', str(e))
         logging.error('Trace: %s', traceback.format_exc())
         raise error.TestFail('Caught exception: %s.' % str(e))
     finally:
         if self._server is not None:
             self._server.stop()
         if self._ethernet_pair is not None:
             self._ethernet_pair.teardown()
    def run_once(self):
        """Test main loop."""
        self._shill_proxy = shill_proxy.ShillProxy()
        manager = self._shill_proxy.manager

        with shill_temporary_profile.ShillTemporaryProfile(
                manager, profile_name=self.TEST_PROFILE_NAME):
            with virtual_ethernet_pair.VirtualEthernetPair(
                    peer_interface_name=self.INTERFACE_NAME,
                    peer_interface_ip=None) as ethernet_pair:
                if not ethernet_pair.is_healthy:
                    raise error.TestFail('Virtual ethernet pair failed.')

                if self.get_authenticated_flag(self.INTERFACE_NAME):
                    raise error.TestFail('Authentication flag already set.')

                with hostapd_server.HostapdServer(
                        interface=ethernet_pair.interface_name) as hostapd:
                    # Wait for hostapd to initialize.
                    time.sleep(1)
                    if not hostapd.running():
                        raise error.TestFail('hostapd process exited.')

                    self.configure_credentials(self.INTERFACE_NAME)
                    hostapd.send_eap_packets()
                    if not self.wait_for_authentication(self.INTERFACE_NAME):
                        raise error.TestFail('Authentication did not complete.')

                    client_mac_address = ethernet_pair.peer_interface_mac
                    if not hostapd.client_has_authenticated(client_mac_address):
                        raise error.TestFail('Server does not agree that '
                                             'client is authenticated')

                    if hostapd.client_has_logged_off(client_mac_address):
                        raise error.TestFail('Client has already logged off')

                    # Since the EAP credentials are associated with the
                    # top-most profile, popping it should cause the client
                    # to immediately log-off.
                    manager.PopProfile(self.TEST_PROFILE_NAME)

                    if self.get_authenticated_flag(self.INTERFACE_NAME):
                        raise error.TestFail('Client is still authenticated.')

                    if not hostapd.client_has_logged_off(client_mac_address):
                        raise error.TestFail('Client did not log off')

                    # Re-pushing the profile should make the EAP credentials
                    # available again, and should cause the client to
                    # re-authenticate.
                    manager.PushProfile(self.TEST_PROFILE_NAME)

                    if not self.wait_for_authentication(self.INTERFACE_NAME):
                        raise error.TestFail('Re-authentication did not '
                                             'complete.')
Exemple #5
0
 def start(self):
     """Start up the chrooted Avahi instance."""
     # Prevent weird interactions between services which talk to Avahi.
     # TODO(wiley) Does Chrome need to die here as well?
     self._services = service_stopper.ServiceStopper(self.SERVICES_TO_STOP)
     self._services.stop_services()
     # We don't want Avahi talking to the real world, so give it a nice
     # fake interface to use.  We'll watch the other half of the pair.
     self._vif = virtual_ethernet_pair.VirtualEthernetPair(
         interface_name=self.unchrooted_interface_name,
         peer_interface_name=self.AVAHI_IF_NAME,
         interface_ip=self.MONITOR_IF_IP.netblock,
         peer_interface_ip=self.AVAHI_IF_IP.netblock,
         # Moving one end into the chroot causes errors.
         ignore_shutdown_errors=True)
     self._vif.setup()
     if not self._vif.is_healthy:
         raise error.TestError('Failed to setup virtual ethernet pair.')
     # By default, take a packet capture of everything Avahi sends out.
     self._tcpdump = tcpdump.Tcpdump(self.unchrooted_interface_name,
                                     self.TCPDUMP_FILE_PATH)
     # We're going to run Avahi in a network namespace to avoid interactions
     # with the outside world.
     self._chroot = network_chroot.NetworkChroot(
         self.AVAHI_IF_NAME, self.AVAHI_IF_IP.addr,
         self.AVAHI_IF_IP.prefix_len)
     self._chroot.add_config_templates(self.AVAHI_CONFIGS)
     self._chroot.add_root_directories(['etc/avahi', 'etc/avahi/services'])
     self._chroot.add_copied_config_files(
         ['etc/resolv.conf', 'etc/avahi/hosts'])
     self._chroot.add_startup_command(
         '/usr/sbin/avahi-daemon --file=/%s >%s 2>&1' %
         (self.AVAHI_CONFIG_FILE, self.AVAHI_LOG_FILE))
     self._chroot.bridge_dbus_namespaces()
     self._chroot.startup()
     # Wait for Avahi to come up, claim its DBus name, settle on a hostname.
     start_time = time.time()
     while time.time() - start_time < self.AVAHI_UP_TIMEOUT_SECONDS:
         if avahi_utils.avahi_ping():
             break
         time.sleep(0.2)
     else:
         raise error.TestFail('Avahi did not come up in time.')
Exemple #6
0
    def run_once(self):
        """Test main loop."""
        self._shill_proxy = shill_proxy.ShillProxy()
        with virtual_ethernet_pair.VirtualEthernetPair(
                peer_interface_name=self.INTERFACE_NAME,
                peer_interface_ip=None) as ethernet_pair:
            if not ethernet_pair.is_healthy:
                raise error.TestFail('Could not create virtual ethernet pair.')

            if self.get_detection_flag(self.INTERFACE_NAME):
                raise error.TestFail('EAP detection flag is already set.')

            with hostapd_server.HostapdServer(
                    interface=ethernet_pair.interface_name) as hostapd:
                # Wait for hostapd to initialize.
                time.sleep(1)
                if not hostapd.running():
                    raise error.TestFail('hostapd process exited.')

                hostapd.send_eap_packets()
                if not self.get_detection_flag(self.INTERFACE_NAME):
                    raise error.TestFail('EAP detection flag is not set.')
 def __init__(self):
     self._arp_announce = 0
     peer_ip = self.IFACE_IP_BASE + '.1'
     peer_interface_ip = peer_ip + '/' + str(self.IFACE_NETWORK_PREFIX)
     self.vif = virtual_ethernet_pair.VirtualEthernetPair(
         interface_name=self.IFACE_NAME,
         peer_interface_name=self.PEER_IFACE_NAME,
         interface_ip=None,
         peer_interface_ip=peer_interface_ip,
         ignore_shutdown_errors=True)
     self.chroot = network_chroot.NetworkChroot(self.PEER_IFACE_NAME,
                                                peer_ip,
                                                self.IFACE_NETWORK_PREFIX)
     self.chroot.add_config_templates(self.NETWORK_CHROOT_CONFIG)
     self.chroot.add_startup_command(
         'iptables -I INPUT -p udp --dport 67 -j ACCEPT')
     self.chroot.add_startup_command(
         'iptables -I INPUT -p tcp --dport 80 -j ACCEPT')
     self._dnsmasq_command = self._GetDnsmasqCommand(peer_ip)
     self.chroot.add_startup_command(self._dnsmasq_command)
     self._test_endpoint_command = self._GetTestEndpointCommand()
     self.chroot.add_startup_command(self._test_endpoint_command)
 def _create_virtual_ethernet_pair(self):
     """Create a virtual ethernet pair."""
     self._virtual_ethernet_pair = virtual_ethernet_pair.VirtualEthernetPair(
         interface_ip=None, peer_interface_ip=None, host=self.host)
     self._virtual_ethernet_pair.setup()