예제 #1
0
 def test_is_in_same_subnet(self):
     """Test is_in_same_subnet function."""
     self.assertTrue(
         utils.is_in_same_subnet('192.168.0.0', '192.168.1.2', 23))
     self.assertFalse(
         utils.is_in_same_subnet('192.168.0.0', '192.168.1.2', 24))
     self.assertTrue(
         utils.is_in_same_subnet('192.168.0.0', '192.168.0.255', 24))
     self.assertFalse(
         utils.is_in_same_subnet('191.168.0.0', '192.168.0.0', 24))
예제 #2
0
    def log_devserver_match_stats(dut_hostname, devserver_url):
        """Log stats whether host and devserver are in the same subnet.

        @param dut_hostname: Hostname of the dut.
        @param devserver_url: Url to the devserver.
        """
        try:
            devserver_name = dev_server.ImageServer.get_server_name(
                devserver_url)
            devserver_ip = socket.gethostbyname(devserver_name)
            dut_ip = socket.gethostbyname(dut_hostname)
        except socket.gaierror as e:
            logging.error('Failed to get IP address, error: %s', e)
            return

        # Take the first 2 octets as the indicator of subnet.
        devserver_subnet = '_'.join(devserver_ip.split('.')[0:2])
        dut_subnet = '_'.join(dut_ip.split('.')[0:2])
        if not utils.is_in_same_subnet(devserver_ip, dut_ip, 19):
            counter = ('devserver_mismatch.%s_to_%s' %
                       (devserver_subnet, dut_subnet))
            autotest_stats.Counter(counter).increment()
            counter = 'devserver_mismatch.%s' % devserver_subnet
        else:
            counter = 'devserver_match.%s' % devserver_subnet

        autotest_stats.Counter(counter).increment()