From 87b7b13ea9c74c75e02bfa974f4cdca9340320e2 Mon Sep 17 00:00:00 2001
From: Jude Cross <jucross@blizzard.com>
Date: Wed, 25 Jul 2018 14:09:20 -0700
Subject: [PATCH] Update client to account for 409 error in cluster actions

This patch allows the senlin client to properly parse a 409
error when a scaling action fails due to a conflict or cooldown

Depends-On: https://review.openstack.org/585573
Change-Id: I2fff7c2cc1bb17c0e32ef5b67294b811aff22192
---
 .gitignore                 | 2 ++
 senlinclient/v1/cluster.py | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/.gitignore b/.gitignore
index b2ea2049..aab8db3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,8 @@ cover/
 htmlcov/
 .tox/
 .coverage
+.coverage.*
+.idea
 .cache
 .stestr/
 coverage.xml
diff --git a/senlinclient/v1/cluster.py b/senlinclient/v1/cluster.py
index cbfa15af..0ba2fd2a 100644
--- a/senlinclient/v1/cluster.py
+++ b/senlinclient/v1/cluster.py
@@ -535,6 +535,10 @@ class ScaleInCluster(command.Command):
 
         resp = senlin_client.cluster_scale_in(parsed_args.cluster,
                                               parsed_args.count)
+        status_code = resp.get('code', None)
+        if status_code in [409]:
+            raise exc.CommandError(_(
+                'Unable to scale in cluster: %s') % resp['error']['message'])
         if 'action' in resp:
             print('Request accepted by action: %s' % resp['action'])
         else:
@@ -566,6 +570,10 @@ class ScaleOutCluster(command.Command):
 
         resp = senlin_client.cluster_scale_out(parsed_args.cluster,
                                                parsed_args.count)
+        status_code = resp.get('code', None)
+        if status_code in [409]:
+            raise exc.CommandError(_(
+                'Unable to scale out cluster: %s') % resp['error']['message'])
         if 'action' in resp:
             print('Request accepted by action: %s' % resp['action'])
         else: