def test_icx_command_match_any(self): wait_for = [ 'result[0] contains "ICX"', 'result[0] contains "test string"' ] set_module_args( dict(commands=['show version'], wait_for=wait_for, match='any')) self.execute_module()
def test_icx_logging_set_aggregate_remove(self): aggregate = [ dict(dest='host', name='172.16.10.55', udp_port=2500, facility='local0'), dict(dest='host', name='2001:db8::1', udp_port=5500) ] set_module_args(dict(aggregate=aggregate, state='absent')) if not self.ENV_ICX_USE_DIFF: result = self.execute_module(changed=True) expected_commands = [ 'no logging facility', 'no logging host 172.16.10.55 udp-port 2500', 'no logging host ipv6 2001:db8::1 udp-port 5500' ] self.assertEqual(result['commands'], expected_commands) else: result = self.execute_module(changed=True) expected_commands = [ 'no logging facility', 'no logging host 172.16.10.55 udp-port 2500', 'no logging host ipv6 2001:db8::1 udp-port 5500' ] self.assertEqual(result['commands'], expected_commands)
def test_icx_rate_limit_output_preset(self): set_module_args(dict(rate_limit_output=dict(port='1/1/2', value=500))) commands = [ 'interface ethernet 1/1/2', 'rate-limit output shaping 500' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_rate_limit_input_lag_absent(self): set_module_args( dict(rate_limit_input=dict( port='1/1/2', lag='LAG1', average_rate=500, state='absent'))) commands = ['lag LAG1', 'no rate-limit input fixed ethernet 1/1/2 500'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_acl_ip_extended_permit(self): ''' Test for successful extended acl ipV4 permit rule''' set_module_args( dict(acl_type='extended', acl_name='acl1', extended_rules=[ (dict(rule_type='permit', ip_protocol_name='ip', source=dict(host='yes', ip_address='1.1.1.1'), destination=dict(any='yes'), traffic_policy_name='policy1')), (dict(rule_type='permit', ip_protocol_name='icmp', source=dict(any='yes'), destination=dict(ip_address='1.1.1.1', mask='0.0.0.0'), icmp_num='25')), (dict(rule_type='permit', ip_protocol_name='tcp', source=dict(any='yes'), destination=dict(any='yes'), source_comparison_operators=dict(operator='eq', port_num='22'), destination_comparison_operators=dict( operator='range', port_name='ftp'))) ])) expected_commands = [ 'ip access-list extended acl1', 'permit ip host 1.1.1.1 any traffic-policy policy1', 'permit icmp any 1.1.1.1 0.0.0.0 25', 'permit tcp any eq 22 any range ftp' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx_rate_limit_output_lag_preset(self): set_module_args( dict(rate_limit_output=dict( port='1/1/2', lag='LAG1', value=500, state='present'))) commands = ['lag LAG1', 'rate-limit output shaping ethernet 1/1/2 500'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_invalid_args_default_acl(self): ''' Test for invalid in_out ''' set_module_args( dict(default_acl=dict( ip_type='ipv4', acl_name='guest', in_out='aa', state='present'))) result = self.execute_module(failed=True)
def test_icx_acl_assign_all_options_remove(self): ''' Test for removing acl assign with all options''' set_module_args( dict(ip_access_group=dict(acl_name='scale12', in_out='in', ethernet='1/1/3', mirror_port=dict(ethernet='3/1/10', state='absent'), logging='enable', state='absent'), ipv6_access_group=dict(acl_name='scale12', in_out='in', lag='7', state='absent'), mac_access_group=dict(mac_acl_name='mac_acl1', vlan=dict(vlan_num='10', interfaces=['ethernet 1/1/3' ]), logging='enable', state='absent'), default_acl=dict(ip_type='ipv4', acl_name='guest', in_out='in', state='absent'))) expected_commands = [ 'interface ethernet 1/1/3', 'no acl-mirror-port ethernet 3/1/10', 'no ip access-group scale12 in logging enable', 'exit', 'interface lag 7', 'no ipv6 access-group scale12 in', 'exit', 'vlan 10', 'no mac access-group mac_acl1 in ethernet 1/1/3 logging enable', 'exit', 'authentication', 'no default-acl ipv4 guest in', 'exit' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx__acl_ipv6_deny_ipv6_icmp(self): ''' Test for successful ipv6 and icmp deny rule''' set_module_args( dict( acl_name='acl1', rules=[ (dict(seq_num='10', rule_type='deny', ip_protocol_name='ipv6', source=dict(host_ipv6_address='2001:DB8:e0ac::2'), destination=dict(any='yes'), routing='yes', dscp_matching='21')), (dict( rule_type='deny', ip_protocol_name='icmp', source=dict(ipv6_prefix_prefix_length='2001:DB8::/64'), destination=dict(host_ipv6_address='2001:DB8:e0ac::2'), icmp_num='25')) ])) expected_commands = [ 'ipv6 access-list acl1', 'sequence 10 deny ipv6 host 2001:DB8:e0ac::2 any routing dscp-matching 21', 'deny icmp 2001:DB8::/64 host 2001:DB8:e0ac::2 25' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx_acl_ipv6_permit_ipv6_icmp(self): ''' Test for successful ipv6 and icmp permit rule''' set_module_args( dict( acl_name='acl1', rules=[ (dict(rule_type='permit', ip_protocol_name='ipv6', source=dict(host_ipv6_address='2001:DB8:e0ac::2'), destination=dict(any='yes'), routing='yes', priority_matching='6')), (dict( seq_num='20', rule_type='permit', ip_protocol_name='icmp', source=dict(ipv6_prefix_prefix_length='2001:DB8::/64'), destination=dict(host_ipv6_address='2001:DB8:e0ac::2'), icmp_num='25')) ])) expected_commands = [ 'ipv6 access-list acl1', 'permit ipv6 host 2001:DB8:e0ac::2 any routing 802.1p-priority-matching 6', 'sequence 20 permit icmp 2001:DB8::/64 host 2001:DB8:e0ac::2 25' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx_aaa_authentication_dot1x_enable(self): ''' Test for successful aaa authentication for dot1x and enable''' set_module_args(dict(dot1x=dict(primary_method='radius', state='present'), enable=dict(primary_method='enable', backup_method_list=['line', 'local'], state='present'))) expected_commands = ['aaa authentication dot1x default radius', 'aaa authentication enable default enable line local'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx_aaa_authorization_all_options_remove(self): ''' Test for removiong aaa authorization with all options''' set_module_args( dict(coa_enable='absent', coa_ignore=dict(request=[ 'dm-request', 'disable-port', 'flip-port', 'modify-acl', 'reauth-host' ], state='absent'), commands=dict(privilege_level=0, primary_method='radius', backup_method1='tacacs+', backup_method2='none', state='absent'), exec_=dict(primary_method='radius', backup_method1='tacacs+', backup_method2='none', state='absent'))) expected_commands = [ 'no aaa authorization coa enable', 'no aaa authorization coa ignore dm-request disable-port flip-port modify-acl reauth-host', 'no aaa authorization commands 0 default radius tacacs+ none', 'no aaa authorization exec default radius tacacs+ none' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx_aaa_authorization_invalid_args_exec_(self): ''' Test for invalid primary_method''' set_module_args( dict(exec_=dict(primary_method='aaa', backup_method1='tacacs+', state='present'))) result = self.execute_module(failed=True)
def test_icx_lldp_all_error(self): interfaces_spec = [dict(name=['ethernet all'], state='absent')] set_module_args(dict(interfaces=interfaces_spec, state='present')) if not self.ENV_ICX_USE_DIFF: self.execute_module(failed=True) else: self.execute_module(failed=True)
def test_icx_dscp_priority(self): set_module_args( dict(dscp_priority=dict( dscp_value='0 2 3 4', priority=1, state='present'))) commands = ['qos-tos map dscp-priority 0 2 3 4 to 1'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_scp_no_user(self): set_module_args( dict(upload='running-config', protocol='scp', remote_server='172.16.10.49', remote_filename='running.conf')) self.execute_module(failed=True)
def test_icx_internal_trunk_queue_absent(self): set_module_args( dict(internal_trunk_queue=dict( level='level6-1/3', queue=6, state='absent'))) commands = ['no qos-internal-trunk-queue level6-1/3 6'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_attach_egress_buffer_profile_preset(self): set_module_args( dict(attach_egress_buffer_profile=dict( port='1/1/3', profile_name='euser1', state='present'))) commands = ['interface ethernet 1/1/3', 'egress-buffer-profile euser1'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_monitor_queue_drop_counters_absent(self): set_module_args( dict(monitor_queue_drop_counters=dict(port_id='1/1/4', state='absent'))) commands = ['no qos monitor-queue-drop-counters 1/1/4'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_acl_mac_all_options(self): ''' Test for successful acl with all options''' set_module_args( dict(acl_name='mac123', accounting='enable', rule=[(dict(rule_type='permit', source=dict(any='yes'), destination=dict(any='yes'), ether_type='0800', log='yes', mirror='yes')), (dict(rule_type='permit', source=dict(source_mac_address='1111.2222.3333', source_mask='ffff.ffff.ffff'), destination=dict( destination_mac_address='4444.5555.6666', destination_mask='ffff.ffff.ffff'), ether_type='0800', log='yes', mirror='yes')), (dict(rule_type='permit', source=dict(source_mac_address='1111.2222.3333', source_mask='ffff.ffff.ffff'), destination=dict(any='yes'), ether_type='0800', log='yes', mirror='yes'))])) expected_commands = [ 'mac access-list mac123', 'enable accounting', 'permit any any ether-type 0800 log mirror', 'permit 1111.2222.3333 ffff.ffff.ffff 4444.5555.6666 ffff.ffff.ffff ether-type 0800 log mirror', 'permit 1111.2222.3333 ffff.ffff.ffff any ether-type 0800 log mirror' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx_egress_shape_ifg_bytes_present(self): set_module_args( dict(egress_shape_ifg_bytes=dict(value_in_bytes=25, state='present'))) commands = ['qos egress-shape-ifg-bytes 25'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_aaa_accounting_all_options_remove(self): ''' Test for removing aaa accounting with all options''' set_module_args( dict(commands=dict(privilege_level=0, primary_method='radius', backup_method1='tacacs+', backup_method2='none', state='absent'), dot1x=dict(primary_method='radius', backup_method1='none', state='absent'), exec_=dict(primary_method='radius', backup_method1='tacacs+', backup_method2='none', state='absent'), mac_auth=dict(primary_method='radius', backup_method1='none', state='absent'), system=dict(primary_method='radius', backup_method1='tacacs+', backup_method2='none', state='absent'), enable_console=dict(state='absent'))) expected_commands = [ 'no aaa accounting commands 0 default start-stop radius tacacs+ none', 'no aaa accounting dot1x default start-stop radius none', 'no aaa accounting exec default start-stop radius tacacs+ none', 'no aaa accounting mac-auth default start-stop radius none', 'no aaa accounting system default start-stop radius tacacs+ none', 'no enable aaa console' ] result = self.execute_module(changed=True) self.assertEqual(result['commands'], expected_commands)
def test_icx_system_set_config(self): set_module_args( dict(hostname='ruckus', name_servers=['172.16.10.2', '11.22.22.4'], domain_search=['ansible.com', 'redhat.com'])) if not self.ENV_ICX_USE_DIFF: commands = [ 'hostname ruckus', 'ip dns domain-list ansible.com', 'ip dns domain-list redhat.com', 'ip dns server-address 11.22.22.4', 'ip dns server-address 172.16.10.2', 'no ip dns domain-list ansib.eg.com', 'no ip dns domain-list red.com', 'no ip dns domain-list test1.com', 'no ip dns server-address 10.22.22.64', 'no ip dns server-address 172.22.22.64' ] self.execute_module(changed=True, commands=commands) else: commands = [ 'hostname ruckus', 'ip dns domain-list ansible.com', 'ip dns domain-list redhat.com', 'ip dns server-address 11.22.22.4', 'ip dns server-address 172.16.10.2' ] self.execute_module(changed=True, commands=commands)
def test_icx_aaa_accounting_invalid_args_mac_auth(self): ''' Test for invalid backup_method1''' set_module_args( dict(mac_auth=dict(primary_method='none', backup_method1='radius', state='present'))) result = self.execute_module(failed=True)
def test_icx_logging_compare(self): set_module_args( dict(dest='host', name='172.16.10.21', check_running_config=True)) if self.get_running_config(compare=True): if not self.ENV_ICX_USE_DIFF: self.execute_module(changed=False) else: self.execute_module(changed=False)
def test_icx_sflow_set_cpu_rate_limit_present(self): set_module_args( dict(sflow_set_cpu_rate_limit=dict( packet_rate='1000', burst_size='5000', state='present'))) commands = ['qos sflow-set-cpu-rate-limit 1000 5000'] result = self.execute_module(changed=True) self.assertEqual(result['commands'], commands)
def test_icx_aaa_accounting_invalid_args_commands(self): ''' Test for invalid privilege_level''' set_module_args( dict(commands=dict(privilege_level=2, primary_method='tacacs+', backup_method1='radius', state='present'))) result = self.execute_module(failed=True)
def test_icx_logging_remove_on(self): set_module_args(dict(dest='on', state='absent')) if not self.ENV_ICX_USE_DIFF: commands = ['no logging on'] self.exec_command(changed=True, commands=commands) else: commands = ['no logging on'] self.exec_command(changed=True, commands=commands)
def test_icx_logging_remove_console(self): set_module_args(dict(dest='console', state='absent')) if not self.ENV_ICX_USE_DIFF: commands = ['no logging console'] self.execute_module(changed=True, commands=commands) else: commands = ['no logging console'] self.execute_module(changed=True, commands=commands)
def test_icx_logging_set_host_udp_port(self): set_module_args(dict(dest='host', name='172.16.10.15', udp_port=2500)) if not self.ENV_ICX_USE_DIFF: commands = ['logging host 172.16.10.15 udp-port 2500'] self.execute_module(changed=True, commands=commands) else: commands = ['logging host 172.16.10.15 udp-port 2500'] self.execute_module(changed=True, commands=commands)