<commit_before>#!/bin/bash

discovery_token=$(facter etcd_discovery_token)
# Exit codes:
# 0: Yup, there's an update
# 1: No, no updates
# 2: Could not reach etcd, so we don't know
# 3: Could not reach etcd, but we also haven't been initialised ourselves.
python -m jiocloud.orchestrate --discovery_token=$discovery_token pending_update
rv=$?

run_puppet() {
        # ensure that our service catalog hiera data is available
        python -m jiocloud.orchestrate --discovery_token=$discovery_token cache_services
        # now run puppet
        puppet apply --detailed-exitcodes --logdest=syslog `puppet config print manifestdir`/site.pp
        # publish the results of that run
        ret_code=$?
        python -m jiocloud.orchestrate --discovery_token=$discovery_token publish_service
        python -m jiocloud.orchestrate --discovery_token=$discovery_token update_own_status puppet $ret_code
        if [[ $ret_code = 1 || $ret_code = 4 || $ret_code = 6 ]]; then
                echo "Puppet failed with return code ${ret_code}"
                sleep 5
                exit 1
        fi
}

validate_service() {
        run-parts --regex=. --verbose --exit-on-error  --report /usr/lib/jiocloud/tests/
        ret_code=$?
        python -m jiocloud.orchestrate --discovery_token=$discovery_token update_own_status validation $ret_code
        if [[ $ret_code != 0 ]]; then
                echo "Validation failed with return code ${ret_code}"
                sleep 5
                exit 1
        fi
}

if [ $rv -eq 0 ]
then
       pending_version=$(python -m jiocloud.orchestrate --discovery_token=$discovery_token current_version)
       apt-get update
       apt-get dist-upgrade -o Dpkg::Options::="--force-confold" -y
       run_puppet
       python -m jiocloud.orchestrate local_version $pending_version
elif [ $rv -eq 1 ]
then
       :
elif [ $rv -eq 2 ]
then
       :
elif [ $rv -eq 3 ]
then
       # Maybe we're the first etcd node (or some other weirdness is going on).
       # Let's just run Puppet and see if things normalize
       run_puppet
fi
validate_service
python -m jiocloud.orchestrate --discovery_token=$discovery_token update_own_info<commit_msg>Only update local version once validation passes<commit_after>#!/bin/bash

discovery_token=$(facter etcd_discovery_token)
# Exit codes:
# 0: Yup, there's an update
# 1: No, no updates
# 2: Could not reach etcd, so we don't know
# 3: Could not reach etcd, but we also haven't been initialised ourselves.
python -m jiocloud.orchestrate --discovery_token=$discovery_token pending_update
rv=$?

run_puppet() {
        # ensure that our service catalog hiera data is available
        python -m jiocloud.orchestrate --discovery_token=$discovery_token cache_services
        # now run puppet
        puppet apply --detailed-exitcodes --logdest=syslog `puppet config print manifestdir`/site.pp
        # publish the results of that run
        ret_code=$?
        python -m jiocloud.orchestrate --discovery_token=$discovery_token publish_service
        python -m jiocloud.orchestrate --discovery_token=$discovery_token update_own_status puppet $ret_code
        if [[ $ret_code = 1 || $ret_code = 4 || $ret_code = 6 ]]; then
                echo "Puppet failed with return code ${ret_code}"
                sleep 5
                exit 1
        fi
}

validate_service() {
        run-parts --regex=. --verbose --exit-on-error  --report /usr/lib/jiocloud/tests/
        ret_code=$?
        python -m jiocloud.orchestrate --discovery_token=$discovery_token update_own_status validation $ret_code
        if [[ $ret_code != 0 ]]; then
                echo "Validation failed with return code ${ret_code}"
                sleep 5
                exit 1
        fi
}

if [ $rv -eq 0 ]
then
       pending_version=$(python -m jiocloud.orchestrate --discovery_token=$discovery_token current_version)
       apt-get update
       apt-get dist-upgrade -o Dpkg::Options::="--force-confold" -y
       run_puppet
elif [ $rv -eq 1 ]
then
       :
elif [ $rv -eq 2 ]
then
       :
elif [ $rv -eq 3 ]
then
       # Maybe we're the first etcd node (or some other weirdness is going on).
       # Let's just run Puppet and see if things normalize
       run_puppet
fi
validate_service
python -m jiocloud.orchestrate local_version $pending_version
python -m jiocloud.orchestrate --discovery_token=$discovery_token update_own_info
{'fraction_non_alphanumeric': 0.09169708029197081, 'fraction_numerical': 0.0072992700729927005, 'mean_word_length': 2.6602671118530883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3672991', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1321, 'n_words': 415}