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