]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
library: Fix new-style modules check mode
authorBenoît Knecht <bknecht@protonmail.ch>
Tue, 1 Sep 2020 11:06:57 +0000 (13:06 +0200)
committerDimitri Savineau <savineau.dimitri@gmail.com>
Tue, 29 Sep 2020 00:41:51 +0000 (20:41 -0400)
Running the `ceph_crush.py`, `ceph_key.py` or `ceph_volume.py` modules in check
mode resulted in the following error:

```
New-style module did not handle its own exit
```

This was due to the fact that they simply returned a `dict` in that case,
instead of calling `module.exit_json()`.

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
(cherry picked from commit 85dd4058145436e86a12ad9f015f5228189437d5)

library/ceph_crush.py
library/ceph_key.py
library/ceph_pool.py
library/ceph_volume.py

index f9e90d685644565ae1fbdb3c4a06facd2f2b7bea..e9b500c982ff8170927dfb3ba653926b1bba2ef3 100644 (file)
@@ -169,14 +169,14 @@ def run_module():
         changed=False,
         stdout='',
         stderr='',
-        rc='',
+        rc=0,
         start='',
         end='',
         delta='',
     )
 
     if module.check_mode:
-        return result
+        module.exit_json(**result)
 
     startd = datetime.datetime.now()
 
index e54b0df7f7d7ba474417ba1fa283eac2a3904863..5b57c2634dd1be71930c017e9e0ce48737b51948 100644 (file)
@@ -528,14 +528,15 @@ def run_module():
         changed=changed,
         stdout='',
         stderr='',
-        rc='',
+        rc=0,
         start='',
         end='',
         delta='',
     )
 
     if module.check_mode:
-        return result
+        module.exit_json(**result)
+
     startd = datetime.datetime.now()
 
     # will return either the image name or None
index 8da6b2a98a07c0e1f0e73a3e8d5837239180bdad..70a0bd20a849d90efa2cc21e8b3acc7e9b8e5876 100644 (file)
@@ -526,11 +526,11 @@ def run_module():
     }
 
     if module.check_mode:
-        return dict(
+        module.exit_json(
             changed=False,
             stdout='',
             stderr='',
-            rc='',
+            rc=0,
             start='',
             end='',
             delta='',
@@ -614,4 +614,3 @@ def main():
 
 if __name__ == '__main__':
     main()
-
index 55faac0032baa09b7c0f75cd48e5fbbb3fcfa25c..2e8e50d49d9c7b9086715dc41cb0a8cb5ceb90a8 100644 (file)
@@ -574,14 +574,14 @@ def run_module():
         changed=False,
         stdout='',
         stderr='',
-        rc='',
+        rc=0,
         start='',
         end='',
         delta='',
     )
 
     if module.check_mode:
-        return result
+        module.exit_json(**result)
 
     # start execution
     startd = datetime.datetime.now()