Merge lp:~rvb/maas/bug-1337190 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 2503
Proposed branch: lp:~rvb/maas/bug-1337190
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 19 lines (+2/-6)
1 file modified
src/maasserver/tests/test_api_nodegroup.py (+2/-6)
To merge this branch: bzr merge lp:~rvb/maas/bug-1337190
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+225444@code.launchpad.net

Commit message

Fix test_updates_mac_cluster_interface: use different interfaces for all the MAC addresses to avoid generating clashing IP addresses.

Description of the change

The problem was that MAC addresses could be linked to the same interface because the interface was chosen at random in:
        mac_addresses = {
            factory.make_mac_address(): random.choice(interfaces)
            for i in range(4)
            }

As a consequence, the call to `get_random_ip_from_interface_range` could return the *same* IP twice in:
        leases = {
            get_random_ip_from_interface_range(interface): (
                mac_address.mac_address)
            for mac_address, interface in mac_addresses.items()
        }
The result was a failure of the whole test because the leases would be missing an entry.

My solution restricts a bit what the test actually tests but I don't think it's a problem in practice because what update_mac_cluster_interfaces() does do not depend on whether the IP addresses in the leases dictionary are on the same interface or not.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/tests/test_api_nodegroup.py'
--- src/maasserver/tests/test_api_nodegroup.py 2014-06-25 16:51:34 +0000
+++ src/maasserver/tests/test_api_nodegroup.py 2014-07-03 09:29:42 +0000
@@ -832,13 +832,9 @@
832832
833 def test_updates_mac_cluster_interfaces(self):833 def test_updates_mac_cluster_interfaces(self):
834 cluster = factory.make_node_group()834 cluster = factory.make_node_group()
835 interfaces = [
836 factory.make_node_group_interface(nodegroup=cluster)
837 for i in range(4)
838 ]
839 interfaces.append(cluster.nodegroupinterface_set.first())
840 mac_addresses = {835 mac_addresses = {
841 factory.make_mac_address(): random.choice(interfaces)836 factory.make_mac_address(): factory.make_node_group_interface(
837 nodegroup=cluster)
842 for i in range(4)838 for i in range(4)
843 }839 }
844 leases = {840 leases = {