@@ -137,6 +137,26 @@ def self.configure(chef_run)
137
137
end
138
138
end
139
139
140
+ describe 'nvidia_imex:enable_force_configuration?' do
141
+ [ [ 'false' , false ] , [ false , false ] , [ 'no' , false ] , [ 'true' , true ] , [ true , true ] , [ 'yes' , true ] ] . each do |force_indicator , actual_indicator |
142
+ context "where node['cluster']['nvidia']['imex']['force_configuration'] is #{ force_indicator } " do
143
+ cached ( :chef_run ) do
144
+ ChefSpec ::SoloRunner . new ( step_into : [ 'nvidia_imex' ] ) do |node |
145
+ node . override [ 'cluster' ] [ 'nvidia' ] [ 'imex' ] [ 'force_configuration' ] = force_indicator
146
+ end
147
+ end
148
+ cached ( :resource ) do
149
+ ConvergeNvidiaImex . configure ( chef_run )
150
+ chef_run . find_resource ( 'nvidia_imex' , 'configure' )
151
+ end
152
+ it "we get #{ actual_indicator } " do
153
+ allow_any_instance_of ( Object ) . to receive ( :enable_force_configuration? ) . and_return ( actual_indicator )
154
+ expect ( resource . enable_force_configuration? ) . to eq ( actual_indicator )
155
+ end
156
+ end
157
+ end
158
+ end
159
+
140
160
describe 'nvidia_imex:install' do
141
161
for_all_oses do |platform , version |
142
162
context "on #{ platform } #{ version } " do
@@ -274,109 +294,121 @@ def self.configure(chef_run)
274
294
end
275
295
276
296
describe 'nvidia_imex:configure' do
277
- for_all_oses do |platform , version |
278
- context "on #{ platform } #{ version } " do
279
- context "when nvidia-imex binary is not installed" do
280
- cached ( :chef_run ) do
281
- stubs_for_resource ( 'nvidia_imex' ) do |res |
282
- allow ( res ) . to receive ( :imex_installed? ) . and_return ( false )
297
+ [ %w( false ) , [ false ] , %w( no ) , %w( true ) , [ true ] , %w( yes ) ] . each do |force_indicator |
298
+ for_all_oses do |platform , version |
299
+ context "on #{ platform } #{ version } with force_configuration #{ force_indicator } " do
300
+ context "when nvidia-imex binary is not installed" do
301
+ cached ( :chef_run ) do
302
+ stubs_for_resource ( 'nvidia_imex' ) do |res |
303
+ allow ( res ) . to receive ( :imex_installed? ) . and_return ( false )
304
+ end
305
+ runner = runner ( platform : platform , version : version , step_into : [ 'nvidia_imex' ] )
306
+ ConvergeNvidiaImex . configure ( runner )
307
+ end
308
+ cached ( :node ) { chef_run . node }
309
+
310
+ it 'does not configure nvidia-imex' do
311
+ is_expected . not_to configure_nvidia_imex ( 'nvidia-imex' )
283
312
end
284
- runner = runner ( platform : platform , version : version , step_into : [ 'nvidia_imex' ] )
285
- ConvergeNvidiaImex . configure ( runner )
286
313
end
287
- cached ( :node ) { chef_run . node }
288
314
289
- it 'does not configure nvidia-imex' do
290
- is_expected . not_to configure_nvidia_imex ( 'nvidia-imex' )
315
+ %w( HeadNode LoginNode ComputeFleet ) . each do |node_type |
316
+ context "when get_nvswitch_count > 1 on #{ node_type } node" do
317
+ cached ( :chef_run ) do
318
+ stubs_for_provider ( 'nvidia_imex[configure]' ) do |pro |
319
+ allow ( pro ) . to receive ( :imex_installed? ) . and_return ( true )
320
+ allow ( pro ) . to receive ( :get_device_ids ) . and_return ( { 'gb200' => 'test' } )
321
+ allow ( pro ) . to receive ( :get_nvswitch_count ) . with ( 'test' ) . and_return ( 4 )
322
+ allow ( pro ) . to receive ( :enable_force_configuration? ) . and_return ( force_indicator )
323
+ end
324
+ runner ( platform : platform , version : version , step_into : [ 'nvidia_imex' ] )
325
+ end
326
+ cached ( :node ) { chef_run . node }
327
+
328
+ before do
329
+ chef_run . node . override [ 'cluster' ] [ 'region' ] = 'aws_region'
330
+ chef_run . node . override [ 'cluster' ] [ 'nvidia' ] [ 'imex' ] [ 'force_configuration' ] = force_indicator
331
+ chef_run . node . override [ 'cluster' ] [ 'nvidia' ] [ 'imex' ] [ 'shared_dir' ] = nvidia_imex_shared_dir
332
+ chef_run . node . override [ 'cluster' ] [ 'node_type' ] = node_type
333
+ chef_run . node . override [ 'cluster' ] [ 'launch_template_id' ] = launch_template_id
334
+ ConvergeNvidiaImex . configure ( chef_run )
335
+ end
336
+
337
+ if ( platform == 'amazon' && version == '2' ) || %w( HeadNode LoginNode ) . include? ( node_type )
338
+ it 'does not configure nvidia-imex' do
339
+ is_expected . not_to create_template ( "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" )
340
+ . with ( source : 'nvidia-imex/nvidia-imex-nodes.erb' )
341
+ . with ( user : 'root' )
342
+ . with ( group : 'root' )
343
+ . with ( mode : '0755' )
344
+ is_expected . not_to create_template ( "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" )
345
+ . with ( source : 'nvidia-imex/nvidia-imex-config.erb' )
346
+ . with ( user : 'root' )
347
+ . with ( group : 'root' )
348
+ . with ( mode : '0755' )
349
+ . with ( variables : { imex_nodes_config_file_path : "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" } )
350
+ is_expected . not_to create_template ( "/etc/systemd/system/nvidia-imex.service" )
351
+ . with ( source : 'nvidia-imex/nvidia-imex.service.erb' )
352
+ . with ( user : 'root' )
353
+ . with ( group : 'root' )
354
+ . with ( mode : '0644' )
355
+ . with ( variables : { imex_main_config_file_path : "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" } )
356
+ is_expected . not_to start_service ( 'nvidia-imex' ) . with_action ( %i( enable start ) ) . with_supports ( { status : true } )
357
+ end
358
+ else
359
+ it 'it starts nvidia-imex service' do
360
+ is_expected . to create_template ( "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" )
361
+ . with ( source : 'nvidia-imex/nvidia-imex-nodes.erb' )
362
+ . with ( user : 'root' )
363
+ . with ( group : 'root' )
364
+ . with ( mode : '0755' )
365
+ is_expected . to create_template ( "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" )
366
+ . with ( source : 'nvidia-imex/nvidia-imex-config.erb' )
367
+ . with ( user : 'root' )
368
+ . with ( group : 'root' )
369
+ . with ( mode : '0755' )
370
+ . with ( variables : { imex_nodes_config_file_path : "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" } )
371
+ is_expected . to create_template ( "/etc/systemd/system/nvidia-imex.service" )
372
+ . with ( source : 'nvidia-imex/nvidia-imex.service.erb' )
373
+ . with ( user : 'root' )
374
+ . with ( group : 'root' )
375
+ . with ( mode : '0644' )
376
+ . with ( variables : { imex_main_config_file_path : "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" } )
377
+ is_expected . to start_service ( 'nvidia-imex' ) . with_action ( %i( enable start ) ) . with_supports ( { status : true } )
378
+ end
379
+ end
380
+ end
291
381
end
292
- end
293
382
294
- %w( HeadNode LoginNode ComputeFleet ) . each do |node_type |
295
- context "when get_nvswitch_count > 1 on #{ node_type } node" do
383
+ context "when get_nvswitch_count <= 1" do
296
384
cached ( :chef_run ) do
297
385
stubs_for_provider ( 'nvidia_imex[configure]' ) do |pro |
298
386
allow ( pro ) . to receive ( :imex_installed? ) . and_return ( true )
299
387
allow ( pro ) . to receive ( :get_device_ids ) . and_return ( { 'gb200' => 'test' } )
300
- allow ( pro ) . to receive ( :get_nvswitch_count ) . with ( 'test' ) . and_return ( 4 )
388
+ allow ( pro ) . to receive ( :get_nvswitch_count ) . with ( 'test' ) . and_return ( 1 )
389
+ allow ( pro ) . to receive ( :enable_force_configuration? ) . and_return ( force_indicator )
301
390
end
302
- runner ( platform : platform , version : version , step_into : [ 'nvidia_imex' ] )
391
+ runner = runner ( platform : platform , version : version , step_into : [ 'nvidia_imex' ] )
392
+ ConvergeNvidiaImex . configure ( runner )
303
393
end
304
394
cached ( :node ) { chef_run . node }
305
395
306
396
before do
307
397
chef_run . node . override [ 'cluster' ] [ 'region' ] = 'aws_region'
308
- chef_run . node . override [ 'cluster' ] [ 'nvidia' ] [ 'imex' ] [ 'shared_dir' ] = nvidia_imex_shared_dir
309
- chef_run . node . override [ 'cluster' ] [ 'node_type' ] = node_type
310
- chef_run . node . override [ 'cluster' ] [ 'launch_template_id' ] = launch_template_id
311
- ConvergeNvidiaImex . configure ( chef_run )
398
+ chef_run . node . override [ 'cluster' ] [ 'nvidia' ] [ 'imex' ] [ 'force_configuration' ] = force_indicator
312
399
end
313
400
314
- if ( platform == 'amazon' && version == '2' ) || %w( HeadNode LoginNode ) . include? ( node_type )
315
- it 'does not configure nvidia-imex' do
316
- is_expected . not_to create_template ( "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" )
317
- . with ( source : 'nvidia-imex/nvidia-imex-nodes.erb' )
318
- . with ( user : 'root' )
319
- . with ( group : 'root' )
320
- . with ( mode : '0755' )
321
- is_expected . not_to create_template ( "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" )
322
- . with ( source : 'nvidia-imex/nvidia-imex-config.erb' )
323
- . with ( user : 'root' )
324
- . with ( group : 'root' )
325
- . with ( mode : '0755' )
326
- . with ( variables : { imex_nodes_config_file_path : "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" } )
327
- is_expected . not_to create_template ( "/etc/systemd/system/nvidia-imex.service" )
328
- . with ( source : 'nvidia-imex/nvidia-imex.service.erb' )
329
- . with ( user : 'root' )
330
- . with ( group : 'root' )
331
- . with ( mode : '0644' )
332
- . with ( variables : { imex_main_config_file_path : "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" } )
333
- is_expected . not_to start_service ( 'nvidia-imex' ) . with_action ( %i( enable start ) ) . with_supports ( { status : true } )
401
+ if [ 'true' , 'yes' , true ] . include? ( force_indicator )
402
+ it 'does configure nvidia-imex' do
403
+ is_expected . to start_service ( 'nvidia-imex' ) . with_action ( %i( enable start ) ) . with_supports ( { status : true } )
334
404
end
335
405
else
336
- it 'it starts nvidia-imex service' do
337
- is_expected . to create_template ( "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" )
338
- . with ( source : 'nvidia-imex/nvidia-imex-nodes.erb' )
339
- . with ( user : 'root' )
340
- . with ( group : 'root' )
341
- . with ( mode : '0755' )
342
- is_expected . to create_template ( "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" )
343
- . with ( source : 'nvidia-imex/nvidia-imex-config.erb' )
344
- . with ( user : 'root' )
345
- . with ( group : 'root' )
346
- . with ( mode : '0755' )
347
- . with ( variables : { imex_nodes_config_file_path : "#{ nvidia_imex_shared_dir } /nodes_config_#{ launch_template_id } .cfg" } )
348
- is_expected . to create_template ( "/etc/systemd/system/nvidia-imex.service" )
349
- . with ( source : 'nvidia-imex/nvidia-imex.service.erb' )
350
- . with ( user : 'root' )
351
- . with ( group : 'root' )
352
- . with ( mode : '0644' )
353
- . with ( variables : { imex_main_config_file_path : "#{ nvidia_imex_shared_dir } /config_#{ launch_template_id } .cfg" } )
354
- is_expected . to start_service ( 'nvidia-imex' ) . with_action ( %i( enable start ) ) . with_supports ( { status : true } )
406
+ it 'does not configure nvidia-imex' do
407
+ is_expected . not_to start_service ( 'nvidia-imex' ) . with_action ( %i( enable start ) ) . with_supports ( { status : true } )
355
408
end
356
409
end
357
410
end
358
411
end
359
-
360
- context "when get_nvswitch_count <= 1" do
361
- cached ( :chef_run ) do
362
- stubs_for_provider ( 'nvidia_imex[configure]' ) do |pro |
363
- allow ( pro ) . to receive ( :imex_installed? ) . and_return ( true )
364
- allow ( pro ) . to receive ( :get_device_ids ) . and_return ( { 'gb200' => 'test' } )
365
- allow ( pro ) . to receive ( :get_nvswitch_count ) . with ( 'test' ) . and_return ( 1 )
366
- end
367
- runner = runner ( platform : platform , version : version , step_into : [ 'nvidia_imex' ] )
368
- ConvergeNvidiaImex . configure ( runner )
369
- end
370
- cached ( :node ) { chef_run . node }
371
-
372
- before do
373
- chef_run . node . override [ 'cluster' ] [ 'region' ] = 'aws_region'
374
- end
375
-
376
- it 'does not configure nvidia-imex' do
377
- is_expected . not_to start_service ( 'nvidia-imex' ) . with_action ( %i( enable start ) ) . with_supports ( { status : true } )
378
- end
379
- end
380
412
end
381
413
end
382
414
end
0 commit comments