blob: cef505c7d0e9444a5b3eaa30a9f8fd16a7a32cc5 [file] [log] [blame]
Chip Boling67b674a2019-02-08 11:42:18 -06001#
2# Copyright 2018 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16from unittest import TestCase, main
17from nose.tools import assert_raises
18from copy import deepcopy
19from mock.mock_adapter_agent import MockAdapterAgent, MockCore
20from pyvoltha.adapters.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults
21from pyvoltha.adapters.extensions.omci.database.mib_db_ext import MibDbExternal
22from pyvoltha.adapters.extensions.omci.database.mib_db_dict import MibDbVolatileDict
23from pyvoltha.adapters.extensions.omci.state_machines.mib_sync import MibSynchronizer
24from pyvoltha.adapters.extensions.omci.tasks.mib_upload import MibUploadTask
25from pyvoltha.adapters.extensions.omci.tasks.get_mds_task import GetMdsTask
26from pyvoltha.adapters.extensions.omci.tasks.mib_resync_task import MibResyncTask
27from pyvoltha.adapters.extensions.omci.tasks.mib_reconcile_task import MibReconcileTask
28
29
30class TestOpenOmciAgent(TestCase):
31 """
32 Test the Open OMCI Agent
33 """
34 def setUp(self):
35 self.adapter_agent = MockAdapterAgent()
36
37 def tearDown(self):
38 if self.adapter_agent is not None:
39 self.adapter_agent.tearDown()
40
41 def test_omci_agent_defaults(self):
42 # Make sure someone does not check in bad default values
43
44 mib_sync = OpenOmciAgentDefaults.get('mib-synchronizer')
45
46 self.assertIsNotNone(mib_sync)
47 self.assertTrue(isinstance(mib_sync['state-machine'], type(MibSynchronizer)))
48 self.assertTrue(isinstance(mib_sync['database'], type(MibDbExternal)))
49
50 mib_sync_tasks = mib_sync.get('tasks')
51
52 self.assertIsNotNone(mib_sync_tasks)
53 self.assertTrue(isinstance(mib_sync_tasks['mib-upload'], type(MibUploadTask)))
54 self.assertTrue(isinstance(mib_sync_tasks['get-mds'], type(GetMdsTask)))
55 self.assertTrue(isinstance(mib_sync_tasks['mib-audit'], type(GetMdsTask)))
56 self.assertTrue(isinstance(mib_sync_tasks['mib-resync'], type(MibResyncTask)))
57 self.assertTrue(isinstance(mib_sync_tasks['mib-reconcile'], type(MibReconcileTask)))
58
59 # caps = OpenOmciAgentDefaults.get('onu-capabilities')
60 #
61 # self.assertIsNotNone(caps)
62
63 def test_omci_agent_default_init(self):
64 agent = OpenOMCIAgent(MockCore)
65
66 self.assertTrue(isinstance(agent.core, type(MockCore)))
67 self.assertTrue(isinstance(agent.database_class, type(MibDbExternal)))
68 self.assertEqual(len(agent.device_ids()), 0)
69 assert_raises(KeyError, agent.get_device, 'deadbeef')
70
71 def test_omci_agent_custom_mib_database(self):
72 custom = deepcopy(OpenOmciAgentDefaults)
73 custom['mib-synchronizer']['database'] = MibDbVolatileDict
74 agent = OpenOMCIAgent(MockCore, support_classes=custom)
75
76 self.assertTrue(isinstance(agent.core, type(MockCore)))
77 self.assertTrue(isinstance(agent.database_class, type(MibDbVolatileDict)))
78
79 def test_omci_agent_start_stop(self):
80 agent = OpenOMCIAgent(MockCore)
81
82 agent.start()
83 agent.start() # Should be a NOP, no side effects
84
85 agent.stop()
86 agent.stop() # Should be a NOP, no side effects
87
88
89if __name__ == '__main__':
90 main()
91