Skip to content

Commit

Permalink
Merge branch 'main' into create_volume
Browse files Browse the repository at this point in the history
  • Loading branch information
TSKushal authored Sep 21, 2023
2 parents 3defb7e + 756e8f5 commit fff5d13
Show file tree
Hide file tree
Showing 23 changed files with 317 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/BOTMETA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ files:
$module_utils/gconftool2.py:
labels: gconftool2
maintainers: russoz
$module_utils/gio_mime.py:
maintainers: russoz
$module_utils/gitlab.py:
keywords: gitlab source_control
labels: gitlab
Expand Down Expand Up @@ -517,6 +519,8 @@ files:
$modules/gem.py:
labels: gem
maintainers: $team_ansible_core johanwiren
$modules/gio_mime.py:
maintainers: russoz
$modules/git_config.py:
maintainers: djmattyg007 mgedmin
$modules/github_:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- redfish_config - adding ``SetSecureBoot`` command (https://github.com/ansible-collections/community.general/pull/7129).
2 changes: 2 additions & 0 deletions changelogs/fragments/7242_ignore_similar_chars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- random_string - added new ``ignore_similar_chars`` and ``similar_chars`` option to ignore certain chars (https://github.com/ansible-collections/community.general/pull/7242).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- gitlab_project_variable - deleted all variables when used with ``purge=true`` due to missing ``raw`` property in KNOWN attributes (https://github.com/ansible-collections/community.general/issues/7250).
- gitlab_group_variable - deleted all variables when used with ``purge=true`` due to missing ``raw`` property in KNOWN attributes (https://github.com/ansible-collections/community.general/issues/7250).
2 changes: 1 addition & 1 deletion plugins/filter/from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
- name: Parse a CSV file's contents
ansible.builtin.debug:
msg: >-
{{ csv_data | community.genera.from_csv(dialect='unix') }}
{{ csv_data | community.general.from_csv(dialect='unix') }}
vars:
csv_data: |
Column 1,Value
Expand Down
21 changes: 21 additions & 0 deletions plugins/lookup/random_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@
- Override all values of O(numbers), O(upper), O(lower), and O(special) with
the given list of characters.
type: str
ignore_similar_chars:
description:
- Ignore similar characters, such as V(l) and V(1), or V(O) and V(0).
- These characters can be configured in O(similar_chars).
default: false
type: bool
version_added: 7.5.0
similar_chars:
description:
- Overide a list of characters not to be use in the string.
default: "il1LoO0"
type: str
version_added: 7.5.0
base64:
description:
- Returns base64 encoded string.
Expand Down Expand Up @@ -173,9 +186,17 @@ def run(self, terms, variables=None, **kwargs):
length = self.get_option("length")
base64_flag = self.get_option("base64")
override_all = self.get_option("override_all")
ignore_similar_chars = self.get_option("ignore_similar_chars")
similar_chars = self.get_option("similar_chars")
values = ""
available_chars_set = ""

if ignore_similar_chars:
number_chars = "".join([sc for sc in number_chars if sc not in similar_chars])
lower_chars = "".join([sc for sc in lower_chars if sc not in similar_chars])
upper_chars = "".join([sc for sc in upper_chars if sc not in similar_chars])
special_chars = "".join([sc for sc in special_chars if sc not in similar_chars])

if override_all:
# Override all the values
available_chars_set = override_all
Expand Down
32 changes: 32 additions & 0 deletions plugins/module_utils/gio_mime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2022, Alexei Znamensky <[email protected]>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import absolute_import, division, print_function
__metaclass__ = type

from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt


def gio_mime_runner(module, **kwargs):
return CmdRunner(
module,
command=['gio', 'mime'],
arg_formats=dict(
mime_type=cmd_runner_fmt.as_list(),
handler=cmd_runner_fmt.as_list(),
),
**kwargs
)


def gio_mime_get(runner, mime_type):
def process(rc, out, err):
if err.startswith("No default applications for"):
return None
out = out.splitlines()[0]
return out.split()[-1]

with runner("mime_type", output_process=process) as ctx:
return ctx.run(mime_type=mime_type)
2 changes: 1 addition & 1 deletion plugins/module_utils/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def gitlab_authentication(module):
def filter_returned_variables(gitlab_variables):
# pop properties we don't know
existing_variables = [dict(x.attributes) for x in gitlab_variables]
KNOWN = ['key', 'value', 'masked', 'protected', 'variable_type', 'environment_scope']
KNOWN = ['key', 'value', 'masked', 'protected', 'variable_type', 'environment_scope', 'raw']
for item in existing_variables:
for key in list(item.keys()):
if key not in KNOWN:
Expand Down
19 changes: 19 additions & 0 deletions plugins/module_utils/redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3432,6 +3432,25 @@ def enable_secure_boot(self):

return self.patch_request(self.root_uri + secure_boot_url, body, check_pyld=True)

def set_secure_boot(self, secure_boot_enable):
# This function enable Secure Boot on an OOB controller

response = self.get_request(self.root_uri + self.systems_uri)
if response["ret"] is False:
return response

server_details = response["data"]
secure_boot_url = server_details["SecureBoot"]["@odata.id"]

response = self.get_request(self.root_uri + secure_boot_url)
if response["ret"] is False:
return response

body = {}
body["SecureBootEnable"] = secure_boot_enable

return self.patch_request(self.root_uri + secure_boot_url, body, check_pyld=True)

def get_hpe_thermal_config(self):
result = {}
key = "Thermal"
Expand Down
108 changes: 108 additions & 0 deletions plugins/modules/gio_mime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2022, Alexei Znamensky <[email protected]>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import absolute_import, division, print_function
__metaclass__ = type

DOCUMENTATION = '''
module: gio_mime
author:
- "Alexei Znamensky (@russoz)"
short_description: Set default handler for MIME type, for applications using Gnome GIO
version_added: 7.5.0
description:
- This module allows configuring the default handler for a specific MIME type, to be used by applications built with th Gnome GIO API.
extends_documentation_fragment:
- community.general.attributes
attributes:
check_mode:
support: full
diff_mode:
support: full
options:
mime_type:
description:
- MIME type for which a default handler will be set.
type: str
required: true
handler:
description:
- Default handler will be set for the MIME type.
type: str
required: true
notes:
- This module is a thin wrapper around the C(gio mime) command (and subcommand).
- See man gio(1) for more details.
seealso:
- name: GIO Documentation
description: Reference documentation for the GIO API..
link: https://docs.gtk.org/gio/
'''

EXAMPLES = """
- name: Set chrome as the default handler for https
community.general.gio_mime:
mime_type: x-scheme-handler/https
handler: google-chrome.desktop
register: result
"""

RETURN = '''
handler:
description:
- The handler set as default.
returned: success
type: str
sample: google-chrome.desktop
stdout:
description:
- The output of the C(gio) command.
returned: success
type: str
sample: Set google-chrome.desktop as the default for x-scheme-handler/https
stderr:
description:
- The error output of the C(gio) command.
returned: failure
type: str
sample: 'gio: Failed to load info for handler "never-existed.desktop"'
'''

from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
from ansible_collections.community.general.plugins.module_utils.gio_mime import gio_mime_runner, gio_mime_get


class GioMime(ModuleHelper):
output_params = ['handler']
module = dict(
argument_spec=dict(
mime_type=dict(type='str', required=True),
handler=dict(type='str', required=True),
),
supports_check_mode=True,
)

def __init_module__(self):
self.runner = gio_mime_runner(self.module, check_rc=True)
self.vars.set_meta("handler", initial_value=gio_mime_get(self.runner, self.vars.mime_type), diff=True, change=True)

def __run__(self):
check_mode_return = (0, 'Module executed in check mode', '')
if self.vars.has_changed("handler"):
with self.runner.context(args_order=["mime_type", "handler"], check_mode_skip=True, check_mode_return=check_mode_return) as ctx:
rc, out, err = ctx.run()
self.vars.stdout = out
self.vars.stderr = err
if self.verbosity >= 4:
self.vars.run_info = ctx.run_info


def main():
GioMime.execute()


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions plugins/modules/gitlab_group_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ def main():
group=dict(type='str', required=True),
purge=dict(type='bool', required=False, default=False),
vars=dict(type='dict', required=False, default=dict(), no_log=True),
# please mind whenever changing the variables dict to also change module_utils/gitlab.py's
# KNOWN dict in filter_returned_variables or bad evil will happen
variables=dict(type='list', elements='dict', required=False, default=list(), options=dict(
name=dict(type='str', required=True),
value=dict(type='str', no_log=True),
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/gitlab_project_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ def main():
project=dict(type='str', required=True),
purge=dict(type='bool', required=False, default=False),
vars=dict(type='dict', required=False, default=dict(), no_log=True),
# please mind whenever changing the variables dict to also change module_utils/gitlab.py's
# KNOWN dict in filter_returned_variables or bad evil will happen
variables=dict(type='list', elements='dict', required=False, default=list(), options=dict(
name=dict(type='str', required=True),
value=dict(type='str', no_log=True),
Expand Down
26 changes: 24 additions & 2 deletions plugins/modules/redfish_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@
type: dict
default: {}
version_added: '7.4.0'
secure_boot_enable:
required: false
description:
- Setting parameter to enable or disable SecureBoot.
type: bool
default: True
version_added: '7.5.0'
author:
- "Jose Delarosa (@jose-delarosa)"
- "T S Kushal (@TSKushal)"
Expand Down Expand Up @@ -294,6 +301,15 @@
username: "{{ username }}"
password: "{{ password }}"
- name: Set SecureBoot
community.general.redfish_config:
category: Systems
command: SetSecureBoot
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
secure_boot_enable: True
- name: Delete All Volumes
community.general.redfish_config:
category: Systems
Expand Down Expand Up @@ -335,7 +351,7 @@
# More will be added as module features are expanded
CATEGORY_COMMANDS_ALL = {
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
"SetDefaultBootOrder", "EnableSecureBoot", "DeleteVolumes", "CreateVolume"],
"SetDefaultBootOrder", "EnableSecureBoot", "SetSecureBoot", "DeleteVolumes", "CreateVolume"],
"Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"],
"Sessions": ["SetSessionService"],
}
Expand Down Expand Up @@ -370,7 +386,8 @@ def main():
sessions_config=dict(type='dict', default={}),
storage_subsystem_id=dict(type='str', default=''),
volume_ids=dict(type='list', default=[], elements='str'),
volume_details=dict(type='dict', default={})
volume_details=dict(type='dict', default={}),
secure_boot_enable=dict(type='bool', default=True)
),
required_together=[
('username', 'password'),
Expand Down Expand Up @@ -427,6 +444,9 @@ def main():
# Volume creation options
volume_details = module.params['volume_details']
storage_subsystem_id = module.params['storage_subsystem_id']

# Set SecureBoot options
secure_boot_enable = module.params['secure_boot_enable']

# Build root URI
root_uri = "https://" + module.params['baseuri']
Expand Down Expand Up @@ -461,6 +481,8 @@ def main():
result = rf_utils.set_default_boot_order()
elif command == "EnableSecureBoot":
result = rf_utils.enable_secure_boot()
elif command == "SetSecureBoot":
result = rf_utils.set_secure_boot(secure_boot_enable)
elif command == "DeleteVolumes":
result = rf_utils.delete_volumes(storage_subsystem_id, volume_ids)
elif command == "CreateVolume":
Expand Down
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
plugins/modules/xfconf.py validate-modules:return-syntax-error
tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.6 # django generated code
tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.7 # django generated code
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ plugins/modules/rax.py use-argspec-type-path
plugins/modules/read_csv.py validate-modules:invalid-documentation
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
plugins/modules/xfconf.py validate-modules:return-syntax-error
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ plugins/modules/rax.py use-argspec-type-path
plugins/modules/read_csv.py validate-modules:invalid-documentation
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
plugins/modules/xfconf.py validate-modules:return-syntax-error
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ plugins/modules/read_csv.py validate-modules:invalid-documentation
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt'
plugins/modules/xfconf.py validate-modules:return-syntax-error
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ plugins/modules/rax.py use-argspec-type-path
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt'
plugins/modules/xfconf.py validate-modules:return-syntax-error
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.16.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt'
plugins/modules/udm_user.py import-3.12 # Uses deprecated stdlib library 'crypt'
plugins/modules/xfconf.py validate-modules:return-syntax-error
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.17.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt'
plugins/modules/udm_user.py import-3.12 # Uses deprecated stdlib library 'crypt'
plugins/modules/xfconf.py validate-modules:return-syntax-error
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
6 changes: 3 additions & 3 deletions tests/unit/plugins/modules/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def run(self):

test_flags = self.test_flags()
if test_flags.get("skip"):
pytest.skip(reason=test_flags["skip"])
pytest.skip()
if test_flags.get("xfail"):
pytest.xfail(reason=test_flags["xfail"])
pytest.xfail()

func()

Expand Down Expand Up @@ -90,7 +90,7 @@ def check_results(self, results):
print("call args list =\n%s" % call_args_list)
print("expected args list =\n%s" % expected_call_args_list)

assert self.mock_run_cmd.call_count == len(self.run_cmd_calls)
assert self.mock_run_cmd.call_count == len(self.run_cmd_calls), "{0} != {1}".format(self.mock_run_cmd.call_count, len(self.run_cmd_calls))
if self.mock_run_cmd.call_count:
assert call_args_list == expected_call_args_list

Expand Down
Loading

0 comments on commit fff5d13

Please sign in to comment.