Exemplo n.º 1
0
    def _spawn(self, loadbalancer, extra_cmd_args=()):
        conf_path = self._get_state_file_path(loadbalancer.id, 'haproxy.conf')
        sock_path = self._get_state_file_path(loadbalancer.id,
                                              'haproxy_stats.sock')
        user_group = self.conf.haproxy.user_group
        haproxy_base_dir = self._get_state_file_path(loadbalancer.id, '')
        jinja_cfg.save_config(conf_path, loadbalancer, sock_path, user_group,
                              haproxy_base_dir)

        def callback(pid_path):
            cmd = ['haproxy', '-f', conf_path, '-p', pid_path]
            cmd.extend(extra_cmd_args)
            return cmd

        pid_data = self._get_state_file_path(loadbalancer.id, 'haproxy.pid')
        pid_path = os.path.split(pid_data)[0]
        namespace = get_ns_name(loadbalancer.id)
        pm = external_process.ProcessManager(
            uuid=loadbalancer.id,
            default_cmd_callback=callback,
            namespace=namespace,
            service=HAPROXY_SERVICE_NAME,
            conf=self.conf,
            pids_path=pid_path,
            pid_file=pid_data,
            custom_reload_callback=callback if extra_cmd_args else None)
        if pm.active:
            pm.reload_cfg()
        else:
            pm.enable()
        self.process_monitor.register(uuid=loadbalancer.id,
                                      service_name=HAPROXY_SERVICE_NAME,
                                      monitored_process=pm)
        # remember deployed loadbalancer id
        self.deployed_loadbalancers[loadbalancer.id] = loadbalancer
Exemplo n.º 2
0
 def test_save_config(self):
     with mock.patch('neutron_lbaas.drivers.haproxy.'
                     'jinja_cfg.render_loadbalancer_obj') as r_t, \
             mock.patch('neutron.common.utils.replace_file') as replace:
         r_t.return_value = 'fake_rendered_template'
         lb = mock.Mock()
         jinja_cfg.save_config('test_conf_path', lb, 'test_sock_path',
                               'nogroup', 'fake_state_path')
         r_t.assert_called_once_with(lb, 'nogroup', 'test_sock_path',
                                     'fake_state_path')
         replace.assert_called_once_with('test_conf_path',
                                         'fake_rendered_template')
Exemplo n.º 3
0
 def test_save_config(self):
     with mock.patch('neutron_lbaas.drivers.haproxy.'
                     'jinja_cfg.render_loadbalancer_obj') as r_t, \
             mock.patch('neutron_lib.utils.file.replace_file') as replace:
         r_t.return_value = 'fake_rendered_template'
         lb = mock.Mock()
         jinja_cfg.save_config('test_conf_path', lb, 'test_sock_path',
                               'nogroup',
                               'fake_state_path')
         r_t.assert_called_once_with(lb,
                                     'nogroup',
                                     'test_sock_path',
                                     'fake_state_path')
         replace.assert_called_once_with('test_conf_path',
                                         'fake_rendered_template')
Exemplo n.º 4
0
    def _spawn(self, loadbalancer, extra_cmd_args=()):
        namespace = get_ns_name(loadbalancer.id)
        conf_path = self._get_state_file_path(loadbalancer.id, 'haproxy.conf')
        pid_path = self._get_state_file_path(loadbalancer.id, 'haproxy.pid')
        sock_path = self._get_state_file_path(loadbalancer.id,
                                              'haproxy_stats.sock')
        user_group = self.conf.haproxy.user_group
        haproxy_base_dir = self._get_state_file_path(loadbalancer.id, '')
        jinja_cfg.save_config(conf_path, loadbalancer, sock_path, user_group,
                              haproxy_base_dir)
        cmd = ['haproxy', '-f', conf_path, '-p', pid_path]
        cmd.extend(extra_cmd_args)

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

        # remember deployed loadbalancer id
        self.deployed_loadbalancers[loadbalancer.id] = loadbalancer
Exemplo n.º 5
0
    def _spawn(self, loadbalancer, extra_cmd_args=()):
        namespace = get_ns_name(loadbalancer.id)
        conf_path = self._get_state_file_path(loadbalancer.id, 'haproxy.conf')
        pid_path = self._get_state_file_path(loadbalancer.id,
                                             'haproxy.pid')
        sock_path = self._get_state_file_path(loadbalancer.id,
                                              'haproxy_stats.sock')
        user_group = self.conf.haproxy.user_group
        haproxy_base_dir = self._get_state_file_path(loadbalancer.id, '')
        jinja_cfg.save_config(conf_path,
                              loadbalancer,
                              sock_path,
                              user_group,
                              haproxy_base_dir)
        cmd = ['haproxy', '-f', conf_path, '-p', pid_path]
        cmd.extend(extra_cmd_args)

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

        # remember deployed loadbalancer id
        self.deployed_loadbalancers[loadbalancer.id] = loadbalancer
Exemplo n.º 6
0
    def _spawn(self, loadbalancer, extra_cmd_args=()):
        conf_path = self._get_state_file_path(loadbalancer.id,
                                              'haproxy.conf')
        sock_path = self._get_state_file_path(loadbalancer.id,
                                              'haproxy_stats.sock')
        user_group = self.conf.haproxy.user_group
        haproxy_base_dir = self._get_state_file_path(loadbalancer.id, '')
        jinja_cfg.save_config(conf_path,
                              loadbalancer,
                              sock_path,
                              user_group,
                              haproxy_base_dir)

        def callback(pid_path):
            cmd = ['haproxy', '-f', conf_path, '-p', pid_path]
            cmd.extend(extra_cmd_args)
            return cmd

        pid_data = self._get_state_file_path(loadbalancer.id, 'haproxy.pid')
        pid_path = os.path.split(pid_data)[0]
        namespace = get_ns_name(loadbalancer.id)
        pm = external_process.ProcessManager(
            uuid=loadbalancer.id,
            default_cmd_callback=callback,
            namespace=namespace,
            service=HAPROXY_SERVICE_NAME,
            conf=self.conf,
            pids_path=pid_path,
            pid_file=pid_data,
            custom_reload_callback=callback if extra_cmd_args else None)
        if pm.active:
            pm.reload_cfg()
        else:
            pm.enable()
        self.process_monitor.register(uuid=loadbalancer.id,
                                      service_name=HAPROXY_SERVICE_NAME,
                                      monitored_process=pm)
        # remember deployed loadbalancer id
        self.deployed_loadbalancers[loadbalancer.id] = loadbalancer