def test_cnos_system_name_servers(self): set_module_args(dict(name_servers=['1.2.3.4', '8.8.8.8'])) commands = [ 'ip name-server 1.2.3.4 vrf default', 'ip name-server 8.8.8.8 vrf default' ] self.execute_module(changed=True, commands=commands)
def test_cnos_user_update_password_changed(self): set_module_args( dict(name='test', configured_password='******', update_password='******')) commands = ['username test', 'username test password test'] self.execute_module(changed=True, commands=commands)
def test_cnos_interface_mtu_out_of_range(self, *args, **kwargs): set_module_args(dict(name='Ethernet0/2', mtu=15000)) result = self.execute_module(failed=True) self.assertEqual(result, { 'msg': 'mtu must be between 64 and 9216', 'failed': True })
def test_cnos_user_update_password_always(self): set_module_args( dict(name='ansible', configured_password='******', update_password='******')) commands = ['username ansible', 'username ansible password test'] self.execute_module(changed=True, commands=commands)
def test_cnos_static_route_change(self): set_module_args( dict(prefix='10.10.30.64', mask='255.255.255.0', next_hop='1.2.4.8')) self.execute_module( changed=True, commands=['ip route 10.10.30.64 255.255.255.0 1.2.4.8 1'])
def test_cnos_facts_gather_subset_config(self): set_module_args({'gather_subset': 'config'}) result = self.execute_module() ansible_facts = result['ansible_facts'] self.assertIn('default', ansible_facts['ansible_net_gather_subset']) self.assertIn('config', ansible_facts['ansible_net_gather_subset']) self.assertEqual('ip10-241-107-39', ansible_facts['ansible_net_hostname']) self.assertIn('ansible_net_config', ansible_facts)
def test_cnos_vlan_rename(self): set_module_args({'vlan_id': '2', 'name': 'test', 'state': 'present'}) result = self.execute_module(changed=True) expected_commands = [ 'vlan 2', 'name test', ] self.assertEqual(result['commands'], expected_commands)
def test_cnos_static_route_present(self): set_module_args( dict(prefix='10.241.107.20', mask='255.255.255.0', next_hop='10.241.106.1')) self.execute_module( changed=True, commands=['ip route 10.241.107.20 255.255.255.0 10.241.106.1 1'])
def test_cnos_user_role(self): set_module_args( dict(name='ansible', role='network-admin', configured_password='******')) result = self.execute_module(changed=True) self.assertIn('username ansible role network-admin', result['commands'])
def test_cnos_config_match_exact(self): lines = [ 'ip address 1.2.3.4 255.255.255.0', 'description test string', 'no shutdown' ] parents = ['interface ethernet 1/13'] set_module_args(dict(lines=lines, parents=parents, match='exact')) commands = parents + lines self.execute_module(changed=True, commands=commands, sort=False)
def test_cnos_interface_mtu(self, *args, **kwargs): set_module_args(dict(name='Ethernet1/2', mtu=1548)) result = self.execute_module(changed=True) self.assertEqual( result, { 'commands': ['interface Ethernet1/2', 'duplex auto', 'mtu 1548'], 'changed': True })
def test_cnos_interface_speed(self, *args, **kwargs): set_module_args(dict(name='Ethernet1/2', speed=1000)) result = self.execute_module(changed=True) self.assertEqual( result, { 'commands': ['interface Ethernet1/2', 'speed 1000', 'duplex auto'], 'changed': True })
def test_cnos_static_route_absent(self): set_module_args( dict(prefix='10.10.30.12', mask='255.255.255.0', next_hop='1.2.4.8', state='absent')) self.execute_module( changed=True, commands=['no ip route 10.10.30.12 255.255.255.0 1.2.4.8 1'])
def test_cnos_banner_create(self): for banner_type in ('login', 'motd'): set_module_args( dict(banner=banner_type, text='test\nbanner\nstring')) commands = [ 'banner {0} test'.format(banner_type), 'banner {0} banner'.format(banner_type), 'banner {0} string'.format(banner_type) ] self.execute_module(changed=True, commands=commands)
def test_cnos_interface_enabled(self, *args, **kwargs): set_module_args(dict(name='Ethernet1/44', enabled=True)) result = self.execute_module(changed=True) self.assertEqual( result, { 'commands': ['interface Ethernet1/44', 'duplex auto', 'no shutdown'], 'changed': True })
def test_cnos_facts_gather_subset_default(self): set_module_args(dict()) result = self.execute_module() ansible_facts = result['ansible_facts'] self.assertIn('hardware', ansible_facts['ansible_net_gather_subset']) self.assertIn('default', ansible_facts['ansible_net_gather_subset']) self.assertIn('interfaces', ansible_facts['ansible_net_gather_subset']) self.assertEqual('ip10-241-107-39', ansible_facts['ansible_net_hostname']) self.assertIn('Ethernet1/1', ansible_facts['ansible_net_interfaces'].keys()) self.assertEqual(3985.8046875, ansible_facts['ansible_net_memtotal_mb']) self.assertEqual(3070.40234375, ansible_facts['ansible_net_memfree_mb'])
def test_cnos_static_route_present_no_defaults(self): set_module_args( dict(prefix='10.241.106.4', mask='255.255.255.0', next_hop='1.2.3.5', description='testing', admin_distance=100)) self.execute_module( changed=True, commands=[ 'ip route 10.241.106.4 255.255.255.0 1.2.3.5 100 description testing' ])
def test_cnos_interface_description(self, *args, **kwargs): set_module_args(dict(name='Ethernet1/2', description='show version')) result = self.execute_module(changed=True) self.assertEqual( result, { 'commands': [ 'interface Ethernet1/2', 'description show version', 'duplex auto' ], 'changed': True })
def test_cnos_vlag_enable(self): set_module_args({ 'username': '******', 'password': '******', 'host': '10.241.107.39', 'deviceType': 'g8272_cnos', 'outputfile': self.test_log, 'vlagArg1': 'enable' }) result = self.execute_module(changed=True) expected_result = 'VLAG configurations accomplished' self.assertEqual(result['msg'], expected_result)
def test_cnos_lldp_absent(self, *args, **kwargs): set_module_args(dict(state='absent')) result = self.execute_module(changed=True) self.assertEqual( result, { 'commands': [ 'interface ethernet 1/1-54', 'no lldp receive', 'no lldp transmit', 'exit', 'interface mgmt 0', 'no lldp receive', 'no lldp transmit', 'exit' ], 'changed': True })
def test_cnos_bgp_vrf(self): set_module_args({ 'username': '******', 'password': '******', 'host': '10.241.107.39', 'deviceType': 'g8272_cnos', 'outputfile': self.test_log, 'asNum': '33', 'bgpArg1': 'vrf' }) result = self.execute_module(changed=True) expected_result = 'BGP configurations accomplished' self.assertEqual(result['msg'], expected_result)
def test_cnos_l2_interface_vlan_does_not_exist(self, *args, **kwargs): set_module_args( dict( name='Ethernet 1/33', mode='access', access_vlan=10, )) result = self.execute_module(failed=True) self.assertEqual( result, { 'msg': 'You are trying to configure a VLAN on an interface ' 'that\ndoes not exist on the switch yet!', 'failed': True, 'vlan': '10' })
def test_cnos_l2_interface_access_vlan(self, *args, **kwargs): set_module_args( dict( name='Ethernet 1/33', mode='access', access_vlan=13, )) result = self.execute_module(changed=True) self.assertEqual( result, { 'commands': ['interface ethernet 1/33', 'switchport access vlan 13'], 'changed': True, 'warnings': [] })
def test_cnos_l2_interface_incorrect_state(self, *args, **kwargs): set_module_args( dict( name='Ethernet 1/44', mode='access', access_vlan=10, )) result = self.execute_module(failed=True) self.assertEqual( result, { 'msg': 'Ensure interface is configured to be a L2\nport first ' 'before using this module. You can use\nthe cnos_' 'interface module for this.', 'failed': True })
def test_cnos_bgp_network(self): set_module_args({ 'username': '******', 'password': '******', 'host': '10.241.107.39', 'deviceType': 'g8272_cnos', 'outputfile': self.test_log, 'asNum': '33', 'bgpArg1': 'address-family', 'bgpArg2': 'ipv4', 'bgpArg3': 'network', 'bgpArg4': '1.2.3.4/5', 'bgpArg5': 'backdoor' }) result = self.execute_module(changed=True) expected_result = 'BGP configurations accomplished' self.assertEqual(result['msg'], expected_result)
def test_cnos_l2_interface_trunk(self, *args, **kwargs): set_module_args( dict(name='Ethernet 1/45', mode='trunk', native_vlan='12', trunk_allowed_vlans='13,12')) result = self.execute_module(changed=True) self.assertEqual( result, { 'commands': [ 'interface ethernet 1/45', 'switchport mode trunk', 'switchport trunk allowed vlan 13,12', 'switchport trunk native vlan 12' ], 'changed': True, 'warnings': [] })
def test_cnos_vlan_with_interfaces(self): set_module_args({ 'vlan_id': '2', 'name': 'vlan2', 'state': 'present', 'interfaces': ['Ethernet1/33', 'Ethernet1/44'] }) result = self.execute_module(changed=True) expected_commands = [ 'vlan 2', 'name vlan2', 'vlan 2', 'interface Ethernet1/33', 'switchport mode access', 'switchport access vlan 2', 'vlan 2', 'interface Ethernet1/44', 'switchport mode access', 'switchport access vlan 2', ] self.assertEqual(result['commands'], expected_commands)
def test_cnos_user_delete(self): set_module_args(dict(name='ansible', state='absent')) commands = [] self.execute_module(changed=False, commands=commands)
def test_cnos_user_purge(self): set_module_args(dict(purge=True)) commands = ['no username admin\n', 'no username ansible\n'] self.execute_module(changed=True, commands=commands)
def test_cnos_user_sshkey(self): set_module_args(dict(name='ansible', sshkey='test')) commands = ['username ansible', 'username ansible sshkey test'] self.execute_module(changed=True, commands=commands)