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 |
| 27 | * K8S_RUN_CONFORMANCE_TEST Run test (bool) |
| 28 | * |
| 29 | * INSTALL_K8S Install K8S (bool) |
| 30 | * INSTALL_OPENSTACK Install OpenStack (bool) |
| 31 | */ |
| 32 | |
| 33 | git = new com.mirantis.mk.git() |
| 34 | openstack = new com.mirantis.mk.openstack() |
| 35 | salt = new com.mirantis.mk.salt() |
| 36 | |
| 37 | node { |
| 38 | |
| 39 | // connection objects |
| 40 | def openstackCloud |
| 41 | def saltMaster |
| 42 | |
| 43 | // value defaults |
| 44 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : "liberty" |
| 45 | def openstackEnv = "${env.WORKSPACE}/venv" |
| 46 | |
| 47 | if (HEAT_STACK_NAME == "") { |
| 48 | HEAT_STACK_NAME = BUILD_TAG |
| 49 | } |
| 50 | |
| 51 | stage ('Download Heat templates') { |
| 52 | git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS) |
| 53 | } |
| 54 | |
Tomáš Kukrál | 7546709 | 2017-02-16 19:48:05 +0100 | [diff] [blame] | 55 | stage('Install OpenStack CLI') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 56 | openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion) |
| 57 | } |
| 58 | |
| 59 | stage('Connect to OpenStack cloud') { |
| 60 | openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT) |
| 61 | openstack.getKeystoneToken(openstackCloud, openstackEnv) |
| 62 | } |
| 63 | |
| 64 | stage('Launch new Heat stack') { |
| 65 | envParams = [ |
| 66 | 'availability_zone': HEAT_STACK_ZONE, |
| 67 | 'public_net': HEAT_STACK_PUBLIC_NET |
| 68 | ] |
| 69 | openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv) |
| 70 | } |
| 71 | |
| 72 | stage("Connect to Salt master") { |
| 73 | saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv) |
Tomáš Kukrál | 4b5f124 | 2017-02-16 19:15:02 +0100 | [diff] [blame] | 74 | saltMasterUrl = "http://${saltMasterHost}:8088" |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 75 | saltMaster = salt.createSaltConnection(saltMasterUrl, SALT_MASTER_CREDENTIALS) |
| 76 | } |
| 77 | |
| 78 | stage("Install core infra") { |
| 79 | // salt.master, reclass |
| 80 | // refresh_pillar |
| 81 | // sync_all |
| 82 | // linux,openssh,salt.minion.ntp |
| 83 | |
| 84 | salt.installFoundationInfra(saltMaster) |
| 85 | salt.validateFoundationInfra(saltMaster) |
| 86 | } |
| 87 | |
Tomáš Kukrál | adccdba | 2017-02-16 23:56:22 +0100 | [diff] [blame^] | 88 | if (INSTALL_K8S == 'true') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 89 | stage("Install Kubernetes infra") { |
| 90 | salt.installOpenstackMcpInfra(saltMaster) |
| 91 | } |
| 92 | |
| 93 | stage("Install Kubernetes control") { |
| 94 | salt.installOpenstackMcpControl(saltMaster) |
| 95 | } |
| 96 | |
Tomáš Kukrál | adccdba | 2017-02-16 23:56:22 +0100 | [diff] [blame^] | 97 | if (K8S_RUN_CONFORMANCE_TEST == 'true') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 98 | stage("Run k8s conformance e2e tests") { |
| 99 | salt.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE) |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
Tomáš Kukrál | adccdba | 2017-02-16 23:56:22 +0100 | [diff] [blame^] | 104 | if (INSTALL_OPENSTACK == 'true') { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 105 | // install Infra and control, tests, ... |
| 106 | |
| 107 | stage("Install OpenStack infra") { |
| 108 | salt.installOpenstackMkInfra(saltMaster) |
| 109 | } |
| 110 | |
| 111 | stage("Install OpenStack control") { |
| 112 | salt.installOpenstackMkControl(saltMaster) |
| 113 | } |
| 114 | |
| 115 | stage("Install OpenStack network") { |
| 116 | salt.installOpenstackMkNetwork(saltMaster) |
| 117 | } |
| 118 | |
| 119 | stage("Install OpenStack compute") { |
| 120 | salt.installOpenstackMkCompute(saltMaster) |
| 121 | } |
| 122 | } |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 123 | |
Tomáš Kukrál | adccdba | 2017-02-16 23:56:22 +0100 | [diff] [blame^] | 124 | if (HEAT_STACK_DELETE == 'true') { |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 125 | stage('Trigger cleanup job') { |
Tomáš Kukrál | 22a6500 | 2017-02-16 15:06:43 +0100 | [diff] [blame] | 126 | 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] | 127 | } |
| 128 | } |
Tomáš Kukrál | 5a34390 | 2017-02-16 11:01:11 +0100 | [diff] [blame] | 129 | } |