Skip to content

Commit 464164d

Browse files
committed
fix version regex and api_version formatting to prevent filtering out valid APIs
1 parent 604f676 commit 464164d

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

openshift/ansiblegen/modules.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def __get_models_for_package(model_package, api_version, requested_models):
5353
continue
5454
model_api = matches.group(0)
5555
base_model_name = model.replace(model_api, '')
56-
model_name_snake = string_utils.camel_case_to_snake(base_model_name)
56+
model_name_snake = string_utils.camel_case_to_snake(base_model_name).lower()
57+
model_api_snake = string_utils.camel_case_to_snake(model_api).lower()
5758
if requested_models and \
5859
base_model_name not in requested_models and \
5960
model_name_snake not in requested_models:
@@ -64,13 +65,15 @@ def __get_models_for_package(model_package, api_version, requested_models):
6465
models.append({
6566
'model': model,
6667
'model_api': model_api,
68+
'model_api_snake': model_api_snake,
6769
'base_model_name': base_model_name,
6870
'model_name_snake': model_name_snake
6971
})
7072
else:
7173
models.append({
7274
'model': model,
7375
'model_api': model_api,
76+
'model_api_snake': model_api_snake,
7477
'base_model_name': base_model_name,
7578
'model_name_snake': model_name_snake
7679
})
@@ -102,18 +105,18 @@ def __generate_modules_impl(cls, models, prefix, output_path):
102105
temp_dir = os.path.realpath(tempfile.mkdtemp()) # jinja temp dir
103106
for model in models:
104107
module_name = "{}_{}_{}.py".format(prefix,
105-
model['model_api'].lower(),
108+
model['model_api_snake'],
106109
model['model_name_snake'])
107110
if prefix == 'openshift':
108-
docs = OpenShiftDocStrings(model['model_name_snake'], model['model_api'])
111+
docs = OpenShiftDocStrings(model['model_name_snake'], model['model_api_snake'])
109112
else:
110-
docs = KubernetesDocStrings(model['model_name_snake'], model['model_api'])
113+
docs = KubernetesDocStrings(model['model_name_snake'], model['model_api_snake'])
111114
context = {
112115
'documentation_string': docs.documentation,
113116
'return_string': docs.return_block,
114117
'examples_string': docs.examples,
115118
'kind': model['model_name_snake'],
116-
'api_version': model['model_api']
119+
'api_version': model['model_api_snake']
117120
}
118121
template_file = prefix + '_module.j2'
119122
cls.__jinja_render_to_file(JINJA2_TEMPLATE_PATH, template_file,

openshift/helper/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
import re
55

66
PRIMITIVES = ('str', 'int', 'bool', 'float', 'IntstrIntOrString')
7-
VERSION_RX = re.compile("V\d((alpha|beta)\d)?")
7+
VERSION_RX = re.compile(".*V\d((alpha|beta)\d)?")

openshift/helper/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,12 @@ def get_model(self, api_version, kind):
484484
:return: class
485485
"""
486486
camel_kind = string_utils.snake_case_to_camel(kind)
487+
camel_api_version = string_utils.snake_case_to_camel(api_version)
487488
# capitalize the first letter of the string without lower-casing the remainder
488-
name = camel_kind[:1].capitalize() + camel_kind[1:]
489-
name = name.replace("Api", "API")
490-
model_name = api_version.capitalize() + name
489+
name = (camel_kind[:1].capitalize() + camel_kind[1:]).replace("Api", "API")
490+
api = camel_api_version[:1].capitalize() + camel_api_version[1:]
491+
492+
model_name = api + name
491493
try:
492494
model = self.model_class_from_name(model_name)
493495
except AttributeError:

scripts/from_gen/preprocess_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def main():
289289

290290

291291
import re
292-
VERSION_RX = re.compile("V\d((alpha|beta)\d)?")
292+
VERSION_RX = re.compile(".*V\d((alpha|beta)\d)?")
293293

294294
DEFAULT_CODEGEN_IGNORE_LINES = {
295295
".gitignore",

scripts/preprocess_spec.py.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
VERSION_RX = re.compile("V\d((alpha|beta)\d)?")
2+
VERSION_RX = re.compile(".*V\d((alpha|beta)\d)?")
33

44
DEFAULT_CODEGEN_IGNORE_LINES = {
55
".gitignore",

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ commands =
4040
/bin/bash update-client.sh
4141

4242
[testenv:update_ansible]
43+
deps =
44+
-rrequirements.txt
4345
commands =
4446
openshift-ansible-gen modules {posargs}
4547

0 commit comments

Comments
 (0)