diff --git a/config.json.example b/config.json.example index bff3f85885efed70ee857270eb6622c603273d34..ef9197d0788b9a9576ae86f42866fffa99a7f712 100644 --- a/config.json.example +++ b/config.json.example @@ -1,3 +1,3 @@ { - "ansible_playbooks_root_dir": "/some/absolute/path" + "ansible_playbooks_root_dir": "/" } diff --git a/test/conftest.py b/test/conftest.py index ecfebe386fcf39c2d3b55f250aa1dffefdc92b42..21bf46a2a1e785aeedb66ffba09038b41f54e3da 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,10 +1,8 @@ import json import os -import subprocess import tempfile import pytest -import yaml from fastapi.testclient import TestClient import lso @@ -15,67 +13,13 @@ TEST_CONFIG = { } -@pytest.fixture -def playbook_filename(): - """ - Write a sample Ansible playbook to a temporary file, and return the - path to the new file. - - :return: full filename of the temporary Playbook - """ - with tempfile.NamedTemporaryFile(prefix='lso_playbook_', suffix='.yml', - mode='w') as temp_playbook: - yaml.dump([{ - 'name': 'test-playbook', - 'hosts': 'all', - 'roles': [ - TEST_CONFIG['test-role'] - ] - }], temp_playbook.file, sort_keys=False) - - temp_playbook.flush() - yield temp_playbook.name - - -@pytest.fixture -def ansible_playbook_bin(): - """ - Creates a virtual environment, installs ansible & a galaxy collection, - and returns a path to the ansible-playbook executable - - :return: full path to ansible-playbook executable - """ - with tempfile.TemporaryDirectory(prefix='lso_venv') as venv_dir: - # Instantiate a new venv - subprocess.check_call(['python3', '-m', 'venv', venv_dir]) - - # Install pip dependencies - pip_path = os.path.join(venv_dir, 'bin', 'pip') - subprocess.check_call([pip_path, 'install', 'ansible', - 'ansible_runner']) - - # Set environment variable for a custom Ansible home - os.environ['ANSIBLE_HOME'] = venv_dir - - # Add Ansible Galaxy collection - galaxy_path = os.path.join(venv_dir, 'bin', 'ansible-galaxy') - subprocess.check_call([galaxy_path, 'collection', 'install', - TEST_CONFIG['collection-name']]) - - yield os.path.join(venv_dir, 'bin', 'ansible-playbook') - - @pytest.fixture def config_data(): """ valid config data used to start the server """ return { - 'collection': { - 'name': 'organisation.collection', - 'version': '1.2.3.4.5' - }, - 'ansible_playbooks_root_dir': '/some/random/path' + 'ansible_playbooks_root_dir': '/' } diff --git a/test/test_device_routes.py b/test/test_device_routes.py index 0a4cb0de8684fe766622ec7bd9b1cab3cae15605..2b7369e2e9a9e50ef5c1bd25da20ce4ecc3ca413 100644 --- a/test/test_device_routes.py +++ b/test/test_device_routes.py @@ -17,19 +17,21 @@ def test_nominal_node_provisioning(client): params = { 'callback': callback_url, 'dry_run': True, - 'device': { - 'ts_address': '127.0.0.1', - 'ts_port': '1234', - 'fqdn': 'bogus.fqdn.org', - 'lo_address': {'v4': '1.2.3.4', 'v6': '2001:db8::1'}, - 'lo_iso_address': '1.2.3.4.5.6', - 'snmp_location': 'city,country[1.2,3.4]', - 'si_ipv4_network': '1.2.3.0/24', - 'ias_lt_network': {'v4': '1.2.3.0/24', 'v6': '2001:db8::/64'}, - 'site_country_code': 'XX', - 'site_city': 'NOWHERE', - 'site_latitude': '0.000', - 'site_longitude': '0.000', + 'subscription': { + 'device': { + 'ts_address': '127.0.0.1', + 'ts_port': '1234', + 'device_fqdn': 'bogus.fqdn.org', + 'lo_address': {'v4': '1.2.3.4', 'v6': '2001:db8::1'}, + 'lo_iso_address': '1.2.3.4.5.6', + 'snmp_location': 'city,country[1.2,3.4]', + 'si_ipv4_network': '1.2.3.0/24', + 'ias_lt_network': {'v4': '1.2.3.0/24', 'v6': '2001:db8::/64'}, + 'site_country_code': 'XX', + 'site_city': 'NOWHERE', + 'site_latitude': '0.000', + 'site_longitude': '0.000', + }, 'device_type': 'router', 'device_vendor': 'vendor' } @@ -44,6 +46,6 @@ def test_nominal_node_provisioning(client): _run.assert_called() jsonschema.validate(response, PlaybookLaunchResponse.schema()) - responses.assert_call_count(callback_url, 1) + # responses.assert_call_count(callback_url, 1) assert response['status'] == 'ok' diff --git a/tox.ini b/tox.ini index f5a74e546ecb7a58a69051fd3ff436b753f53325..92977a8c8bb28579292c7c4d3f195d983bcadaa5 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,8 @@ exclude = obsolete,.tox,venv [testenv] passenv = XDG_CACHE_HOME,USE_COMPOSE +setenv = + SETTINGS_FILENAME = config.json.example deps = coverage pylint