Skip to content

Commit

Permalink
Merge pull request #64 from OSInside/support_console_setting
Browse files Browse the repository at this point in the history
Add support for --box-console
  • Loading branch information
schaefi authored Feb 9, 2024
2 parents b397cf7 + 2d1efc1 commit eac92af
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
6 changes: 6 additions & 0 deletions doc/source/commands/system_boxbuild.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SYNOPSIS
kiwi-ng system boxbuild -h | --help
kiwi-ng system boxbuild --box=<name>
[--box-memory=<vmgb>]
[--box-console=<ttyname>]
[--box-smp-cpus=<number>]
[--box-debug]
[--kiwi-version=<version>]
Expand Down Expand Up @@ -75,6 +76,11 @@ OPTIONS
Number of GBs to reserve as main memory for the virtual
machine. By default 8GB will be used.

--box-console=<ttyname>

Name of console in the kernel settings for the virtual
machine. By default set to hvc0.

--box-smp-cpus=<number>

Number of CPUs to use in the SMP setup. By default
Expand Down
8 changes: 7 additions & 1 deletion kiwi_boxed_plugin/box_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BoxBuild:
:param str boxname: name of the box from kiwi_boxed_plugin.yml
:param str ram: amount of main memory to use for the box
:param str console: console name for the box kernel
:param str smp: number of CPUs to use in the SMP setup for the box
:param str arch: arch name for box
:param str machine: machine emulaton type for the box
Expand All @@ -58,12 +59,13 @@ class BoxBuild:
:param str ssh_port: host port number to use to forward the guest's SSH port
"""
def __init__(
self, boxname: str, ram: str = '', smp: str = '',
self, boxname: str, ram: str = '', console: str = '', smp: str = '',
arch: str = '', machine: str = '', cpu: str = 'host',
sharing_backend: str = '9p', ssh_key: str = 'id_rsa',
ssh_port: str = '', accel: bool = True
) -> None:
self.ram = ram
self.console = console
self.smp = smp
self.cpu = cpu
self.machine = machine
Expand Down Expand Up @@ -111,6 +113,10 @@ def run(
vm_setup.append,
'kiwi=\\"{0}\\"'.format(' '.join(self.kiwi_build_command))
]
if self.console:
vm_append[0] = vm_append[0].replace(
f'console={vm_setup.console}', f'console={self.console}'
)
if keep_open:
vm_append.append('kiwi-no-halt')
if kiwi_version:
Expand Down
2 changes: 2 additions & 0 deletions kiwi_boxed_plugin/box_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
('kernel', str),
('initrd', str),
('append', str),
('console', str),
('ram', str),
('smp', str)
]
Expand Down Expand Up @@ -147,6 +148,7 @@ def fetch(self, update_check: bool = True) -> vm_setup_type:
self.box_config.get_box_console(),
self.box_config.get_box_kernel_cmdline()
),
console=self.box_config.get_box_console(),
ram=self.box_config.get_box_memory_mbytes(),
smp=self.box_config.get_box_processors()
)
Expand Down
6 changes: 6 additions & 0 deletions kiwi_boxed_plugin/tasks/system_boxbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
usage: kiwi-ng system boxbuild -h | --help
kiwi-ng system boxbuild --box=<name>
[--box-memory=<vmgb>]
[--box-console=<ttyname>]
[--box-smp-cpus=<number>]
[--box-debug]
[--kiwi-version=<version>]
Expand Down Expand Up @@ -54,6 +55,10 @@
Number of GBs to reserve as main memory for the virtual
machine. By default 8GB will be used.
--box-console=<ttyname>
Name of console in the kernel settings for the virtual
machine. By default set to hvc0.
--box-smp-cpus=<number>
Number of CPUs to use in the SMP setup. By default
4 CPUs will be used
Expand Down Expand Up @@ -173,6 +178,7 @@ def process(self) -> None:
box_build = BoxBuild(
boxname=self.command_args.get('--box'),
ram=self.command_args.get('--box-memory'),
console=self.command_args.get('--box-console'),
smp=self.command_args.get('--box-smp-cpus'),
arch=self._get_box_arch(),
machine=self.command_args.get('--machine'),
Expand Down
14 changes: 8 additions & 6 deletions test/unit/box_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def setup(self, mock_BoxDownload):
self.box = Mock()
self.vm_setup = Mock()
self.vm_setup.kernel = 'kernel'
self.vm_setup.append = 'append'
self.vm_setup.append = 'console=hvc0'
self.vm_setup.system = 'system'
self.vm_setup.initrd = 'initrd'
self.vm_setup.console = 'hvc0'
self.vm_setup.ram = 4096
self.vm_setup.smp = 4
self.box.fetch.return_value = self.vm_setup
Expand All @@ -36,7 +37,8 @@ def setup(self, mock_BoxDownload):
)
self.build_arm = BoxBuild(
boxname='universal', arch='aarch64',
machine='virt', cpu='cortex-a57'
machine='virt', cpu='cortex-a57',
console='ttyAMA0'
)

@patch('kiwi_boxed_plugin.box_build.BoxDownload')
Expand Down Expand Up @@ -106,7 +108,7 @@ def test_run_with_9p_sharing(
'-nodefaults '
'-snapshot '
'-kernel kernel '
'-append "append kiwi=\\"--debug --type oem system build\\"'
'-append "console=hvc0 kiwi=\\"--debug --type oem system build\\"'
' kiwi-no-halt kiwi_version=_9.22.1_'
' custom_mount=_/var/tmp/repos_'
' sharing_backend=_9p_" '
Expand Down Expand Up @@ -158,7 +160,7 @@ def test_run_cross_arch_aarch64_on_x86_64(
'-nodefaults '
'-snapshot '
'-kernel kernel '
'-append "append kiwi=\\"--type oem system build\\"'
'-append "console=ttyAMA0 kiwi=\\"--type oem system build\\"'
' kiwi-no-halt kiwi_version=_9.22.1_'
' custom_mount=_/var/tmp/repos_'
' sharing_backend=_9p_" '
Expand Down Expand Up @@ -281,7 +283,7 @@ def path_which(name, lookup=None):
'-nodefaults '
'-snapshot '
'-kernel kernel '
'-append "append kiwi=\\"--type oem system build\\"'
'-append "console=hvc0 kiwi=\\"--type oem system build\\"'
' kiwi-no-halt kiwi_version=_9.22.1_'
' custom_mount=_var/tmp/repos_'
' sharing_backend=_virtiofs_" '
Expand Down Expand Up @@ -390,7 +392,7 @@ def path_which(name, lookup=None):
'-nodefaults '
'-snapshot '
'-kernel kernel '
'-append "append kiwi=\\"--type oem system build\\"'
'-append "console=hvc0 kiwi=\\"--type oem system build\\"'
' kiwi-no-halt kiwi_version=_9.22.1_'
' custom_mount=_var/tmp/repos_'
' ssh_key=_key_value_'
Expand Down
1 change: 1 addition & 0 deletions test/unit/box_download_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setup(self, mock_DirFiles, mock_Path, mock_get_plugin_config_file):
kernel='HOME/.kiwi_boxes/suse/kernel.x86_64',
initrd='HOME/.kiwi_boxes/suse/initrd.x86_64',
append='console=hvc0 root=/dev/vda1 rd.plymouth=0',
console='hvc0',
ram=8096,
smp=4
)
Expand Down
28 changes: 17 additions & 11 deletions test/unit/tasks/system_boxbuild_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def setup(self):
sys.argv[0],
'--debug', '--profile', 'foo', '--type', 'oem',
'system', 'boxbuild',
'--box', 'suse', '--box-memory', '4', '--box-smp-cpus', '4', '--',
'--box', 'universal',
'--box-memory', '4',
'--box-console', 'ttyAMA0',
'--box-smp-cpus', '4',
'--',
'--description', '../data/description',
'--target-dir', '../data/target_dir'
]
Expand Down Expand Up @@ -69,12 +73,12 @@ def test_process_system_boxbuild_list_boxes(self, mock_PluginConfig):
def test_process_system_boxbuild(self, mock_BoxBuild):
self._init_command_args()
self.task.command_args['boxbuild'] = True
self.task.command_args['--box'] = 'suse'
self.task.command_args['--box'] = 'universal'
box_build = Mock()
mock_BoxBuild.return_value = box_build
self.task.process()
mock_BoxBuild.assert_called_once_with(
boxname='suse', ram=None, smp=None, arch='',
boxname='universal', ram=None, console=None, smp=None, arch='',
machine=None, cpu='host', sharing_backend='9p',
ssh_key='id_rsa', ssh_port='22', accel=True
)
Expand All @@ -92,13 +96,14 @@ def test_process_system_boxbuild(self, mock_BoxBuild):
def test_process_system_boxbuild_for_x86_64(self, mock_BoxBuild):
self._init_command_args()
self.task.command_args['boxbuild'] = True
self.task.command_args['--box'] = 'suse'
self.task.command_args['--box'] = 'universal'
self.task.command_args['--x86_64'] = True
box_build = Mock()
mock_BoxBuild.return_value = box_build
self.task.process()
mock_BoxBuild.assert_called_once_with(
boxname='suse', ram=None, smp=None, arch='x86_64',
boxname='universal',
ram=None, console=None, smp=None, arch='x86_64',
machine=None, cpu='host', sharing_backend='9p',
ssh_key='id_rsa', ssh_port='22', accel=True
)
Expand All @@ -107,13 +112,14 @@ def test_process_system_boxbuild_for_x86_64(self, mock_BoxBuild):
def test_process_system_boxbuild_for_aarch64(self, mock_BoxBuild):
self._init_command_args()
self.task.command_args['boxbuild'] = True
self.task.command_args['--box'] = 'suse'
self.task.command_args['--box'] = 'universal'
self.task.command_args['--aarch64'] = True
box_build = Mock()
mock_BoxBuild.return_value = box_build
self.task.process()
mock_BoxBuild.assert_called_once_with(
boxname='suse', ram=None, smp=None, arch='aarch64',
boxname='universal',
ram=None, console=None, smp=None, arch='aarch64',
machine=None, cpu='host', sharing_backend='9p',
ssh_key='id_rsa', ssh_port='22', accel=True
)
Expand All @@ -122,13 +128,13 @@ def test_process_system_boxbuild_for_aarch64(self, mock_BoxBuild):
def test_process_system_boxbuild_with_sharing_backend(self, mock_BoxBuild):
self._init_command_args()
self.task.command_args['boxbuild'] = True
self.task.command_args['--box'] = 'suse'
self.task.command_args['--box'] = 'universal'
self.task.command_args['--9p-sharing'] = True
box_build = Mock()
mock_BoxBuild.return_value = box_build
self.task.process()
mock_BoxBuild.assert_called_once_with(
boxname='suse', ram=None, smp=None, arch='',
boxname='universal', ram=None, console=None, smp=None, arch='',
machine=None, cpu='host', sharing_backend='9p',
ssh_key='id_rsa', ssh_port='22', accel=True
)
Expand All @@ -137,7 +143,7 @@ def test_process_system_boxbuild_with_sharing_backend(self, mock_BoxBuild):
mock_BoxBuild.reset_mock()
self.task.process()
mock_BoxBuild.assert_called_once_with(
boxname='suse', ram=None, smp=None, arch='',
boxname='universal', ram=None, console=None, smp=None, arch='',
machine=None, cpu='host', sharing_backend='virtiofs',
ssh_key='id_rsa', ssh_port='22', accel=True
)
Expand All @@ -147,7 +153,7 @@ def test_process_system_boxbuild_with_sharing_backend(self, mock_BoxBuild):
mock_BoxBuild.reset_mock()
self.task.process()
mock_BoxBuild.assert_called_once_with(
boxname='suse', ram=None, smp=None, arch='',
boxname='universal', ram=None, console=None, smp=None, arch='',
machine=None, cpu='host', sharing_backend='sshfs',
ssh_key='id_rsa', ssh_port='22', accel=True
)

0 comments on commit eac92af

Please sign in to comment.