Skip to content

Extend user scripts API, allowing the phase to be specified#435

Open
petrutlucian94 wants to merge 3 commits into
cloudbase:masterfrom
petrutlucian94:script_phases
Open

Extend user scripts API, allowing the phase to be specified#435
petrutlucian94 wants to merge 3 commits into
cloudbase:masterfrom
petrutlucian94:script_phases

Conversation

@petrutlucian94
Copy link
Copy Markdown
Member

@petrutlucian94 petrutlucian94 commented May 19, 2026

When deploying replicas, Coriolis users can specify scripts that will be executed during os-morphing, right after the OS partition is mounted on the minion instance.

In some situations, this is too late since user scripts may be needed in order to be able to mount the OS disk, for example if it’s encrypted.

In other situations it’s too early. Some scripts may need to be executed on the replica instance. This may require provider assistance.

To accommodate these use cases, we’ll extend the deployment API, allowing the user to specify when a given script should be executed. Each script may specify one of the following execution phases:

  • osmorphing-pre-os-mount
  • osmorphing-post-os-mount (default)
  • replica-initial-boot (TBD)

We'll continue to support the basic script format as well. See the API samples for a few examples.

Note that we can't use the OS morphing tools to run pre-os-mount scripts. A few approaches have been considered:

  • initialize the OS morphing tools against the minion root partition
    • hacky
    • unnecessarily complicated and brittle
  • use the base Linux/Windows OS morphing classes
    • can't be instantiated since not all abstract methods are implemented by
      the base classes
  • extend the OS mount tools to allow running pre-os-mount user scripts
    • easiest and most natural approach, implemented by this patch

The PR also fixes Windows user script execution, ensuring that errors get propagated.

We used to retry all SSH commands that failed, even those that
don't actually exist.

We're still retrying commands that are expected to fail, wasting
time unnecessarily during os morphing:

  coriolis.exception.CoriolisException: Command "readlink -en /dev/sda2"
  failed on host '172.17.0.3:22' with exit code: 1
  2026-05-18 12:14:11.783 1667765 WARNING coriolis.osmorphing.osmount.base
  [-] Target not found for symlink: /dev/sda2. Original link path will be returned

What makes things even worse is that the caller functions are
often retried as well, having the "retry_on_error" decorator
without any parameters. Commands that are expected to fail end up being
retried 25 times.

We'll update "exec_ssh_cmd" so that by default it will perform
retries only in case of SSH errors.

For convenience, we're exposing the retry helper arguments (number
of retries, retry interval and terminal exceptions). In addition
to that, we'll introduce a new argument for the list of retried
exceptions.

If the caller needs the actual commands to be retried as well,
"SSHCommandFailed" may be added to the list of retried exceptions.
@petrutlucian94 petrutlucian94 changed the title Script phases Extend user scripts API, allowing the phase to be specified May 19, 2026
@petrutlucian94
Copy link
Copy Markdown
Member Author

Rebased on top of #433, we should merge that one first.

When deploying replicas, Coriolis users can specify scripts that will be executed
during os-morphing, right after the OS partition is mounted on the minion instance.

In some situations, this is too late since user scripts may be needed in order
to be able to mount the OS disk, for example if it’s encrypted.

In other situations it’s too early. Some scripts may need to be executed on
the replica instance. This may require provider assistance.

To accommodate these use cases, we’ll extend the deployment API, allowing the
user to specify when a given script should be executed. Each script may specify
one of the following execution phases:

* osmorphing-pre-os-mount
* osmorphing-post-os-mount (default)
* replica-initial-boot (TBD)

We'll continue to support the basic script format as well. See the API samples
for a few examples.

Note that we can't use the OS morphing tools to run pre-os-mount scripts.
A few approaches have been considered:

* initialize the OS morphing tools against the minion root partition
    * hacky
    * unnecessarily complicated and brittle
* use the base Linux/Windows OS morphing classes
    * can't be instantiated since not all abstract methods are implemented by
      the base classes
* extend the OS mount tools to allow running pre-os-mount user scripts
    * easiest and most natural approach, imlemented by this patch
`powershell.exe -File` doesn't propagate the exit code of the
specified script.

As an alternative, we'll use '& $script; exit $LASTEXITCODE',
moving the execution policy and non-interactive parameters to
the "exec_ps_command" method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant