Beispiel #1
0
def test_default_ip():
    d = DeviceBase('localhost', default_ip_address='127.0.0.1')
    assert d.default_ip_address == '127.0.0.1'
Beispiel #2
0
def test_upload_file_with_already_opened_connection():
    conn_info = dict(DEF_CONN_DICT)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    with d.conn.open() as conn:
        d.files.upload(os.path.join(files_folder, 'conn_settings.yaml'))
Beispiel #3
0
def test_base():
    d = DeviceBase('localhost')
    assert d.os.__class__ == LinuxOS
Beispiel #4
0
def test_set_default_conn_explicitely_bad_name_raises_UnknownConnectionError():
    d = DeviceBase('localhost',
                   connections=dict(default=DEF_TELNET_CONN_DICT,
                                    ssh=DEF_CONN_DICT))
    with pytest.raises(UnknownConnectionError):
        d.conn.set_default('ssh2')
Beispiel #5
0
def test_ssh_connection_via_connection_info_using_open_close():
    conn_info = dict(DEF_CONN_DICT_KEY)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    c = d.conn.default.open()
    assert c.check_output('whoami') == d.users.default.username
    d.conn.default.close()
Beispiel #6
0
def test_default_ip_ipv6():
    d = DeviceBase('localhost', ip_type='ipv6')
    assert d.default_ip_address == '::1'
Beispiel #7
0
def test_base_bad_os():
    with pytest.raises(ValueError):
        d = DeviceBase('localhost', os_name='klWindowssOS')
Beispiel #8
0
def test_ssh_conn_instance_get_open_instances_return_current():
    conn_info = dict(DEF_CONN_DICT)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    with d.conn as c:
        assert d.conn.check_output('whoami') == d.users.default.username
        assert c.prompt_found == d.conn.get_open_instance().prompt_found
Beispiel #9
0
def test_ssh_conn_instance_get_open_instances_raises_ConnectionInstanceOpenError(
):
    conn_info = dict(DEF_CONN_DICT)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    with pytest.raises(exceptions.ConnectionInstanceOpenError):
        assert d.conn.get_open_instances()
Beispiel #10
0
def test_ssh_conn_with_no_interface_info_raises_NoDefaultInterfaceError():
    conn_info = dict(DEF_CONN_DICT)
    # removing user info
    d = DeviceBase(connections=dict(default=conn_info))
    with pytest.raises(exceptions.NoDefaultInterfaceError):
        d.conn.open()
Beispiel #11
0
def test_ssh_conn_open_via_with_without_open():
    conn_info = dict(DEF_CONN_DICT)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    with d.conn:
        assert d.conn.check_output('whoami') == d.users.default.username
Beispiel #12
0
def test_ssh_via_open_connection():
    conn_info = dict(DEF_CONN_DICT)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    conn_instance = d.conn.open()
    assert d.conn.check_output('whoami') == d.users.default.username
    conn_instance.close()
Beispiel #13
0
def test_closig_explicitely_using_instance_name():
    conn_info = dict(DEF_CONN_DICT)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    d.conn.open(instance_name='another')
    assert d.conn.check_output('whoami') == d.users.default.username
    d.conn.close(instance_name='another')
Beispiel #14
0
def test_closig_explicitely_without_with():
    conn_info = dict(DEF_CONN_DICT)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    d.conn.open()
    assert d.conn.check_output('whoami') == d.users.default.username
    d.conn.close()
Beispiel #15
0
def test_default_ip_any_ip_type():
    d = DeviceBase('localhost')
    assert d.default_ip_address in ('::1', '127.0.0.1')
Beispiel #16
0
def test_ssh_key():
    conn_info = dict(DEF_CONN_DICT_KEY_ENC)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    with d.conn.open():
        assert d.conn.check_output('whoami') == d.users.default.username
Beispiel #17
0
def test_default_ip_ipv4():
    d = DeviceBase('localhost', ip_type='ipv4')
    assert d.default_ip_address == '127.0.0.1'
Beispiel #18
0
def test_ssh_key_wrong_key_pass_raises_BadSshKeyPasswordError():
    conn_info = dict(DEF_CONN_DICT_KEY_ENC)
    conn_info['user']['key_password'] = '******'
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    with pytest.raises(BadSshKeyPasswordError):
        d.conn.open()
Beispiel #19
0
def test_base_other_os():
    d = DeviceBase('localhost', os_name='Windows')
    assert d.os.__class__ == WindowsOS
Beispiel #20
0
def test_ssh_connection_via_connection_info_using_with():
    conn_info = dict(DEF_CONN_DICT_KEY)
    d = DeviceBase('localhost', connections=dict(default=conn_info))
    with d.conn.default as c:
        assert c.check_output('whoami') == d.users.default.username
Beispiel #21
0
def test_storage_folder():
    """ a device will have a folder """
    cur_path = os.path.realpath('.')
    d = DeviceBase('localhost', storage_path=cur_path)
    assert d.folder == os.path.join(cur_path, 'localhost')
Beispiel #22
0
def test_add_unimplemented_protocol_raises_NotImplementedProtocolError():
    conn_info = dict(DEF_CONN_DICT)
    conn_info['proto'] = 'cmd'
    with pytest.raises(exceptions.NotImplementedProtocolError):
        DeviceBase('localhost', connections=dict(default=conn_info))