def test_rancher_network(qemu, cloud_config): v = SSH(qemu, ssh_command).check_output(''' ip route get to 10.10.2.120 '''.strip()) assert v.split(' ')[5] + '/24' == \ cloud_config['rancher']['network']['interfaces']['mac=52:54:00:12:34:59']['address']
def test_docker_args(qemu, cloud_config): v = SSH(qemu, ssh_command).check_output(''' ps -ef | grep docker '''.strip()) expected = string.join(cloud_config['rancher']['docker']['args']) assert v.find(expected) != -1
def test_system_docker_http_proxy(qemu): try: SSH(qemu).check_call('sudo reboot') except: pass SSH(qemu).check_call(''' set -x -e if sudo system-docker pull busybox; then exit 1 else exit 0 fi ''')
def test_ssh_key_merging(qemu): SSH(qemu).check_call('bash', '-c', '''cat > test-merge << "SCRIPT" set -x -e rm /var/lib/rancher/conf/cloud-config.yml EXISTING=$(ros config get ssh_authorized_keys | head -1) cat > /var/lib/rancher/conf/metadata << EOF SSHPublicKeys: "0": zero "1": one "2": two EOF ros config set hostname one ros config set hostname two ros config set hostname three cat > expected << EOF $EXISTING - zero - one - two EOF ros config get ssh_authorized_keys > got diff got expected SCRIPT sudo bash test-merge '''.strip())
def test_system_docker_survives_custom_docker_install(qemu): SSH(qemu).check_call(''' set -x -e mkdir x sudo mount $(sudo ros dev LABEL=RANCHER_STATE) x [ -d x/ros_subdir/home/rancher ] '''.strip())
def test_ros_config_bool(qemu): SSH(qemu).check_call(''' set -x -e if [ "$(sudo ros config get rancher.log)" == "true " ]; then sudo ros config get rancher.log exit 1 fi sudo ros config set rancher.log false if [ "$(sudo ros config get rancher.log)" == "false " ]; then sudo ros config get rancher.log exit 1 fi if [ "$(sudo ros config get rancher.debug)" == "false " ]; then sudo ros config get rancher.debug exit 1 fi sudo ros config set rancher.debug true if [ "$(sudo ros config get rancher.debug)" == "true " ]; then sudo ros config get rancher.debug exit 1 fi '''.strip())
def test_docker_not_pid_one(qemu): SSH(qemu, ssh_command).check_call(''' set -e -x for i in $(pidof docker); do [ $i != 1 ] done '''.strip())
def test_docker_tls_args(qemu, cloud_config): SSH(qemu, ssh_command).check_call(''' set -e -x sudo ros tls gen sleep 5 docker --tlsverify version '''.strip())
def test_reboot_with_container_running(qemu): try: SSH(qemu, ssh_command).check_call(''' set -ex docker run -d --restart=always %(image)s sudo reboot '''.strip() % {'image': nginx[u.arch]}) except: pass time.sleep(3) v = SSH(qemu, ssh_command).check_output(''' docker ps -f status=running '''.strip()) assert v.find('nginx') != -1
def test_docker_pid_one(qemu): SSH(qemu, ssh_command).check_call(''' set -e -x for i in $(pidof docker); do if [ $i = 1 ]; then found=true fi done [ "$found" = "true" ] '''.strip())
def test_docker_tls_args(qemu, cloud_config): SSH(qemu, ssh_command).check_call(''' set -e -x sudo ros tls gen --server -H localhost sudo ros tls gen sudo ros c set rancher.docker.tls true sudo system-docker restart docker sleep 5 docker --tlsverify version '''.strip())
def test_network_interfaces_conf(qemu): SSH(qemu).check_call('''cat > test-merge << "SCRIPT" set -x -e ip link show dev br0 ip link show dev br0.100 | grep br0.100@br0 ip link show dev eth1.100 | grep 'master br0' SCRIPT sudo bash test-merge '''.strip())
def test_network_dns_conf(qemu): SSH(qemu).check_call('''cat > test-merge << "SCRIPT" set -x -e cat /etc/resolv.conf | grep "search mydomain.com example.com" cat /etc/resolv.conf | grep "nameserver 208.67.222.123" cat /etc/resolv.conf | grep "nameserver 208.67.220.123" SCRIPT sudo bash test-merge '''.strip())
def test_network_dns_ros_set(qemu): SSH(qemu).check_call(''' set -x -e sudo ros config set rancher.network.dns.search '[a,b]' if [ "$(sudo ros config get rancher.network.dns.search)" == "- a - b " ]; then sudo ros config get rancher.network.dns.search exit 1 fi '''.strip())
def test_network_interfaces_conf(qemu): SSH(qemu).check_call('''cat > test-merge << "SCRIPT" set -x -e ip link show dev br0 ip link show dev br0.100 | grep br0.100@br0 ip link show dev eth1.100 | grep 'master br0' ip link show dev eth6 | grep 'master bond0' ip link show dev eth7 | grep 'master bond0' [ "$(</sys/class/net/bond0/bonding/mode)" = "active-backup 1" ] SCRIPT sudo bash test-merge '''.strip())
def test_docker_http_proxy(qemu): SSH(qemu).check_call(''' set -x -e sudo system-docker exec docker env | grep HTTP_PROXY=invalid sudo system-docker exec docker env | grep HTTPS_PROXY=invalid sudo system-docker exec docker env | grep NO_PROXY=invalid if docker pull busybox; then exit 1 else exit 0 fi ''')
def test_ros_export(qemu): SSH(qemu).check_call(''' set -x -e if sudo ros config export | grep "PRIVATE KEY"; then exit 1 fi sudo ros config export --private | grep "PRIVATE KEY" sudo ros config export --full | grep "udev" sudo ros config export --private --full | grep "ntp" sudo ros config export --full | grep "labels" sudo ros config export --private --full | grep "PRIVATE KEY" '''.strip())
def test_ros_config_string(qemu): SSH(qemu).check_call(''' set -x -e if [ "$(sudo ros config get hostname)" == "hostname3 " ]; then sudo ros config get hostname exit 1 fi sudo ros config set hostname rancher-test if [ "$(sudo ros config get hostname)" == "rancher-test " ]; then sudo ros config get hostname exit 1 fi '''.strip())
def test_ros_install_on_formatted_disk(qemu): u.wait_for_ssh(qemu, ssh_command) subprocess.check_call([ 'sh', '-c', 'docker save rancher/os:%s%s | ./scripts/ssh sudo system-docker load' % (u.version, u.suffix) ], stderr=subprocess.STDOUT, universal_newlines=True) SSH(qemu, ssh_command).check_call(''' set -e -x sudo mkfs.ext4 /dev/vda sudo ros install -f --no-reboot -d /dev/vda -i rancher/os:%s%s '''.strip() % (u.version, u.suffix)) subprocess.call(ssh_command + ['sudo', 'reboot'], stderr=subprocess.STDOUT, universal_newlines=True) u.wait_for_ssh(qemu, ssh_command)
def test_sysctl(qemu): SSH(qemu).check_call("sudo cat /proc/sys/kernel/domainname | grep test") SSH(qemu).check_call("sudo cat /proc/sys/dev/cdrom/debug | grep 1")
def test_lenient_service_parsing(qemu): time.sleep(5) SSH(qemu).check_call("sudo system-docker ps -a | grep test-parsing")
def test_rancher_environment(qemu, cloud_config): v = SSH(qemu, ssh_command).check_output(''' sudo ros env printenv FLANNEL_NETWORK '''.strip()) assert v.strip() == cloud_config['rancher']['environment']['FLANNEL_NETWORK']
def test_dhcpcd(qemu, cloud_config): v = SSH(qemu, ssh_command).check_output(''' ps -ef | grep dhcpcd '''.strip()) assert v.find('dhcpcd -M') != -1
def test_swap(qemu): SSH(qemu).check_call("sudo mkswap /dev/vdb") SSH(qemu).check_call("sudo cloud-init -execute") SSH(qemu).check_call("cat /proc/swaps | grep /dev/vdb")
def test_rancher_environment_in_system_service(qemu): SSH(qemu, ssh_command).check_call(''' sudo system-docker logs env | grep A=A sudo system-docker logs env | grep BB=BB sudo system-docker logs env | grep BC=BC ''')
def test_network_resources_loaded(qemu): SSH(qemu).check_call("apt-get --version") SSH(qemu).check_call("sudo system-docker images | grep tianon/true")
def test_cloud_config_hostname(qemu): SSH(qemu, ssh_command).check_call(''' hostname | grep rancher-test cat /etc/hosts | grep rancher-test ''')
def test_dhcp_hostname(qemu): SSH(qemu, ssh_command).check_call(''' hostname | grep rancher-dev cat /etc/hosts | grep rancher-dev ''')
def test_cloud_config_mounts(qemu): SSH(qemu).check_call('cat /home/rancher/test | grep test')