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
19 changes: 15 additions & 4 deletions plugins/modules/dns_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,29 @@ def modify_dns_config(
# GET method to get the DNS Config by UUID
dns_config = DNSConfig.get_by_uuid(module.params, rest_client)

# If DNS config doesn't exist, raise an exception (error)
state = module.params["state"] # state param value from module

new_dns_servers = build_entry_list([], module.params["dns_servers"], state)[0]
new_search_domains = build_entry_list([], module.params["search_domains"], state)[0]

# If DNS config doesn't exist, create one.
if not dns_config:
raise errors.ScaleComputingError("DNS Config: There is no DNS configuration.")
module.warn("DNS Config: There is no DNS configuration.")
create_task_tag = rest_client.create_record(
endpoint="/rest/v1/DNSConfig",
payload=dict(searchDomains=new_search_domains, serverIPs=new_dns_servers),
check_mode=module.check_mode,
)
TaskTag.wait_task(rest_client, create_task_tag)
after = DNSConfig.get_by_uuid(module.params, rest_client).to_ansible()
return True, DNSConfig.get_state(rest_client), dict(before={}, after=after)

# Otherwise, continue with modifying the configuration
before = dns_config.to_ansible()
old_state = DNSConfig.get_state(
rest_client
) # get the state of DNS config before modification

state = module.params["state"] # state param value from module

# Set action according to specified state param
action = "create"
if state != "set":
Expand Down
80 changes: 52 additions & 28 deletions tests/integration/targets/dns_config/tasks/01_dns_config_info.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,57 @@
---
- environment:
SC_HOST: "{{ sc_host }}"
SC_USERNAME: "{{ sc_username }}"
SC_PASSWORD: "{{ sc_password }}"
# -------------------------------------------------------------------
- include_tasks: helper_api_dns_delete_all.yml

- name: Retrieve info about DNS Config - unconfigured cluster
scale_computing.hypercore.dns_config_info:
register: result
- ansible.builtin.assert:
that:
- result.changed == False
- result.record == {}

# -------------------------------------------------------------------

- include_tasks: helper_api_dns_create_one.yml
vars:
actual_uuid: ""
actual_server_ips: []
actual_search_domains: []
dns_config:
search_domains:
- aa.example.com
- bb.example.com
dns_servers:
- 8.8.4.4
- 8.8.8.8

- name: Retrieve info about DNS Config - configured cluster
scale_computing.hypercore.dns_config_info:
register: result
- ansible.builtin.assert:
that:
- result.record != []
- "{{ result.record.keys() | sort == ['latest_task_tag', 'search_domains', 'server_ips', 'uuid'] }}"
- result.record.uuid == "dnsconfig_guid"
- result.record.server_ips == ["8.8.4.4", "8.8.8.8"]
- result.record.search_domains == ["aa.example.com", "bb.example.com"]
- result.record.latest_task_tag

# -------------------------------------------------------------------

block:
- name: Get expected configs
scale_computing.hypercore.api:
action: get
endpoint: /rest/v1/DNSConfig/dnsconfig_guid
register: dns_config
- ansible.builtin.set_fact:
actual_server_ips: "{{ dns_config.record.0.serverIPs }}"
actual_search_domains: "{{ dns_config.record.0.searchDomains }}"
actual_uuid: "{{ dns_config.record.0.uuid }}"
- name: Prepare for test - DNSConfig object with empty values
scale_computing.hypercore.api:
action: post
endpoint: /rest/v1/DNSConfig/dnsconfig_guid
data:
searchDomains: []
serverIPs: []

- name: Retrieve info about DNS Config
scale_computing.hypercore.dns_config_info:
register: result
- ansible.builtin.assert:
that:
- result.record != []
- "{{ result.record.keys() | sort == ['latest_task_tag', 'search_domains', 'server_ips', 'uuid'] }}"
- result.record.uuid == actual_uuid
- result.record.server_ips == actual_server_ips
- result.record.search_domains == actual_search_domains # fails if set to [], [""] or ['']
- result.record.latest_task_tag
- name: Retrieve info about DNS Config - configured cluster with emtpy values
scale_computing.hypercore.dns_config_info:
register: result
- ansible.builtin.assert:
that:
- result.record != []
- "{{ result.record.keys() | sort == ['latest_task_tag', 'search_domains', 'server_ips', 'uuid'] }}"
- result.record.uuid == "dnsconfig_guid"
- result.record.server_ips == []
- result.record.search_domains == []
- result.record.latest_task_tag
Loading