コード例 #1
0
ファイル: test_netcfg.py プロジェクト: maximerobin/Ufwi
def test_Netcfg():
    l = Logger("")
    n = NetCfgAutoConf(l)
    n.discover()
    s = n.serialize()
    netcfg =  deserialize(s)
    s2 = netcfg.serialize()

    assert s == s2, "buggy assertion"
コード例 #2
0
ファイル: ha_prune.py プロジェクト: maximerobin/Ufwi
def prune_ha_net(manager):
    try:
        net_serialized = manager._modified_configuration.get('network')
    except ConfigError:
        return False

    if net_serialized is None:
        return False

    netcfg = deserialize(net_serialized)

    try:
        deconfigureHA(netcfg)
    except NetCfgError:
        #nothing to do
        return False

    net_serialized = netcfg.serialize()

    for block in (manager._running_configuration, manager._modified_configuration):
        del block['network']
        block.fromDict('network', net_serialized)
    return True
コード例 #3
0
ファイル: templateRules.py プロジェクト: maximerobin/Ufwi
    def setup_class(cls):
        """
            This method is called once when the class is first instanciated. It
            sets up the testing conditions, while saving the current configuration.
        """
        Test.setup_class()

        cls.test_path = cls.results_path+cls.date+"/"+cls.__name__+"/"
        if not isdir(cls.test_path):
            makedirs(cls.test_path)

        # We save the configuration to restore it later
        serialized = cls.client.call('network', 'getNetconfig')
        cls.orig = deepcopy(serialized)

        # Let's tune the netconf to match our needs
        netcfg = deserialize(serialized)

        eth1 = netcfg.getInterfaceBySystemName('eth1')
        eth2 = netcfg.getInterfaceBySystemName('eth2')

        netcfg_bondings = set(netcfg.bondings)
        for bonding in netcfg_bondings:
            if eth1 in bonding.ethernets:
                netcfg.removeInterface(bonding)
                break
        netcfg.removeInterface(eth1)

        netcfg_bondings = set(netcfg.bondings)
        for bonding in netcfg_bondings:
            if eth2 in bonding.ethernets:
                netcfg.removeInterface(bonding)
                break
        netcfg.removeInterface(eth2)

        net1 = NetRW(
                    "Test1",
                    IP("192.168.16.0/24"),
                    service_ip_addrs=set(IP("192.168.16.1"))
                    )

        net2 = NetRW(
                    "Test2",
                    IP("192.168.17.0/24"),
                    service_ip_addrs=set(IP("192.168.17.1"))
                    )

        eth1.addNet(net1)
        eth2.addNet(net2)

        serialized = netcfg.serialize()

        cls.takeNuconfWriteRole()
        cls.client.call("network", "setNetconfig", serialized, "none")
        cls.apply_ufwi_conf()

        cls.should_have_resources = '<interface id=\"eth1\" name=\"eth1\">\n' \
            '         <network address=\"192.168.16.0/24\" id=\"Test1\" />\n' \
            '      </interface>\n' \
            '      <interface id=\"eth2\" name=\"eth2\">\n' \
            '         <network address=\"192.168.17.0/24\" id=\"Test2\" />\n' \
            '      </interface>'

        # We save the last applied ruleset name
        cls.origRuleset = None
        production_rules = cls.client.call('ufwi_ruleset', 'productionRules')
        if production_rules.has_key('ruleset'):
            cls.origRuleset = cls.client.call('ufwi_ruleset',
                                            'productionRules')['ruleset']

        # If the ruleset used exists, we delete it
        for ruleset in cls.client.call('ufwi_ruleset', 'rulesetList', 'ruleset'):
            if cls.ruleV4['name'] in ruleset:
                cls.client.call('ufwi_ruleset',
                                'rulesetDelete',
                                'ruleset',cls.ruleV4['name'])
                break

        # We create a new ruleset and name it
        cls.client.call('ufwi_ruleset', 'rulesetCreate', 'ruleset', '')

        # We create a user group
        user_group = {'group': '9000', 'id': 'tests'}
        cls.client.call('ufwi_ruleset',
                        'objectCreate',
                        'user_groups',
                        user_group,
                        False)

        # We add the rule
        cls.client.call('ufwi_ruleset',
                        'ruleCreate',
                        'acls-ipv4',
                        cls.ruleV4['rule'])

        # Save and apply the rule
        cls.client.call('ufwi_ruleset', 'rulesetSaveAs', cls.ruleV4['name'])
        cls.client.call('ufwi_ruleset', 'applyRules', 'True', 'True')
        cls.client.call('ufwi_ruleset', 'rulesetClose')
コード例 #4
0
ファイル: mockup.py プロジェクト: maximerobin/Ufwi
def init_qnetobject():
    q_netobject = QNetObject.getInstance()
    q_netobject.cfg = deserialize(a_netconfig)