Skip to content

Commit

Permalink
Updade base image and use Python 3.12 by default (release-engineering…
Browse files Browse the repository at this point in the history
…#150)

* Updade base image and use Python 3.12 by default

* Fix using depracated pydantic functions

* Fix using depracated datetime.datetime.utcnow

* Drop invalid description in HTML

* Fix mod-wsgi for Python 3.12
  • Loading branch information
hluk committed Mar 11, 2024
1 parent 5d65e7a commit a0e1e8b
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 111 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/resultsdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -32,6 +32,7 @@ jobs:
command: >-
sudo apt-get update
&& sudo apt-get install
apache2-dev
libkrb5-dev
libldap2-dev
libsasl2-dev
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.fedoraproject.org/fedora:38 as builder
FROM registry.fedoraproject.org/fedora:39 as builder

# hadolint ignore=DL3033,DL4006,SC2039,SC3040
RUN set -exo pipefail \
Expand All @@ -14,10 +14,11 @@ RUN set -exo pipefail \
openldap-devel \
python3 \
python3-devel \
httpd-devel \
# install runtime dependencies
&& yum install -y \
--installroot=/mnt/rootfs \
--releasever=38 \
--releasever=/ \
--setopt install_weak_deps=false \
--nodocs \
--disablerepo=* \
Expand All @@ -26,7 +27,7 @@ RUN set -exo pipefail \
mod_ssl \
openldap \
python3 \
python3-mod_wsgi \
httpd-core \
&& yum --installroot=/mnt/rootfs clean all \
&& rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* \
# https://python-poetry.org/docs/master/#installing-with-the-official-installer
Expand Down Expand Up @@ -102,7 +103,7 @@ WORKDIR /app
USER 1001
EXPOSE 5001
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["mod_wsgi-express-3", "start-server", "/usr/share/resultsdb/resultsdb.wsgi", \
CMD ["mod_wsgi-express", "start-server", "/usr/share/resultsdb/resultsdb.wsgi", \
"--user", "apache", "--group", "apache", \
"--port", "5001", "--threads", "5", \
"--include-file", "/etc/httpd/conf.d/resultsdb.conf", \
Expand Down
164 changes: 87 additions & 77 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ opentelemetry-instrumentation-flask = "^0.44b0"
opentelemetry-instrumentation-sqlalchemy = "^0.44b0"
tenacity = "^8.2.3"

mod-wsgi = "^5.0.0"

[tool.poetry.extras]
test = [
"pytest",
Expand Down
6 changes: 3 additions & 3 deletions resultsdb/controllers/api_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create_result(body: ResultParamsBase):


def create_endpoint(params_class, oidc, provider):
params = params_class.construct()
params = params_class.model_construct()

@oidc.token_auth(provider)
@validate()
Expand All @@ -77,7 +77,7 @@ def create(body: RootModel[params_class]):
return create_result(body.root)

def get_schema():
return jsonify(params.construct().schema()), 200
return jsonify(params.model_construct().model_json_schema()), 200

artifact_type = params.artifact_type()
api.add_url_rule(
Expand Down Expand Up @@ -128,7 +128,7 @@ def index():
"method": "GET",
"description": PermissionsParams.__doc__,
"query_type": "Query",
"schema": PermissionsParams.construct().schema(),
"schema": PermissionsParams.model_construct().model_json_schema(),
}
)
return render_template(
Expand Down
7 changes: 6 additions & 1 deletion resultsdb/models/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def result_outcomes():
return PRESET_OUTCOMES + additional_result_outcomes


def utcnow_naive():
"""Returns current UTC date/time without the timezone info."""
return datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)


class GroupsToResults(db.Model):
__tablename__ = "groups_to_results"
id = db.Column(db.Integer, primary_key=True)
Expand Down Expand Up @@ -101,7 +106,7 @@ class Result(db.Model, DBSerialize):
id = db.Column(db.Integer, primary_key=True)
testcase_name = db.Column(db.Text, db.ForeignKey("testcase.name"))

submit_time = db.Column(db.DateTime, default=datetime.datetime.utcnow)
submit_time = db.Column(db.DateTime, default=utcnow_naive)
outcome = db.Column(db.String(32))
note = db.Column(db.Text)
ref_url = db.Column(db.Text)
Expand Down
8 changes: 5 additions & 3 deletions resultsdb/parsers/api_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pydantic import (
BaseModel,
ConfigDict,
EmailStr,
Field,
HttpUrl,
Expand Down Expand Up @@ -230,8 +231,7 @@ class ResultParamsBase(BaseModel):
default=None,
)

class Config:
str_max_length = MAX_STRING_SIZE
model_config = ConfigDict(str_max_length=MAX_STRING_SIZE)

def result_data(self) -> Iterator[int]:
"""Generator yielding property name and value pairs to store in DB."""
Expand All @@ -240,7 +240,9 @@ def result_data(self) -> Iterator[int]:
else:
yield ("type", self.artifact_type())

properties = self.dict(exclude_unset=True, exclude=self.exclude() | MAIN_RESULT_ATTRIBUTES)
properties = self.model_dump(
exclude_unset=True, exclude=self.exclude() | MAIN_RESULT_ATTRIBUTES
)
for name, value in properties.items():
if isinstance(value, list):
for subvalue in value:
Expand Down
1 change: 0 additions & 1 deletion resultsdb/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Web view on review-rot output.">

<link rel="icon" href="{{ url_for('favicon') }}" />

Expand Down
Empty file removed testing/__init__.py
Empty file.
19 changes: 10 additions & 9 deletions testing/functest_api_v20.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import resultsdb.messaging
from resultsdb.models import db
from resultsdb.models.results import utcnow_naive

try:
basestring
Expand All @@ -37,8 +38,8 @@

class AboutTime(object):
def __eq__(self, value):
start = (datetime.datetime.utcnow() - datetime.timedelta(seconds=10)).isoformat()
stop = (datetime.datetime.utcnow() + datetime.timedelta(seconds=10)).isoformat()
start = (utcnow_naive() - datetime.timedelta(seconds=10)).isoformat()
stop = (utcnow_naive() + datetime.timedelta(seconds=10)).isoformat()
return start <= value <= stop


Expand Down Expand Up @@ -873,30 +874,30 @@ def test_get_results_sorting_by_submit_time(self):

def test_get_results_by_since(self):
self.test_create_result()
before1 = (datetime.datetime.utcnow() - datetime.timedelta(seconds=100)).isoformat()
before2 = (datetime.datetime.utcnow() - datetime.timedelta(seconds=99)).isoformat()
after = (datetime.datetime.utcnow() + datetime.timedelta(seconds=100)).isoformat()
before1 = (utcnow_naive() - datetime.timedelta(seconds=100)).isoformat()
before2 = (utcnow_naive() - datetime.timedelta(seconds=99)).isoformat()
after = (utcnow_naive() + datetime.timedelta(seconds=100)).isoformat()

r = self.app.get("/api/v2.0/results?since=%s" % before1)
data = json.loads(r.data)
assert r.status_code == 200
assert r.status_code == 200, r.text
assert len(data["data"]) == 1
assert data["data"][0] == self.ref_result

r = self.app.get("/api/v2.0/results?since=%s,%s" % (before1, after))
data = json.loads(r.data)
assert r.status_code == 200
assert r.status_code == 200, r.text
assert len(data["data"]) == 1
assert data["data"][0] == self.ref_result

r = self.app.get("/api/v2.0/results?since=%s" % (after))
data = json.loads(r.data)
assert r.status_code == 200
assert r.status_code == 200, r.text
assert len(data["data"]) == 0

r = self.app.get("/api/v2.0/results?since=%s,%s" % (before1, before2))
data = json.loads(r.data)
assert r.status_code == 200
assert r.status_code == 200, r.text
assert len(data["data"]) == 0

def test_get_results_by_result_data(self):
Expand Down
8 changes: 0 additions & 8 deletions testing/functest_create_fedmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# Josef Skladanka <jskladan@redhat.com>

import json
import datetime
import copy

from flask import current_app as app
Expand All @@ -45,13 +44,6 @@ def __init__(self, id, testcase_name, outcome, item, item_type, arch):
]


class AboutTime(object):
def __eq__(self, value):
start = (datetime.datetime.utcnow() - datetime.timedelta(seconds=10)).isoformat()
stop = (datetime.datetime.utcnow() + datetime.timedelta(seconds=10)).isoformat()
return start <= value <= stop


class TestFuncCreateFedmsg:
def setup_method(self, method):
db.session.rollback()
Expand Down
4 changes: 2 additions & 2 deletions testing/test_api_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def test_api_v3_example(params_class, client):
Passing unexpected JSON type must propagate an error to the user.
"""
artifact_type = params_class.artifact_type()
example = params_class.example().dict()
example = params_class.example().model_dump()
r = client.post(f"/api/v3/results/{artifact_type}s", json=example)
assert r.status_code == 201, r.text

Expand All @@ -515,7 +515,7 @@ def test_api_v3_missing_param(params_class, client):
Passing unexpected JSON type must propagate an error to the user.
"""
artifact_type = params_class.artifact_type()
example = params_class.example().dict()
example = params_class.example().model_dump()
del example["outcome"]
r = client.post(f"/api/v3/results/{artifact_type}s", json=example)
assert r.status_code == 400, r.text
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ exclude = .git,.tox,.venv,dist,*egg,conf,resultsdb/alembic
max-line-length=99

[pytest]
skip_install = true
minversion=2.0
python_functions=test should
python_files=test_* functest_*
addopts=--functional -p no:warnings testing/ --cov resultsdb --cov-report=term-missing
addopts=--functional testing/ --cov resultsdb --cov-report=term-missing

[testenv:flake8]
skip_install = true
Expand Down

0 comments on commit a0e1e8b

Please sign in to comment.