def test_constructor(self): '''Constructors and read''' eq=self.assertEqual h=Hosts() eq(h.keys(),[]) h=Hosts(mc='1.0.0.1', mc02='1.0.0.2') eq(h['mc'],'1.0.0.1') eq(h['mc02'],'1.0.0.2') eq(h['1.0.0.1'],'mc') eq(h['1.0.0.2'],'mc02') h=Hosts({'pc':'1.0.0.3','pc02':'1.0.0.4'}) eq(h['pc'],'1.0.0.3') eq(h['pc02'],'1.0.0.4') eq(h['1.0.0.3'],'pc') eq(h['1.0.0.4'],'pc02') h=Hosts(self.hostsfile, ac03='1.0.0.5', ac02='1.0.0.6') eq(h['ac03'],'1.0.0.5') eq(h['ac02'],'1.0.0.6') eq(h['broadcasthost'],'255.255.255.255') eq(h['127.0.0.1'],'localhost localhost.yemen') eq(h['localhost.yemen'],'127.0.0.1') eq(h['localhost'],'127.0.0.1')
def test_del(self): '''Del''' h=Hosts() h['mc'], h['mc02'], h['127.0.0.1'] = '10.0.0.1', '10.0.0.2', 'localhost' del h['10.0.0.1'] del h['mc02'] del h['localhost'] self.assertRaises(KeyError, h.__delitem__, 'tata') self.assertEqual(h.keys(), [])
def test_read(self): '''Read''' eq=self.assertEqual h=Hosts() h.read(self.hostsfile) eq(h.keys(), ['localhost.yemen', 'broadcasthost', 'localhost', '127.0.0.1', '255.255.255.255']) eq(h['broadcasthost'],'255.255.255.255') eq(h['127.0.0.1'],'localhost localhost.yemen') eq(h['localhost.yemen'],'127.0.0.1') eq(h['localhost'],'127.0.0.1')
def doProbe(self, args): state = {} state['status'] = "ok" attr = Hosts().getHost(Hosts().getLocalHost()) for k in attr.keys(): state[k] = attr[k] for cb in self.probeCallbacks: info = cb() for k in info.keys(): state[k] = info[k] return json.dumps(state)