Beispiel #1
0
 def testIncompleteConfig(self):
     dh4p = self.dh4p
     self.loop.RunOnce(timeout=1)
     self.assertFalse(os.path.exists(dnsmasq.DNSMASQCONFIG[0]))
     dh4p.Enable = True
     dh4p.MinAddress = '1.1.1.1'
     self.loop.RunOnce(timeout=1)
     lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
     self.assertEqual(lines, [])
     dh4p.MaxAddress = '3.3.3.3'
     self.loop.RunOnce(timeout=1)
     lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
     expected = ['dhcp-range=1.1.1.1,3.3.3.3,86400\n']
     self.assertEqual(expected, lines)
Beispiel #2
0
 def testEnableDisable(self):
     dh4p = self.dh4p
     dh4p.Enable = True
     dh4p.MinAddress = '1.1.1.1'
     dh4p.MaxAddress = '2.2.2.2'
     self.assertFalse(os.path.exists(dnsmasq.DNSMASQCONFIG[0]))
     self.loop.RunOnce(timeout=1)
     self.assertTrue(os.path.exists(dnsmasq.DNSMASQCONFIG[0]))
     lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
     self.assertEqual(lines, ['dhcp-range=1.1.1.1,2.2.2.2,86400\n'])
     dh4p.Enable = False
     self.loop.RunOnce(timeout=1)
     self.assertTrue(os.path.exists(dnsmasq.DNSMASQCONFIG[0]))
     lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
     self.assertEqual(lines, [])
Beispiel #3
0
    def testAcsUrl(self):
        class FakeAcsConfig(object):
            def __init__(self):
                self.url = None

            def SetAcsUrl(self, value):
                print 'SetAcsUrl(%r)' % value
                self.url = value
                return self.url

            def GetAcsUrl(self):
                return self.url

        dmroot = tr.core.Exporter()
        unused_dh4 = dnsmasq.DHCPv4(dmroot=dmroot)
        self.dh4p.Enable = True

        dmroot.Device = tr.core.Exporter()
        _mgmt = tr.cpe_management_server.CpeManagementServer(
            acs_config=FakeAcsConfig(),
            port=12345,
            ping_path='http://localhost')
        mgmt = management_server.ManagementServer181(_mgmt)
        dmroot.Device.ManagementServer = mgmt

        self.loop.RunOnce()
        self.assertEqual(
            dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0]), [])

        mgmt.URL = 'http://localhost'
        # no idle cycle yet, so config not rewritten
        self.assertEqual(
            dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0]), [])
        self.loop.RunOnce()
        # now it should be updated.
        cfg = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
        self.assertNotEqual(cfg, [])
        cfg = '|'.join(cfg)
        self.assertTrue('option6:1,"http://localhost"' in cfg)
        self.assertTrue('11,"http://localhost"' in cfg)

        mgmt.URL = 'http://localh"ost\\2'
        self.loop.RunOnce()
        cfg = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
        self.assertNotEqual(cfg, [])
        cfg = '|'.join(cfg)
        self.assertTrue('option6:1,"http://localhost2"' in cfg)
        self.assertTrue('11,"http://localhost2"' in cfg)
Beispiel #4
0
 def testUserClassConditionalConfig(self):
     dh4p = self.dh4p
     dh4p.UserClassID = 'userClass'
     self._setConditionalParameters(dh4p)
     self.loop.RunOnce(timeout=1)
     lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
     self.assertTrue('dhcp-userclass=set:test,userClass\n' in lines)
     lines.remove('dhcp-userclass=set:test,userClass\n')
     self._checkConditionalResults(lines)
     self.assertEqual(len(lines), 0)
Beispiel #5
0
 def testMACConditionalConfig(self):
     dh4p = self.dh4p
     dh4p.Chaddr = '11:22:33:44:55:66'
     dh4p.ChaddrMask = 'ff:ff:ff:00:00:00'
     self._setConditionalParameters(dh4p)
     self.loop.RunOnce(timeout=1)
     lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
     self.assertTrue('dhcp-host=11:22:33:*:*:*,set:test\n' in lines)
     lines.remove('dhcp-host=11:22:33:*:*:*,set:test\n')
     self._checkConditionalResults(lines)
     self.assertEqual(len(lines), 0)
Beispiel #6
0
    def testMultipleDhcpHosts(self):
        dh4p = self.dh4p
        h = tr.handle.Handle(dh4p)
        dh4p.Enable = True
        (_, ip) = h.AddExportObject('StaticAddress')
        ip.Enable = True
        ip.Chaddr = '11:22:33:44:55:66'
        ip.Yiaddr = '1.2.3.4'
        (_, ip) = h.AddExportObject('StaticAddress')
        ip.Enable = True
        ip.Chaddr = '22:33:44:55:66:77'
        ip.Yiaddr = '1.2.3.4'
        (_, ip) = h.AddExportObject('StaticAddress')
        ip.Enable = True
        ip.X_CATAWAMPUS_ORG_ClientID = 'cid'
        ip.Yiaddr = '1.2.3.4'

        self.loop.RunOnce(timeout=1)
        lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
        # self.assertTrue before remove() to make the test more clear.
        e = ['dhcp-host=11:22:33:44:55:66,22:33:44:55:66:77,id:cid,1.2.3.4\n']
        self.assertEqual(e, lines)
Beispiel #7
0
 def testBasicConfig(self):
     dh4p = self.dh4p
     dh4p.Enable = True
     dh4p.MinAddress = '1.1.1.1'
     dh4p.MaxAddress = '2.2.2.2'
     dh4p.DomainName = 'example.com'
     dh4p.DNSServers = '3.3.3.3,4.4.4.4'
     dh4p.X_CATAWAMPUS_ORG_NTPServers = '5.5.5.5,6.6.6.6'
     dh4p.IPRouters = '9.9.9.9'
     self.loop.RunOnce(timeout=1)
     lines = dnsmasq._ReadFileActiveLines(dnsmasq.DNSMASQCONFIG[0])
     # self.assertTrue before remove() to make the test more clear.
     expectedLines = [
         'dhcp-range=1.1.1.1,2.2.2.2,86400\n',
         'domain=example.com\n',
         'dhcp-option=option:router,9.9.9.9\n',
         'dhcp-option=option:ntp-server,5.5.5.5,6.6.6.6\n',
         'dhcp-option=option:dns-server,3.3.3.3,4.4.4.4\n',
     ]
     for expected in expectedLines:
         self.assertTrue(expected in lines)
         lines.remove(expected)
     self.assertEqual(len(lines), 0)
     self.assertTrue(os.path.exists(self.restartfile))