Re: [PATCH] Adding stressor validation for stress-ng

John Kacur <[email protected]>
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
Hi Sana,

Thanks for the patch! The validation logic looks good and the error messages are helpful.

One request: could you move `get_valid_stressors()` and `validate_stressor()`
out of the class and make them module-level functions? They don't need access to
the class instance, and module-level functions are easier to unit test and can be
imported directly.

Place them after the imports and before the class definition:

def get_valid_stressors():
    """Query stress-ng for list of valid stressor names."""
    try:
        result = subprocess.run(['stress-ng', '--stressors'],
                              capture_output=True, text=True, check=True)
        return result.stdout.strip().split()
    except (subprocess.CalledProcessError, FileNotFoundError):
        return []

def validate_stressor(stressor_name):
    """Validate a single stressor name against stress-ng's available stressors."""
    valid = get_valid_stressors()
    if not valid:
        return

    if stressor_name not in valid:
        raise ValueError(f"Invalid stress-ng stressor: '{stressor_name}'. "
                        f"Run 'stress-ng --stressors' to see valid options.")

Then call it in _WorkloadPrepare() as: validate_stressor(self.cfg.stressor)

Thanks!
John
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.