Add missing import, improve docs

This commit is contained in:
twangboy 2020-03-09 17:52:08 -06:00
parent 154257e2e9
commit 995975649a
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB
2 changed files with 26 additions and 12 deletions

View file

@ -12,8 +12,10 @@ import salt.utils.platform
try:
import wmi
import salt.utils.winapi
HAS_LIBS = True
except ImportError:
pass
HAS_LIBS = False
log = logging.getLogger(__name__)
@ -22,15 +24,25 @@ def __virtual__():
'''
Only works on Windows systems
'''
if salt.utils.platform.is_windows():
return 'win_dns_client'
return (False, "Module win_dns_client: module only works on Windows systems")
if not salt.utils.platform.is_windows():
return False, 'Module win_dns_client: module only works on Windows ' \
'systems'
if not HAS_LIBS:
return False, 'Module win_dns_client: missing required libraries'
return 'win_dns_client'
def get_dns_servers(interface='Local Area Connection'):
'''
Return a list of the configured DNS servers of the specified interface
Args:
interface (str): The name of the network interface. This is the name as
it appears in the Control Panel under Network Connections
Returns:
list: A list of dns servers
CLI Example:
.. code-block:: bash
@ -121,7 +133,14 @@ def dns_dhcp(interface='Local Area Connection'):
def get_dns_config(interface='Local Area Connection'):
'''
Get the type of DNS configuration (dhcp / static)
Get the type of DNS configuration (dhcp / static).
Args:
interface (str): The name of the network interface. This is the
Description in the Network Connection Details for the device
Returns:
bool: ``True`` if DNS is configured, otherwise ``False``
CLI Example:

View file

@ -10,11 +10,7 @@ import types
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
MagicMock,
patch,
Mock,
)
from tests.support.mock import MagicMock, patch, Mock
# Import Salt Libs
import salt.modules.win_dns_client as win_dns_client
@ -89,8 +85,7 @@ class WinDnsClientTestCase(TestCase, LoaderModuleMockMixin):
Test if it return a list of the configured DNS servers
of the specified interface.
'''
with patch('salt.utils', Mockwinapi), \
patch('salt.utils.winapi.Com', MagicMock()), \
with patch('salt.utils.winapi.Com', MagicMock()), \
patch.object(self.WMI, 'Win32_NetworkAdapter',
return_value=[Mockwmi()]), \
patch.object(self.WMI, 'Win32_NetworkAdapterConfiguration',