Coverage for mlos_bench/mlos_bench/config/environments/os/linux/boot/scripts/local/create_new_grub_cfg.py: 57%

7 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-01 00:52 +0000

1#!/usr/bin/env python3 

2# 

3# Copyright (c) Microsoft Corporation. 

4# Licensed under the MIT License. 

5# 

6""" 

7Python script to parse through JSON and create new config file. 

8 

9This script will be run in the SCHEDULER. NEW_CFG will need to be copied over to the VM 

10(/etc/default/grub.d). 

11""" 

12import json 

13 

14JSON_CONFIG_FILE = "config-boot-time.json" 

15NEW_CFG = "zz-mlos-boot-params.cfg" 

16 

17 

18def _write_config() -> None: 

19 with ( 

20 open(JSON_CONFIG_FILE, encoding="UTF-8") as fh_json, 

21 open(NEW_CFG, "w", encoding="UTF-8") as fh_config, 

22 ): 

23 for key, val in json.load(fh_json).items(): 

24 fh_config.write( 

25 'GRUB_CMDLINE_LINUX_DEFAULT="$' f'{ GRUB_CMDLINE_LINUX_DEFAULT} {key}={val}"\n' 

26 ) 

27 

28 

29if __name__ == "__main__": 

30 _write_config()