8
8
from oracle .weblogic .deploy .util import PyOrderedDict
9
9
10
10
from wlsdeploy .aliases .model_constants import KUBERNETES
11
- from wlsdeploy .tool .extract import domain_resource_extractor
12
11
from wlsdeploy .tool .extract import wko_schema_helper
13
- from wlsdeploy .util import dictionary_utils
14
12
15
13
16
14
class KubernetesSchemaTest (unittest .TestCase ):
@@ -31,93 +29,78 @@ def tearDown(self):
31
29
def testKubernetesSchema (self ):
32
30
# create a model with every element.
33
31
# verify that there are no unknown types or structures.
34
- self ._write_folder (self .schema_map , "" , False , "" , "" )
35
-
36
- def _write_folder (self , folder , name , is_multiple , path , indent ):
37
- label = name
38
- if not label :
39
- label = KUBERNETES
40
-
41
- if wko_schema_helper .is_unsupported_folder (path ):
42
- self ._write_line ("\n " + indent + "# " + label + ": (unsupported folder)" )
43
- return
44
-
45
- self ._write_line ("\n " + indent + label + ":" )
46
- indent = indent + " "
47
-
48
- properties = wko_schema_helper .get_properties (folder )
49
-
50
- multi_key = None
32
+ self ._write_line (KUBERNETES + ":" )
33
+ self ._write_folder (self .schema_map , False , "" , " " )
34
+
35
+ def _write_folder (self , folder , is_multiple , path , indent ):
36
+ # for a multiple (object list) type, the first field is prefixed with a hyphen
37
+ plain_indent = indent
38
+ hyphen_indent = indent [:- 2 ] + "- "
39
+ this_indent = plain_indent
51
40
if is_multiple :
52
- mapped_key = domain_resource_extractor .get_mapped_key (path )
53
- multi_property = dictionary_utils .get_element (properties , mapped_key )
54
- if multi_property :
55
- multi_key = mapped_key
56
- comment = 'maps to ' + multi_key
57
- else :
58
- comment = 'unique key for each'
59
-
60
- self ._write_line (indent + "'" + name + "-1': # " + comment )
61
- indent = indent + " "
41
+ this_indent = hyphen_indent
62
42
43
+ properties = wko_schema_helper .get_properties (folder )
63
44
property_names = list (properties .keys ())
64
45
property_names .sort ()
65
46
66
47
sub_folders = PyOrderedDict ()
67
48
multi_sub_folders = []
68
49
for property_name in property_names :
69
50
property_map = properties [property_name ]
70
-
71
- property_type = dictionary_utils .get_element (property_map , "type" )
72
-
73
- if property_type in wko_schema_helper .OBJECT_TYPES :
74
- additional = dictionary_utils .get_dictionary_element (property_map , "additionalProperties" )
75
- additional_type = dictionary_utils .get_element (additional , "type" )
76
- if additional_type :
77
- if additional_type not in wko_schema_helper .SIMPLE_TYPES :
78
- self .fail ('Unknown map type ' + additional_type + ' for ' + path + ' ' + property_name )
79
- nest_indent = indent + " "
80
- self ._write_line (indent + property_name + ":" )
81
- self ._write_line (nest_indent + "'key-1': " + _get_sample_value (additional_type ))
82
- self ._write_line (nest_indent + "'key-2': " + _get_sample_value (additional_type ))
83
- else :
84
- # single object instance
85
- sub_folders [property_name ] = property_map
86
-
87
- elif property_type == "array" :
88
- array_items = dictionary_utils .get_dictionary_element (property_map , "items" )
89
- array_type = dictionary_utils .get_element (array_items , "type" )
90
- if array_type in wko_schema_helper .OBJECT_TYPES :
91
- # multiple object instances
92
- sub_folders [property_name ] = array_items
93
- multi_sub_folders .append (property_name )
94
- elif array_type in wko_schema_helper .SIMPLE_TYPES :
95
- nest_indent = indent + " "
96
- self ._write_line (indent + property_name + ": [" )
97
- self ._write_line (nest_indent + _get_sample_value (array_type ) + "," )
98
- self ._write_line (nest_indent + _get_sample_value (array_type ))
99
- self ._write_line (indent + "]" )
100
- else :
101
- self .fail ('Unknown array type ' + array_type + ' for ' + path + ' ' + property_name )
102
-
103
- elif property_type in wko_schema_helper .SIMPLE_TYPES :
104
- if property_name != multi_key :
105
- value = _get_sample_value (property_type )
106
- enum_values = wko_schema_helper .get_enum_values (property_map )
107
- if enum_values :
108
- value = "'" + enum_values [0 ] + "' # " + ', ' .join (enum_values )
109
- self ._write_line (indent + str (property_name ) + ": " + value )
51
+ property_type = wko_schema_helper .get_type (property_map )
52
+
53
+ if wko_schema_helper .is_simple_map (property_map ):
54
+ additional_type = wko_schema_helper .get_map_element_type (property_map )
55
+ if additional_type not in wko_schema_helper .SIMPLE_TYPES :
56
+ self .fail ('Unknown map type ' + additional_type + ' for ' + path + ' ' + property_name )
57
+ self ._write_line (this_indent + property_name + ":" )
58
+ this_indent = plain_indent
59
+ nest_indent = this_indent + " "
60
+ self ._write_line (nest_indent + "'key-1': " + _get_sample_value (additional_type ))
61
+ self ._write_line (nest_indent + "'key-2': " + _get_sample_value (additional_type ))
62
+
63
+ elif wko_schema_helper .is_single_object (property_map ):
64
+ # single object instance
65
+ sub_folders [property_name ] = property_map
66
+
67
+ elif wko_schema_helper .is_object_array (property_map ):
68
+ array_items = wko_schema_helper .get_array_item_info (property_map )
69
+ sub_folders [property_name ] = array_items
70
+ multi_sub_folders .append (property_name )
71
+
72
+ elif wko_schema_helper .is_simple_array (property_map ):
73
+ array_type = wko_schema_helper .get_array_element_type (property_map )
74
+ self ._write_line (this_indent + property_name + ":" )
75
+ this_indent = plain_indent
76
+ each_indent = this_indent + "- "
77
+ self ._write_line (each_indent + _get_sample_value (array_type ))
78
+ self ._write_line (each_indent + _get_sample_value (array_type ))
79
+
80
+ elif wko_schema_helper .is_simple_type (property_map ):
81
+ value = _get_sample_value (property_type )
82
+ enum_values = wko_schema_helper .get_enum_values (property_map )
83
+ if enum_values :
84
+ value = "'" + enum_values [0 ] + "' # " + ', ' .join (enum_values )
85
+ self ._write_line (this_indent + str (property_name ) + ": " + value )
86
+ this_indent = plain_indent
110
87
111
88
else :
112
89
self .fail ('Unknown property type ' + str (property_type ) + ' for ' + str (path ) + ' '
113
90
+ str (property_name ))
114
91
115
92
# process sub-folders after attributes for clarity
116
93
for property_name in sub_folders :
117
- subfolder = sub_folders [property_name ]
118
- is_multiple = property_name in multi_sub_folders
119
94
next_path = wko_schema_helper .append_path (path , property_name )
120
- self ._write_folder (subfolder , property_name , is_multiple , next_path , indent )
95
+ if wko_schema_helper .is_unsupported_folder (next_path ):
96
+ self ._write_line (indent + "# " + property_name + ": (unsupported folder)" )
97
+ else :
98
+ self ._write_line (this_indent + property_name + ":" )
99
+ this_indent = plain_indent
100
+ subfolder = sub_folders [property_name ]
101
+ is_multiple = property_name in multi_sub_folders
102
+ child_indent = this_indent + " "
103
+ self ._write_folder (subfolder , is_multiple , next_path , child_indent )
121
104
122
105
def _write_line (self , text ):
123
106
self .out_file .write (text + "\n " )
0 commit comments