add --port flag
This commit is contained in:
1 parent
2d564a1546
commit
9a818fce9f
10 files changed
+294
-14
No files matched your search
@@ -77,6 +77,75 @@ class GuestParsingTests(unittest.TestCase):
|
||||
self.assertEqual(_split_tags(None), ())
|
||||
|
||||
|
||||
class PortDeclarationTests(unittest.TestCase):
|
||||
"""A VM/CT can declare its own backend port."""
|
||||
|
||||
def _guest(self, tags: tuple = ()) -> Guest:
|
||||
return Guest(
|
||||
vmid=101, node="pve", name="web01", kind="qemu", status="running", tags=tags
|
||||
)
|
||||
|
||||
def _client(self, *, description: str = "", tags: tuple = ()) -> ProxmoxClient:
|
||||
transport = FakeTransport()
|
||||
add_proxmox_routes(
|
||||
transport,
|
||||
guests=[
|
||||
{
|
||||
"vmid": 101,
|
||||
"node": "pve",
|
||||
"type": "qemu",
|
||||
"name": "web01",
|
||||
"status": "running",
|
||||
"tags": ",".join(tags),
|
||||
}
|
||||
],
|
||||
guest_config={"description": description},
|
||||
)
|
||||
return client(transport)
|
||||
|
||||
def test_port_from_notes(self) -> None:
|
||||
proxmox = self._client(description="proxdomain-port=8080\n")
|
||||
self.assertEqual(proxmox.guest_port(self._guest()), (8080, "guest notes"))
|
||||
|
||||
def test_port_in_a_sentence(self) -> None:
|
||||
proxmox = self._client(description="App server. proxdomain-port: 3000 for the UI")
|
||||
self.assertEqual(proxmox.guest_port(self._guest())[0], 3000)
|
||||
|
||||
def test_port_from_tag(self) -> None:
|
||||
proxmox = self._client(tags=("proxdomain", "proxdomain-port-8096"))
|
||||
self.assertEqual(proxmox.guest_port(self._guest(tags=("proxdomain", "proxdomain-port-8096"))), (8096, "guest tag"))
|
||||
|
||||
def test_notes_win_over_tag(self) -> None:
|
||||
proxmox = self._client(description="proxdomain-port=8080", tags=("proxdomain-port-9000",))
|
||||
self.assertEqual(
|
||||
proxmox.guest_port(self._guest(tags=("proxdomain-port-9000",)))[0], 8080
|
||||
)
|
||||
|
||||
def test_no_declaration(self) -> None:
|
||||
proxmox = self._client(description="just a web server")
|
||||
self.assertEqual(proxmox.guest_port(self._guest()), (None, ""))
|
||||
|
||||
def test_unrelated_tag_is_ignored(self) -> None:
|
||||
proxmox = self._client(tags=("proxdomain", "prod"))
|
||||
self.assertEqual(proxmox.guest_port(self._guest(tags=("proxdomain", "prod"))), (None, ""))
|
||||
|
||||
def test_out_of_range_port_is_rejected(self) -> None:
|
||||
proxmox = self._client(description="proxdomain-port=70000")
|
||||
with self.assertRaises(ProxdomainError) as ctx:
|
||||
proxmox.guest_port(self._guest())
|
||||
self.assertIn("not a valid TCP port", str(ctx.exception))
|
||||
|
||||
def test_config_read_failure_means_no_declaration(self) -> None:
|
||||
transport = FakeTransport()
|
||||
transport.add(
|
||||
"GET",
|
||||
"/api2/json/nodes/pve/qemu/101/config",
|
||||
{"errors": [{"message": "unavailable"}]},
|
||||
status=500,
|
||||
)
|
||||
self.assertEqual(client(transport).guest_port(self._guest()), (None, ""))
|
||||
|
||||
|
||||
class AddressTests(unittest.TestCase):
|
||||
def _guest(self, kind: str = "qemu", vmid: int = 101) -> Guest:
|
||||
return Guest(vmid=vmid, node="pve", name="web01", kind=kind, status="running")
|
||||
|
||||
Reference in new issue
Block a user