Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions examples/smtp.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
---
- name: Modify SMTP configuration without authentication
scale_computing.hypercore.smtp:
server: smtp-relay.gmail.com
port: 25
use_ssl: false
requires_auth: false
from_address: example@example.com
- name: Create and modify SMTP configuration
hosts: localhost
connection: local
gather_facts: false
vars:
smtp_server: smtp-relay.gmail.com
smtp_port: 25
smtp_from_address: example@example.com

- name: Modify SMTP configuration with authentication
scale_computing.hypercore.smtp:
server: smtp-relay.gmail.com
port: 25
use_ssl: false
auth_user: example
auth_password: example123
from_address: example@example.com
tasks:
- name: Modify SMTP configuration with authentication
scale_computing.hypercore.smtp:
server: "{{ smtp_server }}"
port: "{{ smtp_port }}"
use_ssl: false
auth_user: example
auth_password: example123
from_address: "{{ smtp_from_address }}"

- name: Modify SMTP configuration with required params only
scale_computing.hypercore.smtp:
server: smtp-relay.gmail.com
port: 25
- name: Modify SMTP configuration with required params only, authentication is preserved
scale_computing.hypercore.smtp:
server: "{{ smtp_server }}"
port: "{{ smtp_port }}"

- name: Modify SMTP configuration, remove authentication
scale_computing.hypercore.smtp:
server: "{{ smtp_server }}"
port: "{{ smtp_port }}"
auth_user: ""
auth_password: ""

- name: List SMTP Configuration
scale_computing.hypercore.smtp_info:
register: smtp_info

- ansible.builtin.debug:
msg: Final SMTP configuration is "{{ smtp_info }}"
17 changes: 12 additions & 5 deletions examples/smtp_info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
---
- name: List SMTP Configuration
scale_computing.hypercore.smtp_info:
register: smtp_info
- ansible.builtin.debug:
msg: "{{ smtp_info }}"
- name: List SMTP configuration
hosts: localhost
connection: local
gather_facts: false

tasks:
- name: List SMTP Configuration
scale_computing.hypercore.smtp_info:
register: smtp_info

- ansible.builtin.debug:
msg: "{{ smtp_info }}"
14 changes: 7 additions & 7 deletions plugins/module_utils/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SMTP(PayloadMapper):
def __init__(
self,
uuid: Union[str, None] = None,
smtp_server: Union[str, None] = None,
server: Union[str, None] = None,
port: Union[int, None] = None,
use_ssl: Union[bool, None] = False,
use_auth: Union[bool, None] = False,
Expand All @@ -33,7 +33,7 @@ def __init__(
latest_task_tag: Union[TypedTaskTag, dict[Any, Any], None] = None,
):
self.uuid = uuid
self.smtp_server = smtp_server
self.server = server
self.port = port
self.use_ssl = use_ssl
self.use_auth = use_auth
Expand All @@ -46,7 +46,7 @@ def __init__(
def from_ansible(cls, ansible_data: TypedSmtpFromAnsible) -> SMTP:
return SMTP(
uuid=ansible_data["uuid"],
smtp_server=ansible_data["smtp_server"],
server=ansible_data["server"],
port=ansible_data["port"],
use_ssl=ansible_data["use_ssl"],
use_auth=ansible_data["use_auth"],
Expand All @@ -63,7 +63,7 @@ def from_hypercore(cls, hypercore_data: dict[Any, Any]) -> SMTP:
# raise xzy
return cls(
uuid=hypercore_data["uuid"],
smtp_server=hypercore_data["smtpServer"],
server=hypercore_data["smtpServer"],
port=hypercore_data["port"],
use_ssl=hypercore_data["useSSL"],
use_auth=hypercore_data["useAuth"],
Expand All @@ -75,7 +75,7 @@ def from_hypercore(cls, hypercore_data: dict[Any, Any]) -> SMTP:

def to_hypercore(self) -> dict[Any, Any]:
return dict(
smtpServer=self.smtp_server,
smtpServer=self.server,
port=self.port,
useSSL=self.use_ssl,
useAuth=self.use_auth,
Expand All @@ -87,7 +87,7 @@ def to_hypercore(self) -> dict[Any, Any]:
def to_ansible(self) -> TypedSmtpToAnsible:
return dict(
uuid=self.uuid,
smtp_server=self.smtp_server,
server=self.server,
port=self.port,
use_ssl=self.use_ssl,
use_auth=self.use_auth,
Expand All @@ -104,7 +104,7 @@ def __eq__(self, other: object) -> bool:
return all(
(
self.uuid == other.uuid,
self.smtp_server == other.smtp_server,
self.server == other.server,
self.port == other.port,
self.use_ssl == other.use_ssl,
self.use_auth == other.use_auth,
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/typed_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TypedDiff(TypedDict):
# smtp module
class TypedSmtpToAnsible(TypedDict):
uuid: Union[str, None]
smtp_server: Union[str, None]
server: Union[str, None]
port: Union[int, None]
use_ssl: Union[bool, None]
use_auth: Union[bool, None]
Expand All @@ -125,7 +125,7 @@ class TypedSmtpToAnsible(TypedDict):

class TypedSmtpFromAnsible(TypedDict):
uuid: Union[str, None]
smtp_server: Union[str, None]
server: Union[str, None]
port: Union[int, None]
use_ssl: Union[bool, None]
use_auth: Union[bool, None]
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"""

RETURN = r"""
results:
record:
description:
- Output from modifying entries of the SMTP configuration on HyperCore API.
returned: success
Expand All @@ -107,7 +107,7 @@
state: COMPLETE
taskTag: 761
port: 25
smtp_server: smtp-relay.gmail.com
server: smtp-relay.gmail.com
use_auth: false
use_ssl: false
uuid: smtpconfig_guid
Expand Down Expand Up @@ -187,7 +187,7 @@ def modify_smtp_config(
) # get the state of SMTP config before modification

new_smtp_server, new_smtp_server_change_needed = build_entry(
before.get("smtp_server"), module.params["server"]
before.get("server"), module.params["server"]
)
new_port, new_port_change_needed = build_entry(
before.get("port"), module.params["port"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/smtp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"""

RETURN = r"""
results:
record:
description:
- SMTP configuration record.
returned: success
Expand All @@ -60,7 +60,7 @@
state: COMPLETE
taskTag: 761
port: 25
smtp_server: smtp-relay.gmail.com
server: smtp-relay.gmail.com
use_auth: false
use_ssl: false
uuid: smtpconfig_guid
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/smtp/tasks/01_smtp_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
- ansible.builtin.assert:
that:
- result.changed == False
- result.record.keys() | sort == ['auth_password', 'auth_user', 'from_address', 'latest_task_tag', 'port', 'smtp_server', 'use_auth', 'use_ssl', 'uuid']
- result.record.keys() | sort == ['auth_password', 'auth_user', 'from_address', 'latest_task_tag', 'port', 'server', 'use_auth', 'use_ssl', 'uuid']
- result.record.uuid == "smtpconfig_guid"
- result.record.smtp_server == "mail.example.com"
- result.record.server == "mail.example.com"
- result.record.port == 25
- result.record.use_ssl == False
- result.record.use_auth == False
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/targets/smtp/tasks/02_smtp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
that:
- result.changed == True
- result.diff.before != result.diff.after
- result.record.keys() | sort == ['auth_password', 'auth_user', 'from_address', 'latest_task_tag', 'port', 'smtp_server', 'use_auth', 'use_ssl', 'uuid']
- info.record.smtp_server == "smtp.office365.com"
- result.record.keys() | sort == ['auth_password', 'auth_user', 'from_address', 'latest_task_tag', 'port', 'server', 'use_auth', 'use_ssl', 'uuid']
- info.record.server == "smtp.office365.com"
- info.record.port == 21
- info.record.use_ssl == False
- info.record.use_auth == False
Expand All @@ -61,8 +61,8 @@
that:
- result.changed == False
- result.diff.before == result.diff.after
- result.record.keys() | sort == ['auth_password', 'auth_user', 'from_address', 'latest_task_tag', 'port', 'smtp_server', 'use_auth', 'use_ssl', 'uuid']
- info.record.smtp_server == "smtp.office365.com"
- result.record.keys() | sort == ['auth_password', 'auth_user', 'from_address', 'latest_task_tag', 'port', 'server', 'use_auth', 'use_ssl', 'uuid']
- info.record.server == "smtp.office365.com"
- info.record.port == 21
- info.record.use_ssl == False
- info.record.use_auth == False
Expand Down Expand Up @@ -90,7 +90,7 @@
that:
- result.changed == True
- result.diff.before != result.diff.after
- info.record.smtp_server == "smtp.office365.com"
- info.record.server == "smtp.office365.com"
- info.record.port == 26
- info.record.use_ssl == False
- info.record.use_auth == False
Expand All @@ -112,7 +112,7 @@
that:
- result.changed == False
- result.diff.before == result.diff.after
- info.record.smtp_server == "smtp.office365.com"
- info.record.server == "smtp.office365.com"
- info.record.port == 26
- info.record.use_ssl == False
- info.record.use_auth == False
Expand Down Expand Up @@ -141,7 +141,7 @@
that:
- result.changed == True
- result.diff.before != result.diff.after
- info.record.smtp_server == "smtp-relay.gmail.com"
- info.record.server == "smtp-relay.gmail.com"
- info.record.port == 25
- info.record.use_ssl == False
- info.record.use_auth == True
Expand All @@ -168,7 +168,7 @@
# Complication "before == after" fails too
# latest_task_tag has different sessionID, modifiedTime etc.
# - result.diff.before == result.diff.after
- info.record.smtp_server == "smtp-relay.gmail.com"
- info.record.server == "smtp-relay.gmail.com"
- info.record.port == 25
- info.record.use_ssl == False
- info.record.use_auth == True
Expand All @@ -192,7 +192,7 @@
# Complication "before == after" fails too
# latest_task_tag has different sessionID, modifiedTime etc.
# - result.diff.before == result.diff.after
- info.record.smtp_server == "smtp-relay.gmail.com"
- info.record.server == "smtp-relay.gmail.com"
- info.record.port == 26
- info.record.use_ssl == False
- info.record.use_auth == True
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/plugins/module_utils/test_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestSMTP:
def setup_method(self):
self.smtp = SMTP(
uuid="test",
smtp_server="smtp-relay.gmail.com",
server="smtp-relay.gmail.com",
port=25,
use_ssl=True,
use_auth=True,
Expand Down Expand Up @@ -61,7 +61,7 @@ def setup_method(self):
)
self.ansible_dict = dict(
uuid="test",
smtp_server="smtp-relay.gmail.com",
server="smtp-relay.gmail.com",
port=25,
use_ssl=True,
use_auth=True,
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_get_state(self, rest_client):
print(f"result={result}")
assert result == {
"uuid": "test",
"smtp_server": "smtp-relay.gmail.com",
"server": "smtp-relay.gmail.com",
"port": 25,
"use_ssl": True,
"use_auth": True,
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/plugins/modules/test_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ def test_build_entry(self, api_entry, module_entry, expected):
@pytest.mark.parametrize(
(
"description",
"rc_smtp_server",
"rc_server",
"rc_port",
"rc_use_ssl",
"rc_use_auth",
"rc_auth_user",
"rc_auth_password",
"rc_from_address",
"smtp_server_param",
"server_param",
"port_param",
"use_ssl_param",
"auth_user_param",
"auth_password_param",
"from_address_param",
"expected_smtp_server",
"expected_server",
"expected_port",
"expected_use_ssl",
"expected_use_auth",
Expand Down Expand Up @@ -157,20 +157,20 @@ def test_modify_smtp_config(
rest_client,
task_wait,
mocker,
rc_smtp_server,
rc_server,
rc_port,
rc_use_ssl,
rc_use_auth,
rc_auth_user,
rc_auth_password,
rc_from_address,
smtp_server_param,
server_param,
port_param,
use_ssl_param,
auth_user_param,
auth_password_param,
from_address_param,
expected_smtp_server,
expected_server,
expected_port,
expected_use_ssl,
expected_use_auth,
Expand All @@ -184,7 +184,7 @@ def test_modify_smtp_config(
cluster_instance=dict(
host="https://0.0.0.0", username="admin", password="admin"
),
server=smtp_server_param,
server=server_param,
port=port_param,
use_ssl=use_ssl_param,
auth_user=auth_user_param,
Expand All @@ -196,7 +196,7 @@ def test_modify_smtp_config(
"ansible_collections.scale_computing.hypercore.plugins.module_utils.smtp.SMTP.get_by_uuid"
).return_value = SMTP(
uuid="test",
smtp_server=rc_smtp_server,
server=rc_server,
port=rc_port,
use_ssl=rc_use_ssl,
use_auth=rc_use_auth,
Expand All @@ -215,7 +215,7 @@ def test_modify_smtp_config(
called_with_dict = dict(
endpoint="/rest/v1/AlertSMTPConfig/test",
payload=dict(
smtpServer=expected_smtp_server,
smtpServer=expected_server,
port=expected_port,
useSSL=expected_use_ssl,
authUser=expected_auth_user,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/plugins/modules/test_smtp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_run_record_present(self, rest_client):
result = smtp_info.run(rest_client)
assert result == {
"uuid": "test",
"smtp_server": "smtp-relay.gmail.com",
"server": "smtp-relay.gmail.com",
"port": 25,
"use_ssl": True,
"use_auth": True,
Expand Down