"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/unit/modules/test_libcloud_loadbalancer.py" between
salt-2019.2.0.tar.gz and salt-2019.2.1.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

test_libcloud_loadbalancer.py  (salt-2019.2.0):test_libcloud_loadbalancer.py  (salt-2019.2.1)
skipping to change at line 20 skipping to change at line 20
from tests.support.mixins import LoaderModuleMockMixin from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf from tests.support.unit import TestCase, skipIf
from tests.support.mock import ( from tests.support.mock import (
patch, patch,
MagicMock, MagicMock,
NO_MOCK, NO_MOCK,
NO_MOCK_REASON NO_MOCK_REASON
) )
import salt.modules.libcloud_loadbalancer as libcloud_loadbalancer import salt.modules.libcloud_loadbalancer as libcloud_loadbalancer
from libcloud.loadbalancer.base import BaseDriver, LoadBalancer, Algorithm, Memb try:
er from libcloud.loadbalancer.base import BaseDriver, LoadBalancer, Algorithm,
Member
HAS_LIBCLOUD = True
except ImportError:
HAS_LIBCLOUD = False
if HAS_LIBCLOUD:
class MockLBDriver(BaseDriver):
def __init__(self): # pylint: disable=W0231
self._TEST_BALANCER = LoadBalancer(
id='test_id', name='test_balancer',
state=0, # RUNNING
ip='1.2.3.4',
port=80, driver=self,
extra={})
self._TEST_MEMBER = Member(
id='member_id', ip='12.3.4.5',
port=443, balancer=self._TEST_BALANCER,
extra=None)
def get_balancer(self, balancer_id):
assert balancer_id == 'test_id'
return self._TEST_BALANCER
def list_balancers(self):
return [self._TEST_BALANCER]
def list_protocols(self):
return ['http', 'https']
def create_balancer(self, name, port, protocol, algorithm, members):
assert name == 'new_test_balancer'
assert port == 80
assert protocol == 'http'
assert isinstance(algorithm, (Algorithm, int))
assert isinstance(members, list)
return self._TEST_BALANCER
def destroy_balancer(self, balancer):
assert balancer == self._TEST_BALANCER
return True
def balancer_attach_member(self, balancer, member):
assert isinstance(balancer, LoadBalancer)
assert isinstance(member, Member)
assert member.id is None
assert balancer.id == 'test_id'
return self._TEST_MEMBER
def balancer_detach_member(self, balancer, member):
assert isinstance(balancer, LoadBalancer)
assert isinstance(member, Member)
assert member.id == 'member_id'
assert balancer.id == 'test_id'
return True
def balancer_list_members(self, balancer):
assert isinstance(balancer, LoadBalancer)
assert balancer.id == 'test_id'
return [self._TEST_MEMBER]
class MockLBDriver(BaseDriver): else:
def __init__(self): MockLBDriver = object
self._TEST_BALANCER = LoadBalancer(
id='test_id', name='test_balancer',
state=0, # RUNNING
ip='1.2.3.4',
port=80, driver=self,
extra={})
self._TEST_MEMBER = Member(
id='member_id', ip='12.3.4.5',
port=443, balancer=self._TEST_BALANCER,
extra=None)
def get_balancer(self, balancer_id):
assert balancer_id == 'test_id'
return self._TEST_BALANCER
def list_balancers(self):
return [self._TEST_BALANCER]
def list_protocols(self):
return ['http', 'https']
def create_balancer(self, name, port, protocol, algorithm, members):
assert name == 'new_test_balancer'
assert port == 80
assert protocol == 'http'
assert isinstance(algorithm, (Algorithm, int))
assert isinstance(members, list)
return self._TEST_BALANCER
def destroy_balancer(self, balancer):
assert balancer == self._TEST_BALANCER
return True
def balancer_attach_member(self, balancer, member):
assert isinstance(balancer, LoadBalancer)
assert isinstance(member, Member)
assert member.id is None
assert balancer.id == 'test_id'
return self._TEST_MEMBER
def balancer_detach_member(self, balancer, member):
assert isinstance(balancer, LoadBalancer)
assert isinstance(member, Member)
assert member.id == 'member_id'
assert balancer.id == 'test_id'
return True
def balancer_list_members(self, balancer):
assert isinstance(balancer, LoadBalancer)
assert balancer.id == 'test_id'
return [self._TEST_MEMBER]
def get_mock_driver(): def get_mock_driver():
return MockLBDriver() return MockLBDriver()
@skipIf(not HAS_LIBCLOUD, NO_MOCK_REASON)
@skipIf(NO_MOCK, NO_MOCK_REASON) @skipIf(NO_MOCK, NO_MOCK_REASON)
@patch('salt.modules.libcloud_loadbalancer._get_driver', @patch('salt.modules.libcloud_loadbalancer._get_driver',
MagicMock(return_value=MockLBDriver())) MagicMock(return_value=MockLBDriver()))
class LibcloudLoadBalancerModuleTestCase(TestCase, LoaderModuleMockMixin): class LibcloudLoadBalancerModuleTestCase(TestCase, LoaderModuleMockMixin):
def setup_loader_modules(self): def setup_loader_modules(self):
module_globals = { module_globals = {
'__salt__': { '__salt__': {
'config.option': MagicMock(return_value={ 'config.option': MagicMock(return_value={
'test': { 'test': {
 End of changes. 3 change blocks. 
55 lines changed or deleted 64 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)