multicloud-cli 0.13.0__tar.gz → 0.13.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/PKG-INFO +3 -1
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/README.md +2 -0
- multicloud_cli-0.13.1/multicloud_cli/__init__.py +1 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/net.py +8 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/pool.py +101 -0
- multicloud_cli-0.13.1/tests/test_net.py +49 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_pool.py +68 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_version_check.py +1 -1
- multicloud_cli-0.13.0/multicloud_cli/__init__.py +0 -1
- multicloud_cli-0.13.0/tests/test_net.py +0 -24
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/.gitignore +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/LICENSE +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/account.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/api.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/auth.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/catalog.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/cloud_account.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/config.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/db_access.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/duration.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/exitcodes.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/extend.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/kube.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/main.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/node.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/orgopt.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/output.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/ssh.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/ssh_cert.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/sso.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/multicloud_cli/version_check.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/pyproject.toml +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/__init__.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/conftest.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/helpers.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_account_extend.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_apply.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_auth.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_catalog.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_cloud_account.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_conventions.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_db_access.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_proxy_key.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_ssh.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_ssh_cert.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_sso.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.13.1}/tests/test_sso_session.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: multicloud-cli
|
|
3
|
-
Version: 0.13.
|
|
3
|
+
Version: 0.13.1
|
|
4
4
|
Summary: mctl: the Multicloud command line: sign in, connect your cloud account, run pools
|
|
5
5
|
Project-URL: Homepage, https://multicloud.io
|
|
6
6
|
Author-email: Multicloud Team <info@multicloud.io>
|
|
@@ -159,6 +159,8 @@ mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6
|
|
|
159
159
|
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--max-servers`, `--classes`, `--spot-policy`, `--cpu-units-requests`, `--clouds` or settings: `--set NAME=VALUE` (repeat; VALUE is JSON, else text; the name lists `instance_types`, `excluded_instance_types`, `accelerator_names`, `excluded_accelerator_names`, `accelerator_vendors` and `excluded_accelerator_vendors` also take comma-separated names; `grant.cpu` for grant fields), `--reset NAME`, `--settings JSON\|@file`. Only the options you give change. `mctl pool show` prints the settings, or `default: X` where a setting is unset. On an Extend pool with a `PENDING` or `READY` peering, a change of `accelerator_names` or `excluded_accelerator_names` fails with 409 `POOL_HAS_PEERINGS`: revoke the peering first, or create a second pool. |
|
|
160
160
|
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
161
161
|
| `mctl pool diagnose <pool>` | Why a pool or its Extend bridge does not work: the pool's lifecycle and readiness gates, and for each bridge replica what the pool sees of its WireGuard handshake, with a hint. Reads only; it never wakes a hibernated pool. `--json` prints the raw answer. |
|
|
162
|
+
| `mctl pool cpu-sizing <pool>` | Recommended cpu-units request and burst limit per workload container, from the last 14 days of usage (72 qualifying hours needed), with the current request, observed P95/MAX and `clipped`. `--namespace`, `--owner-kind`, `--window-days`, `--clipped-only`, `--json`. Reads only. |
|
|
163
|
+
| `mctl pool cpu-sizing-history <pool> <namespace> <owner-kind> <owner-name>` | The hourly cpu-units of one workload, per container. `--window-days`, `--json`. |
|
|
162
164
|
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
163
165
|
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
164
166
|
| `mctl pool rotate-credentials <pool>` / `rotation-status <pool>` | Renew the pool's access credentials; show the progress of the last renewal. |
|
|
@@ -128,6 +128,8 @@ mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6
|
|
|
128
128
|
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--max-servers`, `--classes`, `--spot-policy`, `--cpu-units-requests`, `--clouds` or settings: `--set NAME=VALUE` (repeat; VALUE is JSON, else text; the name lists `instance_types`, `excluded_instance_types`, `accelerator_names`, `excluded_accelerator_names`, `accelerator_vendors` and `excluded_accelerator_vendors` also take comma-separated names; `grant.cpu` for grant fields), `--reset NAME`, `--settings JSON\|@file`. Only the options you give change. `mctl pool show` prints the settings, or `default: X` where a setting is unset. On an Extend pool with a `PENDING` or `READY` peering, a change of `accelerator_names` or `excluded_accelerator_names` fails with 409 `POOL_HAS_PEERINGS`: revoke the peering first, or create a second pool. |
|
|
129
129
|
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
130
130
|
| `mctl pool diagnose <pool>` | Why a pool or its Extend bridge does not work: the pool's lifecycle and readiness gates, and for each bridge replica what the pool sees of its WireGuard handshake, with a hint. Reads only; it never wakes a hibernated pool. `--json` prints the raw answer. |
|
|
131
|
+
| `mctl pool cpu-sizing <pool>` | Recommended cpu-units request and burst limit per workload container, from the last 14 days of usage (72 qualifying hours needed), with the current request, observed P95/MAX and `clipped`. `--namespace`, `--owner-kind`, `--window-days`, `--clipped-only`, `--json`. Reads only. |
|
|
132
|
+
| `mctl pool cpu-sizing-history <pool> <namespace> <owner-kind> <owner-name>` | The hourly cpu-units of one workload, per container. `--window-days`, `--json`. |
|
|
131
133
|
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
132
134
|
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
133
135
|
| `mctl pool rotate-credentials <pool>` / `rotation-status <pool>` | Renew the pool's access credentials; show the progress of the last renewal. |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.13.1"
|
|
@@ -11,6 +11,11 @@ from requests.adapters import HTTPAdapter
|
|
|
11
11
|
from . import __version__, exitcodes
|
|
12
12
|
|
|
13
13
|
USER_AGENT = f"mctl/{__version__}"
|
|
14
|
+
# The connect timeout of each address. api. and auth.multicloud.io resolve to several A and AAAA records, and
|
|
15
|
+
# urllib3 tries them one at a time (no Happy Eyeballs): with the read timeout as the connect timeout, one address
|
|
16
|
+
# that drops SYNs cost 30 s per request. The connect timeout also bounds the TLS handshake (urllib3 sets the read
|
|
17
|
+
# timeout only after it): TCP connect plus TLS to the API takes about 0.45 s, so 5 s leaves room for a slow link.
|
|
18
|
+
CONNECT_TIMEOUT_S = 5
|
|
14
19
|
UPGRADE = "uv tool upgrade multicloud-cli (or pipx upgrade multicloud-cli)"
|
|
15
20
|
|
|
16
21
|
|
|
@@ -53,6 +58,9 @@ def request(method: str, url: str, ipv4_only: bool = False, ipv6_only: bool = Fa
|
|
|
53
58
|
"""One request. ``ipv4_only`` / ``ipv6_only`` connect over one address family only: the grant routes read the
|
|
54
59
|
address of the caller as the API sees it, and ``api.multicloud.io`` has A and AAAA records."""
|
|
55
60
|
kw["headers"] = {"User-Agent": USER_AGENT, **(kw.get("headers") or {})}
|
|
61
|
+
timeout = kw.get("timeout")
|
|
62
|
+
if isinstance(timeout, (int, float)) and not isinstance(timeout, bool) and timeout > 0: # a pair is kept as given
|
|
63
|
+
kw["timeout"] = (min(CONNECT_TIMEOUT_S, timeout), timeout)
|
|
56
64
|
if ipv4_only or ipv6_only:
|
|
57
65
|
adapter = IPv6Adapter if ipv6_only else IPv4Adapter
|
|
58
66
|
with requests.Session() as session:
|
|
@@ -272,6 +272,107 @@ def diagnose(ctx, pool_ref, as_json):
|
|
|
272
272
|
click.echo(json.dumps(_plain(data), indent=2, sort_keys=True) if as_json else _diagnose_text(data))
|
|
273
273
|
|
|
274
274
|
|
|
275
|
+
#: GET /pools/{id}/cpu-sizing keeps 35 days of usage; the recommendation always uses 14.
|
|
276
|
+
CPU_SIZING_WINDOW = click.IntRange(1, 35)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _units(value) -> str:
|
|
280
|
+
return "-" if value is None else str(value)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _cpu_now(w: Dict[str, Any]) -> str:
|
|
284
|
+
"""The current request/limit: cpu-units when the pod spec sets them, else raw millicores."""
|
|
285
|
+
cur = w.get("current") or {}
|
|
286
|
+
if w.get("setting_status") == "manifest_units":
|
|
287
|
+
return f"{_units(cur.get('request_units'))}/{_units(cur.get('limit_units'))}u"
|
|
288
|
+
if w.get("setting_status") == "manifest_raw":
|
|
289
|
+
return f"{_units(cur.get('request_mcpu'))}/{_units(cur.get('limit_mcpu'))}m"
|
|
290
|
+
return "-"
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _cpu_recommended(rec: Dict[str, Any]) -> str:
|
|
294
|
+
if rec.get("status") == "ok":
|
|
295
|
+
return f"{rec.get('request_units')}/{rec.get('limit_units')}u"
|
|
296
|
+
return f"wait ({rec.get('qualifying_hours')}/{rec.get('required_hours')}h)"
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def format_cpu_sizing(data: Dict[str, Any], headers: bool = True) -> str:
|
|
300
|
+
rows = []
|
|
301
|
+
for w in data.get("workloads", []):
|
|
302
|
+
obs, rec = w.get("observed") or {}, w.get("recommendation") or {}
|
|
303
|
+
rows.append((f"{w.get('namespace')}/{w.get('owner_kind')}/{w.get('owner_name')}", str(w.get("container")),
|
|
304
|
+
_cpu_now(w), _units(obs.get("p95_units")), _units(obs.get("max_units")),
|
|
305
|
+
_cpu_recommended(rec), "yes" if w.get("clipped") else "no"))
|
|
306
|
+
return _table(("WORKLOAD", "CONTAINER", "NOW (REQ/LIM)", "P95", "MAX", "RECOMMENDED (REQ/LIM)", "CLIPPED"),
|
|
307
|
+
rows, headers)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
@pool.command(name="cpu-sizing")
|
|
311
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
312
|
+
@click.option("--namespace", default=None, help="Only this namespace")
|
|
313
|
+
@click.option("--owner-kind", default=None, help="Only this owner kind, e.g. Deployment")
|
|
314
|
+
@click.option("--window-days", type=CPU_SIZING_WINDOW, default=None,
|
|
315
|
+
help="Days for the observed P95 and MAX (1-35, default 14). Never changes the recommendation")
|
|
316
|
+
@click.option("--clipped-only", is_flag=True, default=False, help="Only workloads whose CPU limit clipped the peak")
|
|
317
|
+
@json_option
|
|
318
|
+
@no_headers_option
|
|
319
|
+
@click.pass_context
|
|
320
|
+
def cpu_sizing(ctx, pool_ref, namespace, owner_kind, window_days, clipped_only, as_json, no_headers):
|
|
321
|
+
"""Show cpu-units recommendations per workload of a pool (id or name).
|
|
322
|
+
|
|
323
|
+
NOW is the current request/limit from the pod spec (u = cpu-units, m = raw millicores); P95 (the 95th
|
|
324
|
+
percentile of the hourly P95 values) and MAX are the observed cpu-units; RECOMMENDED is the request/limit from the last 14 days, or "wait" with the
|
|
325
|
+
qualifying hours so far (72 are needed). Reads only: nothing is applied."""
|
|
326
|
+
params = {k: v for k, v in (("namespace", namespace), ("owner_kind", owner_kind),
|
|
327
|
+
("window_days", window_days)) if v is not None}
|
|
328
|
+
if clipped_only:
|
|
329
|
+
params["clipped_only"] = "true"
|
|
330
|
+
|
|
331
|
+
def go(org):
|
|
332
|
+
return _call(org, "GET", f"/pools/{resolve(org, pool_ref)}/cpu-sizing", READ, params=params or None)
|
|
333
|
+
data = _run(ctx, go)
|
|
334
|
+
if as_json:
|
|
335
|
+
return _dump(data)
|
|
336
|
+
_echo(format_cpu_sizing(data, not no_headers))
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def _history_text(d: Dict[str, Any]) -> str:
|
|
340
|
+
out = [f"{d.get('namespace')}/{d.get('owner_kind')}/{d.get('owner_name')} in pool {d.get('pool_id')}, "
|
|
341
|
+
f"last {d.get('window_days')} days"]
|
|
342
|
+
for c in d.get("containers", []):
|
|
343
|
+
rec = c.get("recommendation") or {}
|
|
344
|
+
out += ["", f"Container {c.get('container')}: recommended {_cpu_recommended(rec)}"
|
|
345
|
+
+ (", CLIPPED: the CPU limit cut the peak" if c.get("clipped") else "")]
|
|
346
|
+
out.append(_table(("HOUR", "SAMPLES", "AVG", "P95", "MAX", "REQ", "LIM"), [
|
|
347
|
+
(str(p.get("hour")), str(p.get("samples")), _units(p.get("avg_units")), _units(p.get("p95_units")),
|
|
348
|
+
_units(p.get("max_units")), _units(p.get("request_units")), _units(p.get("limit_units")))
|
|
349
|
+
for p in c.get("points", [])], True))
|
|
350
|
+
return "\n".join(out)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
@pool.command(name="cpu-sizing-history")
|
|
354
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
355
|
+
@click.argument("namespace")
|
|
356
|
+
@click.argument("owner_kind", metavar="OWNER_KIND")
|
|
357
|
+
@click.argument("owner_name", metavar="OWNER_NAME")
|
|
358
|
+
@click.option("--window-days", type=CPU_SIZING_WINDOW, default=None, help="Days of hourly points (1-35, default 14)")
|
|
359
|
+
@json_option
|
|
360
|
+
@click.pass_context
|
|
361
|
+
def cpu_sizing_history(ctx, pool_ref, namespace, owner_kind, owner_name, window_days, as_json):
|
|
362
|
+
"""Show the hourly cpu-units usage of one workload, per container (values in cpu-units)."""
|
|
363
|
+
from urllib.parse import quote
|
|
364
|
+
segments = "/".join(quote(s, safe="") for s in (namespace, owner_kind, owner_name))
|
|
365
|
+
params = {"window_days": window_days} if window_days is not None else None
|
|
366
|
+
|
|
367
|
+
def go(org):
|
|
368
|
+
return _call(org, "GET", f"/pools/{resolve(org, pool_ref)}/cpu-sizing/workloads/{segments}/history", READ,
|
|
369
|
+
params=params)
|
|
370
|
+
data = _run(ctx, go)
|
|
371
|
+
if as_json:
|
|
372
|
+
return _dump(data)
|
|
373
|
+
_echo(_history_text(data))
|
|
374
|
+
|
|
375
|
+
|
|
275
376
|
def _json_value(ctx, param, value):
|
|
276
377
|
"""A JSON value, or ``@path`` to read it from a file (``@-``: standard input)."""
|
|
277
378
|
if value is None:
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Every request carries User-Agent: mctl/<version>, and the package has one version."""
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from multicloud_cli import __version__, net
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_user_agent_is_added_and_headers_are_kept(monkeypatch):
|
|
8
|
+
seen = {}
|
|
9
|
+
monkeypatch.setattr(requests, "request", lambda m, u, **kw: seen.update(kw) or "r")
|
|
10
|
+
assert net.request("GET", "https://x", headers={"X-API-Key": "k"}, timeout=1) == "r"
|
|
11
|
+
assert seen["headers"] == {"User-Agent": f"mctl/{__version__}", "X-API-Key": "k"}
|
|
12
|
+
net.request("POST", "https://x", data={"a": "b"})
|
|
13
|
+
assert seen["headers"] == {"User-Agent": f"mctl/{__version__}"}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_no_module_calls_requests_directly():
|
|
17
|
+
# A direct requests call would skip the User-Agent header; only net.py may make one.
|
|
18
|
+
import pathlib
|
|
19
|
+
import re
|
|
20
|
+
pkg = pathlib.Path(net.__file__).parent
|
|
21
|
+
hits = [f"{p.name}:{i}" for p in sorted(pkg.glob("*.py")) if p.name != "net.py"
|
|
22
|
+
for i, line in enumerate(p.read_text(encoding="utf-8").splitlines(), 1)
|
|
23
|
+
if re.search(r"\brequests\.(request|get|post|put|patch|delete|head|Session)\(", line)]
|
|
24
|
+
assert hits == []
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_connect_timeout_is_short_per_address(monkeypatch):
|
|
28
|
+
# api. and auth.multicloud.io have 6 addresses and urllib3 tries them one by one: the connect timeout applies
|
|
29
|
+
# per address, so one address that drops SYNs must cost CONNECT_TIMEOUT_S, not the whole read timeout.
|
|
30
|
+
seen = {}
|
|
31
|
+
monkeypatch.setattr(requests, "request", lambda m, u, **kw: seen.update(kw) or "r")
|
|
32
|
+
net.request("GET", "https://x", timeout=30)
|
|
33
|
+
assert seen["timeout"] == (net.CONNECT_TIMEOUT_S, 30)
|
|
34
|
+
net.request("GET", "https://x", timeout=1) # a smaller total stays the bound for both
|
|
35
|
+
assert seen["timeout"] == (1, 1)
|
|
36
|
+
net.request("GET", "https://x", timeout=0) # not a number of seconds: requests decides, as before
|
|
37
|
+
assert seen["timeout"] == 0
|
|
38
|
+
net.request("GET", "https://x", timeout=(5, 7)) # an explicit pair is kept
|
|
39
|
+
assert seen["timeout"] == (5, 7)
|
|
40
|
+
seen.clear()
|
|
41
|
+
net.request("GET", "https://x") # no timeout given: none is added
|
|
42
|
+
assert "timeout" not in seen
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_connect_timeout_on_the_family_routes(monkeypatch):
|
|
46
|
+
seen = {}
|
|
47
|
+
monkeypatch.setattr(requests.Session, "request", lambda self, m, u, **kw: seen.update(kw) or "r")
|
|
48
|
+
net.request("POST", "https://x", timeout=30, ipv6_only=True)
|
|
49
|
+
assert seen["timeout"] == (net.CONNECT_TIMEOUT_S, 30)
|
|
@@ -583,3 +583,71 @@ def test_diagnose_pool_without_a_state_row(monkeypatch):
|
|
|
583
583
|
def test_diagnose_404_exits_not_found(monkeypatch):
|
|
584
584
|
r, _, _ = run(["diagnose", "412"], [reply(404, {"detail": {"error": {"message": "No such pool"}}})], monkeypatch)
|
|
585
585
|
assert r.exit_code == 4
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
# --- mctl pool cpu-sizing / cpu-sizing-history (GET /pools/{id}/cpu-sizing[...]) ---
|
|
589
|
+
|
|
590
|
+
def cpu_sizing_body():
|
|
591
|
+
"""A CpuSizingResponse: one workload with a recommendation, one still collecting data."""
|
|
592
|
+
rec_ok = {"status": "ok", "window_days": 14, "qualifying_hours": 120, "required_hours": 72,
|
|
593
|
+
"request_units": 230, "limit_units": 600}
|
|
594
|
+
rec_wait = {"status": "insufficient_data", "window_days": 14, "qualifying_hours": 9, "required_hours": 72,
|
|
595
|
+
"request_units": None, "limit_units": None}
|
|
596
|
+
obs = {"window_days": 14, "hours": 120, "avg_units": 150, "p95_units": 200, "max_units": 500}
|
|
597
|
+
return {"pool_id": 412, "window_days": 14, "generated_at": "2026-11-21T10:00:00Z", "workloads": [
|
|
598
|
+
{"namespace": "shop", "owner_kind": "Deployment", "owner_name": "web", "container": "app",
|
|
599
|
+
"last_hour": "2026-11-21T09:00:00Z", "namespace_opted_in": True, "setting_status": "manifest_raw",
|
|
600
|
+
"current": {"request_units": None, "limit_units": None, "request_mcpu": 500, "limit_mcpu": 1000},
|
|
601
|
+
"observed": obs, "recommendation": rec_ok, "clipped": True, "limit_bound_share": 0.08},
|
|
602
|
+
{"namespace": "jobs", "owner_kind": "StatefulSet", "owner_name": "db", "container": "pg",
|
|
603
|
+
"last_hour": "2026-11-21T09:00:00Z", "namespace_opted_in": True, "setting_status": "manifest_units",
|
|
604
|
+
"current": {"request_units": 100, "limit_units": 200, "request_mcpu": None, "limit_mcpu": None},
|
|
605
|
+
"observed": obs, "recommendation": rec_wait, "clipped": False, "limit_bound_share": 0.0}]}
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def test_cpu_sizing_table(monkeypatch):
|
|
609
|
+
r, calls, _ = run(["cpu-sizing", "412"], [reply(200, cpu_sizing_body())], monkeypatch)
|
|
610
|
+
assert r.exit_code == 0, r.output
|
|
611
|
+
assert calls[0][:2] == ("GET", f"{BASE}/pools/412/cpu-sizing")
|
|
612
|
+
assert not calls[0][2].get("params")
|
|
613
|
+
lines = r.stdout.splitlines()
|
|
614
|
+
assert lines[0].split()[:2] == ["WORKLOAD", "CONTAINER"]
|
|
615
|
+
assert "shop/Deployment/web" in lines[1] and "500/1000m" in lines[1] and "230/600u" in lines[1]
|
|
616
|
+
assert lines[1].rstrip().endswith("yes")
|
|
617
|
+
assert "100/200u" in lines[2] and "wait (9/72h)" in lines[2]
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def test_cpu_sizing_sends_the_api_query_names(monkeypatch):
|
|
621
|
+
r, calls, _ = run(["cpu-sizing", "412", "--namespace", "shop", "--owner-kind", "Deployment",
|
|
622
|
+
"--window-days", "30", "--clipped-only"], [reply(200, cpu_sizing_body())], monkeypatch)
|
|
623
|
+
assert r.exit_code == 0, r.output
|
|
624
|
+
assert calls[0][2]["params"] == {"namespace": "shop", "owner_kind": "Deployment", "window_days": 30,
|
|
625
|
+
"clipped_only": "true"}
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def test_cpu_sizing_window_is_bounded(monkeypatch):
|
|
629
|
+
r, calls, _ = run(["cpu-sizing", "412", "--window-days", "36"], [reply(200, cpu_sizing_body())], monkeypatch)
|
|
630
|
+
assert r.exit_code != 0 and calls == []
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
def test_cpu_sizing_json_is_the_raw_body(monkeypatch):
|
|
634
|
+
r, _, _ = run(["cpu-sizing", "412", "--json"], [reply(200, cpu_sizing_body())], monkeypatch)
|
|
635
|
+
assert r.exit_code == 0, r.output
|
|
636
|
+
assert json.loads(r.stdout) == cpu_sizing_body()
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
def test_cpu_sizing_history(monkeypatch):
|
|
640
|
+
body = {"pool_id": 412, "namespace": "shop", "owner_kind": "Deployment", "owner_name": "web", "window_days": 2,
|
|
641
|
+
"generated_at": "2026-11-21T10:00:00Z", "containers": [
|
|
642
|
+
{"container": "app", "clipped": True, "limit_bound_share": 0.08,
|
|
643
|
+
"recommendation": {"status": "ok", "window_days": 14, "qualifying_hours": 120,
|
|
644
|
+
"required_hours": 72, "request_units": 230, "limit_units": 600},
|
|
645
|
+
"points": [{"hour": "2026-11-21T09:00:00Z", "samples": 120, "avg_units": 150, "p95_units": 200,
|
|
646
|
+
"max_units": 500, "request_units": None, "limit_units": None}]}]}
|
|
647
|
+
r, calls, _ = run(["cpu-sizing-history", "412", "shop", "Deployment", "web", "--window-days", "2"],
|
|
648
|
+
[reply(200, body)], monkeypatch)
|
|
649
|
+
assert r.exit_code == 0, r.output
|
|
650
|
+
assert calls[0][:2] == ("GET", f"{BASE}/pools/412/cpu-sizing/workloads/shop/Deployment/web/history")
|
|
651
|
+
assert calls[0][2]["params"] == {"window_days": 2}
|
|
652
|
+
assert "Container app: recommended 230/600u, CLIPPED" in r.stdout
|
|
653
|
+
assert "2026-11-21T09:00:00Z" in r.stdout
|
|
@@ -53,7 +53,7 @@ def test_newer_version_prints_one_line(cache, pypi):
|
|
|
53
53
|
err = TtyErr()
|
|
54
54
|
version_check.notify(current="0.8.0", err=err, now=1000.0)
|
|
55
55
|
assert err.getvalue() == f"mctl 0.9.0 is available (you have 0.8.0). Upgrade: {UPGRADE}\n"
|
|
56
|
-
assert pypi["calls"] == [("GET", "https://pypi.org/pypi/multicloud-cli/json", 1)]
|
|
56
|
+
assert pypi["calls"] == [("GET", "https://pypi.org/pypi/multicloud-cli/json", (1, 1))]
|
|
57
57
|
assert json.loads(cache.read_text()) == {"checked_at": 1000.0, "latest": "0.9.0"}
|
|
58
58
|
|
|
59
59
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.13.0"
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"""Every request carries User-Agent: mctl/<version>, and the package has one version."""
|
|
2
|
-
import requests
|
|
3
|
-
|
|
4
|
-
from multicloud_cli import __version__, net
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def test_user_agent_is_added_and_headers_are_kept(monkeypatch):
|
|
8
|
-
seen = {}
|
|
9
|
-
monkeypatch.setattr(requests, "request", lambda m, u, **kw: seen.update(kw) or "r")
|
|
10
|
-
assert net.request("GET", "https://x", headers={"X-API-Key": "k"}, timeout=1) == "r"
|
|
11
|
-
assert seen["headers"] == {"User-Agent": f"mctl/{__version__}", "X-API-Key": "k"}
|
|
12
|
-
net.request("POST", "https://x", data={"a": "b"})
|
|
13
|
-
assert seen["headers"] == {"User-Agent": f"mctl/{__version__}"}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def test_no_module_calls_requests_directly():
|
|
17
|
-
# A direct requests call would skip the User-Agent header; only net.py may make one.
|
|
18
|
-
import pathlib
|
|
19
|
-
import re
|
|
20
|
-
pkg = pathlib.Path(net.__file__).parent
|
|
21
|
-
hits = [f"{p.name}:{i}" for p in sorted(pkg.glob("*.py")) if p.name != "net.py"
|
|
22
|
-
for i, line in enumerate(p.read_text(encoding="utf-8").splitlines(), 1)
|
|
23
|
-
if re.search(r"\brequests\.(request|get|post|put|patch|delete|head|Session)\(", line)]
|
|
24
|
-
assert hits == []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|