def _spawn(self, logical_config, extra_cmd_args=()):
        pool_id = logical_config['pool']['id']
        namespace = get_ns_name(pool_id)
        conf_path = self._get_state_file_path(pool_id, 'conf')
        pid_path = self._get_state_file_path(pool_id, 'pid')
        sock_path = self._get_state_file_path(pool_id, 'sock')
        user_group = self.conf.haproxy.user_group

        hacfg.save_config(conf_path, logical_config, sock_path, user_group)
        cmd = ['haproxy', '-f', conf_path, '-p', pid_path]
        cmd.extend(extra_cmd_args)

        ns = ip_lib.IPWrapper(namespace=namespace)
        ns.netns.execute(cmd)

        # remember the pool<>port mapping
        self.pool_to_port_id[pool_id] = logical_config['vip']['port']['id']
Exemple #2
0
    def _spawn(self, logical_config, extra_cmd_args=()):
        pool_id = logical_config['pool']['id']
        namespace = get_ns_name(pool_id)
        conf_path = self._get_state_file_path(pool_id, 'conf')
        pid_path = self._get_state_file_path(pool_id, 'pid')
        sock_path = self._get_state_file_path(pool_id, 'sock')
        user_group = self.conf.haproxy.user_group

        hacfg.save_config(conf_path, logical_config, sock_path, user_group)
        cmd = ['haproxy', '-f', conf_path, '-p', pid_path]
        cmd.extend(extra_cmd_args)

        ns = ip_lib.IPWrapper(namespace=namespace)
        ns.netns.execute(cmd)

        # remember the pool<>port mapping
        self.pool_to_port_id[pool_id] = logical_config['vip']['port']['id']
Exemple #3
0
    def test_save_config(self):
        with mock.patch('neutron_lbaas.services.loadbalancer.'
                        'drivers.haproxy.cfg._build_global') as b_g, \
                mock.patch('neutron_lbaas.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_defaults') as b_d, \
                mock.patch('neutron_lbaas.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_frontend') as b_f, \
                mock.patch('neutron_lbaas.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_backend') as b_b, \
                mock.patch('neutron.common.utils.replace_file') as replace:
            test_config = ['globals', 'defaults', 'frontend', 'backend']
            b_g.return_value = [test_config[0]]
            b_d.return_value = [test_config[1]]
            b_f.return_value = [test_config[2]]
            b_b.return_value = [test_config[3]]

            cfg.save_config('test_path', mock.Mock())
            replace.assert_called_once_with('test_path',
                                            '\n'.join(test_config))
Exemple #4
0
    def test_save_config(self):
        with mock.patch('neutron_lbaas.services.loadbalancer.'
                        'drivers.haproxy.cfg._build_global') as b_g, \
                mock.patch('neutron_lbaas.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_defaults') as b_d, \
                mock.patch('neutron_lbaas.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_frontend') as b_f, \
                mock.patch('neutron_lbaas.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_backend') as b_b, \
                mock.patch('neutron.common.utils.replace_file') as replace:
            test_config = ['globals', 'defaults', 'frontend', 'backend']
            b_g.return_value = [test_config[0]]
            b_d.return_value = [test_config[1]]
            b_f.return_value = [test_config[2]]
            b_b.return_value = [test_config[3]]

            cfg.save_config('test_path', mock.Mock())
            replace.assert_called_once_with('test_path',
                                            '\n'.join(test_config))
Exemple #5
0
    def test_save_config(self):
        with contextlib.nested(
                mock.patch('neutron.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_global'),
                mock.patch('neutron.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_defaults'),
                mock.patch('neutron.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_frontend'),
                mock.patch('neutron.services.loadbalancer.'
                           'drivers.haproxy.cfg._build_backend'),
                mock.patch('neutron.agent.linux.utils.replace_file')
        ) as (b_g, b_d, b_f, b_b, replace):
            test_config = ['globals', 'defaults', 'frontend', 'backend']
            b_g.return_value = [test_config[0]]
            b_d.return_value = [test_config[1]]
            b_f.return_value = [test_config[2]]
            b_b.return_value = [test_config[3]]

            cfg.save_config('test_path', mock.Mock())
            replace.assert_called_once_with('test_path',
                                            '\n'.join(test_config))