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

function cleanup_from_previous_test() {
    echo "## Cleanup ##"

    echo "Destroying juju environment"
    juju destroy-environment --force -y manual

    VMS=$( sudo uvt-kvm list )
    for VM in $VMS
    do
      echo "Destroying $VM"
      sudo uvt-kvm destroy $VM
    done

    echo "Cleaning up files"
    rm -rf ~/.juju
    rm -f ~/.ssh/known_hosts
    rm -rf ~/openstack-cluster-setup

    echo "Cleaning up libvirt/dnsmasq"
    sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases
    sudo killall dnsmasq
    sudo service libvirt-bin restart
}

function bootstrap() {
    cd ~
    sudo apt-get update
    sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr
    sudo add-apt-repository -y ppa:ansible/ansible
    sudo apt-get update
    sudo apt-get install -y ansible

    [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

    git clone https://github.com/open-cloud/openstack-cluster-setup.git
    cd ~/openstack-cluster-setup

    sed -i "s/ubuntu/`whoami`/" $INVENTORY
    cp vars/example_keystone.yml vars/cord_keystone.yml

    # Log into the local node once to get host key
    ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
}

function setup_openstack() {
    # Run the playbook, but check to see if we're on cloudlab
    if [[ -x /usr/testbed/bin/mkextrafs ]]
    then
      ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="on_cloudlab=True"
    else
      ansible-playbook -i $INVENTORY cord-single-playbook.yml
    fi
}

function build_xos_docker_images() {
    echo ""
    echo "Checking out XOS branch $BUILD_BRANCH"
    ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu<EMAIL>'; git config --global user.name 'XOS ExampleService'"
    ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"

    if [[ $EXAMPLESERVICE -eq 1 ]]
    then
      echo ""
      echo "Adding exampleservice to XOS"
      ssh ubuntu@xos "cd xos; git cherry-pick cd6e972210f4134ffb2f7a36fb3c4baf33f02bef"
    fi

    echo "Rebuilding XOS containers"
    ssh ubuntu@xos "cd xos/containers/xos; make base"
    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
}

function setup_xos() {

    echo "Setting up XOS, will take a few minutes"
    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
    echo ""
    echo "Pause 2 minutes"
    sleep 120

    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn; make fabric"
    echo ""
    echo "Pause 30 seconds"
    sleep 30

    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord; make vtn"

    if [[ $EXAMPLESERVICE -eq 1 ]]
    then
      ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
    fi
}

function setup_test_client() {
    ssh ubuntu@nova-compute "sudo apt-get -y install lxc"<commit_msg>Another attempted workaround for synch bug<commit_after>#!/usr/bin/env bash

function cleanup_from_previous_test() {
    echo "## Cleanup ##"

    echo "Destroying juju environment"
    juju destroy-environment --force -y manual

    VMS=$( sudo uvt-kvm list )
    for VM in $VMS
    do
      echo "Destroying $VM"
      sudo uvt-kvm destroy $VM
    done

    echo "Cleaning up files"
    rm -rf ~/.juju
    rm -f ~/.ssh/known_hosts
    rm -rf ~/openstack-cluster-setup

    echo "Cleaning up libvirt/dnsmasq"
    sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases
    sudo killall dnsmasq
    sudo service libvirt-bin restart
}

function bootstrap() {
    cd ~
    sudo apt-get update
    sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr
    sudo add-apt-repository -y ppa:ansible/ansible
    sudo apt-get update
    sudo apt-get install -y ansible

    [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

    git clone https://github.com/open-cloud/openstack-cluster-setup.git
    cd ~/openstack-cluster-setup

    sed -i "s/ubuntu/`whoami`/" $INVENTORY
    cp vars/example_keystone.yml vars/cord_keystone.yml

    # Log into the local node once to get host key
    ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
}

function setup_openstack() {
    # Run the playbook, but check to see if we're on cloudlab
    if [[ -x /usr/testbed/bin/mkextrafs ]]
    then
      ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="on_cloudlab=True"
    else
      ansible-playbook -i $INVENTORY cord-single-playbook.yml
    fi
}

function build_xos_docker_images() {
    echo ""
    echo "Checking out XOS branch $BUILD_BRANCH"
    ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'"
    ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"

    if [[ $EXAMPLESERVICE -eq 1 ]]
    then
      echo ""
      echo "Adding exampleservice to XOS"
      ssh ubuntu@xos "cd xos; git cherry-pick cd6e972210f4134ffb2f7a36fb3c4baf33f02bef"
    fi

    echo "Rebuilding XOS containers"
    ssh ubuntu@xos "cd xos/containers/xos; make base"
    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
}

function setup_xos() {

    echo "Setting up XOS, will take a few minutes"
    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
    echo ""
    echo "Pause 2 minutes"
    sleep 120

    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn; make fabric"
    echo ""
    echo "Pause 30 seconds"
    sleep 30

    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"

    if [[ $EXAMPLESERVICE -eq 1 ]]
    then
      ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
    fi

    echo ""
    echo "(Temp workaround for bug in Synchronizer) Pause 60 seconds"
    sleep 60
    ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
}

function setup_test_client() {
    ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
{'fraction_non_alphanumeric': 0.10484140233722872, 'fraction_numerical': 0.011018363939899833, 'mean_word_length': 2.8477842003853566, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 2, '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': '1045389', 'n_tokens_mistral': 2321, 'n_tokens_neox': 2105, 'n_words': 597}