Fix test_assign_ip_multiple_groups random failures

Recently the test 'test_assign_ip_multiple_groups' has a random failure
that was depended on the order of entries selected from database. The
test had two errors:

* It didn't change network's CIDR, so node's IP address was checked
  for containing with incorrect (old) CIDR.
* The new IP range was created, but old ones weren't removed. So when
  IP allocation code picked old IP range - the test is passed; when
  the new IP range is picked - the test is failed.

Change-Id: Ib792ea1e4910a568d8bf44c6c6ba8afff0402b3f
Closes-Bug: #1518268
This commit is contained in:
Igor Kalnitsky 2015-12-30 17:23:48 +02:00
parent 7d9d362c7f
commit 7ad94b754d
1 changed files with 23 additions and 25 deletions

View File

@ -335,40 +335,38 @@ class TestNetworkManager(BaseNetworkManagerTest):
)
node_group = self.env.create_node_group()
self.env.nodes[1].group_id = node_group.json_body['id']
self.db().flush()
mgmt_net = self.db.query(NetworkGroup).filter(
NetworkGroup.group_id == node_group.json_body["id"]
).filter_by(
mgmt_net = self.db.query(NetworkGroup).filter_by(
group_id=node_group.json_body['id'],
name=consts.NETWORKS.management
).first()
mock_range = IPAddrRange(
first='9.9.9.1',
last='9.9.9.254',
network_group_id=mgmt_net.id
)
self.db.add(mock_range)
self.db.commit()
# since there's no delete-orphan cascade on network.ip_ranges
# relationship, we have to remove old ip_ranges manually
self.db.query(IPAddrRange).filter_by(
network_group_id=mgmt_net.id).delete()
# set new range for management network of non-default node group
mgmt_net.cidr = '7.7.7.0/24'
mgmt_net.ip_ranges = [IPAddrRange(first='7.7.7.1', last='7.7.7.254')]
self.db().flush()
self.env.network_manager.assign_ips(
self.env.clusters[-1],
self.env.nodes, consts.NETWORKS.management
self.env.nodes,
consts.NETWORKS.management
)
for n in self.env.nodes:
mgmt_net = self.db.query(NetworkGroup).filter(
NetworkGroup.group_id == n.group_id
).filter_by(
name=consts.NETWORKS.management
).first()
ip = self.db.query(IPAddr).\
filter_by(network=mgmt_net.id).\
filter_by(node=n.id).first()
for node in self.env.nodes:
mgmt_net = self.db.query(NetworkGroup).\
filter_by(
group_id=node.group_id,
name=consts.NETWORKS.management).first()
self.assertIn(
IPAddress(ip.ip_addr),
IPNetwork(mgmt_net.cidr)
)
ip = self.db.query(IPAddr).\
filter_by(network=mgmt_net.id, node=node.id).first()
self.assertIn(IPAddress(ip.ip_addr), IPNetwork(mgmt_net.cidr))
def test_ipaddr_joinedload_relations(self):
self.env.create(