Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

autoinstall_snippets/keep_files: keys_found doesn't successfully handle "found one but not another" #3909

@tdlee

Description

@tdlee

Describe the bug

(This supersedes discussion 3902.)

I think I've encountered a long-standing bug as I try to mimic autoinstall_snippets/keep_files in our non-Cobbler kickstart.

In brief: when attempting to preserve multiple different key types (the code offers three: ssh, cfengine, rhn) the shell variable keys_found is too global in scope to handle "found one but not found another".

In our case, we use ssh and cfengine. Suppose the previous system had keys ssh but not cfengine.

Each call to search_for_keys immediately sets keys_found=no.

  • The first call (for ssh) finds the keys, so (correctly) sets keys_found=yes.
  • The second call (for cfengine) immediately sets keys_found=no. Because there were no previous CFEngine keys, keys_found remains as no.
  • The subsequent calls to restore_keys then BOTH (i.e ssh and cfengine) interrogate the single variable keys_found and BOTH find it "no" (from the final key), even though the earlier ssh result had been "yes".

So I think that the single keys_found variable needs to be replaced by a variable-per-key implementation.

Steps to reproduce

It was somewhat over 12 years ago, in a previous job, that I used Cobbler. My current job uses kickstart but not Cobbler. We want to mimic Cobbler's keep_files functionality, so I'm adapting the code into our use and find this problem. (In the previous job, we only attempted a single key so didn't encounter this bug.)

My suggested reproduce steps are:

  1. Cobbler environment with preserve_files_ks having at least two cases; e.g. "ssh" and "cfengine" in that order.
  2. Reinstall a previous OS that had "ssh" but not "cfengine"; that is, keys for an early item in that preserve_files_ks list but, crucially, absent for the final item in the list.
  3. Observe that valid keys (in this case "ssh") fail to be preserved.

Expected behavior

keep_files should attempt to keep keys it finds, even if other keys (whose preservation is being attempted) had been absent,

Cobbler version

N/A, but believed to be all.

Operating system

RHEL

Additional information

I could easily attempt a blind patch, based on our own non-Cobbler adaptation of the Cobbler code.

But also:

  1. There doesn't appear to be any sort of unit test or similar for keep_files. (Have I overlooked it?)
  2. The keep_files code would benefit from wider tidy-up that would interact considerably with any proposed patch. Should I attempt a minimal patch (i.e. limited to this keys_found bug)? Or can I work on the broader matters with someone with access to a Cobbler environment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions