-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added requests-toolbelt (missing dependency), resolves #10 - also added pytest configuration files - added fixtures for tests to pass - added tests which were missing from Bitbucket - applied black formatting - GitHub test automation - assure 3.5 compatibility - remove hashes from requirements.txt
- Loading branch information
Showing
23 changed files
with
2,257 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# basic workflow to run tests | ||
|
||
name: CI | ||
|
||
on: | ||
|
||
# Triggers the workflow on push or pull request events but only for the master branch | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.5, 3.6, 3.7, 3.8] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
# pip install flake8 pytest | ||
# if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi | ||
pip install -r tests/requirements.txt | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.direnv/ | ||
.envrc | ||
.python-version | ||
.venv | ||
dist/ | ||
*/__pycache__ | ||
docs/build/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
|
||
.phony: export | ||
|
||
# https://github.com/python-poetry/poetry/issues/3160 | ||
# when resolved, we should be able to run with hashes | ||
tests/requirements.txt: poetry.lock | ||
poetry export --format=requirements.txt --dev --without-hashes --output=$@ | ||
|
||
clean: | ||
rm -rf dist virl2_client.egg-info .built | ||
find . -type f -name '*.pyc' -exec rm {} \; || true | ||
find . -type d -name '__pycache__' -exec rmdir {} \; || true | ||
cd docs && make clean | ||
|
||
poetry: | ||
poetry update | ||
|
||
export: tests/requirements.txt | ||
@echo "exported dependencies" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# | ||
# Python bindings for the Cisco VIRL 2 Network Simulation Platform | ||
# | ||
# This file is part of VIRL 2 | ||
# | ||
# Copyright 2020-2021 Cisco Systems Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import pytest | ||
import time | ||
import warnings | ||
|
||
from requests import HTTPError | ||
from unittest.mock import patch | ||
from urllib3.exceptions import InsecureRequestWarning | ||
|
||
from virl2_client import ClientLibrary | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--controller-url", | ||
default="http://127.0.0.1:8001", | ||
help="The URL of simple controller server", | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def controller_url(request): | ||
return request.config.getoption("--controller-url") | ||
|
||
|
||
@pytest.fixture | ||
def no_ssl_warnings(): | ||
with warnings.catch_warnings(): | ||
# We don't care about SSL connections to untrusted servers in tests: | ||
warnings.simplefilter("ignore", InsecureRequestWarning) | ||
yield | ||
|
||
|
||
def stop_wipe_and_remove_all_labs(client_library: ClientLibrary): | ||
lab_list = client_library.get_lab_list() | ||
for lab_id in lab_list: | ||
lab = client_library.join_existing_lab(lab_id) | ||
lab.stop() | ||
lab.wipe() | ||
client_library.remove_lab(lab_id) | ||
|
||
|
||
def client_library_keep_labs_base( | ||
url, usr="cml2", pwd="cml2cml2", ssl_verify=False, allow_http=True | ||
): | ||
clientlibrary = ClientLibrary( | ||
url, | ||
username=usr, | ||
password=pwd, | ||
ssl_verify=ssl_verify, | ||
allow_http=allow_http, | ||
) | ||
for _ in range(5): | ||
try: | ||
clientlibrary.is_system_ready() | ||
except HTTPError as err: | ||
if err.errno == 504: | ||
# system still initialising, wait longer | ||
time.sleep(2) | ||
|
||
return clientlibrary | ||
|
||
|
||
@pytest.fixture | ||
def client_library_keep_labs(no_ssl_warnings, controller_url: str) -> ClientLibrary: | ||
# for integration testing, the client library needs to connect to a mock simulator | ||
# running via HTTP on a non SSL servr / non-standard port. We therefore need to | ||
# set the allow_http to True. Otherwise the client library would enforce the HTTPS | ||
# scheme and the tests would fail. This should never be required in the wild. | ||
yield client_library_keep_labs_base(url=controller_url) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def client_library_session(controller_url: str) -> ClientLibrary: | ||
"""This client library has session lifetime""" | ||
yield client_library_keep_labs_base(url=controller_url) | ||
|
||
|
||
@pytest.fixture | ||
def client_library(client_library_keep_labs: ClientLibrary) -> ClientLibrary: | ||
clientlibrary = client_library_keep_labs | ||
stop_wipe_and_remove_all_labs(clientlibrary) | ||
# Reset "current" lab: | ||
clientlibrary.lab = None | ||
yield clientlibrary | ||
# tear down - delete labs from the tests | ||
# TODO: see if these need updating now remove_all_labs doesnt stop the lab | ||
stop_wipe_and_remove_all_labs(clientlibrary) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
virl2\_client.models package | ||
============================ | ||
|
||
.. automodule:: virl2_client.models | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Submodules | ||
---------- | ||
|
||
virl2\_client.models.authentication | ||
----------------------------------- | ||
|
||
.. automodule:: virl2_client.models.authentication | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.cl\_pyats | ||
------------------------------ | ||
|
||
.. automodule:: virl2_client.models.cl_pyats | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.groups | ||
--------------------------- | ||
|
||
.. automodule:: virl2_client.models.groups | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.interface | ||
------------------------------ | ||
|
||
.. automodule:: virl2_client.models.interface | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.lab | ||
------------------------ | ||
|
||
.. automodule:: virl2_client.models.lab | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.licensing | ||
------------------------------ | ||
|
||
.. automodule:: virl2_client.models.licensing | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.link | ||
------------------------- | ||
|
||
.. automodule:: virl2_client.models.link | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.node | ||
------------------------- | ||
|
||
.. automodule:: virl2_client.models.node | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.node\_image\_definitions | ||
--------------------------------------------- | ||
|
||
.. automodule:: virl2_client.models.node_image_definitions | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.system | ||
--------------------------- | ||
|
||
.. automodule:: virl2_client.models.system | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
virl2\_client.models.users | ||
-------------------------- | ||
|
||
.. automodule:: virl2_client.models.users | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.