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

Add the BATS executor #55

Merged
merged 2 commits into from
Sep 12, 2023
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
53 changes: 53 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: pytest
on:
pull_request:
branches:
- "**"
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
name: Check out repository
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Prepare SSH key
run: |
ssh-keygen -t ed25519 -f ~/.ssh/id_rsa -N ''
cat > ~/.ssh/config <<EOF
Host localhost
User runner
HostName 127.0.0.1
EOF
cat - ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
- name: Prepare binary executors
run: |
sudo apt-get install bats
- name: Prepare python env
run: |
python -m venv env
env/bin/python -m pip install -U pip
env/bin/python -m pip install -r requirements/celery.txt
- name: Run unit tests (pytest)
env:
CELERY_CONFIG_PATH: tests/tests_config.yaml
SSH_USERNAME: runner
SSH_PRIVATE_KEY: ~/.ssh/id_rsa
IGNORE_ENCRYPTED_KEYS: true
run: env/bin/python -m pytest -v --cov-report term-missing:skip-covered
--cov-report xml:/tmp/coverage.xml --junitxml=/tmp/pytest.xml
--cov=alts tests/ | tee /tmp/pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: /tmp/pytest-coverage.txt
pytest-xml-coverage-path: /tmp/coverage.xml
title: Coverage report for changed files
badge-title: Total coverage
hide-badge: false
hide-report: false
report-only-changed-files: true
hide-comment: false
remove-link-from-badge: false
junitxml-path: /tmp/pytest.xml
36 changes: 29 additions & 7 deletions alts/shared/constants.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@

__all__ = ['API_VERSION', 'ARCHITECTURES', 'COSTS', 'DRIVERS',
'DEFAULT_FILE_CHUNK_SIZE', 'DEBIAN_FLAVORS', 'RHEL_FLAVORS',
'SUPPORTED_ARCHITECTURES', 'SUPPORTED_DISTRIBUTIONS',
'DEFAULT_REQUEST_TIMEOUT', 'DEFAULT_UPLOADER_CONCURRENCY']
__all__ = [
'API_VERSION',
'ARCHITECTURES',
'COSTS',
'DRIVERS',
'DEFAULT_FILE_CHUNK_SIZE',
'DEBIAN_FLAVORS',
'RHEL_FLAVORS',
'SUPPORTED_ARCHITECTURES',
'SUPPORTED_DISTRIBUTIONS',
'DEFAULT_REQUEST_TIMEOUT',
'DEFAULT_UPLOADER_CONCURRENCY',
]


# YYYYMMDD format for API version
API_VERSION = '20210512'
COSTS = [str(i) for i in range(5)]
ARCHITECTURES = ('x86_64', 'aarch64', 'ppc64le', 's390x')
DRIVERS = ('docker', 'opennebula')
SUPPORTED_ARCHITECTURES = ['x86_64', 'i686', 'amd64', 'arm64', 'aarch64',
'ppc64le', 's390x']
SUPPORTED_ARCHITECTURES = [
'x86_64',
'i686',
'amd64',
'arm64',
'aarch64',
'ppc64le',
's390x',
]
SUPPORTED_DISTRIBUTIONS = ['almalinux', 'centos', 'ubuntu', 'debian']
RHEL_FLAVORS = ('rhel', 'fedora', 'centos', 'almalinux', 'cloudlinux')
DEBIAN_FLAVORS = ('debian', 'ubuntu', 'raspbian')
Expand All @@ -20,3 +35,10 @@
DEFAULT_FILE_CHUNK_SIZE = 8388608 # 8 megabytes in bytes
DEFAULT_REQUEST_TIMEOUT = 60 # 1 minute
DEFAULT_UPLOADER_CONCURRENCY = 4

DEFAULT_SSH_AUTH_METHODS = [
'gssapi-keyex',
'gssapi-with-mic',
'hostbased',
'publickey',
]
94 changes: 66 additions & 28 deletions alts/shared/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

from alts.shared import constants


__all__ = ['CeleryConfig', 'Repository', 'SchedulerConfig',
'TaskRequestResponse', 'TaskRequestPayload', 'TaskResultResponse']
__all__ = [
'CeleryConfig',
'Repository',
'SchedulerConfig',
'TaskRequestResponse',
'TaskRequestPayload',
'TaskResultResponse',
]


class Repository(BaseModel):
Expand All @@ -20,10 +25,25 @@ class AsyncSSHParams(BaseModel):
host: str
username: typing.Optional[str]
password: typing.Optional[str]
timeout: typing.Optional[int]
client_keys_files: typing.Optional[typing.List[str]] = None
known_hosts_files: typing.Optional[typing.List[str]] = None
env_vars: typing.Optional[typing.Dict[str, typing.Any]] = None
disable_known_hosts_check: bool = False
ignore_encrypted_keys: bool = False
preferred_auth: typing.Union[
str,
typing.List[str],
] = constants.DEFAULT_SSH_AUTH_METHODS


class CommandResult(BaseModel):
exit_code: int
stdout: str
stderr: str

def is_successful(self, expected_exit_code: int = 0) -> bool:
return self.exit_code == expected_exit_code


class TaskRequestPayload(BaseModel):
Expand Down Expand Up @@ -111,8 +131,10 @@ def broker_url(self) -> str:
else:
schema = 'amqp'
port = self.rabbitmq_port
return (f'{schema}://{self.rabbitmq_user}:{self.rabbitmq_password}@'
f'{self.rabbitmq_host}:{port}/{self.rabbitmq_vhost}')
return (
f'{schema}://{self.rabbitmq_user}:{self.rabbitmq_password}@'
f'{self.rabbitmq_host}:{port}/{self.rabbitmq_vhost}'
)


class RedisBrokerConfig(BaseBrokerConfig):
Expand All @@ -129,59 +151,67 @@ def broker_url(self) -> str:
f'redis://{self.redis_user}:{self.redis_password}@'
f'{self.redis_host}:{self.redis_port}/{self.redis_db_number}'
)
return (f'redis://{self.redis_host}:{self.redis_port}/'
f'{self.redis_db_number}')
return (
f'redis://{self.redis_host}:{self.redis_port}/'
f'{self.redis_db_number}'
)


class AzureResultsConfig(BaseResultsConfig):
azureblockblob_container_name: typing.Optional[str]
azureblockblob_container_name: str
azureblockblob_base_path: str = 'celery_result_backend/'
azure_connection_string: typing.Optional[str]
azure_connection_string: str


class FilesystemResultsConfig(BaseResultsConfig):
path: typing.Optional[str]
path: str


class RedisResultsConfig(BaseResultsConfig, RedisBrokerConfig):
pass


class S3ResultsConfig(BaseResultsConfig):
s3_access_key_id: typing.Optional[str]
s3_secret_access_key: typing.Optional[str]
s3_bucket: typing.Optional[str]
s3_access_key_id: str
s3_secret_access_key: str
s3_bucket: str
s3_base_path: str = 'celery_result_backend/'
s3_region: typing.Optional[str]
s3_endpoint_url: typing.Optional[str] = None
s3_region: str
s3_endpoint_url: str


class AzureLogsConfig(BaseLogsConfig, AzureResultsConfig):
azure_logs_container: typing.Optional[str]
azure_logs_container: str


class PulpLogsConfig(BaseLogsConfig):
pulp_host: typing.Optional[str]
pulp_user: typing.Optional[str]
pulp_password: typing.Optional[str]
pulp_host: str
pulp_user: str
pulp_password: str


class CeleryConfig(BaseModel):
def __init__(self, **data):
super().__init__(**data)
# Fill attributes from results config
for field_name, field in self.results_backend_config.__fields__.items():
if (field_name == 'broker_url' or
field_name.startswith(('s3_', 'azure'))):
for (
field_name,
field,
) in self.results_backend_config.__fields__.items():
if field_name == 'broker_url' or field_name.startswith(
('s3_', 'azure')
):
setattr(self, field_name, field)

# Whether to setup Celery SSL
use_ssl: bool = False
# Celery configuration variables
broker_config: typing.Union[RabbitmqBrokerConfig, RedisBrokerConfig]
results_backend_config: typing.Union[
AzureResultsConfig, FilesystemResultsConfig, RedisResultsConfig,
S3ResultsConfig
AzureResultsConfig,
FilesystemResultsConfig,
RedisResultsConfig,
S3ResultsConfig,
]
result_backend_always_retry: bool = True
result_backend_max_retries: int = 10
Expand All @@ -202,8 +232,12 @@ def __init__(self, **data):
# Task track timeout
task_tracking_timeout: int = 3600
# Supported architectures and distributions
supported_architectures: typing.List[str] = constants.SUPPORTED_ARCHITECTURES
supported_distributions: typing.List[str] = constants.SUPPORTED_DISTRIBUTIONS
supported_architectures: typing.List[
str
] = constants.SUPPORTED_ARCHITECTURES
supported_distributions: typing.List[
str
] = constants.SUPPORTED_DISTRIBUTIONS
rhel_flavors: typing.Tuple[str] = constants.RHEL_FLAVORS
debian_flavors: typing.Tuple[str] = constants.DEBIAN_FLAVORS
supported_runners: typing.Union[typing.List[str], str] = 'all'
Expand Down Expand Up @@ -244,8 +278,12 @@ def result_backend(self) -> str:
def broker_url(self) -> str:
return self.broker_config.broker_url

def get_opennebula_template_id(self, dist_name: str, dist_version: str,
dist_arch: str):
def get_opennebula_template_id(
self,
dist_name: str,
dist_version: str,
dist_arch: str,
):
# TODO: Remove the method, for now leave the placeholder
return ''

Expand Down
Loading