9
9
10
10
from hpc_provisioner import handlers , pcluster_manager
11
11
from hpc_provisioner .cluster import Cluster , ClusterJSONEncoder
12
- from hpc_provisioner .constants import FILESYSTEMS
12
+ from hpc_provisioner .constants import (
13
+ BILLING_TAG_KEY ,
14
+ BILLING_TAG_VALUE ,
15
+ DRAS ,
16
+ PROJECT_TAG_KEY ,
17
+ VLAB_TAG_KEY ,
18
+ )
13
19
from hpc_provisioner .pcluster_manager import InvalidRequest
14
20
15
21
logger = logging .getLogger ("test_logger" )
@@ -234,23 +240,36 @@ def test_post(patched_boto3, patched_dynamodb_resource, post_event, key_exists,
234
240
)
235
241
@patch ("hpc_provisioner.aws_queries.free_subnet" )
236
242
@patch ("hpc_provisioner.pcluster_manager.remove_key" )
243
+ @patch ("hpc_provisioner.pcluster_manager.boto3" )
237
244
@patch ("hpc_provisioner.handlers.dynamodb_resource" )
238
245
def test_delete (
239
246
patched_dynamodb_resource ,
247
+ patched_boto3 ,
240
248
patched_remove_key ,
241
249
patched_free_subnet ,
242
250
patched_dynamodb_client ,
243
251
data ,
244
252
delete_event ,
245
253
test_cluster ,
246
254
):
255
+ mock_fsx_client = MagicMock ()
256
+ mock_fsx_client .describe_file_systems .return_value = {
257
+ "FileSystems" : [
258
+ {"FileSystemId" : "fs-123" , "Tags" : [{"Key" : "Name" , "Value" : test_cluster .name }]},
259
+ {
260
+ "FileSystemId" : "fs-234" ,
261
+ "Tags" : [{"Key" : "Name" , "Value" : f"{ test_cluster .name } -2" }],
262
+ },
263
+ ]
264
+ }
265
+ patched_boto3 .client .return_value = mock_fsx_client
247
266
mock_resource = MagicMock ()
248
267
mock_table = MagicMock ()
249
268
mock_resource .Table .return_value = mock_table
250
269
patched_dynamodb_resource .return_value = mock_resource
251
270
252
- mock_client = MagicMock ()
253
- patched_dynamodb_client .return_value = mock_client
271
+ mock_dynamodb_client = MagicMock ()
272
+ patched_dynamodb_client .return_value = mock_dynamodb_client
254
273
with patch (
255
274
"hpc_provisioner.pcluster_manager.pc.delete_cluster" , return_value = data ["deletingCluster" ]
256
275
) as patched_delete_cluster :
@@ -270,10 +289,13 @@ def test_delete(
270
289
assert actual_response == expected_response
271
290
patched_get_registered_subnets .assert_called_once ()
272
291
assert patched_remove_key .call_count == 2
273
- call1 = call (mock_client , "subnet-123" )
274
- call2 = call (mock_client , "subnet-234" )
292
+ call1 = call (mock_dynamodb_client , "subnet-123" )
293
+ call2 = call (mock_dynamodb_client , "subnet-234" )
275
294
patched_free_subnet .assert_has_calls ([call1 , call2 ], any_order = True )
276
295
mock_table .delete_item .assert_called_once_with (Key = {"name" : test_cluster .name })
296
+ mock_fsx_client .delete_file_system .assert_called_once_with (
297
+ FileSystemId = "fs-123" , ClientRequestToken = "fs-123"
298
+ )
277
299
278
300
279
301
def test_get_not_found (get_event ):
@@ -303,14 +325,19 @@ def test_get_internal_server_error(get_event):
303
325
"hpc_provisioner.aws_queries.dynamodb_client" ,
304
326
)
305
327
@patch ("hpc_provisioner.pcluster_manager.remove_key" )
328
+ @patch ("hpc_provisioner.pcluster_manager.boto3" )
306
329
@patch ("hpc_provisioner.handlers.dynamodb_resource" )
307
330
def test_delete_not_found (
308
331
patched_dynamodb_resource ,
332
+ patched_boto3 ,
309
333
patched_remove_key ,
310
334
patched_dynamodb_client ,
311
335
delete_event ,
312
336
test_cluster ,
313
337
):
338
+ mock_fsx_client = MagicMock ()
339
+ mock_fsx_client .describe_file_systems .return_value = {"FileSystems" : []}
340
+ patched_boto3 .client .return_value = mock_fsx_client
314
341
mock_resource = MagicMock ()
315
342
mock_table = MagicMock ()
316
343
mock_resource .Table .return_value = mock_table
@@ -332,14 +359,19 @@ def test_delete_not_found(
332
359
"hpc_provisioner.aws_queries.dynamodb_client" ,
333
360
)
334
361
@patch ("hpc_provisioner.pcluster_manager.remove_key" )
362
+ @patch ("hpc_provisioner.pcluster_manager.boto3" )
335
363
@patch ("hpc_provisioner.handlers.dynamodb_resource" )
336
364
def test_delete_internal_server_error (
337
365
patched_dynamodb_resource ,
366
+ patched_boto3 ,
338
367
patched_remove_key ,
339
368
patched_dynamodb_client ,
340
369
delete_event ,
341
370
test_cluster ,
342
371
):
372
+ mock_fsx_client = MagicMock ()
373
+ mock_fsx_client .describe_file_systems .return_value = {"FileSystems" : []}
374
+ patched_boto3 .client .return_value = mock_fsx_client
343
375
mock_resource = MagicMock ()
344
376
mock_table = MagicMock ()
345
377
mock_resource .Table .return_value = mock_table
@@ -456,42 +488,62 @@ def test_load_tier(tier, is_valid):
456
488
def test_dra_check_no_fs_created_yet (
457
489
patched_do_cluster_create , patched_boto3 , patched_dynamodb_resource
458
490
):
491
+ pending_clusters = [
492
+ Cluster (project_id = "proj1" , vlab_id = "testing" ),
493
+ Cluster (project_id = "proj2" , vlab_id = "testing" ),
494
+ ]
459
495
mock_fsx_client = MagicMock ()
460
496
mock_fsx_client .describe_file_systems .side_effect = [
461
497
{"FileSystems" : []},
462
498
{"FileSystems" : []},
463
499
{"FileSystems" : []},
464
- {"FileSystems" : [{"Lifecycle" : "CREATING" }]},
500
+ {"FileSystems" : []},
501
+ {
502
+ "FileSystems" : [
503
+ {
504
+ "Lifecycle" : "CREATING" ,
505
+ "Tags" : [{"Key" : "Name" , "Value" : pending_clusters [0 ].name }],
506
+ }
507
+ ]
508
+ },
465
509
]
466
510
file_system_id = "fs-123"
467
511
mock_fsx_client .create_file_system .return_value = {
468
512
"FileSystem" : {"FileSystemId" : file_system_id }
469
513
}
470
514
patched_boto3 .client .return_value = mock_fsx_client
471
- pending_clusters = [
472
- Cluster (project_id = "proj1" , vlab_id = "testing" ),
473
- Cluster (project_id = "proj2" , vlab_id = "testing" ),
474
- ]
475
515
with patch (
476
516
"hpc_provisioner.handlers.get_unclaimed_clusters" ,
477
517
return_value = pending_clusters ,
478
518
):
479
519
return_value = handlers .dra_check_handler ({})
480
520
assert return_value == {
481
521
"statusCode" : 200 ,
482
- "body" : f"Precreating fsx for cluster { pending_clusters [0 ].name } " ,
522
+ "headers" : {"Content-Type" : "application/json" },
523
+ "body" : json .dumps (
524
+ {
525
+ pending_clusters [
526
+ 0
527
+ ].name : f"Precreating fsx for cluster { pending_clusters [0 ].name } " ,
528
+ pending_clusters [
529
+ 1
530
+ ].name : f"A filesystem is being created - skipping cluster { pending_clusters [1 ].name } for now" ,
531
+ }
532
+ ),
483
533
}
484
534
patched_do_cluster_create .assert_not_called ()
485
535
mock_fsx_client .create_file_system .assert_called_once_with (
486
- ClientRequestToken = "projects" ,
536
+ ClientRequestToken = pending_clusters [ 0 ]. name ,
487
537
FileSystemType = "LUSTRE" ,
488
538
StorageCapacity = 19200 ,
489
539
StorageType = "SSD" ,
490
540
SubnetIds = json .loads (os .environ ["FS_SUBNET_IDS" ]),
491
541
SecurityGroupIds = [os .environ ["FS_SG_ID" ]],
492
542
Tags = [
493
- {"Key" : "SBO_Billing" , "Value" : "hpc:parallelcluster" },
494
- {"Key" : "Name" , "Value" : FILESYSTEMS [0 ]["name" ]},
543
+ {"Key" : BILLING_TAG_KEY , "Value" : BILLING_TAG_VALUE },
544
+ {"Key" : VLAB_TAG_KEY , "Value" : pending_clusters [0 ].vlab_id },
545
+ {"Key" : PROJECT_TAG_KEY , "Value" : pending_clusters [0 ].project_id },
546
+ {"Key" : "Name" , "Value" : pending_clusters [0 ].name },
495
547
],
496
548
LustreConfiguration = {
497
549
"WeeklyMaintenanceStartTime" : "6:05:00" ,
@@ -504,16 +556,16 @@ def test_dra_check_no_fs_created_yet(
504
556
)
505
557
mock_fsx_client .create_data_repository_association .assert_called_once_with (
506
558
FileSystemId = file_system_id ,
507
- FileSystemPath = FILESYSTEMS [0 ]["mountpoint" ],
559
+ FileSystemPath = DRAS [0 ]["mountpoint" ],
508
560
DataRepositoryPath = os .environ ["SBO_NEXUSDATA_BUCKET" ],
509
561
BatchImportMetaDataOnCreate = True ,
510
562
ImportedFileChunkSize = 1024 ,
511
563
S3 = {"AutoImportPolicy" : {"Events" : ["NEW" , "CHANGED" , "DELETED" ]}},
512
- ClientRequestToken = f"{ file_system_id } -testing-proj1" ,
564
+ ClientRequestToken = f"{ file_system_id } -testing-proj1-projects " ,
513
565
Tags = [
514
566
{
515
567
"Key" : "Name" ,
516
- "Value" : f"{ file_system_id } -{ FILESYSTEMS [0 ]['mountpoint' ]} " ,
568
+ "Value" : f"{ file_system_id } -{ DRAS [0 ]['mountpoint' ]} " ,
517
569
},
518
570
{"Key" : "SBO_Billing" , "Value" : "hpc:parallelcluster" },
519
571
{"Key" : "obp:costcenter:vlabid" , "Value" : pending_clusters [0 ].vlab_id },
@@ -522,32 +574,6 @@ def test_dra_check_no_fs_created_yet(
522
574
)
523
575
524
576
525
- @patch ("hpc_provisioner.pcluster_manager.boto3" )
526
- @patch ("hpc_provisioner.handlers.do_cluster_create" )
527
- def test_dra_check_common_fs_creating (patched_do_cluster_create , patched_boto3 ):
528
- mock_fsx_client = MagicMock ()
529
- mock_fsx_client .describe_file_systems .return_value = {
530
- "FileSystems" : [{"Lifecycle" : "CREATING" , "Tags" : [{"Key" : "Name" , "Value" : "projects" }]}]
531
- }
532
- patched_boto3 .client .return_value = mock_fsx_client
533
- pending_clusters = [
534
- Cluster (project_id = "proj1" , vlab_id = "testing" ),
535
- Cluster (project_id = "proj2" , vlab_id = "testing" ),
536
- ]
537
- with patch (
538
- "hpc_provisioner.handlers.get_unclaimed_clusters" ,
539
- return_value = pending_clusters ,
540
- ):
541
- return_value = handlers .dra_check_handler ({})
542
- assert return_value == {
543
- "statusCode" : 200 ,
544
- "body" : f"A filesystem is being created - skipping cluster { pending_clusters [0 ].name } for now" ,
545
- }
546
- patched_do_cluster_create .assert_not_called ()
547
- mock_fsx_client .create_file_system .assert_not_called ()
548
- mock_fsx_client .create_data_repository_association .assert_not_called ()
549
-
550
-
551
577
@patch ("hpc_provisioner.pcluster_manager.boto3" )
552
578
@patch ("hpc_provisioner.handlers.do_cluster_create" )
553
579
def test_dra_check_fs_for_other_cluster_creating (patched_do_cluster_create , patched_boto3 ):
@@ -556,7 +582,7 @@ def test_dra_check_fs_for_other_cluster_creating(patched_do_cluster_create, patc
556
582
"FileSystems" : [
557
583
{
558
584
"Lifecycle" : "CREATING" ,
559
- "Tags" : [{"Key" : "Name" , "Value" : "scratch- pcluster-testing-proj2" }],
585
+ "Tags" : [{"Key" : "Name" , "Value" : "pcluster-testing-proj2" }],
560
586
}
561
587
]
562
588
}
@@ -572,7 +598,17 @@ def test_dra_check_fs_for_other_cluster_creating(patched_do_cluster_create, patc
572
598
return_value = handlers .dra_check_handler ({})
573
599
assert return_value == {
574
600
"statusCode" : 200 ,
575
- "body" : f"A filesystem is being created - skipping cluster { pending_clusters [0 ].name } for now" ,
601
+ "headers" : {"Content-Type" : "application/json" },
602
+ "body" : json .dumps (
603
+ {
604
+ pending_clusters [
605
+ 0
606
+ ].name : f"A filesystem is being created - skipping cluster { pending_clusters [0 ].name } for now" ,
607
+ pending_clusters [
608
+ 1
609
+ ].name : f"A filesystem is being created - skipping cluster { pending_clusters [1 ].name } for now" ,
610
+ }
611
+ ),
576
612
}
577
613
patched_do_cluster_create .assert_not_called ()
578
614
mock_fsx_client .create_file_system .assert_not_called ()
0 commit comments