Example #1
0
    def test_valid_routes(self):
        route_table = """Routing tables

Internet:
Destination        Gateway            Flags     Netif Expire
0.0.0.0            10.145.187.193     UGS         em0       
10.145.187.192/26  0.0.0.0            US          em0       
168.63.129.16      10.145.187.193     UH          em0       
169.254.169.254    10.145.187.193     UHS         em0       
192.168.43.0       0.0.0.0            US        vtbd0     
"""

        with patch.object(shellutil, 'run_command', return_value=route_table):
            raw_route_list = FreeBSDOSUtil().read_route_table()

        self.assertEqual(len(raw_route_list), 6)

        route_list = FreeBSDOSUtil().get_list_of_routes(raw_route_list)

        self.assertEqual(len(route_list), 5)
        self.assertEqual(route_list[0].gateway_quad(), '10.145.187.193')
        self.assertEqual(route_list[1].gateway_quad(), '0.0.0.0')
        self.assertEqual(route_list[1].mask_quad(), '255.255.255.192')
        self.assertEqual(route_list[2].destination_quad(), '168.63.129.16')
        self.assertEqual(route_list[1].flags, 1)
        self.assertEqual(route_list[2].flags, 33)
        self.assertEqual(route_list[3].flags, 5)
        self.assertEqual((route_list[3].metric - route_list[4].metric), 1)
        self.assertEqual(route_list[0].interface, 'em0')
        self.assertEqual(route_list[4].interface, 'vtbd0')
Example #2
0
    def test_no_primary_does_not_throw(self):
        freebsdosutil = FreeBSDOSUtil()

        with patch.object(freebsdosutil, '_get_net_info', return_value=('em0', '10.0.0.1', 'e5:f0:38:aa:da:52')):
            try:
                freebsdosutil.get_first_if()[0]
            except Exception as e:  # pylint: disable=unused-variable
                print(textutil.format_exception(e))
                exception = True  # pylint: disable=unused-variable
Example #3
0
    def test_no_routes(self):
        route_table = """Routing tables

Internet:
Destination        Gateway            Flags     Netif Expire
"""

        with patch.object(shellutil, 'run_command', return_value=route_table):
            raw_route_list = FreeBSDOSUtil().read_route_table()

        self.assertEqual(len(FreeBSDOSUtil().get_list_of_routes(raw_route_list)), 0)
Example #4
0
    def test_no_primary_does_not_throw(self):
        freebsdosutil = FreeBSDOSUtil()

        with patch.object(freebsdosutil,
                          '_get_net_info',
                          return_value=('em0', '10.0.0.1',
                                        'e5:f0:38:aa:da:52')):
            try:
                freebsdosutil.get_first_if()[0]
            except Exception as e:
                print(traceback.format_exc())
                exception = True
Example #5
0
    def test_get_first_if(self):
        """
        Validate that the agent can find the first active non-loopback
        interface.
        This test case used to run live, but not all developers have an eth*
        interface. It is perfectly valid to have a br*, but this test does not
        account for that.
        """
        freebsdosutil = FreeBSDOSUtil()

        with patch.object(freebsdosutil, '_get_net_info', return_value=('em0', '10.0.0.1', 'e5:f0:38:aa:da:52')):
            ifname, ipaddr = freebsdosutil.get_first_if()
        
        self.assertEqual(ifname, 'em0')
        self.assertEqual(ipaddr, '10.0.0.1')
Example #6
0
    def test_empty_proc_net_route(self):
        route_table = ""

        with patch.object(shellutil, 'run_command', return_value=route_table):
            # Header line only
            self.assertEqual(len(FreeBSDOSUtil().read_route_table()), 1)
Example #7
0
 def test_get_dhcp_pid_should_return_a_list_of_pids(self):
     osutil_get_dhcp_pid_should_return_a_list_of_pids(self, FreeBSDOSUtil())