Skip to content

Commit

Permalink
Merge pull request #35 from ceph/wip-fix-tox
Browse files Browse the repository at this point in the history
Fix tox tests and enable actions
  • Loading branch information
kshtsk authored Jul 31, 2024
2 parents 243d314 + 4ba0d6e commit ab20066
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 64 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ci

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
name: CI on python${{ matrix.python }} via ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
python: "3.10"
- os: ubuntu-22.04
python: "3.11"
- os: ubuntu-24.04
python: "3.12"
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install system deps
run: sudo apt-get -y install libvirt-dev
- name: Install tox
run: pip install tox
- name: Run unit tests
run: tox -e py3
2 changes: 1 addition & 1 deletion downburst/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get(distro, distroversion, arch):
parser.feed(r.content.decode())
parser.close()
list = parser.filenames
imageprefix = distro + '-' + distroversion + '-(\d+)'
imageprefix = distro + '-' + distroversion + r'-(\d+)'
imagesuffix = '-cloudimg-' + arch + '.(img|raw)'
imagestring = imageprefix + imagesuffix
file = search(imagestring=imagestring, list=list)
Expand Down
4 changes: 2 additions & 2 deletions downburst/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from lxml import etree
import pkg_resources
import importlib

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -134,7 +134,7 @@ def domain(
raw = False,
emulator = None,
):
with pkg_resources.resource_stream('downburst', 'template.xml') as f:
with importlib.resources.files('downburst').joinpath('template.xml').open() as f:
tree = etree.parse(f)
(domain,) = tree.xpath('/domain')
domain.set('type', hypervisor)
Expand Down
79 changes: 19 additions & 60 deletions downburst/test/test_discover.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,22 @@
from .. import discover
from unittest.mock import patch, Mock

@patch('requests.get')
def test_ubuntu_handler(m_requests_get):
h = discover.UbuntuHandler()
assert 'focal' == h.get_release('20.04')
assert '18.04' == h.get_version('bionic')
m_request = Mock()
m_request.content = (
b"focal server release 20230302\n"
b"jammy server release 20230303\n")
m_requests_get.return_value = m_request
assert ('20230302','release') == h.get_serial('focal')

@patch('downburst.discover.UbuntuHandler.get_serial')
def test_get(m_get_serial):
m_get_serial.return_value = ('20230420', 'release')
checksum = 'cd824b19795e8a6b9ae993b0b5157de0275e952a7a9e8b9717ca07acec22f51b'
res = discover.get('ubuntu', '20.04', 'x86_64')
assert checksum == res['checksum']

def test_extract():
PATH = (
'server/releases/precise/release-20120424'
+ '/ubuntu-12.04-server-cloudimg-amd64-disk1.img'
)
URL = 'https://cloud-images.ubuntu.com/' + PATH
SHA512 = (
'0737607be5c9b8ef9b7c45a77802b0098ce99d73'
+ '7e1a233e1e582f98ea10b6619dcb280bb7e5c6ce'
+ 'fcba275473e9be56a7058fea534db7534908d3d0'
+ '83c569bd'
)
catalog = dict(
catalog=[
dict(
distro_code_name='oneiric',
borkbork=True,
),
dict(
distro_code_name='precise',
build_types=dict(
misleading='bork bork',
server=[
dict(
release_tag='daily',
borkbork=True,
),
dict(
release_tag='release',
build_serial='20120424',
arches=dict(
misleading='bork bork',
amd64=dict(
file_list=[
dict(
file_type='tar.gz',
borkbork=True,
),
dict(
file_type='qcow2',
build_serial='20120424',
path=PATH,
sha512=SHA512,
),
],
),
),
),
],
),
),
],
)
got = discover.extract(catalog)
assert got is not None
assert got == dict(
serial='20120424',
url=URL,
sha512=SHA512,
)
11 changes: 11 additions & 0 deletions downburst/test/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ def test_domain_name():
assert name == 'fakename'


def test_domain_arch():
tree = template.domain(
name='fakename',
disk_key='/fake/path',
iso_key='/fake/iso',
emulator='/fake/emulator/path',
)
arch = tree.xpath('/domain/os/type/@arch')
assert arch == ['x86_64']


def test_domain_disk():
tree = template.domain(
name='fakename',
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[tox]
envlist = py27
envlist = py3

[testenv]
deps=
-r{toxinidir}/requirements-dev.txt
requests
lxml
pytest
Expand Down

0 comments on commit ab20066

Please sign in to comment.