Skip to content

Commit

Permalink
Merge pull request #129 from ricolin/add-staffeln-UT-CI
Browse files Browse the repository at this point in the history
Add staffeln ut ci

relate to #110

Reviewed-by: Mohammed Naser <[email protected]>
Reviewed-by: Rico Lin <[email protected]>
  • Loading branch information
atmosphere-ci[bot] authored Dec 11, 2024
2 parents 6a68711 + 0a1c2d0 commit 98f19e1
Show file tree
Hide file tree
Showing 63 changed files with 888 additions and 215 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
16 changes: 0 additions & 16 deletions .github/workflows/linters.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ releasenotes/build
*.log

# envvar openrc file
*openrc.sh
*openrc.sh
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.0.0
hooks:
- id: conventional-pre-commit
stages:
- commit-msg

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: trailing-whitespace
3 changes: 2 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import os
import sys
Expand Down Expand Up @@ -39,7 +40,7 @@
# openstackdocstheme options
openstackdocs_repo_name = "openstack/staffeln"
openstackdocs_bug_project = (
"replace with the name of the project on Launchpad or the ID from Storyboard"
"replace with the name of the project on " "Launchpad or the ID from Storyboard"
)
openstackdocs_bug_tag = ""

Expand Down
2 changes: 1 addition & 1 deletion hack/stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SWIFT_HASH=66a3d6b56c1f479c8b4e70ab5c2000f5
SWIFT_REPLICAS=1
enable_plugin neutron https://opendev.org/openstack/neutron
#swift
enable_service s-proxy s-object s-container s-account
enable_service s-proxy s-object s-container s-account
# Cinder
enable_service c-bak
[[post-config|/etc/neutron/neutron.conf]]
Expand Down
7 changes: 2 additions & 5 deletions releasenotes/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is execfile()d with the current directory set to its
# containing dir.
#
Expand All @@ -20,20 +19,18 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
from __future__ import annotations

extensions = [
"openstackdocstheme",
"reno.sphinxext",
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ parse
tooz # Apache-2.0
sherlock>=0.4.1 # MIT
kubernetes # Apache-2.0
# email
# smtplib
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ classifier =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: Implementation :: CPython

Expand All @@ -35,4 +37,4 @@ console_scripts =
wsgi_scripts =
staffeln-api-wsgi = staffeln.api:app
staffeln.database.migration_backend =
sqlalchemy = staffeln.db.sqlalchemy.migration
sqlalchemy = staffeln.db.sqlalchemy.migration
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
from __future__ import annotations

import setuptools

setuptools.setup(setup_requires=["pbr"], pbr=True)
2 changes: 1 addition & 1 deletion staffeln/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
Expand All @@ -11,6 +10,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import pbr.version

Expand Down
7 changes: 5 additions & 2 deletions staffeln/api/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

from flask import Flask, Response, request
from oslo_log import log

from staffeln import objects
from staffeln.common import context

Expand All @@ -22,8 +25,8 @@ def backup_id():
backup = objects.Volume.get_backup_by_backup_id( # pylint: disable=E1120
context=ctx, backup_id=request.args["backup_id"]
)
# backup_info is None when there is no entry of the backup id in backup_table.
# So the backup should not be the automated backup.
# backup_info is None when there is no entry of the backup id in
# backup_table. So the backup should not be the automated backup.
if backup is None:
return Response(
"True",
Expand Down
2 changes: 2 additions & 0 deletions staffeln/api/middleware/parsable_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
Based on pecan.middleware.errordocument
"""
from __future__ import annotations

from oslo_serialization import jsonutils

from staffeln.i18n import _


Expand Down
2 changes: 2 additions & 0 deletions staffeln/api/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import app

if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion staffeln/cmd/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Starter script for Staffeln API service"""

from __future__ import annotations

import os
import sys

import staffeln.conf
from oslo_log import log as logging

import staffeln.conf
from staffeln.api import app as api_app
from staffeln.common import service
from staffeln.i18n import _
Expand Down
15 changes: 12 additions & 3 deletions staffeln/cmd/conductor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Starter script for the staffeln conductor service."""

from __future__ import annotations

import cotyledon
import staffeln.conf
from cotyledon import oslo_config_glue

import staffeln.conf
from staffeln.common import service
from staffeln.conductor import manager

Expand All @@ -13,9 +16,15 @@ def main():
service.prepare_service()

sm = cotyledon.ServiceManager()
sm.add(manager.BackupManager, workers=CONF.conductor.backup_workers, args=(CONF,))
sm.add(
manager.RotationManager, workers=CONF.conductor.rotation_workers, args=(CONF,)
manager.BackupManager,
workers=CONF.conductor.backup_workers,
args=(CONF,),
)
sm.add(
manager.RotationManager,
workers=CONF.conductor.rotation_workers,
args=(CONF,),
)
oslo_config_glue.setup(sm, CONF)
sm.run()
8 changes: 7 additions & 1 deletion staffeln/cmd/dbmanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
Run storage database migration.
"""

from __future__ import annotations

import sys

from oslo_config import cfg

from staffeln import conf
from staffeln.common import service
from staffeln.db import migration
Expand Down Expand Up @@ -33,7 +36,10 @@ def add_command_parsers(subparsers):


command_opt = cfg.SubCommandOpt(
"command", title="Command", help="Available commands", handler=add_command_parsers
"command",
title="Command",
help="Available commands",
handler=add_command_parsers,
)


Expand Down
2 changes: 2 additions & 0 deletions staffeln/common/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import openstack


Expand Down
2 changes: 2 additions & 0 deletions staffeln/common/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# from staffeln.common import rpc
from __future__ import annotations

import staffeln.conf
from staffeln import version

Expand Down
2 changes: 2 additions & 0 deletions staffeln/common/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

BACKUP_INIT = 4
BACKUP_FAILED = 3
BACKUP_COMPLETED = 2
Expand Down
10 changes: 8 additions & 2 deletions staffeln/common/context.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from __future__ import annotations

from oslo_context import context
from oslo_log import log

LOG = log.getLogger(__name__)


class RequestContext(context.RequestContext):
"""Added security context with request parameters from openstack common library"""
"""Added security context
Added security context with request
parameters from openstack common library
"""

def __init__(
self,
Expand All @@ -14,7 +20,7 @@ def __init__(
instance_id=None,
executed_at=None,
backup_status=None,
**kwargs
**kwargs,
):
self.backup_id = backup_id
self.volume_id = volume_id
Expand Down
12 changes: 9 additions & 3 deletions staffeln/common/email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
""" Email module with SMTP"""

from __future__ import annotations

import smtplib
from email import utils
from email.header import Header
Expand Down Expand Up @@ -32,18 +34,22 @@ def send(smtp_profile):

try:
smtp_obj = smtplib.SMTP(
smtp_profile["smtp_server_domain"], smtp_profile["smtp_server_port"]
smtp_profile["smtp_server_domain"],
smtp_profile["smtp_server_port"],
)
smtp_obj.connect(
smtp_profile["smtp_server_domain"], smtp_profile["smtp_server_port"]
smtp_profile["smtp_server_domain"],
smtp_profile["smtp_server_port"],
)
smtp_obj.ehlo()
smtp_obj.starttls()
smtp_obj.ehlo()
# SMTP Login
smtp_obj.login(smtp_profile["src_email"], smtp_profile["src_pwd"])
smtp_obj.sendmail(
smtp_profile["src_email"], smtp_profile["dest_email"], msg.as_string()
smtp_profile["src_email"],
smtp_profile["dest_email"],
msg.as_string(),
)
# Email Sent
except smtplib.SMTPException as error:
Expand Down
10 changes: 8 additions & 2 deletions staffeln/common/lock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import errno
import glob
import os
Expand All @@ -8,9 +10,10 @@

import sherlock
from oslo_log import log
from staffeln import conf, exception
from tooz import coordination

from staffeln import conf, exception

CONF = conf.CONF
LOG = log.getLogger(__name__)

Expand Down Expand Up @@ -146,7 +149,10 @@ class K8sCoordinator(object):
"""

def __init__(
self, expire: int = 3600, timeout: int = 10, namespace: str = "openstack"
self,
expire: int = 3600,
timeout: int = 10,
namespace: str = "openstack",
):
self.timeout = timeout
self.expire = expire
Expand Down
Loading

0 comments on commit 98f19e1

Please sign in to comment.