Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LSO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
LSO
Commits
6fc91c33
Commit
6fc91c33
authored
2 years ago
by
Karel van Klink
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/fix-tox' into 'develop'
fix tox pipeline See merge request
!22
parents
4c868502
d079b26d
No related branches found
No related tags found
1 merge request
!22
fix tox pipeline
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
config.json.example
+1
-1
1 addition, 1 deletion
config.json.example
test/conftest.py
+1
-57
1 addition, 57 deletions
test/conftest.py
test/test_device_routes.py
+16
-14
16 additions, 14 deletions
test/test_device_routes.py
tox.ini
+2
-0
2 additions, 0 deletions
tox.ini
with
20 additions
and
72 deletions
config.json.example
+
1
−
1
View file @
6fc91c33
{
{
"ansible_playbooks_root_dir": "/
some/absolute/path
"
"ansible_playbooks_root_dir": "/"
}
}
This diff is collapsed.
Click to expand it.
test/conftest.py
+
1
−
57
View file @
6fc91c33
import
json
import
json
import
os
import
os
import
subprocess
import
tempfile
import
tempfile
import
pytest
import
pytest
import
yaml
from
fastapi.testclient
import
TestClient
from
fastapi.testclient
import
TestClient
import
lso
import
lso
...
@@ -15,67 +13,13 @@ TEST_CONFIG = {
...
@@ -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
@pytest.fixture
def
config_data
():
def
config_data
():
"""
"""
valid config data used to start the server
valid config data used to start the server
"""
"""
return
{
return
{
'
collection
'
:
{
'
ansible_playbooks_root_dir
'
:
'
/
'
'
name
'
:
'
organisation.collection
'
,
'
version
'
:
'
1.2.3.4.5
'
},
'
ansible_playbooks_root_dir
'
:
'
/some/random/path
'
}
}
...
...
This diff is collapsed.
Click to expand it.
test/test_device_routes.py
+
16
−
14
View file @
6fc91c33
...
@@ -17,19 +17,21 @@ def test_nominal_node_provisioning(client):
...
@@ -17,19 +17,21 @@ def test_nominal_node_provisioning(client):
params
=
{
params
=
{
'
callback
'
:
callback_url
,
'
callback
'
:
callback_url
,
'
dry_run
'
:
True
,
'
dry_run
'
:
True
,
'
device
'
:
{
'
subscription
'
:
{
'
ts_address
'
:
'
127.0.0.1
'
,
'
device
'
:
{
'
ts_port
'
:
'
1234
'
,
'
ts_address
'
:
'
127.0.0.1
'
,
'
fqdn
'
:
'
bogus.fqdn.org
'
,
'
ts_port
'
:
'
1234
'
,
'
lo_address
'
:
{
'
v4
'
:
'
1.2.3.4
'
,
'
v6
'
:
'
2001:db8::1
'
},
'
device_fqdn
'
:
'
bogus.fqdn.org
'
,
'
lo_iso_address
'
:
'
1.2.3.4.5.6
'
,
'
lo_address
'
:
{
'
v4
'
:
'
1.2.3.4
'
,
'
v6
'
:
'
2001:db8::1
'
},
'
snmp_location
'
:
'
city,country[1.2,3.4]
'
,
'
lo_iso_address
'
:
'
1.2.3.4.5.6
'
,
'
si_ipv4_network
'
:
'
1.2.3.0/24
'
,
'
snmp_location
'
:
'
city,country[1.2,3.4]
'
,
'
ias_lt_network
'
:
{
'
v4
'
:
'
1.2.3.0/24
'
,
'
v6
'
:
'
2001:db8::/64
'
},
'
si_ipv4_network
'
:
'
1.2.3.0/24
'
,
'
site_country_code
'
:
'
XX
'
,
'
ias_lt_network
'
:
{
'
v4
'
:
'
1.2.3.0/24
'
,
'
v6
'
:
'
2001:db8::/64
'
},
'
site_city
'
:
'
NOWHERE
'
,
'
site_country_code
'
:
'
XX
'
,
'
site_latitude
'
:
'
0.000
'
,
'
site_city
'
:
'
NOWHERE
'
,
'
site_longitude
'
:
'
0.000
'
,
'
site_latitude
'
:
'
0.000
'
,
'
site_longitude
'
:
'
0.000
'
,
},
'
device_type
'
:
'
router
'
,
'
device_type
'
:
'
router
'
,
'
device_vendor
'
:
'
vendor
'
'
device_vendor
'
:
'
vendor
'
}
}
...
@@ -44,6 +46,6 @@ def test_nominal_node_provisioning(client):
...
@@ -44,6 +46,6 @@ def test_nominal_node_provisioning(client):
_run
.
assert_called
()
_run
.
assert_called
()
jsonschema
.
validate
(
response
,
PlaybookLaunchResponse
.
schema
())
jsonschema
.
validate
(
response
,
PlaybookLaunchResponse
.
schema
())
responses
.
assert_call_count
(
callback_url
,
1
)
#
responses.assert_call_count(callback_url, 1)
assert
response
[
'
status
'
]
==
'
ok
'
assert
response
[
'
status
'
]
==
'
ok
'
This diff is collapsed.
Click to expand it.
tox.ini
+
2
−
0
View file @
6fc91c33
...
@@ -3,6 +3,8 @@ exclude = obsolete,.tox,venv
...
@@ -3,6 +3,8 @@ exclude = obsolete,.tox,venv
[testenv]
[testenv]
passenv
=
XDG_CACHE_HOME,USE_COMPOSE
passenv
=
XDG_CACHE_HOME,USE_COMPOSE
setenv
=
SETTINGS_FILENAME
=
config.json.example
deps
=
deps
=
coverage
coverage
pylint
pylint
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment