test_01_cloud_config.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pytest
  2. import rancherostest.util as u
  3. import subprocess
  4. import yaml
  5. ssh_command = ['ssh', '-p', '2222', '-F', './assets/scripts_ssh_config', '-i', './tests/integration/assets/test.key',
  6. 'rancher@localhost']
  7. cloud_config_path = './tests/integration/assets/cloud-config-01.yml'
  8. @pytest.fixture(scope="module")
  9. def qemu(request):
  10. return u.run_qemu(request, ['--cloud-config', cloud_config_path,
  11. '-net', 'nic,vlan=1,model=virtio', '-net', 'user,vlan=1,net=10.10.2.0/24'])
  12. @pytest.fixture(scope="module")
  13. def cloud_config():
  14. return yaml.load(open(cloud_config_path))
  15. @pytest.mark.timeout(40)
  16. def test_ssh_authorized_keys(qemu):
  17. assert qemu is not None
  18. u.wait_for_ssh(ssh_command)
  19. assert True
  20. @pytest.mark.timeout(40)
  21. def test_rancher_environment(qemu, cloud_config):
  22. assert qemu is not None
  23. u.wait_for_ssh(ssh_command)
  24. v = subprocess.check_output(
  25. ssh_command + ['sudo', 'rancherctl', 'env', 'printenv', 'FLANNEL_NETWORK'],
  26. stderr=subprocess.STDOUT, universal_newlines=True)
  27. assert v.strip() == cloud_config['rancher']['environment']['FLANNEL_NETWORK']
  28. @pytest.mark.timeout(40)
  29. def test_rancher_network(qemu, cloud_config):
  30. assert qemu is not None
  31. u.wait_for_ssh(ssh_command)
  32. v = subprocess.check_output(
  33. ssh_command + ['ip', 'route', 'get', 'to', '10.10.2.120'],
  34. stderr=subprocess.STDOUT, universal_newlines=True)
  35. assert v.split(' ')[2] == 'eth1'
  36. assert v.split(' ')[5] + '/24' == cloud_config['rancher']['network']['interfaces']['eth1']['address']