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

Upgrade to connexion 3 #1058

Closed
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
9 changes: 4 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip codecov flake8
Expand All @@ -37,4 +37,3 @@ jobs:
- name: Run tests
run: |
docker-compose -f docker-compose.test.yml up --build --exit-code-from test

6 changes: 3 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pur = ">=5.4.1"
pytest = ">=5.0.1"
pylint = ">=2.3.1"
pytest-cov = ">=2.7.1"
pytest-flask = ">=1.1.0"
testing-postgresql = ">=1.3.0"

[packages]
Expand All @@ -19,8 +18,7 @@ app-common-python = ">=0.2.5"
boto3 = ">=1.16.13"
botocore = ">=1.19.13"
click = ">=0.7"
connexion = {extras = ["swagger-ui"],version = "==2.14.1"}
flask = "==2.2.5"
connexion = {extras = ["swagger-ui", "uvicorn", "flask"], version = "3.0.5"}
gitpython = ">=3.1.30"
iso8601 = ">=0.1.12"
jsonschema = ">=3.2.0"
Expand All @@ -37,6 +35,8 @@ tornado = ">=6.0.3"
watchtower = ">=1.0.0"
werkzeug = ">=1.0.1"
yarl = ">=1.6.2"
a2wsgi = "*"
ipdb = "*"

[requires]
python_version = "3.9"
1,646 changes: 1,026 additions & 620 deletions Pipfile.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions conf/test.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
POSTGRESQL_USER=vmaas_admin
POSTGRESQL_PASSWORD=vmaas_admin_pwd
POSTGRESQL_DATABASE=vmaas
POSTGRESQL_HOST=vmaas_database
POSTGRESQL_PORT=5432
export POSTGRESQL_USER=vmaas_admin
export POSTGRESQL_PASSWORD=vmaas_admin_pwd
export POSTGRESQL_DATABASE=vmaas
export POSTGRESQL_HOST=vmaas_database
export POSTGRESQL_PORT=5432

IS_TEST=TRUE
export IS_TEST=TRUE

REPO_NAME_PREFIXES=rhul-,rhl-
PROMETHEUS_MULTIPROC_DIR=/tmp/prometheus_multiproc_dir
export REPO_NAME_PREFIXES=rhul-,rhl-
export PROMETHEUS_MULTIPROC_DIR=/tmp/prometheus_multiproc_dir
19 changes: 12 additions & 7 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ services:
user: root
security_opt:
- label=disable
# command: >
# bash -c 'cd /vmaas && python3 -m vmaas.common.wait_for_services python3 -m vmaas.reposcan.database.upgrade \
# && ./run_tests.sh vmaas/reposcan'
# command: >
# bash -c 'cd /vmaas && ./scripts/check_deps_versions.sh \
# && ./scripts/validate_dashboards.py ./monitoring/grafana/dashboards/ \
# && python3 -m vmaas.common.wait_for_services python3 -m vmaas.reposcan.database.upgrade \
# && ./run_tests.sh vmaas/common \
# && ./run_tests.sh vmaas/reposcan \
# && ./run_tests.sh vmaas/webapp \
# && bash <(curl -s https://codecov.io/bash)'
command: >
bash -c 'cd /vmaas && ./scripts/check_deps_versions.sh \
&& ./scripts/validate_dashboards.py ./monitoring/grafana/dashboards/ \
&& python3 -m vmaas.common.wait_for_services python3 -m vmaas.reposcan.database.upgrade \
&& ./run_tests.sh vmaas/common \
&& ./run_tests.sh vmaas/reposcan \
&& ./run_tests.sh vmaas/webapp \
&& bash <(curl -s https://codecov.io/bash)'
bash -c 'cd /vmaas && tail -f /dev/null'
126 changes: 63 additions & 63 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,72 +52,72 @@ services:
depends_on:
- vmaas_database

vmaas_webapp:
command: /vmaas/entrypoint.sh webapp
container_name: vmaas-webapp
hostname: vmaas-webapp
image: vmaas/app:latest
restart: unless-stopped
env_file:
- ./conf/common.env
- ./conf/webapp.env
ports:
- 8080:8000
- 9081:10000
depends_on:
- vmaas_reposcan
# vmaas_webapp:
# command: /vmaas/entrypoint.sh webapp
# container_name: vmaas-webapp
# hostname: vmaas-webapp
# image: vmaas/app:latest
# restart: unless-stopped
# env_file:
# - ./conf/common.env
# - ./conf/webapp.env
# ports:
# - 8080:8000
# - 9081:10000
# depends_on:
# - vmaas_reposcan

vmaas_webapp_go:
command: /vmaas/entrypoint.sh webapp-go
container_name: vmaas-webapp-go
hostname: vmaas-webapp-go
image: vmaas/app:latest
restart: unless-stopped
env_file:
- ./conf/common.env
- ./conf/webapp_go.env
ports:
- 8000:8000
- 9088:10000
depends_on:
- vmaas_reposcan
- vmaas_webapp # to proxy requests
# vmaas_webapp_go:
# command: /vmaas/entrypoint.sh webapp-go
# container_name: vmaas-webapp-go
# hostname: vmaas-webapp-go
# image: vmaas/app:latest
# restart: unless-stopped
# env_file:
# - ./conf/common.env
# - ./conf/webapp_go.env
# ports:
# - 8000:8000
# - 9088:10000
# depends_on:
# - vmaas_reposcan
# - vmaas_webapp # to proxy requests

vmaas_prometheus:
container_name: vmaas-prometheus
image: prom/prometheus:v2.21.0
volumes:
- prometheus-data:/prometheus
- ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
security_opt:
- label=disable
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
ports:
- 9090:9090
depends_on:
- vmaas_reposcan
- vmaas_webapp
restart: unless-stopped
profiles:
- monitoring
# vmaas_prometheus:
# container_name: vmaas-prometheus
# image: prom/prometheus:v2.21.0
# volumes:
# - prometheus-data:/prometheus
# - ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
# security_opt:
# - label=disable
# command:
# - '--config.file=/etc/prometheus/prometheus.yml'
# - '--storage.tsdb.path=/prometheus'
# - '--web.console.libraries=/usr/share/prometheus/console_libraries'
# - '--web.console.templates=/usr/share/prometheus/consoles'
# ports:
# - 9090:9090
# depends_on:
# - vmaas_reposcan
# - vmaas_webapp
# restart: unless-stopped
# profiles:
# - monitoring

vmaas_grafana:
container_name: vmaas-grafana
build:
context: ./
dockerfile: ./monitoring/grafana/Dockerfile
image: vmaas-grafana:latest
depends_on:
- vmaas_prometheus
ports:
- 3000:3000
restart: unless-stopped
profiles:
- monitoring
# vmaas_grafana:
# container_name: vmaas-grafana
# build:
# context: ./
# dockerfile: ./monitoring/grafana/Dockerfile
# image: vmaas-grafana:latest
# depends_on:
# - vmaas_prometheus
# ports:
# - 3000:3000
# restart: unless-stopped
# profiles:
# - monitoring

volumes:
vmaas-db-data:
Expand Down
12 changes: 12 additions & 0 deletions vmaas/reposcan/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ def write_testing_data(conn):
with conn.cursor() as cursor:
cursor.execute(VMAAS_DB_DATA.read_text(encoding="utf-8"))
conn.commit()


@pytest.fixture
def client(app):
with app.test_client() as client:
yield client


@pytest.fixture
def client_class(request, client):
if request.cls is not None:
request.cls.client = client
1 change: 1 addition & 0 deletions vmaas/reposcan/dump.output
15 changes: 8 additions & 7 deletions vmaas/reposcan/reposcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import connexion
import git
from a2wsgi import ASGIMiddleware
from connexion.options import SwaggerUIOptions
from flask import request
from prometheus_client import generate_latest
from tornado.ioloop import IOLoop, PeriodicCallback
Expand Down Expand Up @@ -840,17 +842,18 @@ class SyncTask:
_running_task_type = None
_pid = None
workers = Pool(1)
ioloop = IOLoop.current()

@classmethod
def start(cls, task_type, func, callback, *args, **kwargs):
"""Start specified function with given parameters in separate worker."""
cls._running = True
cls._running_task_type = task_type
cls._pid = cls.workers._pool[0].pid # pylint: disable=protected-access
ioloop = IOLoop.instance()
cls.ioloop = IOLoop.current()

def _callback(result):
ioloop.add_callback(lambda: callback(result))
cls.ioloop.add_callback(lambda: callback(result))

def _err_callback(err):
LOGGER.error("SyncTask error: %s", err)
Expand Down Expand Up @@ -926,10 +929,8 @@ def terminate(*_):
for sig in KILL_SIGNALS:
signal.signal(sig, terminate)

app = connexion.App(__name__, options={
'swagger_ui': True,
'openapi_spec_path': '/openapi.json'
})
app = connexion.App(__name__,
swagger_ui_options=SwaggerUIOptions(swagger_ui=True))

# Response validation is disabled due to returing streamed response in GET /pkgtree
# https://github.com/zalando/connexion/pull/467 should fix it
Expand All @@ -953,4 +954,4 @@ def set_headers(response): # pylint: disable=unused-variable
response.headers["Access-Control-Allow-Headers"] = "Content-Type"
return response

return app
return ASGIMiddleware(app, loop=SyncTask.ioloop) # As of connexion >3.0 ASGI server should be used as default, otherwise wrapped by such middleware.
22 changes: 12 additions & 10 deletions vmaas/reposcan/test/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from http import HTTPStatus
import pytest
from vmaas.reposcan import reposcan
# from tornado.wsgi import WSGIContainer

URL_BASE = ""

Expand Down Expand Up @@ -51,21 +52,22 @@ def fetch(self, path, **kwargs):
if 'data' in kwargs or 'json' in kwargs:
headers.update({'Content-type': 'application/json'})
method = kwargs.get('method', 'get')
self.client.headers = headers
if method.upper() == 'PATCH':
response = self.client.patch(path, **kwargs) # pylint: disable=no-member
response = self.client.patch(path, content=kwargs.get("data")) # pylint: disable=no-member
elif method.upper() == 'POST':
response = self.client.post(path, **kwargs) # pylint: disable=no-member
response = self.client.post(path, content=kwargs.get("data")) # pylint: disable=no-member
elif method.upper() == 'PUT':
response = self.client.put(path, **kwargs) # pylint: disable=no-member
response = self.client.put(path, content=kwargs.get("data")) # pylint: disable=no-member
elif method.upper() == 'DELETE':
response = self.client.delete(path, **kwargs) # pylint: disable=no-member
response = self.client.delete(path) # pylint: disable=no-member
else:
response = self.client.get(path, **kwargs) # pylint: disable=no-member
response = self.client.get(path) # pylint: disable=no-member
return FlaskTestResponse(response, method.upper(), path)

def raw_get(self, path, **kwargs):
def raw_get(self, path):
"""Raw get to an URI without headers"""
response = self.client.get(path, **kwargs) # pylint: disable=no-member
response = self.client.get(path) # pylint: disable=no-member
return FlaskTestResponse(response, "GET", path)

# pylint: disable=invalid-name
Expand Down Expand Up @@ -97,13 +99,13 @@ def load(response):
"""Loads the response content."""
parsed = None
try:
parsed = json.loads(response.data)
parsed = response.json()
# pylint: disable=broad-except
except Exception:
pass

if not parsed and response.data:
parsed = str(response.data, "utf-8")
if not parsed and response.content:
parsed = str(response.content, "utf-8")

return parsed

Expand Down
5 changes: 2 additions & 3 deletions vmaas/reposcan/test/test_reposcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ def test_add_repo_1_with_certs(self):
"key": "$RHSM-CDN-KEY"
}
}]"""

# import ipdb; ipdb.set_trace()
resp = self.fetch('/api/v1/repos', method='POST', data=body)
self.assertEqual(HTTPStatus.OK, resp.status)
self.assertEqual({"msg": "Import repositories task started.", "success": True}, resp.body)
self.assertTrue(resp.status in [HTTPStatus.OK, HTTPStatus.TOO_MANY_REQUESTS])
resp = self.fetch('/api/v1/task/cancel', method='PUT', data=body)

def test_add_repo_2(self):
Expand Down
Loading
Loading