Refactoring in salt functions
Complete refactoring of Orchestrate.groovy salt calls, fix bugs and
simplify code.
Change-Id: I5eced97df6b050c74932ea58254a0fa95e3d9849
diff --git a/src/com/mirantis/mk/Orchestrate.groovy b/src/com/mirantis/mk/Orchestrate.groovy
index 2afbd49..a49d594 100644
--- a/src/com/mirantis/mk/Orchestrate.groovy
+++ b/src/com/mirantis/mk/Orchestrate.groovy
@@ -7,11 +7,11 @@
def validateFoundationInfra(master) {
def salt = new com.mirantis.mk.Salt()
- salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
- salt.runSaltProcessStep(master, 'I@salt:minion', 'test.version', [], null, true)
- salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
- salt.runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory', [], null, true)
- salt.runSaltProcessStep(master, 'I@salt:minion', 'state.show_top', [], null, true)
+ salt.cmdRun(master, 'I@salt:master' ,'salt-key')
+ salt.runSaltProcessStep(master, 'I@salt:minion', 'test.version')
+ salt.cmdRun(master, 'I@salt:master' ,'reclass-salt --top')
+ salt.runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory')
+ salt.runSaltProcessStep(master, 'I@salt:minion', 'state.show_top')
}
def installFoundationInfra(master, staticMgmtNet=false) {
@@ -20,64 +20,55 @@
// NOTE(vsaienko) Apply reclass first, it may update cluster model
// apply linux and salt.master salt.minion states afterwards to make sure
// correct cluster model is used.
- salt.enforceState(master, 'I@salt:master', ['reclass'], true)
+ salt.enforceState(master, 'I@salt:master', ['reclass'])
- salt.enforceState(master, 'I@salt:master', ['linux.system'], true)
+ salt.enforceState(master, 'I@salt:master', ['linux.system'])
salt.enforceState(master, 'I@salt:master', ['salt.master'], true, false, null, false, 120, 2)
- salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
+ salt.fullRefresh(master, "*")
salt.enforceState(master, 'I@salt:master', ['salt.minion'], true, false, null, false, 60, 2)
- salt.enforceState(master, 'I@salt:master', ['salt.minion'], true)
- salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, '*', 'saltutil.refresh_grains', [], null, true)
- salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
+ salt.enforceState(master, 'I@salt:master', ['salt.minion'])
+ salt.fullRefresh(master, "*")
- salt.enforceState(master, '*', ['linux.system'], true)
+ salt.enforceState(master, '*', ['linux.system'])
if (staticMgmtNet) {
salt.runSaltProcessStep(master, '*', 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
}
- salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'ntp'], true)
+ salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'ntp'])
salt.enforceState(master, '*', ['salt.minion'], true, false, null, false, 60, 2)
sleep(5)
- salt.enforceState(master, '*', ['linux.network.host'], true)
+ salt.enforceState(master, '*', ['linux.network.host'])
}
def installFoundationInfraOnTarget(master, target, staticMgmtNet=false) {
def salt = new com.mirantis.mk.Salt()
salt.enforceState(master, 'I@salt:master', ['reclass'], true, false, null, false, 120, 2)
-
- salt.runSaltProcessStep(master, target, 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, target, 'saltutil.sync_all', [], null, true)
-
- salt.enforceState(master, target, ['linux.system'], true)
+ salt.fullRefresh(master, target)
+ salt.enforceState(master, target, ['linux.system'])
if (staticMgmtNet) {
salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
}
salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
- salt.enforceState(master, target, ['salt.minion'], true)
+ salt.enforceState(master, target, ['salt.minion'])
- salt.enforceState(master, target, ['linux', 'openssh', 'ntp'], true)
+ salt.enforceState(master, target, ['linux', 'openssh', 'ntp'])
sleep(5)
- salt.enforceState(master, target, ['linux.network.host'], true)
+ salt.enforceState(master, target, ['linux.network.host'])
}
def installInfraKvm(master) {
def salt = new com.mirantis.mk.Salt()
-
- salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.sync_all', [], null, true)
+ salt.fullRefresh(master, 'I@linux:system')
salt.enforceState(master, 'I@salt:control', ['salt.minion'], true, false, null, false, 60, 2)
- salt.enforceState(master, 'I@salt:control', ['linux.system', 'linux.network', 'ntp'], true)
- salt.enforceState(master, 'I@salt:control', 'libvirt', true)
- salt.enforceState(master, 'I@salt:control', 'salt.control', true)
+ salt.enforceState(master, 'I@salt:control', ['linux.system', 'linux.network', 'ntp'])
+ salt.enforceState(master, 'I@salt:control', 'libvirt')
+ salt.enforceState(master, 'I@salt:control', 'salt.control')
sleep(600)
- salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.sync_all', [], null, true)
+ salt.fullRefresh(master, '* and not kvm*')
}
def installInfra(master) {
@@ -85,40 +76,29 @@
// Install glusterfs
if (salt.testTarget(master, 'I@glusterfs:server')) {
- salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service', true)
+ salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service')
- withEnv(['ASK_ON_ERROR=false']){
- retry(5) {
- salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true)
- }
- }
-
- salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
- salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
+ salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true, true, null, false, -1, 5)
+ salt.cmdRun(master, 'I@glusterfs:server', "gluster peer status; gluster volume status")
}
// Ensure glusterfs clusters is ready
if (salt.testTarget(master, 'I@glusterfs:client')) {
- salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client', true)
+ salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client')
}
// Install galera
if (salt.testTarget(master, 'I@galera:master') || salt.testTarget(master, 'I@galera:slave')) {
- withEnv(['ASK_ON_ERROR=false']){
- retry(2) {
- salt.enforceState(master, 'I@galera:master', 'galera', true)
- }
- }
- salt.enforceState(master, 'I@galera:slave', 'galera', true)
+ salt.enforceState(master, 'I@galera:master', 'galera', true, true, null, false, -1, 2)
// Check galera status
salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
// If galera is not enabled check if we need to install mysql:server
} else if (salt.testTarget(master, 'I@mysql:server')){
- salt.enforceState(master, 'I@mysql:server', 'mysql.server', true)
+ salt.enforceState(master, 'I@mysql:server', 'mysql.server')
if (salt.testTarget(master, 'I@mysql:client')){
- salt.enforceState(master, 'I@mysql:client', 'mysql.client', true)
+ salt.enforceState(master, 'I@mysql:client', 'mysql.client')
}
}
@@ -130,32 +110,28 @@
// Install keepalived
if (salt.testTarget(master, 'I@keepalived:cluster')) {
- salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived', true)
- salt.enforceState(master, 'I@keepalived:cluster', 'keepalived', true)
+ salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived')
+ salt.enforceState(master, 'I@keepalived:cluster', 'keepalived')
}
// Install rabbitmq
if (salt.testTarget(master, 'I@rabbitmq:server')) {
- withEnv(['ASK_ON_ERROR=false']){
- retry(2) {
- salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true)
- }
- }
+ salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true, true, null, false, -1, 2)
// Check the rabbitmq status
- salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
+ salt.cmdRun(master, 'I@rabbitmq:server', 'rabbitmqctl cluster_status')
}
// Install haproxy
if (salt.testTarget(master, 'I@haproxy:proxy')) {
- salt.enforceState(master, 'I@haproxy:proxy', 'haproxy', true)
+ salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
}
// Install memcached
if (salt.testTarget(master, 'I@memcached:server')) {
- salt.enforceState(master, 'I@memcached:server', 'memcached', true)
+ salt.enforceState(master, 'I@memcached:server', 'memcached')
}
// Install etcd
@@ -166,10 +142,9 @@
}
def installOpenstackInfra(master) {
- def orchestrate = new com.mirantis.mk.Orchestrate()
-
- // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
- orchestrate.installInfra(master)
+ def common = new com.mirantis.mk.Common()
+ common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
+ installInfra(master)
}
@@ -178,18 +153,17 @@
// Install horizon dashboard
if (salt.testTarget(master, 'I@horizon:server')) {
- salt.enforceState(master, 'I@horizon:server', 'horizon', true)
+ salt.enforceState(master, 'I@horizon:server', 'horizon')
}
if (salt.testTarget(master, 'I@nginx:server')) {
- salt.enforceState(master, 'I@nginx:server', 'salt.minion', true)
- salt.enforceState(master, 'I@nginx:server', 'nginx', true)
+ salt.enforceState(master, 'I@nginx:server', 'salt.minion')
+ salt.enforceState(master, 'I@nginx:server', 'nginx')
}
// setup keystone service
if (salt.testTarget(master, 'I@keystone:server')) {
- //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
- salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server', true)
- salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
+ salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server')
+ salt.enforceState(master, 'I@keystone:server', 'keystone.server')
// populate keystone services/tenants/roles/users
// keystone:client must be called locally
@@ -198,78 +172,77 @@
sleep(30)
}
if (salt.testTarget(master, 'I@keystone:client')) {
- salt.enforceState(master, 'I@keystone:client and *01*', 'keystone.client', true)
- salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
+ salt.enforceState(master, 'I@keystone:client and *01*', 'keystone.client')
+ salt.enforceState(master, 'I@keystone:client', 'keystone.client')
}
if (salt.testTarget(master, 'I@keystone:server')) {
- salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonercv3; openstack service list'], null, true)
+ salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; openstack service list')
}
// Install glance
if (salt.testTarget(master, 'I@glance:server')) {
//runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
- salt.enforceState(master, 'I@glance:server and *01*', 'glance.server', true)
- salt.enforceState(master, 'I@glance:server', 'glance.server', true)
+ salt.enforceState(master, 'I@glance:server and *01*', 'glance.server')
+ salt.enforceState(master, 'I@glance:server', 'glance.server')
}
// Check glance service
if (salt.testTarget(master, 'I@glance:server')){
- salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
+ salt.cmdRun(master, 'I@keystone:server','. /root/keystonerc; glance image-list')
}
// Create glance resources
if (salt.testTarget(master, 'I@glance:client')) {
- salt.enforceState(master, 'I@glance:client', 'glance.client', true)
+ salt.enforceState(master, 'I@glance:client', 'glance.client')
}
// Install and check nova service
if (salt.testTarget(master, 'I@nova:controller')) {
- //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
- salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller', true)
- salt.enforceState(master, 'I@nova:controller', 'nova.controller', true)
+ // run on first node first
+ salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller')
+ salt.enforceState(master, 'I@nova:controller', 'nova.controller')
if (salt.testTarget(master, 'I@keystone:server')) {
- salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
+ salt.cmdRun(master, 'I@keystone:server', '. /root/keystonerc; nova service-list')
}
}
// Create nova resources
if (salt.testTarget(master, 'I@nova:client')) {
- salt.enforceState(master, 'I@nova:client', 'nova.client', true)
+ salt.enforceState(master, 'I@nova:client', 'nova.client')
}
// Install and check cinder service
if (salt.testTarget(master, 'I@cinder:controller')) {
- //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
- salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder', true)
- salt.enforceState(master, 'I@cinder:controller', 'cinder', true)
+ // run on first node first
+ salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder')
+ salt.enforceState(master, 'I@cinder:controller', 'cinder')
if (salt.testTarget(master, 'I@keystone:server')) {
- salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
+ salt.cmdRun(master, 'I@keystone:server', '. /root/keystonerc; cinder list')
}
}
// Install neutron service
if (salt.testTarget(master, 'I@neutron:server')) {
- //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
-
- salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server', true)
- salt.enforceState(master, 'I@neutron:server', 'neutron.server', true)
+ // run on first node first
+ salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server')
+ salt.enforceState(master, 'I@neutron:server', 'neutron.server')
if (salt.testTarget(master, 'I@keystone:server')) {
- salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
+ salt.cmdRun(master, 'I@keystone:server','. /root/keystonerc; neutron agent-list')
}
}
// Create neutron resources
if (salt.testTarget(master, 'I@neutron:client')) {
- salt.enforceState(master, 'I@neutron:client', 'neutron.client', true)
+ salt.enforceState(master, 'I@neutron:client', 'neutron.client')
}
// Install heat service
if (salt.testTarget(master, 'I@heat:server')) {
- //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
- salt.enforceState(master, 'I@heat:server and *01*', 'heat', true)
- salt.enforceState(master, 'I@heat:server', 'heat', true)
+ // run on first node first
+ salt.enforceState(master, 'I@heat:server and *01*', 'heat')
+ salt.enforceState(master, 'I@heat:server', 'heat')
if (salt.testTarget(master, 'I@keystone:server')) {
- salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
+ salt.cmdRun(master, 'I@keystone:server', '. /root/keystonerc; heat resource-type-list')
}
}
@@ -280,51 +253,51 @@
// Install ironic service
if (salt.testTarget(master, 'I@ironic:api')) {
- salt.enforceState(master, 'I@ironic:api and *01*', 'ironic.api', true)
- salt.enforceState(master, 'I@ironic:api', 'ironic.api', true)
+ salt.enforceState(master, 'I@ironic:api and *01*', 'ironic.api')
+ salt.enforceState(master, 'I@ironic:api', 'ironic.api')
}
// Install designate service
if (salt.testTarget(master, 'I@designate:server:enabled')) {
if (salt.testTarget(master, 'I@designate:server:backend:bind9')) {
- salt.enforceState(master, 'I@bind:server', 'bind.server', true)
+ salt.enforceState(master, 'I@bind:server', 'bind.server')
}
if (salt.testTarget(master, 'I@designate:server:backend:pdns4')) {
- salt.enforceState(master, 'I@powerdns:server', 'powerdns.server', true)
+ salt.enforceState(master, 'I@powerdns:server', 'powerdns.server')
}
- salt.enforceState(master, 'I@designate:server and *01*', 'designate.server', true)
- salt.enforceState(master, 'I@designate:server', 'designate.server', true)
+ salt.enforceState(master, 'I@designate:server and *01*', 'designate.server')
+ salt.enforceState(master, 'I@designate:server', 'designate.server')
}
// Install octavia api service
if (salt.testTarget(master, 'I@octavia:api')) {
- salt.enforceState(master, 'I@octavia:api', 'octavia', true)
+ salt.enforceState(master, 'I@octavia:api', 'octavia')
}
// Install DogTag server service
if (salt.testTarget(master, 'I@dogtag:server')) {
- salt.enforceState(master, 'I@dogtag:server and *01*', 'dogtag.server', true)
- salt.enforceState(master, 'I@dogtag:server', 'dogtag.server', true)
+ salt.enforceState(master, 'I@dogtag:server and *01*', 'dogtag.server')
+ salt.enforceState(master, 'I@dogtag:server', 'dogtag.server')
}
// Install barbican server service
if (salt.testTarget(master, 'I@barbican:server')) {
- salt.enforceState(master, 'I@barbican:server and *01*', 'barbican.server', true)
- salt.enforceState(master, 'I@barbican:server', 'barbican.server', true)
+ salt.enforceState(master, 'I@barbican:server and *01*', 'barbican.server')
+ salt.enforceState(master, 'I@barbican:server', 'barbican.server')
}
// Install barbican client
if (salt.testTarget(master, 'I@barbican:client')) {
- salt.enforceState(master, 'I@barbican:client', 'barbican.client', true)
+ salt.enforceState(master, 'I@barbican:client', 'barbican.client')
}
// Install ceilometer server
if (salt.testTarget(master, 'I@ceilometer:server')) {
- salt.enforceState(master, 'I@ceilometer:server', 'ceilometer', true)
+ salt.enforceState(master, 'I@ceilometer:server', 'ceilometer')
}
// Install aodh server
if (salt.testTarget(master, 'I@aodh:server')) {
- salt.enforceState(master, 'I@aodh:server', 'aodh', true)
+ salt.enforceState(master, 'I@aodh:server', 'aodh')
}
}
@@ -333,11 +306,11 @@
def salt = new com.mirantis.mk.Salt()
if (salt.testTarget(master, 'I@ironic:conductor')) {
- salt.enforceState(master, 'I@ironic:conductor', 'ironic.conductor', true)
- salt.enforceState(master, 'I@ironic:conductor', 'apache', true)
+ salt.enforceState(master, 'I@ironic:conductor', 'ironic.conductor')
+ salt.enforceState(master, 'I@ironic:conductor', 'apache')
}
if (salt.testTarget(master, 'I@tftpd_hpa:server')) {
- salt.enforceState(master, 'I@tftpd_hpa:server', 'tftpd_hpa', true)
+ salt.enforceState(master, 'I@tftpd_hpa:server', 'tftpd_hpa')
}
if (salt.testTarget(master, 'I@nova:compute')) {
@@ -345,10 +318,10 @@
}
if (salt.testTarget(master, 'I@baremetal_simulator:enabled')) {
- salt.enforceState(master, 'I@baremetal_simulator:enabled', 'baremetal_simulator', true)
+ salt.enforceState(master, 'I@baremetal_simulator:enabled', 'baremetal_simulator')
}
if (salt.testTarget(master, 'I@ironic:client')) {
- salt.enforceState(master, 'I@ironic:client', 'ironic.client', true)
+ salt.enforceState(master, 'I@ironic:client', 'ironic.client')
}
}
@@ -357,24 +330,23 @@
def installOpenstackNetwork(master, physical = "false") {
def salt = new com.mirantis.mk.Salt()
- salt.runSaltProcessStep(master, 'I@neutron:gateway', 'state.apply', [], null, true)
+ salt.enforceHighstate(master, 'I@neutron:gateway')
// install octavia manager services
if (salt.testTarget(master, 'I@octavia:manager')) {
- salt.runSaltProcessStep(master, 'I@salt:master', 'mine.update', ['*'], null, true)
- salt.enforceState(master, 'I@octavia:manager', 'octavia', true)
- salt.enforceState(master, 'I@octavia:manager', 'salt.minion.ca', true)
- salt.enforceState(master, 'I@octavia:manager', 'salt.minion.cert', true)
+ salt.runSaltProcessStep(master, 'I@salt:master', 'mine.update', ['*'])
+ salt.enforceState(master, 'I@octavia:manager', 'octavia')
+ salt.enforceState(master, 'I@octavia:manager', 'salt.minion.ca')
+ salt.enforceState(master, 'I@octavia:manager', 'salt.minion.cert')
}
}
def installOpenstackCompute(master) {
def salt = new com.mirantis.mk.Salt()
-
// Configure compute nodes
retry(2) {
- salt.runSaltProcessStep(master, 'I@nova:compute', 'state.highstate', ['exclude=opencontrail.client'], null, true)
+ salt.enforceHighstateWithExclude(master, 'I@nova:compute', 'opencontrail.client')
}
}
@@ -385,31 +357,16 @@
// Install opencontrail database services
- //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
- if(env["ASK_ON_ERROR"] && env["ASK_ON_ERROR"] == "true"){
- salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
- salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database', true)
- }else{
- try {
- salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
- } catch (Exception e) {
- common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database and *01*')
- }
- try {
- salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
- } catch (Exception e) {
- common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
- }
- }
+ salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database')
+ salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database')
// Install opencontrail control services
- //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
- salt.runSaltProcessStep(master, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
- salt.runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
- salt.runSaltProcessStep(master, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
+ salt.enforceStateWithExclude(master, "I@opencontrail:control and *01*", "opencontrail", "opencontrail.client")
+ salt.enforceStateWithExclude(master, "I@opencontrail:control", "opencontrail", "opencontrail.client")
+ salt.enforceStateWithExclude(master, "I@opencontrail:collector and *01*", "opencontrail", "opencontrail.client")
if (salt.testTarget(master, 'I@docker:client and I@opencontrail:control')) {
- salt.enforceState(master, 'I@opencontrail:control or I@opencontrail:collector', 'docker.client', true)
+ salt.enforceState(master, 'I@opencontrail:control or I@opencontrail:collector', 'docker.client')
}
}
@@ -419,34 +376,26 @@
def common = new com.mirantis.mk.Common()
// Configure compute nodes
// Provision opencontrail control services
- salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client', true)
+ salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client')
// Provision opencontrail virtual routers
// Generate script /usr/lib/contrail/if-vhost0 for up vhost0
- if(env["ASK_ON_ERROR"] && env["ASK_ON_ERROR"] == "true"){
- salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
- }else{
- try {
- salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
- } catch (Exception e) {
- common.warningMsg('Exception in state opencontrail on I@opencontrail:compute')
- }
- }
+ salt.enforceStateWithExclude(master, "I@opencontrail:compute", "opencontrail", "opencontrail.client")
- salt.runSaltProcessStep(master, 'I@nova:compute', 'cmd.run', ['exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || sleep 5 && reboot & "'], null, true)
+ salt.cmdRun(master, 'I@nova:compute', 'exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || sleep 5 && reboot & "')
if (salt.testTarget(master, 'I@opencontrail:compute')) {
sleep(300)
- salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client', true)
- salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail', true)
+ salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client')
+ salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail')
}
}
def installKubernetesInfra(master) {
- def orchestrate = new com.mirantis.mk.Orchestrate()
- // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
- orchestrate.installInfra(master)
+ def common = new com.mirantis.mk.Common()
+ common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
+ installInfra(master)
}
@@ -463,7 +412,7 @@
}
// Run k8s without master.setup
- salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
+ salt.enforceStateWithExclude(master, 'I@kubernetes:master', "kubernetes", "kubernetes.master.setup")
// Run k8s master setup
salt.enforceState(master, 'I@kubernetes:master and *01*', 'kubernetes.master.setup')
@@ -475,10 +424,7 @@
def installKubernetesCompute(master) {
def salt = new com.mirantis.mk.Salt()
-
- // Refresh minion's pillar data
- salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
+ salt.fullRefresh(master, "*")
// Bootstrap all nodes
salt.enforceState(master, 'I@kubernetes:pool', 'linux')
@@ -506,23 +452,20 @@
//Install and Configure Docker
salt.enforceState(master, 'I@docker:swarm', 'docker.host')
- salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm', true)
- salt.enforceState(master, 'I@docker:swarm', 'salt.minion.grains', true)
- salt.runSaltProcessStep(master, 'I@docker:swarm', 'mine.update', [], null, true)
- salt.runSaltProcessStep(master, 'I@docker:swarm', 'saltutil.refresh_modules', [], null, true)
+ salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm')
+ salt.enforceState(master, 'I@docker:swarm', 'salt.minion.grains')
+ salt.runSaltProcessStep(master, 'I@docker:swarm', 'mine.update')
+ salt.runSaltProcessStep(master, 'I@docker:swarm', 'saltutil.refresh_modules')
sleep(5)
- salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm', true)
- salt.enforceState(master, 'I@docker:swarm:role:manager', 'docker.swarm', true)
- salt.cmdRun(master, 'I@docker:swarm:role:master', 'docker node ls', true)
+ salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm')
+ salt.enforceState(master, 'I@docker:swarm:role:manager', 'docker.swarm')
+ salt.cmdRun(master, 'I@docker:swarm:role:master', 'docker node ls')
}
def installCicd(master) {
def salt = new com.mirantis.mk.Salt()
-
- //Install and Configure Docker
- salt.runSaltProcessStep(master, 'I@jenkins:client or I@gerrit:client', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, 'I@jenkins:client or I@gerrit:client', 'saltutil.sync_all', [], null, true)
+ salt.fullRefresh(master, 'I@jenkins:client or I@gerrit:client')
if (salt.testTarget(master, 'I@aptly:publisher')) {
salt.enforceState(master, 'I@aptly:publisher', 'aptly.publisher',true, null, false, -1, 2)
@@ -540,25 +483,23 @@
}
if (salt.testTarget(master, 'I@python:environment')) {
- salt.enforceState(master, 'I@python:environment', 'python', true)
+ salt.enforceState(master, 'I@python:environment', 'python')
}
withEnv(['ASK_ON_ERROR=false']){
retry(2){
try{
- salt.enforceState(master, 'I@gerrit:client', 'gerrit', true)
+ salt.enforceState(master, 'I@gerrit:client', 'gerrit')
}catch(e){
- salt.runSaltProcessStep(master, 'I@gerrit:client', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, 'I@gerrit:client', 'saltutil.sync_all', [], null, true)
+ salt.fullRefresh(master, 'I@gerrit:client')
throw e //rethrow for retry handler
}
}
retry(2){
try{
- salt.enforceState(master, 'I@jenkins:client', 'jenkins', true)
+ salt.enforceState(master, 'I@jenkins:client', 'jenkins')
}catch(e){
- salt.runSaltProcessStep(master, 'I@jenkins:client', 'saltutil.refresh_pillar', [], null, true)
- salt.runSaltProcessStep(master, 'I@jenkins:client', 'saltutil.sync_all', [], null, true)
+ salt.fullRefresh(master, 'I@jenkins:client')
throw e //rethrow for retry handler
}
}
@@ -578,52 +519,48 @@
salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
if (salt.testTarget(master, 'I@nginx:server')) {
- salt.enforceState(master, 'I@nginx:server', 'nginx', true)
+ salt.enforceState(master, 'I@nginx:server', 'nginx')
}
if (salt.testTarget(master, 'I@glusterfs:client')) {
- salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client', true)
+ salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client')
}
}
// Launch containers
- salt.enforceState(master, 'I@docker:swarm:role:master and I@prometheus:server', 'docker.client', true)
- salt.runSaltProcessStep(master, 'I@docker:swarm and I@prometheus:server', 'dockerng.ps', [], null, true)
+ salt.enforceState(master, 'I@docker:swarm:role:master and I@prometheus:server', 'docker.client')
+ salt.runSaltProcessStep(master, 'I@docker:swarm and I@prometheus:server', 'dockerng.ps')
//Install Telegraf
- salt.enforceState(master, 'I@telegraf:agent or I@telegraf:remote_agent', 'telegraf', true)
+ salt.enforceState(master, 'I@telegraf:agent or I@telegraf:remote_agent', 'telegraf')
// Install Prometheus exporters
if (salt.testTarget(master, 'I@prometheus:exporters')) {
- salt.enforceState(master, 'I@prometheus:exporters', 'prometheus', true)
+ salt.enforceState(master, 'I@prometheus:exporters', 'prometheus')
}
//Install Elasticsearch and Kibana
- salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
- salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
- salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
- salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
- salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
- salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
- salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
- salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
+ salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server')
+ salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server')
+ salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server')
+ salt.enforceState(master, 'I@kibana:server', 'kibana.server')
+ salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client')
+ salt.enforceState(master, 'I@kibana:client', 'kibana.client')
+ salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb')
+ salt.enforceState(master, 'I@influxdb:server', 'influxdb')
salt.enforceState(master, 'I@heka:log_collector', 'heka.log_collector')
// Install heka ceilometer collector
if (salt.testTarget(master, 'I@heka:ceilometer_collector:enabled')) {
- salt.enforceState(master, 'I@heka:ceilometer_collector:enabled', 'heka.ceilometer_collector', true)
+ salt.enforceState(master, 'I@heka:ceilometer_collector:enabled', 'heka.ceilometer_collector')
salt.runSaltProcessStep(master, 'I@heka:ceilometer_collector:enabled', 'service.restart', ['ceilometer_collector'], null, true)
}
// Install galera
if (common.checkContains('STACK_INSTALL', 'k8s')) {
- withEnv(['ASK_ON_ERROR=false']){
- retry(2) {
- salt.enforceState(master, 'I@galera:master', 'galera', true)
- }
- }
- salt.enforceState(master, 'I@galera:slave', 'galera', true)
+ salt.enforceState(master, 'I@galera:master', 'galera', true, true, null, false, -1, 2)
+ salt.enforceState(master, 'I@galera:slave', 'galera')
// Check galera status
salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
@@ -631,17 +568,16 @@
}
//Collect Grains
- salt.enforceState(master, 'I@salt:minion', 'salt.minion.grains', true)
- salt.runSaltProcessStep(master, 'I@salt:minion', 'saltutil.refresh_modules', [], null, true)
- salt.runSaltProcessStep(master, 'I@salt:minion', 'mine.update', [], null, true)
+ salt.enforceState(master, 'I@salt:minion', 'salt.minion.grains')
+ salt.runSaltProcessStep(master, 'I@salt:minion', 'saltutil.refresh_modules')
+ salt.runSaltProcessStep(master, 'I@salt:minion', 'mine.update')
sleep(5)
//Configure services in Docker Swarm
if (common.checkContains('STACK_INSTALL', 'k8s')) {
- salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', 'prometheus', true, false)
- }
- else {
- salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', ['prometheus', 'heka.remote_collector'], true, false)
+ salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', 'prometheus', true, false)
+ } else {
+ salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', ['prometheus', 'heka.remote_collector'], true, false)
}
//Configure Grafana
@@ -657,7 +593,7 @@
common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
sleep(120)
- salt.enforceState(master, 'I@grafana:client', 'grafana.client', true)
+ salt.enforceState(master, 'I@grafana:client', 'grafana.client')
}
def installStacklightv1Control(master) {
@@ -665,17 +601,17 @@
// infra install
// Install the StackLight backends
- salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
- salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
+ salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server')
+ salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server')
- salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
- salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
+ salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb')
+ salt.enforceState(master, 'I@influxdb:server', 'influxdb')
- salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
- salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
+ salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server')
+ salt.enforceState(master, 'I@kibana:server', 'kibana.server')
- salt.enforceState(master, '*01* and I@grafana:server','grafana.server', true)
- salt.enforceState(master, 'I@grafana:server','grafana.server', true)
+ salt.enforceState(master, '*01* and I@grafana:server','grafana.server')
+ salt.enforceState(master, 'I@grafana:server','grafana.server')
def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
def alarming_service = alarming_service_pillar['return'][0].values()[0]
@@ -683,20 +619,20 @@
switch (alarming_service) {
case 'sensu':
// Update Sensu
- salt.enforceState(master, 'I@sensu:server and I@rabbitmq:server', 'rabbitmq', true)
- salt.enforceState(master, 'I@redis:cluster:role:master', 'redis', true)
- salt.enforceState(master, 'I@redis:server', 'redis', true)
- salt.enforceState(master, 'I@sensu:server', 'sensu', true)
+ salt.enforceState(master, 'I@sensu:server and I@rabbitmq:server', 'rabbitmq')
+ salt.enforceState(master, 'I@redis:cluster:role:master', 'redis')
+ salt.enforceState(master, 'I@redis:server', 'redis')
+ salt.enforceState(master, 'I@sensu:server', 'sensu')
default:
// Update Nagios
- salt.enforceState(master, 'I@nagios:server', 'nagios.server', true)
+ salt.enforceState(master, 'I@nagios:server', 'nagios.server')
// Stop the Nagios service because the package starts it by default and it will
// started later only on the node holding the VIP address
salt.runSaltProcessStep(master, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
}
- salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
- salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
+ salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service')
+ salt.enforceState(master, 'I@kibana:client', 'kibana.client')
sleep(10)
}
@@ -705,32 +641,32 @@
def salt = new com.mirantis.mk.Salt()
def common = new com.mirantis.mk.Common()
- salt.runSaltProcessStep(master, 'I@elasticsearch:client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
+ salt.cmdRun(master, 'I@elasticsearch:client', 'salt-call state.sls elasticsearch.client')
// salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
- salt.runSaltProcessStep(master, 'I@kibana:client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
+ salt.cmdRun(master, 'I@kibana:client', 'salt-call state.sls kibana.client')
// salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
// Install collectd, heka and sensu services on the nodes, this will also
// generate the metadata that goes into the grains and eventually into Salt Mine
- salt.enforceState(master, '*', 'collectd', true)
- salt.enforceState(master, '*', 'salt.minion', true)
- salt.enforceState(master, '*', 'heka', true)
+ salt.enforceState(master, '*', 'collectd')
+ salt.enforceState(master, '*', 'salt.minion')
+ salt.enforceState(master, '*', 'heka')
// Gather the Grafana metadata as grains
salt.enforceState(master, 'I@grafana:collector', 'grafana.collector', true)
// Update Salt Mine
- salt.enforceState(master, '*', 'salt.minion.grains', true)
- salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules', [], null, true)
- salt.runSaltProcessStep(master, '*', 'mine.update', [], null, true)
+ salt.enforceState(master, '*', 'salt.minion.grains')
+ salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules')
+ salt.runSaltProcessStep(master, '*', 'mine.update')
sleep(5)
// Update Heka
- salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
+ salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka')
// Update collectd
- salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd', true)
+ salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd')
def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
def alarming_service = alarming_service_pillar['return'][0].values()[0]
@@ -739,19 +675,19 @@
case 'sensu':
// Update Sensu
// TODO for stacklight team, should be fixed in model
- salt.enforceState(master, 'I@sensu:client', 'sensu', true)
+ salt.enforceState(master, 'I@sensu:client', 'sensu')
default:
break
// Default is nagios, and was enforced in installStacklightControl()
}
- salt.runSaltProcessStep(master, 'I@grafana:client and *01*', 'cmd.run', ['salt-call state.sls grafana.client'], null, true)
+ salt.cmdRun(master, 'I@grafana:client and *01*', 'salt-call state.sls grafana.client')
// salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
// Finalize the configuration of Grafana (add the dashboards...)
- salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
- salt.enforceState(master, 'I@grafana:client and *02*', 'grafana.client', true)
- salt.enforceState(master, 'I@grafana:client and *03*', 'grafana.client', true)
+ salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client')
+ salt.enforceState(master, 'I@grafana:client and *02*', 'grafana.client')
+ salt.enforceState(master, 'I@grafana:client and *03*', 'grafana.client')
// nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
// Get the StackLight monitoring VIP addres
@@ -764,10 +700,10 @@
if (stacklight_vip) {
// (re)Start manually the services that are bound to the monitoring VIP
common.infoMsg("restart services on node with IP: ${stacklight_vip}")
- salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
- salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
- salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
- salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
+ salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'])
+ salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'])
+ salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'])
+ salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'])
} else {
throw new Exception("Missing stacklight_vip")
}
@@ -781,19 +717,19 @@
def installCephMon(master, target='I@ceph:mon') {
def salt = new com.mirantis.mk.Salt()
- salt.enforceState(master, 'I@ceph:common', 'salt.minion.grains', true)
+ salt.enforceState(master, 'I@ceph:common', 'salt.minion.grains')
// generate keyrings
if (salt.testTarget(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin')) {
- salt.enforceState(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'ceph.mon', true)
- salt.runSaltProcessStep(master, 'I@ceph:mon', 'saltutil.sync_grains', [], null, true)
- salt.runSaltProcessStep(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'mine.update', [], null, true)
+ salt.enforceState(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'ceph.mon')
+ salt.runSaltProcessStep(master, 'I@ceph:mon', 'saltutil.sync_grains')
+ salt.runSaltProcessStep(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'mine.update')
sleep(5)
}
// install Ceph Mons
- salt.enforceState(master, target, 'ceph.mon', true)
+ salt.enforceState(master, target, 'ceph.mon')
if (salt.testTarget(master, 'I@ceph:mgr')) {
- salt.enforceState(master, 'I@ceph:mgr', 'ceph.mgr', true)
+ salt.enforceState(master, 'I@ceph:mgr', 'ceph.mgr')
}
}
@@ -801,16 +737,16 @@
def salt = new com.mirantis.mk.Salt()
// install Ceph OSDs
- salt.enforceState(master, target, 'ceph.osd', true)
- salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains', [], null, true)
- salt.enforceState(master, target, 'ceph.osd.custom', true)
- salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains', [], null, true)
- salt.runSaltProcessStep(master, 'I@ceph:osd', 'mine.update', [], null, true)
+ salt.enforceState(master, target, 'ceph.osd')
+ salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains')
+ salt.enforceState(master, target, 'ceph.osd.custom')
+ salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains')
+ salt.runSaltProcessStep(master, 'I@ceph:osd', 'mine.update')
// setup pools, keyrings and maybe crush
if (salt.testTarget(master, 'I@ceph:setup') && setup) {
sleep(5)
- salt.enforceState(master, 'I@ceph:setup', 'ceph.setup', true)
+ salt.enforceState(master, 'I@ceph:setup', 'ceph.setup')
}
}
@@ -819,12 +755,12 @@
// install Ceph Radosgw
if (salt.testTarget(master, 'I@ceph:radosgw')) {
- salt.runSaltProcessStep(master, 'I@ceph:radosgw', 'saltutil.sync_grains', [], null, true)
- salt.enforceState(master, 'I@ceph:radosgw', 'ceph.radosgw', true)
+ salt.runSaltProcessStep(master, 'I@ceph:radosgw', 'saltutil.sync_grains')
+ salt.enforceState(master, 'I@ceph:radosgw', 'ceph.radosgw')
}
// setup Keystone service and endpoints for swift or / and S3
if (salt.testTarget(master, 'I@keystone:client')) {
- salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
+ salt.enforceState(master, 'I@keystone:client', 'keystone.client')
}
}
@@ -833,16 +769,16 @@
// connect Ceph to the env
if (salt.testTarget(master, 'I@ceph:common and I@glance:server')) {
- salt.enforceState(master, 'I@ceph:common and I@glance:server', ['ceph.common', 'ceph.setup.keyring', 'glance'], true)
+ salt.enforceState(master, 'I@ceph:common and I@glance:server', ['ceph.common', 'ceph.setup.keyring', 'glance'])
salt.runSaltProcessStep(master, 'I@ceph:common and I@glance:server', 'service.restart', ['glance-api', 'glance-glare', 'glance-registry'])
}
if (salt.testTarget(master, 'I@ceph:common and I@cinder:controller')) {
- salt.enforceState(master, 'I@ceph:common and I@cinder:controller', ['ceph.common', 'ceph.setup.keyring', 'cinder'], true)
+ salt.enforceState(master, 'I@ceph:common and I@cinder:controller', ['ceph.common', 'ceph.setup.keyring', 'cinder'])
}
if (salt.testTarget(master, 'I@ceph:common and I@nova:compute')) {
- salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['ceph.common', 'ceph.setup.keyring'], true)
- salt.runSaltProcessStep(master, 'I@ceph:common and I@nova:compute', 'saltutil.sync_grains', [], null, true)
- salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['nova'], true)
+ salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['ceph.common', 'ceph.setup.keyring'])
+ salt.runSaltProcessStep(master, 'I@ceph:common and I@nova:compute', 'saltutil.sync_grains')
+ salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['nova'])
}
}
@@ -856,9 +792,9 @@
}
if (salt.testTarget(master, 'I@devops_portal:config')) {
- salt.enforceState(master, 'I@devops_portal:config', 'devops_portal.config', true)
- salt.enforceState(master, 'I@rundeck:client', ['linux.system.user', 'openssh'], true)
- salt.enforceState(master, 'I@rundeck:server', 'rundeck.server', true)
+ salt.enforceState(master, 'I@devops_portal:config', 'devops_portal.config')
+ salt.enforceState(master, 'I@rundeck:client', ['linux.system.user', 'openssh'])
+ salt.enforceState(master, 'I@rundeck:server', 'rundeck.server')
}
}
@@ -891,14 +827,14 @@
common.infoMsg("Waiting for Pushkin to come up..")
salt.cmdRun(master, 'I@postgresql:client', "while true; do curl -sf ${oss_vip}:8887/apps >/dev/null && break; done")
}
- salt.enforceState(master, 'I@postgresql:client', 'postgresql.client', true)
+ salt.enforceState(master, 'I@postgresql:client', 'postgresql.client')
// Rundeck
timeout(10) {
common.infoMsg("Waiting for Rundeck to come up..")
salt.cmdRun(master, 'I@rundeck:client', "while true; do curl -sf ${oss_vip}:4440 >/dev/null && break; done")
}
- salt.enforceState(master, 'I@rundeck:client', 'rundeck.client', true)
+ salt.enforceState(master, 'I@rundeck:client', 'rundeck.client')
// Elasticsearch
pillar = salt.getPillar(master, 'I@elasticsearch:client', 'elasticsearch:client:server:host')
@@ -913,5 +849,5 @@
common.infoMsg('Waiting for Elasticsearch to come up..')
salt.cmdRun(master, 'I@elasticsearch:client', "while true; do curl -sf ${elasticsearch_vip}:9200 >/dev/null && break; done")
}
- salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
+ salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client')
}
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index c112de8..2e7b4b3 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -128,27 +128,49 @@
}
}
+
/**
* Enforces state on given saltId and target
* @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
* @param target State enforcing target
* @param state Salt state
+ * @param excludedStates states which will be excluded from main state (default empty string)
+ * @param output print output (optional, default true)
+ * @param failOnError throw exception on salt state result:false (optional, default true)
+ * @param batch salt batch parameter integer or string with percents (optional, default null - disable batch)
+ * @param optional Optional flag (if true pipeline will continue even if no minions for target found)
+ * @param read_timeout http session read timeout (optional, default -1 - disabled)
+ * @param retries Retry count for salt state. (optional, default -1 - no retries)
+ * @param queue salt queue parameter for state.sls calls (optional, default true) - CANNOT BE USED WITH BATCH
+ * @param saltArgs additional salt args eq. ["runas=aptly"]
+ * @return output of salt command
+ */
+def enforceStateWithExclude(saltId, target, state, excludedStates = "", output = true, failOnError = true, batch = null, optional = false, read_timeout=-1, retries=-1, queue=true, saltArgs=[]) {
+ saltArgs << "exclude=${excludedStates}"
+ return enforceState(saltId, target, state, output, failOnError, batch, optional, read_timeout, retries, queue, saltArgs)
+}
+
+/* Enforces state on given saltId and target
+ * @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
+ * @param target State enforcing target
+ * @param state Salt state
* @param output print output (optional, default true)
* @param failOnError throw exception on salt state result:false (optional, default true)
* @param batch salt batch parameter integer or string with percents (optional, default null - disable batch)
+ * @param optional Optional flag (if true pipeline will continue even if no minions for target found)
* @param read_timeout http session read timeout (optional, default -1 - disabled)
* @param retries Retry count for salt state. (optional, default -1 - no retries)
* @param queue salt queue parameter for state.sls calls (optional, default true) - CANNOT BE USED WITH BATCH
+ * @param saltArgs additional salt args eq. ["runas=aptly", exclude="opencontrail.database"]
* @return output of salt command
*/
-def enforceState(saltId, target, state, output = true, failOnError = true, batch = null, optional = false, read_timeout=-1, retries=-1, queue=true) {
+def enforceState(saltId, target, state, output = true, failOnError = true, batch = null, optional = false, read_timeout=-1, retries=-1, queue=true, saltArgs = []) {
def common = new com.mirantis.mk.Common()
- def run_states
-
+ // add state to salt args
if (state instanceof String) {
- run_states = state
+ saltArgs << state
} else {
- run_states = state.join(',')
+ saltArgs << state.join(',')
}
common.infoMsg("Running state ${run_states} on ${target}")
@@ -161,13 +183,15 @@
if (optional == false || testTarget(saltId, target)){
if (retries > 0){
- failOnError = true
retry(retries){
- out = runSaltCommand(saltId, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, [run_states], kwargs, -1, read_timeout)
- checkResult(out, failOnError, output)
+ // we have to reverse order in saltArgs because salt state have to be first
+ out = runSaltCommand(saltId, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, saltArgs.reverse(), kwargs, -1, read_timeout)
+ // failOnError should be passed as true because we need to throw exception for retry block handler
+ checkResult(out, true, output, true, true) //disable ask on error because we are using retry here
}
} else {
- out = runSaltCommand(saltId, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, [run_states], kwargs, -1, read_timeout)
+ // we have to reverse order in saltArgs because salt state have to be first
+ out = runSaltCommand(saltId, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, saltArgs.reverse(), kwargs, -1, read_timeout)
checkResult(out, failOnError, output)
}
waitForMinion(out)
@@ -196,6 +220,7 @@
cmd = cmd + " && echo Salt command execution success"
}
+ // add cmd name to salt args list
saltArgs << cmd
def out = runSaltCommand(saltId, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', batch, saltArgs.reverse())
@@ -391,6 +416,34 @@
}
/**
+ * Perform complete salt refresh between master and target
+ * Method will call saltutil.refresh_pillar, saltutil.refresh_grains and saltutil.sync_all
+ * @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
+ * @param target Get pillar target
+ * @return output of salt command
+ */
+def fullRefresh(saltId, target){
+ runSaltProcessStep(saltId, target, 'saltutil.refresh_pillar', [], null, true)
+ runSaltProcessStep(saltId, target, 'saltutil.refresh_grains', [], null, true)
+ runSaltProcessStep(saltId, target, 'saltutil.sync_all', [], null, true)
+}
+
+/**
+ * Enforce highstate on given targets
+ * @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
+ * @param target Highstate enforcing target
+ * @param excludedStates states which will be excluded from main state (default empty string)
+ * @param output print output (optional, default true)
+ * @param failOnError throw exception on salt state result:false (optional, default true)
+ * @param batch salt batch parameter integer or string with percents (optional, default null - disable batch)
+ * @param saltArgs additional salt args eq. ["runas=aptly", exclude="opencontrail.database"]
+ * @return output of salt command
+ */
+def enforceHighstateWithExclude(saltId, target, excludedStates = "", output = false, failOnError = true, batch = null, saltArgs = []) {
+ saltArgs << "exclude=${excludedStates}"
+ return enforceHighstate(saltId, target, output, failOnError, batch, saltArgs)
+}
+/**
* Enforce highstate on given targets
* @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
* @param target Highstate enforcing target
@@ -399,7 +452,7 @@
* @param batch salt batch parameter integer or string with percents (optional, default null - disable batch)
* @return output of salt command
*/
-def enforceHighstate(saltId, target, output = false, failOnError = true, batch = null) {
+def enforceHighstate(saltId, target, output = false, failOnError = true, batch = null, saltArgs = []) {
def out = runSaltCommand(saltId, 'local', ['expression': target, 'type': 'compound'], 'state.highstate', batch)
def common = new com.mirantis.mk.Common()
@@ -475,11 +528,11 @@
* @param fun Salt process step function
* @param arg process step arguments (optional, default [])
* @param batch salt batch parameter integer or string with percents (optional, default null - disable batch)
- * @param output print output (optional, default false)
+ * @param output print output (optional, default true)
* @param timeout Additional argument salt api timeout
* @return output of salt command
*/
-def runSaltProcessStep(saltId, tgt, fun, arg = [], batch = null, output = false, timeout = -1, kwargs = null) {
+def runSaltProcessStep(saltId, tgt, fun, arg = [], batch = null, output = true, timeout = -1, kwargs = null) {
def common = new com.mirantis.mk.Common()
def salt = new com.mirantis.mk.Salt()
def out
@@ -505,8 +558,9 @@
* @param failOnError Do you want to throw exception if salt-call fails (optional, default true)
* @param printResults Do you want to print salt results (optional, default true)
* @param printOnlyChanges If true (default), print only changed resources
+ * @param disableAskOnError Flag for disabling ASK_ON_ERROR feature (optional, default false)
*/
-def checkResult(result, failOnError = true, printResults = true, printOnlyChanges = true) {
+def checkResult(result, failOnError = true, printResults = true, printOnlyChanges = true, disableAskOnError = false) {
def common = new com.mirantis.mk.Common()
if(result != null){
if(result['return']){
@@ -565,7 +619,7 @@
common.debugMsg("checkResult: checking resource: ${resource}")
if(resource instanceof String || (resource["result"] != null && !resource["result"]) || (resource["result"] instanceof String && resource["result"] == "false")){
def prettyResource = common.prettify(resource)
- if(env["ASK_ON_ERROR"] && env["ASK_ON_ERROR"] == "true"){
+ if(!disableAskOnError && env["ASK_ON_ERROR"] && env["ASK_ON_ERROR"] == "true"){
timeout(time:1, unit:'HOURS') {
input message: "False result on ${nodeKey} found, resource ${prettyResource}. \nDo you want to continue?"
}
diff --git a/src/com/mirantis/mk/Test.groovy b/src/com/mirantis/mk/Test.groovy
index 87f6a56..5a192d3 100644
--- a/src/com/mirantis/mk/Test.groovy
+++ b/src/com/mirantis/mk/Test.groovy
@@ -143,8 +143,7 @@
def copyTempestResults(master, target) {
def salt = new com.mirantis.mk.Salt()
if (! target.contains('cfg')) {
- salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["mkdir /root/rally_reports/ && " +
- "rsync -av /root/rally_reports/ cfg01:/root/rally_reports/"])
+ salt.cmdRun(master, target, "mkdir /root/rally_reports/ && rsync -av /root/rally_reports/ cfg01:/root/rally_reports/")
}
}
@@ -155,7 +154,7 @@
*/
def catTestsOutput(master, image) {
def salt = new com.mirantis.mk.Salt()
- salt.runSaltProcessStep(master, 'cfg01*', 'cmd.run', ["cat /home/ubuntu/${image}.output"])
+ salt.cmdRun(master, 'cfg01*', "cat /home/ubuntu/${image}.output")
}
@@ -165,7 +164,7 @@
*/
def install_docker(master, target) {
def salt = new com.mirantis.mk.Salt()
- salt.runSaltProcessStep(master, "${target}", 'pkg.install', ["docker.io"])
+ salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
}
@@ -197,9 +196,9 @@
"-e TEST_GROUP=${testGroup} " +
"${image}"
if (master == null) {
- sh("${command}")
+ sh(command)
} else {
- salt.cmdRun(master, "${target}", "${command}")
+ salt.cmdRun(master, target, command)
}
}
@@ -216,7 +215,7 @@
def artifacts_dir = '_artifacts/'
def output_file = 'rally_reports.tar'
- salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["tar -cf /root/${output_file} -C ${reports_dir} ."])
+ salt.cmdRun(master, target, "tar -cf /root/${output_file} -C ${reports_dir} .")
sh "mkdir -p ${artifacts_dir}"
encoded = salt.cmdRun(master, target, "cat /root/${output_file}", true, null, false)['return'][0].values()[0].replaceAll('Salt command execution success','')