Honor custom CLI defaults in guided VM creation
This commit is contained in:
@@ -112,3 +112,48 @@ class CLITests(unittest.TestCase):
|
||||
self.assertNotIn('supersecret', result.stderr)
|
||||
self.assertNotIn('private', result.stderr)
|
||||
self.assertNotIn('Traceback', result.stderr)
|
||||
|
||||
def guided_defaults_profile(self, command):
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
from hydra.cli import main
|
||||
from hydra.runtime import Runtime
|
||||
from test_media import iso_bytes
|
||||
from test_runtime import FAKE_IMG, FAKE_QEMU
|
||||
|
||||
self.defaults.write_text('network="bridge"\nbridge="testbr0"\nwidth=1600\nheight=900\nrefresh_millihz=75000\n')
|
||||
iso = self.root / 'guided.iso'
|
||||
iso.write_bytes(iso_bytes())
|
||||
qemu = self.root / 'fake-qemu'
|
||||
qemu.write_text(FAKE_QEMU); qemu.chmod(0o700)
|
||||
image = self.root / 'fake-img'
|
||||
image.write_text(FAKE_IMG); image.chmod(0o700)
|
||||
viewer = self.root / 'fake-viewer'
|
||||
viewer.write_text('#!/bin/sh\necho --hide-toolbar\n'); viewer.chmod(0o700)
|
||||
runtime = Runtime(self.root / 'config', self.root / 'state', self.root / 'run')
|
||||
def cleanup():
|
||||
if runtime.status('guided')['status'] == 'running':
|
||||
runtime.stop('guided', force=True)
|
||||
self.addCleanup(cleanup)
|
||||
inputs = [':run ' + str(iso), 'guided', '512', '1', '8M', '', ':quit']
|
||||
with patch.dict(os.environ, {'HYDRA_QEMU': str(qemu), 'HYDRA_QEMU_IMG': str(image),
|
||||
'HYDRA_VIEWER': str(viewer), 'WAYLAND_DISPLAY': 'unused',
|
||||
'HYDRA_SESSION_MANIFEST': ''}), \
|
||||
patch('sys.stdin.isatty', return_value=True), patch('builtins.input', side_effect=inputs), \
|
||||
patch('hydra.launch.available_memory_mib', return_value=8192), \
|
||||
patch('hydra.session.view', return_value=0), contextlib.redirect_stdout(io.StringIO()):
|
||||
self.assertEqual(main(self.base[2:] + command), 0)
|
||||
self.assertEqual(runtime.status('guided')['status'], 'running')
|
||||
return runtime.profile('guided')
|
||||
|
||||
def test_menu_guided_run_honors_cli_custom_network_and_display_defaults(self):
|
||||
profile = self.guided_defaults_profile(['menu'])
|
||||
self.assertEqual((profile.network, profile.bridge, profile.width, profile.height, profile.refresh_millihz),
|
||||
('bridge', 'testbr0', 1600, 900, 75000))
|
||||
|
||||
def test_plain_interactive_guided_run_honors_cli_custom_network_and_display_defaults(self):
|
||||
profile = self.guided_defaults_profile([])
|
||||
self.assertEqual((profile.network, profile.bridge, profile.width, profile.height, profile.refresh_millihz),
|
||||
('bridge', 'testbr0', 1600, 900, 75000))
|
||||
|
||||
Reference in New Issue
Block a user