@@ -524,13 +524,15 @@ def test_cache_template_exists(self, mock_exists):
524
524
525
525
mock_exists .assert_has_calls (exist_calls )
526
526
527
+ @mock .patch ('nova.image.format_inspector.detect_file_format' )
527
528
@mock .patch .object (imagebackend .utils , 'synchronized' )
528
529
@mock .patch ('nova.virt.libvirt.utils.create_image' )
529
530
@mock .patch .object (os .path , 'exists' , side_effect = [])
530
531
@mock .patch .object (imagebackend .Image , 'verify_base_size' )
531
532
@mock .patch ('nova.privsep.path.utime' )
532
533
def test_create_image (
533
- self , mock_utime , mock_verify , mock_exist , mock_create , mock_sync
534
+ self , mock_utime , mock_verify , mock_exist , mock_create , mock_sync ,
535
+ mock_detect_format
534
536
):
535
537
mock_sync .side_effect = lambda * a , ** kw : self ._fake_deco
536
538
fn = mock .MagicMock ()
@@ -551,15 +553,19 @@ def test_create_image(
551
553
mock_exist .assert_has_calls (exist_calls )
552
554
self .assertTrue (mock_sync .called )
553
555
mock_utime .assert_called ()
556
+ mock_detect_format .assert_called_once ()
557
+ mock_detect_format .return_value .safety_check .assert_called_once_with ()
554
558
559
+ @mock .patch ('nova.image.format_inspector.detect_file_format' )
555
560
@mock .patch .object (imagebackend .utils , 'synchronized' )
556
561
@mock .patch ('nova.virt.libvirt.utils.create_image' )
557
562
@mock .patch .object (imagebackend .disk , 'extend' )
558
563
@mock .patch .object (os .path , 'exists' , side_effect = [])
559
564
@mock .patch .object (imagebackend .Qcow2 , 'get_disk_size' )
560
565
@mock .patch ('nova.privsep.path.utime' )
561
566
def test_create_image_too_small (self , mock_utime , mock_get , mock_exist ,
562
- mock_extend , mock_create , mock_sync ):
567
+ mock_extend , mock_create , mock_sync ,
568
+ mock_detect_format ):
563
569
mock_sync .side_effect = lambda * a , ** kw : self ._fake_deco
564
570
mock_get .return_value = self .SIZE
565
571
fn = mock .MagicMock ()
@@ -576,7 +582,9 @@ def test_create_image_too_small(self, mock_utime, mock_get, mock_exist,
576
582
self .assertTrue (mock_sync .called )
577
583
self .assertFalse (mock_create .called )
578
584
self .assertFalse (mock_extend .called )
585
+ mock_detect_format .assert_called_once ()
579
586
587
+ @mock .patch ('nova.image.format_inspector.detect_file_format' )
580
588
@mock .patch .object (imagebackend .utils , 'synchronized' )
581
589
@mock .patch ('nova.virt.libvirt.utils.create_image' )
582
590
@mock .patch ('nova.virt.libvirt.utils.get_disk_backing_file' )
@@ -588,7 +596,8 @@ def test_create_image_too_small(self, mock_utime, mock_get, mock_exist,
588
596
def test_generate_resized_backing_files (self , mock_utime , mock_copy ,
589
597
mock_verify , mock_exist ,
590
598
mock_extend , mock_get ,
591
- mock_create , mock_sync ):
599
+ mock_create , mock_sync ,
600
+ mock_detect_format ):
592
601
mock_sync .side_effect = lambda * a , ** kw : self ._fake_deco
593
602
mock_get .return_value = self .QCOW2_BASE
594
603
fn = mock .MagicMock ()
@@ -615,7 +624,9 @@ def test_generate_resized_backing_files(self, mock_utime, mock_copy,
615
624
self .assertTrue (mock_sync .called )
616
625
self .assertFalse (mock_create .called )
617
626
mock_utime .assert_called ()
627
+ mock_detect_format .assert_called_once ()
618
628
629
+ @mock .patch ('nova.image.format_inspector.detect_file_format' )
619
630
@mock .patch .object (imagebackend .utils , 'synchronized' )
620
631
@mock .patch ('nova.virt.libvirt.utils.create_image' )
621
632
@mock .patch ('nova.virt.libvirt.utils.get_disk_backing_file' )
@@ -626,7 +637,8 @@ def test_generate_resized_backing_files(self, mock_utime, mock_copy,
626
637
def test_qcow2_exists_and_has_no_backing_file (self , mock_utime ,
627
638
mock_verify , mock_exist ,
628
639
mock_extend , mock_get ,
629
- mock_create , mock_sync ):
640
+ mock_create , mock_sync ,
641
+ mock_detect_format ):
630
642
mock_sync .side_effect = lambda * a , ** kw : self ._fake_deco
631
643
mock_get .return_value = None
632
644
fn = mock .MagicMock ()
@@ -647,6 +659,31 @@ def test_qcow2_exists_and_has_no_backing_file(self, mock_utime,
647
659
self .assertTrue (mock_sync .called )
648
660
self .assertFalse (mock_create .called )
649
661
self .assertFalse (mock_extend .called )
662
+ mock_detect_format .assert_called_once ()
663
+
664
+ @mock .patch ('nova.image.format_inspector.detect_file_format' )
665
+ @mock .patch .object (imagebackend .utils , 'synchronized' )
666
+ @mock .patch ('nova.virt.libvirt.utils.create_image' )
667
+ @mock .patch ('nova.virt.libvirt.utils.get_disk_backing_file' )
668
+ @mock .patch .object (imagebackend .disk , 'extend' )
669
+ @mock .patch .object (os .path , 'exists' , side_effect = [])
670
+ @mock .patch .object (imagebackend .Image , 'verify_base_size' )
671
+ def test_qcow2_exists_and_fails_safety_check (self ,
672
+ mock_verify , mock_exist ,
673
+ mock_extend , mock_get ,
674
+ mock_create , mock_sync ,
675
+ mock_detect_format ):
676
+ mock_detect_format .return_value .safety_check .return_value = False
677
+ mock_sync .side_effect = lambda * a , ** kw : self ._fake_deco
678
+ mock_get .return_value = None
679
+ fn = mock .MagicMock ()
680
+ mock_exist .side_effect = [False , True , False , True , True ]
681
+ image = self .image_class (self .INSTANCE , self .NAME )
682
+
683
+ self .assertRaises (exception .InvalidDiskInfo ,
684
+ image .create_image , fn , self .TEMPLATE_PATH ,
685
+ self .SIZE )
686
+ mock_verify .assert_not_called ()
650
687
651
688
def test_resolve_driver_format (self ):
652
689
image = self .image_class (self .INSTANCE , self .NAME )
0 commit comments