forked from ansible-collections/hetzner.hcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(inventory): ensure host ipv6 variable is json serializable (ansib…
…le-collections#496) ##### SUMMARY Fix ansible-collections#495 Related to ansible-collections#477 ##### ISSUE TYPE - Bugfix Pull Request ##### COMPONENT NAME inventory
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- inventory - Ensure inventory host variables are serializable and can be cached. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from unittest.mock import MagicMock | ||
|
||
from plugins.inventory.hcloud import InventoryModule, first_ipv6_address | ||
from plugins.module_utils.vendor.hcloud.servers import BoundServer | ||
|
||
|
||
def test_first_ipv6_address(): | ||
found = first_ipv6_address("2001:db8::/64") | ||
assert isinstance(found, str) | ||
assert found == "2001:db8::1" | ||
|
||
|
||
def test_build_inventory_server(): | ||
client = MagicMock() | ||
inventory = InventoryModule() | ||
inventory.get_option = MagicMock() | ||
inventory.get_option.return_value = None | ||
|
||
server = BoundServer( | ||
client, | ||
{ | ||
"id": 45921624, | ||
"name": "my-server", | ||
"labels": {}, | ||
"status": "running", | ||
"public_net": { | ||
"ipv4": { | ||
"id": 56583278, | ||
"ip": "127.0.0.1", | ||
"blocked": False, | ||
"dns_ptr": "static.1.0.0.127.clients.your-server.de", | ||
}, | ||
"ipv6": {"id": 56583279, "ip": "2001:db8::/64", "blocked": False, "dns_ptr": []}, | ||
"floating_ips": [], | ||
"firewalls": [], | ||
}, | ||
"private_net": [], | ||
"server_type": {"id": 1, "name": "cx11", "architecture": "x86"}, | ||
"datacenter": { | ||
"id": 3, | ||
"name": "hel1-dc2", | ||
"location": {"id": 3, "name": "hel1"}, | ||
}, | ||
"image": {"id": 114690387, "name": "debian-12", "os_flavor": "debian", "os_version": "12"}, | ||
}, | ||
) | ||
# pylint: disable=protected-access | ||
variables = inventory._build_inventory_server(server) | ||
|
||
# Ensure the host_vars are json serializable | ||
json.dumps(variables) | ||
|
||
assert variables == { | ||
"id": 45921624, | ||
"name": "my-server", | ||
"status": "running", | ||
"type": "cx11", | ||
"server_type": "cx11", | ||
"architecture": "x86", | ||
"location": "hel1", | ||
"datacenter": "hel1-dc2", | ||
"labels": {}, | ||
"ipv4": "127.0.0.1", | ||
"ipv6": "2001:db8::1", | ||
"ipv6_network": "2001:db8::", | ||
"ipv6_network_mask": "64", | ||
"private_networks": [], | ||
"image_id": 114690387, | ||
"image_name": "debian-12", | ||
"image_os_flavor": "debian", | ||
"ansible_host": None, | ||
} |