Skip to content

Commit

Permalink
Dev 2.6 rc2 to main (#43)
Browse files Browse the repository at this point in the history
* 2.6.0 changes from BB

SIMPLE-5561 fixed test with events

Updated test requirements

Bumped requests to 2.31.0 to prevent known vulnerabilities
  • Loading branch information
tmikuska committed Jun 26, 2023
1 parent 1f3e3d5 commit 831f841
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 52 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 21 additions & 25 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
anyio==3.6.2; python_full_version >= "3.6.2" and python_version >= "3.7"
attrs==22.1.0; python_version >= "3.7"
certifi==2022.9.24; python_version >= "3.7"
cfgv==3.3.1; python_full_version >= "3.6.1" and python_version >= "3.7"
certifi==2022.12.7; python_version >= "3.7"
cfgv==3.3.1; python_full_version >= "3.6.1" and python_version >= "3.8"
colorama==0.4.6; python_version >= "3.7" and python_full_version < "3.0.0" and sys_platform == "win32" or sys_platform == "win32" and python_version >= "3.7" and python_full_version >= "3.7.0"
distlib==0.3.6; python_version >= "3.7"
exceptiongroup==1.0.4; python_version < "3.11" and python_version >= "3.7"
filelock==3.8.0; python_version >= "3.7"
flake8==5.0.4; python_full_version >= "3.6.1"
distlib==0.3.6; python_version >= "3.8"
exceptiongroup==1.1.1; python_version < "3.11" and python_version >= "3.7"
filelock==3.11.0; python_version >= "3.8"
flake8==6.0.0; python_full_version >= "3.8.1"
h11==0.14.0; python_version >= "3.7"
httpcore==0.16.2; python_version >= "3.7"
httpx==0.23.1; python_version >= "3.7"
identify==2.5.9; python_version >= "3.7"
idna==3.4; python_version >= "3.7" and python_full_version >= "3.6.2"
iniconfig==1.1.1; python_version >= "3.7"
mccabe==0.7.0; python_version >= "3.6" and python_full_version >= "3.6.1"
nodeenv==1.7.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.7.0" and python_version >= "3.7"
packaging==21.3; python_version >= "3.7"
platformdirs==2.5.4; python_version >= "3.7"
httpcore==0.17.0; python_version >= "3.7"
httpx==0.24.0; python_version >= "3.7"
identify==2.5.22; python_version >= "3.8"
idna==3.4; python_full_version >= "3.6.2" and python_version >= "3.7"
iniconfig==2.0.0; python_version >= "3.7"
mccabe==0.7.0; python_version >= "3.6" and python_full_version >= "3.8.1"
nodeenv==1.7.0; python_version >= "3.8" and python_full_version < "3.0.0" or python_full_version >= "3.7.0" and python_version >= "3.8"
packaging==23.1; python_version >= "3.7"
platformdirs==3.2.0; python_version >= "3.8"
pluggy==1.0.0; python_version >= "3.7"
pre-commit==2.20.0; python_version >= "3.7"
pycodestyle==2.9.1; python_version >= "3.6" and python_full_version >= "3.6.1"
pyflakes==2.5.0; python_version >= "3.6" and python_full_version >= "3.6.1"
pyparsing==3.0.9; python_full_version >= "3.6.8" and python_version >= "3.7"
pytest==7.2.0; python_version >= "3.7"
pyyaml==6.0; python_version >= "3.7"
pre-commit==3.2.2; python_version >= "3.8"
pycodestyle==2.10.0; python_version >= "3.6" and python_full_version >= "3.8.1"
pyflakes==3.0.1; python_version >= "3.6" and python_full_version >= "3.8.1"
pytest==7.3.1; python_version >= "3.7"
pyyaml==6.0; python_version >= "3.8"
respx==0.20.1; python_version >= "3.7"
rfc3986==1.5.0; python_version >= "3.7"
sniffio==1.3.0; python_full_version >= "3.6.2" and python_version >= "3.7"
toml==0.10.2; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.7"
tomli==2.0.1; python_version < "3.11" and python_version >= "3.7"
virtualenv==20.17.0; python_version >= "3.7"
virtualenv==20.21.0; python_version >= "3.8"
8 changes: 8 additions & 0 deletions virl2_client/event_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ def _parse_lab_state(self, event: Event) -> None:

def _parse_element_created(self, event: Event) -> None:
new_element: Node | Interface | Link
existing_elements: dict = getattr(event.lab, f"_{event.element_type}s", {})
if event.element_id in existing_elements:
# element was created by this client, so it already exists,
# but the event might at least contain some new data
# that was added during serverside creation
event.element = existing_elements[event.element_id]
self._parse_element_modified(event)
return
if event.element_type == "node":
new_element = event.lab._import_node(
event.element_id,
Expand Down
2 changes: 1 addition & 1 deletion virl2_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
node and image definition and helper classes for automation
and authentication."""

from .auth_management import AuthManagement
from .authentication import TokenAuth
from .groups import GroupManagement
from .interface import Interface
from .lab import Lab
from .auth_management import AuthManagement
from .licensing import Licensing
from .link import Link
from .node import Node
Expand Down
4 changes: 2 additions & 2 deletions virl2_client/models/auth_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from __future__ import annotations

import time
from typing import Any, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Optional

from .resource_pools import ResourcePool
from ..exceptions import MethodNotActive
from .resource_pools import ResourcePool

if TYPE_CHECKING:
from httpx import Client
Expand Down
1 change: 0 additions & 1 deletion virl2_client/models/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def token(self, value: Optional[str]):
def auth_flow(
self, request: httpx.Request
) -> Generator[httpx.Request, httpx.Response, None]:

request.headers["Authorization"] = "Bearer {}".format(self.token)
response = yield request

Expand Down
15 changes: 8 additions & 7 deletions virl2_client/models/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Optional
from ..utils import _UNCHANGED

from ..utils import UNCHANGED

if TYPE_CHECKING:
import httpx
Expand Down Expand Up @@ -91,9 +92,9 @@ def update_group(
self,
group_id: str,
name: Optional[str] = None,
description: Optional[str] = _UNCHANGED,
members: Optional[list[str]] = _UNCHANGED,
labs: Optional[list[dict[str, str]]] = _UNCHANGED,
description: Optional[str] = UNCHANGED,
members: Optional[list[str]] = UNCHANGED,
labs: Optional[list[dict[str, str]]] = UNCHANGED,
) -> dict:
"""
Updates a group.
Expand All @@ -108,11 +109,11 @@ def update_group(
data: dict[str, str | list] = {}
if name is not None:
data["name"] = name
if description is not _UNCHANGED:
if description is not UNCHANGED:
data["description"] = description
if members is not _UNCHANGED:
if members is not UNCHANGED:
data["members"] = members
if labs is not _UNCHANGED:
if labs is not UNCHANGED:
data["labs"] = labs
url = self.base_url + "/{}".format(group_id)
return self._session.patch(url, json=data).json()
Expand Down
1 change: 0 additions & 1 deletion virl2_client/models/licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@


class Licensing:

max_wait = 30
wait_interval = 1.5

Expand Down
9 changes: 5 additions & 4 deletions virl2_client/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ def state(self) -> Optional[str]:
@check_stale
@locked
def interfaces(self) -> list[Interface]:
self.lab.sync_topology_if_outdated()
# self.lab.sync_topology_if_outdated()
return [iface for iface in self.lab.interfaces() if iface.node is self]

@locked
def physical_interfaces(self) -> list[Interface]:
self.lab.sync_topology_if_outdated()
# self.lab.sync_topology_if_outdated()
return [iface for iface in self.interfaces() if iface.physical]

@check_stale
Expand Down Expand Up @@ -607,8 +607,9 @@ def map_l3_addresses_to_interfaces(
continue
ipv4 = entry.get("ip4")
ipv6 = entry.get("ip6")
iface = self.get_interface_by_label(label)
if not iface:
try:
iface = self.get_interface_by_label(label)
except InterfaceNotFound:
continue
iface.ip_snooped_info = {
"mac_address": mac_address,
Expand Down
20 changes: 11 additions & 9 deletions virl2_client/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Optional
from ..utils import _UNCHANGED

from ..utils import UNCHANGED

if TYPE_CHECKING:
import httpx

Expand Down Expand Up @@ -98,12 +100,12 @@ def create_user(
def update_user(
self,
user_id: str,
fullname: Optional[str] = _UNCHANGED,
description: Optional[str] = _UNCHANGED,
groups: Optional[list[str]] = _UNCHANGED,
fullname: Optional[str] = UNCHANGED,
description: Optional[str] = UNCHANGED,
groups: Optional[list[str]] = UNCHANGED,
admin: Optional[bool] = None,
password_dict: Optional[dict[str, str]] = None,
resource_pool: Optional[str] = _UNCHANGED,
resource_pool: Optional[str] = UNCHANGED,
) -> dict:
"""
Updates user.
Expand All @@ -118,17 +120,17 @@ def update_user(
:return: user object
"""
data: dict[str, Any] = {}
if fullname is not _UNCHANGED:
if fullname is not UNCHANGED:
data["fullname"] = fullname
if description is not _UNCHANGED:
if description is not UNCHANGED:
data["description"] = description
if admin is not None:
data["admin"] = admin
if groups is not _UNCHANGED:
if groups is not UNCHANGED:
data["groups"] = groups
if password_dict is not None:
data["password"] = password_dict
if resource_pool is not _UNCHANGED:
if resource_pool is not UNCHANGED:
data["resource_pool"] = resource_pool

url = self.base_url + "/{}".format(user_id)
Expand Down
2 changes: 1 addition & 1 deletion virl2_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __repr__(self):
return "<Unchanged>"


_UNCHANGED = _Sentinel()
UNCHANGED = _Sentinel()


def _make_not_found(instance: Element, owner: Type[Element]) -> ElementNotFound:
Expand Down

0 comments on commit 831f841

Please sign in to comment.