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

chore: pull types from wip PR for upcoming Model.wait_for_idle #1203

Merged
merged 21 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a0fac06
chore: pull types from wip PR for upcoming Model.wait_for_idle
dimaqq Nov 20, 2024
ee6414e
chore: type hints for wait_for_idle specifically
dimaqq Nov 20, 2024
99d8fc1
chore: no need to `assert connection`
dimaqq Nov 22, 2024
8cf92b3
chore: use StatusStr for known status values
dimaqq Nov 22, 2024
bc93dfd
chore: update tox.ini for the new pacakge
dimaqq Nov 22, 2024
945bac4
chore: keep python versions independent in testing
dimaqq Nov 22, 2024
af5fb47
chore: better url.URL docstring
dimaqq Nov 22, 2024
bc881e4
chore: guard access to model.info on connection
dimaqq Nov 22, 2024
35499f4
chore: simpler tox.ini
dimaqq Nov 22, 2024
018aa2d
chore: test the new StatusStr vs severity_map
dimaqq Nov 22, 2024
3a56b5d
chore: simplify worst status selection
dimaqq Nov 22, 2024
3784fe8
chore: try building in a newer environment
dimaqq Nov 22, 2024
2f07806
chore: rely on pyproject.toml when building docs
dimaqq Nov 22, 2024
fbe1e63
chore: make pylxd optional, as it brings in ws4py from 2018
dimaqq Nov 22, 2024
e2740a1
chore: update Model.info docstring
dimaqq Nov 22, 2024
2fdcaef
chore: dedent, drop setuptools in dev
dimaqq Nov 22, 2024
08b0e0b
chore: readthedocs by trial and error
dimaqq Nov 22, 2024
9f45c06
chore: readthedocs by trial and error
dimaqq Nov 22, 2024
f2c6c50
chore: readthedocs by trial and error
dimaqq Nov 22, 2024
39ca34c
chore: note the sphinx issue
dimaqq Nov 22, 2024
f6efcf7
Merge branch 'chore-lighter-tox' into chore-type-hints-for-wait-for-idle
dimaqq Nov 22, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
name: Unit tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
dimaqq marked this conversation as resolved.
Show resolved Hide resolved
matrix:
python:
- "3.8"
Expand Down
24 changes: 9 additions & 15 deletions juju/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .facade_versions import client_facade_versions, known_unsupported_facades

SpecifiedFacades: TypeAlias = "dict[str, dict[Literal['versions'], Sequence[int]]]"
_WebSocket: TypeAlias = "websockets.legacy.client.WebSocketClientProtocol"
_WebSocket: TypeAlias = websockets.WebSocketClientProtocol

LEVELS = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR"]
log = logging.getLogger("juju.client.connection")
Expand Down Expand Up @@ -291,7 +291,7 @@ def is_using_old_client(self):
def is_open(self):
return self.monitor.status == Monitor.CONNECTED

def _get_ssl(self, cert=None):
def _get_ssl(self, cert: str | None = None) -> ssl.SSLContext:
context = ssl.create_default_context(
purpose=ssl.Purpose.SERVER_AUTH, cadata=cert
)
Expand All @@ -305,7 +305,9 @@ def _get_ssl(self, cert=None):
context.check_hostname = False
return context

async def _open(self, endpoint, cacert) -> tuple[_WebSocket, str, str, str]:
async def _open(
self, endpoint: str, cacert: str
) -> tuple[_WebSocket, str, str, str]:
if self.is_debug_log_connection:
assert self.uuid
url = f"wss://user-{self.username}:{self.password}@{endpoint}/model/{self.uuid}/log"
Expand All @@ -323,10 +325,6 @@ async def _open(self, endpoint, cacert) -> tuple[_WebSocket, str, str, str]:
sock = self.proxy.socket()
server_hostname = "juju-app"

def _exit_tasks():
for task in jasyncio.all_tasks():
task.cancel()

dimaqq marked this conversation as resolved.
Show resolved Hide resolved
return (
(
await websockets.connect(
Expand All @@ -342,7 +340,7 @@ def _exit_tasks():
cacert,
)

async def close(self, to_reconnect=False):
async def close(self, to_reconnect: bool = False):
if not self._ws:
return
self.monitor.close_called.set()
Expand Down Expand Up @@ -380,11 +378,7 @@ async def close(self, to_reconnect=False):

async def _recv(self, request_id: int) -> dict[str, Any]:
if not self.is_open:
raise websockets.exceptions.ConnectionClosed(
websockets.frames.Close(
websockets.frames.CloseCode.NORMAL_CLOSURE, "websocket closed"
)
)
raise websockets.exceptions.ConnectionClosedOK(None, None)
try:
return await self.messages.get(request_id)
except GeneratorExit:
Expand Down Expand Up @@ -626,7 +620,7 @@ async def rpc(

return result

def _http_headers(self):
def _http_headers(self) -> dict[str, str]:
"""Return dictionary of http headers necessary for making an http
connection to the endpoint of this Connection.

Expand All @@ -640,7 +634,7 @@ def _http_headers(self):
token = base64.b64encode(creds.encode())
return {"Authorization": f"Basic {token.decode()}"}

def https_connection(self):
def https_connection(self) -> tuple[HTTPSConnection, dict[str, str], str]:
"""Return an https connection to this Connection's endpoint.

Returns a 3-tuple containing::
Expand Down
3 changes: 2 additions & 1 deletion juju/client/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
self.model_name = None
self.jujudata = jujudata or FileJujuData()

def is_connected(self):
def is_connected(self) -> bool:
"""Report whether there is a currently connected controller or not"""
return self._connection is not None

Expand All @@ -60,6 +60,7 @@ def connection(self) -> Connection:
"""
if not self.is_connected():
raise NoConnectionException("not connected")
assert self._connection
return self._connection

async def connect(self, **kwargs):
Expand Down
Loading
Loading