Merge "Neutron Router Rebalancing Unit Test Improvements"

This commit is contained in:
Zuul 2019-03-26 18:46:40 +00:00 committed by Gerrit Code Review
commit 4b99e115f0
3 changed files with 879 additions and 298 deletions

View File

@ -20,7 +20,8 @@ def fake_nfvi_remove_router_from_agent(a, b, c):
pass
@mock.patch('nfv_vim.nfvi.nfvi_remove_router_from_agent', fake_nfvi_remove_router_from_agent)
@mock.patch('nfv_vim.nfvi.nfvi_remove_router_from_agent',
fake_nfvi_remove_router_from_agent)
class TestNeutronRebalance(testcase.NFVTestCase):
def setUp(self):
@ -34,105 +35,155 @@ class TestNeutronRebalance(testcase.NFVTestCase):
_L3Rebalance.router_diff_threshold = 1
# Down agent will be first agent in list.
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet3'],
'host': u'compute-0',
'id': u'00000000-3de6-4717-93d4-0f23c38d2bf2',
'host_uuid': u'eb2eca67-1018-4c84-9b2c-b9c2662c41a6'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-2',
'id': u'22222222-5a5f-4c58-9399-12d0b8e7e321',
'host_uuid': u'021f35d2-4a98-41ab-87c5-2660cecd501d'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-1',
'id': u'11111111-562c-438c-8083-0733ebbbe881',
'host_uuid': u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-3',
'id': u'33333333-8989-438c-7083-344322513677',
'host_uuid': u'23423524-8b11-4ba8-8ef1-2346625326eb'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-5',
'id': u'55555555-930c-438c-6083-173472902843',
'host_uuid': u'09132345-7b11-4ca7-8ef1-3a5423c17ecd'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-4',
'id': u'44444444-0074-438c-5083-023486659382',
'host_uuid': u'89891234-3b11-9da8-8ef1-aaa4a3a17aea'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet3'],
'host': u'compute-0',
'id': u'00000000-3de6-4717-93d4-0f23c38d2bf2',
'host_uuid': u'eb2eca67-1018-4c84-9b2c-b9c2662c41a6'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-2',
'id': u'22222222-5a5f-4c58-9399-12d0b8e7e321',
'host_uuid': u'021f35d2-4a98-41ab-87c5-2660cecd501d'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-1',
'id': u'11111111-562c-438c-8083-0733ebbbe881',
'host_uuid': u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-3',
'id': u'33333333-8989-438c-7083-344322513677',
'host_uuid': u'23423524-8b11-4ba8-8ef1-2346625326eb'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-5',
'id': u'55555555-930c-438c-6083-173472902843',
'host_uuid': u'09132345-7b11-4ca7-8ef1-3a5423c17ecd'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-4',
'id': u'44444444-0074-438c-5083-023486659382',
'host_uuid': u'89891234-3b11-9da8-8ef1-aaa4a3a17aea'})
# compute-0 routers
agent_id = u'00000000-3de6-4717-93d4-0f23c38d2bf2'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'415302d1-829c-42ec-aab5-a5b592de5c41')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'fb6c7812-5aa6-4303-a8e8-654d2c61c107')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'71205e20-d42f-46d0-ad6b-dd325f9b959b')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'43223570-ab32-25d0-ae6c-352aaab23532')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'45692991-e52f-96c0-bd6d-ed428f9a969b')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'97867e20-a92e-1610-a161-1d121f1b151b')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'415302d1-829c-42ec-aab5-a5b592de5c41')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'fb6c7812-5aa6-4303-a8e8-654d2c61c107')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'71205e20-d42f-46d0-ad6b-dd325f9b959b')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'43223570-ab32-25d0-ae6c-352aaab23532')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'45692991-e52f-96c0-bd6d-ed428f9a969b')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'97867e20-a92e-1610-a161-1d121f1b151b')
# compute-2 routers
agent_id = u'22222222-5a5f-4c58-9399-12d0b8e7e321'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'7c0909c6-c03f-4c14-9d05-e910ab5eb255')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'0c59b77a-b316-4963-90e5-bf689568ac58')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'23423422-3433-fdfd-2222-fdsdfsasvccd')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'11432542-aabb-3415-4443-xcvlkweroidd')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'7c0909c6-c03f-4c14-9d05-e910ab5eb255')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'0c59b77a-b316-4963-90e5-bf689568ac58')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'23423422-3433-fdfd-2222-fdsdfsasvccd')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'11432542-aabb-3415-4443-xcvlkweroidd')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw')
# compute-1 routers
agent_id = u'11111111-562c-438c-8083-0733ebbbe881'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'5054adb8-aef5-445d-b335-fc4bb3ee0871')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'91f20f34-ad68-4483-9ae7-8f917a1460d8')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'23093482-bd68-4c83-cae9-9287467ababa')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'5054adb8-aef5-445d-b335-fc4bb3ee0871')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'91f20f34-ad68-4483-9ae7-8f917a1460d8')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'23093482-bd68-4c83-cae9-9287467ababa')
# compute-3 routers
agent_id = u'33333333-8989-438c-7083-344322513677'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'51019325-a1d4-410f-a83d-9eb54743dcf0')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'c1c8c935-6302-4c5d-98ee-c12bbd900abf')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'51019325-a1d4-410f-a83d-9eb54743dcf0')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'c1c8c935-6302-4c5d-98ee-c12bbd900abf')
# compute-5 routers
agent_id = u'55555555-930c-438c-6083-173472902843'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'2e50468a-755a-4bfb-bc29-f7aadc66c598')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'2e50468a-755a-4bfb-bc29-f7aadc66c598')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef')
# compute-4 routers
agent_id = u'44444444-0074-438c-5083-023486659382'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'4c0213e7-4b36-439b-9e47-d5509e0950f1')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'021f35d2-4a98-41ab-87c5-2660cecd501d')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'4c0213e7-4b36-439b-9e47-d5509e0950f1')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'021f35d2-4a98-41ab-87c5-2660cecd501d')
_L3Rebalance.networks_per_router[u'415302d1-829c-42ec-aab5-a5b592de5c41'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'fb6c7812-5aa6-4303-a8e8-654d2c61c107'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'71205e20-d42f-46d0-ad6b-dd325f9b959b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'43223570-ab32-25d0-ae6c-352aaab23532'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'45692991-e52f-96c0-bd6d-ed428f9a969b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'97867e20-a92e-1610-a161-1d121f1b151b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'415302d1-829c-42ec-aab5-a5b592de5c41'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'fb6c7812-5aa6-4303-a8e8-654d2c61c107'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'71205e20-d42f-46d0-ad6b-dd325f9b959b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'43223570-ab32-25d0-ae6c-352aaab23532'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'45692991-e52f-96c0-bd6d-ed428f9a969b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'97867e20-a92e-1610-a161-1d121f1b151b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'7c0909c6-c03f-4c14-9d05-e910ab5eb255'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'0c59b77a-b316-4963-90e5-bf689568ac58'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'23423422-3433-fdfd-2222-fdsdfsasvccd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'11432542-aabb-3415-4443-xcvlkweroidd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'7c0909c6-c03f-4c14-9d05-e910ab5eb255'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'0c59b77a-b316-4963-90e5-bf689568ac58'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'23423422-3433-fdfd-2222-fdsdfsasvccd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'11432542-aabb-3415-4443-xcvlkweroidd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'5054adb8-aef5-445d-b335-fc4bb3ee0871'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'91f20f34-ad68-4483-9ae7-8f917a1460d8'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'23093482-bd68-4c83-cae9-9287467ababa'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'5054adb8-aef5-445d-b335-fc4bb3ee0871'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'91f20f34-ad68-4483-9ae7-8f917a1460d8'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'23093482-bd68-4c83-cae9-9287467ababa'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'51019325-a1d4-410f-a83d-9eb54743dcf0'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'c1c8c935-6302-4c5d-98ee-c12bbd900abf'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'51019325-a1d4-410f-a83d-9eb54743dcf0'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'c1c8c935-6302-4c5d-98ee-c12bbd900abf'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'2e50468a-755a-4bfb-bc29-f7aadc66c598'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'2e50468a-755a-4bfb-bc29-f7aadc66c598'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'4c0213e7-4b36-439b-9e47-d5509e0950f1'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'021f35d2-4a98-41ab-87c5-2660cecd501d'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'4c0213e7-4b36-439b-9e47-d5509e0950f1'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'021f35d2-4a98-41ab-87c5-2660cecd501d'] = ['physnet0', 'physnet1']
_L3Rebalance.state_machine_in_progress = False
_L3Rebalance.l3agent_idx = 0
@ -144,14 +195,17 @@ class TestNeutronRebalance(testcase.NFVTestCase):
_L3Rebalance.set_state(L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT)
_L3Rebalance.working_host = 'compute-0'
while (_L3Rebalance.get_state() == L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT):
while (_L3Rebalance.get_state() ==
L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT):
_reschedule_down_agent()
# Only agents that can host physnet3 are 3 and 5, expect routers from agent 0
# to be evenly spread over the two of them.
# Only agents that can host physnet3 are 3 and 5, expect routers
# from agent 0 to be evenly spread over the two of them.
if DEBUG_PRINTING:
print("_L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
print("_L3Rebalance.router_ids_per_agent= %s" % _L3Rebalance.router_ids_per_agent)
print("_L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
print("_L3Rebalance.router_ids_per_agent= %s" %
_L3Rebalance.router_ids_per_agent)
assert _L3Rebalance.num_routers_on_agents[0] == 0
assert _L3Rebalance.num_routers_on_agents[1] == 6
@ -164,99 +218,145 @@ class TestNeutronRebalance(testcase.NFVTestCase):
_L3Rebalance.reinit()
_L3Rebalance.router_diff_threshold = 1
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet3'],
'host': u'compute-0',
'id': u'00000000-3de6-4717-93d4-0f23c38d2bf2',
'host_uuid': u'eb2eca67-1018-4c84-9b2c-b9c2662c41a6'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-2',
'id': u'22222222-5a5f-4c58-9399-12d0b8e7e321',
'host_uuid': u'021f35d2-4a98-41ab-87c5-2660cecd501d'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-1',
'id': u'11111111-562c-438c-8083-0733ebbbe881',
'host_uuid': u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-3',
'id': u'33333333-8989-438c-7083-344322513677',
'host_uuid': u'23423524-8b11-4ba8-8ef1-2346625326eb'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-5',
'id': u'55555555-930c-438c-6083-173472902843',
'host_uuid': u'09132345-7b11-4ca7-8ef1-3a5423c17ecd'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-4',
'id': u'44444444-0074-438c-5083-023486659382',
'host_uuid': u'89891234-3b11-9da8-8ef1-aaa4a3a17aea'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet3'],
'host': u'compute-0',
'id': u'00000000-3de6-4717-93d4-0f23c38d2bf2',
'host_uuid': u'eb2eca67-1018-4c84-9b2c-b9c2662c41a6'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-2',
'id': u'22222222-5a5f-4c58-9399-12d0b8e7e321',
'host_uuid': u'021f35d2-4a98-41ab-87c5-2660cecd501d'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-1',
'id': u'11111111-562c-438c-8083-0733ebbbe881',
'host_uuid': u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-3',
'id': u'33333333-8989-438c-7083-344322513677',
'host_uuid': u'23423524-8b11-4ba8-8ef1-2346625326eb'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-5',
'id': u'55555555-930c-438c-6083-173472902843',
'host_uuid': u'09132345-7b11-4ca7-8ef1-3a5423c17ecd'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1', u'physnet3'],
'host': u'compute-4',
'id': u'44444444-0074-438c-5083-023486659382',
'host_uuid': u'89891234-3b11-9da8-8ef1-aaa4a3a17aea'})
# compute-0 routers
agent_id = u'00000000-3de6-4717-93d4-0f23c38d2bf2'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'415302d1-829c-42ec-aab5-a5b592de5c41')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'fb6c7812-5aa6-4303-a8e8-654d2c61c107')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'71205e20-d42f-46d0-ad6b-dd325f9b959b')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'43223570-ab32-25d0-ae6c-352aaab23532')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'45692991-e52f-96c0-bd6d-ed428f9a969b')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'97867e20-a92e-1610-a161-1d121f1b151b')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'415302d1-829c-42ec-aab5-a5b592de5c41')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'fb6c7812-5aa6-4303-a8e8-654d2c61c107')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'71205e20-d42f-46d0-ad6b-dd325f9b959b')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'43223570-ab32-25d0-ae6c-352aaab23532')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'45692991-e52f-96c0-bd6d-ed428f9a969b')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'97867e20-a92e-1610-a161-1d121f1b151b')
# compute-2 routers
agent_id = u'22222222-5a5f-4c58-9399-12d0b8e7e321'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'7c0909c6-c03f-4c14-9d05-e910ab5eb255')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'0c59b77a-b316-4963-90e5-bf689568ac58')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'23423422-3433-fdfd-2222-fdsdfsasvccd')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'11432542-aabb-3415-4443-xcvlkweroidd')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'7c0909c6-c03f-4c14-9d05-e910ab5eb255')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'0c59b77a-b316-4963-90e5-bf689568ac58')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'23423422-3433-fdfd-2222-fdsdfsasvccd')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'11432542-aabb-3415-4443-xcvlkweroidd')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw')
# compute-1 routers
agent_id = u'11111111-562c-438c-8083-0733ebbbe881'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'5054adb8-aef5-445d-b335-fc4bb3ee0871')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'91f20f34-ad68-4483-9ae7-8f917a1460d8')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'23093482-bd68-4c83-cae9-9287467ababa')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'5054adb8-aef5-445d-b335-fc4bb3ee0871')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'91f20f34-ad68-4483-9ae7-8f917a1460d8')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'23093482-bd68-4c83-cae9-9287467ababa')
# compute-3 routers
agent_id = u'33333333-8989-438c-7083-344322513677'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'51019325-a1d4-410f-a83d-9eb54743dcf0')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'c1c8c935-6302-4c5d-98ee-c12bbd900abf')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'51019325-a1d4-410f-a83d-9eb54743dcf0')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'c1c8c935-6302-4c5d-98ee-c12bbd900abf')
# compute-5 routers
agent_id = u'55555555-930c-438c-6083-173472902843'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.router_ids_per_agent[agent_id].append(u'4c0213e7-4b36-439b-9e47-d5509e0950f1')
_L3Rebalance.router_ids_per_agent[agent_id].append(u'021f35d2-4a98-41ab-87c5-2660cecd501d')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'4c0213e7-4b36-439b-9e47-d5509e0950f1')
_L3Rebalance.router_ids_per_agent[agent_id].append(
u'021f35d2-4a98-41ab-87c5-2660cecd501d')
# compute-4 routers
agent_id = u'44444444-0074-438c-5083-023486659382'
_L3Rebalance.router_ids_per_agent[agent_id] = list()
_L3Rebalance.networks_per_router[u'415302d1-829c-42ec-aab5-a5b592de5c41'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'fb6c7812-5aa6-4303-a8e8-654d2c61c107'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'71205e20-d42f-46d0-ad6b-dd325f9b959b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'43223570-ab32-25d0-ae6c-352aaab23532'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'45692991-e52f-96c0-bd6d-ed428f9a969b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'97867e20-a92e-1610-a161-1d121f1b151b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'415302d1-829c-42ec-aab5-a5b592de5c41'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'fb6c7812-5aa6-4303-a8e8-654d2c61c107'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'f900c5a3-a8f2-4348-a63f-ed0b9d2ca2b1'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'71205e20-d42f-46d0-ad6b-dd325f9b959b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'43223570-ab32-25d0-ae6c-352aaab23532'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'45692991-e52f-96c0-bd6d-ed428f9a969b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[
u'97867e20-a92e-1610-a161-1d121f1b151b'] = ['physnet0', 'physnet3']
_L3Rebalance.networks_per_router[u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'7c0909c6-c03f-4c14-9d05-e910ab5eb255'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'0c59b77a-b316-4963-90e5-bf689568ac58'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'23423422-3433-fdfd-2222-fdsdfsasvccd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'11432542-aabb-3415-4443-xcvlkweroidd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'a913c4a3-4d6b-4a4d-9cf5-f8b7c30224a4'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'7c0909c6-c03f-4c14-9d05-e910ab5eb255'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'0c59b77a-b316-4963-90e5-bf689568ac58'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'23423422-3433-fdfd-2222-fdsdfsasvccd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'11432542-aabb-3415-4443-xcvlkweroidd'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'sd093kds-b2dd-eb3d-23bs-asdwebesdedw'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'5054adb8-aef5-445d-b335-fc4bb3ee0871'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'91f20f34-ad68-4483-9ae7-8f917a1460d8'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'23093482-bd68-4c83-cae9-9287467ababa'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'5054adb8-aef5-445d-b335-fc4bb3ee0871'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'91f20f34-ad68-4483-9ae7-8f917a1460d8'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'23093482-bd68-4c83-cae9-9287467ababa'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'51019325-a1d4-410f-a83d-9eb54743dcf0'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'c1c8c935-6302-4c5d-98ee-c12bbd900abf'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'51019325-a1d4-410f-a83d-9eb54743dcf0'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'c1c8c935-6302-4c5d-98ee-c12bbd900abf'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'4c0213e7-4b36-439b-9e47-d5509e0950f1'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[u'021f35d2-4a98-41ab-87c5-2660cecd501d'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'4c0213e7-4b36-439b-9e47-d5509e0950f1'] = ['physnet0', 'physnet1']
_L3Rebalance.networks_per_router[
u'021f35d2-4a98-41ab-87c5-2660cecd501d'] = ['physnet0', 'physnet1']
_L3Rebalance.state_machine_in_progress = False
_L3Rebalance.l3agent_idx = 0
@ -268,14 +368,17 @@ class TestNeutronRebalance(testcase.NFVTestCase):
_L3Rebalance.set_state(L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT)
_L3Rebalance.working_host = None
while (_L3Rebalance.get_state() == L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT):
while (_L3Rebalance.get_state() ==
L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT):
_reschedule_new_agent()
# Only agents that can host physnet3 are 3 and 5, expect routers from agent 0
# to be evenly spread over the two of them.
# Only agents that can host physnet3 are 3 and 5, expect routers
# from agent 0 to be evenly spread over the two of them.
if DEBUG_PRINTING:
print("_L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
print("_L3Rebalance.router_ids_per_agent= %s" % _L3Rebalance.router_ids_per_agent)
print("_L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
print("_L3Rebalance.router_ids_per_agent= %s" %
_L3Rebalance.router_ids_per_agent)
assert _L3Rebalance.num_routers_on_agents[0] == 4
assert _L3Rebalance.num_routers_on_agents[1] == 4
@ -287,34 +390,41 @@ class TestNeutronRebalance(testcase.NFVTestCase):
def run_rebalance(self, num_agents_list, network_name_extra, host_name):
_L3Rebalance.reinit()
_L3Rebalance.l3agents.append({'datanets': ['physnet0', 'physnet1'],
'host': u'compute-0',
'id': 'agentid-compute-0',
'host_uuid': u'eb2eca67-1018-4c84-9b2c-b9c2662c41a6'})
_L3Rebalance.l3agents.append({'datanets': ['physnet0', 'physnet1'],
'host': u'compute-1',
'id': 'agentid-compute-1',
'host_uuid': u'021f35d2-4a98-41ab-87c5-2660cecd501d'})
_L3Rebalance.l3agents.append({'datanets': ['physnet0', 'physnet1'],
'host': u'compute-2',
'id': 'agentid-compute-2',
'host_uuid': u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'})
_L3Rebalance.l3agents.append({'datanets': ['physnet0', 'physnet1', network_name_extra],
'host': u'compute-3',
'id': 'agentid-compute-3',
'host_uuid': u'23423524-8b11-4ba8-8ef1-2346625326eb'})
_L3Rebalance.l3agents.append({'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-4',
'id': 'agentid-compute-4',
'host_uuid': u'09132345-7b11-4ca7-8ef1-3a5423c17ecd'})
_L3Rebalance.l3agents.append({'datanets': ['physnet0', 'physnet1', network_name_extra],
'host': u'compute-5',
'id': 'agentid-compute-5',
'host_uuid': u'89891234-3b11-9da8-8ef1-aaa4a3a17aea'})
_L3Rebalance.l3agents.append({'datanets': ['physnet0', 'physnet1', network_name_extra],
'host': u'compute-6',
'id': 'agentid-compute-6',
'host_uuid': u'bbbaaac4-3b21-87a8-65f1-6a3422a11aba'})
_L3Rebalance.l3agents.append(
{'datanets': ['physnet0', 'physnet1'],
'host': u'compute-0',
'id': 'agentid-compute-0',
'host_uuid': u'eb2eca67-1018-4c84-9b2c-b9c2662c41a6'})
_L3Rebalance.l3agents.append(
{'datanets': ['physnet0', 'physnet1'],
'host': u'compute-1',
'id': 'agentid-compute-1',
'host_uuid': u'021f35d2-4a98-41ab-87c5-2660cecd501d'})
_L3Rebalance.l3agents.append(
{'datanets': ['physnet0', 'physnet1'],
'host': u'compute-2',
'id': 'agentid-compute-2',
'host_uuid': u'7ebc0819-2b11-4aa8-8ef1-3a5423c17eef'})
_L3Rebalance.l3agents.append(
{'datanets': ['physnet0', 'physnet1', network_name_extra],
'host': u'compute-3',
'id': 'agentid-compute-3',
'host_uuid': u'23423524-8b11-4ba8-8ef1-2346625326eb'})
_L3Rebalance.l3agents.append(
{'datanets': [u'physnet0', u'physnet1'],
'host': u'compute-4',
'id': 'agentid-compute-4',
'host_uuid': u'09132345-7b11-4ca7-8ef1-3a5423c17ecd'})
_L3Rebalance.l3agents.append(
{'datanets': ['physnet0', 'physnet1', network_name_extra],
'host': u'compute-5',
'id': 'agentid-compute-5',
'host_uuid': u'89891234-3b11-9da8-8ef1-aaa4a3a17aea'})
_L3Rebalance.l3agents.append(
{'datanets': ['physnet0', 'physnet1', network_name_extra],
'host': u'compute-6',
'id': 'agentid-compute-6',
'host_uuid': u'bbbaaac4-3b21-87a8-65f1-6a3422a11aba'})
# compute-0 routers
agent_id = 'agentid-compute-0'
@ -322,8 +432,10 @@ class TestNeutronRebalance(testcase.NFVTestCase):
num_routers = num_agents_list[0]
_L3Rebalance.num_routers_on_agents.append(num_routers)
for router in range(0, num_routers):
_L3Rebalance.router_ids_per_agent[agent_id].append(agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = ['physnet0', 'physnet1']
_L3Rebalance.router_ids_per_agent[agent_id].append(
agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = \
['physnet0', 'physnet1']
# compute-1 routers
agent_id = 'agentid-compute-1'
@ -331,8 +443,10 @@ class TestNeutronRebalance(testcase.NFVTestCase):
num_routers = num_agents_list[1]
_L3Rebalance.num_routers_on_agents.append(num_routers)
for router in range(0, num_routers):
_L3Rebalance.router_ids_per_agent[agent_id].append(agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = ['physnet0', 'physnet1']
_L3Rebalance.router_ids_per_agent[agent_id].append(
agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = \
['physnet0', 'physnet1']
# compute-2 routers
agent_id = 'agentid-compute-2'
@ -340,8 +454,10 @@ class TestNeutronRebalance(testcase.NFVTestCase):
num_routers = num_agents_list[2]
_L3Rebalance.num_routers_on_agents.append(num_routers)
for router in range(0, num_routers):
_L3Rebalance.router_ids_per_agent[agent_id].append(agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = ['physnet0', 'physnet1']
_L3Rebalance.router_ids_per_agent[agent_id].append(
agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = \
['physnet0', 'physnet1']
# compute-3 routers
agent_id = 'agentid-compute-3'
@ -349,8 +465,10 @@ class TestNeutronRebalance(testcase.NFVTestCase):
num_routers = num_agents_list[3]
_L3Rebalance.num_routers_on_agents.append(num_routers)
for router in range(0, num_routers):
_L3Rebalance.router_ids_per_agent[agent_id].append(agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = ['physnet0', network_name_extra]
_L3Rebalance.router_ids_per_agent[agent_id].append(
agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = \
['physnet0', network_name_extra]
# compute-4 routers
agent_id = 'agentid-compute-4'
@ -358,8 +476,10 @@ class TestNeutronRebalance(testcase.NFVTestCase):
num_routers = num_agents_list[4]
_L3Rebalance.num_routers_on_agents.append(num_routers)
for router in range(0, num_routers):
_L3Rebalance.router_ids_per_agent[agent_id].append(agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = ['physnet0', 'physnet1']
_L3Rebalance.router_ids_per_agent[agent_id].append(
agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = \
['physnet0', 'physnet1']
# compute-5 routers
agent_id = 'agentid-compute-5'
@ -367,8 +487,10 @@ class TestNeutronRebalance(testcase.NFVTestCase):
num_routers = num_agents_list[5]
_L3Rebalance.num_routers_on_agents.append(num_routers)
for router in range(0, num_routers):
_L3Rebalance.router_ids_per_agent[agent_id].append(agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = ['physnet0', 'physnet1', network_name_extra]
_L3Rebalance.router_ids_per_agent[agent_id].append(
agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = \
['physnet0', 'physnet1', network_name_extra]
# compute-6 routers
agent_id = 'agentid-compute-6'
@ -376,8 +498,10 @@ class TestNeutronRebalance(testcase.NFVTestCase):
num_routers = num_agents_list[6]
_L3Rebalance.num_routers_on_agents.append(num_routers)
for router in range(0, num_routers):
_L3Rebalance.router_ids_per_agent[agent_id].append(agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = ['physnet0', 'physnet1', network_name_extra]
_L3Rebalance.router_ids_per_agent[agent_id].append(
agent_id + '-' + str(router))
_L3Rebalance.networks_per_router[agent_id + '-' + str(router)] = \
['physnet0', 'physnet1', network_name_extra]
_L3Rebalance.state_machine_in_progress = False
_L3Rebalance.num_l3agents = len(num_agents_list)
@ -385,11 +509,13 @@ class TestNeutronRebalance(testcase.NFVTestCase):
_L3Rebalance.working_host = host_name
if host_name is not None:
_L3Rebalance.set_state(L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT)
while (_L3Rebalance.get_state() == L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT):
while (_L3Rebalance.get_state() ==
L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT):
_reschedule_down_agent()
else:
_L3Rebalance.set_state(L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT)
while (_L3Rebalance.get_state() == L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT):
while (_L3Rebalance.get_state() ==
L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT):
_reschedule_new_agent()
def rebalance(self, host_name=None):
@ -397,7 +523,8 @@ class TestNeutronRebalance(testcase.NFVTestCase):
# among supported.
num_agents_in = [97, 67, 78, 145, 21, 108, 35]
if DEBUG_PRINTING:
print("host_name = %s, num_agents_in = %s" % (host_name, num_agents_in))
print("host_name = %s, num_agents_in = %s" %
(host_name, num_agents_in))
self.run_rebalance(num_agents_in, 'physnet3', host_name)
assert sum(num_agents_in) == sum(_L3Rebalance.num_routers_on_agents)
@ -414,51 +541,64 @@ class TestNeutronRebalance(testcase.NFVTestCase):
# TODO(kevin), make sure each router is only present once.
if DEBUG_PRINTING:
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
del num_agents_in[:]
num_agents_in = [5, 20, 31, 32, 44, 0, 0]
if DEBUG_PRINTING:
print("host_name = %s, num_agents_in = %s" % (host_name, num_agents_in))
print("host_name = %s, num_agents_in = %s" %
(host_name, num_agents_in))
self.run_rebalance(num_agents_in, 'physnet3', host_name)
assert sum(num_agents_in) == sum(_L3Rebalance.num_routers_on_agents)
if DEBUG_PRINTING:
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" % _L3Rebalance.router_ids_per_agent)
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" %
# _L3Rebalance.router_ids_per_agent)
del num_agents_in[:]
num_agents_in = [0, 11, 31, 11, 44, 0, 25]
if DEBUG_PRINTING:
print("host_name = %s, num_agents_in = %s" % (host_name, num_agents_in))
print("host_name = %s, num_agents_in = %s" %
(host_name, num_agents_in))
self.run_rebalance(num_agents_in, 'physnet2', host_name)
assert sum(num_agents_in) == sum(_L3Rebalance.num_routers_on_agents)
if DEBUG_PRINTING:
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" % _L3Rebalance.router_ids_per_agent)
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" %
# _L3Rebalance.router_ids_per_agent)
del num_agents_in[:]
num_agents_in = [5, 3, 55, 32, 210, 35, 105]
if DEBUG_PRINTING:
print("host_name = %s, num_agents_in = %s" % (host_name, num_agents_in))
print("host_name = %s, num_agents_in = %s" %
(host_name, num_agents_in))
self.run_rebalance(num_agents_in, 'physnet3', host_name)
assert sum(num_agents_in) == sum(_L3Rebalance.num_routers_on_agents)
if DEBUG_PRINTING:
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" % _L3Rebalance.router_ids_per_agent)
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" %
# _L3Rebalance.router_ids_per_agent)
del num_agents_in[:]
num_agents_in = [0, 0, 5, 0, 0, 0, 0]
if DEBUG_PRINTING:
print("host_name = %s, num_agents_in = %s" % (host_name, num_agents_in))
print("host_name = %s, num_agents_in = %s" %
(host_name, num_agents_in))
self.run_rebalance(num_agents_in, 'physnet2', host_name)
assert sum(num_agents_in) == sum(_L3Rebalance.num_routers_on_agents)
if DEBUG_PRINTING:
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" % _L3Rebalance.router_ids_per_agent)
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" %
# _L3Rebalance.router_ids_per_agent)
for test in range(0, 50):
del num_agents_in[:]
@ -470,11 +610,14 @@ class TestNeutronRebalance(testcase.NFVTestCase):
random.randint(0, 150),
random.randint(0, 150)]
if DEBUG_PRINTING:
print("host_name = %s, num_agents_in = %s" % (host_name, num_agents_in))
print("host_name = %s, num_agents_in = %s" %
(host_name, num_agents_in))
self.run_rebalance(num_agents_in, 'physnet1', host_name)
assert sum(num_agents_in) == sum(_L3Rebalance.num_routers_on_agents)
assert (sum(num_agents_in) ==
sum(_L3Rebalance.num_routers_on_agents))
if DEBUG_PRINTING:
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
for test in range(0, 50):
del num_agents_in[:]
@ -486,12 +629,16 @@ class TestNeutronRebalance(testcase.NFVTestCase):
random.randint(0, 150),
random.randint(0, 150)]
if DEBUG_PRINTING:
print("host_name = %s, num_agents_in = %s" % (host_name, num_agents_in))
print("host_name = %s, num_agents_in = %s" %
(host_name, num_agents_in))
self.run_rebalance(num_agents_in, 'physnet3', host_name)
assert sum(num_agents_in) == sum(_L3Rebalance.num_routers_on_agents)
assert (sum(num_agents_in) ==
sum(_L3Rebalance.num_routers_on_agents))
if DEBUG_PRINTING:
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" % _L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" % _L3Rebalance.router_ids_per_agent)
print("Test 2 _L3Rebalance.num_routers_on_agents= %s" %
_L3Rebalance.num_routers_on_agents)
# print("Test 2 _L3Rebalance.router_ids_per_agent= %s" %
# _L3Rebalance.router_ids_per_agent)
def test_rebalance_new_host(self):
_L3Rebalance.router_diff_threshold = 1

View File

@ -0,0 +1,363 @@
#
# Copyright (c) 2015-2016 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import mock
import random
from nfv_vim.network_rebalance._network_rebalance import _add_router_to_agent_callback_body # noqa: H501
from nfv_vim.network_rebalance._network_rebalance import _get_agent_routers_callback_body # noqa: H501
from nfv_vim.network_rebalance._network_rebalance import _get_datanetworks_callback_body # noqa: H501
from nfv_vim.network_rebalance._network_rebalance import _get_network_agents_callback_body # noqa: H501
from nfv_vim.network_rebalance._network_rebalance import _get_physical_network_callback_body # noqa: H501
from nfv_vim.network_rebalance._network_rebalance import _get_router_ports_callback_body # noqa: H501
from nfv_vim.network_rebalance._network_rebalance import _L3Rebalance
from nfv_vim.network_rebalance._network_rebalance import _remove_router_from_agent_callback_body # noqa: H501
from nfv_vim.network_rebalance._network_rebalance import _run_state_machine
from nfv_vim.network_rebalance._network_rebalance import add_rebalance_work
from nfv_vim.network_rebalance._network_rebalance import L3_REBALANCE_STATE
from . import testcase # noqa: H304
DEBUG_PRINTING = False
_fake_host_table = dict()
class _fake_host(object):
def __init__(self, uuid):
self.uuid = uuid
NUM_AGENTS = 0
MAX_AGENTS = 20
MAX_ROUTERS = 50
MAX_PORTS = 10
MAX_NETWORKS = 2
MAX_LOOPCOUNT = 2 * MAX_AGENTS * MAX_ROUTERS * MAX_PORTS * MAX_NETWORKS
def build_get_agents_response():
get_agents_response = dict()
get_agents_response['completed'] = True
get_agents_response['reason'] = ''
get_agents_response['result-data'] = list()
NUM_AGENTS = random.randint(0, MAX_AGENTS - 1)
for x in range(0, NUM_AGENTS):
host_name = "compute-" + str(x)
get_agents_response_entry = \
{"host": host_name, "agent_type": "L3 agent",
"id": host_name + "_id", "alive": True,
"admin_state_up": True}
get_agents_response['result-data'].append(get_agents_response_entry)
add_to_fake_host_table(host_name)
return get_agents_response
def build_get_agent_routers_response(agent_id):
get_agent_routers_response = dict()
get_agent_routers_response['completed'] = True
get_agent_routers_response['reason'] = ''
get_agent_routers_response['result-data'] = list()
for x in range(0, random.randint(0, MAX_ROUTERS - 1)):
host_name = "compute-" + str(x)
get_agent_routers_response_entry = \
{"id": agent_id + "_router_" + str(x)}
get_agent_routers_response['result-data'].append(
get_agent_routers_response_entry)
return get_agent_routers_response
def build_get_router_ports_response(router):
get_router_ports_response = dict()
get_router_ports_response['completed'] = True
get_router_ports_response['reason'] = ''
get_router_ports_response['result-data'] = dict()
get_router_ports_response['result-data']['ports'] = list()
for x in range(0, random.randint(1, MAX_PORTS - 1)):
get_router_ports_response_entry = \
{"network_id": router + "_netid" + str(x)}
get_router_ports_response['result-data']['ports'].append(
get_router_ports_response_entry)
return get_router_ports_response
def build_get_physical_network_response(network_id):
get_physical_network_response = dict()
get_physical_network_response['completed'] = True
get_physical_network_response['reason'] = ''
network = random.randint(0, MAX_NETWORKS - 1)
if network == 0:
get_physical_network_response['result-data'] = \
{u'provider:physical_network': u'physnet0'}
else:
get_physical_network_response['result-data'] = \
{u'provider:physical_network': u'physnet1'}
return get_physical_network_response
def build_get_datanetworks_response(host_id):
get_datanetworks_response = dict()
get_datanetworks_response['completed'] = True
get_datanetworks_response['reason'] = ''
get_datanetworks_response['result-data'] = list()
get_datanetworks_response['result-data'].append(
{u'datanetwork_name': u'physnet0'})
get_datanetworks_response['result-data'].append(
{u'datanetwork_name': u'physnet1'})
return get_datanetworks_response
class dlog(object):
def __init__(self):
self.nothing = 0
def verbose(self, string):
if DEBUG_PRINTING:
print("Verbose: " + string)
else:
pass
def info(self, string):
if DEBUG_PRINTING:
print("Info: " + string)
else:
pass
def warn(self, string):
print("Warn: " + string)
def error(self, string):
print("Error: " + string)
def debug(self, string):
if DEBUG_PRINTING:
print("Debug: " + string)
else:
pass
dlog_local = dlog()
def fake_nfvi_get_network_agents(a):
response = build_get_agents_response()
if DEBUG_PRINTING:
print("fake_nfvi_get_network_agents")
print("response = %s" % response)
_get_network_agents_callback_body(response)
def fake_nfvi_get_agent_routers(agent_id, b):
response = build_get_agent_routers_response(agent_id)
if DEBUG_PRINTING:
print("fake_nfvi_get_agent_routers")
print("agent_id = %s" % agent_id)
print("response = %s" % response)
_get_agent_routers_callback_body(agent_id, response)
def fake_nfvi_get_router_ports(router, b):
response = build_get_router_ports_response(router)
if DEBUG_PRINTING:
print("fake_nfvi_get_router_ports")
print("response = %s" % response)
_get_router_ports_callback_body(router, response)
def fake_nfvi_get_physical_network(network_id, b):
response = build_get_physical_network_response(network_id)
if DEBUG_PRINTING:
print("fake_nfvi_get_physical_network")
print("response = %s" % response)
_get_physical_network_callback_body(network_id, response)
def fake_nfvi_get_datanetworks(host_id, b):
response = build_get_datanetworks_response(host_id)
if DEBUG_PRINTING:
print("fake_nfvi_get_datanetworks")
print("response = %s" % response)
_get_datanetworks_callback_body(host_id, response)
def fake_nfvi_remove_router_from_agent(a, b, c):
response = dict()
response['completed'] = True
response['reason'] = ''
if DEBUG_PRINTING:
print("fake_nfvi_remove_router_from_agent")
print("response = %s" % response)
_remove_router_from_agent_callback_body(a, b, response)
def fake_nfvi_add_router_to_agent(a, b, c):
response = dict()
response['completed'] = True
response['reason'] = ''
if DEBUG_PRINTING:
print("fake_nfvi_add_router_to_agent")
print("response = %s" % response)
_add_router_to_agent_callback_body(response)
def fake_tables_get_host_table():
return _fake_host_table
def add_to_fake_host_table(host_name):
_fake_host_table[host_name] = _fake_host(host_name + "_uuid")
@mock.patch('nfv_vim.network_rebalance._network_rebalance.DLOG',
dlog_local)
@mock.patch('nfv_vim.nfvi.nfvi_remove_router_from_agent',
fake_nfvi_remove_router_from_agent)
@mock.patch('nfv_vim.nfvi.nfvi_get_agent_routers',
fake_nfvi_get_agent_routers)
@mock.patch('nfv_vim.nfvi.nfvi_get_network_agents',
fake_nfvi_get_network_agents)
@mock.patch('nfv_vim.nfvi.nfvi_get_router_ports',
fake_nfvi_get_router_ports)
@mock.patch('nfv_vim.nfvi.nfvi_get_physical_network',
fake_nfvi_get_physical_network)
@mock.patch('nfv_vim.nfvi.nfvi_get_datanetworks',
fake_nfvi_get_datanetworks)
@mock.patch('nfv_vim.nfvi.nfvi_remove_router_from_agent',
fake_nfvi_remove_router_from_agent)
@mock.patch('nfv_vim.nfvi.nfvi_add_router_to_agent',
fake_nfvi_add_router_to_agent)
@mock.patch('nfv_vim.tables.tables_get_host_table',
fake_tables_get_host_table)
class TestNeutronRebalance2(testcase.NFVTestCase):
def setUp(self):
super(TestNeutronRebalance2, self).setUp()
def tearDown(self):
super(TestNeutronRebalance2, self).tearDown()
def test_rebalance_down_host_randomized_w_api_calls(self):
initial_router_count = 0
initial_router_config = list()
for x in range(1, 200):
_L3Rebalance.router_diff_threshold = random.randint(1, 4)
add_rebalance_work('compute-0', True)
loopcount = 0
if DEBUG_PRINTING:
print("HOST DOWN TEST NUMBER %s" % str(x))
while True:
loopcount += 1
old_state = _L3Rebalance.get_state()
_run_state_machine()
new_state = _L3Rebalance.get_state()
if ((old_state ==
L3_REBALANCE_STATE.GET_ROUTERS_HOSTED_ON_AGENT) and
(new_state ==
L3_REBALANCE_STATE.GET_ROUTER_PORT_NETWORKS)):
for idx in range(len(_L3Rebalance.num_routers_on_agents)):
initial_router_config.append(
_L3Rebalance.num_routers_on_agents[idx])
initial_router_count = \
sum(_L3Rebalance.num_routers_on_agents)
if (_L3Rebalance.get_state() == L3_REBALANCE_STATE.DONE) and \
(len(_L3Rebalance.host_down_queue) == 0):
final_router_count = \
sum(_L3Rebalance.num_routers_on_agents)
if DEBUG_PRINTING:
print("router_diff_threshold: %s" %
_L3Rebalance.router_diff_threshold)
print("initial_router_count: %s, "
"final_router_count: %s" %
(initial_router_count, final_router_count))
print("initial num_routers_on_agents: %s, "
"final num_routers_on_agents: %s" %
(initial_router_config,
_L3Rebalance.num_routers_on_agents))
del initial_router_config[:]
if len(_L3Rebalance.num_routers_on_agents) > 2:
num_routers_length = \
len(_L3Rebalance.num_routers_on_agents)
assert ((num_routers_length == 0) or
_L3Rebalance.num_routers_on_agents[0] == 0)
assert (initial_router_count == final_router_count)
else:
if DEBUG_PRINTING:
print("less than 2 agents, nothing to do")
break
if loopcount > MAX_LOOPCOUNT:
print("Loopcount exit!!! loopcount:%s" % loopcount)
assert loopcount < MAX_LOOPCOUNT
def test_rebalance_up_host_randomized_w_api_calls(self):
initial_router_count = 0
initial_router_config = list()
for x in range(1, 200):
_L3Rebalance.router_diff_threshold = random.randint(1, 4)
add_rebalance_work('compute-0', False)
loopcount = 0
if DEBUG_PRINTING:
print("HOST UP TEST NUMBER %s" % str(x))
while True:
loopcount += 1
old_state = _L3Rebalance.get_state()
_run_state_machine()
new_state = _L3Rebalance.get_state()
if ((old_state ==
L3_REBALANCE_STATE.GET_ROUTERS_HOSTED_ON_AGENT) and
((new_state ==
L3_REBALANCE_STATE.GET_ROUTER_PORT_NETWORKS) or
(new_state == L3_REBALANCE_STATE.DONE))):
# new_state DONE is for already balanced case
for idx in range(len(_L3Rebalance.num_routers_on_agents)):
initial_router_config.append(
_L3Rebalance.num_routers_on_agents[idx])
initial_router_count = sum(
_L3Rebalance.num_routers_on_agents)
if ((_L3Rebalance.get_state() == L3_REBALANCE_STATE.DONE) and
(len(_L3Rebalance.host_up_queue) == 0)):
final_router_count = sum(
_L3Rebalance.num_routers_on_agents)
if DEBUG_PRINTING:
print("router_diff_threshold: %s" %
_L3Rebalance.router_diff_threshold)
print("initial_router_count: %s, "
"final_router_count: %s" %
(initial_router_count, final_router_count))
print("initial num_routers_on_agents: %s, "
"final num_routers_on_agents: %s" %
(initial_router_config,
_L3Rebalance.num_routers_on_agents))
del initial_router_config[:]
if len(_L3Rebalance.num_routers_on_agents) > 2:
assert (initial_router_count == final_router_count)
assert (max(_L3Rebalance.num_routers_on_agents) -
min(_L3Rebalance.num_routers_on_agents) <=
_L3Rebalance.router_diff_threshold)
else:
if DEBUG_PRINTING:
print("less than 2 agents, nothing to do")
break
if loopcount > MAX_LOOPCOUNT:
print("Loopcount exit!!! loopcount:%s" % loopcount)
assert loopcount < MAX_LOOPCOUNT

View File

@ -328,7 +328,8 @@ class L3AgentRebalance(object):
max_routers = self.num_routers_on_agents[agent_with_most_routers]
if ((max_routers - min_routers) <= _L3Rebalance.router_diff_threshold):
DLOG.debug("max:%s - min:%s <= DIFF, balanced" % (max_routers, min_routers))
DLOG.info("L3 Agent routers balanced, max:%s min:%s threshold:%s" %
(max_routers, min_routers, _L3Rebalance.router_diff_threshold))
return True
return False
@ -438,10 +439,17 @@ def _add_router_to_agent_callback():
"""
Add router to agent callback
"""
global _L3Rebalance
response = (yield)
_add_router_to_agent_callback_body(response)
def _add_router_to_agent_callback_body(response):
"""
Add router to agent callback body
"""
global _L3Rebalance
_L3Rebalance.state_machine_in_progress = False
DLOG.debug("_add_router_to_agent_callback, response = %s" % response)
if not response['completed']:
@ -454,10 +462,17 @@ def _remove_router_from_agent_callback(to_agent_id, router_id):
"""
Remove router from agent callback
"""
global _L3Rebalance
response = (yield)
_remove_router_from_agent_callback_body(to_agent_id, router_id, response)
def _remove_router_from_agent_callback_body(to_agent_id, router_id, response):
"""
Remove router from agent callback body
"""
global _L3Rebalance
DLOG.debug("_remove_router_from_agent_callback , response = %s" % response)
if response['completed']:
# After successfully detaching router from agent, attach
@ -475,10 +490,17 @@ def _get_datanetworks_callback(host_id):
"""
Get data networks callback
"""
global _L3Rebalance
response = (yield)
_get_datanetworks_callback_body(host_id, response)
def _get_datanetworks_callback_body(host_id, response):
"""
Get data networks callback body
"""
global _L3Rebalance
_L3Rebalance.state_machine_in_progress = False
DLOG.debug("_get_datanetworks, response = %s" % response)
if response['completed']:
@ -512,10 +534,17 @@ def _get_physical_network_callback(network_id):
"""
Get Physical Network callback
"""
global _L3Rebalance
response = (yield)
_get_physical_network_callback_body(network_id, response)
def _get_physical_network_callback_body(network_id, response):
"""
Get Physical Network callback body
"""
global _L3Rebalance
_L3Rebalance.state_machine_in_progress = False
DLOG.debug("_get_physical_network_callback, response = %s" % response)
if response['completed']:
@ -550,14 +579,29 @@ def _get_router_ports_callback(router):
Get Router Ports callback. Save the network_id for each port attached
to the router.
"""
global _L3Rebalance
response = (yield)
_get_router_ports_callback_body(router, response)
def _get_router_ports_callback_body(router, response):
"""
Get Router Ports callback body
"""
global _L3Rebalance
_L3Rebalance.state_machine_in_progress = False
DLOG.debug("_get_router_ports_callback, response = %s" % response)
if response['completed']:
result_data = response.get('result-data', None)
if result_data.get('ports', None) is None:
# It is possible that while running the state machine that
# information has become stale due to the user modifying routers.
# Abort if this is the case.
DLOG.warn("No port information for router: %s" % router)
_L3Rebalance.set_state(L3_REBALANCE_STATE.DONE)
return
for port in result_data['ports']:
network_id = port['network_id']
_L3Rebalance.add_network_to_router(router, network_id)
@ -601,10 +645,17 @@ def _get_agent_routers_callback(agent_id):
"""
Get Agent Routers callback
"""
global _L3Rebalance
response = (yield)
_get_agent_routers_callback_body(agent_id, response)
def _get_agent_routers_callback_body(agent_id, response):
"""
Get Agent Routers callback body
"""
global _L3Rebalance
_L3Rebalance.state_machine_in_progress = False
DLOG.debug("_get_agent_routers_callback, response = %s" % response)
if response['completed']:
@ -669,10 +720,17 @@ def _get_network_agents_callback():
"""
Get Network Agents callback
"""
global _L3Rebalance
response = (yield)
_get_network_agents_callback_body(response)
def _get_network_agents_callback_body(response):
"""
Get Network Agents callback body
"""
global _L3Rebalance
_L3Rebalance.state_machine_in_progress = False
DLOG.debug("_get_network_agents_callback, response = %s" % response)
if response['completed']:
@ -682,7 +740,7 @@ def _get_network_agents_callback():
if num_agents < 2:
# no sense doing anything if less than 2 agents
DLOG.debug("Less than 2 l3agents, no rebalancing required")
DLOG.info("Less than 2 l3agents, no rebalancing required")
_L3Rebalance.set_state(L3_REBALANCE_STATE.DONE)
else:
_L3Rebalance.set_state(L3_REBALANCE_STATE.GET_ROUTERS_HOSTED_ON_AGENT)
@ -877,6 +935,84 @@ def _reschedule_new_agent():
_L3Rebalance.set_state(L3_REBALANCE_STATE.DONE)
def _run_state_machine():
global _L3Rebalance
if not _L3Rebalance.state_machine_in_progress:
_L3Rebalance.state_machine_in_progress = True
my_state = _L3Rebalance.get_state()
DLOG.debug("Network Rebalance State %s" % my_state)
if my_state == L3_REBALANCE_STATE.GET_NETWORK_AGENTS:
_L3Rebalance.reinit()
_get_network_agents()
elif my_state == L3_REBALANCE_STATE.GET_ROUTERS_HOSTED_ON_AGENT:
_get_routers_on_agents()
elif my_state == L3_REBALANCE_STATE.GET_ROUTER_PORT_NETWORKS:
_get_router_port_networks()
elif my_state == L3_REBALANCE_STATE.GET_PHYSICAL_NETWORK_FROM_NETWORKS:
_get_physical_networks()
elif my_state == L3_REBALANCE_STATE.GET_HOST_PHYSICAL_NETWORKS:
_get_host_data_networks()
elif my_state == L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT:
_reschedule_down_agent()
elif my_state == L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT:
_reschedule_new_agent()
elif my_state == L3_REBALANCE_STATE.DONE:
_L3Rebalance.state_machine_in_progress = False
# Check for work...
if ((len(_L3Rebalance.host_up_queue) > 0) or
(len(_L3Rebalance.host_down_queue) > 0)):
_L3Rebalance.set_state(L3_REBALANCE_STATE.HOLD_OFF)
elif my_state == L3_REBALANCE_STATE.HOLD_OFF:
_L3Rebalance.state_machine_in_progress = False
if _L3Rebalance.hold_off_is_done():
if len(_L3Rebalance.host_down_queue) > 0:
# A reschedule for every down host is required.
# Do the down hosts rescheduling before handling
# the up hosts, as if both are pending, we don't
# want to move routers to agents that are about to
# go down.
down_host = _L3Rebalance.host_down_queue.pop(0)
_L3Rebalance.set_working_host(down_host)
DLOG.info("Triggering L3 Agent reschedule for "
"disabled l3 agent host: %s" %
down_host)
elif len(_L3Rebalance.host_up_queue) > 0:
# Even if multiple hosts come up, we only need to
# reschedule once
_L3Rebalance.set_working_host(None)
DLOG.info("Triggering L3 Agent reschedule for "
"enabled l3 agent host(s): %s" %
_L3Rebalance.host_up_queue)
del _L3Rebalance.host_up_queue[:]
_L3Rebalance.set_state(L3_REBALANCE_STATE.GET_NETWORK_AGENTS)
else:
DLOG.error("Unknown state: %s, resetting" % my_state)
_L3Rebalance.set_state(L3_REBALANCE_STATE.DONE)
@coroutine
def _nr_timer():
"""
@ -886,80 +1022,7 @@ def _nr_timer():
while True:
(yield)
if not _L3Rebalance.state_machine_in_progress:
_L3Rebalance.state_machine_in_progress = True
my_state = _L3Rebalance.get_state()
DLOG.debug("Network Rebalance State %s" % my_state)
if my_state == L3_REBALANCE_STATE.GET_NETWORK_AGENTS:
_L3Rebalance.reinit()
_get_network_agents()
elif my_state == L3_REBALANCE_STATE.GET_ROUTERS_HOSTED_ON_AGENT:
_get_routers_on_agents()
elif my_state == L3_REBALANCE_STATE.GET_ROUTER_PORT_NETWORKS:
_get_router_port_networks()
elif my_state == L3_REBALANCE_STATE.GET_PHYSICAL_NETWORK_FROM_NETWORKS:
_get_physical_networks()
elif my_state == L3_REBALANCE_STATE.GET_HOST_PHYSICAL_NETWORKS:
_get_host_data_networks()
elif my_state == L3_REBALANCE_STATE.RESCHEDULE_DOWN_AGENT:
_reschedule_down_agent()
elif my_state == L3_REBALANCE_STATE.RESCHEDULE_NEW_AGENT:
_reschedule_new_agent()
elif my_state == L3_REBALANCE_STATE.DONE:
_L3Rebalance.state_machine_in_progress = False
# Check for work...
if ((len(_L3Rebalance.host_up_queue) > 0) or
(len(_L3Rebalance.host_down_queue) > 0)):
_L3Rebalance.set_state(L3_REBALANCE_STATE.HOLD_OFF)
elif my_state == L3_REBALANCE_STATE.HOLD_OFF:
_L3Rebalance.state_machine_in_progress = False
if _L3Rebalance.hold_off_is_done():
if len(_L3Rebalance.host_down_queue) > 0:
# A reschedule for every down host is required.
# Do the down hosts rescheduling before handling
# the up hosts, as if both are pending, we don't
# want to move routers to agents that are about to
# go down.
down_host = _L3Rebalance.host_down_queue.pop(0)
_L3Rebalance.set_working_host(down_host)
DLOG.info("Triggering L3 Agent reschedule for "
"disabled l3 agent host: %s" %
down_host)
elif len(_L3Rebalance.host_up_queue) > 0:
# Even if multiple hosts come up, we only need to
# reschedule once
_L3Rebalance.set_working_host(None)
DLOG.info("Triggering L3 Agent reschedule for "
"enabled l3 agent host(s): %s" %
_L3Rebalance.host_up_queue)
del _L3Rebalance.host_up_queue[:]
_L3Rebalance.set_state(L3_REBALANCE_STATE.GET_NETWORK_AGENTS)
else:
DLOG.error("Unknown state: %s, resetting" % my_state)
_L3Rebalance.set_state(L3_REBALANCE_STATE.DONE)
_run_state_machine()
def nr_initialize():
@ -975,6 +1038,14 @@ def nr_initialize():
_nr_timer_interval = int(section.get('timer_interval', 10))
_L3Rebalance.router_diff_threshold = int(section.get('router_diff_threshold', 3))
_L3Rebalance.hold_off = int(section.get('hold_off', 3))
if _L3Rebalance.router_diff_threshold < 1:
DLOG.warn("Invalid setting for router_diff_threshold: %s, forcing to 1" %
_L3Rebalance.router_diff_threshold)
_L3Rebalance.router_diff_threshold = 1
if _nr_timer_interval < 1:
DLOG.warn("Invalid setting for timer_interval: %s, forcing to 1" %
_nr_timer_interval)
_nr_timer_interval = 1
else:
_nr_timer_interval = 10
_L3Rebalance.router_diff_threshold = 3