Skip to content

Commit

Permalink
Merge branch 'main' into jasyncio
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmilsonRodrigues authored Nov 27, 2024
2 parents f6259b9 + 7662197 commit dcd9d9f
Show file tree
Hide file tree
Showing 22 changed files with 439 additions and 333 deletions.
59 changes: 20 additions & 39 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ jobs:
python:
- "3.10"
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: pip install tox
- name: Run validation tests
run: tox -e validate
- uses: astral-sh/[email protected]
- run: uvx -p ${{ matrix.python }} tox -e validate

unit-tests:
name: Unit tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- "3.8"
Expand All @@ -55,16 +52,12 @@ jobs:
- "3.12"
- "3.13"
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: pip install tox
- name: Run unit tests
run: tox -e py3
- uses: astral-sh/[email protected]
- run: uvx -p ${{ matrix.python }} tox -e unit

integration:
name: Integration
Expand All @@ -84,21 +77,14 @@ jobs:
- "3.3/stable"
- "3.4/stable"
- "3.5/stable"
# A bunch of tests fail with juju.errors.JujuError: base: [email protected]/stable
# * test_subordinate_units
# * test_destroy_unit
# * test_ssh
# * ...
# - "3.6/beta"
- "3.6/candidate"
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
- uses: astral-sh/[email protected]
- uses: charmed-kubernetes/actions-operator@main
with:
provider: lxd
juju-channel: ${{ matrix.juju }}
Expand Down Expand Up @@ -130,9 +116,7 @@ jobs:
# # set model defaults
# juju model-defaults apt-http-proxy=$PROXY apt-https-proxy=$PROXY juju-http-proxy=$PROXY juju-https-proxy=$PROXY snap-http-proxy=$PROXY snap-https-proxy=$PROXY
# juju model-defaults
- name: Run integration
# Force one single concurrent test
run: tox -e integration
- run: uvx -p ${{ matrix.python }} tox -e integration

integration-quarantine:
name: Quarantined Integration Tests
Expand All @@ -150,16 +134,13 @@ jobs:
- "3.4/stable"
- "3.5/stable"
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
- uses: astral-sh/[email protected]
- uses: charmed-kubernetes/actions-operator@main
with:
provider: lxd
juju-channel: ${{ matrix.juju }}
- name: Run integration
run: tox -e integration-quarantine
- run: uvx -p ${{ matrix.python }} tox -e integration-quarantine
12 changes: 9 additions & 3 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ version: 2

python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
- dev
- docs

build:
os: ubuntu-22.04
os: ubuntu-24.04
tools:
python: "3.10"
# Older Shpinx uses imghdr that was removed in Python 3.13
# See e.g. https://github.com/python/cpython/issues/104818
python: "3.12"

sphinx:
configuration: docs/conf.py
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ clean:
find . -name __pycache__ -type d -exec rm -r {} +
find . -name *.pyc -delete
rm -rf .tox
rm -rf docs/_build/

.PHONY: .tox
.tox:
tox -r --notest
rm -rf build dist docs/_build/

.PHONY: client
client:
Expand All @@ -21,19 +17,19 @@ client:
pre-commit run --files $(shell echo juju/client/_[cd]*.py)

.PHONY: run-unit-tests
run-unit-tests: .tox
tox -e py3
run-unit-tests:
uvx tox -e unit

.PHONY: run-integration-tests
run-integration-tests: .tox
tox -e integration
run-integration-tests:
uvx tox -e integration

.PHONY: run-all-tests
test: run-unit-tests run-integration-tests

.PHONY: docs
docs:
tox -e docs
uvx tox -e docs

.PHONY: build-test
build-test:
Expand Down
16 changes: 0 additions & 16 deletions docs/requirements.txt

This file was deleted.

29 changes: 16 additions & 13 deletions juju/bundle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.
from __future__ import annotations

import asyncio
import base64
Expand All @@ -9,7 +10,7 @@
import zipfile
from contextlib import closing
from pathlib import Path
from typing import Dict, Optional
from typing import TYPE_CHECKING, Mapping, cast

import requests
import yaml
Expand All @@ -18,12 +19,15 @@
from . import utils
from .client import client
from .constraints import parse as parse_constraints
from .constraints import parse_storage_constraint
from .errors import JujuError
from .origin import Channel, Source
from .url import URL, Schema
from .utils import get_base_from_origin_or_channel

if TYPE_CHECKING:
from .constraints import StorageConstraintDict
from .model import Model

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -600,7 +604,8 @@ class AddApplicationChange(ChangeInfo):
:options: holds application options.
:constraints: optional application constraints.
:storage: optional storage constraints, in the form of `{label: constraint}`.
The label is a string specified by the charm, while the constraint is a string following
The label is a string specified by the charm, while the constraint is
either a constraints.StorageConstraintDict, or a string following
`the juju storage constraint directive format <https://juju.is/docs/juju/storage-constraint>`_,
specifying the storage pool, number of volumes, and size of each volume.
:devices: optional devices constraints.
Expand All @@ -611,7 +616,7 @@ class AddApplicationChange(ChangeInfo):
application's charm.
"""

storage: Optional[Dict[str, str]]
storage: Mapping[str, str | StorageConstraintDict] | None = None

@staticmethod
def method():
Expand All @@ -628,7 +633,8 @@ async def run(self, context):
# NB: this should really be handled by the controller when generating the
# bundle change plan, and this short-term workaround may be missing some
# aspects of the logic which the CLI client contains to handle edge cases.
if self.application in context.model.applications:
model = cast("Model", context.model) # pyright: ignore[reportUnknownMemberType]
if self.application in model.applications:
log.debug("Skipping %s; already in model", self.application)
return self.application

Expand All @@ -638,9 +644,9 @@ async def run(self, context):
if self.options is not None:
options = self.options
if context.trusted:
if context.model.info.agent_version < client.Number.from_json("2.4.0"):
if model.info.agent_version < client.Number.from_json("2.4.0"):
raise NotImplementedError(
f"trusted is not supported on model version {context.model.info.agent_version}"
f"trusted is not supported on model version {model.info.agent_version}"
)
options["trust"] = "true"

Expand Down Expand Up @@ -677,22 +683,19 @@ async def run(self, context):
.get("resources", {})
)
if Schema.CHARM_HUB.matches(url.schema):
resources = await context.model._add_charmhub_resources(
resources = await model._add_charmhub_resources(
self.application, charm, origin, overrides=self.resources
)

await context.model._deploy(
await model._deploy(
charm_url=charm,
application=self.application,
series=self.series,
config=options,
constraints=self.constraints,
endpoint_bindings=self.endpoint_bindings,
resources=resources,
storage={
label: parse_storage_constraint(constraint)
for label, constraint in (self.storage or {}).items()
},
storage=self.storage,
channel=self.channel,
devices=self.devices,
num_units=self.num_units,
Expand Down
11 changes: 11 additions & 0 deletions juju/client/_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,7 @@ class ApplicationStatus(Type):
"charm": "charm",
"charm_channel": "charm-channel",
"charm_profile": "charm-profile",
"charm_rev": "charm-rev",
"charm_version": "charm-version",
"endpoint_bindings": "endpoint-bindings",
"err": "err",
Expand All @@ -3154,6 +3155,7 @@ class ApplicationStatus(Type):
"charm": "charm",
"charm-channel": "charm_channel",
"charm-profile": "charm_profile",
"charm-rev": "charm_rev",
"charm-version": "charm_version",
"endpoint-bindings": "endpoint_bindings",
"err": "err",
Expand All @@ -3178,6 +3180,7 @@ def __init__(
charm=None,
charm_channel=None,
charm_profile=None,
charm_rev=None,
charm_version=None,
endpoint_bindings=None,
err=None,
Expand All @@ -3200,6 +3203,7 @@ def __init__(
charm : str
charm_channel : str
charm_profile : str
charm_rev : int
charm_version : str
endpoint_bindings : typing.Mapping[str, str]
err : Error
Expand All @@ -3221,6 +3225,7 @@ def __init__(
charm_ = charm
charm_channel_ = charm_channel
charm_profile_ = charm_profile
charm_rev_ = charm_rev
charm_version_ = charm_version
endpoint_bindings_ = endpoint_bindings
err_ = Error.from_json(err) if err else None
Expand Down Expand Up @@ -3266,6 +3271,11 @@ def __init__(
f"Expected charm_profile_ to be a str, received: {type(charm_profile_)}"
)

if charm_rev_ is not None and not isinstance(charm_rev_, int):
raise Exception(
f"Expected charm_rev_ to be a int, received: {type(charm_rev_)}"
)

if charm_version_ is not None and not isinstance(charm_version_, (bytes, str)):
raise Exception(
f"Expected charm_version_ to be a str, received: {type(charm_version_)}"
Expand Down Expand Up @@ -3346,6 +3356,7 @@ def __init__(
self.charm = charm_
self.charm_channel = charm_channel_
self.charm_profile = charm_profile_
self.charm_rev = charm_rev_
self.charm_version = charm_version_
self.endpoint_bindings = endpoint_bindings_
self.err = err_
Expand Down
Loading

0 comments on commit dcd9d9f

Please sign in to comment.