1
0
mirror of https://github.com/rancher/os.git synced 2025-07-08 04:18:38 +00:00
os/tests/integration/rostest/test_01_cloud_config.py

104 lines
2.6 KiB
Python
Raw Normal View History

2015-09-11 15:27:00 +00:00
import string
2015-05-08 10:15:14 +00:00
import pytest
import rostest.util as u
from rostest.util import SSH
import yaml
2015-05-08 10:15:14 +00:00
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
2015-09-11 15:27:00 +00:00
cloud_config_path = './tests/integration/assets/test_01/cloud-config.yml'
2015-05-08 10:15:14 +00:00
2016-04-01 18:00:42 +00:00
net_args = {'amd64': ['-net', 'nic,vlan=1,model=virtio,macaddr=52:54:00:12:34:59',
'-net', 'user,vlan=1,net=10.10.2.0/24'],
'arm64': ['-netdev', 'user,id=net1,net=10.10.2.0/24',
'-device', 'virtio-net-device,netdev=net1,mac=52:54:00:12:34:59']}
net_args['arm'] = net_args['arm64']
2015-05-08 10:15:14 +00:00
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path] + net_args[u.arch])
u.flush_out(q.stdout)
return q
2015-05-08 13:58:10 +00:00
@pytest.fixture(scope="module")
2015-05-08 17:22:26 +00:00
def cloud_config():
2015-05-08 13:58:10 +00:00
return yaml.load(open(cloud_config_path))
2015-05-08 10:15:14 +00:00
@pytest.mark.timeout(40)
2015-05-08 11:23:12 +00:00
def test_ssh_authorized_keys(qemu):
u.wait_for_ssh(qemu, ssh_command)
2015-05-08 11:23:12 +00:00
assert True
@pytest.mark.timeout(40)
2015-05-08 17:22:26 +00:00
def test_rancher_environment(qemu, cloud_config):
2016-04-01 18:00:42 +00:00
v = SSH(qemu, ssh_command).check_output('''
sudo ros env printenv FLANNEL_NETWORK
'''.strip())
2015-05-08 10:15:14 +00:00
2015-05-08 17:22:26 +00:00
assert v.strip() == cloud_config['rancher']['environment']['FLANNEL_NETWORK']
2015-05-08 14:39:09 +00:00
2015-09-11 15:27:00 +00:00
@pytest.mark.timeout(40)
def test_docker_args(qemu, cloud_config):
2016-04-01 18:00:42 +00:00
v = SSH(qemu, ssh_command).check_output('''
ps -ef | grep docker
'''.strip())
2015-09-11 15:27:00 +00:00
expected = string.join(cloud_config['rancher']['docker']['args'])
assert v.find(expected) != -1
@pytest.mark.timeout(40)
def test_dhcpcd(qemu, cloud_config):
2016-04-01 18:00:42 +00:00
v = SSH(qemu, ssh_command).check_output('''
ps -ef | grep dhcpcd
'''.strip())
assert v.find('dhcpcd -M') != -1
@pytest.mark.timeout(40)
def test_services_include(qemu, cloud_config):
u.wait_for_ssh(qemu, ssh_command, ['docker inspect kernel-headers >/dev/null 2>&1'])
2015-11-17 13:08:37 +00:00
@pytest.mark.timeout(40)
def test_docker_tls_args(qemu, cloud_config):
2016-04-01 01:56:18 +00:00
SSH(qemu, ssh_command).check_call('''
set -e -x
sudo ros tls gen --server -H localhost
2016-04-01 01:56:18 +00:00
sudo ros tls gen
sudo ros c set rancher.docker.tls true
sudo system-docker restart docker
2016-04-01 18:00:42 +00:00
sleep 5
2016-04-01 01:56:18 +00:00
docker --tlsverify version
'''.strip())
2015-11-17 13:08:37 +00:00
2015-05-08 14:39:09 +00:00
@pytest.mark.timeout(40)
2015-05-08 17:22:26 +00:00
def test_rancher_network(qemu, cloud_config):
2016-04-01 18:00:42 +00:00
v = SSH(qemu, ssh_command).check_output('''
ip route get to 10.10.2.120
'''.strip())
2015-05-08 14:39:09 +00:00
2016-04-01 18:00:42 +00:00
assert v.split(' ')[5] + '/24' == \
cloud_config['rancher']['network']['interfaces']['mac=52:54:00:12:34:59']['address']
2016-06-06 17:17:21 +00:00
def test_docker_pid_one(qemu):
2016-04-01 01:56:18 +00:00
SSH(qemu, ssh_command).check_call('''
set -e -x
for i in $(pidof docker); do
2016-06-06 17:17:21 +00:00
if [ $i = 1 ]; then
found=true
fi
2016-04-01 01:56:18 +00:00
done
2016-06-06 17:17:21 +00:00
[ "$found" = "true" ]
'''.strip())