diff --git a/.travis.yml b/.travis.yml index 216df98..32c22f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ install: script: - pylama - wget --quiet netng.pl/routeros_test_images/routeros_6.33.3.qcow2 -O images/routeros_6.33.3.qcow2 + - wget --quiet netng.pl/routeros_test_images/routeros_6.43rc21.qcow2 -O images/routeros_6.43rc21.qcow2 - py.test --pylama deploy: provider: pypi diff --git a/images/README.md b/images/README.md index ce698e2..bc57634 100644 --- a/images/README.md +++ b/images/README.md @@ -15,5 +15,6 @@ qemu-system-i386 \ -cdrom ISO_FILE.iso \ -vnc :3 ``` -Install every package except: -- kvm + +* Install every package except `kvm` +* Add `dhcp-client` on `ether1` diff --git a/librouteros/__init__.py b/librouteros/__init__.py index 5e25564..feeadee 100644 --- a/librouteros/__init__.py +++ b/librouteros/__init__.py @@ -43,13 +43,19 @@ def connect(host, username, password, **kwargs): api = arguments['subclass'](protocol=protocol) try: - sentence = api('/login') + # First send dummy credentials to know if we get a =ret= back. + # This way we know if it is a pre 6.43 auth method or not. + sentence = api('/login', **{'name': 'dummy_user', 'password': 'dummy_password'}) token = sentence[0]['ret'] - encoded = encode_password(token, password) - api('/login', **{'name': username, 'response': encoded}) - except (ConnectionError, TrapError, FatalError, MultiTrapError): + except (TrapError, MultiTrapError): + # Login failed so use 6.43 auth method. + api('/login', **{'name': username, 'password': password}) + except (ConnectionError, FatalError): transport.close() raise + else: + # We got =ret= so use pre 6.43 auth method. + api('/login', **{'name': username, 'response': encode_password(token, password)}) return api diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index e1134c0..1c79f54 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -23,7 +23,7 @@ def api_session(): raise librouteros.ConnectionError('could not connect to device') -@pytest.fixture(scope='session') +@pytest.fixture(scope='session', params=('6.33.3', '6.43rc21')) def disk_image(request): """Create a temporary disk image backed by original one.""" img = NamedTemporaryFile() @@ -32,7 +32,7 @@ def disk_image(request): 'qemu-img', 'create', '-f', 'qcow2', # Path to backing file must be absolute or relative to new image - '-b', str(py.path.local().join('images/routeros_6.33.3.qcow2')), + '-b', str(py.path.local().join('images/routeros_{}.qcow2'.format(request.param))), img.name, ] check_call(cmd, stdout=DEV_NULL)