| 1 |
from unittest.mock import patch |
| 2 |
from pytest import raises |
| 3 |
|
| 4 |
from kiwi.boxbuild.box_config import BoxConfig |
| 5 |
from kiwi.exceptions import ( |
| 6 |
KiwiBoxConfigError, |
| 7 |
KiwiBoxNameError, |
| 8 |
KiwiBoxArchNotFoundError |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
class TestBoxConfig: |
| 13 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 14 |
@patch('platform.machine') |
| 15 |
def setup(self, mock_platform_machine, mock_get_box_config_file): |
| 16 |
mock_platform_machine.return_value = 'x86_64' |
| 17 |
mock_get_box_config_file.return_value = \ |
| 18 |
'../data/boxbuild/kiwi_boxed_plugin.yml' |
| 19 |
self.box_config = BoxConfig('suse') |
| 20 |
|
| 21 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 22 |
@patch('platform.machine') |
| 23 |
def setup_method( |
| 24 |
self, cls, mock_platform_machine, mock_get_box_config_file |
| 25 |
): |
| 26 |
self.setup() |
| 27 |
|
| 28 |
@patch('yaml.safe_load') |
| 29 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 30 |
def test_setup_raises_on_load_config( |
| 31 |
self, mock_get_box_config_file, mock_yaml_safe_load |
| 32 |
): |
| 33 |
mock_get_box_config_file.return_value = \ |
| 34 |
'../data/boxbuild/kiwi_boxed_plugin.yml' |
| 35 |
mock_yaml_safe_load.side_effect = Exception |
| 36 |
with raises(KiwiBoxConfigError): |
| 37 |
BoxConfig('suse') |
| 38 |
|
| 39 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 40 |
def test_setup_raises_on_unsupported_arch( |
| 41 |
self, mock_get_box_config_file |
| 42 |
): |
| 43 |
mock_get_box_config_file.return_value = \ |
| 44 |
'../data/boxbuild/kiwi_boxed_plugin.yml' |
| 45 |
with raises(KiwiBoxArchNotFoundError): |
| 46 |
BoxConfig('suse', 'artificial_arch') |
| 47 |
|
| 48 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 49 |
def test_setup_raises_box_not_found(self, mock_get_box_config_file): |
| 50 |
mock_get_box_config_file.return_value = \ |
| 51 |
'../data/boxbuild/kiwi_boxed_plugin.yml' |
| 52 |
with raises(KiwiBoxNameError): |
| 53 |
self.box_config = BoxConfig('foo', 'x86_64') |
| 54 |
|
| 55 |
def test_get_box_arch(self): |
| 56 |
assert self.box_config.get_box_arch() == 'x86_64' |
| 57 |
|
| 58 |
def test_get_box_memory_mbytes(self): |
| 59 |
assert self.box_config.get_box_memory_mbytes() == '8096M' |
| 60 |
|
| 61 |
def test_get_box_console(self): |
| 62 |
assert self.box_config.get_box_console() == 'hvc0' |
| 63 |
|
| 64 |
def test_get_box_kernel_cmdline(self): |
| 65 |
assert self.box_config.get_box_kernel_cmdline() == \ |
| 66 |
'root=/dev/vda1 rd.plymouth=0' |
| 67 |
|
| 68 |
def test_get_box_source(self): |
| 69 |
assert self.box_config.get_box_source() == \ |
| 70 |
'obs://Virtualization:Appliances:SelfContained:suse/images' |
| 71 |
|
| 72 |
def test_get_box_packages_file(self): |
| 73 |
assert self.box_config.get_box_packages_file() == \ |
| 74 |
'SUSE-Box.x86_64-1.42.1-System-BuildBox.report' |
| 75 |
|
| 76 |
def test_get_box_packages_shasum_file(self): |
| 77 |
assert self.box_config.get_box_packages_shasum_file() == \ |
| 78 |
'SUSE-Box.x86_64-1.42.1-System-BuildBox.report.sha256' |
| 79 |
|
| 80 |
def test_get_box_files(self): |
| 81 |
assert self.box_config.get_box_files() == [ |
| 82 |
'SUSE-Box.x86_64-1.42.1-Kernel-BuildBox.tar.xz', |
| 83 |
'SUSE-Box.x86_64-1.42.1-Kernel-BuildBox.tar.xz.sha256', |
| 84 |
'SUSE-Box.x86_64-1.42.1-System-BuildBox.qcow2', |
| 85 |
'SUSE-Box.x86_64-1.42.1-System-BuildBox.qcow2.sha256' |
| 86 |
] |