You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.0 KiB

  1. def run(username, credentialsId, ami, network_plugin, aws_access, aws_secret) {
  2. def inventory_path = pwd() + "/inventory/sample/hosts.ini"
  3. dir('tests') {
  4. wrap([$class: 'AnsiColorBuildWrapper', colorMapName: "xterm"]) {
  5. try {
  6. create_vm("${env.JOB_NAME}-${env.BUILD_NUMBER}", inventory_path, ami, username, network_plugin, aws_access, aws_secret)
  7. install_cluster(inventory_path, credentialsId, network_plugin)
  8. test_apiserver(inventory_path, credentialsId)
  9. test_create_pod(inventory_path, credentialsId)
  10. test_network(inventory_path, credentialsId)
  11. } finally {
  12. delete_vm(inventory_path, credentialsId, aws_access, aws_secret)
  13. }
  14. }
  15. }
  16. }
  17. def create_vm(run_id, inventory_path, ami, username, network_plugin, aws_access, aws_secret) {
  18. ansiblePlaybook(
  19. inventory: 'local_inventory/hosts.cfg',
  20. playbook: 'cloud_playbooks/create-aws.yml',
  21. extraVars: [
  22. test_id: run_id,
  23. kube_network_plugin: network_plugin,
  24. aws_access_key: [value: aws_access, hidden: true],
  25. aws_secret_key: [value: aws_secret, hidden: true],
  26. aws_ami_id: ami,
  27. aws_security_group: [value: 'sg-cb0327a2', hidden: true],
  28. key_name: 'travis-ci',
  29. inventory_path: inventory_path,
  30. aws_region: 'eu-central-1',
  31. ssh_user: username
  32. ],
  33. colorized: true
  34. )
  35. }
  36. def delete_vm(inventory_path, credentialsId, aws_access, aws_secret) {
  37. ansiblePlaybook(
  38. inventory: inventory_path,
  39. playbook: 'cloud_playbooks/delete-aws.yml',
  40. credentialsId: credentialsId,
  41. extraVars: [
  42. aws_access_key: [value: aws_access, hidden: true],
  43. aws_secret_key: [value: aws_secret, hidden: true]
  44. ],
  45. colorized: true
  46. )
  47. }
  48. def install_cluster(inventory_path, credentialsId, network_plugin) {
  49. ansiblePlaybook(
  50. inventory: inventory_path,
  51. playbook: '../cluster.yml',
  52. sudo: true,
  53. credentialsId: credentialsId,
  54. extraVars: [
  55. kube_network_plugin: network_plugin
  56. ],
  57. extras: "-e cloud_provider=aws",
  58. colorized: true
  59. )
  60. }
  61. def test_apiserver(inventory_path, credentialsId) {
  62. ansiblePlaybook(
  63. inventory: inventory_path,
  64. playbook: 'testcases/010_check-apiserver.yml',
  65. credentialsId: credentialsId,
  66. colorized: true
  67. )
  68. }
  69. def test_create_pod(inventory_path, credentialsId) {
  70. ansiblePlaybook(
  71. inventory: inventory_path,
  72. playbook: 'testcases/020_check-create-pod.yml',
  73. sudo: true,
  74. credentialsId: credentialsId,
  75. colorized: true
  76. )
  77. }
  78. def test_network(inventory_path, credentialsId) {
  79. ansiblePlaybook(
  80. inventory: inventory_path,
  81. playbook: 'testcases/030_check-network.yml',
  82. sudo: true,
  83. credentialsId: credentialsId,
  84. colorized: true
  85. )
  86. }
  87. return this;