test-kitchen / kitchen-vagrant

A Test Kitchen Driver for Vagrant
Other
348 stars 189 forks source link

kitchen adds carriage return to shebang on bootstrap.sh when converging effortless package #437

Open jmitchusson opened 3 years ago

jmitchusson commented 3 years ago

:speaking_head: Foreword

Thank for taking the time to fill this bug report fully. Without it we may not be able to fix the bug, and the issue may be closed without resolution.

:ghost: Brief Description

kitchen converge fails to find /tmp/kitchen/bootstrap.sh. when I login to the vm instance (bento/centos-7' version '202010.22.0 hosted on win 10 1909) it has correct permissions. when I attempt a './bootstrap.sh' stderr is ''/bin/bash^M: bad interpreter".

Version

2.7.2

Environment

Host: Win 10 1909 Guest VM: bento/centos-7' version '202010.22.0 chefdk: 4.12.0 Test Kitchen: 2.7.2 VirtualBox: 6.1

kitchen.yml

---
driver:
  name: vagrant
  provider: virtualbox
  synced_folders:
    - ["./results", "/tmp/results"]

provisioner:
  name: shell

verifier:
  name: inspec

platforms:
  - name: centos/7

suites:
  - name: default
    include: centos/7
    provisioner:
      arguments: ["devops", "pb_effortless_habdash"]
    run_list:
      - recipe[pb_habitat_effortless_test]
    verifier:
      inspec_tests:
        - test/integration/default

bootstrap.sh:

#!/bin/bash
HAB_BLDR_URL="<bldr.url>"
HAB_LICENSE="accept"
HAB_AUTH_TOKEN="<token>"
HAB_VERSION="1.6.181"
HAB_RELEASE="20201030172917"
HAB_ARCHIVE="hab-${HAB_VERSION}-${HAB_RELEASE}-x86_64-linux.tar.gz"
ARTIFACTORY_URL="<art.url>"
HAB_SERVICE_FILE="/etc/systemd/system/hab-sup.service"
HAB_SERVICE_TXT="/tmp/kitchen/data/hab_service_file.txt"
BIN_HAB="/bin/hab"
USR_LOCAL_BIN_HAB="/usr/local/bin/hab"
USR_BIN_HAB="/usr/bin/hab"
ID="800"
NAME="hab:x"
SHELL="/sbin/nologin"
ETC_PASSWD_SHOULD_BE="${NAME}:${ID}:${ID}.*${SHELL}"
GREP_ETC_ID="grep ${ID} /etc/"
GREP_ETC_NAME="grep ${NAME} /etc/"
GREP_ETC_GROUP_ID="$(${GREP_ETC_ID}group)"
GREP_ETC_PASSWD_ID="$(${GREP_ETC_ID}passwd)"
GREP_ETC_GROUP_NAME="$(${GREP_ETC_NAME}group)"
GREP_ETC_PASSWD_NAME="$(${GREP_ETC_NAME}passwd)"
INSTALL="yum install"

export HAB_BLDR_URL=${HAB_BLDR_URL}
export HAB_AUTH_TOKEN=${HAB_AUTH_TOKEN}
if [ ! -x ${BIN_HAB} ] && [ ! -x ${USR_LOCAL_BIN_HAB} ]  && [ ! -x ${USR_BIN_HAB} ]; then
    export HAB_LICENSE=${HAB_LICENSE}
    ${INSTALL} -y dos2unix
    CHECK="$(curl -kILs ${ARTIFACTORY_URL} | tr -d ' ' | awk -F: '/X-Checksum-Sha256:/{print $NF}' | dos2unix)"
    curl -k -L -o ${HAB_ARCHIVE} ${ARTIFACTORY_URL}
    echo "${CHECK}  ${HAB_ARCHIVE}" | sha256sum -c - && \
    tar -xvzf ${HAB_ARCHIVE} --strip-components 1 && \
    ./hab pkg install --binlink core/hab/${HAB_VERSION} && \
     rm -f ${HAB_ARCHIVE} ./hab

    if [[ ${GREP_ETC_GROUP_ID} =~ ${NAME} ]]; then
        echo "Hab group exist with correct config"
    elif [ ${GREP_ETC_GROUP_NAME} ]; then
        groupmod -g ${ID} hab && true
        echo "hab group found with wrong gid.  Changing to ${ID}."
    else
        groupadd -g ${ID} hab && true
        echo "Creating hab group with gid ${ID}"
    fi

    if [[ ${GREP_ETC_PASSWD_ID} =~ ${ETC_PASSWD_SHOULD_BE} ]]; then
        echo "Hab user exist"
    elif [ ${GREP_ETC_PASSWD_NAME} ]; then
        usermod -g ${ID}  -u ${ID}-s ${SHELL} hab && true
        echo "hab user found with wrong uid.  Changing uid ${ID}."
    else
        useradd -u ${ID} -g ${ID} -s ${SHELL} hab && true
        echo "Creating hab user with gid ${ID}, uid ${ID}, and shell ${SHELL}"
    fi

    # hab pkg install core/hab-sup
    # hab pkg install core/hab-launcher
    # cat ${HAB_SERVICE_TXT} > ${HAB_SERVICE_FILE}
    # systemctl daemon-reload
    # systemctl enable hab-sup
    # systemctl start hab-sup
    # echo "$(systemctl status hab-sup)"

else
    echo "Hab exe already installed at ${BIN_HAB}, ${USR_LOCAL_BIN_HAB}, or ${USR_BIN_HAB}."
fi

pkg_origin=$1
pkg_name=$2
echo ${pkg_origin}
echo ${pkg_name}

echo "Starting $pkg_origin/$pkg_name"

latest_hart_file=$(ls -la /tmp/results/$pkg_origin-$pkg_name* | tail -n 1 | cut -d " " -f 9)
echo "Latest hart file is $latest_hart_file"

echo "Installing $latest_hart_file"
hab pkg install $latest_hart_file

echo "Determining pkg_prefix for $latest_hart_file"
pkg_prefix=$(find /hab/pkgs/$pkg_origin/$pkg_name -maxdepth 2 -mindepth 2 | sort | tail -n 1)

echo "Found $pkg_prefix"

echo "Running chef for $pkg_origin/$pkg_name"
cd $pkg_prefix
hab pkg exec $pkg_origin/$pkg_name chef-client -z -c $pkg_prefix/config/bootstrap-config.rb

Scenario

Test an effortless package

Steps to Reproduce

run 'kitchen converge' with the above setup.

Expected Result

bootstrap.sh executes

Actual Result

sudo -E /tmp/kitchen/bootstrap.sh devops pb_effortless_habdash ') sudo: unable to execute /tmp/kitchen/bootstrap.sh: No such file or directory D Cleaning up local sandbox in C:/Users/jmitc/AppData/Local/Temp/default-centos-7-sandbox-20201208-5584-q8656w

:heavy_plus_sign: Additional context

Add any other context about the problem here. e.g. related issues or existing pull requests.

marcparadise commented 3 years ago

@jmitchusson to confirm, there is no carriage return in the original script at that location?