VOL-1233: Change pon resource manager to use blocking KV client library
VOL-1232: PON Resource Manager allocates same alloc id across different pon ports, and is not acceptable by asfvolt16 platform
VOL-1245: When OpenOlt device is delete, there is Unhandled error during the deletion of child brcm_openomci ONUs
Change-Id: I3f939cb12e0456b2014a133968a77fba1c4c6e63
diff --git a/tests/utests/common/test_pon_resource_manager.py b/tests/utests/common/test_pon_resource_manager.py
index 74c4736..6205ee4 100644
--- a/tests/utests/common/test_pon_resource_manager.py
+++ b/tests/utests/common/test_pon_resource_manager.py
@@ -17,10 +17,8 @@
from unittest import TestCase, main
from bitstring import BitArray
-from common.kvstore.kv_client import KVPair
from common.pon_resource_manager.resource_manager import PONResourceManager
from mock import Mock
-from twisted.internet.defer import inlineCallbacks
class TestResourceManager(TestCase):
@@ -29,97 +27,81 @@
'0001c889ee7189fb', 'consul',
'localhost', 8500)
self.default_resource_range = {
- "onu_start_idx": 1,
- "onu_end_idx": 127,
- "alloc_id_start_idx": 1024,
- "alloc_id_end_idx": 65534,
- "gem_port_id_start_idx": 1024,
- "gem_port_id_end_idx": 16383,
- "num_of_pon_port": 16
+ "onu_id_start": 1,
+ "onu_id_end": 127,
+ "alloc_id_start": 1024,
+ "alloc_id_end": 2816,
+ "gemport_id_start": 1024,
+ "gemport_id_end": 8960,
+ "pon_ports": 16
}
def tearDown(self):
self._rm = None
self.default_resource_range = None
- @inlineCallbacks
def test_init_pon_resource_ranges(self):
- key = PONResourceManager.PON_RESOURCE_RANGE_CONFIG_PATH.format(
- 'xgspon', 'default')
- value = json.dumps(self.default_resource_range).encode('utf-8')
- output = KVPair(key, value, None)
- self._rm._kv_store.get = Mock(return_value=(output, None))
+ output = json.dumps(self.default_resource_range).encode('utf-8')
+ self._rm._get_olt_vendor = Mock(return_value='default')
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
- yield self._rm.init_pon_resource_ranges()
+ self._rm.init_resource_ranges_from_kv_store()
self.assertEqual(self._rm.pon_resource_ranges,
self.default_resource_range)
- self._rm._kv_store.get = Mock(return_value=(None, None))
-
- yield self._rm.init_pon_resource_ranges()
+ self._rm.init_default_pon_resource_ranges()
self.assertEqual(self._rm.pon_resource_ranges,
self.default_resource_range)
- @inlineCallbacks
def test_init_resource_id_pool(self):
- self._rm._kv_store.get = Mock(return_value=(None, None))
- self._rm._kv_store.put = Mock(return_value=None)
- status = yield self._rm.init_resource_id_pool(0, 'ONU_ID', 1, 127)
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=None)
+ self._rm._kv_store.update_to_kv_store = Mock(return_value=True)
+ status = self._rm.init_resource_id_pool(0, 'ONU_ID', 1, 127)
self.assertTrue(status)
- status = yield self._rm.init_resource_id_pool(
+ status = self._rm.init_resource_id_pool(
1, 'ALLOC_ID', 1024, 16383)
self.assertTrue(status)
- status = yield self._rm.init_resource_id_pool(
+ status = self._rm.init_resource_id_pool(
2, 'GEMPORT_ID', 1023, 65534)
self.assertTrue(status)
- @inlineCallbacks
def test_get_resource_id(self):
# Get onu id test
onu_id_resource = self._rm._format_resource(0, 1, 127)
- key = self._rm._get_path(0, PONResourceManager.ONU_ID)
- value = onu_id_resource.encode('utf-8')
- output = KVPair(key, value, None)
- self._rm._kv_store.get = Mock(return_value=(output, None))
- self._rm._kv_store.put = Mock(return_value=None)
- result = yield self._rm.get_resource_id(0, 'ONU_ID')
+ output = onu_id_resource.encode('utf-8')
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
+ self._rm._kv_store.update_to_kv_store = Mock(return_value=True)
+ result = self._rm.get_resource_id(0, 'ONU_ID')
self.assertEqual(result, 1)
# Get alloc id test
alloc_id_resource = self._rm._format_resource(1, 1024, 16383)
- key = self._rm._get_path(1, PONResourceManager.ALLOC_ID)
- value = alloc_id_resource.encode('utf-8')
- output = KVPair(key, value, None)
- self._rm._kv_store.get = Mock(return_value=(output, None))
- result = yield self._rm.get_resource_id(1, 'ALLOC_ID', 1)
+ output = alloc_id_resource.encode('utf-8')
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
+ result = self._rm.get_resource_id(1, 'ALLOC_ID', 1)
self.assertEqual(result[0], 1024)
- result = yield self._rm.get_resource_id(1, 'ALLOC_ID', 4)
+ result = self._rm.get_resource_id(1, 'ALLOC_ID', 4)
self.assertEqual(result, [1024, 1025, 1026, 1027])
# Get gemport id test
gemport_id_resource = self._rm._format_resource(2, 1023, 65534)
- key = self._rm._get_path(2, PONResourceManager.GEMPORT_ID)
- value = gemport_id_resource.encode('utf-8')
- output = KVPair(key, value, None)
- self._rm._kv_store.get = Mock(return_value=(output, None))
- result = yield self._rm.get_resource_id(2, 'GEMPORT_ID', 1)
+ output = gemport_id_resource.encode('utf-8')
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
+ result = self._rm.get_resource_id(2, 'GEMPORT_ID', 1)
self.assertEqual(result[0], 1023)
- result = yield self._rm.get_resource_id(2, 'GEMPORT_ID', 5)
+ result = self._rm.get_resource_id(2, 'GEMPORT_ID', 5)
self.assertEqual(result, [1023, 1024, 1025, 1026, 1027])
- @inlineCallbacks
def test_free_resource_id(self):
# Free onu id test
- self._rm._kv_store.put = Mock(return_value=None)
+ self._rm._kv_store.update_to_kv_store = Mock(return_value=True)
onu_id_resource = eval(self._rm._format_resource(0, 1, 127))
onu_id_resource['pool'] = BitArray('0b' + onu_id_resource['pool'])
self._rm._generate_next_id(onu_id_resource)
onu_id_resource['pool'] = onu_id_resource['pool'].bin
- key = self._rm._get_path(0, PONResourceManager.ONU_ID)
- value = json.dumps(onu_id_resource).encode('utf-8')
- output = KVPair(key, value, None)
- self._rm._kv_store.get = Mock(return_value=(output, None))
- result = yield self._rm.free_resource_id(0, 'ONU_ID', 1)
+ output = json.dumps(onu_id_resource).encode('utf-8')
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
+ result = self._rm.free_resource_id(0, 'ONU_ID', 1)
self.assertTrue(result)
# Free alloc id test
@@ -130,10 +112,8 @@
self._rm._generate_next_id(alloc_id_resource)
alloc_id_resource['pool'] = alloc_id_resource['pool'].bin
- key = self._rm._get_path(0, PONResourceManager.ALLOC_ID)
- value = json.dumps(alloc_id_resource).encode('utf-8')
- output = KVPair(key, value, None)
- self._rm._kv_store.get = Mock(return_value=(output, None))
+ output = json.dumps(alloc_id_resource).encode('utf-8')
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
result = self._rm.free_resource_id(1, 'ALLOC_ID',
[1024, 1025, 1026, 1027, 1028])
self.assertTrue(result)
@@ -147,21 +127,18 @@
self._rm._generate_next_id(gemport_id_resource)
gemport_id_resource['pool'] = gemport_id_resource['pool'].bin
- key = self._rm._get_path(0, PONResourceManager.GEMPORT_ID)
- value = json.dumps(gemport_id_resource).encode('utf-8')
- output = KVPair(key, value, None)
- self._rm._kv_store.get = Mock(return_value=(output, None))
+ output = json.dumps(gemport_id_resource).encode('utf-8')
+ self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
result = self._rm.free_resource_id(2, 'GEMPORT_ID',
[1023, 1024, 1025, 1026, 1027, 1028])
self.assertTrue(result)
- @inlineCallbacks
def test_clear_resource_id_pool(self):
- self._rm._kv_store.delete = Mock(return_value=None)
- status = yield self._rm.clear_resource_id_pool(0, 'ONU_ID')
+ self._rm._kv_store.remove_from_kv_store = Mock(return_value=True)
+ status = self._rm.clear_resource_id_pool(0, 'ONU_ID')
self.assertTrue(status)
- self._rm._kv_store.delete = Mock(return_value="error")
- status = yield self._rm.clear_resource_id_pool(1, 'ALLOC_ID')
+ self._rm._kv_store.remove_from_kv_store = Mock(return_value=False)
+ status = self._rm.clear_resource_id_pool(1, 'ALLOC_ID')
self.assertFalse(status)