Skip to content

Commit

Permalink
release 2.3.0 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschmied committed Mar 15, 2022
1 parent f2c0139 commit c59feb4
Show file tree
Hide file tree
Showing 43 changed files with 7,725 additions and 2,815 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# 3.5 is a bit of a pain, we should consider dropping it?
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.envrc
.python-version
.venv
Expand All @@ -7,3 +8,4 @@ dist/
docs/build/*
*.pyc
*.egg-info
pytest_integration.xml
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

#
# for the eslint command to work, this is needed:
#
# yarn global add eslint
#
# however, this might still not be the correct solution
# as the eslintrc.json and some eslint plugins are
# probably only available when in the proper directory
#

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 21.5b1
hooks:
- id: black
language_version: python3
15 changes: 6 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

.phony: export docs
.phony: export diff

# 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 . -not -path ./.venv -depth -type f -name '*.pyc' -exec rm {} \; || true
find . -not -path ./.venv -depth -type d -name '__pycache__' -exec rmdir {} \; || true
rm -rf dist virl2_client.egg-info .built .pytest_cache
find . -depth -type f -name '*.pyc' -exec rm {} \; || true
find . -depth -type d -name '__pycache__' -exec rmdir {} \; || true
cd docs && make clean

poetry:
Expand All @@ -18,8 +18,5 @@ poetry:
export: tests/requirements.txt
@echo "exported dependencies"

docs: docs/dist

docs/dist:
@pushd docs && make buildapi
@sphinx-build -b html -t internal docs/source docs/dist
diff:
diff -ruN -X.gitignore -x.github -x.git -xdist -x.pytest_cache ./ ../simple/virl2_client/ | pygmentize | less -r
99 changes: 72 additions & 27 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,60 @@
# limitations under the License.
#

import os
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
from virl2_client import ClientConfig, ClientLibrary


def pytest_addoption(parser):
# only add these options if the test is run inside the
# root virl2 repository itself and not from outside
root_dir = parser.extra_info.get("rootdir", "")
if not root_dir.endswith("virl2_client"):
return

parser.addoption(
"--controller-url",
default="http://127.0.0.1:8001",
help="The URL of simple controller server",
default="https://127.0.0.1",
metavar="VIRL2_URL",
help="The URL of a CML2 controller",
)

parser.addoption(
"--controller-username",
default=None,
metavar="VIRL2_USER",
help="The user on CML2 controller",
)

@pytest.fixture(scope="session")
def controller_url(request):
return request.config.getoption("--controller-url")
parser.addoption(
"--controller-password",
default=None,
metavar="VIRL2_PASS",
help="The user's password on CML2 controller",
)

parser.addoption(
"--controller-ssl-verify",
default=False,
nargs="?",
const=True,
metavar="CA_BUNDLE",
help="Verify certificate of CML2 controller",
)

parser.addoption(
"--controller-allow-http",
default=False,
action="store_true",
help="Allow HTTP for CML2 controller URL",
)


@pytest.fixture
Expand All @@ -59,49 +91,62 @@ def stop_wipe_and_remove_all_labs(client_library: ClientLibrary):
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,
@pytest.fixture(scope="session")
def client_config(request) -> ClientConfig:
return ClientConfig(
url=request.config.getoption("--controller-url"),
username=request.config.getoption("--controller-username"),
password=request.config.getoption("--controller-password"),
ssl_verify=request.config.getoption("--controller-ssl-verify"),
allow_http=request.config.getoption("--controller-allow-http"),
raise_for_auth_failure=True,
)


def client_library_keep_labs_base(client_config: ClientConfig) -> ClientLibrary:
client_library = client_config.make_client()
for _ in range(5):
try:
clientlibrary.is_system_ready()
client_library.is_system_ready()
except HTTPError as err:
if err.errno == 504:
# system still initialising, wait longer
time.sleep(2)

return clientlibrary
return client_library


@pytest.fixture
def client_library_keep_labs(no_ssl_warnings, controller_url: str) -> ClientLibrary:
def client_library_keep_labs(
no_ssl_warnings, client_config: ClientConfig
) -> 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)
yield client_library_keep_labs_base(client_config)


@pytest.fixture(scope="session")
def client_library_session(controller_url: str) -> ClientLibrary:
def client_library_session(client_config: ClientConfig) -> ClientLibrary:
"""This client library has session lifetime"""
yield client_library_keep_labs_base(url=controller_url)
yield client_library_keep_labs_base(client_config)


@pytest.fixture
def client_library(client_library_keep_labs: ClientLibrary) -> ClientLibrary:
clientlibrary = client_library_keep_labs
stop_wipe_and_remove_all_labs(clientlibrary)
client_library = client_library_keep_labs
stop_wipe_and_remove_all_labs(client_library)
# Reset "current" lab:
clientlibrary.lab = None
yield clientlibrary
client_library.lab = None
yield client_library
# 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)
stop_wipe_and_remove_all_labs(client_library)


@pytest.fixture(scope="function")
def change_test_dir(request):
os.chdir(request.fspath.dirname)
yield
os.chdir(request.config.invocation_dir)
41 changes: 26 additions & 15 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ and is interactive::

LAB_USERNAME = 'cisco'
LAB_PASSWORD = 'cisco'
VIRL_CONTROLLER = 'virl2-controller'
VIRL_CONTROLLER = 'cml2-controller'
VIRL_USERNAME = input('username: ')
VIRL_PASSWORD = getpass.getpass('password: ')

Expand Down Expand Up @@ -180,16 +180,20 @@ and retrieve licensing status using the the VIRL2 client library::
import json
from virl2_client import ClientLibrary

VIRL_CONTROLLER = "virl2-controller"
VIRL_CONTROLLER = "cml2-controller"
VIRL_USERNAME = input("username: ")
VIRL_PASSWORD = getpass.getpass("password: ")
SL_TOKEN = input("Smart License token: ")
SL_TOKEN = input("smart license token: ")
PRODUCT_CONFIG = input("product configuration: ")

client = ClientLibrary(VIRL_CONTROLLER, VIRL_USERNAME, VIRL_PASSWORD, ssl_verify=False)

# Get the licensing handle from the client as a property
licensing = client.licensing

# Set the product configuration
licensing.set_product_license(PRODUCT_CONFIG)

# Setup default license transport (i.e., directly connected to the external
# Smart License server)
licensing.set_default_transport()
Expand Down Expand Up @@ -221,7 +225,6 @@ The output for this would look something like the following::


{
"udi": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"registration": {
"status": "COMPLETED",
"expires": "2021-06-10 20:17:39",
Expand Down Expand Up @@ -257,15 +260,6 @@ The output for this would look something like the following::
},
"expires": "2020-10-23 16:39:07"
},
"reservation_mode": false,
"transport": {
"ssms": "https://tools.cisco.com/its/service/oddce/services/DDCEService",
"proxy": {
"server": null,
"port": null
},
"default_ssms": "https://tools.cisco.com/its/service/oddce/services/DDCEService"
},
"features": [
{
"name": "CML - Enterprise License",
Expand All @@ -282,6 +276,23 @@ The output for this would look something like the following::
"version": "1.0"
}
]
"reservation_mode": false,
"transport": {
"ssms": "https://tools.cisco.com/its/service/oddce/services/DDCEService",
"proxy": {
"server": null,
"port": null
},
"default_ssms": "https://tools.cisco.com/its/service/oddce/services/DDCEService"
},
"udi": {
"hostname": "cml2-controller",
"product_uuid": "00000000-0000-4000-a000-000000000000"
},
"product_license": {
"active": "CML_Personal",
"is_enterprise": False
}
}

[
Expand Down Expand Up @@ -328,7 +339,7 @@ should be removed::

from virl2_client import ClientLibrary

VIRL_CONTROLLER = "virl2-controller"
VIRL_CONTROLLER = "cml2-controller"
VIRL_USERNAME = input("username: ")
VIRL_PASSWORD = getpass.getpass("password: ")
LAB_NAME = input("enter lab name: ")
Expand Down Expand Up @@ -368,7 +379,7 @@ should be removed::
print()
lnum = 0
while lnum < 1 or lnum > i:
lnum = input("Enter link number to condition (1-{}): ".format(i))
lnum = input("enter link number to condition (1-{}): ".format(i))
try:
lnum = int(lnum)
except ValueError:
Expand Down
Loading

0 comments on commit c59feb4

Please sign in to comment.