| 1 |
import yaml |
| 2 |
from unittest.mock import patch |
| 3 |
from pytest import raises |
| 4 |
|
| 5 |
from kiwi.boxbuild.boxes_config import BoxesConfig |
| 6 |
from kiwi.exceptions import KiwiBoxConfigError |
| 7 |
|
| 8 |
|
| 9 |
class TestBoxesConfig: |
| 10 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 11 |
def setup(self, mock_get_box_config_file): |
| 12 |
mock_get_box_config_file.return_value = \ |
| 13 |
'../data/boxbuild/kiwi_boxed_plugin.yml' |
| 14 |
self.plugin_config = BoxesConfig() |
| 15 |
|
| 16 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 17 |
def setup_method(self, cls, mock_get_box_config_file): |
| 18 |
self.setup() |
| 19 |
|
| 20 |
@patch('kiwi.boxbuild.defaults.BoxBuildDefaults.get_box_config_file') |
| 21 |
def test_invalid_config(self, mock_get_box_config_file): |
| 22 |
mock_get_box_config_file.return_value = \ |
| 23 |
'../data/boxbuild/kiwi_boxed_plugin_invalid.yml' |
| 24 |
with raises(KiwiBoxConfigError): |
| 25 |
BoxesConfig() |
| 26 |
|
| 27 |
def test_get_config(self): |
| 28 |
assert self.plugin_config.get_config() == [ |
| 29 |
{ |
| 30 |
'name': 'suse', |
| 31 |
'mem_mb': '8096M', |
| 32 |
'processors': 4, |
| 33 |
'console': 'hvc0', |
| 34 |
'arch': [ |
| 35 |
{ |
| 36 |
'name': 'x86_64', |
| 37 |
'cmdline': ['root=/dev/vda1', 'rd.plymouth=0'], |
| 38 |
'source': |
| 39 |
'obs://Virtualization:Appliances:SelfContained:' |
| 40 |
'suse/images', |
| 41 |
'packages_file': |
| 42 |
'SUSE-Box.x86_64-1.42.1-System-BuildBox.report', |
| 43 |
'boxfiles': [ |
| 44 |
'SUSE-Box.x86_64-1.42.1-Kernel-BuildBox.tar.xz', |
| 45 |
'SUSE-Box.x86_64-1.42.1-System-BuildBox.qcow2' |
| 46 |
], |
| 47 |
'container': 'some', |
| 48 |
'use_initrd': True |
| 49 |
} |
| 50 |
] |
| 51 |
}, |
| 52 |
{ |
| 53 |
'name': 'universal', |
| 54 |
'mem_mb': '8096M', |
| 55 |
'processors': 4, |
| 56 |
'console': 'hvc0', |
| 57 |
'arch': [ |
| 58 |
{ |
| 59 |
'name': 'x86_64', |
| 60 |
'cmdline': [ |
| 61 |
'root=/dev/vda3', 'rd.plymouth=0', 'selinux=0' |
| 62 |
], |
| 63 |
'source': |
| 64 |
'obs://Virtualization:Appliances:SelfContained:' |
| 65 |
'universal/images', |
| 66 |
'packages_file': |
| 67 |
'Universal-Box.x86_64-1.1.2-System-BuildBox.report', |
| 68 |
'boxfiles': [ |
| 69 |
'Universal-Box.x86_64-1.1.2-Kernel-BuildBox.tar.xz', |
| 70 |
'Universal-Box.x86_64-1.1.2-System-BuildBox.qcow2' |
| 71 |
], |
| 72 |
'container': 'some', |
| 73 |
'use_initrd': True |
| 74 |
}, |
| 75 |
{ |
| 76 |
'name': 'aarch64', |
| 77 |
'cmdline': [ |
| 78 |
'root=/dev/vda2', 'rd.plymouth=0', 'selinux=0' |
| 79 |
], |
| 80 |
'source': |
| 81 |
'obs://Virtualization:Appliances:SelfContained:' |
| 82 |
'universal/images', |
| 83 |
'packages_file': 'Universal-Box.' |
| 84 |
'aarch64-1.1.2-System-BuildBox.report', |
| 85 |
'boxfiles': [ |
| 86 |
'Universal-Box.aarch64-1.1.2-' |
| 87 |
'Kernel-BuildBox.tar.xz', |
| 88 |
'Universal-Box.aarch64-1.1.2-' |
| 89 |
'System-BuildBox.qcow2' |
| 90 |
], |
| 91 |
'container': 'some', |
| 92 |
'use_initrd': True |
| 93 |
} |
| 94 |
] |
| 95 |
} |
| 96 |
] |
| 97 |
|
| 98 |
def test_dump_config(self): |
| 99 |
assert self.plugin_config.dump_config() == yaml.dump( |
| 100 |
self.plugin_config.get_config() |
| 101 |
) |
| 102 |
|
| 103 |
@patch('yaml.safe_load') |
| 104 |
def test_setup_raises(self, mock_yaml_safe_load): |
| 105 |
mock_yaml_safe_load.side_effect = Exception |
| 106 |
with raises(KiwiBoxConfigError): |
| 107 |
BoxesConfig() |