]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
Do not pass NoneType as argument to ceph_crush_rule
authorDmitriy Rabotyagov <dmitriy.rabotyagov@cleura.com>
Wed, 25 Oct 2023 11:47:19 +0000 (13:47 +0200)
committerTeoman ONAY <tonay@redhat.com>
Wed, 6 Dec 2023 18:13:39 +0000 (19:13 +0100)
With ansible-core 2.15 it is not possible to pass argument of unexpected
type, as otherwise module will fail with:
`'None' is not a string and conversion is not allowed`

With that we want to only get all existing crush rules, so we can simply
supply an empty string as a name argument, which would satisfy
requirements and have same behaviour for previous ansible versions.

Alternative approach would be to stop making `name` as a required
argument to the module and use empty string as default value
when info state is used.

Signed-off-by: Dmitriy Rabotyagov <noonedeadpunk@gmail.com>
library/ceph_crush_rule.py
roles/ceph-facts/tasks/get_def_crush_rule_name.yml
tests/library/test_ceph_crush_rule.py

index 88ec8434cbcff032aafad1f9711797aa7380395d..e696a9fb72377e11c7c7f70eb3872a4417f6fa4b 100644 (file)
@@ -46,7 +46,8 @@ description:
 options:
     name:
         description:
-            - name of the Ceph Crush rule.
+            - name of the Ceph Crush rule. If state is 'info' - empty string
+              can be provided as a value to get all crush rules
         required: true
     cluster:
         description:
index 4b1a04eb01a378a37516208b207382805372453d..cdfcfbf3622114b4065e503ad52ca19711ff56ad 100644 (file)
@@ -1,7 +1,7 @@
 ---
 - name: get current default crush rule details
   ceph_crush_rule:
-    name: null
+    name: ""
     cluster: "{{ cluster }}"
     state: info
   environment:
index e3bd9b173f21b0d05eaaaf92e7f31784f2ce04c7..c8e51be2c48cd0a2047dd5ca793ef2556045f836 100644 (file)
@@ -396,6 +396,31 @@ class TestCephCrushRuleModule(object):
         assert result['stderr'] == stderr
         assert result['stdout'] == stdout
 
+    @patch('ansible.module_utils.basic.AnsibleModule.exit_json')
+    @patch('ansible.module_utils.basic.AnsibleModule.run_command')
+    def test_get_all_rules(self, m_run_command, m_exit_json):
+        ca_test_common.set_module_args({
+            'name': str(),
+            'state': 'info'
+        })
+        m_exit_json.side_effect = ca_test_common.exit_json
+        rc = 0
+        stderr = ''
+        stdout = '{{"rule_name":"{}","steps":[{{"item_name":"{}"}},{{"type":"{}"}}]}}'.format(fake_name, fake_bucket_root, fake_bucket_type)
+        m_run_command.return_value = rc, stdout, stderr
+
+        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
+            ceph_crush_rule.main()
+
+        result = result.value.args[0]
+        assert not result['changed']
+        assert result['cmd'] == ['ceph', '-n', fake_user, '-k', fake_keyring,
+                                 '--cluster', fake_cluster, 'osd', 'crush', 'rule',
+                                 'dump', '', '--format=json']
+        assert result['rc'] == rc
+        assert result['stderr'] == stderr
+        assert result['stdout'] == stdout
+
     @patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': fake_container_binary})
     @patch.dict(os.environ, {'CEPH_CONTAINER_IMAGE': fake_container_image})
     @patch('ansible.module_utils.basic.AnsibleModule.exit_json')