Exemplo n.º 1
0
        def ping_host(source,
                      host,
                      count,
                      size=CONF.validation.ping_size,
                      nic=None,
                      mtu=None,
                      fragmentation=True,
                      pattern=None):
            IP_VERSION_4 = neutron_lib_constants.IP_VERSION_4
            IP_VERSION_6 = neutron_lib_constants.IP_VERSION_6

            # Use 'ping6' for IPv6 addresses, 'ping' for IPv4 and hostnames
            ip_version = (IP_VERSION_6
                          if netaddr.valid_ipv6(host) else IP_VERSION_4)
            cmd = ('ping6' if ip_version == IP_VERSION_6 else 'ping')
            if nic:
                cmd = 'sudo {cmd} -I {nic}'.format(cmd=cmd, nic=nic)
            if mtu:
                if not fragmentation:
                    cmd += ' -M do'
                size = str(
                    net_utils.get_ping_payload_size(mtu=mtu,
                                                    ip_version=ip_version))
            if pattern:
                cmd += ' -p {pattern}'.format(pattern=pattern)
            cmd += ' -c{0} -W{0} -s{1} {2}'.format(count, size, host)
            return source.exec_command(cmd)
Exemplo n.º 2
0
    def ping_ip_address(self,
                        ip_address,
                        should_succeed=True,
                        ping_timeout=None,
                        mtu=None):
        # the code is taken from tempest/scenario/manager.py in tempest git
        timeout = ping_timeout or CONF.validation.ping_timeout
        cmd = ['ping', '-c1', '-w1']

        if mtu:
            cmd += [
                # don't fragment
                '-M',
                'do',
                # ping receives just the size of ICMP payload
                '-s',
                str(net_utils.get_ping_payload_size(mtu, 4))
            ]
        cmd.append(ip_address)

        def ping():
            proc = subprocess.Popen(cmd,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            proc.communicate()

            return (proc.returncode == 0) == should_succeed

        caller = test_utils.find_test_caller()
        LOG.debug(
            '%(caller)s begins to ping %(ip)s in %(timeout)s sec and the'
            ' expected result is %(should_succeed)s', {
                'caller': caller,
                'ip': ip_address,
                'timeout': timeout,
                'should_succeed':
                'reachable' if should_succeed else 'unreachable'
            })
        result = test_utils.call_until_true(ping, timeout, 1)

        # To make sure ping_ip_address called by test works
        # as expected.
        self.assertTrue(result)

        LOG.debug(
            '%(caller)s finishes ping %(ip)s in %(timeout)s sec and the '
            'ping result is %(result)s', {
                'caller': caller,
                'ip': ip_address,
                'timeout': timeout,
                'result': 'expected' if result else 'unexpected'
            })
        return result
Exemplo n.º 3
0
 def ping_host(source, host, count=CONF.validation.ping_count,
               size=CONF.validation.ping_size, nic=None, mtu=None,
               fragmentation=True):
     addr = netaddr.IPAddress(host)
     cmd = 'ping6' if addr.version == 6 else 'ping'
     if nic:
         cmd = 'sudo {cmd} -I {nic}'.format(cmd=cmd, nic=nic)
     if mtu:
         if not fragmentation:
             cmd += ' -M do'
         size = str(net_utils.get_ping_payload_size(
             mtu=mtu, ip_version=addr.version))
     cmd += ' -c{0} -w{0} -s{1} {2}'.format(count, size, host)
     return source.exec_command(cmd)
Exemplo n.º 4
0
 def ping_host(source, host, count=CONF.validation.ping_count,
               size=CONF.validation.ping_size, nic=None, mtu=None,
               fragmentation=True):
     addr = netaddr.IPAddress(host)
     cmd = 'ping6' if addr.version == 6 else 'ping'
     if nic:
         cmd = 'sudo {cmd} -I {nic}'.format(cmd=cmd, nic=nic)
     if mtu:
         if not fragmentation:
             cmd += ' -M do'
         size = str(net_utils.get_ping_payload_size(
             mtu=mtu, ip_version=addr.version))
     cmd += ' -c{0} -w{0} -s{1} {2}'.format(count, size, host)
     return source.exec_command(cmd)
Exemplo n.º 5
0
    def ping_ip_address(self,
                        ip_address,
                        should_succeed=True,
                        ping_timeout=None,
                        mtu=None,
                        server=None):
        timeout = ping_timeout or CONF.validation.ping_timeout
        cmd = ['ping', '-c1', '-w1']

        if mtu:
            cmd += [
                # don't fragment
                '-M',
                'do',
                # ping receives just the size of ICMP payload
                '-s',
                str(net_utils.get_ping_payload_size(mtu, 4))
            ]
        cmd.append(ip_address)

        def ping():
            proc = subprocess.Popen(cmd,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            proc.communicate()

            return (proc.returncode == 0) == should_succeed

        caller = test_utils.find_test_caller()
        LOG.debug(
            '%(caller)s begins to ping %(ip)s in %(timeout)s sec and the'
            ' expected result is %(should_succeed)s', {
                'caller': caller,
                'ip': ip_address,
                'timeout': timeout,
                'should_succeed':
                'reachable' if should_succeed else 'unreachable'
            })
        result = test_utils.call_until_true(ping, timeout, 1)
        LOG.debug(
            '%(caller)s finishes ping %(ip)s in %(timeout)s sec and the '
            'ping result is %(result)s', {
                'caller': caller,
                'ip': ip_address,
                'timeout': timeout,
                'result': 'expected' if result else 'unexpected'
            })
        if server:
            self._log_console_output([server])
        return result
Exemplo n.º 6
0
    def ping_ip_address(self,
                        ip_address,
                        should_succeed=True,
                        ping_timeout=None,
                        mtu=None):
        timeout = ping_timeout or CONF.validation.ping_timeout
        cmd = ['ping', '-c1', '-w1']

        if mtu:
            cmd += [
                # don't fragment
                '-M',
                'do',
                # ping receives just the size of ICMP payload
                '-s',
                str(net_utils.get_ping_payload_size(mtu, 4))
            ]
        cmd.append(ip_address)

        def ping():
            proc = subprocess.Popen(cmd,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            proc.communicate()

            return (proc.returncode == 0) == should_succeed

        caller = test_utils.find_test_caller()
        LOG.debug("{caller} begins to ping {ip} in {timeout} sec and the"
                  " expected result is {should_succeed}".format(
                      caller=caller,
                      ip=ip_address,
                      timeout=timeout,
                      should_succeed=('reachable'
                                      if should_succeed else 'unreachable')))
        result = test_utils.call_until_true(ping, timeout, 1)
        LOG.debug("{caller} finishes ping {ip} in {timeout} sec and the "
                  "ping result is {result}".format(
                      caller=caller,
                      ip=ip_address,
                      timeout=timeout,
                      result='expected' if result else 'unexpected'))
        return result
Exemplo n.º 7
0
    def ping_ip_address(self, ip_address, should_succeed=True,
                        ping_timeout=None, mtu=None):
        timeout = ping_timeout or CONF.validation.ping_timeout
        cmd = ['ping', '-c1', '-w1']

        if mtu:
            cmd += [
                # don't fragment
                '-M', 'do',
                # ping receives just the size of ICMP payload
                '-s', str(net_utils.get_ping_payload_size(mtu, 4))
            ]
        cmd.append(ip_address)

        def ping():
            proc = subprocess.Popen(cmd,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            proc.communicate()

            return (proc.returncode == 0) == should_succeed

        caller = test_utils.find_test_caller()
        LOG.debug("{caller} begins to ping {ip} in {timeout} sec and the"
                  " expected result is {should_succeed}"
                  .format(caller=caller,
                          ip=ip_address,
                          timeout=timeout,
                          should_succeed=('reachable' if should_succeed
                                          else 'unreachable')))
        result = test_utils.call_until_true(ping, timeout, 1)
        LOG.debug("{caller} finishes ping {ip} in {timeout} sec and the "
                  "ping result is {result}"
                  .format(caller=caller,
                          ip=ip_address,
                          timeout=timeout,
                          result='expected' if result else 'unexpected'))
        return result
Exemplo n.º 8
0
    def ping_ip_address(self, ip_address, should_succeed=True,
                        ping_timeout=None, mtu=None):
        # the code is taken from tempest/scenario/manager.py in tempest git
        timeout = ping_timeout or CONF.validation.ping_timeout
        cmd = ['ping', '-c1', '-w1']

        if mtu:
            cmd += [
                # don't fragment
                '-M', 'do',
                # ping receives just the size of ICMP payload
                '-s', str(net_utils.get_ping_payload_size(mtu, 4))
            ]
        cmd.append(ip_address)

        def ping():
            proc = subprocess.Popen(cmd,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            proc.communicate()

            return (proc.returncode == 0) == should_succeed

        caller = test_utils.find_test_caller()
        LOG.debug('%(caller)s begins to ping %(ip)s in %(timeout)s sec and the'
                  ' expected result is %(should_succeed)s', {
                      'caller': caller, 'ip': ip_address, 'timeout': timeout,
                      'should_succeed':
                      'reachable' if should_succeed else 'unreachable'
                  })
        result = test_utils.call_until_true(ping, timeout, 1)
        LOG.debug('%(caller)s finishes ping %(ip)s in %(timeout)s sec and the '
                  'ping result is %(result)s', {
                      'caller': caller, 'ip': ip_address, 'timeout': timeout,
                      'result': 'expected' if result else 'unexpected'
                  })
        return result
Exemplo n.º 9
0
 def test_None(self):
     self.assertIsNone(net_utils.get_ping_payload_size(None, mock.Mock()))
Exemplo n.º 10
0
 def test_ipv6(self):
     self.assertEqual(1406, net_utils.get_ping_payload_size(1450, 6))
Exemplo n.º 11
0
 def test_ipv4(self):
     self.assertEqual(1422, net_utils.get_ping_payload_size(1450, 4))