Add galera.upgrade states
This patch adds granular upgrade states for mysql service.
Change-Id: I69b4e04e9a58518055fd006112d43069733d0843
Related-Prod: PROD-29630
diff --git a/galera/upgrade/pkgs_latest.sls b/galera/upgrade/pkgs_latest.sls
new file mode 100644
index 0000000..c112756
--- /dev/null
+++ b/galera/upgrade/pkgs_latest.sls
@@ -0,0 +1,46 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+{%- if master.get('enabled', False) %}
+{%- set galera = master %}
+{%- else %}
+{%- set galera = slave %}
+{%- endif %}
+
+galera_task_pkgs_latest:
+ test.show_notification:
+ - name: "dump_message_pkgs_latest"
+ - text: "Running galera.upgrade.pkgs_latest"
+
+policy-rc.d_present:
+ file.managed:
+ - name: /usr/sbin/policy-rc.d
+ - mode: 755
+ - contents: |
+ #!/bin/sh
+ exit 101
+
+{%- if galera.get('enabled', False) %}
+ {%- if galera.version is defined %}
+galera_packages:
+ pkg.installed:
+ - names: {{ galera.pkgs }}
+ - version: {{ galera.version }}
+ - require:
+ - file: policy-rc.d_present
+ - require_in:
+ - file: policy-rc.d_absent
+ {%- else %}
+galera_packages:
+ pkg.latest:
+ - names: {{ galera.pkgs }}
+ - require:
+ - file: policy-rc.d_present
+ - require_in:
+ - file: policy-rc.d_absent
+ {%- endif %}
+
+{%- endif %}
+
+policy-rc.d_absent:
+ file.absent:
+ - name: /usr/sbin/policy-rc.d
diff --git a/galera/upgrade/pre/init.sls b/galera/upgrade/pre/init.sls
new file mode 100644
index 0000000..1d92250
--- /dev/null
+++ b/galera/upgrade/pre/init.sls
@@ -0,0 +1,12 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+{%- if master.get('enabled', False) %}
+{%- set galera = master %}
+{%- else %}
+{%- set galera = slave %}
+{%- endif %}
+
+galera_pre:
+ test.show_notification:
+ - name: "dump_message_pre-upgrade_galera"
+ - text: "Running galera.upgrade.pre"
diff --git a/galera/upgrade/render_config.sls b/galera/upgrade/render_config.sls
new file mode 100644
index 0000000..8df6e86
--- /dev/null
+++ b/galera/upgrade/render_config.sls
@@ -0,0 +1,21 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+{%- if master.get('enabled', False) %}
+{%- set galera = master %}
+{%- else %}
+{%- set galera = slave %}
+{%- endif %}
+
+galera_render_config:
+ test.show_notification:
+ - name: "dump_message_render_config_galera"
+ - text: "Running galera.upgrade.render_config"
+
+galera_config:
+ file.managed:
+ - name: {{ galera.config }}
+ - source: salt://galera/files/my.cnf
+ - template: jinja
+ - group: mysql
+ - makedirs: True
+ - mode: 640
diff --git a/galera/upgrade/service_running.sls b/galera/upgrade/service_running.sls
new file mode 100644
index 0000000..e41a826
--- /dev/null
+++ b/galera/upgrade/service_running.sls
@@ -0,0 +1,24 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+{%- if master.get('enabled', False) %}
+{%- set galera = master %}
+{%- else %}
+{%- set galera = slave %}
+{%- endif %}
+
+galera_task_service_running:
+ test.show_notification:
+ - name: "dump_message_service_running_mysql"
+ - text: "Running galera.upgrade.service_running"
+
+{%- if galera.get('enabled', False) %}
+
+mysql_service_running:
+ service.running:
+ - enable: true
+ - name: {{ galera.service }}
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+
+{%- endif %}
diff --git a/galera/upgrade/service_stopped.sls b/galera/upgrade/service_stopped.sls
new file mode 100644
index 0000000..cf65895
--- /dev/null
+++ b/galera/upgrade/service_stopped.sls
@@ -0,0 +1,24 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+{%- if master.get('enabled', False) %}
+{%- set galera = master %}
+{%- else %}
+{%- set galera = slave %}
+{%- endif %}
+
+mysql_task_service_stopped:
+ test.show_notification:
+ - name: "dump_message_service_stopped_mysql"
+ - text: "Running galera.upgrade.service_stopped"
+
+{%- if galera.get('enabled', False) %}
+
+mysql_service_stopped:
+ service.dead:
+ - enable: false
+ - name: {{ galera.service }}
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+
+{%- endif %}
diff --git a/galera/upgrade/upgrade/init.sls b/galera/upgrade/upgrade/init.sls
new file mode 100644
index 0000000..34a06af
--- /dev/null
+++ b/galera/upgrade/upgrade/init.sls
@@ -0,0 +1,12 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+galera_upgrade:
+ test.show_notification:
+ - name: "dump_message_upgrade_galera"
+ - text: "Running galera.upgrade.upgrade"
+
+include:
+ - galera.upgrade.service_stopped
+ - galera.upgrade.pkgs_latest
+ - galera.upgrade.render_config
+ - galera.upgrade.service_running
diff --git a/galera/upgrade/upgrade/post.sls b/galera/upgrade/upgrade/post.sls
new file mode 100644
index 0000000..1624d69
--- /dev/null
+++ b/galera/upgrade/upgrade/post.sls
@@ -0,0 +1,6 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+galera_upgrade_post:
+ test.show_notification:
+ - name: "dump_message_upgrade_galera_post"
+ - text: "Running galera.upgrade.upgrade.post"
diff --git a/galera/upgrade/upgrade/pre.sls b/galera/upgrade/upgrade/pre.sls
new file mode 100644
index 0000000..451a9dc
--- /dev/null
+++ b/galera/upgrade/upgrade/pre.sls
@@ -0,0 +1,6 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+galera_upgrade_pre:
+ test.show_notification:
+ - name: "dump_message_upgrade_galera_pre"
+ - text: "Running galera.upgrade.upgrade.pre"
diff --git a/galera/upgrade/verify/_service.sls b/galera/upgrade/verify/_service.sls
new file mode 100644
index 0000000..730f8e4
--- /dev/null
+++ b/galera/upgrade/verify/_service.sls
@@ -0,0 +1,11 @@
+{%- from "galera/map.jinja" import master,slave with context %}
+
+{%- if master.get('enabled', False) %}
+{%- set galera = master %}
+{%- else %}
+{%- set galera = slave %}
+{%- endif %}
+
+galera_task_uprade_verify_service:
+ test.show_notification:
+ - text: "Running galera.upgrade.verify._service"
diff --git a/galera/upgrade/verify/init.sls b/galera/upgrade/verify/init.sls
new file mode 100644
index 0000000..e9cb8ce
--- /dev/null
+++ b/galera/upgrade/verify/init.sls
@@ -0,0 +1,7 @@
+galera_upgrade_verify:
+ test.show_notification:
+ - name: "dump_message_upgrade_galera_verify"
+ - text: "Running galera.upgrade.verify"
+
+include:
+ - galera.upgrade.verify._service