<commit_before>#!/usr/bin/env bash

CASE=$1


TIMEOUT_POST_START=60
TIMEOUT_POST_DETECT=30
TIMEOUT_WAIT_END=120

TIMEOUT_WAIT_HTTP_UP=60


echo "Is a travis run? $TRAVIS"

# Set a valid display name for debug
opsbro agent parameters set display_name "$CASE"


# Haproxy is the central node, it will ensure us that all nodes will talk togethers
if [ $CASE == "NODE-HAPROXY" ]; then
   opsbro agent parameters set proxy-node true
   opsbro agent parameters add groups demo_haproxy
fi


# Client node will need to expose nodes with DNS
if [ $CASE == "NODE-CLIENT" ]; then
   opsbro packs overload global.dns
   opsbro packs parameters set local.dns.port  53
   opsbro agent parameters add groups dns-listener
   printf "nameserver 127.0.0.1\n" > /etc/resolv.conf
fi


# We are ready, launch the whole daemons
/etc/init.d/opsbro start

echo "Daemon started `date`"

# For debug purpose
ip addr show | grep 'scope global'


sleep $TIMEOUT_POST_START



# Let the nodes join them selve.
# NOTE: the haproxy node will be slower to get here, because he need to install haproxy during the start
echo "Launching UDP detection `date`"
opsbro gossip detect --auto-join

echo "Sleeping while others nodes pop up too"
sleep $TIMEOUT_POST_DETECT

MEMBERS=$(opsbro gossip members)
NB_MEMBERS=$(echo "$MEMBERS" | grep 'docker-container' | wc -l)

printf "Current members: `date` $MEMBERS\n"


# Must have all 4 nodes available
if [ $NB_MEMBERS != 4 ]; then
   echo "`date` BAD number of members: $NB_MEMBERS"
   echo "$MEMBERS"
   cat /var/log/opsbro/gossip.log
   exit 2
fi


# Check that HTTP nodes are running well
if [ $CASE == "NODE-HTTP-1" ] || [ $CASE == "NODE-HTTP-2" ]; then
   PAYLOAD=$(curl -s http://localhost/)
   echo "PAYLOAD $PAYLOAD"
   if [ "$PAYLOAD" != "$CASE" ]; then
      echo "ERROR: `date` the http page is not ready"
      exit 2
   fi

   # They must have the apache group
   opsbro detectors wait-group 'apache'
   if [ $? != 0 ];then
      echo "ERROR:  `date` the apache group was not detected"
      exit 2
   fi

   echo "$CASE  `date` will wait for queries"
   sleep $TIMEOUT_WAIT_END

   echo "Finish, exiting  `date`"
   exit 2
fi


# Haproxy compliance must have installed the haproxy package
if [ $CASE == "NODE-HAPROXY" ]; then

    echo "HAPROXY `date` wait for http nodes to be up"
    sleep $TIMEOUT_WAIT_HTTP_UP

    echo "HAPROXY: look to see if haproxy is installed  `date`"
    opsbro compliance wait-compliant "TEST HAPROXY" --timeout=60
    if [ $? != 0 ]; then
        echo "Haproxy compliance cannot be fixed in COMPLIANCE state in 60s"
        opsbro compliance state
        exit 2
    fi

    echo "Compliance history that did install HAPROXY   `date`"
    opsbro compliance state


    echo "The haproxy group should now be detected"
    opsbro detectors wait-group 'haproxy'
    if [ $? != 0 ];then
       echo "ERROR: the haproxy group was not detected"
       exit 2
    fi


    echo "Testing local proxying"
    /etc/init.d/haproxy status | grep 'haproxy is running'
    if [ $? != 0 ];then
       echo "ERROR: the haproxy daemon is not running"
       cat /var/log/opsbro/generator.log
       cat /etc/haproxy/haproxy.cfg
       exit 2
    fi

    echo "HAPROXY: look if local proxying is valid  `date`"
    OUT=$(curl -s http://localhost)
    if [[ "$OUT" != "NODE-HTTP-1" ]] && [[ "$OUT" != "NODE-HTTP-2" ]]; then
         echo "Cannot reach real HTTP servers from the local HAPROXY: $OUT"
         cat /var/log/opsbro/generator.log
         cat /etc/haproxy/haproxy.cfg
         ls -thor /var/log/haproxy
         cat /etc/log/haproxy*
         cat /etc/log/haproxy/*
         exit 2
    fi


    grep 'NODE-HTTP-2' /etc/haproxy/haproxy.cfg > /dev/null
    if [ $? != 0 ];then
       echo "ERROR: cannot find the NODE-HTTP-2 in the haproxy configuration"
       cat /etc/haproxy/haproxy.cfg
       exit 2
    fi<commit_msg>Fix: TEST now we have a full build phase, then the run phase, so we can have more easier synchronization between tests<commit_after>#!/usr/bin/env bash

CASE=$1


TIMEOUT_POST_START=60
TIMEOUT_POST_DETECT=30
TIMEOUT_WAIT_END=120

TIMEOUT_WAIT_HTTP_UP=60



echo "$CASE starts to run `date` $TRAVIS"


# Set a valid display name for debug
opsbro agent parameters set display_name "$CASE"


# Haproxy is the central node, it will ensure us that all nodes will talk togethers
if [ $CASE == "NODE-HAPROXY" ]; then
   opsbro agent parameters set proxy-node true
   opsbro agent parameters add groups demo_haproxy
fi


# Client node will need to expose nodes with DNS
if [ $CASE == "NODE-CLIENT" ]; then
   opsbro packs overload global.dns
   opsbro packs parameters set local.dns.port  53
   opsbro agent parameters add groups dns-listener
   printf "nameserver 127.0.0.1\n" > /etc/resolv.conf
fi


# We are ready, launch the whole daemons
/etc/init.d/opsbro start

echo "Daemon started `date`"

# For debug purpose
ip addr show | grep 'scope global'


sleep $TIMEOUT_POST_START



# Let the nodes join them selve.
# NOTE: the haproxy node will be slower to get here, because he need to install haproxy during the start
echo "Launching UDP detection `date`"
opsbro gossip detect --auto-join

echo "Sleeping while others nodes pop up too"
sleep $TIMEOUT_POST_DETECT

MEMBERS=$(opsbro gossip members)
NB_MEMBERS=$(echo "$MEMBERS" | grep 'docker-container' | wc -l)

printf "Current members: `date` $MEMBERS\n"


# Must have all 4 nodes available
if [ $NB_MEMBERS != 4 ]; then
   echo "`date` BAD number of members: $NB_MEMBERS"
   echo "$MEMBERS"
   cat /var/log/opsbro/gossip.log
   exit 2
fi


# Check that HTTP nodes are running well
if [ $CASE == "NODE-HTTP-1" ] || [ $CASE == "NODE-HTTP-2" ]; then
   PAYLOAD=$(curl -s http://localhost/)
   echo "PAYLOAD $PAYLOAD"
   if [ "$PAYLOAD" != "$CASE" ]; then
      echo "ERROR: `date` the http page is not ready"
      exit 2
   fi

   # They must have the apache group
   opsbro detectors wait-group 'apache'
   if [ $? != 0 ];then
      echo "ERROR:  `date` the apache group was not detected"
      exit 2
   fi

   echo "$CASE  `date` will wait for queries"
   sleep $TIMEOUT_WAIT_END

   echo "Finish, exiting  `date`"
   exit 2
fi


# Haproxy compliance must have installed the haproxy package
if [ $CASE == "NODE-HAPROXY" ]; then

    echo "HAPROXY `date` wait for http nodes to be up"
    sleep $TIMEOUT_WAIT_HTTP_UP

    echo "HAPROXY: look to see if haproxy is installed  `date`"
    opsbro compliance wait-compliant "TEST HAPROXY" --timeout=60
    if [ $? != 0 ]; then
        echo "Haproxy compliance cannot be fixed in COMPLIANCE state in 60s"
        opsbro compliance state
        exit 2
    fi

    echo "Compliance history that did install HAPROXY   `date`"
    opsbro compliance state


    echo "The haproxy group should now be detected"
    opsbro detectors wait-group 'haproxy'
    if [ $? != 0 ];then
       echo "ERROR: the haproxy group was not detected"
       exit 2
    fi


    echo "Testing local proxying"
    /etc/init.d/haproxy status | grep 'haproxy is running'
    if [ $? != 0 ];then
       echo "ERROR: the haproxy daemon is not running"
       cat /var/log/opsbro/generator.log
       cat /etc/haproxy/haproxy.cfg
       exit 2
    fi

    echo "HAPROXY: look if local proxying is valid  `date`"
    OUT=$(curl -s http://localhost)
    if [[ "$OUT" != "NODE-HTTP-1" ]] && [[ "$OUT" != "NODE-HTTP-2" ]]; then
         echo "HAPROXY `date` Cannot reach real HTTP servers from the local HAPROXY: $OUT"
         cat /var/log/opsbro/generator.log
         cat /etc/haproxy/haproxy.cfg
         exit 2
    fi


    grep 'NODE-HTTP-2' /etc/haproxy/haproxy.cfg > /dev/null
    if [ $? != 0 ];then
       echo "ERROR: cannot find the NODE-HTTP-2 in the haproxy configuration"
       cat /etc/haproxy/haproxy.cfg
       exit 2
    fi
{'fraction_non_alphanumeric': 0.09884169884169884, 'fraction_numerical': 0.011325611325611325, 'mean_word_length': 2.8893893893893896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6779944', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2576, 'n_words': 950}