osd: refact osd pool creation

Currently, the command executed is wrong, eg:

```
  cmd:
  - podman
  - exec
  - ceph-mon-controller-0
  - ceph
  - --cluster
  - ceph
  - osd
  - pool
  - create
  - volumes
  - '32'
  - '32'
  - replicated_rule
  - '1'
  delta: '0:00:01.625525'
  end: '2020-02-27 16:41:05.232705'
  item:
```

From documentation, the osd pool creation command is :

```
ceph osd pool create {pool-name} {pg-num} [{pgp-num}] [replicated] \
     [crush-rule-name] [expected-num-objects]
ceph osd pool create {pool-name} {pg-num}  {pgp-num}   erasure \
     [erasure-code-profile] [crush-rule-name] [expected_num_objects]
```

it means we pass '1' (from item.type) as value for
`expected_num_objects` by default which is very likely not what we want.

Also, this commit modifies the default value when no `rule_name` is set
to use the existing variable `osd_pool_default_crush_rule`

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1808495

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit bf1f125d71)
pull/5133/head
Guillaume Abrioux 2020-02-28 11:41:00 +01:00
parent 2c440d4427
commit ae06d684b8
3 changed files with 21 additions and 12 deletions

View File

@ -85,12 +85,15 @@
osd pool create {{ item.0.name }}
{{ item.0.pg_num | default(osd_pool_default_pg_num) }}
{{ item.0.pgp_num | default(item.0.pg_num) | default(osd_pool_default_pg_num) }}
{{ 'replicated_rule' if not item.0.rule_name | default('replicated_rule') else item.0.rule_name | default('replicated_rule') }}
{{ 1 if item.0.type|default(1) == 'replicated' else 3 if item.0.type|default(1) == 'erasure' else item.0.type|default(1) }}
{%- if (item.0.type | default("1") == '3' or item.0.type | default("1") == 'erasure') and item.0.erasure_profile %}
{%- if item.0.type | default(1) | int == 1 or item.0.type | default('replicated') == 'replicated' %}
replicated
{{ item.0.rule_name | default(osd_pool_default_crush_rule) }}
{%- else %}
erasure
{{ item.0.erasure_profile }}
{{ item.0.rule_name | default('erasure-code') }}
{%- endif %}
{{ item.0.expected_num_objects | default('') }}
{{ item.0.expected_num_objects | default(0) }}
with_together:
- "{{ pools }}"
- "{{ created_pools.results }}"

View File

@ -27,12 +27,15 @@
osd pool create {{ item.name }}
{{ item.pg_num | default(osd_pool_default_pg_num) }}
{{ item.pgp_num | default(item.pg_num) | default(osd_pool_default_pg_num) }}
{{ 'replicated_rule' if not item.rule_name | default('replicated_rule') else item.rule_name | default('replicated_rule') }}
{{ 1 if item.type|default(1) == 'replicated' else 3 if item.type|default(1) == 'erasure' else item.type|default(1) }}
{%- if (item.type | default("1") == '3' or item.type | default("1") == 'erasure') and item.erasure_profile | length > 0 %}
{%- if item.type | default(1) | int == 1 or item.type | default('replicated') == 'replicated' %}
replicated
{{ item.rule_name | default(osd_pool_default_crush_rule) }}
{%- else %}
erasure
{{ item.erasure_profile }}
{{ item.rule_name | default('erasure-code') }}
{%- endif %}
{{ item.expected_num_objects | default('') }}
{{ item.expected_num_objects | default(0) }}
changed_when: false
with_items:
- "{{ cephfs_pools }}"

View File

@ -17,12 +17,15 @@
osd pool create {{ item.0.name }}
{{ item.0.pg_num | default(osd_pool_default_pg_num) }}
{{ item.0.pgp_num | default(item.0.pg_num) | default(osd_pool_default_pg_num) }}
{{ 'replicated_rule' if not item.0.rule_name | default('replicated_rule') else item.0.rule_name | default('replicated_rule') }}
{{ 1 if item.0.type|default(1) == 'replicated' else 3 if item.0.type|default(1) == 'erasure' else item.0.type|default(1) }}
{%- if (item.0.type | default("1") == '3' or item.0.type | default("1") == 'erasure') and item.0.erasure_profile %}
{%- if item.0.type | default(1) | int == 1 or item.0.type | default('replicated') == 'replicated' %}
replicated
{{ item.0.rule_name | default(osd_pool_default_crush_rule) }}
{%- else %}
erasure
{{ item.0.erasure_profile }}
{{ item.0.rule_name | default('erasure-code') }}
{%- endif %}
{{ item.0.expected_num_objects | default('') }}
{{ item.0.expected_num_objects | default(0) }}
with_together:
- "{{ openstack_pools | unique }}"
- "{{ created_pools.results }}"