]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
ceph-volume: make the batch action idempotent
authorAndrew Schoen <aschoen@redhat.com>
Mon, 1 Oct 2018 17:51:47 +0000 (12:51 -0500)
committerSébastien Han <seb@redhat.com>
Tue, 9 Oct 2018 14:09:50 +0000 (10:09 -0400)
The command is run with --report first to see if any OSDs will be
created or not. If they will be, then the command is run. If not, then
changed is set to False and the module exits.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
library/ceph_volume.py

index f59b70d11a3a751436cc311ffa5fbb68074b40bb..f05bab57c5da2b5d4139a8d7b564e287c711cc01 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 import datetime
 import json
+import copy
 
 
 ANSIBLE_METADATA = {
@@ -257,11 +258,10 @@ def batch(module):
     if objectstore == "bluestore" and block_db_size != "-1":
         cmd.extend(["--block-db-size", block_db_size])
 
-    if report:
-        cmd.extend([
-            "--report",
-            "--format=json",
-        ])
+    report_flags = [
+        "--report",
+        "--format=json",
+    ]
 
     cmd.extend(batch_devices)
 
@@ -281,11 +281,23 @@ def batch(module):
 
     startd = datetime.datetime.now()
 
-    rc, out, err = module.run_command(cmd, encoding=None)
+    report_cmd = copy.copy(cmd)
+    report_cmd.extend(report_flags)
+
+    rc, out, err = module.run_command(report_cmd, encoding=None)
+    report_result = json.loads(out)
+    if not report:
+        rc, out, err = module.run_command(cmd, encoding=None)
+    else:
+        cmd = report_cmd
 
     endd = datetime.datetime.now()
     delta = endd - startd
 
+    changed = True
+    if not report:
+        changed = report_result['changed']
+
     result = dict(
         cmd=cmd,
         stdout=out.rstrip(b"\r\n"),
@@ -294,7 +306,7 @@ def batch(module):
         start=str(startd),
         end=str(endd),
         delta=str(delta),
-        changed=True,
+        changed=changed,
     )
 
     if rc != 0: