blob: 5b0a569e480ab0de1371440aabff856dfc167cbd [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#
Zack Williams84a71e92019-11-15 09:00:19 -070016from __future__ import absolute_import
Chip Boling67b674a2019-02-08 11:42:18 -060017from unittest import TestCase, main
18from nose.tools import assert_raises
19from copy import deepcopy
Zack Williams84a71e92019-11-15 09:00:19 -070020from .mock.mock_adapter_agent import MockAdapterAgent, MockCore
Chip Boling67b674a2019-02-08 11:42:18 -060021from pyvoltha.adapters.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults
22from pyvoltha.adapters.extensions.omci.database.mib_db_ext import MibDbExternal
23from pyvoltha.adapters.extensions.omci.database.mib_db_dict import MibDbVolatileDict
24from pyvoltha.adapters.extensions.omci.state_machines.mib_sync import MibSynchronizer
25from pyvoltha.adapters.extensions.omci.tasks.mib_upload import MibUploadTask
26from pyvoltha.adapters.extensions.omci.tasks.get_mds_task import GetMdsTask
27from pyvoltha.adapters.extensions.omci.tasks.mib_resync_task import MibResyncTask
28from pyvoltha.adapters.extensions.omci.tasks.mib_reconcile_task import MibReconcileTask
29
30
31class TestOpenOmciAgent(TestCase):
32 """
33 Test the Open OMCI Agent
34 """
35 def setUp(self):
36 self.adapter_agent = MockAdapterAgent()
37
38 def tearDown(self):
39 if self.adapter_agent is not None:
40 self.adapter_agent.tearDown()
41
42 def test_omci_agent_defaults(self):
43 # Make sure someone does not check in bad default values
44
45 mib_sync = OpenOmciAgentDefaults.get('mib-synchronizer')
46
47 self.assertIsNotNone(mib_sync)
48 self.assertTrue(isinstance(mib_sync['state-machine'], type(MibSynchronizer)))
49 self.assertTrue(isinstance(mib_sync['database'], type(MibDbExternal)))
50
51 mib_sync_tasks = mib_sync.get('tasks')
52
53 self.assertIsNotNone(mib_sync_tasks)
54 self.assertTrue(isinstance(mib_sync_tasks['mib-upload'], type(MibUploadTask)))
55 self.assertTrue(isinstance(mib_sync_tasks['get-mds'], type(GetMdsTask)))
56 self.assertTrue(isinstance(mib_sync_tasks['mib-audit'], type(GetMdsTask)))
57 self.assertTrue(isinstance(mib_sync_tasks['mib-resync'], type(MibResyncTask)))
58 self.assertTrue(isinstance(mib_sync_tasks['mib-reconcile'], type(MibReconcileTask)))
59
60 # caps = OpenOmciAgentDefaults.get('onu-capabilities')
61 #
62 # self.assertIsNotNone(caps)
63
64 def test_omci_agent_default_init(self):
65 agent = OpenOMCIAgent(MockCore)
66
67 self.assertTrue(isinstance(agent.core, type(MockCore)))
68 self.assertTrue(isinstance(agent.database_class, type(MibDbExternal)))
69 self.assertEqual(len(agent.device_ids()), 0)
70 assert_raises(KeyError, agent.get_device, 'deadbeef')
71
72 def test_omci_agent_custom_mib_database(self):
73 custom = deepcopy(OpenOmciAgentDefaults)
74 custom['mib-synchronizer']['database'] = MibDbVolatileDict
75 agent = OpenOMCIAgent(MockCore, support_classes=custom)
76
77 self.assertTrue(isinstance(agent.core, type(MockCore)))
78 self.assertTrue(isinstance(agent.database_class, type(MibDbVolatileDict)))
79
80 def test_omci_agent_start_stop(self):
81 agent = OpenOMCIAgent(MockCore)
82
83 agent.start()
84 agent.start() # Should be a NOP, no side effects
85
86 agent.stop()
87 agent.stop() # Should be a NOP, no side effects
88
89
90if __name__ == '__main__':
91 main()
92