Allow getHeatStackServers method to find nested servers
Currently getHeatStackServers method is broken.
This patch fixes it by fixing typo in getHeatStackResourceInfo call
Also this patch adds method for finding servers in all nested stacks,
depth is set to 1000 to make sure we can get very big nested stacks.
Change-Id: Idd948050d3f9fd93ef4ed218aa1d70ef8a7c189e
Related-Prod: PROD-17558
diff --git a/src/com/mirantis/mk/Openstack.groovy b/src/com/mirantis/mk/Openstack.groovy
index 029d2a6..ddd9bca 100644
--- a/src/com/mirantis/mk/Openstack.groovy
+++ b/src/com/mirantis/mk/Openstack.groovy
@@ -298,10 +298,12 @@
* @param env Connection parameters for OpenStack API endpoint
* @param name Name of the managed Heat stack instance
* @param path Optional path to the custom virtualenv
+ * @param depth Optional depth of stack for listing resources,
+ * 0 - do not list nested resources
*/
-def getHeatStackResources(env, name, path = null) {
+def getHeatStackResources(env, name, path = null, depth = 0) {
def python = new com.mirantis.mk.Python()
- cmd = "heat resource-list ${name}"
+ cmd = "heat resource-list --nested-depth ${depth} ${name}"
outputTable = runOpenstackCommand(cmd, env, path)
output = python.parseTextTable(outputTable, 'list', 'prettytable', path)
return output
@@ -350,20 +352,20 @@
}
/**
- * Return list of servers from OpenStack Heat stack
+ * Return hashmap of hashes server_id:server_name of servers from OpenStack Heat stack
*
* @param env Connection parameters for OpenStack API endpoint
* @param name Name of the managed Heat stack instance
* @param path Optional path to the custom virtualenv
*/
def getHeatStackServers(env, name, path = null) {
- resources = heatGetStackResources(env, name, path)
- servers = []
+ // set depth to 1000 to ensure all nested resources are shown
+ resources = getHeatStackResources(env, name, path, 1000)
+ servers = [:]
for (resource in resources) {
if (resource.resource_type == 'OS::Nova::Server') {
- resourceName = resource.resource_name
- server = heatGetStackResourceInfo(env, name, resourceName, path)
- servers.add(server.attributes.name)
+ server = openstack.getHeatStackResourceInfo(env, resource.stack_name, resource.resource_name, path)
+ servers[server.attributes.id] = server.attributes.name
}
}
echo("[Stack ${name}] Servers: ${servers}")