Add more upgrade tasks according to phases

Update README
Introduce:
 * glance.upgrade.upgrade.pre
 * glance.upgrade.upgrade.post
 * glance.upgrade.verify

Change-Id: I718ae7b2861e4e0f1858894d882d01356e98422c
diff --git a/README.rst b/README.rst
index e9c2d30..b6c2df8 100644
--- a/README.rst
+++ b/README.rst
@@ -444,6 +444,65 @@
 
     glance image-update "Windows 7 x86_64" --property hw_vif_model=rtl8139
 
+Upgrades
+========
+
+Each openstack formula provide set of phases (logical bloks) that will help to
+build flexible upgrade orchestration logic for particular components. The list
+of phases and theirs descriptions are listed in table below:
+
++-------------------------------+------------------------------------------------------+
+| State                         | Description                                          |
++===============================+======================================================+
+| <app>.upgrade.service_running | Ensure that all services for particular application  |
+|                               | are enabled for autostart and running                |
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.service_stopped | Ensure that all services for particular application  |
+|                               | disabled for autostart and dead                      |
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.pkgs_latest     | Ensure that packages used by particular application  |
+|                               | are installed to latest available version.           |
+|                               | This will not upgrade data plane packages like qemu  |
+|                               | and openvswitch as usually minimal required version  |
+|                               | in openstack services is really old. The data plane  |
+|                               | packages should be upgraded separately by `apt-get   |
+|                               | upgrade` or `apt-get dist-upgrade`                   |
+|                               | Applying this state will not autostart service.      |
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.render_config   | Ensure configuration is rendered actual version.     +
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.pre             | We assume this state is applied on all nodes in the  |
+|                               | cloud before running upgrade.                        |
+|                               | Only non destructive actions will be applied during  |
+|                               | this phase. Perform service built in service check   |
+|                               | like (keystone-manage doctor and nova-status upgrade)|
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.upgrade.pre     | Mostly applicable for data plane nodes. During this  |
+|                               | phase resources will be gracefully removed from      |
+|                               | current node if it is allowed. Services for upgraded |
+|                               | application will be set to admin disabled state to   |
+|                               | make sure node will not participate in resources     |
+|                               | scheduling. For example on gtw nodes this will set   |
+|                               | all agents to admin disable state and will move all  |
+|                               | routers to other agents.                             |
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.upgrade         | This state will basically upgrade application on     |
+|                               | particular target. Stop services, render             |
+|                               | configuration, install new packages, run offline     |
+|                               | dbsync (for ctl), start services. Data plane should  |
+|                               | not be affected, only OpenStack python services.     |
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.upgrade.post    | Add services back to scheduling.                     |
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.post            | This phase should be launched only when upgrade of   |
+|                               | the cloud is completed. Cleanup temporary files,     |
+|                               | perform other post upgrade tasks.                    |
++-------------------------------+------------------------------------------------------+
+| <app>.upgrade.verify          | Here we will do basic health checks (API CRUD        |
+|                               | operations, verify do not have dead network          |
+|                               | agents/compute services)                             |
++-------------------------------+------------------------------------------------------+
+
 
 Read more
 ==========
diff --git a/glance/upgrade/post/init.sls b/glance/upgrade/post/init.sls
index a11375e..e0298ee 100644
--- a/glance/upgrade/post/init.sls
+++ b/glance/upgrade/post/init.sls
@@ -1,5 +1,7 @@
-{%- from "glance/map.jinja" import server with context %}
-
 glance_post:
   test.show_notification:
     - text: "Running glance.upgrade.post"
+
+keystone_os_client_config_absent:
+  file.absent:
+    - name: /etc/openstack/clouds.yml
diff --git a/glance/upgrade/pre/init.sls b/glance/upgrade/pre/init.sls
index d362737..3587e37 100644
--- a/glance/upgrade/pre/init.sls
+++ b/glance/upgrade/pre/init.sls
@@ -1,8 +1,14 @@
-{%- from "glance/map.jinja" import server with context %}
-
-include:
- - glance.upgrade.verify.api
-
 glance_pre:
   test.show_notification:
     - text: "Running glance.upgrade.pre"
+
+{%- set os_content = salt['mine.get']('I@keystone:client:os_client_config:enabled:true', 'keystone_os_client_config', 'compound').values()[0] %}
+keystone_os_client_config:
+  file.managed:
+    - name: /etc/openstack/clouds.yml
+    - contents: |
+        {{ os_content |yaml(False)|indent(8) }}
+    - user: 'root'
+    - group: 'root'
+    - makedirs: True
+    - unless: test -f /etc/openstack/clouds.yml
\ No newline at end of file
diff --git a/glance/upgrade/upgrade/init.sls b/glance/upgrade/upgrade/init.sls
index 2242144..ec02f85 100644
--- a/glance/upgrade/upgrade/init.sls
+++ b/glance/upgrade/upgrade/init.sls
@@ -1,8 +1,10 @@
 {%- from "glance/map.jinja" import server with context %}
 
 include:
+ - glance.upgrade.upgrade.pre
  - glance.upgrade.service_stopped
  - glance.upgrade.pkgs_latest
  - glance.upgrade.render_config
  - glance.db.offline_sync
  - glance.upgrade.service_running
+ - glance.upgrade.upgrade.post
diff --git a/glance/upgrade/upgrade/post.sls b/glance/upgrade/upgrade/post.sls
new file mode 100644
index 0000000..b4c90e7
--- /dev/null
+++ b/glance/upgrade/upgrade/post.sls
@@ -0,0 +1,3 @@
+glance_upgrade_uprade_post:
+  test.show_notification:
+    - text: "Running glance.upgrade.upgrade.post"
diff --git a/glance/upgrade/upgrade/pre.sls b/glance/upgrade/upgrade/pre.sls
new file mode 100644
index 0000000..163a3f7
--- /dev/null
+++ b/glance/upgrade/upgrade/pre.sls
@@ -0,0 +1,3 @@
+glance_upgrade_upgrade_pre:
+  test.show_notification:
+    - text: "Running glance.upgrade.upgrade.pre"
diff --git a/glance/upgrade/verify/api.sls b/glance/upgrade/verify/_api.sls
similarity index 100%
rename from glance/upgrade/verify/api.sls
rename to glance/upgrade/verify/_api.sls
diff --git a/glance/upgrade/verify/init.sls b/glance/upgrade/verify/init.sls
new file mode 100644
index 0000000..5184ff2
--- /dev/null
+++ b/glance/upgrade/verify/init.sls
@@ -0,0 +1,2 @@
+include:
+ - glance.upgrade.verify._api