Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increased Python version to 3.11 #334

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1253906
Update requirements.txt
Josephine-Rutten Dec 22, 2023
da30fba
small code changes
Josephine-Rutten Jan 11, 2024
39d579d
Update cnaas-setup.sh
Josephine-Rutten Jan 12, 2024
6cfdaa0
Update requirements.txt
Josephine-Rutten Jan 15, 2024
d96e4d2
upped version in docker-compose, upped docker debian version to bookw…
Josephine-Rutten Jan 15, 2024
c93d950
Update cnaas-setup.sh
Josephine-Rutten Jan 15, 2024
62b8e15
Merge branch 'develop' into feature.increasepythonversion
Josephine-Rutten Jan 18, 2024
f13c6c3
migrate to pydantic v2, optional fields defaults to None to mark them as
indy-independence Jan 22, 2024
90be20b
pydantic started using json schema defs?
indy-independence Jan 22, 2024
025a972
revert change to docker compose version
indy-independence Jan 22, 2024
1653d18
Add auth_setting to disable verification of audience
indy-independence Jan 24, 2024
db8db43
make logic easier to read
indy-independence Jan 24, 2024
068c087
replace each_item validator with annotated int
indy-independence Jan 24, 2024
df0cbce
Use pydanticv2 field_validators instead of v1 validators
indy-independence Jan 24, 2024
011049f
Fix more remaining pydanticv2 optional migrations
indy-independence Jan 25, 2024
4110222
Update app_settings to also use new pydanticv2 field_validator
indy-independence Jan 25, 2024
0ebe5d0
pydanticv2 migration, ValidationError changed modules
indy-independence Jan 25, 2024
16dda49
More pydanticv2 migrations, schema->model_json_schema, and
indy-independence Jan 25, 2024
37a039c
Update python version badge
indy-independence Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:buster
FROM debian:bookworm

USER root

Expand All @@ -16,7 +16,7 @@ RUN apt-get update \
libpq-dev \
libssl-dev \
net-tools \
netcat \
netcat-traditional \
netcat-openbsd \
nginx \
procps \
Expand All @@ -26,11 +26,17 @@ RUN apt-get update \
python3-venv \
python3-wheel \
python3-yaml \
python3-full \
psmisc \
supervisor \
uwsgi-plugin-python3 \
ssh-client \
&& pip3 install --no-cache-dir uwsgi
python3-gevent\

&& pip3 install --no-cache-dir uwsgi --break-system-packages
# && apt-get install -y uwsgi

#RUN pip3 install uwsgi

# Prepare for supervisord, ngninx
COPY config/supervisord_app.conf /etc/supervisor/supervisord.conf
Expand Down Expand Up @@ -80,7 +86,6 @@ USER www-data
# Prepare for uwsgi
COPY --chown=root:www-data config/uwsgi.ini /opt/cnaas/venv/cnaas-nms/


# Expose HTTPS
EXPOSE 1443

Expand Down
4 changes: 3 additions & 1 deletion docker/api/cnaas-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export DEBIAN_FRONTEND noninteractive


# Start venv
python3 -m venv /opt/cnaas/venv
python3.11 -m venv /opt/cnaas/venv
cd /opt/cnaas/venv/
source bin/activate

Expand All @@ -21,4 +21,6 @@ git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*
git fetch --all
git checkout $2
# install dependencies
python3 -m pip install --no-cache-dir uwsgi
python3 -m pip install --no-cache-dir uwsgi gevent
python3 -m pip install --no-cache-dir -r requirements.txt
2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.7'
version: '3.11'
services:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm is this just a search replace gone wrong? this setting is for docker and not the python version


#
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ mypy-extensions==0.4.3
markupsafe==2.1.1
nornir==3.3.0
nornir-jinja2==0.2.0
nornir-napalm==0.3.0
nornir-napalm==0.4.0
nornir-netmiko==0.2.0
nornir-utils==0.2.0
napalm==4.0.0
napalm==4.1.0
nose==1.3.7
pluggy==1.0.0
psycopg2==2.9.3
psycopg2-binary==2.9.3
psycopg2-binary==2.9.9
pytest==7.1.3
pytest-cov==3.0.0
pytest-docker-compose==3.2.1
Expand All @@ -30,8 +29,10 @@ Sphinx==5.1.1
SQLAlchemy==1.4.41
sqlalchemy-stubs==0.4
SQLAlchemy-Utils==0.38.3
pydantic==1.10.2
Werkzeug==2.2.3
pydantic==2.3.0
Werkzeug==3.0.1
greenlet==3.0.1
pyyaml!=6.0.0,!=5.4.0,!=5.4.1
pydantic_settings==2.1.0
Authlib==1.0.1
python-jose==3.1.0
2 changes: 1 addition & 1 deletion src/cnaas_nms/api/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_settings_model(testclient: FlaskClient):
result = testclient.get("/api/v1.0/settings/model")
assert result.status_code == 200
assert result.content_type == "application/json"
assert "definitions" in result.json
assert "$defs" in result.json


def test_settings_server(testclient: FlaskClient):
Expand Down
5 changes: 3 additions & 2 deletions src/cnaas_nms/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from typing import Optional

import yaml
from pydantic import BaseSettings, PostgresDsn, validator
from pydantic import PostgresDsn, validator
from pydantic_settings import BaseSettings


class AppSettings(BaseSettings):
Expand All @@ -14,7 +15,7 @@ class AppSettings(BaseSettings):
CNAAS_DB_PORT: int = 5432
REDIS_HOSTNAME: str = "127.0.0.1"
REDIS_PORT: int = 6379
POSTGRES_DSN: PostgresDsn = (
POSTGRES_DSN: str = (
f"postgresql://{CNAAS_DB_USERNAME}:{CNAAS_DB_PASSWORD}@{CNAAS_DB_HOSTNAME}:{CNAAS_DB_PORT}/{CNAAS_DB_DATABASE}"
)
USERNAME_INIT: str = "admin"
Expand Down
56 changes: 29 additions & 27 deletions src/cnaas_nms/db/settings_fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ipaddress import AddressValueError, IPv4Interface
from typing import Dict, List, Optional
from typing import Annotated, Dict, List, Optional

from pydantic import BaseModel, Field, conint, validator

Expand All @@ -22,22 +22,24 @@
HOST_REGEX = f"^({IPV4_REGEX}|{IPV6_REGEX}|{FQDN_REGEX})$"
HOSTNAME_REGEX = r"^([a-zA-Z0-9-]{1,63})(\.[a-z0-9-]{1,63})*$"
DOMAIN_NAME_REGEX = r"^([a-zA-Z0-9-]{1,63})(\.[a-z0-9-]{1,63})+$"
host_schema = Field(..., regex=HOST_REGEX, max_length=253, description="Hostname, FQDN or IP address")
hostname_schema = Field(..., regex=HOSTNAME_REGEX, max_length=253, description="Hostname or FQDN")
domain_name_schema = Field(None, regex=DOMAIN_NAME_REGEX, max_length=251, description="DNS domain name")
ipv4_schema = Field(..., regex=f"^{IPV4_REGEX}$", description="IPv4 address")
host_schema = Field(..., pattern=HOST_REGEX, max_length=253, description="Hostname, FQDN or IP address")
hostname_schema = Field(..., pattern=HOSTNAME_REGEX, max_length=253, description="Hostname or FQDN")
domain_name_schema = Field(None, pattern=DOMAIN_NAME_REGEX, max_length=251, description="DNS domain name")
ipv4_schema = Field(..., pattern=f"^{IPV4_REGEX}$", description="IPv4 address")
IPV4_IF_REGEX = f"{IPV4_REGEX}" + r"\/[0-9]{1,2}"
ipv4_if_schema = Field(None, regex=f"^{IPV4_IF_REGEX}$", description="IPv4 address in CIDR/prefix notation (0.0.0.0/0)")
ipv6_schema = Field(..., regex=f"^{IPV6_REGEX}$", description="IPv6 address")
ipv4_if_schema = Field(
None, pattern=f"^{IPV4_IF_REGEX}$", description="IPv4 address in CIDR/prefix notation (0.0.0.0/0)"
)
ipv6_schema = Field(..., pattern=f"^{IPV6_REGEX}$", description="IPv6 address")
IPV6_IF_REGEX = f"{IPV6_REGEX}" + r"\/[0-9]{1,3}"
ipv6_if_schema = Field(None, regex=f"^{IPV6_IF_REGEX}$", description="IPv6 address in CIDR/prefix notation (::/0)")
ipv4_or_ipv6_if_schema = Field(None, regex=f"({IPV4_IF_REGEX}|{IPV6_IF_REGEX})", description="IPv4 or IPv6 prefix")
ipv6_if_schema = Field(None, pattern=f"^{IPV6_IF_REGEX}$", description="IPv6 address in CIDR/prefix notation (::/0)")
ipv4_or_ipv6_if_schema = Field(None, pattern=f"({IPV4_IF_REGEX}|{IPV6_IF_REGEX})", description="IPv4 or IPv6 prefix")

# VLAN name is alphanumeric max 32 chars on Cisco
# should not start with number according to some Juniper doc
VLAN_NAME_REGEX = r"^[a-zA-Z][a-zA-Z0-9-_]{0,31}$"
vlan_name_schema = Field(
None, regex=VLAN_NAME_REGEX, description="Max 32 alphanumeric chars, " + "beginning with a non-numeric character"
None, pattern=VLAN_NAME_REGEX, description="Max 32 alphanumeric chars, " + "beginning with a non-numeric character"
)
vlan_id_schema = Field(..., gt=0, lt=4096, description="Numeric 802.1Q VLAN ID, 1-4095")
vlan_id_schema_optional = Field(None, gt=0, lt=4096, description="Numeric 802.1Q VLAN ID, 1-4095")
Expand All @@ -47,24 +49,24 @@
as_num_schema = Field(None, description="BGP Autonomous System number, 1-4294967295 (asdot notation not supported)")
as_num_type = conint(strict=True, gt=0, lt=4294967296)
IFNAME_REGEX = r"([a-zA-Z0-9\/\.:-])+"
ifname_schema = Field(None, regex=f"^{IFNAME_REGEX}$", description="Interface name")
ifname_schema = Field(None, pattern=f"^{IFNAME_REGEX}$", description="Interface name")
IFNAME_RANGE_REGEX = r"([a-zA-Z0-9\/\.:\-\[\]])+"
ifname_range_schema = Field(
None, regex=f"^{IFNAME_RANGE_REGEX}$", description="Interface range pattern or interface name"
None, pattern=f"^{IFNAME_RANGE_REGEX}$", description="Interface range pattern or interface name"
)
IFCLASS_REGEX = r"(custom|downlink|fabric|port_template_[a-zA-Z0-9_]+)"
ifclass_schema = Field(None, regex=f"^{IFCLASS_REGEX}$", description="Interface class: custom, downlink or uplink")
ifclass_schema = Field(None, pattern=f"^{IFCLASS_REGEX}$", description="Interface class: custom, downlink or uplink")
ifdescr_schema = Field(None, max_length=64, description="Interface description, 0-64 characters")
tcpudp_port_schema = Field(None, ge=0, lt=65536, description="TCP or UDP port number, 0-65535")
ebgp_multihop_schema = Field(None, ge=1, le=255, description="Numeric IP TTL, 1-255")
maximum_routes_schema = Field(None, ge=0, le=4294967294, description="Maximum number of routes to receive from peer")
accept_or_reject_schema = Field(..., regex=r"^(accept|reject)$", description="Value has to be 'accept' or 'reject'")
accept_or_reject_schema = Field(..., pattern=r"^(accept|reject)$", description="Value has to be 'accept' or 'reject'")
prefix_size_or_range_schema = Field(
None, regex=r"^[0-9]{1,3}([-][0-9]{1,3})?$", description="Prefix size or range 0-128"
None, pattern=r"^[0-9]{1,3}([-][0-9]{1,3})?$", description="Prefix size or range 0-128"
)

GROUP_NAME = r"^([a-zA-Z0-9_-]{1,63}\.?)+$"
group_name = Field(..., regex=GROUP_NAME, max_length=253)
group_name = Field(..., pattern=GROUP_NAME, max_length=253)
group_priority_schema = Field(
0, ge=0, le=100, description="Group priority 0-100, default 0, higher value means higher priority"
)
Expand Down Expand Up @@ -270,15 +272,15 @@ def vlan_id_high_greater_than_low(cls, v, values, **kwargs):


class f_vxlan(BaseModel):
description: str = None
description: Optional[str] = None
vni: int = vxlan_vni_schema
vrf: Optional[str] = vlan_name_schema
vlan_id: int = vlan_id_schema
vlan_name: str = vlan_name_schema
ipv4_gw: Optional[str] = None
ipv4_secondaries: Optional[List[str]]
ipv4_secondaries: Optional[List[str]] = None
ipv6_gw: Optional[str] = ipv6_if_schema
dhcp_relays: Optional[List[f_dhcp_relay]]
dhcp_relays: Optional[List[f_dhcp_relay]] = None
mtu: Optional[int] = mtu_schema
vxlan_host_route: bool = True
acl_ipv4_in: Optional[str] = None
Expand Down Expand Up @@ -333,7 +335,7 @@ class f_user(BaseModel):

class f_prefixset_item(BaseModel):
prefix: str = ipv4_or_ipv6_if_schema
masklength_range: Optional[str] = prefix_size_or_range_schema
masklength_range: Optional[Annotated[int, Field(ge=0, le=128)] | Annotated[str, prefix_size_or_range_schema]] = None


class f_prefixset(BaseModel):
Expand Down Expand Up @@ -362,16 +364,16 @@ class f_root(BaseModel):
snmp_servers: List[f_snmp_server] = []
dns_servers: List[f_dns_server] = []
flow_collectors: List[f_flow_collector] = []
dhcp_relays: Optional[List[f_dhcp_relay]]
dhcp_relays: Optional[List[f_dhcp_relay]] = None
interfaces: List[f_interface] = []
vrfs: List[f_vrf] = []
vxlans: Dict[str, f_vxlan] = {}
underlay: f_underlay = None
evpn_peers: List[f_evpn_peer] = []
extroute_static: Optional[f_extroute_static]
extroute_ospfv3: Optional[f_extroute_ospfv3]
extroute_bgp: Optional[f_extroute_bgp]
internal_vlans: Optional[f_internal_vlans]
extroute_static: Optional[f_extroute_static] = None
extroute_ospfv3: Optional[f_extroute_ospfv3] = None
extroute_bgp: Optional[f_extroute_bgp] = None
internal_vlans: Optional[f_internal_vlans] = None
dot1x_fail_vlan: Optional[int] = vlan_id_schema_optional
cli_prepend_str: str = ""
cli_append_str: str = ""
Expand All @@ -397,8 +399,8 @@ def reserved_priority(cls, v, values, **kwargs):


class f_group(BaseModel):
group: Optional[f_group_item]
group: Optional[f_group_item] = None


class f_groups(BaseModel):
groups: Optional[List[f_group]]
groups: Optional[List[f_group]] = None
Loading