Ejemplo n.º 1
0
class DefGwTest(unittest.TestCase):
    """
    Validate default router setting.
    """
    def setUp(self):
        self.gw_store = defaultdict(str)
        self.dhcp_gw_info = UplinkGatewayInfo(self.gw_store)

    def test_gw_ip_for_DHCP(self):
        self.assertEqual(self.dhcp_gw_info.getIP(), None)
        self.assertEqual(self.dhcp_gw_info.getMac(), None)

    def test_gw_ip_for_Ip_pool(self):
        self.dhcp_gw_info.read_default_gw()

        def_gw_cmd = "ip route show |grep default| awk '{print $3}'"
        p = subprocess.Popen([def_gw_cmd], stdout=subprocess.PIPE, shell=True)
        def_ip = p.stdout.read().decode("utf-8").strip()
        self.assertEqual(self.dhcp_gw_info.getIP(), str(def_ip))
        self.assertEqual(self.dhcp_gw_info.getMac(), None)
Ejemplo n.º 2
0
    def set_deafult_gw_mac(self, args):
        """
        Set mac address of the GW
        Args:
            args: mac address
        Returns:
        """

        gw_mac = ip_address(args.ip)
        gw_info = UplinkGatewayInfo()
        gw_info.update_mac(str(gw_mac))

        print("set Default gw mac to %s" % gw_info.getMac())
Ejemplo n.º 3
0
    def list_all_record(self, args):
        """
                Print list DHCP and GW records.
        Args:
            args: None

        Returns: None
        """

        for k, v in self.dhcp_client_state.items():
            print("mac: %s DHCP state: %s" % (k.replace('_', ':'), str(v)))

        gw_info = UplinkGatewayInfo(store.GatewayInfoMap())
        print("Default GW: %s" % gw_info.getIP())
        print("GW Mac address: %s" % gw_info.getMac())