Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 17 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,27 @@ description = "TDP library for TDP Manager"
authors = [{ name = "TOSIT" }]
license = "Apache-2.0"
readme = "README.md"
requires-python = ">=3.9.0,!=3.9.7,<4.0"
requires-python = "==3.12.*"
dependencies = [
"ansible-core==2.15.13",
"networkx==2.5.1",
"ansible-core==2.16.15",
"networkx==3.6.1",
"PyYAML==6.0.3",
"GitPython==3.1.46",
"SQLAlchemy==2.0.45",
"click==8.0.4",
"tabulate==0.8.10",
"python-dotenv==0.20.0",
"jsonschema==4.10.3",
"pydantic==2.6.4",
"alembic==1.13.3",
"alembic-postgresql-enum==1.2.0",
"exceptiongroup==1.3.1",
"SQLAlchemy==2.0.46",
"click==8.3.1",
"tabulate==0.9.0", # Python 3.12 suported by 0.10.0 but not released yet (Not maintained)
"python-dotenv==1.2.0",
"jsonschema==4.26.0",
"pydantic==2.12.5",
"alembic==1.18.1",
]

[project.optional-dependencies]
visualization = [
"matplotlib==3.3.4",
"pydot==1.4.2",
# numpy is not a direct dependency of tdp-lib
# we need to fix its version because networkx < 3.3 is not compatible with numpy 2.0
# numpy is an optional dependency of networkx but is installed by matplotlib
"numpy<2.0.0",
"matplotlib==3.10.8",
"pydot==4.0.1",
]
postgresql = ["psycopg2-binary==2.9.11"]
postgresql = ["psycopg2-binary==2.9.11", "alembic-postgresql-enum==1.8.0"]
mysql = ["pymysql==1.1.2"]

[project.scripts]
Expand All @@ -44,10 +38,10 @@ Documentation = "https://github.com/TOSIT-IO/tdp-lib"

[dependency-groups]
dev = [
"pytest>=7.4.0,<8",
"ruff>=0.11.12,<1",
"pytest-xdist>=3.5.0,<4",
"python-lorem>=1.3.0.post1,<2",
"pytest>=9.0.2,<10",
"ruff>=0.14.14,<1",
"pytest-xdist>=3.8.0,<4",
"python-lorem>=1.3.0.post3,<2", # Not maintained
]

[build-system]
Expand Down
8 changes: 4 additions & 4 deletions tdp/core/deployment/deployment_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from collections import OrderedDict
from collections.abc import Callable, Iterator
from datetime import datetime
from datetime import datetime, timezone
from functools import partial
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -127,13 +127,13 @@ def __next__(
return operation_rec, partial(self._process_operation_fn, operation_rec)
# StopIteration is a "normal" exception raised when the iteration has stopped
except StopIteration as e:
self.deployment.end_time = datetime.utcnow()
self.deployment.end_time = datetime.now(timezone.utc)
if not self.deployment.state == DeploymentStateEnum.FAILURE:
self.deployment.state = DeploymentStateEnum.SUCCESS
raise e
# An unforeseen error has occured, stop the deployment and set as failure
except Exception as e:
self.deployment.end_time = datetime.utcnow()
self.deployment.end_time = datetime.now(timezone.utc)
self.deployment.state = DeploymentStateEnum.FAILURE
raise e

Expand All @@ -151,7 +151,7 @@ def _process_operation_fn(

# Set deployment status to failure if the operation failed
if operation_rec.state != OperationStateEnum.SUCCESS:
self.deployment.end_time = datetime.utcnow()
self.deployment.end_time = datetime.now(timezone.utc)
self.deployment.state = DeploymentStateEnum.FAILURE
# Return early as status is not updated
return
Expand Down
8 changes: 4 additions & 4 deletions tdp/core/deployment/deployment_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import logging
from datetime import datetime
from datetime import datetime, timezone
from typing import TYPE_CHECKING

from tdp.core.deployment.deployment_iterator import DeploymentIterator
Expand Down Expand Up @@ -50,7 +50,7 @@ def _run_operation(self, operation_rec: OperationModel) -> None:
Args:
operation_rec: Operation record to run, modified in place with the result.
"""
operation_rec.start_time = datetime.utcnow()
operation_rec.start_time = datetime.now(timezone.utc)

operation: Operation = self._collections.operations[operation_rec.operation]

Expand All @@ -62,7 +62,7 @@ def _run_operation(self, operation_rec: OperationModel) -> None:
logger.error(logs)
operation_rec.state = OperationStateEnum.FAILURE
operation_rec.logs = logs.encode("utf-8")
operation_rec.end_time = datetime.utcnow()
operation_rec.end_time = datetime.now(timezone.utc)
return

# Execute the operation
Expand All @@ -72,7 +72,7 @@ def _run_operation(self, operation_rec: OperationModel) -> None:
host=operation_rec.host,
extra_vars=operation_rec.extra_vars,
)
operation_rec.end_time = datetime.utcnow()
operation_rec.end_time = datetime.now(timezone.utc)

# ? This case shouldn't happen as the executor should return a valid state
if state not in OperationStateEnum:
Expand Down
5 changes: 2 additions & 3 deletions tdp/core/models/deployment_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

import logging
from collections.abc import Iterable
from datetime import datetime
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Literal, NamedTuple, Optional

from exceptiongroup import ExceptionGroup
from sqlalchemy import JSON
from sqlalchemy.orm import Mapped, mapped_column, relationship
from tabulate import tabulate
Expand Down Expand Up @@ -545,7 +544,7 @@ def start_running(self) -> None:
self.state = DeploymentStateEnum.RUNNING
for operation in self.operations:
operation.state = OperationStateEnum.PENDING
self.start_time = datetime.utcnow()
self.start_time = datetime.now(timezone.utc)

def fix_running(self):
# Only RUNNING deployment can be fixed
Expand Down
4 changes: 2 additions & 2 deletions tdp/core/models/sch_status_log_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 TOSIT.IO
# SPDX-License-Identifier: Apache-2.0

from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Optional

from sqlalchemy import ForeignKey, String
Expand All @@ -27,7 +27,7 @@ class SCHStatusLogModel(BaseModel):
doc="Unique id of the cluster status log.", primary_key=True
)
event_time: Mapped[datetime] = mapped_column(
default=datetime.utcnow,
default=datetime.now(timezone.utc),
doc="Timestamp of the component version log.",
)
service: Mapped[str] = mapped_column(
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/core/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

import pytest
from sqlalchemy.engine import Engine
Expand All @@ -25,8 +25,8 @@ def test_create_deployment(db_engine: Engine):
"hosts": ["host1", "host2"],
"restart": False,
},
start_time=datetime.utcnow(),
end_time=datetime.utcnow() + timedelta(0, 1),
start_time=datetime.now(timezone.utc),
end_time=datetime.now(timezone.utc) + timedelta(0, 1),
state="SUCCESS",
deployment_type="Dag",
)
Expand All @@ -42,8 +42,8 @@ def test_create_deployment(db_engine: Engine):
deployment_id=deployment.id,
operation="start_target1",
host="host1",
start_time=datetime.utcnow(),
end_time=datetime.utcnow() + timedelta(0, 1),
start_time=datetime.now(timezone.utc),
end_time=datetime.now(timezone.utc) + timedelta(0, 1),
state="Success",
logs=b"operation log",
)
Expand Down
Loading