Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c717aea394 | ||
|
|
ea35ba2758 | ||
|
|
5e5e2f9095 |
+6
-2
@@ -11,8 +11,12 @@ CMD ["python", "-m", "unittest", "discover", "-s", "tests", "-v"]
|
|||||||
|
|
||||||
FROM python:3.11-slim
|
FROM python:3.11-slim
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||||
RUN groupadd --gid 1001 archive-control \
|
RUN if ! getent group 1001 >/dev/null; then \
|
||||||
&& useradd --uid 1001 --gid 1001 --no-create-home archive-control
|
groupadd --gid 1001 archive-control; \
|
||||||
|
fi \
|
||||||
|
&& if ! getent passwd 1001 >/dev/null; then \
|
||||||
|
useradd --uid 1001 --gid 1001 --no-create-home archive-control; \
|
||||||
|
fi
|
||||||
COPY --from=builder /wheels /wheels
|
COPY --from=builder /wheels /wheels
|
||||||
RUN pip install --no-cache-dir /wheels/*.whl && rm -rf /wheels
|
RUN pip install --no-cache-dir /wheels/*.whl && rm -rf /wheels
|
||||||
USER 1001:1001
|
USER 1001:1001
|
||||||
|
|||||||
@@ -259,6 +259,28 @@ Generated protobuf Python bindings are committed in each consumer with the
|
|||||||
exact `archive-control-proto` tag/commit recorded. Release order is proto,
|
exact `archive-control-proto` tag/commit recorded. Release order is proto,
|
||||||
control consumer, client consumer, E2E, then image publication.
|
control consumer, client consumer, E2E, then image publication.
|
||||||
|
|
||||||
|
### Reproducible multi-platform Buildx lifecycle
|
||||||
|
|
||||||
|
The named Buildx builders are local acceleration/cache only; they are not a
|
||||||
|
deployment dependency and can be removed after publication. To create a fresh
|
||||||
|
builder, verify its platforms, publish a release, and remove it afterwards:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker buildx create --name archive-control-release --driver docker-container --use
|
||||||
|
docker buildx inspect --bootstrap
|
||||||
|
docker buildx build --platform linux/amd64,linux/arm64 \
|
||||||
|
--tag sodium/archive-clients:vX.Y.Z --push .
|
||||||
|
docker buildx rm archive-control-release
|
||||||
|
```
|
||||||
|
|
||||||
|
`docker buildx inspect` must list both `linux/amd64` and `linux/arm64` before
|
||||||
|
publishing. If the host has no arm64 emulation, install/configure it according
|
||||||
|
to the host Docker distribution before the build; do not publish a partial
|
||||||
|
single-platform tag. Retain the pushed manifest digest in the release notes
|
||||||
|
and deploy the immutable tag or digest. The optional `archive-control-qemu`
|
||||||
|
builder follows the same lifecycle when it is used for an emulation smoke
|
||||||
|
build.
|
||||||
|
|
||||||
## Operator usage
|
## Operator usage
|
||||||
|
|
||||||
1. Prepare local qB, sync, state, backup, config, and secret mounts with the
|
1. Prepare local qB, sync, state, backup, config, and secret mounts with the
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "archive-clients"
|
name = "archive-clients"
|
||||||
version = "0.1.15"
|
version = "0.1.17"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
dependencies = ["protobuf==7.35.1", "websockets==16.0"]
|
dependencies = ["protobuf==7.35.1", "websockets==16.0"]
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
@@ -16,6 +17,8 @@ from urllib import error, parse, request
|
|||||||
from archive_clients.config import ServiceConfig
|
from archive_clients.config import ServiceConfig
|
||||||
from archive_clients.resources import NormalizedResource, normalize_resource
|
from archive_clients.resources import NormalizedResource, normalize_resource
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class QBittorrentError(RuntimeError):
|
class QBittorrentError(RuntimeError):
|
||||||
pass
|
pass
|
||||||
@@ -72,7 +75,17 @@ class QBittorrentReader:
|
|||||||
torrent_hash = torrent.get("hash")
|
torrent_hash = torrent.get("hash")
|
||||||
if not isinstance(torrent_hash, str):
|
if not isinstance(torrent_hash, str):
|
||||||
raise QBittorrentError("qBittorrent torrent hash is invalid")
|
raise QBittorrentError("qBittorrent torrent hash is invalid")
|
||||||
|
try:
|
||||||
result.append(self._normalize(torrent, torrent_hash))
|
result.append(self._normalize(torrent, torrent_hash))
|
||||||
|
except ValueError as exc:
|
||||||
|
# A stale or malformed qBittorrent entry must not hide every
|
||||||
|
# otherwise valid resource from Archive/Evict inventory.
|
||||||
|
# Keep it ineligible and leave an operator-visible diagnosis.
|
||||||
|
logger.warning(
|
||||||
|
"Skipping qBittorrent resource with inconsistent "
|
||||||
|
"metadata: hash=%s name=%r reason=%s",
|
||||||
|
torrent_hash, torrent.get("name"), exc,
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_resource(self, torrent_hash: str) -> NormalizedResource | None:
|
def get_resource(self, torrent_hash: str) -> NormalizedResource | None:
|
||||||
|
|||||||
@@ -205,6 +205,54 @@ class QBittorrentReaderTests(unittest.TestCase):
|
|||||||
self.assertEqual(resources, [])
|
self.assertEqual(resources, [])
|
||||||
self.assertEqual(len(opener.calls), 2)
|
self.assertEqual(len(opener.calls), 2)
|
||||||
|
|
||||||
|
def test_listing_skips_malformed_torrent_and_keeps_valid_resources(self):
|
||||||
|
def torrent(name, content):
|
||||||
|
info = {
|
||||||
|
b"length": len(content), b"name": name.encode(),
|
||||||
|
b"piece length": 16384, b"pieces": b"x" * 20,
|
||||||
|
}
|
||||||
|
return encode({b"info": info}), hashlib.sha1(encode(info)).hexdigest()
|
||||||
|
|
||||||
|
first_bytes, first_hash = torrent("first.txt", b"one")
|
||||||
|
malformed_bytes, malformed_hash = torrent("broken.txt", b"bad")
|
||||||
|
second_bytes, second_hash = torrent("second.txt", b"two")
|
||||||
|
torrents = [
|
||||||
|
{"hash": first_hash, "name": "first.txt", "state": "uploading"},
|
||||||
|
{"hash": malformed_hash, "name": "broken.txt", "state": "stalledUP"},
|
||||||
|
{"hash": second_hash, "name": "second.txt", "state": "uploading"},
|
||||||
|
]
|
||||||
|
responses = [
|
||||||
|
b"Ok.", json.dumps(torrents).encode(),
|
||||||
|
b'[{"index":0,"name":"first.txt","size":3,"progress":1,"priority":1}]',
|
||||||
|
first_bytes,
|
||||||
|
b'[{"index":0,"name":"broken.txt","size":3,"progress":1,"priority":1},'
|
||||||
|
b'{"index":1,"name":"unexpected.txt","size":1,"progress":1,"priority":1}]',
|
||||||
|
malformed_bytes,
|
||||||
|
b'[{"index":0,"name":"second.txt","size":3,"progress":1,"priority":1}]',
|
||||||
|
second_bytes,
|
||||||
|
]
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
password = root / "password"
|
||||||
|
password.write_text("secret", encoding="utf-8")
|
||||||
|
os.chmod(password, 0o600)
|
||||||
|
config = ServiceConfig(
|
||||||
|
"http://qb", PurePosixPath("/downloads"), root,
|
||||||
|
username="admin", password_file=password,
|
||||||
|
)
|
||||||
|
opener = _Opener(responses)
|
||||||
|
with patch(
|
||||||
|
"archive_clients.qbittorrent.request.build_opener",
|
||||||
|
return_value=opener,
|
||||||
|
), self.assertLogs("archive_clients.qbittorrent", "WARNING") as logs:
|
||||||
|
resources = QBittorrentReader(config).list_resources()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
[resource.summary.display_name for resource in resources],
|
||||||
|
["first.txt", "second.txt"],
|
||||||
|
)
|
||||||
|
self.assertIn(malformed_hash, "\n".join(logs.output))
|
||||||
|
|
||||||
def test_stopped_add_selection_recheck_and_entry_only_delete(self):
|
def test_stopped_add_selection_recheck_and_entry_only_delete(self):
|
||||||
torrent_hash = "a" * 40
|
torrent_hash = "a" * 40
|
||||||
responses = [
|
responses = [
|
||||||
|
|||||||
Reference in New Issue
Block a user