Commit 276ecf2
authored
Merge pull request #666 from cderici/improve-constraint-parsing
#666
#### Description
Since the constraints are parsed at the client side, we might as well validate the constraints before sending, instead of relying on the provider's capability of handling invalid constraints. In #661 it is reported that an invalid constraint is not raising an exception on MAAS.
Fixes #661
#### QA Steps
```sh
tox -e py3 -- tests/unit/test_constraints.py
```
or you should see an error when you try to use an invalid constraint (e.g. `root-disk>=16G`)
```sh
Python 3.9.7 (default, Sep 10 2021, 14:59:43)
[GCC 11.2.0] on linux
>>> import juju
>>> import juju.constraints
>>> juju.constraints.parse('tags=scalebot-dev-controller arch=amd64 root-disk>=16G')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/caner/work/cderici/python-libjuju/juju/constraints.py", line 79, in parse
normalized_constraints[normalize_key(k)] = normalize_list_value(v) if\n File "/home/caner/work/cderici/python-libjuju/juju/constraints.py", line 95, in normalize_key
raise Exception("unknown constraint in %s" % orig_key)
Exception: unknown constraint in root-disk>
>>>
```
#### Notes & Discussion
This is fundamentally not the ideal way of handling the constraints, which is also related to https://bugs.launchpad.net/juju/+bug/1645402, however, as long as the clients are responsible for parsing the constraints, it makes sense to avoid any unnecessary api calls due to invalid constraints.2 files changed
Lines changed: 44 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
35 | 54 | | |
36 | 55 | | |
37 | 56 | | |
| |||
51 | 70 | | |
52 | 71 | | |
53 | 72 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
59 | 81 | | |
60 | | - | |
| 82 | + | |
61 | 83 | | |
62 | 84 | | |
63 | | - | |
64 | | - | |
| 85 | + | |
| 86 | + | |
65 | 87 | | |
66 | 88 | | |
67 | 89 | | |
68 | 90 | | |
69 | 91 | | |
70 | 92 | | |
71 | 93 | | |
| 94 | + | |
| 95 | + | |
72 | 96 | | |
73 | 97 | | |
74 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
56 | | - | |
| 58 | + | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| |||
0 commit comments