#!/usr/bin/env bash
# fake openstack for phase-07-conductor-graft.sh tests.
# Logs every call to $OS_LOG (so the harness can assert 7.1 verify-first NEVER
# calls `security group rule create`). Steered by env:
#   DOMAIN_MISSING USER_MISSING PROJECT_MISSING COE_403
: "${OS_LOG:=/dev/null}"
printf 'openstack %s\n' "$*" >> "$OS_LOG"

j=" $* "
case "$j" in
  *" domain show magnum "*)
    [ "${DOMAIN_MISSING:-0}" = 1 ] && exit 1
    echo "d9d0a4a8215d49f2aeb243b6aea4b0b0" ;;
  *" user show magnum_domain_admin "*)
    [ "${USER_MISSING:-0}" = 1 ] && exit 1
    echo "0885dca38f8043ed85d5e72f14a54124" ;;
  *" project show "*)
    [ "${PROJECT_MISSING:-0}" = 1 ] && exit 1
    echo "d5bc125c7c1841d389b76cd0a7b0a915" ;;
  *" coe service list "*)
    if [ "${COE_403:-0}" = 1 ]; then
      echo "ERROR (Forbidden): Keystone client authentication failed" >&2; exit 1
    fi
    echo "| id | host | binary           | state |"
    echo "|  1 | None | magnum-conductor | up    |" ;;
  *" security group rule create "*)
    # should NEVER run on the happy path (7.1 is verify-first)
    echo "RULE-CREATE-CALLED" ; exit 0 ;;
  *)
    exit 0 ;;
esac
exit 0
