Editing /etc/network/interfaces
The splitting / partitioning makes this very complicated and hard to follow. Instead of splitting and then putting the pieces back together, it would be vastly simpler to replace with a regex, for example:

import re


def set_mode(mode, iface, interfaces):
    """
    Set the mode for the specified interface
    :param mode: 'dhcp' or 'static'
    :param iface: name of the interface, for example eth1, eth2, ...
    :param interfaces: content of /etc/network/interfaces
    :return: updated content, to be saved in /etc/network/interfaces
    """
    iface_prefix = 'iface {} inet '.format(iface)
    iface_entry = iface_prefix + mode
    if iface_prefix in interfaces:
        interfaces = re.sub(iface_prefix + r'.*', iface_entry, interfaces)
    else:
        interfaces += '\n' + iface_entry
    return interfaces


For your sample file, the following gives me the same output with the original method and this new one:

with open('./interfaces') as fh:
    content = fh.read()
    print set_mode('static', 'eth8', content)
    print '---'
    print set_mode('dhcp', 'eth8', content)
    print '---'
    print set_mode('dhcp', 'eth1', content)


Coding style

The original code has several issues that violate PEP8, the official coding style guide of Python:


Use snake_case for function and variable names (that's why I renamed setMode to set_mode
Put spaces around operators: a=something instead of a = something
A docstring is strongly recommended for the set_mode function