Skip to content
Snippets Groups Projects
Commit a342244c authored by Andrii Sosiuk's avatar Andrii Sosiuk
Browse files

[ACTIONS] add add_include_to_local_conf

  Add action add_include_to_local_conf_opt, which appends "include value" to
  local.conf. Doesn't append anything to local.conf if the value set is empty.
parent 8988bb97
No related branches found
No related tags found
No related merge requests found
Pipeline #259042 passed with stage
in 1 minute and 1 second
...@@ -53,6 +53,7 @@ The association of clusters and actions implemented are written in the table bel ...@@ -53,6 +53,7 @@ The association of clusters and actions implemented are written in the table bel
| CONFIG_LAYERS | add_to_bblayers_conf | | CONFIG_LAYERS | add_to_bblayers_conf |
| CONFIG_FLAVOUR | add_bblayers_conf_cleaos_and_arch | | CONFIG_FLAVOUR | add_bblayers_conf_cleaos_and_arch |
| CONFIG_YS-APPEND | add_append_to_local_conf | | CONFIG_YS-APPEND | add_append_to_local_conf |
| CONFIG_YS-INCLUDE | add_include_to_local_conf |
| CONFIG_YS | add_to_local_conf | | CONFIG_YS | add_to_local_conf |
| CONFIG_ES | modify_files_tree | | CONFIG_ES | modify_files_tree |
| CONFIG_KERNELCFG | add_to_local_conf | | CONFIG_KERNELCFG | add_to_local_conf |
...@@ -170,10 +171,11 @@ For `action` is intended the operation that a specific cluster needs. The `actio ...@@ -170,10 +171,11 @@ For `action` is intended the operation that a specific cluster needs. The `actio
|-------------------------------------|---------------------------------------------------------------| |-------------------------------------|---------------------------------------------------------------|
| `add_to_local_conf` | Adds a variable to `local.conf` | | `add_to_local_conf` | Adds a variable to `local.conf` |
| `add_append_to_local_conf` | Adds a variable to `local.conf` with `+=` assignment | | `add_append_to_local_conf` | Adds a variable to `local.conf` with `+=` assignment |
| `add_include_to_local_conf` | Adds an `include value` statement to `local.conf` |
| `replace_in_local_conf` | Replaces an existing variable in `local.conf` with a new value| | `replace_in_local_conf` | Replaces an existing variable in `local.conf` with a new value|
| `add_to_bblayers_conf` | Adds a layer into the `bblayers.conf` | | `add_to_bblayers_conf` | Adds a layer into the `bblayers.conf` |
| `add_bblayers_conf_cleaos_and_arch` | Adds Clea OS and architecture specific layers | `add_bblayers_conf_cleaos_and_arch` | Adds Clea OS and architecture specific layers |
| `check_machine_conf` | Checks the machine.conf file in the layers tree | | `check_machine_conf` | Checks the machine.conf file in the layers tree |
| `modify_files_tree` | Not implemented yet | | `modify_files_tree` | Not implemented yet |
| `process_rauc_conf` | Not implemented yet | | `process_rauc_conf` | Not implemented yet |
| `do_nothing` | No actions required | | `do_nothing` | No actions required |
...@@ -407,4 +409,4 @@ doxygen doxygen/Doxyfile ...@@ -407,4 +409,4 @@ doxygen doxygen/Doxyfile
The documents are created in the `doxygen` directory. The documents are created in the `doxygen` directory.
# Unit test # Unit test
For unit testing have a look to [`tests/README.md`](./tests/README.md). For unit testing have a look to [`tests/README.md`](./tests/README.md).
\ No newline at end of file
...@@ -17,6 +17,7 @@ CONFIG_CLUSTERS = { ...@@ -17,6 +17,7 @@ CONFIG_CLUSTERS = {
"CONFIG_LAYERS": [ssa.add_to_bblayers_conf], "CONFIG_LAYERS": [ssa.add_to_bblayers_conf],
"CONFIG_FLAVOUR": [ssa.add_bblayers_conf_cleaos_and_arch], "CONFIG_FLAVOUR": [ssa.add_bblayers_conf_cleaos_and_arch],
"CONFIG_YS-APPEND": [ssa.add_append_to_local_conf], "CONFIG_YS-APPEND": [ssa.add_append_to_local_conf],
"CONFIG_YS-INCLUDE": [ssa.add_include_to_local_conf],
"CONFIG_YS": [ssa.add_to_local_conf], "CONFIG_YS": [ssa.add_to_local_conf],
"CONFIG_ES": [ssa.modify_files_tree], "CONFIG_ES": [ssa.modify_files_tree],
"CONFIG_KERNELCFG": [ssa.add_to_local_conf], "CONFIG_KERNELCFG": [ssa.add_to_local_conf],
...@@ -26,4 +27,4 @@ CONFIG_CLUSTERS = { ...@@ -26,4 +27,4 @@ CONFIG_CLUSTERS = {
"CONFIG_CLOUD": [ssa.add_to_local_conf], "CONFIG_CLOUD": [ssa.add_to_local_conf],
"CONFIG_RAUC": [ssa.process_rauc_conf, ssa.add_to_local_conf], "CONFIG_RAUC": [ssa.process_rauc_conf, ssa.add_to_local_conf],
"CONFIG_QEMU": [ssa.add_to_local_conf_opt], "CONFIG_QEMU": [ssa.add_to_local_conf_opt],
} }
\ No newline at end of file
...@@ -134,11 +134,46 @@ def add_append_to_local_conf(build_dir, conf, conf_line, cluster_name, *args): ...@@ -134,11 +134,46 @@ def add_append_to_local_conf(build_dir, conf, conf_line, cluster_name, *args):
else: else:
ssu.eprint(f"Warning: could not add the configuration \"{conf_line}\" in local.conf.") ssu.eprint(f"Warning: could not add the configuration \"{conf_line}\" in local.conf.")
##
# @brief Appends an "include" string to the local.conf file only if a non-empty value is set.
#
# This function adds a new configuration entry to the local.conf file based on the
# provided configuration line. It extracts the variable name and value from the
# configuration line and, if the value is not empty, appends the "include" string to
# the local.conf file in the specified build directory.
#
# @param build_dir The directory where the build is taking place and where the local.conf file is located.
# @param conf The configuration object (not used in this function, but typically contains build configuration data).
# @param conf_line The configuration line containing the variable name and value to be added to local.conf.
# @param cluster_name The name of the cluster (not used in this function, typically used for cluster-specific configurations).
# @param args Additional arguments if needed (not used in this function).
#
# @return None
#
# @details
# - The function constructs the path to the local.conf file using the provided build directory.
# - It extracts the variable name and value from the provided configuration line using the `ssc.extract_value_from_config_line` function.
# - If both the variable name and value are valid, it formats them into a "include value" statement and appends this string to the local.conf file.
# - If the variable name or value is missing, the function logs a warning message and does not modify the file.
# - The variable name is not passed into local.conf file as it is not needed in the include statement.
#
# @note The `conf` and `cluster_name` parameters are not used in this function. Consider removing them if they are not needed.
def add_include_to_local_conf(build_dir, conf, conf_line, cluster_name, *args):
local_conf_path = os.path.abspath(os.path.join(build_dir, "conf/local.conf"))
varname, varval = ssc.extract_value_from_config_line(conf_line)
if varname != None and varval != None:
if varval != "":
string = f"include \"{varval}\""
logger.debug(f"Adding to local.conf -- the string: {string}")
ssu.append_to_file(local_conf_path, string)
else:
ssu.eprint(f"Warning: could not add the configuration \"{conf_line}\" in local.conf.")
## ##
# @brief Modifies the bblayers.conf file by adding or removing layers based on the configuration. # @brief Modifies the bblayers.conf file by adding or removing layers based on the configuration.
# #
# This function updates the bblayers.conf file by adding or removing layers as specified # This function updates the bblayers.conf file by adding or removing layers as specified
# in the configuration. It reads the configuration to determine the required operation # in the configuration. It reads the configuration to determine the required operation
# (addition or removal) and the target layer, and then performs the modification. # (addition or removal) and the target layer, and then performs the modification.
# #
# @param build_dir The build directory containing the bblayers.conf file to modify. # @param build_dir The build directory containing the bblayers.conf file to modify.
...@@ -512,4 +547,4 @@ def modify_files_tree(*args): ...@@ -512,4 +547,4 @@ def modify_files_tree(*args):
pass pass
def do_nothing(*args): def do_nothing(*args):
pass pass
\ No newline at end of file
...@@ -206,8 +206,79 @@ class TestActionLocalConfClass: ...@@ -206,8 +206,79 @@ class TestActionLocalConfClass:
else: else:
mock_eprint.assert_not_called() mock_eprint.assert_not_called()
## @brief Test add_include_to_local_conf function.
#
# This test evaluates the behavior of the add_include_to_local_conf function for various configuration lines and checks
# whether the appropriate appending actions are taken in the local.conf file based on the input parameters.
#
# @param tmp_path Temporary directory for testing.
# @param conf_line The configuration line to test with.
# @param extract_value_return Tuple representing the expected return value from the mock extraction function.
# @param expected_warning Boolean indicating whether a warning should be logged.
# @param should_append Boolean indicating whether the line should be appended to local.conf.
@pytest.mark.parametrize(
"conf_line, extract_value_return, should_append, expected_warning", [
# Valid case: include should be appended
("CONFIG_GRP-INCLUDE_VAR-NAME_VAR-VAL=y", ("VAR_NAME", "VAR-VAL"), True, False),
# Valid case: include should be append
("CONFIG_GRP-INCLUDE_VAR-NAME=VAR-VAL", ("VAR_NAME", "VAR-VAL"), True, False),
# Valid case: include should NOT be appended (empty value)
("CONFIG_GRP-INCLUDE_VAR-NAME=", ("VAR_NAME", ""), False, False),
# Invalid extraction (None, None)
("INVALID_LINE", (None, None), False, True),
]
)
def test_add_include_to_local_conf(self, tmp_path, conf_line, extract_value_return, expected_warning, should_append):
# Setup mock directory and file
build_dir = tmp_path / "build"
build_dir.mkdir()
local_conf_path = build_dir / "conf" / "local.conf"
local_conf_path.parent.mkdir(parents=True)
local_conf_content = """
MY_VAR_1 = "1"
MY_VAR_2 = "2"
"""
# Write the initial content to local.conf
with open(local_conf_path, 'w') as f:
local_conf_path.write_text(local_conf_content.strip())
# Set up the mock for extract_value_from_config_line
with patch('seco_setup_conf.extract_value_from_config_line', return_value=extract_value_return) as mock_extract, \
patch('seco_setup_utils.append_to_file', side_effect=ssu.append_to_file) as mock_append, \
patch('seco_setup_utils.eprint') as mock_eprint:
ssa.add_include_to_local_conf(build_dir, conf=None, conf_line=conf_line, cluster_name=None)
# Verify extract_value_from_config_line was called correctly
mock_extract.assert_called_once_with(conf_line)
if should_append:
varname, varval = extract_value_return
# Verify that append_to_file was called with the correct arguments
expected_string = f"include \"{varval}\""
mock_append.assert_called_once_with(str(local_conf_path), expected_string)
updated_content = local_conf_path.read_text()
# Check strings that already were in the local.conf
for line in local_conf_content.strip().splitlines():
assert line in updated_content
# Check new string
assert expected_string in updated_content
else:
# Ensure append_to_file was not called for invalid configuration
mock_append.assert_not_called()
if expected_warning:
mock_eprint.assert_called_once_with(f"Warning: could not add the configuration \"{conf_line}\" in local.conf.")
else:
mock_eprint.assert_not_called()
class TestBblayersConfClass: class TestBblayersConfClass:
## @brief Fixture to set up the bblayers.conf file. ## @brief Fixture to set up the bblayers.conf file.
# #
# This fixture creates a temporary directory structure to hold the bblayers.conf file, including necessary # This fixture creates a temporary directory structure to hold the bblayers.conf file, including necessary
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment