Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libcloud DNS module fix #34628

Merged
merged 4 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions salt/modules/libcloud_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def __virtual__():

def __init__(opts):
salt.utils.compat.pack_dunder(__name__)
if HAS_LIBCLOUD:
__utils__['libcloud.assign_funcs'](__name__, 'dns', pack=__salt__)


def _get_driver(profile):
Expand All @@ -73,7 +71,7 @@ def _get_driver(profile):
key = config.get('key')
secret = config.get('secret', None)
secure = config.get('secure', True)
host = config.get('jost', None)
host = config.get('host', None)
port = config.get('port', None)
return cls(key, secret, secure, host, port)

Expand Down
70 changes: 70 additions & 0 deletions tests/unit/modules/libcloud_dns_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Anthony Shaw <anthonyshaw@apache.org>`
'''

# Import Python Libs
from __future__ import absolute_import

# Import Salt Testing Libs
from salttesting import skipIf
from tests.unit import ModuleTestCase, hasDependency
from salttesting.mock import (
patch,
MagicMock,
NO_MOCK,
NO_MOCK_REASON
)
from salttesting.helpers import ensure_in_syspath
from salt.modules import libcloud_dns

ensure_in_syspath('../../')

SERVICE_NAME = 'libcloud_dns'
libcloud_dns.__salt__ = {}
libcloud_dns.__utils__ = {}


class MockDNSDriver(object):
def __init__(self):
pass


def get_mock_driver():
return MockDNSDriver()


@skipIf(NO_MOCK, NO_MOCK_REASON)
@patch('salt.modules.libcloud_dns._get_driver',
MagicMock(return_value=MockDNSDriver()))
class LibcloudDnsModuleTestCase(ModuleTestCase):
def setUp(self):
hasDependency('libcloud')

def get_config(service):
if service == SERVICE_NAME:
return {
'test': {
'driver': 'test',
'key': '2orgk34kgk34g'
}
}
else:
raise KeyError("service name invalid")

self.setup_loader()
self.loader.set_result(libcloud_dns, 'config.option', get_config)

def test_module_creation(self, *args):
client = libcloud_dns._get_driver('test')
self.assertFalse(client is None)

def test_init(self):
with patch('salt.utils.compat.pack_dunder', return_value=False) as dunder:
libcloud_dns.__init__(None)
dunder.assert_called_with('salt.modules.libcloud_dns')


if __name__ == '__main__':
from unit import run_tests
run_tests(LibcloudDnsModuleTestCase)