Commit 03332e6
authored
Merge pull request #974 from jack-w-shaw/JUJU-4779_parse_local_charms_properly-master
#974
Port forward #969
Parse charm URLs consistantly for local charms
Local charm URLs are confused in pylibjuju because often a charm
url-like string is passed into deploy, to explicitly specify a local
charm. These 'urls' were of the form 'local:/path/to/charm'
Local URLs were parsed accordingly.
However, the above is in no sense a url really so should be treated as
such. This also means that pylibjuju is unable to parse real local charm
urls returned to the client from the server when, say, uploading a local
charm.
Drop support for local charms like this. Instead parse local charm urls the
same way we parse charmhub charm url.
This has the side-effect, however, that we can no longer treat all
objects to deploy as URLs. Now, they are either URLs (ch or cs charms)
or paths or paths prepended with 'local:' (local charms)
As such, in deploy code and refresh code, we often need to branch on
is_local_charm. This is to ensure we don't attempt to parse paths as
URLs. Everywhere we URL.parse user input, we ensure the entity is not a
path
This resolves #961
#### QA Steps
```
tox -e unit -- tests/unit/test_url.py
```
```
tox -e integration -- tests/integration/test_model.py::test_deploy_local_bundle_dir
tox -e integration -- tests/integration/test_model.py::test_deploy_local_bundle_file
tox -e integration -- tests/integration/test_model.py::test_deploy_bundle_local_charms
tox -e integration -- tests/integration/test_model.py::test_deploy_local_charm
```
All CI tests need to pass.
(In a python interpreter)
```
>>> from juju.url import URL
>>> u = URL.parse("local:focal/ubuntu-12")
>>> print(u.name)
ubuntu
>>> print(u.revision)
12
>>> URL.parse("local:/path/to/charm")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jack/juju/python-libjuju/juju/url.py", line 50, in parse
c = parse_v2_url(u, s, default_store)
File "/home/jack/juju/python-libjuju/juju/url.py", line 138, in parse_v2_url
raise JujuError("charm or bundle URL {} malformed".format(s))
juju.errors.JujuError: charm or bundle URL local:/path/to/charm malformed
```
Ensure the example scripts still function
```
$ python examples/deploy_bundle.py
$ python examples/deploy_local_bundle_with_resources.py
```
Verify the following example script runs successfully:
```
from juju import jasyncio
from juju.model import Model
async def main():
model = Model()
print('Connecting to model')
await model.connect()
try:
print('path="/home/jack/charms/ubuntu"')
await depl(model, path="/home/jack/charms/ubuntu")
print('switch="/home/jack/charms/ubuntu"')
await depl(model, switch="/home/jack/charms/ubuntu")
print('switch="local:/home/jack/charms/ubuntu"')
await depl(model, switch="local:/home/jack/charms/ubuntu")
finally:
print('Disconnecting from model')
await model.disconnect()
async def depl(model, **kwargs):
try:
app = await model.deploy("ubuntu")
await model.block_until(lambda: all(u[0].workload_status == 'active' for u in app.units))
await app.refresh(**kwargs)
finally:
await app.remove()
await model.block_until(lambda: not len(model.applications))
if __name__ == '__main__':
jasyncio.run(main())
```4 files changed
Lines changed: 133 additions & 86 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | | - | |
250 | 248 | | |
251 | 249 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
258 | 255 | | |
259 | | - | |
260 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
261 | 263 | | |
262 | 264 | | |
263 | 265 | | |
| |||
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
287 | | - | |
| 289 | + | |
288 | 290 | | |
289 | 291 | | |
290 | 292 | | |
| |||
295 | 297 | | |
296 | 298 | | |
297 | 299 | | |
298 | | - | |
| 300 | + | |
299 | 301 | | |
300 | 302 | | |
301 | 303 | | |
| |||
389 | 391 | | |
390 | 392 | | |
391 | 393 | | |
392 | | - | |
393 | 394 | | |
394 | 395 | | |
395 | 396 | | |
| |||
443 | 444 | | |
444 | 445 | | |
445 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
446 | 462 | | |
447 | 463 | | |
448 | 464 | | |
| |||
676 | 692 | | |
677 | 693 | | |
678 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
679 | 698 | | |
680 | 699 | | |
681 | 700 | | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | 701 | | |
686 | 702 | | |
687 | 703 | | |
| |||
700 | 716 | | |
701 | 717 | | |
702 | 718 | | |
703 | | - | |
| 719 | + | |
704 | 720 | | |
705 | 721 | | |
706 | 722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
| 453 | + | |
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | | - | |
465 | | - | |
466 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
467 | 469 | | |
468 | | - | |
469 | 470 | | |
470 | 471 | | |
471 | 472 | | |
472 | 473 | | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
| 474 | + | |
477 | 475 | | |
478 | 476 | | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
491 | 482 | | |
492 | 483 | | |
493 | | - | |
| 484 | + | |
494 | 485 | | |
495 | 486 | | |
496 | 487 | | |
| |||
541 | 532 | | |
542 | 533 | | |
543 | 534 | | |
544 | | - | |
| 535 | + | |
545 | 536 | | |
546 | 537 | | |
547 | 538 | | |
| |||
591 | 582 | | |
592 | 583 | | |
593 | 584 | | |
594 | | - | |
595 | | - | |
| 585 | + | |
| 586 | + | |
596 | 587 | | |
597 | 588 | | |
598 | 589 | | |
| |||
1670 | 1661 | | |
1671 | 1662 | | |
1672 | 1663 | | |
1673 | | - | |
| 1664 | + | |
1674 | 1665 | | |
1675 | 1666 | | |
1676 | 1667 | | |
| |||
1716 | 1707 | | |
1717 | 1708 | | |
1718 | 1709 | | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
1722 | 1716 | | |
1723 | | - | |
1724 | | - | |
1725 | 1717 | | |
1726 | | - | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
1727 | 1723 | | |
1728 | | - | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
1729 | 1727 | | |
1730 | | - | |
1731 | | - | |
| 1728 | + | |
| 1729 | + | |
1732 | 1730 | | |
1733 | 1731 | | |
1734 | | - | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
1738 | | - | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
1739 | 1737 | | |
1740 | 1738 | | |
1741 | 1739 | | |
| |||
1750 | 1748 | | |
1751 | 1749 | | |
1752 | 1750 | | |
1753 | | - | |
| 1751 | + | |
1754 | 1752 | | |
1755 | 1753 | | |
1756 | 1754 | | |
| |||
1778 | 1776 | | |
1779 | 1777 | | |
1780 | 1778 | | |
1781 | | - | |
1782 | | - | |
| 1779 | + | |
1783 | 1780 | | |
1784 | 1781 | | |
1785 | 1782 | | |
| |||
1793 | 1790 | | |
1794 | 1791 | | |
1795 | 1792 | | |
1796 | | - | |
| 1793 | + | |
1797 | 1794 | | |
1798 | 1795 | | |
1799 | 1796 | | |
| |||
1879 | 1876 | | |
1880 | 1877 | | |
1881 | 1878 | | |
1882 | | - | |
| 1879 | + | |
1883 | 1880 | | |
1884 | 1881 | | |
1885 | 1882 | | |
| |||
1919 | 1916 | | |
1920 | 1917 | | |
1921 | 1918 | | |
1922 | | - | |
| 1919 | + | |
1923 | 1920 | | |
1924 | | - | |
| 1921 | + | |
1925 | 1922 | | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
1926 | 1926 | | |
1927 | 1927 | | |
1928 | 1928 | | |
1929 | 1929 | | |
1930 | | - | |
1931 | | - | |
| 1930 | + | |
1932 | 1931 | | |
1933 | 1932 | | |
1934 | 1933 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 46 | + | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | | - | |
| 50 | + | |
53 | 51 | | |
54 | 52 | | |
55 | 53 | | |
| |||
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
124 | | - | |
125 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
| |||
0 commit comments