| #!/usr/bin/python |
| # Copyright 2012 Google Inc. All Rights Reserved. |
| # |
| # Disable some checks that aren't important for tests: |
| #gpylint: disable-msg=E0602,C6409,C6111,C0111 |
| |
| __author__ = 'Avery Pennarun (apenwarr@google.com)' |
| |
| from wvtest import * |
| import core |
| |
| |
| @wvtest |
| def testConfigCore(): |
| hosts = core.Hosts() |
| WVPASSEQ(len(hosts), 0) |
| h1 = hosts.FindOrAdd(ether='11:22:33:44:55:66') |
| h1.Set(name='testname', ip='1.2.3.4') |
| h1.platform = 'bob' |
| WVPASSEQ(len(hosts), 1) |
| h1b = hosts.FindOrAdd(ip='1.2.3.4') |
| WVPASSEQ(len(hosts), 1) |
| WVPASSEQ(h1b.name, 'testname') |
| WVPASSEQ(h1b.ether, '11:22:33:44:55:66') |
| WVPASSEQ(h1, h1b) |
| |
| # test Host.Query() |
| WVPASSEQ(hosts.Query(ip=True), [h1]) |
| WVPASSEQ(hosts.Query(ip=False), []) |
| WVPASSEQ(hosts.Query(ip='1.2.3.4'), [h1]) |
| WVPASSEQ(hosts.Query(ip='1.2.3.5'), []) |
| WVPASSEQ(hosts.Query(ip='1.2.3.4', maxcount=0), []) |
| WVEXCEPT(core.QueryError, hosts.Query, ip='1.2.3.5', mincount=1) |
| |
| # add a second host |
| h2 = hosts.FindOrAdd(ether='22:33:44:22:33:44') |
| h2.Set(name='test2') |
| |
| WVPASSEQ(len(hosts), 2) |
| WVPASSEQ(hosts.Query(ip='1.2.3.4'), [h1]) |
| WVPASSEQ(hosts.Query(ip=None), [h2]) |
| WVPASSEQ(hosts.Query(name='test2'), [h2]) |
| WVPASSEQ(hosts.Query(ip=True), [h1]) |
| WVPASSEQ(sorted(hosts.Query(name=True)), sorted([h1, h2])) |
| WVPASSEQ(hosts.Query(ether=True, name='test2'), [h2]) |
| WVPASSEQ(hosts.Query(ether=True, name='testname'), [h1]) |