Skip to content

Commit

Permalink
Missing changes from Bitbucket
Browse files Browse the repository at this point in the history
- 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
rschmied committed May 18, 2021
1 parent 10d891b commit 0acbc1d
Show file tree
Hide file tree
Showing 23 changed files with 2,257 additions and 459 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.direnv/
.envrc
.python-version
.venv
dist/
*/__pycache__
docs/build/*
Expand Down
14 changes: 14 additions & 0 deletions Makefile
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"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CI](https://github.com/CiscoDevNet/virl2-client/actions/workflows/main.yml/badge.svg)](https://github.com/CiscoDevNet/virl2-client/actions/workflows/main.yml)

# VIRL 2 Client Library

## Introduction
Expand Down
107 changes: 107 additions & 0 deletions conftest.py
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)
99 changes: 99 additions & 0 deletions docs/source/api/virl2_client.models.rst
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:

25 changes: 17 additions & 8 deletions docs/source/virl2_client.rst → docs/source/api/virl2_client.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
VIRL :sup:`2` API Client
=========================
virl2\_client package
=====================

.. automodule:: virl2_client
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------
Expand All @@ -8,26 +13,30 @@ Subpackages

virl2_client.models

Exceptions
-----------
Submodules
----------

virl2\_client.exceptions
------------------------

.. automodule:: virl2_client.exceptions
:members:
:undoc-members:
:show-inheritance:

Utils
------
virl2\_client.utils
-------------------

.. automodule:: virl2_client.utils
:members:
:undoc-members:
:show-inheritance:

ClientLibrary
--------------
virl2\_client.virl2\_client
---------------------------

.. automodule:: virl2_client.virl2_client
:members:
:undoc-members:
:show-inheritance:

7 changes: 0 additions & 7 deletions docs/source/modules.rst

This file was deleted.

Loading

0 comments on commit 0acbc1d

Please sign in to comment.