From f6736a4b0ccbd32ef4552fef5e27273c07ca5e94 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Thu, 11 Apr 2019 06:45:28 -0400 Subject: [PATCH] Network/Router agent rebalancing bug fix. Add fix to ignore down agents in rescheduling. Change-Id: I5d06bd489f2d67be996e55608b77e31c1ed85114 Closes-Bug: #1824027 Signed-off-by: Kevin Smith --- .../tests/test_dhcp_network_rebalance_randomized.py | 7 ++++++- .../tests/test_network_rebalance_randomized.py | 7 ++++++- nfv/nfv-vim/nfv_vim/network_rebalance/_dhcp_rebalance.py | 7 ++++--- .../nfv_vim/network_rebalance/_network_rebalance.py | 9 +++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py index 0e410954..00c26a3c 100644 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py @@ -45,10 +45,15 @@ def build_get_agents_response(): NUM_AGENTS = random.randint(2, MAX_AGENTS - 1) for x in range(0, NUM_AGENTS): host_name = "compute-" + str(x) + admin_state_up = True + # randomly set admin_state_up on some agents to False + admin_state_down = random.randint(0, 5) + if admin_state_down == 0: + admin_state_up = False get_agents_response_entry = \ {"host": host_name, "agent_type": "DHCP agent", "id": host_name + "_id", "alive": True, - "admin_state_up": True} + "admin_state_up": admin_state_up} get_agents_response['result-data'].append(get_agents_response_entry) add_to_fake_host_table(host_name) diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py index 6dad2a41..9f655ed3 100644 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py @@ -49,10 +49,15 @@ def build_get_agents_response(): NUM_AGENTS = random.randint(0, MAX_AGENTS - 1) for x in range(0, NUM_AGENTS): host_name = "compute-" + str(x) + admin_state_up = True + # randomly set admin_state_up on some agents to False + admin_state_down = random.randint(0, 5) + if admin_state_down == 0: + admin_state_up = False get_agents_response_entry = \ {"host": host_name, "agent_type": "L3 agent", "id": host_name + "_id", "alive": True, - "admin_state_up": True} + "admin_state_up": admin_state_up} get_agents_response['result-data'].append(get_agents_response_entry) add_to_fake_host_table(host_name) diff --git a/nfv/nfv-vim/nfv_vim/network_rebalance/_dhcp_rebalance.py b/nfv/nfv-vim/nfv_vim/network_rebalance/_dhcp_rebalance.py index f14b7339..534c5bed 100644 --- a/nfv/nfv-vim/nfv_vim/network_rebalance/_dhcp_rebalance.py +++ b/nfv/nfv-vim/nfv_vim/network_rebalance/_dhcp_rebalance.py @@ -124,7 +124,7 @@ class DHCPAgentRebalance(object): _DHCPRebalance.num_networks_on_agents.append( len(_DHCPRebalance.network_ids_per_agent[agent_id])) self.dhcpagent_idx += 1 - return self.dhcpagent_idx == self.num_dhcp_agents + return self.dhcpagent_idx >= self.num_dhcp_agents def get_host_id_of_current_dhcp_agent(self): return self.dhcp_agents[self.dhcpagent_idx]['host_uuid'] @@ -137,7 +137,7 @@ class DHCPAgentRebalance(object): def datanetworks_done(self): self.dhcpagent_idx += 1 - if self.dhcpagent_idx == self.num_dhcp_agents: + if self.dhcpagent_idx >= self.num_dhcp_agents: return True else: return False @@ -187,9 +187,10 @@ class DHCPAgentRebalance(object): # (if applicable) first in the list. if agent['host'] == self.get_working_host(): self.dhcp_agents.insert(0, agent_info_dict) + self.add_agent(agent['id']) elif agent['alive'] and agent['admin_state_up']: self.dhcp_agents.append(agent_info_dict) - self.add_agent(agent['id']) + self.add_agent(agent['id']) DLOG.debug("self.dhcp_agents = %s" % self.dhcp_agents) return len(self.dhcp_agents) diff --git a/nfv/nfv-vim/nfv_vim/network_rebalance/_network_rebalance.py b/nfv/nfv-vim/nfv_vim/network_rebalance/_network_rebalance.py index 64ae3efd..420c5b10 100644 --- a/nfv/nfv-vim/nfv_vim/network_rebalance/_network_rebalance.py +++ b/nfv/nfv-vim/nfv_vim/network_rebalance/_network_rebalance.py @@ -129,7 +129,7 @@ class L3AgentRebalance(object): _L3Rebalance.num_routers_on_agents.append( len(_L3Rebalance.router_ids_per_agent[agent_id])) self.l3agent_idx += 1 - return self.l3agent_idx == self.num_l3agents + return self.l3agent_idx >= self.num_l3agents def add_network_to_router(self, router_to_resched, network_id): self.networks_per_router[router_to_resched].append(network_id) @@ -145,7 +145,7 @@ class L3AgentRebalance(object): self.router_idx = 0 self.l3agent_idx += 1 if (((self.working_host is not None) and (self.l3agent_idx == 1)) - or (self.l3agent_idx == self.num_l3agents)): + or (self.l3agent_idx >= self.num_l3agents)): # We have router port info for all routers on all agents # that we care about. Get the Physical Network info for these. return True @@ -223,7 +223,7 @@ class L3AgentRebalance(object): def datanetworks_done(self): self.l3agent_idx += 1 - if self.l3agent_idx == self.num_l3agents: + if self.l3agent_idx >= self.num_l3agents: return True else: return False @@ -278,9 +278,10 @@ class L3AgentRebalance(object): # (if applicable) first in the list. if agent['host'] == self.get_working_host(): self.l3agents.insert(0, agent_info_dict) + self.add_agent(agent['id']) elif agent['alive'] and agent['admin_state_up']: self.l3agents.append(agent_info_dict) - self.add_agent(agent['id']) + self.add_agent(agent['id']) return len(self.l3agents)