コード例 #1
0
def test_check_metrics(capsys):
    import hemApp
    metrics = hemApp.initialise_metrics({"type":"console"})
    discovery = {
        "type":"file",
        "name":"tests/hosts.yaml",
        "metrics": metrics}
    hemApp.discover_hosts(discovery)
    try:
        captured = capsys.readouterr()
        assert "discovery_file" in captured.out
    except AttributeError:
        print("Capsys not working in python 3.3 or 3.4 - investigating")
コード例 #2
0
def test_check_content():
    import hemApp
    hosts = hemApp.discover_hosts({
        "type":"file",
        "name":"tests/hosts.yaml"})
    assert type(hosts) == list
    print(hosts)
    assert 'hostone' in hosts
コード例 #3
0
def test_check_notfound():
    import hemApp
    try:
        with unittest.assertLogs(level='ERROR') as cm:
            hosts = hemApp.discover_hosts({
                "type":"file",
                "name":"notfound.nonexistent"})
        assert 'ERROR:hemApp.drivers.discovery_file:File not found' in cm.output
    except AttributeError:
        # self.assertLogs doesn't work in Python 2.x
        hosts = hemApp.discover_hosts({
            "type":"file",
            "name":"notfound.nonexistent"})
    except FileNotFoundError:
        assert False
    assert type(hosts) == list
    assert hosts == []
コード例 #4
0
def test_check_content_key():
    import hemApp
    hosts = hemApp.discover_hosts({
        "type":"file",
        "name":"tests/hosts_key.yaml",
        "key":"hostname"})
    assert type(hosts) == list
    print(hosts)
    assert 'host1.example.com' in hosts
コード例 #5
0
 def test_check_notfound(self):
     import hemApp
     try:
         with self.assertLogs(level='ERROR') as cm:
             hosts = hemApp.discover_hosts({
                 "type": "dns",
                 "name": "notfound.nonexistent"
             })
         assert 'ERROR:hemApp.drivers.discovery_dns:DNS name notfound.nonexistent not found' in cm.output
     except AttributeError:
         # self.assertLogs doesn't work in Python 2.x
         hosts = hemApp.discover_hosts({
             "type": "dns",
             "name": "notfound.nonexistent"
         })
     except dns.resolver.NXDOMAIN:
         assert False == True
     assert type(hosts) == list
     assert hosts == []
コード例 #6
0
def test_check_content_keyed_objects_enable():
    import hemApp
    hosts = hemApp.discover_hosts({
        "type": "file",
        "name": "tests/hosts_keyed_objects.yaml",
        "enabled_key": "check",
        "key": "hostname"
    })
    assert type(hosts) == list
    print(hosts)
    assert 'host0.example.com' not in hosts
    assert 'host1.example.com' in hosts
    assert 'host2.example.com' in hosts
コード例 #7
0
    def test_check_init(self):
        import hemApp
        with requests_mock.mock() as m:
            m.get('http://1.1.1.1:8500/v1/catalog/service/testing',
                  text="""
[
  {
    "ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
    "Node": "foobar",
    "Address": "192.168.10.10",
    "Datacenter": "dc1",
    "TaggedAddresses": {
      "lan": "192.168.10.10",
      "wan": "10.0.10.10"
    },
    "NodeMeta": {
      "somekey": "somevalue"
    },
    "CreateIndex": 51,
    "ModifyIndex": 51,
    "ServiceAddress": "172.17.0.3",
    "ServiceEnableTagOverride": false,
    "ServiceID": "32a2a47f7992:nodea:5000",
    "ServiceName": "foobar",
    "ServicePort": 5000,
    "ServiceTags": [
      "tacos"
    ]
  }
]""")
            hosts = hemApp.discover_hosts({
                "type": "consul",
                "server": "1.1.1.1",
                "name": "testing"
            })
            self.assertEqual(type(hosts), list)
            self.assertTrue("192.168.10.10:5000" in hosts)
コード例 #8
0
def test_check_init():
    import hemApp
    hosts = hemApp.discover_hosts({"type": "file", "name": "hosts.yaml"})
    assert type(hosts) == list
コード例 #9
0
 def test_check_init(self):
     import hemApp
     hosts = hemApp.discover_hosts({"type": "dns", "name": "example.com"})
     self.assertEqual(type(hosts), list)