Beispiel #1
0
    def _test_dnsmasq_execute(self, extra_expected=None):
        network_ref = {'id': 'fake',
                       'label': 'fake',
                       'gateway': '10.0.0.1',
                       'multi_host': False,
                       'cidr': '10.0.0.0/24',
                       'netmask': '255.255.255.0',
                       'dns1': '8.8.4.4',
                       'dhcp_start': '1.0.0.2',
                       'dhcp_server': '10.0.0.1',
                       'share_address': False}

        def fake_execute(*args, **kwargs):
            executes.append(args)
            return "", ""

        def fake_add_dhcp_mangle_rule(*args, **kwargs):
            executes.append(args)

        self.stubs.Set(linux_net, '_execute', fake_execute)
        self.stubs.Set(linux_net, '_add_dhcp_mangle_rule',
                       fake_add_dhcp_mangle_rule)

        self.stubs.Set(os, 'chmod', lambda *a, **kw: None)
        self.stubs.Set(linux_net, 'write_to_file', lambda *a, **kw: None)
        self.stubs.Set(linux_net, '_dnsmasq_pid_for', lambda *a, **kw: None)
        dev = 'br100'

        default_domain = CONF.dhcp_domain
        for domain in ('', default_domain):
            executes = []
            self.flags(dhcp_domain=domain)
            fixedips = self._get_fixedips(network_ref)
            linux_net.restart_dhcp(self.context, dev, network_ref, fixedips)
            expected = ['env',
            'CONFIG_FILE=%s' % jsonutils.dumps(CONF.dhcpbridge_flagfile),
            'NETWORK_ID=fake',
            'dnsmasq',
            '--strict-order',
            '--bind-interfaces',
            '--conf-file=%s' % CONF.dnsmasq_config_file,
            '--pid-file=%s' % linux_net._dhcp_file(dev, 'pid'),
            '--dhcp-optsfile=%s' % linux_net._dhcp_file(dev, 'opts'),
            '--listen-address=%s' % network_ref['dhcp_server'],
            '--except-interface=lo',
            "--dhcp-range=set:%s,%s,static,%s,%ss" % (network_ref['label'],
                                                    network_ref['dhcp_start'],
                                                    network_ref['netmask'],
                                                    CONF.dhcp_lease_time),
            '--dhcp-lease-max=256',
            '--dhcp-hostsfile=%s' % linux_net._dhcp_file(dev, 'conf'),
            '--dhcp-script=%s' % CONF.dhcpbridge,
            '--leasefile-ro']

            if CONF.dhcp_domain:
                expected.append('--domain=%s' % CONF.dhcp_domain)

            if extra_expected:
                expected += extra_expected
            self.assertEqual([(dev,), tuple(expected)], executes)
Beispiel #2
0
    def _test_dnsmasq_execute(self, extra_expected=None):
        network_ref = {
            'id': 'fake',
            'label': 'fake',
            'gateway': '10.0.0.1',
            'multi_host': False,
            'cidr': '10.0.0.0/24',
            'netmask': '255.255.255.0',
            'dns1': '8.8.4.4',
            'dhcp_start': '1.0.0.2',
            'dhcp_server': '10.0.0.1',
            'share_address': False
        }

        def fake_execute(*args, **kwargs):
            executes.append(args)
            return "", ""

        def fake_add_dhcp_mangle_rule(*args, **kwargs):
            executes.append(args)

        self.stubs.Set(linux_net, '_execute', fake_execute)
        self.stubs.Set(linux_net, '_add_dhcp_mangle_rule',
                       fake_add_dhcp_mangle_rule)

        self.stubs.Set(os, 'chmod', lambda *a, **kw: None)
        self.stubs.Set(linux_net, 'write_to_file', lambda *a, **kw: None)
        self.stubs.Set(linux_net, '_dnsmasq_pid_for', lambda *a, **kw: None)
        dev = 'br100'

        default_domain = CONF.dhcp_domain
        for domain in ('', default_domain):
            executes = []
            self.flags(dhcp_domain=domain)
            fixedips = self._get_fixedips(network_ref)
            linux_net.restart_dhcp(self.context, dev, network_ref, fixedips)
            expected = [
                'env',
                'CONFIG_FILE=%s' % jsonutils.dumps(CONF.dhcpbridge_flagfile),
                'NETWORK_ID=fake', 'dnsmasq', '--strict-order',
                '--bind-interfaces',
                '--conf-file=%s' % CONF.dnsmasq_config_file,
                '--pid-file=%s' % linux_net._dhcp_file(dev, 'pid'),
                '--dhcp-optsfile=%s' % linux_net._dhcp_file(dev, 'opts'),
                '--listen-address=%s' % network_ref['dhcp_server'],
                '--except-interface=lo',
                "--dhcp-range=set:%s,%s,static,%s,%ss" %
                (network_ref['label'], network_ref['dhcp_start'],
                 network_ref['netmask'], CONF.dhcp_lease_time),
                '--dhcp-lease-max=256',
                '--dhcp-hostsfile=%s' % linux_net._dhcp_file(dev, 'conf'),
                '--dhcp-script=%s' % CONF.dhcpbridge, '--leasefile-ro'
            ]

            if CONF.dhcp_domain:
                expected.append('--domain=%s' % CONF.dhcp_domain)

            if extra_expected:
                expected += extra_expected
            self.assertEqual([(dev, ), tuple(expected)], executes)
Beispiel #3
0
    def _test_dnsmasq_execute(self, extra_expected=None):
        network_ref = {
            "id": "fake",
            "label": "fake",
            "multi_host": False,
            "cidr": "10.0.0.0/24",
            "netmask": "255.255.255.0",
            "dns1": "8.8.4.4",
            "dhcp_start": "1.0.0.2",
            "dhcp_server": "10.0.0.1",
        }

        def fake_execute(*args, **kwargs):
            executes.append(args)
            return "", ""

        self.stubs.Set(linux_net, "_execute", fake_execute)

        self.stubs.Set(os, "chmod", lambda *a, **kw: None)
        self.stubs.Set(linux_net, "write_to_file", lambda *a, **kw: None)
        self.stubs.Set(linux_net, "_dnsmasq_pid_for", lambda *a, **kw: None)
        dev = "br100"

        default_domain = CONF.dhcp_domain
        for domain in ("", default_domain):
            executes = []
            CONF.dhcp_domain = domain
            linux_net.restart_dhcp(self.context, dev, network_ref)
            expected = [
                "env",
                "CONFIG_FILE=%s" % jsonutils.dumps(CONF.dhcpbridge_flagfile),
                "NETWORK_ID=fake",
                "dnsmasq",
                "--strict-order",
                "--bind-interfaces",
                "--conf-file=%s" % CONF.dnsmasq_config_file,
                "--pid-file=%s" % linux_net._dhcp_file(dev, "pid"),
                "--listen-address=%s" % network_ref["dhcp_server"],
                "--except-interface=lo",
                "--dhcp-range=set:%s,%s,static,%s,%ss"
                % (network_ref["label"], network_ref["dhcp_start"], network_ref["netmask"], CONF.dhcp_lease_time),
                "--dhcp-lease-max=256",
                "--dhcp-hostsfile=%s" % linux_net._dhcp_file(dev, "conf"),
                "--dhcp-script=%s" % CONF.dhcpbridge,
                "--leasefile-ro",
            ]

            if CONF.dhcp_domain:
                expected.append("--domain=%s" % CONF.dhcp_domain)

            if extra_expected:
                expected += extra_expected
            self.assertEqual([tuple(expected)], executes)
Beispiel #4
0
    def _test_dnsmasq_execute(self, extra_expected=None):
        network_ref = {'id': 'fake',
                       'label': 'fake',
                       'multi_host': False,
                       'cidr': '10.0.0.0/24',
                       'dns1': '8.8.4.4',
                       'dhcp_start': '1.0.0.2',
                       'dhcp_server': '10.0.0.1'}
        executes = []

        def fake_execute(*args, **kwargs):
            executes.append(args)
            return "", ""

        self.stubs.Set(linux_net, '_execute', fake_execute)

        self.stubs.Set(os, 'chmod', lambda *a, **kw: None)
        self.stubs.Set(linux_net, 'write_to_file', lambda *a, **kw: None)
        self.stubs.Set(linux_net, '_dnsmasq_pid_for', lambda *a, **kw: None)
        dev = 'br100'
        linux_net.restart_dhcp(self.context, dev, network_ref)
        expected = ['env',
          'CONFIG_FILE=%s' % jsonutils.dumps(CONF.dhcpbridge_flagfile),
          'NETWORK_ID=fake',
          'dnsmasq',
          '--strict-order',
          '--bind-interfaces',
          '--conf-file=%s' % CONF.dnsmasq_config_file,
          '--domain=%s' % CONF.dhcp_domain,
          '--pid-file=%s' % linux_net._dhcp_file(dev, 'pid'),
          '--listen-address=%s' % network_ref['dhcp_server'],
          '--except-interface=lo',
          "--dhcp-range=set:'%s',%s,static,%ss" % (network_ref['label'],
                                                   network_ref['dhcp_start'],
                                                   CONF.dhcp_lease_time),
          '--dhcp-lease-max=256',
          '--dhcp-hostsfile=%s' % linux_net._dhcp_file(dev, 'conf'),
          '--dhcp-script=%s' % CONF.dhcpbridge,
          '--leasefile-ro']
        if extra_expected:
            expected += extra_expected
        self.assertEqual([tuple(expected)], executes)