Neutron Router Rebalancing Unit Test Improvements

Add REST API calls to the tox unit tests and add fully
randomized tests.  A few small robustness improvements
added as well.

Change-Id: Idaa6bde281989ac3442d3060750ae07f352066c7
Story: 2003857
Task: 30163
Signed-off-by: Kevin Smith <kevin.smith@windriver.com>
This commit is contained in:
Kevin Smith
2019-03-25 09:03:42 -04:00
parent 1b07201fcf
commit 5ffd20a3ab
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