Earlier  
Posted Nick Remark
#openstack-nova - 2022-07-27
11:45:06 gibi \o/
11:46:51 sean-k-mooney stephenfin: gibi how do we want to proceed with the mock change?
11:46:58 gibi sean-k-mooney: good question
11:47:13 sean-k-mooney im kind of sad that we chose to delay it last cycle
11:47:16 sean-k-mooney to drop 3.6
11:47:18 gibi sean-k-mooney: I'm not sure I will have enough time today to try to fix the duplicate mock issue
11:47:27 sean-k-mooney and now we added 3.10 which is causing other issues
11:47:40 gibi I don't know if stephenfin looked at it yet or not
11:49:19 gibi I can be convinced to let it land and fix the 310 issue separately I just affraid that we will forget about it and only realize it again when we want to make the py310 job votinh
11:49:23 gibi g
11:50:18 sean-k-mooney ya thats a valid concen
11:50:32 sean-k-mooney the 3.10 fixes shoudl be a seperate patch in my opipion
11:50:41 sean-k-mooney it would be nice ot have it in the seriese
11:50:42 gibi I agree with that
11:50:49 sean-k-mooney but not sure how much work it is
11:51:02 sean-k-mooney im also not partically happy with the decision they made in 3.10
11:51:03 gibi me neither but I feel like it is not a oneliner
11:51:31 sean-k-mooney double mocking is perhaps ineffenct but i think it should be allowed
11:51:48 sean-k-mooney so im sad they made that breakign change
11:52:32 gibi lets wait for stephenfin to chime in. Also I can try to look into it tomorrow to see how big is the issue
11:52:36 gibi then we can reconsider
11:52:48 sean-k-mooney we might need to add a helper funciton that check if its mocked and only create a new mock if not
11:52:59 gibi I would go and remove the duplicates if possible
11:53:08 gibi but I don't know how hard that will be
11:53:17 sean-k-mooney yes if we can do that once
11:53:25 sean-k-mooney then we will never hit this again because it will fail
11:53:35 gibi the helper feels like a coverup
11:54:00 sean-k-mooney im just worried about loading the context of is this mocked
11:54:27 sean-k-mooney again with the new behaivor it shoudl be obvious i guess because it will fail
11:54:34 gibi yeah
11:56:48 sean-k-mooney i just hope this does not cause shared global state
11:57:11 sean-k-mooney the fixture should be set up for every test
11:57:37 sean-k-mooney but we likely will have to replace part of them in the test where its double mocking
11:58:02 sean-k-mooney as i feel like we double mock somethimes when the fixture does not provide exactly what we want
11:58:09 sean-k-mooney i know i have done that at least once
11:58:32 gibi yes, I think that is the "normal" case when we double mock. I did that before
11:58:42 gibi so in this case the fixture should expose the mock
11:58:54 gibi so the test case can use it instead of remocking it
11:59:18 sean-k-mooney well we can jsut create a new mock object and assign it
11:59:27 sean-k-mooney instaed of having it patch it again
11:59:40 gibi we cannot create the new Mock as autospec will fail
11:59:54 gibi as it will try to spec what is already mocked
12:00:08 sean-k-mooney we can with mock.Mock()
12:00:13 gibi hm
12:00:14 sean-k-mooney we dont tend to use autospec much
12:00:29 sean-k-mooney we do in somecases but i rarely do
12:01:14 gibi A().foo = mock.Mock() is a monkeypatch that is not reverted automatically so that is a bad pattern
12:01:43 gibi also I think there is automatic autospecing in the mock lib (obviously not for mock.Mock() but for mock.patch decorator)
12:02:09 sean-k-mooney i dont think there is
12:02:14 sean-k-mooney or at least
12:02:21 sean-k-mooney its behavior shoudl be the same as the standard lib
12:02:28 sean-k-mooney so if there is it shoudl be in both
12:02:48 sean-k-mooney gibi: in the A().foo = mock.Mock()
12:03:08 sean-k-mooney we shoudl not need to revert that automaticlly if A is a mock already
12:03:52 gibi ahh, yeah, I ment there is automatic autospec in both lib and stdlib
12:04:56 gibi sean-k-mooney: yeah, if A().foo is already a mocked then that mock's patcher.stop() will revert the change. But the caller doing the A().foo = mock.Mock() does not know if foo is a Mock. So we establish a dangerous pattern
12:05:37 gibi if that pattern is used to other than a mocked field the we will leak global state between tests
12:06:22 sean-k-mooney gibi: right but we would only do that for the double mock case
12:06:40 sean-k-mooney but i agreee in general its bad
12:06:49 sean-k-mooney we have leaked state that way in the past
12:06:51 gibi yes, now, but then the next new dev came look at the code and think that A().foo = mock.Mock() is a generic pattern
12:07:05 sean-k-mooney where a mock was assinged to a stdlib function
12:07:25 sean-k-mooney so that is why i was wondering if we need a nova helper fucniton
12:07:34 sean-k-mooney to basiclaly always do the right thing
12:07:50 gibi but that mean all our mocking need to go through that helper
12:07:54 gibi that will be a massive change
12:08:19 sean-k-mooney perhaps i need to think about what pattern we can actully use that will work
12:08:36 gibi anyhow I'd like to do a non theorethicaly investigation with this
12:08:40 sean-k-mooney perhaps using the mock as a context manager
12:08:49 sean-k-mooney but not sure if that would still fail for the double mocking case
12:09:04 gibi btw this is why I remembered automatic autospeccing https://review.opendev.org/q/message:autospec+project:openstack/nova+status:merged
12:09:53 sean-k-mooney sure but that not automatic
12:10:06 sean-k-mooney that was exiplcitly enabling it and new right
12:10:11 gibi yeah, I missremembered
12:10:16 sean-k-mooney oh ok
12:10:54 gibi I will look at this mock thing tomorrow
12:11:10 gibi now I'm in a middle fighting with reshape + provider generation conflict
12:12:12 gibi I'm in the denial phase where I think my code is correct and reshape is broken :D
12:12:46 sean-k-mooney :)
12:13:08 sean-k-mooney maybe but if thats the case you will probly have to fix it in placment yes
12:13:17 sean-k-mooney so hopefully the issue is in your current code
12:13:21 gibi I know :D
12:13:24 sean-k-mooney that feels like less work
12:13:25 gibi hence "denial"
12:13:54 gibi anyhow I think this is the first case when we both create new RPs and reshape allocations at the same time
12:14:08 gibi from nova
12:14:55 gibi and RP creation is outside of the reshape code
12:15:02 sean-k-mooney if nova has not done it its likely no one else has
12:15:17 sean-k-mooney i dont think neutron or cyborg have used reshapes before
12:16:28 gibi me neither
12:50:54 bauzas I just capture the discussion
12:51:10 bauzas is it because unittest.mock is not on par with our mock lib ?
12:52:16 gibi it is that in py310 unittest.mock introduced a breaking change. The mock lib is a rolling backport of the upstream unittest.mock so at some point this change will appera in the standalone mock lib too
12:52:19 kashyap bauzas: Please put the stable/wallaby backport through: https://review.opendev.org/c/openstack/nova/+/851206
12:52:34 kashyap gibi ACKed it too; and you've ACKed the upstream main
12:53:39 gibi kashyap: we need to land the backports in order
12:53:44 gibi so we land the yoga first
12:53:48 gibi then xena
12:53:50 gibi then wallaby
12:54:03 kashyap gibi: Oh, yes. I mean to also implicitly look at 'em. :)

Earlier   Later