test_01_cloud_config.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import string
  2. import pytest
  3. import rostest.util as u
  4. from rostest.util import SSH
  5. import yaml
  6. ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
  7. cloud_config_path = './tests/integration/assets/test_01/cloud-config.yml'
  8. net_args = {'amd64': ['-net', 'nic,vlan=1,model=virtio,macaddr=52:54:00:12:34:59',
  9. '-net', 'user,vlan=1,net=10.10.2.0/24'],
  10. 'arm64': ['-netdev', 'user,id=net1,net=10.10.2.0/24',
  11. '-device', 'virtio-net-device,netdev=net1,mac=52:54:00:12:34:59']}
  12. net_args['arm'] = net_args['arm64']
  13. @pytest.fixture(scope="module")
  14. def qemu(request):
  15. q = u.run_qemu(request, ['--cloud-config', cloud_config_path] + net_args[u.arch])
  16. u.flush_out(q.stdout)
  17. return q
  18. @pytest.fixture(scope="module")
  19. def cloud_config():
  20. return yaml.load(open(cloud_config_path))
  21. @pytest.mark.timeout(40)
  22. def test_ssh_authorized_keys(qemu):
  23. u.wait_for_ssh(qemu, ssh_command)
  24. assert True
  25. @pytest.mark.timeout(40)
  26. def test_rancher_environment(qemu, cloud_config):
  27. v = SSH(qemu, ssh_command).check_output('''
  28. sudo ros env printenv FLANNEL_NETWORK
  29. '''.strip())
  30. assert v.strip() == cloud_config['rancher']['environment']['FLANNEL_NETWORK']
  31. @pytest.mark.timeout(40)
  32. def test_docker_args(qemu, cloud_config):
  33. v = SSH(qemu, ssh_command).check_output('''
  34. ps -ef | grep docker
  35. '''.strip())
  36. expected = string.join(cloud_config['rancher']['docker']['args'])
  37. assert v.find(expected) != -1
  38. @pytest.mark.timeout(40)
  39. def test_dhcpcd(qemu, cloud_config):
  40. v = SSH(qemu, ssh_command).check_output('''
  41. ps -ef | grep dhcpcd
  42. '''.strip())
  43. assert v.find('dhcpcd -M') != -1
  44. @pytest.mark.timeout(40)
  45. def test_services_include(qemu, cloud_config):
  46. u.wait_for_ssh(qemu, ssh_command, ['docker inspect kernel-headers >/dev/null 2>&1'])
  47. @pytest.mark.timeout(40)
  48. def test_docker_tls_args(qemu, cloud_config):
  49. SSH(qemu, ssh_command).check_call('''
  50. set -e -x
  51. sudo ros tls gen --server -H localhost
  52. sudo ros tls gen
  53. sudo ros c set rancher.docker.tls true
  54. sudo system-docker restart docker
  55. sleep 5
  56. docker --tlsverify version
  57. '''.strip())
  58. @pytest.mark.timeout(40)
  59. def test_rancher_network(qemu, cloud_config):
  60. v = SSH(qemu, ssh_command).check_output('''
  61. ip route get to 10.10.2.120
  62. '''.strip())
  63. assert v.split(' ')[5] + '/24' == \
  64. cloud_config['rancher']['network']['interfaces']['mac=52:54:00:12:34:59']['address']
  65. def test_docker_pid_one(qemu):
  66. SSH(qemu, ssh_command).check_call('''
  67. set -e -x
  68. for i in $(pidof docker); do
  69. if [ $i = 1 ]; then
  70. found=true
  71. fi
  72. done
  73. [ "$found" = "true" ]
  74. '''.strip())