Example #1
0
def test_execmd_out_of_session():
    """
    Assert that config commands are not performed if vyos session is not set up
    """
    #teardown session because it is yet set up by setup_module()
    args = ['show','nat','source']
    session.teardown_config_session()
    #execmd would fail. Otherwise, there is a bug :p
    with pytest.raises(SessionNotExists) as e:
        handler = execUtils(args)
        handler.execmd()
    assert e.value.message == 'Configure session do not exists'
    #resetup session to continue executing remaining tests 
    session.setup_config_session()
Example #2
0
def test_execmd_out_of_session():
    """
    Assert that config commands are not performed if vyos session is not set up
    """
    #teardown session because it is yet set up by setup_module()
    args = ['show', 'nat', 'source']
    session.teardown_config_session()
    #execmd would fail. Otherwise, there is a bug :p
    with pytest.raises(SessionNotExists) as e:
        handler = execUtils(args)
        handler.execmd()
    assert e.value.message == 'Configure session do not exists'
    #resetup session to continue executing remaining tests
    session.setup_config_session()
Example #3
0
def test_not_in_session():
    """
    Assert that teardown_sesstion() fails whether session dosn't exist
    """
    assert session.teardown_config_session()
    assert not session.teardown_config_session()
    assert session.setup_config_session() == True
def test_not_in_session():
    """
    Assert that teardown_sesstion() fails whether session dosn't exist
    """
    assert session.teardown_config_session()
    assert not session.teardown_config_session()
    assert session.setup_config_session() == True    
Example #5
0
def test_setup_session():
    """
    Test if vyos session is set up correctely. Check also if environment variables are exists.
    """
    assert session.setup_config_session() == True

    for env_var in session.session_envs.keys():
        assert session.session_envs.get(env_var) == os.environ.get(env_var)
def test_setup_session():
    """
    Test if vyos session is set up correctely. Check also if environment variables are exists.
    """
    assert session.setup_config_session() == True

    for env_var in session.session_envs.keys():
        assert session.session_envs.get(env_var) == os.environ.get(env_var)
Example #7
0
            return False
        return self.nat_config(action,type,suffix)

    def nat_translation_addr_port(self,action,type,rule_num,trans_addr_port):
        if vld.testip(trans_addr_port):
            suffix=[rule_num,"translation address",trans_addr_port]
        elif str(trans_addr_port).isdigit():
            suffix=[rule_num,"translation port",trans_addr_port]
        else:
            logger.error("%s: unknown type either it is an ip address or a port number in translation operation!"%addr_port)
            return False
        return self.nat_config(action,type,suffix)

    def nat_protocol(self,action,type,rule_num,prot="all"):
        suffix=[rule_num,"protocol",prot]
        return self.nat_config(action,type,suffix)

"""
session.setup_config_session()
obj=natHandler()
#obj.nat_interfaces('set','destination','444','inbound-interface','eth1')
#obj.nat_filter_addr_port('set','destination','444','source','192.168.2.0')
#obj.nat_filter_addr_port('delete','destination','444','source','80')
#obj.nat_protocol('delete','destination','444','tcp')
#obj.nat_translation_addr_port('delete','destination','444','8080')
#obj.nat_translation_addr_port('set','destination','444','10.0.0.1')
#obj.del_nat_rule('destination','444')
session.commit()
session.teardown_config_session()
"""
Example #8
0
            addr_params.extend(["next-hop", nexthop])
        return self.route("set", "route", addr_params)

    def delete_addr_route(self, dst_subnet):
        if not vld.testip(dst_subnet):
            return False
        return self.route("delete", "route", dst_subnet + "/24")

    def set_interface_route(self, dst_subnet, next_iface):
        if not vld.testip(dst_subnet) or not vld.testiface(next_iface):
            return False
        interface_params = [
            dst_subnet + "/24", "next-hop-interface", next_iface
        ]
        return self.route("set", "interface-route", interface_params)

    def delete_interface_route(self, dst_subnet):
        if not vld.testip(dst_subnet):
            return False
        return self.route("delete", "interface-route", dst_subnet + "/24")


"""
session.setup_config_session()
obj = routingHandler()
obj.add_addr_route("192.168.2.0","192.168.2.1")
obj.set_interface_route("192.168.2.0","vtun0")
session.commit()
session.teardown_config_session()
"""
Example #9
0
def setup_module(module):
    """
    Set up a config session
    """
    session.setup_config_session()
Example #10
0
def setup_module(module):
    """
    Set up a config session
    """
    session.setup_config_session()