def test_module_args(mock_module,
                     mock_curr_config,
                     mock_desired_config,
                     mock_compare,
                     mock_replace,
                     mock_exists):
    """ cl_bridge - test module args """
    mock_exists.return_value = True
    cl_int.main()
    mock_module.assert_called_with(
        required_together=[['virtual_ip', 'virtual_mac']],
        argument_spec={
            'addr_method': {
                'type': 'str',
                'choices': ['', 'dhcp']},
            'name': {'required': True, 'type': 'str'},
            'ports': {'required': True, 'type': 'list'},
            'mtu': {'type': 'str'},
            'alias_name': {'type': 'str'},
            'ipv4': {'type': 'list'},
            'ipv6': {'type': 'list'},
            'virtual_mac': {'type': 'str'},
            'virtual_ip': {'type': 'str'},
            'vids': {'type': 'list'},
            'pvid': {'type': 'str'},
            'mstpctl_treeprio': {'type': 'str'},
            'stp': {'type': 'bool', 'default': 'yes', 'choices': [
                'yes', 'on', '1', 'true', 1, 'no', 'off', '0', 'false', 0]},
            'vlan_aware': {'type': 'bool', 'choices': ['yes', 'on', '1',
                           'true', 1, 'no', 'off', '0', 'false', 0]},
            'location': {'type': 'str', 'default': '/etc/network/interfaces.d'}}
    )
예제 #2
0
def test_module_args(mock_module,
                     mock_curr_config,
                     mock_desired_config,
                     mock_compare,
                     mock_replace,
                     mock_exists):
    """ cl_bridge - test module args """
    mock_exists.return_value = True
    cl_int.main()
    mock_module.assert_called_with(
        required_together=[['virtual_ip', 'virtual_mac']],
        argument_spec={
            'addr_method': {
                'type': 'str',
                'choices': ['', 'dhcp']},
            'name': {'required': True, 'type': 'str'},
            'ports': {'required': True, 'type': 'list'},
            'mtu': {'type': 'str'},
            'alias_name': {'type': 'str'},
            'ipv4': {'type': 'list'},
            'ipv6': {'type': 'list'},
            'virtual_mac': {'type': 'str'},
            'virtual_ip': {'type': 'str'},
            'vids': {'type': 'list'},
            'pvid': {'type': 'str'},
            'mstpctl_treeprio': {'type': 'str'},
            'mcsnoop': {'type': 'bool',
                        'choices': ['yes', 'on', '1', 'true', 1,
                                    'no', 'off', '0', 'false', 0]},
            'stp': {'type': 'bool', 'default': 'yes', 'choices': [
                'yes', 'on', '1', 'true', 1, 'no', 'off', '0', 'false', 0]},
            'vlan_aware': {'type': 'bool', 'choices': ['yes', 'on', '1',
                           'true', 1, 'no', 'off', '0', 'false', 0]},
            'location': {'type': 'str', 'default': '/etc/network/interfaces.d'}}
    )
def test_main_integration_test(mock_module,
                     mock_curr_config,
                     mock_desired_config,
                     mock_compare,
                     mock_replace, mock_exists):
    """ cl_bridge - basic integration test of main """
    mock_exists.return_value = True
    instance = mock_module.return_value
    # if config_changed == false. no change
    instance.params = {'name': 'swp1'}
    mock_compare.return_value = False
    cl_int.main()
    instance.exit_json.assert_called_with(
        msg='interface swp1 config not changed',
        changed=False)
    # if config_changed == true, change
    mock_compare.return_value = True
    cl_int.main()
    instance.exit_json.assert_called_with(
        msg='interface swp1 config updated',
        changed=True)
    # if location does not exist
    instance.params['location'] = '/etc/network/ansible'
    mock_exists.return_value = False
    cl_int.main()
    instance.fail_json.assert_called_with(msg='/etc/network/ansible does not exist.')
예제 #4
0
def test_main_integration_test(mock_module,
                               mock_curr_config,
                               mock_desired_config,
                               mock_compare,
                               mock_replace, mock_exists):
    """ cl_bridge - basic integration test of main """
    mock_exists.return_value = True
    instance = mock_module.return_value
    # if config_changed == false. no change
    instance.params = {'name': 'swp1'}
    mock_compare.return_value = False
    cl_int.main()
    instance.exit_json.assert_called_with(
        msg='interface swp1 config not changed',
        changed=False)
    # if config_changed == true, change
    mock_compare.return_value = True
    cl_int.main()
    instance.exit_json.assert_called_with(
        msg='interface swp1 config updated',
        changed=True)
    # if location does not exist
    instance.params['location'] = '/etc/network/ansible'
    mock_exists.return_value = False
    cl_int.main()
    instance.fail_json.assert_called_with(msg='/etc/network/ansible does not exist.')