Skip to content

Commit 0d88ef8

Browse files
Nicolas Lacassenlacasse
authored andcommitted
network.id should look for attrs "Id" and "id"...
...before falling back to a synthetic id based on the hash of the network name. Checking both is needed to support the Docker-compatible format ("Id") and Libpod-native format ("id"). This is analagous to how podman-py handles network.name -- we check attrs "Name" and "name" in that order. Fixes #584 Signed-off-by: Nicolas Lacasse <[email protected]>
1 parent 34409e8 commit 0d88ef8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

podman/domain/networks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ class Network(PodmanResource):
3030
@property
3131
def id(self): # pylint: disable=invalid-name
3232
"""str: Returns the identifier of the network."""
33-
with suppress(KeyError):
33+
if "Id" in self.attrs:
3434
return self.attrs["Id"]
3535

36+
if "id" in self.attrs:
37+
return self.attrs["id"]
38+
3639
with suppress(KeyError):
3740
sha256 = hashlib.sha256(self.attrs["name"].encode("ascii"))
3841
return sha256.hexdigest()

podman/tests/integration/test_networks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def test_network_crud(self):
6464
names = [i.name for i in nets]
6565
self.assertIn("integration_test", names)
6666

67+
with self.subTest("Get by ID"):
68+
network = self.client.networks.get("integration_test")
69+
net_id = network.id
70+
assert isinstance(net_id, str)
71+
network_by_id = self.client.networks.get(net_id)
72+
self.assertEqual(network.name, network_by_id.name)
73+
6774
with self.subTest("Delete network"):
6875
network = self.client.networks.get("integration_test")
6976
network.remove(force=True)

0 commit comments

Comments
 (0)