1# 2# Copyright OpenEmbedded Contributors 3# 4# SPDX-License-Identifier: MIT 5# 6from oeqa.runtime.case import OERuntimeTestCase 7from oeqa.core.decorator.depends import OETestDepends 8from oeqa.core.decorator.data import skipIfQemu 9 10class Ethernet_Test(OERuntimeTestCase): 11 12 def set_ip(self, x): 13 x = x.split(".") 14 sample_host_address = '150' 15 x[3] = sample_host_address 16 x = '.'.join(x) 17 return x 18 19 @skipIfQemu() 20 @OETestDepends(['ssh.SSHTest.test_ssh']) 21 def test_set_virtual_ip(self): 22 (status, output) = self.target.run("ifconfig eth0 | grep 'inet ' | awk '{print $2}'") 23 self.assertEqual(status, 0, msg='Failed to get ip address. Make sure you have an ethernet connection on your device, output: %s' % output) 24 original_ip = output 25 virtual_ip = self.set_ip(original_ip) 26 27 (status, output) = self.target.run("ifconfig eth0:1 %s netmask 255.255.255.0 && sleep 2 && ping -c 5 %s && ifconfig eth0:1 down" % (virtual_ip,virtual_ip)) 28 self.assertEqual(status, 0, msg='Failed to create virtual ip address, output: %s' % output) 29 30 @skipIfQemu() 31 @OETestDepends(['ethernet_ip_connman.Ethernet_Test.test_set_virtual_ip']) 32 def test_get_ip_from_dhcp(self): 33 (status, output) = self.target.run("connmanctl services | grep -E '*AO Wired|*AR Wired' | awk '{print $3}'") 34 self.assertEqual(status, 0, msg='No wired interfaces are detected, output: %s' % output) 35 wired_interfaces = output 36 37 (status, output) = self.target.run("ip route | grep default | awk '{print $3}'") 38 self.assertEqual(status, 0, msg='Failed to retrieve the default gateway, output: %s' % output) 39 default_gateway = output 40 41 (status, output) = self.target.run("connmanctl config %s --ipv4 dhcp && sleep 2 && ping -c 5 %s" % (wired_interfaces,default_gateway)) 42 self.assertEqual(status, 0, msg='Failed to get dynamic IP address via DHCP in connmand, output: %s' % output)