def __new__(self, table_type, storage_provider): # noqa: C901 host_architecture = platform.machine() if host_architecture == 'x86_64': if table_type == 'gpt': return PartitionerGpt(storage_provider) elif table_type == 'msdos': return PartitionerMsDos(storage_provider) elif host_architecture == 'i686' or host_architecture == 'i586': if table_type == 'msdos': return PartitionerMsDos(storage_provider) elif 'ppc64' in host_architecture: if table_type == 'gpt': return PartitionerGpt(storage_provider) elif table_type == 'msdos': return PartitionerMsDos(storage_provider) elif 's390' in host_architecture: if table_type == 'dasd': return PartitionerDasd(storage_provider) elif table_type == 'msdos': return PartitionerMsDos(storage_provider) elif 'arm' in host_architecture or host_architecture == 'aarch64': if table_type == 'gpt': return PartitionerGpt(storage_provider) elif table_type == 'msdos': return PartitionerMsDos(storage_provider) raise KiwiPartitionerSetupError( 'Support for partitioner on %s architecture not implemented' % host_architecture)
def test_create_custom_start_sector(self, mock_flag, mock_command): disk_provider = Mock() disk_provider.get_device = Mock(return_value='/dev/loop0') partitioner = PartitionerGpt(disk_provider, 4096) partitioner.create('name', 100, 't.linux', ['t.csm']) partitioner.create('name', 100, 't.linux', ['t.csm']) mock_command.assert_has_calls([ call( ['sgdisk', '-n', '1:4096:+100M', '-c', '1:name', '/dev/loop0']), call(['sgdisk', '-n', '2:0:+100M', '-c', '2:name', '/dev/loop0']) ]) assert mock_flag.call_args_list[0] == \ call(1, 't.linux') assert mock_flag.call_args_list[1] == \ call(1, 't.csm')
def test_create_custom_start_sector(self, mock_flag, mock_command): disk_provider = mock.Mock() disk_provider.get_device = mock.Mock( return_value='/dev/loop0' ) partitioner = PartitionerGpt(disk_provider, 4096) partitioner.create('name', 100, 't.linux', ['t.csm']) partitioner.create('name', 100, 't.linux', ['t.csm']) mock_command.assert_has_calls([ call([ 'sgdisk', '-n', '1:4096:+100M', '-c', '1:name', '/dev/loop0' ]), call([ 'sgdisk', '-n', '2:0:+100M', '-c', '2:name', '/dev/loop0' ]) ]) assert mock_flag.call_args_list[0] == \ call(1, 't.linux') assert mock_flag.call_args_list[1] == \ call(1, 't.csm')
def __new__(self, table_type, storage_provider, start_sector=None): # noqa: C901 host_architecture = platform.machine() if host_architecture == 'x86_64': if table_type == 'gpt': return PartitionerGpt(storage_provider, start_sector) elif table_type == 'msdos': return PartitionerMsDos(storage_provider, start_sector) elif host_architecture == 'i686' or host_architecture == 'i586': if table_type == 'msdos': return PartitionerMsDos(storage_provider, start_sector) elif 'ppc64' in host_architecture: if table_type == 'gpt': return PartitionerGpt(storage_provider, start_sector) elif table_type == 'msdos': return PartitionerMsDos(storage_provider, start_sector) elif 's390' in host_architecture: if table_type == 'dasd': if start_sector: log.warning('disk_start_sector value is ignored ' 'for dasd partitions') return PartitionerDasd(storage_provider) elif table_type == 'msdos': return PartitionerMsDos(storage_provider, start_sector) elif 'arm' in host_architecture or host_architecture == 'aarch64': if table_type == 'gpt': return PartitionerGpt(storage_provider, start_sector) elif table_type == 'msdos': return PartitionerMsDos(storage_provider, start_sector) raise KiwiPartitionerSetupError( 'Support for partitioner on %s architecture not implemented' % host_architecture)
def setup(self): disk_provider = mock.Mock() disk_provider.get_device = mock.Mock(return_value='/dev/loop0') self.partitioner = PartitionerGpt(disk_provider)
class TestPartitionerGpt(object): def setup(self): disk_provider = mock.Mock() disk_provider.get_device = mock.Mock(return_value='/dev/loop0') self.partitioner = PartitionerGpt(disk_provider) @patch('kiwi.partitioner.gpt.Command.run') @patch('kiwi.partitioner.gpt.PartitionerGpt.set_flag') def test_create(self, mock_flag, mock_command): self.partitioner.create('name', 100, 't.linux', ['t.csm']) mock_command.assert_called_once_with( ['sgdisk', '-n', '1:0:+100M', '-c', '1:name', '/dev/loop0']) call = mock_flag.call_args_list[0] assert mock_flag.call_args_list[0] == \ call(1, 't.linux') call = mock_flag.call_args_list[1] assert mock_flag.call_args_list[1] == \ call(1, 't.csm') @patch('kiwi.partitioner.gpt.Command.run') @patch('kiwi.partitioner.gpt.PartitionerGpt.set_flag') def test_create_all_free(self, mock_flag, mock_command): self.partitioner.create('name', 'all_free', 't.linux') mock_command.assert_called_once_with( ['sgdisk', '-n', '1:0:0', '-c', '1:name', '/dev/loop0']) @raises(KiwiPartitionerGptFlagError) def test_set_flag_invalid(self): self.partitioner.set_flag(1, 'foo') @patch('kiwi.partitioner.gpt.Command.run') def test_set_flag(self, mock_command): self.partitioner.set_flag(1, 't.csm') mock_command.assert_called_once_with( ['sgdisk', '-t', '1:EF02', '/dev/loop0']) @patch('kiwi.logger.log.warning') def test_set_flag_ignored(self, mock_warn): self.partitioner.set_flag(1, 'f.active') assert mock_warn.called @patch('kiwi.partitioner.gpt.Command.run') def test_set_hybrid_mbr(self, mock_command): self.partitioner.partition_id = 5 self.partitioner.set_hybrid_mbr() mock_command.assert_called_once_with( ['sgdisk', '-h', '1:2:3', '/dev/loop0'])
def setup(self): disk_provider = mock.Mock() disk_provider.get_device = mock.Mock( return_value='/dev/loop0' ) self.partitioner = PartitionerGpt(disk_provider)
class TestPartitionerGpt(object): def setup(self): disk_provider = mock.Mock() disk_provider.get_device = mock.Mock( return_value='/dev/loop0' ) self.partitioner = PartitionerGpt(disk_provider) @patch('kiwi.partitioner.gpt.Command.run') @patch('kiwi.partitioner.gpt.PartitionerGpt.set_flag') def test_create(self, mock_flag, mock_command): self.partitioner.create('name', 100, 't.linux', ['t.csm']) mock_command.assert_called_once_with( ['sgdisk', '-n', '1:0:+100M', '-c', '1:name', '/dev/loop0'] ) call = mock_flag.call_args_list[0] assert mock_flag.call_args_list[0] == \ call(1, 't.linux') call = mock_flag.call_args_list[1] assert mock_flag.call_args_list[1] == \ call(1, 't.csm') @patch('kiwi.partitioner.gpt.Command.run') @patch('kiwi.partitioner.gpt.PartitionerGpt.set_flag') def test_create_custom_start_sector(self, mock_flag, mock_command): disk_provider = mock.Mock() disk_provider.get_device = mock.Mock( return_value='/dev/loop0' ) partitioner = PartitionerGpt(disk_provider, 4096) partitioner.create('name', 100, 't.linux', ['t.csm']) partitioner.create('name', 100, 't.linux', ['t.csm']) mock_command.assert_has_calls([ call([ 'sgdisk', '-n', '1:4096:+100M', '-c', '1:name', '/dev/loop0' ]), call([ 'sgdisk', '-n', '2:0:+100M', '-c', '2:name', '/dev/loop0' ]) ]) assert mock_flag.call_args_list[0] == \ call(1, 't.linux') assert mock_flag.call_args_list[1] == \ call(1, 't.csm') @patch('kiwi.partitioner.gpt.Command.run') @patch('kiwi.partitioner.gpt.PartitionerGpt.set_flag') def test_create_all_free(self, mock_flag, mock_command): self.partitioner.create('name', 'all_free', 't.linux') mock_command.assert_called_once_with( ['sgdisk', '-n', '1:0:0', '-c', '1:name', '/dev/loop0'] ) @raises(KiwiPartitionerGptFlagError) def test_set_flag_invalid(self): self.partitioner.set_flag(1, 'foo') @patch('kiwi.partitioner.gpt.Command.run') def test_set_flag(self, mock_command): self.partitioner.set_flag(1, 't.csm') mock_command.assert_called_once_with( ['sgdisk', '-t', '1:EF02', '/dev/loop0'] ) @patch('kiwi.logger.log.warning') def test_set_flag_ignored(self, mock_warn): self.partitioner.set_flag(1, 'f.active') assert mock_warn.called @patch('kiwi.partitioner.gpt.Command.run') def test_set_hybrid_mbr(self, mock_command): self.partitioner.partition_id = 5 self.partitioner.set_hybrid_mbr() mock_command.assert_called_once_with( ['sgdisk', '-h', '1:2:3', '/dev/loop0'] ) @patch('kiwi.partitioner.gpt.Command.run') def test_set_mbr(self, mock_command): command_output = mock.Mock() command_output.output = '...(EFI System)' self.partitioner.partition_id = 4 mock_command.return_value = command_output self.partitioner.set_mbr() assert mock_command.call_args_list == [ call(['sgdisk', '-i=1', '/dev/loop0']), call(['sgdisk', '-i=2', '/dev/loop0']), call(['sgdisk', '-i=3', '/dev/loop0']), call(['sgdisk', '-i=4', '/dev/loop0']), call(['sgdisk', '-m', '1:2:3:4', '/dev/loop0']), call(['sgdisk', '-t', '4:8300', '/dev/loop0']) ] @patch('kiwi.partitioner.gpt.Command.run') def test_resize_table(self, mock_command): self.partitioner.resize_table(42) mock_command.assert_called_once_with( ['sgdisk', '--resize-table', '42', '/dev/loop0'] )
class TestPartitionerGpt(object): def setup(self): disk_provider = mock.Mock() disk_provider.get_device = mock.Mock(return_value="/dev/loop0") self.partitioner = PartitionerGpt(disk_provider) @patch("kiwi.partitioner.gpt.Command.run") @patch("kiwi.partitioner.gpt.PartitionerGpt.set_flag") def test_create(self, mock_flag, mock_command): self.partitioner.create("name", 100, "t.linux", ["t.csm"]) mock_command.assert_called_once_with(["sgdisk", "-n", "1:0:+100M", "-c", "1:name", "/dev/loop0"]) call = mock_flag.call_args_list[0] assert mock_flag.call_args_list[0] == call(1, "t.linux") call = mock_flag.call_args_list[1] assert mock_flag.call_args_list[1] == call(1, "t.csm") @patch("kiwi.partitioner.gpt.Command.run") @patch("kiwi.partitioner.gpt.PartitionerGpt.set_flag") def test_create_all_free(self, mock_flag, mock_command): self.partitioner.create("name", "all_free", "t.linux") mock_command.assert_called_once_with(["sgdisk", "-n", "1:0:0", "-c", "1:name", "/dev/loop0"]) @raises(KiwiPartitionerGptFlagError) def test_set_flag_invalid(self): self.partitioner.set_flag(1, "foo") @patch("kiwi.partitioner.gpt.Command.run") def test_set_flag(self, mock_command): self.partitioner.set_flag(1, "t.csm") mock_command.assert_called_once_with(["sgdisk", "-t", "1:EF02", "/dev/loop0"]) @patch("kiwi.logger.log.warning") def test_set_flag_ignored(self, mock_warn): self.partitioner.set_flag(1, "f.active") assert mock_warn.called @patch("kiwi.partitioner.gpt.Command.run") def test_set_hybrid_mbr(self, mock_command): self.partitioner.partition_id = 5 self.partitioner.set_hybrid_mbr() mock_command.assert_called_once_with(["sgdisk", "-h", "1:2:3", "/dev/loop0"])