<commit_before>#!/usr/bin/env python3
#
# Copyright (C) 2020 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import re
import os
import unittest

from vyos.configsession import ConfigSession
from vyos.configsession import ConfigSessionError
from vyos.ifconfig import Section
from vyos.template import address_from_cidr
from vyos.util import cmd
from vyos.util import process_named_running
from vyos.util import read_file

PROCESS_NAME = 'dhcrelay'
RELAY_CONF = '/run/dhcp-relay/dhcpv6.conf'
base_path = ['service', 'dhcpv6-relay']

upstream_if = 'eth0'
upstream_if_addr = '2001:db8::1/64'
listen_addr = '2001:db8:ffff::1/64'
interfaces = []

class TestServiceDHCPv6Relay(unittest.TestCase):
    def setUp(self):
        self.session = ConfigSession(os.getpid())
        for tmp in interfaces:
            listen = listen_addr
            if tmp == upstream_if:
                listen = upstream_if_addr
            self.session.set(['interfaces', 'ethernet', tmp, 'address', listen])

    def tearDown(self):
        self.session.delete(base_path)
        for tmp in interfaces:
            listen = listen_addr
            if tmp == upstream_if:
                listen = upstream_if_addr
            self.session.delete(['interfaces', 'ethernet', tmp, 'address', listen])

        self.session.commit()
        del self.session

    def test_relay_default(self):
        dhcpv6_server = '2001:db8::ffff'
        hop_count = '20'

        self.session.set(base_path + ['upstream-interface', upstream_if, 'address', dhcpv6_server])
        self.session.set(base_path + ['use-interface-id-option'])
        self.session.set(base_path + ['max-hop-count', hop_count])

        # add listener on all ethernet interfaces except the upstream interface
        for tmp in interfaces:<commit_msg>smoketest: dhcpv6-relay: T3095: verify the verify() section<commit_after>#!/usr/bin/env python3
#
# Copyright (C) 2020 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import re
import os
import unittest

from vyos.configsession import ConfigSession
from vyos.configsession import ConfigSessionError
from vyos.ifconfig import Section
from vyos.template import address_from_cidr
from vyos.util import cmd
from vyos.util import process_named_running
from vyos.util import read_file

PROCESS_NAME = 'dhcrelay'
RELAY_CONF = '/run/dhcp-relay/dhcpv6.conf'
base_path = ['service', 'dhcpv6-relay']

upstream_if = 'eth0'
upstream_if_addr = '2001:db8::1/64'
listen_addr = '2001:db8:ffff::1/64'
interfaces = []

class TestServiceDHCPv6Relay(unittest.TestCase):
    def setUp(self):
        self.session = ConfigSession(os.getpid())
        for tmp in interfaces:
            listen = listen_addr
            if tmp == upstream_if:
                listen = upstream_if_addr
            self.session.set(['interfaces', 'ethernet', tmp, 'address', listen])

    def tearDown(self):
        self.session.delete(base_path)
        for tmp in interfaces:
            listen = listen_addr
            if tmp == upstream_if:
                listen = upstream_if_addr
            self.session.delete(['interfaces', 'ethernet', tmp, 'address', listen])

        self.session.commit()
        del self.session

    def test_relay_default(self):
        dhcpv6_server = '2001:db8::ffff'
        hop_count = '20'

        self.session.set(base_path + ['use-interface-id-option'])
        self.session.set(base_path + ['max-hop-count', hop_count])

        # check validate() - Must set at least one listen and upstream
        # interface addresses.
        with self.assertRaises(ConfigSessionError):
            self.session.commit()
        self.session.set(base_path + ['upstream-interface', upstream_if, 'address', dhcpv6_server])

        # check validate() - Must set at least one listen and upstream
        # interface addresses.
        with self.assertRaises(ConfigSessionError):
            self.session.commit()

        # add listener on all ethernet interfaces except the upstream interface
        for tmp in interfaces:
{'fraction_non_alphanumeric': 0.09002338269680436, 'fraction_numerical': 0.01461418550272798, 'mean_word_length': 3.2491721854304636, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '929350', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1449, 'n_words': 477}