Skip to content

Commit 6d4af2c

Browse files
Change filter spec
Signed-off-by: Stew Francis <[email protected]> So mutually exclusive and required one of isn't applied to the last node which doesn't have `and` and `or` nodes. Remove corresponding ignores from sanity tests, and add ignores for new required nodes that aren't in the deep part of the spec
1 parent e561457 commit 6d4af2c

File tree

2 files changed

+67
-69
lines changed

2 files changed

+67
-69
lines changed

plugins/module_utils/cmci.py

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -48,73 +48,75 @@
4848

4949
GET_PARAMETERS = 'get_parameters'
5050

51-
ATTRIBUTE_ARGUMENTS = {
52-
'attribute': {
53-
'type': 'str',
54-
'required': False
55-
},
56-
'operator': {
57-
'type': 'str',
58-
'required': False,
59-
'default': 'EQ',
60-
'choices': ['<', '<=', '=', '>', '>=', '¬=', '==', '!=', 'EQ', 'NE',
61-
'LT', 'LE', 'GE', 'GT', 'IS']
62-
},
63-
'value': {
64-
'type': 'str',
65-
'required': False
66-
}
67-
}
68-
69-
70-
def _cf_child(children): # type: (dict[str, Any]) -> dict[str, Any]
71-
return {
72-
'required': False,
73-
'required_together': [('attribute', 'value')],
74-
'required_one_of': [('attribute', 'and', 'or')],
75-
'mutually_exclusive': [('attribute', 'and', 'or'),
76-
('and', 'operator'),
77-
('and', 'value'),
78-
('or', 'operator'),
79-
('or', 'value')
80-
],
81-
'options': children
82-
}
83-
84-
85-
def _cf_options(children):
86-
basic_list_dict = {
87-
'type': 'list',
88-
'elements': 'dict',
89-
}
9051

91-
# These warnings are a PyCharm bug:
92-
# https://youtrack.jetbrains.com/issue/PY-43664
93-
and_list = {'and': dict(
94-
chain(basic_list_dict.items(), _cf_child(children).items())
95-
)}
96-
or_list = {'or': dict(
97-
chain(basic_list_dict.items(), _cf_child(children).items())
98-
)}
99-
return dict(
100-
chain(ATTRIBUTE_ARGUMENTS.items(), and_list.items(), or_list.items())
101-
)
52+
def _attribute_arguments(required):
53+
return [
54+
('attribute', {
55+
'type': 'str',
56+
'required': required
57+
}),
58+
('operator', {
59+
'type': 'str',
60+
'required': False,
61+
'default': 'EQ',
62+
'choices': ['<', '<=', '=', '>', '>=', '¬=', '==', '!=', 'EQ', 'NE',
63+
'LT', 'LE', 'GE', 'GT', 'IS']
64+
}),
65+
('value', {
66+
'type': 'str',
67+
'required': required
68+
})
69+
]
70+
71+
72+
def _cf_node(options): # type: ([(str, Any)]) -> [(str, Any)]
73+
74+
sub = dict(chain(
75+
options,
76+
[
77+
('type', 'list'),
78+
('elements', 'dict')
79+
]
80+
))
81+
82+
return [
83+
('required', False),
84+
('required_together', [
85+
('attribute', 'value')
86+
]),
87+
('required_one_of', [
88+
('attribute', 'and', 'or')
89+
]),
90+
('mutually_exclusive', [
91+
('attribute', 'and', 'or'),
92+
('and', 'operator'),
93+
('and', 'value'),
94+
('or', 'operator'),
95+
('or', 'value')
96+
]),
97+
('options', dict(chain(
98+
_attribute_arguments(False),
99+
[
100+
('and', sub),
101+
('or', sub)
102+
]
103+
)))
104+
]
102105

103106

104107
def _complex_filter():
105-
children = _cf_child(
106-
_cf_options(
107-
_cf_options(
108-
_cf_options(
109-
ATTRIBUTE_ARGUMENTS
108+
return dict(chain(
109+
_cf_node(
110+
_cf_node(
111+
_cf_node(
112+
_cf_node([
113+
('options', dict(_attribute_arguments(True)))
114+
])
110115
)
111116
)
112-
)
113-
)
114-
base_type = {'type': 'dict'}
115-
# This warning is a PyCharm bug:
116-
# https://youtrack.jetbrains.com/issue/PY-43664
117-
return dict(chain(children.items(), base_type.items()))
117+
),
118+
[('type', 'dict')]
119+
))
118120

119121

120122
def parameters_argument(name): # type: (str) -> Dict[str, Any]

tests/sanity/ignore-2.10.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ plugins/modules/cmci_get.py validate-modules:missing-suboption-docs # We have a
66
plugins/modules/cmci_get.py validate-modules:parameter-type-not-in-doc # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
77
plugins/modules/cmci_get.py validate-modules:undocumented-parameter # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
88
plugins/modules/cmci_get.py validate-modules:doc-elements-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
9-
plugins/modules/cmci_get.py validate-modules:mutually_exclusive-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
10-
plugins/modules/cmci_get.py validate-modules:required_one_of-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
9+
plugins/modules/cmci_get.py validate-modules:doc-required-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
1110
plugins/modules/cmci_action.py validate-modules:missing-gplv3-license # Licence is Apache-2.0
1211
plugins/modules/cmci_action.py validate-modules:doc-choices-do-not-match-spec # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
1312
plugins/modules/cmci_action.py validate-modules:doc-default-does-not-match-spec # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
1413
plugins/modules/cmci_action.py validate-modules:missing-suboption-docs # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
1514
plugins/modules/cmci_action.py validate-modules:parameter-type-not-in-doc # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
1615
plugins/modules/cmci_action.py validate-modules:undocumented-parameter # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
1716
plugins/modules/cmci_action.py validate-modules:doc-elements-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
18-
plugins/modules/cmci_action.py validate-modules:mutually_exclusive-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
19-
plugins/modules/cmci_action.py validate-modules:required_one_of-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
17+
plugins/modules/cmci_action.py validate-modules:doc-required-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
2018
plugins/modules/cmci_create.py validate-modules:missing-gplv3-license # Licence is Apache-2.0
2119
plugins/modules/cmci_delete.py validate-modules:missing-gplv3-license # Licence is Apache-2.0
2220
plugins/modules/cmci_delete.py validate-modules:doc-choices-do-not-match-spec # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
@@ -25,14 +23,12 @@ plugins/modules/cmci_delete.py validate-modules:missing-suboption-docs # We have
2523
plugins/modules/cmci_delete.py validate-modules:parameter-type-not-in-doc # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
2624
plugins/modules/cmci_delete.py validate-modules:undocumented-parameter # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
2725
plugins/modules/cmci_delete.py validate-modules:doc-elements-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
28-
plugins/modules/cmci_delete.py validate-modules:mutually_exclusive-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
29-
plugins/modules/cmci_delete.py validate-modules:required_one_of-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
26+
plugins/modules/cmci_delete.py validate-modules:doc-required-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
3027
plugins/modules/cmci_update.py validate-modules:missing-gplv3-license # Licence is Apache-2.0
3128
plugins/modules/cmci_update.py validate-modules:doc-choices-do-not-match-spec # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
3229
plugins/modules/cmci_update.py validate-modules:doc-default-does-not-match-spec # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
3330
plugins/modules/cmci_update.py validate-modules:missing-suboption-docs # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
3431
plugins/modules/cmci_update.py validate-modules:parameter-type-not-in-doc # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
3532
plugins/modules/cmci_update.py validate-modules:undocumented-parameter # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
3633
plugins/modules/cmci_update.py validate-modules:doc-elements-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
37-
plugins/modules/cmci_update.py validate-modules:mutually_exclusive-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
38-
plugins/modules/cmci_update.py validate-modules:required_one_of-unknown # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error
34+
plugins/modules/cmci_update.py validate-modules:doc-required-mismatch # We have a complex_filter DSL as part of our plugin YAML. The same config is accepted 4 levels deep. We only include the (quite long) documentation for this at the highest level, which causes this error

0 commit comments

Comments
 (0)