@@ -150,6 +150,35 @@ def table_pprint(lists_of_items_by_state: dict, ascii: bool = False, colorized:
150
150
print (SingleTable (data , title ).table )
151
151
152
152
153
+ def unexpected_values_pprint (lists_of_items_by_state : dict , ascii : bool = False ):
154
+ """Generate and print a pretty table for output information.
155
+
156
+ Args:
157
+ lists_of_items_by_state (dict of VROElementMetadata[]): A dict of items, stored by
158
+ import state
159
+ ascii (bool): Use ASCII for output or not? Defaults to False.
160
+ colorized (bool, optional): Use color or not?. Defaults to True.
161
+ """
162
+ if not lists_of_items_by_state ['unexpected_values' ]:
163
+ return
164
+ data = []
165
+ title = "Unexpected values in configurationElements"
166
+ # Headers
167
+ data .append (["ID" , "Name" , "Type" , "Package" , "Nb values" ])
168
+ for element in lists_of_items_by_state .get ('unexpected_values' , []):
169
+ data .append ([
170
+ element .id ,
171
+ element .name ,
172
+ element .type ,
173
+ element .version ,
174
+ element .valued_items
175
+ ])
176
+ if ascii :
177
+ print ("\n " + AsciiTable (data , title ).table )
178
+ else :
179
+ print ("\n " + SingleTable (data , title ).table )
180
+
181
+
153
182
def create_diff_file (src_elt : bytes , dst_elt : bytes , src_name : str , dst_name : str , diff_folder : str , state : str ):
154
183
"""Create a diff file between two versions of element data_content.
155
184
@@ -188,7 +217,8 @@ def diff_vro_items(items_src,
188
217
compared_package : str ,
189
218
ascii : bool = False ,
190
219
colorized : bool = True ,
191
- diff_folder : bool = None ):
220
+ diff_folder : bool = None ,
221
+ empty_config : bool = True ):
192
222
"""Compare two vRO items lists.
193
223
194
224
Args:
@@ -205,7 +235,8 @@ def diff_vro_items(items_src,
205
235
'upgrade' : [],
206
236
'conflict' : [],
207
237
'new' : [],
208
- 'unsupported' : []
238
+ 'unsupported' : [],
239
+ 'unexpected_values' : []
209
240
}
210
241
for idst in items_dst :
211
242
found = False
@@ -242,13 +273,17 @@ def diff_vro_items(items_src,
242
273
if (not found ) and (idst .type in SUPPORTED_ELEMENT_TYPES ):
243
274
logger .debug ("%s is NOT IN source package" % idst )
244
275
state = 'new'
276
+ if idst .type == "ConfigurationElement" and empty_config :
277
+ if idst .count_values_from_configuration_elt ():
278
+ lists_of_items_by_state ['unexpected_values' ].append (idst )
245
279
lists_of_items_by_state [state ].append (idst )
246
280
logger .info ("File A: %d elements" % len (items_src ))
247
281
logger .info ("File B: %d elements" % len (items_dst ))
248
282
logger .info ("Items to upgrade:\t \t %d" % len (lists_of_items_by_state ['upgrade' ]))
249
283
logger .info ("Items without upgrade:\t %d" % len (lists_of_items_by_state ['no_upgrade' ]))
250
284
logger .info ("Items in upgrade conflict:\t %d" % len (lists_of_items_by_state ['conflict' ]))
251
285
logger .info ("New items:\t \t \t %d" % len (lists_of_items_by_state ['new' ]))
286
+ logger .info ("ConfigurationElements with values:\t \t \t %d" % len (lists_of_items_by_state ['unexpected_values' ]))
252
287
logger .warning ("Unsupported items:\t \t %d" % len (lists_of_items_by_state ['unsupported' ]))
253
288
total = (
254
289
len (lists_of_items_by_state ['unsupported' ])
@@ -259,25 +294,37 @@ def diff_vro_items(items_src,
259
294
)
260
295
logger .info ("Total items:\t \t \t %s" % total )
261
296
table_pprint (lists_of_items_by_state , ascii = ascii , colorized = colorized )
262
- return len ( lists_of_items_by_state [ 'conflict' ])
297
+ return lists_of_items_by_state
263
298
264
299
265
300
@click .command (context_settings = CLI_CONTEXT_SETTINGS )
266
- @click .option ('-r' ,
267
- '--reference_package' ,
301
+ @click .option ('-r' , '--reference_package' ,
268
302
help = "Reference package to compare your package with." ,
269
303
type = click .File ('rb' ),
270
304
required = True )
271
- @click .argument ('compared_package' , type = click .File ('rb' ))
272
- @click .option ('-l' , '--legend' , is_flag = True , help = "Display the legend after the diff table" )
273
- @click .option ('-t' , '--test' , is_flag = True ,
305
+ @click .argument ('compared_package' ,
306
+ type = click .File ('rb' ))
307
+ @click .option ('-l' , '--legend' ,
308
+ is_flag = True ,
309
+ help = "Display the legend after the diff table" )
310
+ @click .option ('-t' , '--test' ,
311
+ is_flag = True ,
274
312
help = "Exit with `0` if package can be safely imported. Else, returns the number of errors" )
275
- @click .option ('-a' , '--ascii' , is_flag = True , help = "Only use ASCII symbols to display results" )
276
- @click .option ('-b' , '--no_color' , is_flag = True , help = "Do not colorized the output" )
277
- @click .option ('-d' , '--diff' , help = "A folder where to generate unified diff files output" ,
278
- type = click .Path (dir_okay = True , resolve_path = True ))
313
+ @click .option ('-a' , '--ascii' ,
314
+ is_flag = True ,
315
+ help = "Only use ASCII symbols to display results" )
316
+ @click .option ('-b' , '--no_color' ,
317
+ is_flag = True ,
318
+ help = "Do not colorized the output" )
319
+ @click .option ('-d' , '--diff' ,
320
+ type = click .Path (dir_okay = True , resolve_path = True ),
321
+ help = "A folder where to generate unified diff files output" )
322
+ @click .option ('-e' , '--empty-config' ,
323
+ is_flag = True ,
324
+ help = "Check for values in the configuration elements: if so, exit with failure status." )
279
325
def cli (reference_package : str , compared_package : str , legend : bool = False ,
280
- test : bool = False , ascii : bool = False , no_color : bool = False , diff : str = None ):
326
+ test : bool = False , ascii : bool = False , no_color : bool = False , diff : str = None ,
327
+ empty_config : bool = False ):
281
328
"""Compare two vRealize Orchestrator packages.
282
329
283
330
Use the [-r/--reference_package] option to specify the reference package.
@@ -287,7 +334,7 @@ def cli(reference_package: str, compared_package: str, legend: bool = False,
287
334
logger .info ("Reading items from the destination package" )
288
335
vro_items_dst = get_vroitems_from_package (compared_package )
289
336
logger .info ("Starting the comparison of both contents" )
290
- exit_code = diff_vro_items (
337
+ lists_of_items_by_state = diff_vro_items (
291
338
vro_items_src ,
292
339
vro_items_dst ,
293
340
ascii = ascii ,
@@ -302,10 +349,16 @@ def cli(reference_package: str, compared_package: str, legend: bool = False,
302
349
if diff :
303
350
logger .info ("Unified diff files are stored in: %s" % diff )
304
351
print ("Unified diff files are stored in: %s" % diff )
352
+ exit_code = 0
305
353
if test :
306
- logger .info ("Exiting with number of conflicts:" + str (exit_code ))
307
- exit (exit_code )
354
+ logger .info ("Exiting with number of conflicts:" + str (len (lists_of_items_by_state ['conflict' ])))
355
+ exit_code += len (lists_of_items_by_state ['conflict' ])
356
+ if empty_config :
357
+ unexpected_values_pprint (lists_of_items_by_state , ascii = ascii )
358
+ logger .info ("Exiting with number of values in configurationElements" )
359
+ exit_code += len (lists_of_items_by_state ['unexpected_values' ])
308
360
logger .info ("End of execution of the diff tool for vRO packages." )
361
+ exit (exit_code )
309
362
310
363
311
364
def main ():
0 commit comments