2015-09-11 15:27:00 +00:00
|
|
|
import string
|
2015-05-08 10:15:14 +00:00
|
|
|
import subprocess
|
|
|
|
|
2015-12-17 09:59:52 +00:00
|
|
|
import pytest
|
|
|
|
import rostest.util as u
|
|
|
|
import yaml
|
2015-05-08 10:15:14 +00:00
|
|
|
|
2015-09-18 15:58:42 +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
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def qemu(request):
|
2015-12-17 09:59:52 +00:00
|
|
|
q = u.run_qemu(request, ['--cloud-config', cloud_config_path,
|
|
|
|
'-net', 'nic,vlan=1,model=virtio', '-net', 'user,vlan=1,net=10.10.2.0/24'])
|
|
|
|
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):
|
2015-12-17 09:59:52 +00:00
|
|
|
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):
|
2015-12-17 09:59:52 +00:00
|
|
|
u.wait_for_ssh(qemu, ssh_command)
|
2015-05-08 10:15:14 +00:00
|
|
|
|
2015-05-08 13:58:10 +00:00
|
|
|
v = subprocess.check_output(
|
2015-11-18 09:04:46 +00:00
|
|
|
ssh_command + ['sudo', 'ros', 'env', 'printenv', 'FLANNEL_NETWORK'],
|
2015-05-08 13:58:10 +00:00
|
|
|
stderr=subprocess.STDOUT, universal_newlines=True)
|
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):
|
2015-12-17 09:59:52 +00:00
|
|
|
u.wait_for_ssh(qemu, ssh_command)
|
2015-09-11 15:27:00 +00:00
|
|
|
|
|
|
|
v = subprocess.check_output(
|
|
|
|
ssh_command + ['sh', '-c', 'ps -ef | grep docker'],
|
|
|
|
stderr=subprocess.STDOUT, universal_newlines=True)
|
|
|
|
|
|
|
|
expected = string.join(cloud_config['rancher']['docker']['args'])
|
|
|
|
|
|
|
|
assert v.find(expected) != -1
|
|
|
|
|
|
|
|
|
2015-11-18 09:50:56 +00:00
|
|
|
@pytest.mark.timeout(40)
|
|
|
|
def test_dhcpcd(qemu, cloud_config):
|
2015-12-17 09:59:52 +00:00
|
|
|
u.wait_for_ssh(qemu, ssh_command)
|
2015-11-18 09:50:56 +00:00
|
|
|
|
|
|
|
v = subprocess.check_output(
|
|
|
|
ssh_command + ['sh', '-c', 'ps -ef | grep dhcpcd'],
|
|
|
|
stderr=subprocess.STDOUT, universal_newlines=True)
|
|
|
|
|
|
|
|
assert v.find('dhcpcd -M') != -1
|
|
|
|
|
|
|
|
|
2015-11-17 13:08:37 +00:00
|
|
|
@pytest.mark.timeout(40)
|
|
|
|
def test_docker_tls_args(qemu, cloud_config):
|
2015-12-17 09:59:52 +00:00
|
|
|
u.wait_for_ssh(qemu, ssh_command)
|
2015-11-17 13:08:37 +00:00
|
|
|
|
|
|
|
subprocess.check_call(
|
2015-12-11 08:40:24 +00:00
|
|
|
ssh_command + ['sudo', 'ros', 'tls', 'gen'],
|
2015-11-17 13:08:37 +00:00
|
|
|
stderr=subprocess.STDOUT, universal_newlines=True)
|
|
|
|
|
|
|
|
subprocess.check_call(
|
2015-12-11 12:38:00 +00:00
|
|
|
ssh_command + ['docker', '--tlsverify', 'version'],
|
2015-11-17 13:08:37 +00:00
|
|
|
stderr=subprocess.STDOUT, universal_newlines=True)
|
|
|
|
|
|
|
|
|
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):
|
2015-12-17 09:59:52 +00:00
|
|
|
u.wait_for_ssh(qemu, ssh_command)
|
2015-05-08 14:39:09 +00:00
|
|
|
|
|
|
|
v = subprocess.check_output(
|
2015-05-08 15:02:08 +00:00
|
|
|
ssh_command + ['ip', 'route', 'get', 'to', '10.10.2.120'],
|
2015-05-08 14:39:09 +00:00
|
|
|
stderr=subprocess.STDOUT, universal_newlines=True)
|
|
|
|
|
2015-05-08 15:02:08 +00:00
|
|
|
assert v.split(' ')[2] == 'eth1'
|
2015-05-08 17:22:26 +00:00
|
|
|
assert v.split(' ')[5] + '/24' == cloud_config['rancher']['network']['interfaces']['eth1']['address']
|