salt/tests/unit/modules/test_netscaler.py

1125 lines
35 KiB
Python
Raw Normal View History

2015-04-16 11:51:51 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
2015-04-16 11:51:51 +00:00
'''
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
2015-04-16 11:51:51 +00:00
# Import Salt Testing Libs
2017-03-21 17:58:19 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
2015-04-16 11:51:51 +00:00
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
import salt.modules.netscaler as netscaler
2015-04-16 11:51:51 +00:00
class MockJson(Exception):
'''
Mock Json class
'''
@staticmethod
def loads(content):
'''
Mock loads method
'''
return content
@staticmethod
def dumps(dumps):
'''
Mock dumps method
'''
return dumps
class MockNSNitroError(Exception):
'''
Mock NSNitroError class
'''
def __init__(self, message='error'):
self._message = message
super(MockNSNitroError, self).__init__(self.message)
def _get_message(self):
'''
get_message method
'''
return self._message
def _set_message(self, message):
'''
set_message method
'''
self._message = message
message = property(_get_message, _set_message)
class MockNSNitro(object):
'''
Mock NSNitro class
'''
flag = None
def __init__(self, host, user, passwd, bol):
pass
@staticmethod
def login():
'''
Mock login method
'''
return True
@staticmethod
def logout():
'''
Mock logout method
'''
return True
class MockNSServiceGroup(object):
'''
Mock NSServiceGroup class
'''
def __init__(self):
self.sg_name = None
def set_servicegroupname(self, sg_name):
'''
Mock set_servicegroupname method
'''
self.sg_name = sg_name
return MockNSServiceGroup()
@staticmethod
2015-04-17 07:04:26 +00:00
def get(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock get method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSServiceGroup()
@staticmethod
2015-04-17 07:04:26 +00:00
def add(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock add method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSServiceGroup()
@staticmethod
2015-04-17 07:04:26 +00:00
def delete(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock delete method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSServiceGroup()
@staticmethod
2015-04-17 07:04:26 +00:00
def get_servers(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock get_servers method
'''
if MockNSNitro.flag:
raise MockNSNitroError
2015-04-17 07:04:26 +00:00
return [MockNSServiceGroup()]
2015-04-16 11:51:51 +00:00
@staticmethod
2015-04-17 07:04:26 +00:00
def enable_server(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock enable_server method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSServiceGroup()
@staticmethod
2015-04-17 07:04:26 +00:00
def disable_server(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock disable_server method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSServiceGroup()
2015-04-17 07:04:26 +00:00
@staticmethod
def get_servername():
'''
Mock get_servername method
'''
return 'serviceGroupName'
2015-04-16 11:51:51 +00:00
@staticmethod
def get_state():
'''
Mock get_state method
'''
return 'ENABLED'
@staticmethod
def get_servicetype():
'''
Mock get_servicetype method
'''
return ''
@staticmethod
def set_servicetype(bol):
'''
Mock set_servicetype method
'''
return bol
class MockNSServiceGroupServerBinding(object):
'''
Mock NSServiceGroupServerBinding class
'''
def __init__(self):
self.sg_name = None
def set_servername(self, sg_name):
'''
Mock set_servername method
'''
self.sg_name = sg_name
return MockNSServiceGroupServerBinding()
def set_servicegroupname(self, sg_name):
'''
Mock set_servicegroupname method
'''
self.sg_name = sg_name
return MockNSServiceGroupServerBinding()
def set_port(self, sg_name):
'''
Mock set_port method
'''
self.sg_name = sg_name
return MockNSServiceGroupServerBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def add(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock add method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSServiceGroupServerBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def delete(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock delete method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSServiceGroupServerBinding()
class MockNSService(object):
'''
Mock NSService class
'''
def __init__(self):
self.sg_name = None
def set_name(self, sg_name):
'''
Mock set_name method
'''
self.sg_name = sg_name
return MockNSService()
@staticmethod
2015-04-17 07:04:26 +00:00
def get(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock get method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSService()
@staticmethod
2015-04-17 07:04:26 +00:00
def enable(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock enable method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSService()
@staticmethod
2015-04-17 07:04:26 +00:00
def disable(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock disable method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSService()
@staticmethod
def get_svrstate():
'''
Mock get_svrstate method
'''
return 'UP'
class MockNSServer(object):
'''
Mock NSServer class
'''
flag = None
def __init__(self):
self.sg_name = None
def set_name(self, sg_name):
'''
Mock set_name method
'''
self.sg_name = sg_name
return MockNSServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def get(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock get method
'''
return MockNSServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def add(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock add method
'''
return MockNSServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def delete(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock delete method
'''
return MockNSServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def update(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock update method
'''
return MockNSServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def enable(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock enable method
'''
return MockNSServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def disable(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock disable method
'''
return MockNSServer()
@staticmethod
def get_ipaddress():
'''
Mock get_ipaddress method
'''
return ''
@staticmethod
def set_ipaddress(s_ip):
'''
Mock set_ipaddress method
'''
return s_ip
def get_state(self):
'''
Mock get_state method
'''
if self.flag == 1:
return ''
elif self.flag == 2:
return 'DISABLED'
return 'ENABLED'
class MockNSLBVServer(object):
'''
Mock NSLBVServer class
'''
def __init__(self):
self.sg_name = None
def set_name(self, sg_name):
'''
Mock set_name method
'''
self.sg_name = sg_name
return MockNSLBVServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def get(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock get method
'''
return MockNSLBVServer()
@staticmethod
def set_ipv46(v_ip):
'''
Mock set_ipv46 method
'''
return v_ip
@staticmethod
def set_port(v_port):
'''
Mock set_port method
'''
return v_port
@staticmethod
def set_servicetype(v_type):
'''
Mock set_servicetype method
'''
return v_type
@staticmethod
def get_ipv46():
'''
Mock get_ipv46 method
'''
return ''
@staticmethod
def get_port():
'''
Mock get_port method
'''
return ''
@staticmethod
def get_servicetype():
'''
Mock get_servicetype method
'''
return ''
@staticmethod
2015-04-17 07:04:26 +00:00
def add(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock add method
'''
return MockNSLBVServer()
@staticmethod
2015-04-17 07:04:26 +00:00
def delete(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock delete method
'''
return MockNSLBVServer()
class MockNSLBVServerServiceGroupBinding(object):
'''
Mock NSLBVServerServiceGroupBinding class
'''
flag = None
def __init__(self):
self.sg_name = None
def set_name(self, sg_name):
'''
Mock set_name method
'''
self.sg_name = sg_name
return MockNSLBVServerServiceGroupBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def get(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock get method
'''
if MockNSNitro.flag:
raise MockNSNitroError
2015-04-17 07:04:26 +00:00
return [MockNSLBVServerServiceGroupBinding()]
@staticmethod
def get_servicegroupname():
'''
Mock get_servicegroupname method
'''
return 'serviceGroupName'
2015-04-16 11:51:51 +00:00
def set_servicegroupname(self, sg_name):
'''
Mock set_servicegroupname method
'''
self.sg_name = sg_name
if self.flag:
return None
return MockNSLBVServerServiceGroupBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def add(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock add method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSLBVServerServiceGroupBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def delete(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock delete method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSLBVServerServiceGroupBinding()
class MockNSSSLVServerSSLCertKeyBinding(object):
'''
Mock NSSSLVServerSSLCertKeyBinding class
'''
def __init__(self):
self.sg_name = None
def set_vservername(self, sg_name):
'''
Mock set_vservername method
'''
self.sg_name = sg_name
return MockNSSSLVServerSSLCertKeyBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def get(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock get method
'''
if MockNSNitro.flag:
raise MockNSNitroError
2015-04-17 07:04:26 +00:00
return [MockNSSSLVServerSSLCertKeyBinding()]
@staticmethod
def get_certkeyname():
'''
Mock get_certkeyname method
'''
return 'serviceGroupName'
2015-04-16 11:51:51 +00:00
def set_certkeyname(self, sg_name):
'''
Mock set_certkeyname method
'''
self.sg_name = sg_name
return MockNSSSLVServerSSLCertKeyBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def add(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock add method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSSSLVServerSSLCertKeyBinding()
@staticmethod
2015-04-17 07:04:26 +00:00
def delete(obj, servicegroup):
2015-04-16 11:51:51 +00:00
'''
Mock delete method
'''
if MockNSNitro.flag:
raise MockNSNitroError
return MockNSSSLVServerSSLCertKeyBinding()
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-21 17:58:19 +00:00
class NetscalerTestCase(TestCase, LoaderModuleMockMixin):
2015-04-16 11:51:51 +00:00
'''
TestCase for salt.modules.netscaler
'''
def setup_loader_modules(self):
2017-03-21 17:58:19 +00:00
return {
netscaler: {
'NSNitro': MockNSNitro,
'NSServiceGroup': MockNSServiceGroup,
'NSServiceGroupServerBinding': MockNSServiceGroupServerBinding,
'NSLBVServerServiceGroupBinding': MockNSLBVServerServiceGroupBinding,
'NSService': MockNSService,
'NSServer': MockNSServer,
'NSLBVServer': MockNSLBVServer,
'NSNitroError': MockNSNitroError,
'NSSSLVServerSSLCertKeyBinding': MockNSSSLVServerSSLCertKeyBinding,
2017-03-21 17:58:19 +00:00
}
}
2015-04-16 11:51:51 +00:00
# 'servicegroup_exists' function tests: 1
def test_servicegroup_exists(self):
'''
Tests if it checks if a service group exists
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
MockNSNitro.flag = None
self.assertTrue(netscaler.servicegroup_exists('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.servicegroup_exists('serviceGrpName',
sg_type='HTTP'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
MockNSNitro.flag = True
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.servicegroup_exists('serGrpNme'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_add' function tests: 1
def test_servicegroup_add(self):
'''
Tests if it add a new service group
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.servicegroup_add('serviceGroupName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
MockNSNitro.flag = True
self.assertFalse(netscaler.servicegroup_add('serviceGroupName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.servicegroup_add('serveGrpName'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_delete' function tests: 1
def test_servicegroup_delete(self):
'''
Tests if it delete a new service group
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
MockNSNitro.flag = None
self.assertTrue(netscaler.servicegroup_delete('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(side_effect=[None, MockNSServiceGroup()])
with patch.object(netscaler, '_servicegroup_get', mock):
MockNSNitro.flag = True
self.assertFalse(netscaler.servicegroup_delete('srGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.servicegroup_delete('sGNam'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_server_exists' function tests: 1
def test_servicegroup_server_exists(self):
'''
Tests if it check if a server:port combination
is a member of a servicegroup
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.servicegroup_server_exists
('serviceGrpName', 'serverName', 'serverPort'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_server_up' function tests: 1
def test_servicegroup_server_up(self):
'''
Tests if it check if a server:port combination
is a member of a servicegroup
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.servicegroup_server_up
('serviceGrpName', 'serverName', 'serverPort'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_server_enable' function tests: 1
def test_servicegroup_server_enable(self):
'''
Tests if it enable a server:port member of a servicegroup
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.servicegroup_server_enable
('serviceGrpName', 'serverName', 'serverPort'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_servicegroup_get_server',
MagicMock(return_value=MockNSServiceGroup())):
MockNSNitro.flag = None
self.assertTrue(netscaler.servicegroup_server_enable
('servGrpName', 'serverName', 'serPort'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.servicegroup_server_enable
('serGrpName', 'serverName', 'sPort'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_server_disable' function tests: 1
2015-04-17 07:04:26 +00:00
def test_sergrp_server_disable(self):
2015-04-16 11:51:51 +00:00
'''
Tests if it disable a server:port member of a servicegroup
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.servicegroup_server_disable
('serviceGrpName', 'serverName', 'serverPort'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_servicegroup_get_server',
MagicMock(return_value=MockNSServiceGroup())):
MockNSNitro.flag = None
self.assertTrue(netscaler.servicegroup_server_disable
('serveGrpName', 'serverName', 'serPort'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.servicegroup_server_disable
('servGrpName', 'serverName', 'sPort'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_server_add' function tests: 1
def test_servicegroup_server_add(self):
'''
Tests if it add a server:port member to a servicegroup
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.servicegroup_server_add
('serGrpName', 'serverName', 'sPort'))
MockNSNitro.flag = None
self.assertTrue(netscaler.servicegroup_server_add
('serGrpName', 'serverName', 'serverPort'))
mock = MagicMock(return_value=
MockNSServiceGroupServerBinding())
with patch.object(netscaler, '_servicegroup_get_server',
mock):
MockNSNitro.flag = True
self.assertFalse(netscaler.servicegroup_server_add
('serviceGroupName', 'serverName',
'serPort'))
2015-04-16 11:51:51 +00:00
# 'servicegroup_server_delete' function tests: 1
def test_servicegroup_server_delete(self):
'''
Tests if it remove a server:port member to a servicegroup
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.servicegroup_server_delete
('servGrpName', 'serverName', 'sPort'))
self.assertFalse(netscaler.servicegroup_server_delete
('serviceGroupName', 'serverName',
'serverPort'))
mock = MagicMock(return_value=
MockNSServiceGroupServerBinding())
with patch.object(netscaler, '_servicegroup_get_server',
mock):
MockNSNitro.flag = None
self.assertTrue(netscaler.servicegroup_server_delete
('serviceGroupName', 'serverName',
'serPort'))
2015-04-16 11:51:51 +00:00
# 'service_up' function tests: 1
def test_service_up(self):
'''
Tests if it checks if a service is UP
'''
mock = MagicMock(return_value=MockNSService())
with patch.object(netscaler, '_service_get', mock):
self.assertTrue(netscaler.service_up('serviceGrpName'))
# 'service_exists' function tests: 1
def test_service_exists(self):
'''
Tests if it checks if a service is UP
'''
mock = MagicMock(return_value=MockNSService())
with patch.object(netscaler, '_service_get', mock):
self.assertTrue(netscaler.service_exists('serviceGrpName'))
# 'service_enable' function tests: 1
def test_service_enable(self):
'''
Tests if it enable a service
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.service_enable('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.service_enable('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value=MockNSService())
with patch.object(netscaler, '_service_get', mock):
self.assertFalse(netscaler.service_enable('serGrpName'))
2015-04-16 11:51:51 +00:00
# 'service_disable' function tests: 1
def test_service_disable(self):
'''
Tests if it disable a service
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.service_disable('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.service_disable('serceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value=MockNSService())
with patch.object(netscaler, '_service_get', mock):
self.assertFalse(netscaler.service_disable('seGrpName'))
2015-04-16 11:51:51 +00:00
# 'server_exists' function tests: 1
def test_server_exists(self):
'''
Tests if it checks if a server exists
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.server_exists('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.server_exists('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.server_exists('serviceGrpName',
ip='1.0.0.1'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.server_exists('serviceGrpName',
s_state='serverName'))
2015-04-16 11:51:51 +00:00
# 'server_add' function tests: 1
def test_server_add(self):
'''
Tests if it add a server
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.server_add('servGrpName', '1.0.0.1'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.server_add('serviceGrpName',
'1.0.0.1'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value=False)
with patch.object(netscaler, 'server_exists', mock):
self.assertTrue(netscaler.server_add('serviceGrpName',
'1.0.0.1'))
2015-04-16 11:51:51 +00:00
# 'server_delete' function tests: 1
def test_server_delete(self):
'''
Tests if it delete a server
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.server_delete('serviceGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(side_effect=[MockNSServer(), None])
with patch.object(netscaler, '_server_get', mock):
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.server_delete('serGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.server_delete('serviceGrpName'))
2015-04-16 11:51:51 +00:00
# 'server_update' function tests: 1
def test_server_update(self):
'''
Tests if it update a server's attributes
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(side_effect=[None, MockNSServer(), MockNSServer(),
MockNSServer()])
with patch.object(netscaler, '_server_get', mock):
self.assertFalse(netscaler.server_update('seGrName', '1.0.0.1'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.server_update('serGrpName', ''))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.server_update('serGrpName',
'1.0.0.1'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.server_update('serGrpName',
'1.0.0.1'))
2015-04-16 11:51:51 +00:00
# 'server_enabled' function tests: 1
def test_server_enabled(self):
'''
Tests if it check if a server is enabled globally
'''
mock = MagicMock(return_value=MockNSServer())
with patch.object(netscaler, '_server_get', mock):
MockNSServer.flag = None
self.assertTrue(netscaler.server_enabled('serGrpName'))
# 'server_enable' function tests: 1
def test_server_enable(self):
'''
Tests if it enables a server globally
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.server_enable('serGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
MockNSServer.flag = 1
self.assertTrue(netscaler.server_enable('serGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(side_effect=[MockNSServer(), None])
with patch.object(netscaler, '_server_get', mock):
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
2015-04-16 11:51:51 +00:00
self.assertFalse(netscaler.server_enable('serGrpName'))
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.server_enable('serGrpName'))
2015-04-16 11:51:51 +00:00
# 'server_disable' function tests: 1
def test_server_disable(self):
'''
Tests if it disable a server globally
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.server_disable('serGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
MockNSServer.flag = 2
self.assertTrue(netscaler.server_disable('serGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
MockNSServer.flag = None
mock = MagicMock(side_effect=[None, MockNSServer()])
with patch.object(netscaler, '_server_get', mock):
self.assertFalse(netscaler.server_disable('serGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.server_disable('serGrpName'))
2015-04-16 11:51:51 +00:00
# 'vserver_exists' function tests: 1
def test_vserver_exists(self):
'''
Tests if it checks if a vserver exists
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.vserver_exists('vserverName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.vserver_exists('vserverName',
v_ip='1.0.0.1'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.vserver_exists('vserrName', v_ip='',
v_port='vserverPort'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
self.assertFalse(netscaler.vserver_exists('vserrName', v_ip='',
v_port='',
v_type='vserverType'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value=None)
with patch.object(netscaler, '_vserver_get', mock):
self.assertFalse(netscaler.vserver_exists('vserverName'))
2015-04-16 11:51:51 +00:00
# 'vserver_add' function tests: 1
def test_vserver_add(self):
'''
Tests if it add a new lb vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.vserver_add('alex.patate.chaude.443',
'1.2.3.4', '443', 'SSL'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value=False)
with patch.object(netscaler, 'vserver_exists', mock):
self.assertTrue(netscaler.vserver_add('alex.pae.chaude.443',
'1.2.3.4', '443',
'SSL'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.vserver_add('alex.chde.443',
'1.2.3.4', '443',
'SSL'))
2015-04-16 11:51:51 +00:00
# 'vserver_delete' function tests: 1
def test_vserver_delete(self):
'''
Tests if it delete a new lb vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.vserver_delete('alex.pe.chaude.443'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(side_effect=[None, MockNSLBVServer()])
with patch.object(netscaler, '_vserver_get', mock):
self.assertFalse(netscaler.vserver_delete('alex.chade.443'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.vserver_delete('al.cha.443'))
2015-04-16 11:51:51 +00:00
# 'vserver_servicegroup_exists' function tests: 1
2015-04-17 07:04:26 +00:00
def test_vser_sergrp_exists(self):
2015-04-16 11:51:51 +00:00
'''
Tests if it checks if a servicegroup is tied to a vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.vserver_servicegroup_exists
('vserverName', 'serviceGroupName'))
2015-04-16 11:51:51 +00:00
# 'vserver_servicegroup_add' function tests: 1
def test_vserver_servicegroup_add(self):
'''
Tests if it bind a servicegroup to a vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
MockNSNitro.flag = None
self.assertTrue(netscaler.vserver_servicegroup_add
('vserverName', 'serGroupName'))
mock = MagicMock(side_effect=
[MockNSLBVServerServiceGroupBinding(), None])
with patch.object(netscaler, 'vserver_servicegroup_exists',
mock):
self.assertFalse(netscaler.vserver_servicegroup_add
('vserName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
2015-04-16 11:51:51 +00:00
self.assertFalse(netscaler.vserver_servicegroup_add
2015-04-17 07:04:26 +00:00
('vName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
# 'vserver_servicegroup_delete' function tests: 1
2015-04-17 07:04:26 +00:00
def test_vser_sergrp_delete(self):
2015-04-16 11:51:51 +00:00
'''
Tests if it unbind a servicegroup from a vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertFalse(netscaler.vserver_servicegroup_delete
('vservName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value=
MockNSLBVServerServiceGroupBinding())
with patch.object(netscaler, 'vserver_servicegroup_exists',
mock):
MockNSNitro.flag = None
self.assertTrue(netscaler.vserver_servicegroup_delete
('vName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.vserver_servicegroup_delete
('vserverName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
# 'vserver_sslcert_exists' function tests: 1
def test_vserver_sslcert_exists(self):
'''
Tests if it checks if a SSL certificate is tied to a vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
self.assertTrue(netscaler.vserver_sslcert_exists
('vserverName', 'serviceGroupName'))
2015-04-16 11:51:51 +00:00
# 'vserver_sslcert_add' function tests: 1
def test_vserver_sslcert_add(self):
'''
Tests if it binds a SSL certificate to a vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(side_effect=[MockNSSSLVServerSSLCertKeyBinding(),
None, None])
with patch.object(netscaler, 'vserver_sslcert_exists', mock):
self.assertFalse(netscaler.vserver_sslcert_add
('vserName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
2015-04-16 11:51:51 +00:00
self.assertFalse(netscaler.vserver_sslcert_add
2015-04-17 07:04:26 +00:00
('vName', 'serGrName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
MockNSNitro.flag = None
self.assertTrue(netscaler.vserver_sslcert_add
('vserverName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
# 'vserver_sslcert_delete' function tests: 1
def test_vserver_sslcert_delete(self):
'''
Tests if it unbinds a SSL certificate from a vserver
'''
2015-04-17 07:04:26 +00:00
mock = MagicMock(side_effect=[None,
MockNSSSLVServerSSLCertKeyBinding(),
MockNSSSLVServerSSLCertKeyBinding()])
with patch.object(netscaler, 'vserver_sslcert_exists', mock):
self.assertFalse(netscaler.vserver_sslcert_delete('vName',
'serGrpName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
mock = MagicMock(return_value='')
with patch.dict(netscaler.__salt__, {'config.option': mock}):
MockNSNitro.flag = None
self.assertTrue(netscaler.vserver_sslcert_delete
('vservName', 'serGroupName'))
2015-04-16 11:51:51 +00:00
2015-04-17 07:04:26 +00:00
with patch.object(netscaler, '_connect',
MagicMock(return_value=None)):
self.assertFalse(netscaler.vserver_sslcert_delete
('vserverName', 'serGroupName'))