Esempio n. 1
0
 def test_add(self):
     host = Host("test1")
     assert_equals(len(host), 1)
     host = Host(Hostname("test1"))
     host_entry_1 = Hostname("test1")
     assert_equals(len(host), 1)
     host.add(host_entry_1)
     assert_equals(len(host), 1)
Esempio n. 2
0
 def test_add_fqdn_to_shortname(self):
     # New fqdn updates the domain if exisiting domain is empty
     host = Host(Hostname('test1'))
     assert_equals(host[0].fqdn, 'test1')
     host_entry_2 = Hostname('test1.example.com')
     host.add(host_entry_2)
     assert_equals(len(host), 1)
     assert_equals(host[0].fqdn, host_entry_2.fqdn)
Esempio n. 3
0
 def test_add_fqdn_to_shortname(self):
     # New fqdn updates the domain if exisiting domain is empty
     host = Host(Hostname("test1"))
     assert_equals(host[0].fqdn, "test1")
     host_entry_2 = Hostname("test1.example.com")
     host.add(host_entry_2)
     assert_equals(len(host), 1)
     assert_equals(host[0].fqdn, host_entry_2.fqdn)
Esempio n. 4
0
 def test_add_new_host_existing_ip(self):
     # New Hostname with duplicate ip adds new host entry
     host = Host(Hostname("test1", "1.2.3.4"))
     host_entry_3 = Hostname("test2", "1.2.3.4")
     host.add(host_entry_3)
     assert_equals(len(host), 2)
     assert_equals(host[-1].fqdn, host_entry_3.fqdn)
     del host[-1]
     assert_equals(len(host), 1)
     host_entry_4 = Hostname("test2.example.com", "1.2.3.4")
     host.add(host_entry_4)
     assert_equals(len(host), 2)
     assert_equals(host[-1].fqdn, host_entry_4.fqdn)
Esempio n. 5
0
 def test_add_ip_to_no_ip_host(self):
     # New IP with matching hostnames updates existing hostname's ip
     host_entry_1 = Hostname("test1.example.com")
     host = Host(host_entry_1)
     host_entry_2 = Hostname("test1", "1.2.3.4")
     host.add(host_entry_2)
     assert_equals(host[0].ip, host_entry_2.ip)
     assert_equals(len(host), 1)
     assert_equals(host[0].fqdn, host_entry_1.fqdn)
     host[0].ip = None
     host_entry_3 = Hostname("test1.example.com", "1.2.3.4")
     host.add(host_entry_3)
     assert_equals(len(host), 1)
     assert_equals(host[0].fqdn, host_entry_3.fqdn)
     assert_equals(host[0].ip, host_entry_3.ip)
Esempio n. 6
0
 def test_add_new_ip_existing_name(self):
     # New Hostname with duplicate ip adds new host entry
     host = Host(Hostname("test1", "1.2.3.4"))
     host.add(Hostname("test1", "2.3.4.5"))
     assert_equals(len(host), 2)
     assert_equals(host[0].fqdn, "test1")
     assert_equals(host[1].fqdn, "test1")
     assert_equals(host[0].ip, "1.2.3.4")
     assert_equals(host[1].ip, "2.3.4.5")
     del host[-1]
     host.add(Hostname("test1.example.com", "2.3.4.5"))
     assert_equals(len(host), 2)
     assert_equals(host[0].fqdn, "test1.example.com")
     assert_equals(host[1].fqdn, "test1.example.com")
     assert_equals(host[0].ip, "1.2.3.4")
     assert_equals(host[1].ip, "2.3.4.5")
Esempio n. 7
0
 def test_add(self):
     host = Host('test1')
     assert_equals(len(host), 1)
     host = Host(Hostname('test1'))
     host_entry_1 = Hostname('test1')
     assert_equals(len(host), 1)
     host.add(host_entry_1)
     assert_equals(len(host), 1)
Esempio n. 8
0
    def test_equals(self):
        """ Hosts are equal if there is one overlapping entry """
        host = Host(Hostname('test', '1.2.3.4'))
        assert_true('test' in host)
        assert_true(Hostname('test') in host)
        assert_true(Hostname('test', '1.2.3.4') in host)
        assert_true(Hostname('test.example.com') in host)
        assert_true(Hostname('test.example.com', '1.2.3.4') in host)

        assert_false('test1' in host)
        assert_false(Hostname('test1') in host)
        assert_false(Hostname('test1', '2.3.4.5') in host)
        assert_false(Hostname('test1.example.com') in host)
        assert_false(Hostname('test1.example.com', '2.3.4.5') in host)
Esempio n. 9
0
 def test_add_new_host_existing_ip(self):
     # New Hostname with duplicate ip adds new host entry
     host = Host(Hostname('test1', '1.2.3.4'))
     host_entry_3 = Hostname('test2', '1.2.3.4')
     host.add(host_entry_3)
     assert_equals(len(host), 2)
     assert_equals(host[-1].fqdn, host_entry_3.fqdn)
     del host[-1]
     assert_equals(len(host), 1)
     host_entry_4 = Hostname('test2.example.com', '1.2.3.4')
     host.add(host_entry_4)
     assert_equals(len(host), 2)
     assert_equals(host[-1].fqdn, host_entry_4.fqdn)
Esempio n. 10
0
 def test_add_ip_to_no_ip_host(self):
     # New IP with matching hostnames updates existing hostname's ip
     host_entry_1 = Hostname('test1.example.com')
     host = Host(host_entry_1)
     host_entry_2 = Hostname('test1', '1.2.3.4')
     host.add(host_entry_2)
     assert_equals(host[0].ip, host_entry_2.ip)
     assert_equals(len(host), 1)
     assert_equals(host[0].fqdn, host_entry_1.fqdn)
     host[0].ip = None
     host_entry_3 = Hostname('test1.example.com', '1.2.3.4')
     host.add(host_entry_3)
     assert_equals(len(host), 1)
     assert_equals(host[0].fqdn, host_entry_3.fqdn)
     assert_equals(host[0].ip, host_entry_3.ip)
Esempio n. 11
0
 def test_add_new_ip_existing_name(self):
     # New Hostname with duplicate ip adds new host entry
     host = Host(Hostname('test1', '1.2.3.4'))
     host.add(Hostname('test1', '2.3.4.5'))
     assert_equals(len(host), 2)
     assert_equals(host[0].fqdn, 'test1')
     assert_equals(host[1].fqdn, 'test1')
     assert_equals(host[0].ip, '1.2.3.4')
     assert_equals(host[1].ip, '2.3.4.5')
     del host[-1]
     host.add(Hostname('test1.example.com', '2.3.4.5'))
     assert_equals(len(host), 2)
     assert_equals(host[0].fqdn, 'test1.example.com')
     assert_equals(host[1].fqdn, 'test1.example.com')
     assert_equals(host[0].ip, '1.2.3.4')
     assert_equals(host[1].ip, '2.3.4.5')
Esempio n. 12
0
 def test_display_hostname(self):
     host = Host('test1')
     assert_equals(host.display_hostname, 'test1')
     host._add('test2')
     assert_equals(host.display_hostname, 'test1')
Esempio n. 13
0
 def test_display_hostname_update(self):
     host = Host('test1')
     assert_equals(host.display_hostname, 'test1')
     host.add('test1.example.com')
     assert_equals(host.display_hostname, 'test1.example.com')
Esempio n. 14
0
 def test_display_hostname_update(self):
     host = Host("test1")
     assert_equals(host.display_hostname, "test1")
     host.add("test1.example.com")
     assert_equals(host.display_hostname, "test1.example.com")
Esempio n. 15
0
 def test_display_hostname(self):
     host = Host("test1")
     assert_equals(host.display_hostname, "test1")
     host._add("test2")
     assert_equals(host.display_hostname, "test1")
Esempio n. 16
0
 def test_repr(self):
     host = Host("test1")
     assert_equals(host.__repr__(), "<Host test1>")
Esempio n. 17
0
 def test_str(self):
     host = Host("test1")
     assert_equals(host.__str__(), "Host test1")
     host = Host("test1")
Esempio n. 18
0
 def test_repr(self):
     host = Host('test1')
     assert_equals(host.__repr__(), '<Host test1>')
Esempio n. 19
0
 def test_contains_ip(self):
     host = Host('test1', '1.2.3.4')
     assert_in('1.2.3.4', host)
     assert_not_in('2.3.4.5', host)
Esempio n. 20
0
 def test_add_failure(self):
     host = Host(Hostname('test1'))
     assert_raises(TypeError, host.add, list())
     # Different host, add fails
     host_entry_2 = Hostname('test2')
     assert_raises(ValueError, host.add, host_entry_2)
Esempio n. 21
0
 def test_initilization(self):
     host = Host('test1')
     assert_in('test1', host)
Esempio n. 22
0
 def test_str(self):
     host = Host('test1')
     assert_equals(host.__str__(), 'Host test1')
     host = Host('test1')