def check_vendor_encapsulated_options(self, option_string):
        """Check that the ipconfig in the client shows the the vendor options.

        @param option_string string expected value for vendor options.

        """
        proxy = shill_proxy.ShillProxy()
        device = proxy.find_object(
                'Device',
                {'Name': self.ethernet_pair.peer_interface_name})
        if device is None:
            raise error.TestFail('Device was not found.')
        device_properties = device.GetProperties(utf8_strings=True)
        ipconfig_path = device_properties['IPConfigs'][0]
        ipconfig = proxy.get_dbus_object('org.chromium.flimflam.IPConfig',
                                         ipconfig_path)
        ipconfig_properties = ipconfig.GetProperties(utf8_strings=True)
        ipconfig_vendor_encapsulated_options = ''.join(map(chr,
            ipconfig_properties['VendorEncapsulatedOptions']))
        if ipconfig_vendor_encapsulated_options != option_string:
            raise error.TestFail('Shill vendor encapsulated options %s does '
                                 'not match expected %s.' %
                                 (ipconfig_vendor_encapsulated_options,
                                  option_string))

        device_path = shill_proxy.ShillProxy.dbus2primitive(device.object_path)
        service = proxy.find_object('Service', {'Device': device_path})
        tethering = service.GetProperties()['Tethering']
        expected_value = 'Confirmed'
        if tethering != expected_value:
            raise error.TestFail('Service tethering state %s does '
                                 'not match expected %s.' %
                                 (tethering, expected_value))
 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()
 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 check_mtu_config(self, mtu):
        """Check that the ipconfig and interface in the client has correct MTU.

        @param mtu int expected MTU value.

        """
        proxy = shill_proxy.ShillProxy()
        device = proxy.find_object(
            'Device', {'Name': self.ethernet_pair.peer_interface_name})
        if device is None:
            raise error.TestFail('Device was not found.')
        device_properties = device.GetProperties(utf8_strings=True)
        ipconfig_path = device_properties['IPConfigs'][0]
        ipconfig = proxy.get_dbus_object('org.chromium.flimflam.IPConfig',
                                         ipconfig_path)
        ipconfig_properties = ipconfig.GetProperties(utf8_strings=True)
        ipconfig_mtu = ipconfig_properties['Mtu']
        if ipconfig_mtu != mtu:
            raise error.TestFail('Shill MTU %d does not match expected %d.' %
                                 (ipconfig_mtu, mtu))

        interface_mtu = interface.Interface(
            self.ethernet_pair.peer_interface_name).mtu
        if interface_mtu != mtu:
            raise error.TestFail('Interface MTU %d does not match '
                                 'expected %d.' %
                                 (interface_mtu, ipconfig_mtu))
Exemplo n.º 5
0
    def run_once(self, forgive_flaky=False):
        """Test main loop"""
        # full_revision looks like "3.4.0".
        full_revision = utils.system_output('uname -r')
        # base_revision looks like "3.4".
        base_revision = '.'.join(full_revision.split('.')[:2])
        logging.info('Kernel base is %s', base_revision)

        proxy = shill_proxy.ShillProxy()

        uninit = proxy.get_proxy().get_dbus_property(
            proxy.manager,
            shill_proxy.ShillProxy.MANAGER_PROPERTY_UNINITIALIZED_TECHNOLOGIES)
        logging.info("Uninitialized technologies: %s", uninit)
        # If Wifi support is not enabled for shill, it will be uninitialized.
        # Don't fail the test if Wifi was intentionally disabled.
        if "wifi" in uninit:
            raise error.TestNAError('Wireless support not enabled')

        wlan_ifs = [
            nic for nic in interface.get_interfaces() if nic.is_wifi_device()
        ]
        if wlan_ifs:
            net_if = wlan_ifs[0]
        else:
            raise self.NoDeviceFailure(forgive_flaky,
                                       'Found no recognized wireless device')

        # Some systems (e.g., moblab) might blacklist certain devices. We don't
        # rely on shill for most of this test, but it can be a helpful clue if
        # we see shill barfing.
        device_obj = proxy.find_object('Device',
                                       {'Type': proxy.TECHNOLOGY_WIFI})
        if device_obj is None:
            logging.warning("Shill couldn't find wireless device; "
                            "did someone blacklist it?")

        device_description = net_if.device_description
        if not device_description:
            raise error.TestFail('Device %s is not supported' % net_if.name)

        device_name, module_path = device_description
        logging.info('Device name %s, module path %s', device_name,
                     module_path)
        if not device_name in self.EXPECTED_DRIVER:
            raise error.TestFail('Unexpected device name %s' % device_name)

        if not base_revision in self.EXPECTED_DRIVER[device_name]:
            raise error.TestNAError(
                'Unexpected base kernel revision %s with device name %s' %
                (base_revision, device_name))

        expected_driver = self.EXPECTED_DRIVER[device_name][base_revision]
        if module_path != expected_driver:
            raise error.TestFail(
                'Unexpected driver for %s/%s; got %s but expected %s' %
                (base_revision, device_name, module_path, expected_driver))
    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.')
    def check_shill_gateway_setup(self, interface_name, gateway_ip):
        """Check that the ipconfig in the client shows the gateway IP.

        @param interface_name string client network interface name.
        @param gateway_ip string expected gateway IP address.

        """
        proxy = shill_proxy.ShillProxy()
        device = proxy.find_object('Device', {'Name': interface_name})
        if device is None:
            raise error.TestFail('Device was not found.')
        device_properties = device.GetProperties(utf8_strings=True)
        ipconfig_path = device_properties['IPConfigs'][0]
        ipconfig = proxy.get_dbus_object('org.chromium.flimflam.IPConfig',
                                         ipconfig_path)
        ipconfig_properties = ipconfig.GetProperties(utf8_strings=True)
        ipconfig_gateway = ipconfig_properties['Gateway']
        if ipconfig_gateway != gateway_ip:
            raise error.TestFail('Shill gateway %s does '
                                 'not match expected %s.' %
                                 (ipconfig_gateway, gateway_ip))
Exemplo n.º 8
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 check_wpad_config(self, proxy_auto_config):
        """Check that the ipconfig in the client shows the the proxy config.

        @param proxy_auto_config string expected value for proxy autoconfig.

        """
        proxy = shill_proxy.ShillProxy()
        device = proxy.find_object(
            'Device', {'Name': self.ethernet_pair.peer_interface_name})
        if device is None:
            raise error.TestFail('Device was not found.')
        device_properties = device.GetProperties(utf8_strings=True)
        ipconfig_path = device_properties['IPConfigs'][0]
        ipconfig = proxy.get_dbus_object('org.chromium.flimflam.IPConfig',
                                         ipconfig_path)
        ipconfig_properties = ipconfig.GetProperties(utf8_strings=True)
        ipconfig_proxy_auto_config = ipconfig_properties[
            'WebProxyAutoDiscoveryUrl']
        if ipconfig_proxy_auto_config != proxy_auto_config:
            raise error.TestFail(
                'Shill proxy config %s does not match '
                'expected %s.' %
                (proxy_auto_config, ipconfig_proxy_auto_config))
Exemplo n.º 10
0
    def run_once(self):
        """Test main loop"""
        # full_revision looks like "3.4.0".
        full_revision = utils.system_output('uname -r')
        # base_revision looks like "3.4".
        base_revision = '.'.join(full_revision.split('.')[:2])
        logging.info('Kernel base is %s', base_revision)

        proxy = shill_proxy.ShillProxy()
        device_obj = proxy.find_object('Device',
                                       {'Type': proxy.TECHNOLOGY_WIFI})
        if device_obj is None:
            raise error.TestNAError('Found no recognized wireless device')

        device = device_obj.GetProperties()['Interface']
        net_if = interface.Interface(device)
        device_description = net_if.device_description
        if not device_description:
            raise error.TestFail('Device %s is not supported' % device)

        device_name, module_path = device_description
        logging.info('Device name %s, module path %s', device_name,
                     module_path)
        if not device_name in self.EXPECTED_DRIVER:
            raise error.TestFail('Unexpected device name %s' % device_name)

        if not base_revision in self.EXPECTED_DRIVER[device_name]:
            raise error.TestNAError(
                'Unexpected base kernel revision %s with device name %s' %
                (base_revision, device_name))

        expected_driver = self.EXPECTED_DRIVER[device_name][base_revision]
        if module_path != expected_driver:
            raise error.TestFail(
                'Unexpected driver for %s/%s; got %s but expected %s' %
                (base_revision, device_name, module_path, expected_driver))
Exemplo n.º 11
0
 def run_once(self, vpn_types=[]):
     """Test main loop."""
     self._shill_proxy = shill_proxy.ShillProxy()
     for vpn_type in vpn_types:
         self.run_vpn_test(vpn_type)