Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 1 | # |
| 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 Williams | 84a71e9 | 2019-11-15 09:00:19 -0700 | [diff] [blame] | 16 | from __future__ import absolute_import |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 17 | from unittest import TestCase, main |
| 18 | from nose.tools import assert_raises |
| 19 | from copy import deepcopy |
Zack Williams | 84a71e9 | 2019-11-15 09:00:19 -0700 | [diff] [blame] | 20 | from .mock.mock_adapter_agent import MockAdapterAgent, MockCore |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 21 | from pyvoltha.adapters.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults |
| 22 | from pyvoltha.adapters.extensions.omci.database.mib_db_ext import MibDbExternal |
| 23 | from pyvoltha.adapters.extensions.omci.database.mib_db_dict import MibDbVolatileDict |
| 24 | from pyvoltha.adapters.extensions.omci.state_machines.mib_sync import MibSynchronizer |
| 25 | from pyvoltha.adapters.extensions.omci.tasks.mib_upload import MibUploadTask |
| 26 | from pyvoltha.adapters.extensions.omci.tasks.get_mds_task import GetMdsTask |
| 27 | from pyvoltha.adapters.extensions.omci.tasks.mib_resync_task import MibResyncTask |
| 28 | from pyvoltha.adapters.extensions.omci.tasks.mib_reconcile_task import MibReconcileTask |
| 29 | |
| 30 | |
| 31 | class 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 | |
| 90 | if __name__ == '__main__': |
| 91 | main() |
| 92 | |