Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Launch heat stack with basic k8s |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * HEAT_TEMPLATE_URL URL to git repo with Heat templates |
| 7 | * HEAT_TEMPLATE_CREDENTIALS Credentials to the Heat templates repo |
| 8 | * HEAT_TEMPLATE_BRANCH Heat templates repo branch |
| 9 | * HEAT_STACK_NAME Heat stack name |
| 10 | * HEAT_STACK_TEMPLATE Heat stack HOT template |
| 11 | * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters |
| 12 | * HEAT_STACK_ZONE Heat stack availability zone |
| 13 | * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool |
| 14 | * HEAT_STACK_DELETE Delete Heat stack when finished (bool) |
| 15 | * HEAT_STACK_CLEANUP_JOB Name of job for deleting Heat stack |
| 16 | * |
| 17 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 18 | * |
| 19 | * OPENSTACK_API_URL OpenStack API address |
| 20 | * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API |
| 21 | * OPENSTACK_API_PROJECT OpenStack project to connect to |
| 22 | * OPENSTACK_API_CLIENT Versions of OpenStack python clients |
| 23 | * OPENSTACK_API_VERSION Version of the OpenStack API (2/3) |
| 24 | * |
| 25 | * K8S_API_SERVER Kubernetes API address |
| 26 | * K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 27 | * |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 28 | * INSTALL What should be installed (k8s, openstack, ...) |
| 29 | * TESTS Run tests (bool) |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | git = new com.mirantis.mk.git() |
| 33 | openstack = new com.mirantis.mk.openstack() |
| 34 | salt = new com.mirantis.mk.salt() |
| 35 | |
| 36 | node { |
| 37 | |
| 38 | // connection objects |
| 39 | def openstackCloud |
| 40 | def saltMaster |
| 41 | |
| 42 | // value defaults |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 43 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty' |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 44 | def openstackEnv = "${env.WORKSPACE}/venv" |
| 45 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 46 | if (HEAT_STACK_NAME == '') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 47 | HEAT_STACK_NAME = BUILD_TAG |
| 48 | } |
| 49 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 50 | // |
| 51 | // Bootstrap |
| 52 | // |
| 53 | |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 54 | stage ('Download Heat templates') { |
| 55 | git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS) |
| 56 | } |
| 57 | |
Tomáš Kukrál | 7546709 | 2017-02-16 19:48:05 +0100 | [diff] [blame] | 58 | stage('Install OpenStack CLI') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 59 | openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion) |
| 60 | } |
| 61 | |
| 62 | stage('Connect to OpenStack cloud') { |
| 63 | openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT) |
| 64 | openstack.getKeystoneToken(openstackCloud, openstackEnv) |
| 65 | } |
| 66 | |
| 67 | stage('Launch new Heat stack') { |
| 68 | envParams = [ |
| 69 | 'availability_zone': HEAT_STACK_ZONE, |
| 70 | 'public_net': HEAT_STACK_PUBLIC_NET |
| 71 | ] |
| 72 | openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv) |
| 73 | } |
| 74 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 75 | stage('Connect to Salt master') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 76 | saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv) |
Tomáš Kukrál | 4b5f124 | 2017-02-16 19:15:02 +0100 | [diff] [blame] | 77 | saltMasterUrl = "http://${saltMasterHost}:8088" |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 78 | saltMaster = salt.createSaltConnection(saltMasterUrl, SALT_MASTER_CREDENTIALS) |
| 79 | } |
| 80 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 81 | // |
| 82 | // Install |
| 83 | // |
| 84 | |
| 85 | stage('Install core infra') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 86 | // salt.master, reclass |
| 87 | // refresh_pillar |
| 88 | // sync_all |
| 89 | // linux,openssh,salt.minion.ntp |
| 90 | |
| 91 | salt.installFoundationInfra(saltMaster) |
| 92 | salt.validateFoundationInfra(saltMaster) |
| 93 | } |
| 94 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 95 | |
| 96 | if (INSTALL.toLowerCase().contains('k8s')) { |
| 97 | stage('Install Kubernetes infra') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 98 | salt.installOpenstackMcpInfra(saltMaster) |
| 99 | } |
| 100 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 101 | stage('Install Kubernetes control') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 102 | salt.installOpenstackMcpControl(saltMaster) |
| 103 | } |
| 104 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 105 | if (TESTS.toLowerCase().contains('k8s')) { |
Tomáš Kukrál | 490d975 | 2017-02-19 19:23:20 +0100 | [diff] [blame^] | 106 | stage('Run k8s bootstrap tests') { |
| 107 | salt.runConformanceTests(saltMaster, K8S_API_SERVER, 'tomkukral/k8s-scripts') |
| 108 | } |
| 109 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 110 | stage('Run k8s conformance e2e tests') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 111 | salt.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE) |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 116 | if (INSTALL.toLowerCase().contains('openstack')) { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 117 | // install Infra and control, tests, ... |
| 118 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 119 | stage('Install OpenStack infra') { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 120 | salt.installOpenstackMkInfra(saltMaster) |
| 121 | } |
| 122 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 123 | stage('Install OpenStack control') { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 124 | salt.installOpenstackMkControl(saltMaster) |
| 125 | } |
| 126 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 127 | stage('Install OpenStack network') { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 128 | salt.installOpenstackMkNetwork(saltMaster) |
| 129 | } |
| 130 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 131 | stage('Install OpenStack compute') { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 132 | salt.installOpenstackMkCompute(saltMaster) |
| 133 | } |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 134 | |
| 135 | //if (TESTS.toLowerCase().contains('openstack')) { |
| 136 | // stage('Run OpenStack tests') { |
| 137 | // salt... |
| 138 | // } |
| 139 | //} |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 140 | } |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 141 | |
Tomáš Kukrál | d92ab80 | 2017-02-17 11:34:07 +0100 | [diff] [blame] | 142 | // |
| 143 | // Cleanup |
| 144 | // |
| 145 | |
Tomáš Kukrál | adccdba | 2017-02-16 23:56:22 +0100 | [diff] [blame] | 146 | if (HEAT_STACK_DELETE == 'true') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 147 | stage('Trigger cleanup job') { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 148 | build job: 'deploy_heat_cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]] |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 149 | } |
| 150 | } |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 151 | } |