- 
                Notifications
    You must be signed in to change notification settings 
- Fork 120
network.id should look for attrs "Id" and "id"... #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| [APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nlacasse The full list of commands accepted by this bot can be found here. 
Needs approval from an approver in each of these files:
 Approvers can indicate their approval by writing  | 
...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 containers#584
Signed-off-by: Nicolas Lacasse <nicolas.lacasse@gmail.com>
    d900a1b    to
    0d88ef8      
    Compare
  
    | Personally, I don't think we should ever generate a fake network id like this, but some tests depend on that behavior, so I left it in. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nlacasse what about returning Id or id depending on the endpoint. the libpod api and docker's are essentially the same. they differ in the /libpod prefix. If this is a fix for the docker api only and breaks libpod behavior, I'd suggest to return it via the compatible endpoint
| 
 I'm not sure I understand the suggestion. Does the  Also, note that my change does not break docker (or any) behavior, it only fixes  I think it's best to handle  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, you are right. This is about libpod. I missed part of it.
To the fix!
I don't like to return lowercase id or uppercase Id, if that's a fix let's be as precise as possible and return the correct value. If podman wants id, we have to look for id. If docker wants Id we look for that.
Therefore, let's return id correctly in Network.id property and work from there.
Now, there are a few unit tests that should be inspected too.
podman.tests.unit.test_network.NetworkTestCase testMethod=test_id
If we want to be sure that libpod returns id, we have to change Id-> id. to be sure we are doing things right, we can also version the tests so it will pass conditionally to the new fix.
@@ -61,9 +61,9 @@ class NetworkTestCase(unittest.TestCase):
         self.addCleanup(self.client.close)
 
     def test_id(self):
-        expected = {"Id": "1cf06390-709d-4ffa-a054-c3083abe367c"}
+        expected = {"id": "1cf06390-709d-4ffa-a054-c3083abe367c"}
         actual = Network(attrs=expected)
-        self.assertEqual(actual.id, expected["Id"])
+        self.assertEqual(actual.id, expected["id"])
 
         actual = Network(attrs={"name": "database"})
         self.assertEqual(Note that if you return "id" or "Id" you are not actually making any good use of this test, which would pass regardlessly. I would strongly like this test to fail strictly, to test for libpod. therefore we want this to return id or fail.
We are going to add test_compatible_id later for docker.
podman.tests.unit.test_network.NetworkTestCase testMethod=test_connect
this is more tricky, because this tests a docker payload which has Id as argument.
The Network.id call comes from inside Network.connect. something like this is usually handled in podman-py's style. by passing the compatible option to the request as a keyword argument, it returns a correct docker response.
@@ -99,6 +99,7 @@ class NetworkTestCase(unittest.TestCase):
             "podman_ctnr",
             aliases=["production"],
             ipv4_address="172.16.0.1",
+            compatible=True,
         )
         self.assertEqual(adapter.call_count, 1)
         self.assertDictEqual(But with only the compatible change we get to an unwanted behavior. within Network.connect we make a Network.id cal, that cannot return "Id" or "id" based on a keyword arg. The solution to return either "Id" or "id" is not precise in this test.
How to fix it? turns out, some of the tests are wrong too! but with some more investigation and adding Network.get_compatible_id we can solve a lot of issues (maybe not all, but that's a more solid approach in my opinion)
Here's the whole patch which makes tox -e py -- podman/tests/unit/test_network.py pass.
Let me know :)
| def id(self): # pylint: disable=invalid-name | ||
| """str: Returns the identifier of the network.""" | ||
| with suppress(KeyError): | ||
| if "Id" in self.attrs: | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd stick with the old behavior and simply return id. that's what we want.
| names = [i.name for i in nets] | ||
| self.assertIn("integration_test", names) | ||
|  | ||
| with self.subTest("Get by ID"): | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this test actually fail if id or Id?
| hey, @nlacasse. Any update? do you need help or clarification from my side? | 
...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