Esempio n. 1
0
def test_name_resolving():
    destroy_model()
    create_model('test-model')

    destroy_laboratory()
    create_laboratory('test-lab')

    h = add_host('test1')
    d = add_device('node1')

    he = h.add_interface('eth')
    de = d.add_interface('eth1')

    assert h == resolve_host_name('test1')
    assert d == resolve_device_name('node1')
    assert he == resolve_interface_name('test1.eth', model=True)
    assert he == resolve_interface_name('test1.eth')
    assert de == resolve_interface_name('node1.eth1', laboratory=True)
    assert de == resolve_interface_name('node1.eth1')

    py.test.raises(Exceptions.ConfigurationError, resolve_host_name, 'foo')
    py.test.raises(Exceptions.ConfigurationError, resolve_host_name, 'node1')
    py.test.raises(Exceptions.ConfigurationError, resolve_host_name, 'test1.')
    py.test.raises(Exceptions.ConfigurationError, resolve_host_name, 'test1 ')
    py.test.raises(Exceptions.ConfigurationError, resolve_host_name, '.test1')

    py.test.raises(Exceptions.ConfigurationError, resolve_device_name, 'foo')
    py.test.raises(Exceptions.ConfigurationError, resolve_device_name, 'test1')
    py.test.raises(Exceptions.ConfigurationError, resolve_device_name, 'node1.')
    py.test.raises(Exceptions.ConfigurationError, resolve_device_name, 'node1 ')
    py.test.raises(Exceptions.ConfigurationError, resolve_device_name, '.node1')

    py.test.raises(Exceptions.ConfigurationError, resolve_interface_name, 'node1.eth1', model=True)
    py.test.raises(Exceptions.ConfigurationError, resolve_interface_name, 'test1.eth', laboratory=True)
Esempio n. 2
0
def test_no_duplicates():
    clear()

    add_device('foo')
    py.test.raises(Exceptions.NameExistsError, add_device, 'foo')
Esempio n. 3
0
def test_add_device():
    clear()
    add_device('foo')
    assert len(get_laboratory().devices()) == 1
    assert get_laboratory().devices()[0]['name'] == 'foo'