2015-06-17 11:20:40 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
2015-06-17 11:20:40 +00:00
|
|
|
'''
|
|
|
|
# Import Python libs
|
2018-01-26 12:43:11 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2015-06-17 11:20:40 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-22 16:42:17 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import (
|
2015-06-17 11:20:40 +00:00
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
MagicMock,
|
|
|
|
patch
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.states.serverdensity_device as serverdensity_device
|
2015-06-17 11:20:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-22 16:42:17 +00:00
|
|
|
class ServerdensityDeviceTestCase(TestCase, LoaderModuleMockMixin):
|
2015-06-17 11:20:40 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.states.serverdensity_device
|
|
|
|
'''
|
2017-03-22 16:42:17 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {serverdensity_device: {}}
|
|
|
|
|
2015-06-17 11:20:40 +00:00
|
|
|
# 'monitored' function tests: 1
|
|
|
|
|
|
|
|
def test_monitored(self):
|
|
|
|
'''
|
|
|
|
Test to device is monitored with Server Density.
|
|
|
|
'''
|
|
|
|
name = 'my_special_server'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'changes': {},
|
|
|
|
'result': True,
|
|
|
|
'comment': ''}
|
|
|
|
|
|
|
|
mock_dict = MagicMock(return_value={'id': name})
|
|
|
|
mock_t = MagicMock(side_effect=[True, {'agentKey': True},
|
|
|
|
[{'agentKey': True}]])
|
|
|
|
mock_sd = MagicMock(side_effect=[['sd-agent'], [], True])
|
|
|
|
with patch.dict(serverdensity_device.__salt__,
|
|
|
|
{'status.all_status': mock_dict,
|
|
|
|
'grains.items': mock_dict,
|
|
|
|
'serverdensity_device.ls': mock_t,
|
|
|
|
'pkg.list_pkgs': mock_sd,
|
|
|
|
'serverdensity_device.install_agent': mock_sd}):
|
|
|
|
comt = ('Such server name already exists in this'
|
|
|
|
' Server Density account. And sd-agent is installed')
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(serverdensity_device.monitored(name), ret)
|
|
|
|
|
|
|
|
comt = ('Successfully installed agent and created'
|
|
|
|
' device in Server Density db.')
|
|
|
|
ret.update({'comment': comt, 'changes': {'created_device':
|
|
|
|
{'agentKey': True},
|
|
|
|
'installed_agent': True}})
|
|
|
|
self.assertDictEqual(serverdensity_device.monitored(name), ret)
|