`salt`, `unless`and `qvm.halted`

In my saltsetup, I

  1. check whether a given package exists in a particulate template
  2. if no: I fire up a named dispvm and built the package from source therein, move the result to the template and install it there and
  3. try to shut down the build dvm as follows:
Shutdown built-dvm:
  cmd.run:
    - name:   qvm-run-vm {{ build_dvm }} -- sudo shutdown now
    - unless:
      - fun: qvm.halted
        args: 
          - {{ build_dvm }}

The latter keeps failing with salt stating that it does not know the qvm.haltedmodule … driving me nuts. What Am I doing wrong?

qvm-run-vm is bogus
qvm-run {{ build_dvm }} -- sudo shutdown now is better

This would work:

Shutdown built-dvm:
  cmd.run:
    - name:   qvm-run {{ build_dvm }} -- sudo shutdown now
    - unless:
        qvm.halted
          - name: {{ build_dvm }}

But why bother when you have a native state:

Shutdown built-dvm:
  qvm.shutdown:
    - name:  {{ build_dvm }} 

Thank you for your time. You led me on the right path. However:

qvm-run-vm is bogus

Not so. Does not work for me. qvm-run: command not found. Is it because the call is executed in the template and not dom0, and (at least in my case, Archlinux template) there is no qvm-run available in the template?

Shutdown built-dvm:
  qvm.shutdown:
    - name:  {{ build_dvm }} 

Also does not work for me. The error is

State 'qvm.shutdown' was not found in SLS '<PATH>'
                Reason: 'qvm.shutdown' is not available.

Again: because this runs in the template?

So the following works for me. As the shutdown now call results in a vchan connection closed early error, I am now forgoing the entire unless business and define return codes 129 (target VM not running) & 255 (connection closed early) as a success:

Shutdown built-dvm:
  cmd.run:
    - name: qvm-run-vm {{ build_dvm }} -- sudo shutdown now
    - success_retcodes:
      - 129
      - 255