def test_case_insensitve_assert_host_id(self): hostmap = HostMap() hostmap.add_hostref("Test1") hostmap.assert_host_id("test1", "host-test1-forcedid") self.perform_mapping(hostmap) self.assertEquals(hostmap.get_hostid("test1"), "host-test1-forcedid") self.assertEquals(hostmap.get_hostid("Test1"), "host-test1-forcedid")
def test_short_fqdn(self): hostmap = HostMap() hostmap.add_hostref("test1") hostmap.add_hostref("test1.example.com") hostmap.add_hostref("test2") hostmap.add_hostref("test2.example.com") self.perform_mapping(hostmap) # These should be condensed down, if they resolve to the # same IP. Otherwise, it does not assume that they are the same. self.assertEquals(len(hostmap.all_hostids()), 2) # It should use the longer name, as well. self.assertEquals(hostmap.get_hostid("test1"), "host-test1.example.com") self.assertEquals(hostmap.get_hostid("test2"), "host-test2.example.com")
def test_suffixed_names(self): hostmap = HostMap() hostmap.add_hostref("test1:somecrazysuffix_thatisreallylong") hostmap.add_hostref("test1.example.com") hostmap.add_hostref("test1") hostmap.add_hostref("test2.example.com") self.perform_mapping(hostmap) # These should be condensed down, if they resolve to the # same IP. Otherwise, it does not assume that they are the same. self.assertEquals(len(hostmap.all_hostids()), 2) # It should use the longer name, as well, but not the crazy suffixed # one.. self.assertEquals(hostmap.get_hostid("test1"), "host-test1.example.com") self.assertEquals(hostmap.get_hostid("test1:somecrazysuffix_thatisreallylong"), "host-test1.example.com")
def test_freeze_thaw_mappings(self): hostmap = HostMap() hostmap.add_hostref("test1") hostmap.add_hostref("test2") hostmap.add_hostref("test3") hostmap.assert_host_id("test2", "host-test2-forcedid") self.perform_mapping(hostmap) self.assertEquals(len(hostmap.all_hostids()), 3) frozen = hostmap.freeze_mappings() hostmap.clear_mappings() hostmap.thaw_mappings(frozen) hostmap.add_hostref("test1") hostmap.add_hostref("test2") hostmap.add_hostref("test3") self.perform_mapping(hostmap) self.assertEquals(len(hostmap.all_hostids()), 3) self.assertEquals(hostmap.get_hostid("test1"), "host-test1") self.assertEquals(hostmap.get_hostid("test2"), "host-test2-forcedid") self.assertEquals(hostmap.get_hostid("test3"), "host-test3")