2
2
from test .integration .helpers import (
3
3
get_test_label ,
4
4
retry_sending_request ,
5
+ send_request_when_resource_available ,
5
6
wait_for_condition ,
6
7
)
7
8
@@ -65,6 +66,53 @@ def linode_with_volume_firewall(test_linode_client):
65
66
linode_instance .delete ()
66
67
67
68
69
+ @pytest .fixture (scope = "session" )
70
+ def linode_for_network_interface_tests (test_linode_client ):
71
+ client = test_linode_client
72
+ available_regions = client .regions ()
73
+ chosen_region = available_regions [0 ]
74
+ timestamp = str (time .time_ns ())
75
+ label = "TestSDK-" + timestamp
76
+
77
+ linode_instance , password = client .linode .instance_create (
78
+ "g6-nanode-1" , chosen_region , image = "linode/debian10" , label = label
79
+ )
80
+
81
+ yield linode_instance
82
+
83
+ linode_instance .delete ()
84
+
85
+
86
+ @pytest .fixture (scope = "session" , autouse = True )
87
+ def linode_for_disk_tests (test_linode_client ):
88
+ client = test_linode_client
89
+ available_regions = client .regions ()
90
+ chosen_region = available_regions [0 ]
91
+ label = get_test_label ()
92
+
93
+ linode_instance , password = client .linode .instance_create (
94
+ "g6-nanode-1" ,
95
+ chosen_region ,
96
+ image = "linode/debian10" ,
97
+ label = label + "_long_tests" ,
98
+ )
99
+
100
+ time .sleep (10 )
101
+
102
+ # Provisioning time
103
+ wait_for_condition (10 , 300 , get_status , linode_instance , "running" )
104
+
105
+ time .sleep (10 )
106
+
107
+ linode_instance .shutdown ()
108
+
109
+ wait_for_condition (10 , 100 , get_status , linode_instance , "offline" )
110
+
111
+ yield linode_instance
112
+
113
+ linode_instance .delete ()
114
+
115
+
68
116
@pytest .mark .smoke
69
117
@pytest .fixture
70
118
def create_linode_for_long_running_tests (test_linode_client ):
@@ -289,22 +337,53 @@ def test_linode_volumes(linode_with_volume_firewall):
289
337
assert "TestSDK" in volumes [0 ].label
290
338
291
339
292
- def test_linode_disk_duplicate (test_linode_client , create_linode ):
293
- pytest .skip ("Need to find out the space sizing when duplicating disks" )
294
- linode = create_linode
340
+ def wait_for_disk_status (disk : Disk , timeout ):
341
+ start_time = time .time ()
342
+ while True :
343
+ try :
344
+ if disk .status == "ready" :
345
+ return disk .status
346
+ except ApiError :
347
+ if time .time () - start_time > timeout :
348
+ raise TimeoutError ("Wait for condition timeout error" )
349
+
350
+
351
+ @pytest .mark .dependency ()
352
+ def test_disk_resize_and_duplicate (test_linode_client , linode_for_disk_tests ):
353
+ linode = linode_for_disk_tests
354
+
355
+ disk = linode .disks [0 ]
356
+
357
+ disk .resize (5000 )
358
+
359
+ # Using hard sleep instead of wait as the status shows ready when it is resizing
360
+ time .sleep (120 )
295
361
296
362
disk = test_linode_client .load (Disk , linode .disks [0 ].id , linode .id )
297
363
298
- try :
299
- dup_disk = disk .duplicate ()
300
- assert dup_disk .linode_id == linode .id
301
- except ApiError as e :
302
- assert e .status == 400
303
- assert "Insufficient space" in str (e .json )
364
+ assert disk .size == 5000
365
+
366
+ dup_disk = disk .duplicate ()
367
+
368
+ time .sleep (40 )
369
+
370
+ wait_for_disk_status (dup_disk , 120 )
371
+
372
+ assert dup_disk .linode_id == linode .id
373
+
374
+
375
+ @pytest .mark .dependency (depends = ["test_disk_resize_and_duplicate" ])
376
+ def test_linode_create_disk (test_linode_client , linode_for_disk_tests ):
377
+ linode = test_linode_client .load (Instance , linode_for_disk_tests .id )
378
+
379
+ disk = linode .disk_create (size = 500 )
380
+
381
+ wait_for_disk_status (disk , 120 )
382
+
383
+ assert disk .linode_id == linode .id
304
384
305
385
306
386
def test_linode_instance_password (create_linode_for_pass_reset ):
307
- pytest .skip ("Failing due to mismatched request body" )
308
387
linode = create_linode_for_pass_reset [0 ]
309
388
password = create_linode_for_pass_reset [1 ]
310
389
@@ -343,25 +422,14 @@ def test_linode_initate_migration(test_linode_client):
343
422
344
423
wait_for_condition (10 , 100 , get_status , linode , "running" )
345
424
# Says it could take up to ~6 hrs for migration to fully complete
346
- linode .initiate_migration (region = "us-central" )
347
425
348
- res = linode .delete ()
349
-
350
- assert res
351
-
352
-
353
- def test_linode_create_disk (create_linode ):
354
- pytest .skip (
355
- "Pre-requisite for the test account need to comply with this test"
426
+ send_request_when_resource_available (
427
+ 300 , linode .initiate_migration , "us-central"
356
428
)
357
- linode = create_linode
358
- disk , gen_pass = linode .disk_create ()
359
429
430
+ res = linode .delete ()
360
431
361
- def test_disk_resize ():
362
- pytest .skip (
363
- "Pre-requisite for the test account need to comply with this test"
364
- )
432
+ assert res
365
433
366
434
367
435
def test_config_update_interfaces (create_linode ):
@@ -387,19 +455,9 @@ def test_config_update_interfaces(create_linode):
387
455
388
456
389
457
def test_get_config (test_linode_client , create_linode ):
390
- pytest .skip (
391
- "Model get method: client.load(Config, 123, 123) does not work..."
392
- )
393
458
linode = create_linode
394
- json = test_linode_client .get (
395
- "linode/instances/"
396
- + str (linode .id )
397
- + "/configs/"
398
- + str (linode .configs [0 ].id )
399
- )
400
- config = Config (
401
- test_linode_client , linode .id , linode .configs [0 ].id , json = json
402
- )
459
+
460
+ config = test_linode_client .load (Config , linode .configs [0 ].id , linode .id )
403
461
404
462
assert config .id == linode .configs [0 ].id
405
463
@@ -429,18 +487,6 @@ def test_get_linode_types_overrides(test_linode_client):
429
487
assert linode_type .region_prices [0 ].monthly >= 0
430
488
431
489
432
- def test_get_linode_type_by_id (test_linode_client ):
433
- pytest .skip (
434
- "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)"
435
- )
436
-
437
-
438
- def test_get_linode_type_gpu ():
439
- pytest .skip (
440
- "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)"
441
- )
442
-
443
-
444
490
def test_save_linode_noforce (test_linode_client , create_linode ):
445
491
linode = create_linode
446
492
old_label = linode .label
@@ -464,28 +510,29 @@ def test_save_linode_force(test_linode_client, create_linode):
464
510
465
511
466
512
class TestNetworkInterface :
467
- def test_list (self , create_linode ):
468
- linode = create_linode
513
+ def test_list (self , linode_for_network_interface_tests ):
514
+ linode = linode_for_network_interface_tests
469
515
470
516
config : Config = linode .configs [0 ]
471
517
472
518
config .interface_create_public (
473
519
primary = True ,
474
520
)
475
- config .interface_create_vlan (
476
- label = "testvlan" , ipam_address = "10.0.0.3/32"
477
- )
521
+
522
+ label = str (time .time_ns ()) + "vlabel"
523
+
524
+ config .interface_create_vlan (label = label , ipam_address = "10.0.0.3/32" )
478
525
479
526
interface = config .network_interfaces
480
527
481
528
assert interface [0 ].purpose == "public"
482
529
assert interface [0 ].primary
483
530
assert interface [1 ].purpose == "vlan"
484
- assert interface [1 ].label == "testvlan"
531
+ assert interface [1 ].label == label
485
532
assert interface [1 ].ipam_address == "10.0.0.3/32"
486
533
487
- def test_create_public (self , create_linode ):
488
- linode = create_linode
534
+ def test_create_public (self , linode_for_network_interface_tests ):
535
+ linode = linode_for_network_interface_tests
489
536
490
537
config : Config = linode .configs [0 ]
491
538
@@ -502,8 +549,8 @@ def test_create_public(self, create_linode):
502
549
assert interface .purpose == "public"
503
550
assert interface .primary
504
551
505
- def test_create_vlan (self , create_linode ):
506
- linode = create_linode
552
+ def test_create_vlan (self , linode_for_network_interface_tests ):
553
+ linode = linode_for_network_interface_tests
507
554
508
555
config : Config = linode .configs [0 ]
509
556
@@ -521,7 +568,11 @@ def test_create_vlan(self, create_linode):
521
568
assert interface .label == "testvlan"
522
569
assert interface .ipam_address == "10.0.0.2/32"
523
570
524
- def test_create_vpc (self , create_linode , create_vpc_with_subnet_and_linode ):
571
+ def test_create_vpc (
572
+ self ,
573
+ linode_for_network_interface_tests ,
574
+ create_vpc_with_subnet_and_linode ,
575
+ ):
525
576
vpc , subnet , linode , _ = create_vpc_with_subnet_and_linode
526
577
527
578
config : Config = linode .configs [0 ]
@@ -545,7 +596,11 @@ def test_create_vpc(self, create_linode, create_vpc_with_subnet_and_linode):
545
596
assert interface .ipv4 .nat_1_1 == linode .ipv4 [0 ]
546
597
assert interface .ip_ranges == ["10.0.0.5/32" ]
547
598
548
- def test_update_vpc (self , create_linode , create_vpc_with_subnet_and_linode ):
599
+ def test_update_vpc (
600
+ self ,
601
+ linode_for_network_interface_tests ,
602
+ create_vpc_with_subnet_and_linode ,
603
+ ):
549
604
vpc , subnet , linode , _ = create_vpc_with_subnet_and_linode
550
605
551
606
config : Config = linode .configs [0 ]
@@ -575,25 +630,31 @@ def test_update_vpc(self, create_linode, create_vpc_with_subnet_and_linode):
575
630
assert interface .ipv4 .nat_1_1 == linode .ipv4 [0 ]
576
631
assert interface .ip_ranges == ["10.0.0.6/32" ]
577
632
578
- def test_reorder (self , create_linode ):
579
- linode = create_linode
633
+ def test_reorder (self , linode_for_network_interface_tests ):
634
+ linode = linode_for_network_interface_tests
580
635
581
636
config : Config = linode .configs [0 ]
582
637
583
638
pub_interface = config .interface_create_public (
584
639
primary = True ,
585
640
)
641
+
642
+ label = str (time .time_ns ()) + "vlabel"
586
643
vlan_interface = config .interface_create_vlan (
587
- label = "testvlan" , ipam_address = "10.0.0.3/32"
644
+ label = label , ipam_address = "10.0.0.3/32"
588
645
)
589
646
647
+ send_request_when_resource_available (300 , linode .shutdown )
648
+
590
649
interfaces = config .network_interfaces
591
650
interfaces .reverse ()
592
651
593
- config .interface_reorder (interfaces )
652
+ send_request_when_resource_available (
653
+ 300 , config .interface_reorder , interfaces
654
+ )
594
655
config .invalidate ()
595
656
596
- assert [v .id for v in config .interfaces ] == [
657
+ assert [v .id for v in config .interfaces [: 2 ] ] == [
597
658
vlan_interface .id ,
598
659
pub_interface .id ,
599
660
]
@@ -606,7 +667,11 @@ def test_delete_interface_containing_vpc(
606
667
config : Config = linode .configs [0 ]
607
668
608
669
config .interfaces = []
609
- config .save ()
670
+
671
+ # must power off linode before saving
672
+ send_request_when_resource_available (300 , linode .shutdown )
673
+
674
+ send_request_when_resource_available (60 , config .save )
610
675
611
676
interface = config .interface_create_vpc (
612
677
subnet = subnet ,
0 commit comments