Skip to content

Commit e74c014

Browse files
committed
Fix creating server with firewall wrong request format
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
1 parent 56ec13c commit e74c014

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

hcloud/servers/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def create(self,
457457
if networks is not None:
458458
data['networks'] = [network.id for network in networks]
459459
if firewalls is not None:
460-
data['firewalls'] = [firewall.id for firewall in firewalls]
460+
data['firewalls'] = [{"id": firewall.id} for firewall in firewalls]
461461
if user_data is not None:
462462
data['user_data'] = user_data
463463
if labels is not None:

tests/unit/servers/test_client.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
from hcloud.firewalls.client import BoundFirewall
5+
from hcloud.firewalls.domain import Firewall
56
from hcloud.floating_ips.client import BoundFloatingIP
67
from hcloud.isos.client import BoundIso
78
from hcloud.servers.client import ServersClient, BoundServer
@@ -576,6 +577,46 @@ def test_create_with_networks(self, servers_client, response_create_simple_serve
576577

577578
assert next_actions[0].id == 13
578579

580+
def test_create_with_firewalls(self, servers_client, response_create_simple_server):
581+
servers_client._client.request.return_value = response_create_simple_server
582+
firewalls = [Firewall(id=1), BoundFirewall(mock.MagicMock(), dict(id=2))]
583+
response = servers_client.create(
584+
"my-server",
585+
server_type=ServerType(name="cx11"),
586+
image=Image(id=4711),
587+
firewalls=firewalls,
588+
start_after_create=False
589+
)
590+
servers_client._client.request.assert_called_with(
591+
url="/servers",
592+
method="POST",
593+
json={
594+
'name': "my-server",
595+
'server_type': "cx11",
596+
'image': 4711,
597+
'firewalls': [{"id": 1}, {"id": 2}],
598+
"start_after_create": False
599+
}
600+
)
601+
602+
bound_server = response.server
603+
bound_action = response.action
604+
next_actions = response.next_actions
605+
root_password = response.root_password
606+
607+
assert root_password == "YItygq1v3GYjjMomLaKc"
608+
609+
assert bound_server._client is servers_client
610+
assert bound_server.id == 1
611+
assert bound_server.name == "my-server"
612+
613+
assert isinstance(bound_action, BoundAction)
614+
assert bound_action._client == servers_client._client.actions
615+
assert bound_action.id == 1
616+
assert bound_action.command == "create_server"
617+
618+
assert next_actions[0].id == 13
619+
579620
@pytest.mark.parametrize("server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))])
580621
def test_get_actions_list(self, servers_client, server, response_get_actions):
581622
servers_client._client.request.return_value = response_get_actions

0 commit comments

Comments
 (0)