From 1cc921cef4b0a7dd81e34dab9d710a8e19b20a1f Mon Sep 17 00:00:00 2001
From: "Mark T. Voelker" <mvoelker@vmware.com>
Date: Fri, 21 Apr 2017 14:08:55 -0400
Subject: [PATCH] Rescan disk bus before using volume

In the LAMP stack workload, we found that one issue for interoperability
between clouds was that in some combinations of
hypervisor/adapter/storage is is necessary to rescan the scsi bus of a
guest VM in order to detect a newly attached Cinder volume.[1] We
neglected to do that in the K8s workload, so this patch ammends the
Ansible play that formats the volume to scan the SCSI bus first.

Note that the LAMP workload was targetted toward one guest OS platform
(Ubuntu), and worked by installing the scsitools package and running the
rescan-scsi-bus script that it provides.  The K8s workload is different
in that it's currently targetted toward multiple guests including Ubuntu
and CoreOS [2]...the latter of which doesn't have a package manager.
Rather than build conditionals into the code to handle this, I've taken
a slightly simpler and more platform-agnostic approach in this patch by
simply looking in /sys/class/scsi_host to see what adapters are present
and then scanning each of them with an echo command.  This approach has
a few advantages: 1.) it works on guest OS's in which the name of the
package containing the rescan-scsi-tools script is different than on
Ubuntu, 2.) it works on guest OS's that don't have a package manager at
all, and 3.) since it doesn't require installing any additional
software, it is slightly faster and requires trivially less disk
footprint.

[1] https://review.openstack.org/#/c/383923/
[2] CentOS support is coming too:
https://review.openstack.org/#/c/457199/

Change-Id: Ie7204a23bc7a7d1da9a8cc60e684fc987159a41a
---
 workloads/ansible/shade/k8s/roles/worker/tasks/main.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/workloads/ansible/shade/k8s/roles/worker/tasks/main.yml b/workloads/ansible/shade/k8s/roles/worker/tasks/main.yml
index 0faecbb..5c28ee0 100755
--- a/workloads/ansible/shade/k8s/roles/worker/tasks/main.yml
+++ b/workloads/ansible/shade/k8s/roles/worker/tasks/main.yml
@@ -18,6 +18,9 @@
 - stat: path=/tmp/diskflag
   register: diskflag
 
+- shell: for adapter in $(echo `find /sys/class/scsi_host -name "host*"`); do echo "- - -" > ${adapter}/scan; done
+  when: diskflag.stat.exists == false
+
 - shell: parted -s "{{ app_env.block_device_name }}" mklabel msdos
   when: diskflag.stat.exists == false