Unit Test Cases for monitor.py
Change-Id: I0bbb85aecfe660c540432d7b7778eec9d5b6c83b
This commit is contained in:
parent
6d18059043
commit
b2ae216c5a
|
@ -0,0 +1,107 @@
|
|||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import json
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from tacker.common import driver_manager
|
||||
from tacker.vm.monitor import VNFMonitor
|
||||
|
||||
|
||||
class TestVNFMonitor(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestVNFMonitor, self).setUp()
|
||||
self.addCleanup(mock.patch.stopall)
|
||||
|
||||
def test_to_hosting_device(self):
|
||||
monitoring_policy = {
|
||||
"vdus": {
|
||||
"vdu1": {
|
||||
"ping": {
|
||||
"actions": {
|
||||
"failure": "respawn"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
test_device_id = 'a737497c-761c-11e5-89c3-9cb6541d805d'
|
||||
test_device_dict = {
|
||||
'id': test_device_id,
|
||||
'mgmt_url': '{"vdu1": "192.168.120.3"}',
|
||||
'attributes': {
|
||||
'monitoring_policy': json.dumps(monitoring_policy)
|
||||
}
|
||||
}
|
||||
action_cb = mock.MagicMock()
|
||||
output_dict = VNFMonitor.to_hosting_vnf(test_device_dict,
|
||||
action_cb)
|
||||
self.assertEqual(output_dict['id'], test_device_id)
|
||||
|
||||
@mock.patch('tacker.vm.monitor.VNFMonitor.__run__')
|
||||
def test_add_hosting_vnf(self, mock_monitor_run):
|
||||
test_id = '25e4f0bd-0672-4b66-8f2f-51a979d020a9'
|
||||
test_device_dict = {
|
||||
'id': test_id,
|
||||
'management_ip_addresses': {
|
||||
'vdu1': '192.168.120.4'
|
||||
}
|
||||
}
|
||||
test_vnfmonitor = VNFMonitor()
|
||||
test_vnfmonitor.add_hosting_vnf(test_device_dict)
|
||||
test_device_id = test_vnfmonitor._hosting_vnfs.keys()[0]
|
||||
self.assertEqual(test_device_id, test_id)
|
||||
|
||||
@mock.patch('tacker.vm.monitor.VNFMonitor.__run__')
|
||||
@mock.patch('tacker.vm.monitor_drivers.ping.ping.VNFMonitorPing.'
|
||||
'_is_pingable')
|
||||
def test_run_monitor(self, mock_monitor_run, mock_pingable):
|
||||
test_id = '25e4f0bd-0672-4b66-8f2f-51a979d020a9'
|
||||
mock_pingable.return_value = True
|
||||
test_hosting_vnf = {
|
||||
'id': test_id,
|
||||
'management_ip_addresses': {
|
||||
'vdu1': '192.168.120.6'
|
||||
},
|
||||
'monitoring_policy': {
|
||||
'vdus': {
|
||||
'vdu1': {
|
||||
'ping': {
|
||||
'actions': {
|
||||
'failure': 'respawn'
|
||||
},
|
||||
'monitoring_params': {
|
||||
'count': 1,
|
||||
'monitoring_delay': 0,
|
||||
'interval': 0,
|
||||
'timeout': 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'boot_at': timeutils.utcnow(),
|
||||
'action_cb': mock.MagicMock()
|
||||
}
|
||||
test_hosting_vnf['device'] = {}
|
||||
test_vnfmonitor = VNFMonitor()
|
||||
test_vnfmonitor._monitor_manager = driver_manager.DriverManager(
|
||||
'tacker.servicevm.monitor.drivers',
|
||||
['ping'])
|
||||
test_vnfmonitor.run_monitor(test_hosting_vnf)
|
||||
mock_pingable.assert_called_once_with()
|
Loading…
Reference in New Issue