22
22
from oslo_concurrency import processutils
23
23
import requests
24
24
25
+ from ironic_python_agent .extensions import image
25
26
from ironic_python_agent import partition_utils
26
27
from ironic_python_agent .tests .unit import base
27
28
@@ -654,6 +655,7 @@ def test_create_partition_exists(self, mock_get_configdrive,
654
655
mock_dd .assert_called_with (configdrive_file , configdrive_part )
655
656
mock_unlink .assert_called_with (configdrive_file )
656
657
658
+ @mock .patch ('oslo_utils.uuidutils.generate_uuid' , lambda : 'fake-uuid' )
657
659
@mock .patch .object (utils , 'execute' , autospec = True )
658
660
@mock .patch .object (utils , 'unlink_without_raise' ,
659
661
autospec = True )
@@ -663,50 +665,32 @@ def test_create_partition_exists(self, mock_get_configdrive,
663
665
autospec = True )
664
666
@mock .patch .object (disk_utils , 'get_partition_table_type' ,
665
667
autospec = True )
666
- @mock .patch .object (disk_utils , 'list_partitions' ,
667
- autospec = True )
668
+ @mock .patch .object (image , '_get_partition' , autospec = True )
668
669
@mock .patch .object (partition_utils , 'get_labelled_partition' ,
669
670
autospec = True )
670
671
@mock .patch .object (partition_utils , 'get_configdrive' ,
671
672
autospec = True )
672
673
def test_create_partition_gpt (self , mock_get_configdrive ,
673
674
mock_get_labelled_partition ,
674
- mock_list_partitions , mock_table_type ,
675
+ mock_get_partition_by_uuid ,
676
+ mock_table_type ,
675
677
mock_fix_gpt_partition ,
676
678
mock_dd , mock_unlink , mock_execute ):
677
679
config_url = 'http://1.2.3.4/cd'
678
680
configdrive_file = '/tmp/xyz'
679
681
configdrive_mb = 10
680
682
681
- initial_partitions = [{'end' : 49152 , 'number' : 1 , 'start' : 1 ,
682
- 'flags' : 'boot' , 'filesystem' : 'ext4' ,
683
- 'size' : 49151 },
684
- {'end' : 51099 , 'number' : 3 , 'start' : 49153 ,
685
- 'flags' : '' , 'filesystem' : '' , 'size' : 2046 },
686
- {'end' : 51099 , 'number' : 5 , 'start' : 49153 ,
687
- 'flags' : '' , 'filesystem' : '' , 'size' : 2046 }]
688
- updated_partitions = [{'end' : 49152 , 'number' : 1 , 'start' : 1 ,
689
- 'flags' : 'boot' , 'filesystem' : 'ext4' ,
690
- 'size' : 49151 },
691
- {'end' : 51099 , 'number' : 3 , 'start' : 49153 ,
692
- 'flags' : '' , 'filesystem' : '' , 'size' : 2046 },
693
- {'end' : 51099 , 'number' : 4 , 'start' : 49153 ,
694
- 'flags' : '' , 'filesystem' : '' , 'size' : 2046 },
695
- {'end' : 51099 , 'number' : 5 , 'start' : 49153 ,
696
- 'flags' : '' , 'filesystem' : '' , 'size' : 2046 }]
697
-
698
683
mock_get_configdrive .return_value = (configdrive_mb , configdrive_file )
699
684
mock_get_labelled_partition .return_value = None
700
685
701
686
mock_table_type .return_value = 'gpt'
702
- mock_list_partitions .side_effect = [initial_partitions ,
703
- updated_partitions ]
704
687
expected_part = '/dev/fake4'
688
+ mock_get_partition_by_uuid .return_value = expected_part
705
689
partition_utils .create_config_drive_partition (self .node_uuid , self .dev ,
706
690
config_url )
707
691
mock_execute .assert_has_calls ([
708
- mock .call ('sgdisk' , '-n' , '0:-64MB:0' , self . dev ,
709
- run_as_root = True ),
692
+ mock .call ('sgdisk' , '-n' , '0:-64MB:0' , '-u' , '0:fake-uuid' ,
693
+ self . dev , run_as_root = True ),
710
694
mock .call ('sync' ),
711
695
mock .call ('udevadm' , 'settle' ),
712
696
mock .call ('partprobe' , self .dev , attempts = 10 , run_as_root = True ),
@@ -717,7 +701,6 @@ def test_create_partition_gpt(self, mock_get_configdrive,
717
701
delay_on_retry = True )
718
702
])
719
703
720
- self .assertEqual (2 , mock_list_partitions .call_count )
721
704
mock_table_type .assert_called_with (self .dev )
722
705
mock_fix_gpt_partition .assert_called_with (self .dev , self .node_uuid )
723
706
mock_dd .assert_called_with (configdrive_file , expected_part )
0 commit comments