@@ -309,9 +309,8 @@ def call_automate(obj_type, obj_id, open_url_task_id = nil)
309
309
310
310
it "will process an array of objects with a server and user" do
311
311
extras = "MiqServer%3A%3Amiq_server=12"
312
- FactoryBot . create ( :small_environment )
313
- attrs = { "MiqServer::miq_server" => "12" , "array::tag" => "Classification::1,Classification::2" }
314
- result_str = "array%3A%3Atag=Classification%3A%3A1%2CClassification%3A%3A2"
312
+ attrs = { "MiqServer::miq_server" => "12" , "Array::tags" => [ "Classification::1,Classification::2" ] }
313
+ result_str = "TagArray%3A%3Atags=Classification%3A%3A1%2CClassification%3A%3A2"
315
314
uri = "/System/Process/AUTOMATION?#{ extras } &#{ result_str } &object_name=AUTOMATION"
316
315
expect ( MiqAeEngine . create_automation_object ( "AUTOMATION" , attrs ) ) . to eq ( uri )
317
316
end
@@ -375,20 +374,22 @@ def call_automate(obj_type, obj_id, open_url_task_id = nil)
375
374
end
376
375
377
376
it "with an array of Vms" do
378
- result_arr = [ ]
379
377
hash = { "vms" => Vm . all }
380
- result_str = "vms=#{ hash [ "vms" ] . collect { |v | v . id . to_s } . join ( "=" ) } "
381
- hash [ "vms" ] . collect { |v | result_arr . push ( v . id . to_s ) }
378
+ result_str = "vms=#{ hash [ "vms" ] . collect { |v | "ManageIQ::Providers::Vmware::InfraManager::Vm::#{ v . id } " } . join ( "=" ) } "
382
379
result = MiqAeEngine . create_automation_attributes ( hash )
380
+ result_arr = if hash [ "vms" ] . length == 1
381
+ "ManageIQ::Providers::Vmware::InfraManager::Vm::#{ hash [ "vms" ] [ 0 ] . id } "
382
+ else
383
+ hash [ "vms" ] . collect { |v | "ManageIQ::Providers::Vmware::InfraManager::Vm::#{ v . id } " }
384
+ end
383
385
expect ( MiqAeEngine . create_automation_attributes_string ( hash ) ) . to eq ( result_str )
384
386
expect ( result [ "vms" ] ) . to eq ( result_arr )
385
387
end
386
388
387
389
it "with an array containing a single Vm" do
388
- result_arr = [ ]
389
390
hash = { "vms" => [ Vm . first ] }
390
- result_str = "vms=#{ hash [ "vms" ] . collect { |v | v . id . to_s } . join ( "=" ) } "
391
- hash [ "vms" ] . collect { | v | result_arr . push ( v . id . to_s ) }
391
+ result_str = "vms=#{ hash [ "vms" ] . collect { |v | "ManageIQ::Providers::Vmware::InfraManager::Vm:: #{ v . id } " } . join ( "=" ) } "
392
+ result_arr = "ManageIQ::Providers::Vmware::InfraManager::Vm:: #{ hash [ "vms" ] [ 0 ] . id } "
392
393
result = MiqAeEngine . create_automation_attributes ( hash )
393
394
expect ( MiqAeEngine . create_automation_attributes_string ( hash ) ) . to eq ( result_str )
394
395
expect ( result [ "vms" ] ) . to eq ( result_arr )
@@ -408,24 +409,33 @@ def call_automate(obj_type, obj_id, open_url_task_id = nil)
408
409
end
409
410
410
411
it "with an array of Hosts" do
411
- result_arr = [ ]
412
412
hash = { "hosts" => Host . all }
413
- result_str = "hosts=#{ hash [ "hosts" ] . collect { |h | h . id . to_s } . join ( "=" ) } "
414
- hash [ "hosts" ] . collect { |h | result_arr . push ( h . id . to_s ) }
413
+ result_str = "hosts=#{ hash [ "hosts" ] . collect { |h | "Host::#{ h . id } " } . join ( "=" ) } "
414
+ result_arr = if hash [ "hosts" ] . length == 1
415
+ "Host::#{ hash [ "hosts" ] [ 0 ] . id } "
416
+ else
417
+ hash [ "hosts" ] . collect { |h | "Host::#{ h . id } " }
418
+ end
415
419
result = MiqAeEngine . create_automation_attributes ( hash )
416
420
expect ( MiqAeEngine . create_automation_attributes_string ( hash ) ) . to eq ( result_str )
417
421
expect ( result [ "hosts" ] ) . to eq ( result_arr )
418
422
end
419
423
420
424
it "with multiple arrays" do
421
- vm_result_arr = [ ]
422
- host_result_arr = [ ]
423
425
hash = { "vms" => Vm . all }
424
- vm_result_str = "vms=#{ hash [ "vms" ] . collect { |v | v . id . to_s } . join ( "=" ) } "
425
- hash [ "vms" ] . collect { |v | vm_result_arr . push ( v . id . to_s ) }
426
+ vm_result_str = "vms=#{ hash [ "vms" ] . collect { |v | "ManageIQ::Providers::Vmware::InfraManager::Vm::#{ v . id } " } . join ( "=" ) } "
427
+ vm_result_arr = if hash [ "vms" ] . length == 1
428
+ "ManageIQ::Providers::Vmware::InfraManager::Vm::#{ hash [ "vms" ] [ 0 ] . id } "
429
+ else
430
+ hash [ "vms" ] . collect { |v | "ManageIQ::Providers::Vmware::InfraManager::Vm::#{ v . id } " }
431
+ end
426
432
hash [ "hosts" ] = Host . all
427
- host_result_str = "hosts=#{ hash [ "hosts" ] . collect { |h | h . id . to_s } . join ( "=" ) } "
428
- hash [ "hosts" ] . collect { |h | host_result_arr . push ( h . id . to_s ) }
433
+ host_result_str = "hosts=#{ hash [ "hosts" ] . collect { |h | "Host::#{ h . id } " } . join ( "=" ) } "
434
+ host_result_arr = if hash [ "hosts" ] . length == 1
435
+ "Host::#{ hash [ "hosts" ] [ 0 ] . id } "
436
+ else
437
+ hash [ "hosts" ] . collect { |h | "Host#{ h . id } " }
438
+ end
429
439
result = MiqAeEngine . create_automation_attributes ( hash )
430
440
expect ( result [ "vms" ] ) . to eq ( vm_result_arr )
431
441
expect ( result [ "hosts" ] ) . to eq ( host_result_arr )
@@ -434,16 +444,32 @@ def call_automate(obj_type, obj_id, open_url_task_id = nil)
434
444
expect ( result_str ) . to include ( host_result_str )
435
445
end
436
446
447
+ it "with an array of Tags" do
448
+ FactoryBot . create ( :classification )
449
+ FactoryBot . create ( :classification )
450
+ FactoryBot . create ( :classification )
451
+ hash = { "tags" => Classification . all }
452
+ result_str = "tags=#{ hash [ "tags" ] . collect { |h | "Classification::#{ h . id } " } . join ( "=" ) } "
453
+ result_arr = if hash [ "tags" ] . length == 1
454
+ "Classification::#{ hash [ "tags" ] [ 0 ] . id } "
455
+ else
456
+ hash [ "tags" ] . collect { |h | "Classification::#{ h . id } " }
457
+ end
458
+ result = MiqAeEngine . create_automation_attributes ( hash )
459
+ expect ( MiqAeEngine . create_automation_attributes_string ( hash ) ) . to eq ( result_str )
460
+ expect ( result [ "tags" ] ) . to eq ( result_arr )
461
+ end
462
+
437
463
it "with invalid object references" do
438
464
hash = { "vms" => [ "bogus::12" ] }
439
465
result = MiqAeEngine . create_automation_attributes ( hash )
440
- expect ( result [ "vms" ] ) . to eq ( [ "bogus::12" ] )
466
+ expect ( result [ "vms" ] ) . to eq ( "bogus::12" )
441
467
expect ( MiqAeEngine . create_automation_attributes_string ( hash ) ) . to eq ( "vms=bogus::12" )
442
468
end
443
469
444
470
it "with garbage values" do
445
471
hash = { "vms" => [ "bogus::12,garbage::moreso,notevenclose" ] }
446
- bogus_arr = [ "bogus::12,garbage::moreso,notevenclose" ]
472
+ bogus_arr = "bogus::12,garbage::moreso,notevenclose"
447
473
result = MiqAeEngine . create_automation_attributes ( hash )
448
474
expect ( result [ "vms" ] ) . to eq ( bogus_arr )
449
475
expect ( MiqAeEngine . create_automation_attributes_string ( hash ) ) . to eq ( "vms=bogus::12,garbage::moreso,notevenclose" )
@@ -789,6 +815,28 @@ def call_automate(obj_type, obj_id, open_url_task_id = nil)
789
815
my_objects_array . each { |o | o . kind_of? ( MiqAeMethodService ::MiqAeServiceModelBase ) }
790
816
end
791
817
818
+ it "processes tags array arguments properly" do
819
+ tag1 = FactoryBot . create ( :classification )
820
+ tag2 = FactoryBot . create ( :classification )
821
+ tag3 = FactoryBot . create ( :classification )
822
+
823
+ EvmSpecHelper . import_yaml_model ( File . join ( model_data_dir , "miq_ae_engine_spec5" ) , domain )
824
+ ws = MiqAeEngine . instantiate ( "/EVM/AUTOMATE/test1?TagArray::my_objects=Classification::#{ tag1 . id } \x1F Classification::#{ tag2 . id } \x1F Classification::#{ tag3 . id } " , user )
825
+ my_objects_array = ws . root ( "my_objects" )
826
+ expect ( my_objects_array . length ) . to eq ( 3 )
827
+ my_objects_array . each { |o | o . kind_of? ( MiqAeMethodService ::MiqAeServiceModelBase ) }
828
+ end
829
+
830
+ it "processes tags array with a single value arguments properly" do
831
+ tag1 = FactoryBot . create ( :classification )
832
+
833
+ EvmSpecHelper . import_yaml_model ( File . join ( model_data_dir , "miq_ae_engine_spec5" ) , domain )
834
+ ws = MiqAeEngine . instantiate ( "/EVM/AUTOMATE/test1?TagArray::my_objects=Classification::#{ tag1 . id } " , user )
835
+ my_objects_array = ws . root ( "my_objects" )
836
+ expect ( my_objects_array . length ) . to eq ( 1 )
837
+ my_objects_array . each { |o | o . kind_of? ( MiqAeMethodService ::MiqAeServiceModelBase ) }
838
+ end
839
+
792
840
it "processes an empty array properly" do
793
841
EvmSpecHelper . import_yaml_model ( File . join ( model_data_dir , "miq_ae_engine_spec6" ) , domain )
794
842
ws = MiqAeEngine . instantiate ( "/EVM/AUTOMATE/test1?Array::my_objects=" , user )
0 commit comments