mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
refactor(vrtManager): a VM's addresses are read once a page, not once an object
wvmInstance kept the guest agent's and the ARP table's addresses from
the first NIC it was asked about, and never read them again on that
object; it carried a lease lookup that was never filled.
The addresses are now one {MAC: (IPv4, IPv6)} read, kept like the
domain XML only inside a cached_reads block: the VM page, which reads
its NICs twice, asks the agent once (it may take its whole timeout),
and a read outside a page's block is a new one. The agent's addresses
still come before the ARP table's.
This commit is contained in:
parent
2d7e23864e
commit
b2b2386db9
4 changed files with 44 additions and 57 deletions
|
|
@ -27,7 +27,6 @@ AGENT = [{"name": "lo", "ip-addresses": [{"ip-address-type": "ipv4", "ip-address
|
|||
|
||||
def vm(agent):
|
||||
inst = wvmInstance.__new__(wvmInstance)
|
||||
inst._ip_cache = None
|
||||
inst.instance = MagicMock()
|
||||
inst.instance.interfaceAddresses.side_effect = lambda source: {VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP: ARP}[source]
|
||||
patch.object(inst, "get_status", return_value=1).start()
|
||||
|
|
@ -54,6 +53,19 @@ class InterfaceAddressesTestCase(unittest.TestCase):
|
|||
self.assertEqual([c.args for c in inst.instance.interfaceAddresses.call_args_list],
|
||||
[(VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP,)])
|
||||
|
||||
def test_the_addresses_are_read_once_in_a_page_and_again_after_it(self):
|
||||
inst = vm(agent=True)
|
||||
with inst.cached_reads():
|
||||
inst.get_interface_addresses(MAC)
|
||||
inst.get_interface_addresses("52:54:00:00:00:02")
|
||||
self.assertEqual(self.agent.call_count, 1)
|
||||
# outside a page's block, a new read: a NIC's address can change
|
||||
inst.get_interface_addresses(MAC)
|
||||
self.assertEqual(self.agent.call_count, 2)
|
||||
|
||||
def test_a_mac_without_addresses_has_none(self):
|
||||
self.assertEqual(vm(agent=False).get_interface_addresses("52:54:00:00:00:02"), (None, None))
|
||||
|
||||
def test_an_agent_that_does_not_answer_leaves_the_arp_address(self):
|
||||
self.agent.side_effect = libvirtError("guest agent didn't respond to command within '10' seconds")
|
||||
self.assertEqual(vm(agent=True).get_interface_addresses(MAC), (["192.0.2.10"], []))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue