Repository: ansible/ansible
Pull request: ovirt search name with space
##### SUMMARY
<!--- Describe the change below, including rationale and design decisions -->
ovirt modules now will search names with spaces
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
Fixes #59140
##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
- Bugfix Pull Request

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below -->
ovirt
##### ADDITIONAL INFORMATION
<!--- Include additional information to help people understand the change here -->
<!--- A step-by-step reproduction of the problem is helpful if there is no related issue -->

<!--- Paste verbatim command output below, e.g. before and after your change -->
```paste below

```


Problem statement:
oVirt: when having network with spaces in name, the search fails to find it.
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Explain the problem briefly below -->
When having network with spaces in name, the search fails to find it.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
ovirt_network

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
2.8.1
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below

```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->


##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
ovirt_network:
    name: Storage - VLAN
    vm_network: False
    vlan_tag: 33
    data_center: Default
    description: Storage with VLAN Tagging
    comment: Storage with VLAN Tagging
    clusters:
      - name: Default
        required: False
        migration: True
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->


##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
ovirtsdk4.Error: Fault reason is "Operation Failed". Fault detail is "[Cannot add Network. The name of the logical network 'Storage - VLAN 33' is already used by an existing logical network in the same data-center.
```

The problem is that in oVirt API searching object with spaces in name, it won't find it. We need to quote the search string.

Hints from issue discussion:
Files identified in the description:
* [`lib/ansible/modules/cloud/ovirt/ovirt_network.py`](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/ovirt/ovirt_network.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @mnecas @mwperina
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I have encountered this error and I would like to help in anyway I can to fix it.

Commit message: init ovirt_search_name_with_space

Patch to review:
diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py
index 4b2b48526c5823..da65bcbda8dbec 100644
--- a/lib/ansible/module_utils/ovirt.py
+++ b/lib/ansible/module_utils/ovirt.py
@@ -254,7 +254,7 @@ def search_by_attributes(service, list_params=None, **kwargs):
     # Check if 'list' method support search(look for search parameter):
     if 'search' in inspect.getargspec(service.list)[0]:
         res = service.list(
-            search=' and '.join('{0}={1}'.format(k, v) for k, v in kwargs.items()),
+            search=' and '.join('{0}="{1}"'.format(k, v) for k, v in kwargs.items()),
             **list_params
         )
     else:


Code review comments:
diff_hunk: @@ -254,7 +254,7 @@ def search_by_attributes(service, list_params=None, **kwargs):
     # Check if 'list' method support search(look for search parameter):
     if 'search' in inspect.getargspec(service.list)[0]:
         res = service.list(
-            search=' and '.join('{0}={1}'.format(k, v) for k, v in kwargs.items()),
+            search=' and '.join('{0}="{1}"'.format(k, v) for k, v in kwargs.items()),
path: lib/ansible/module_utils/ovirt.py
text: @user1:
I think it should be on line 284 as well.