mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
test/: PEP8 compliancy (#24803)
* test/: PEP8 compliancy - Make PEP8 compliant * Python3 chokes on casting int to bytes (#24952) But if we tell the formatter that the var is a number, it works
This commit is contained in:
committed by
John R Barker
parent
31c59ad5f9
commit
4efec414e7
@@ -14,13 +14,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import unittest
|
||||
from ansible.modules.network.cumulus import nclu
|
||||
|
||||
import sys
|
||||
import time
|
||||
from ansible.module_utils.basic import *
|
||||
import unittest
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.modules.network.cumulus import nclu
|
||||
|
||||
|
||||
class FakeModule(object):
|
||||
@@ -172,7 +171,6 @@ class TestNclu(unittest.TestCase):
|
||||
self.assertEqual(module.fail_code, {})
|
||||
self.assertEqual(changed, True)
|
||||
|
||||
|
||||
def test_command_atomic(self):
|
||||
module = FakeModule()
|
||||
changed, output = nclu.run_nclu(module,
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import os
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import patch
|
||||
@@ -35,6 +35,7 @@ def set_module_args(args):
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
@@ -56,13 +57,14 @@ def load_fixture(name):
|
||||
class AnsibleExitJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleFailJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestEosModule(unittest.TestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None,
|
||||
sort=True, defaults=False, transport='cli'):
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False, transport='cli'):
|
||||
|
||||
self.load_fixtures(commands, transport=transport)
|
||||
|
||||
@@ -110,4 +112,3 @@ class TestEosModule(unittest.TestCase):
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
pass
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.eos import eos_command
|
||||
from .eos_module import TestEosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestEosCommandModule(TestEosModule):
|
||||
|
||||
module = eos_command
|
||||
|
||||
@@ -71,7 +71,7 @@ class TestEosConfigModule(TestEosModule):
|
||||
|
||||
def test_eos_config_before(self):
|
||||
args = dict(lines=['hostname switch01', 'ip domain-name eng.ansible.com'],
|
||||
before=['before command'])
|
||||
before=['before command'])
|
||||
|
||||
set_module_args(args)
|
||||
|
||||
@@ -83,7 +83,7 @@ class TestEosConfigModule(TestEosModule):
|
||||
|
||||
def test_eos_config_after(self):
|
||||
args = dict(lines=['hostname switch01', 'ip domain-name eng.ansible.com'],
|
||||
after=['after command'])
|
||||
after=['after command'])
|
||||
|
||||
set_module_args(args)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.eos import eos_system
|
||||
from .eos_module import TestEosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestEosSystemModule(TestEosModule):
|
||||
|
||||
module = eos_system
|
||||
@@ -75,20 +76,20 @@ class TestEosSystemModule(TestEosModule):
|
||||
'ip domain lookup source-interface Ethernet1']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
#def test_eos_system_name_servers(self):
|
||||
# name_servers = ['8.8.8.8', '8.8.4.4']
|
||||
# set_module_args(dict(name_servers=name_servers))
|
||||
# commands = ['ip name-server 8.8.4.4',
|
||||
# 'no ip name-server vrf mgmt 8.8.4.4']
|
||||
# self.execute_module(changed=True, commands=commands)
|
||||
# def test_eos_system_name_servers(self):
|
||||
# name_servers = ['8.8.8.8', '8.8.4.4']
|
||||
# set_module_args(dict(name_servers=name_servers))
|
||||
# commands = ['ip name-server 8.8.4.4',
|
||||
# 'no ip name-server vrf mgmt 8.8.4.4']
|
||||
# self.execute_module(changed=True, commands=commands)
|
||||
|
||||
#def rest_eos_system_name_servers_complex(self):
|
||||
# name_servers = dict(server='8.8.8.8', vrf='test')
|
||||
# set_module_args(dict(name_servers=name_servers))
|
||||
# commands = ['ip name-server vrf test 8.8.8.8',
|
||||
# 'no ip name-server vrf default 8.8.8.8',
|
||||
# 'no ip name-server vrf mgmt 8.8.4.4']
|
||||
# self.execute_module(changed=True, commands=commands)
|
||||
# def rest_eos_system_name_servers_complex(self):
|
||||
# name_servers = dict(server='8.8.8.8', vrf='test')
|
||||
# set_module_args(dict(name_servers=name_servers))
|
||||
# commands = ['ip name-server vrf test 8.8.8.8',
|
||||
# 'no ip name-server vrf default 8.8.8.8',
|
||||
# 'no ip name-server vrf mgmt 8.8.4.4']
|
||||
# self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_eos_system_state_absent(self):
|
||||
set_module_args(dict(state='absent'))
|
||||
@@ -104,4 +105,3 @@ class TestEosSystemModule(TestEosModule):
|
||||
name_servers = dict(server='8.8.8.8', vrf='missing')
|
||||
set_module_args(dict(name_servers=name_servers))
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
|
||||
@@ -95,5 +95,3 @@ class TestEosUserModule(TestEosModule):
|
||||
set_module_args(dict(username='ansible', password='test', update_password='always'))
|
||||
commands = ['username ansible secret test']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ def set_module_args(args):
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
@@ -56,13 +57,14 @@ def load_fixture(name):
|
||||
class AnsibleExitJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleFailJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestIosModule(unittest.TestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None,
|
||||
sort=True, defaults=False):
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
||||
|
||||
self.load_fixtures(commands)
|
||||
|
||||
@@ -110,4 +112,3 @@ class TestIosModule(unittest.TestCase):
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
pass
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ class TestIosBannerModule(TestIosModule):
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.exec_command.return_value = (0,
|
||||
load_fixture('ios_banner_show_banner.txt').strip(), None)
|
||||
self.exec_command.return_value = (0, load_fixture('ios_banner_show_banner.txt').strip(), None)
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def test_ios_banner_create(self):
|
||||
|
||||
@@ -25,6 +25,7 @@ from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.ios import ios_command
|
||||
from .ios_module import TestIosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestIosCommandModule(TestIosModule):
|
||||
|
||||
module = ios_command
|
||||
|
||||
@@ -89,19 +89,19 @@ class TestIosConfigModule(TestIosModule):
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_ios_config_before(self):
|
||||
set_module_args(dict(lines=['hostname foo'], before=['test1','test2']))
|
||||
set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
|
||||
commands = ['test1', 'test2', 'hostname foo']
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_ios_config_after(self):
|
||||
set_module_args(dict(lines=['hostname foo'], after=['test1','test2']))
|
||||
set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
|
||||
commands = ['hostname foo', 'test1', 'test2']
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_ios_config_before_after_no_change(self):
|
||||
set_module_args(dict(lines=['hostname router'],
|
||||
before=['test1', 'test2'],
|
||||
after=['test3','test4']))
|
||||
after=['test3', 'test4']))
|
||||
self.execute_module()
|
||||
|
||||
def test_ios_config_config(self):
|
||||
|
||||
@@ -51,7 +51,6 @@ class TestIosSystemModule(TestIosModule):
|
||||
commands = ['hostname foo']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
|
||||
def test_ios_system_domain_name(self):
|
||||
set_module_args(dict(domain_name=['test.com']))
|
||||
commands = ['ip domain name test.com',
|
||||
@@ -120,4 +119,3 @@ class TestIosSystemModule(TestIosModule):
|
||||
name_servers = dict(server='8.8.8.8', vrf='missing')
|
||||
set_module_args(dict(name_servers=name_servers))
|
||||
self.execute_module(failed=True)
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.ios import _ios_template
|
||||
from .ios_module import TestIosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestIosTemplateModule(TestIosModule):
|
||||
|
||||
module = _ios_template
|
||||
|
||||
@@ -122,5 +122,3 @@ class TestIosVrfModule(TestIosModule):
|
||||
commands = ['no vrf definition test_1', 'vrf definition test_2',
|
||||
'description test string']
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ def set_module_args(args):
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
@@ -56,13 +57,14 @@ def load_fixture(name):
|
||||
class AnsibleExitJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleFailJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestIosxrModule(unittest.TestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None,
|
||||
sort=True, defaults=False):
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
||||
|
||||
self.load_fixtures(commands)
|
||||
|
||||
@@ -110,4 +112,3 @@ class TestIosxrModule(unittest.TestCase):
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
pass
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.iosxr import iosxr_config
|
||||
from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestIosxrConfigModule(TestIosxrModule):
|
||||
|
||||
module = iosxr_config
|
||||
@@ -73,19 +74,19 @@ class TestIosxrConfigModule(TestIosxrModule):
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_iosxr_config_before(self):
|
||||
set_module_args(dict(lines=['hostname foo'], before=['test1','test2']))
|
||||
set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
|
||||
commands = ['test1', 'test2', 'hostname foo']
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_iosxr_config_after(self):
|
||||
set_module_args(dict(lines=['hostname foo'], after=['test1','test2']))
|
||||
set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
|
||||
commands = ['hostname foo', 'test1', 'test2']
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_iosxr_config_before_after_no_change(self):
|
||||
set_module_args(dict(lines=['hostname router'],
|
||||
before=['test1', 'test2'],
|
||||
after=['test3','test4']))
|
||||
after=['test3', 'test4']))
|
||||
self.execute_module()
|
||||
|
||||
def test_iosxr_config_config(self):
|
||||
|
||||
@@ -66,8 +66,7 @@ class TestIosxrFacts(TestIosxrModule):
|
||||
self.assertIn('interfaces', ansible_facts['ansible_net_gather_subset'])
|
||||
self.assertEquals('iosxr01', ansible_facts['ansible_net_hostname'])
|
||||
self.assertEquals(['disk0:', 'flash0:'], ansible_facts['ansible_net_filesystems'])
|
||||
self.assertIn('GigabitEthernet0/0/0/0',
|
||||
ansible_facts['ansible_net_interfaces'].keys())
|
||||
self.assertIn('GigabitEthernet0/0/0/0', ansible_facts['ansible_net_interfaces'].keys())
|
||||
self.assertEquals('3095', ansible_facts['ansible_net_memtotal_mb'])
|
||||
self.assertEquals('1499', ansible_facts['ansible_net_memfree_mb'])
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class TestIosxrSystemModule(TestIosxrModule):
|
||||
|
||||
def test_iosxr_system_domain_search(self):
|
||||
set_module_args(dict(domain_search=['ansible.com', 'redhat.com']))
|
||||
commands=['domain list ansible.com', 'no domain list cisco.com']
|
||||
commands = ['domain list ansible.com', 'no domain list cisco.com']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_iosxr_system_lookup_source(self):
|
||||
@@ -78,14 +78,18 @@ class TestIosxrSystemModule(TestIosxrModule):
|
||||
|
||||
def test_iosxr_system_state_absent(self):
|
||||
set_module_args(dict(state='absent'))
|
||||
commands = ['no hostname', 'no domain name',
|
||||
'no domain lookup disable',
|
||||
'no domain lookup source-interface MgmtEth0/0/CPU0/0',
|
||||
'no domain list redhat.com', 'no domain list cisco.com',
|
||||
'no domain name-server 8.8.8.8', 'no domain name-server 8.8.4.4']
|
||||
commands = [
|
||||
'no hostname',
|
||||
'no domain name',
|
||||
'no domain lookup disable',
|
||||
'no domain lookup source-interface MgmtEth0/0/CPU0/0',
|
||||
'no domain list redhat.com',
|
||||
'no domain list cisco.com',
|
||||
'no domain name-server 8.8.8.8',
|
||||
'no domain name-server 8.8.4.4'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_iosxr_system_no_change(self):
|
||||
set_module_args(dict(hostname='iosxr01', domain_name='eng.ansible.com'))
|
||||
self.execute_module()
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ def set_module_args(args):
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
@@ -56,13 +57,14 @@ def load_fixture(name):
|
||||
class AnsibleExitJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleFailJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestNxosModule(unittest.TestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None,
|
||||
sort=True, defaults=False):
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
||||
|
||||
self.load_fixtures(commands)
|
||||
|
||||
@@ -110,4 +112,3 @@ class TestNxosModule(unittest.TestCase):
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
pass
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.nxos import nxos_command
|
||||
from .nxos_module import TestNxosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestNxosCommandModule(TestNxosModule):
|
||||
|
||||
module = nxos_command
|
||||
|
||||
@@ -73,7 +73,7 @@ class TestNxosConfigModule(TestNxosModule):
|
||||
|
||||
def test_nxos_config_before(self):
|
||||
args = dict(lines=['hostname switch01', 'ip domain-name eng.ansible.com'],
|
||||
before=['before command'])
|
||||
before=['before command'])
|
||||
|
||||
set_module_args(args)
|
||||
|
||||
@@ -85,7 +85,7 @@ class TestNxosConfigModule(TestNxosModule):
|
||||
|
||||
def test_nxos_config_after(self):
|
||||
args = dict(lines=['hostname switch01', 'ip domain-name eng.ansible.com'],
|
||||
after=['after command'])
|
||||
after=['after command'])
|
||||
|
||||
set_module_args(args)
|
||||
|
||||
@@ -134,6 +134,3 @@ class TestNxosConfigModule(TestNxosModule):
|
||||
set_module_args(args)
|
||||
result = self.execute_module()
|
||||
self.assertIn('__backup__', result)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -61,4 +61,3 @@ class TestNxosEvpnGlobalModule(TestNxosModule):
|
||||
set_module_args(dict(nv_overlay_evpn=False))
|
||||
commands = ['no nv overlay evpn']
|
||||
self.start_configured(changed=True, commands=commands)
|
||||
|
||||
|
||||
@@ -126,5 +126,3 @@ class TestNxosSystemModule(TestNxosModule):
|
||||
'vrf context management', 'no ip name-server 172.26.1.1', 'exit',
|
||||
'no system jumbomtu']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.vyos import vyos_command
|
||||
from .vyos_module import TestVyosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestVyosCommandModule(TestVyosModule):
|
||||
|
||||
module = vyos_command
|
||||
|
||||
@@ -35,6 +35,7 @@ def set_module_args(args):
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
@@ -56,14 +57,14 @@ def load_fixture(name):
|
||||
class AnsibleExitJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleFailJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestVyosModule(unittest.TestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None,
|
||||
sort=True, defaults=False):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
||||
self.load_fixtures(commands)
|
||||
|
||||
if failed:
|
||||
@@ -110,4 +111,3 @@ class TestVyosModule(unittest.TestCase):
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user