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') hacfg.save_config(conf_path, logical_config, sock_path) cmd = ['haproxy', '-f', conf_path, '-p', pid_path] cmd.extend(extra_cmd_args) ns = ip_lib.IPWrapper(self.root_helper, namespace) ns.netns.execute(cmd) # remember the pool<>port mapping self.pool_to_port_id[pool_id] = logical_config['vip']['port']['id']
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') hacfg.save_config(conf_path, logical_config, sock_path) cmd = ['haproxy', '-f', conf_path, '-p', pid_path] cmd.extend(extra_cmd_args) ns = ip_lib.IPWrapper(self.root_helper, namespace) ns.netns.execute(cmd) # remember the pool<>port mapping self.pool_to_port_id[pool_id] = logical_config['vip']['port']['id']
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))
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(self.root_helper, namespace) ns.netns.execute(cmd) # remember the pool<>port mapping self.pool_to_port_id[pool_id] = logical_config["vip"]["port"]["id"]
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))
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))
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') #/var/lib/neutron/lbaas/3195b1f3-a453-4c35-a4a2-aa63b2678765/conf pid_path = self._get_state_file_path(pool_id, 'pid') #/var/lib/neutron/lbaas/3195b1f3-a453-4c35-a4a2-aa63b2678765/pid sock_path = self._get_state_file_path(pool_id, 'sock') #/var/lib/neutron/lbaas/3195b1f3-a453-4c35-a4a2-aa63b2678765/sock user_group = self.conf.haproxy.user_group #'nogroup' hacfg.save_config(conf_path, logical_config, sock_path, user_group) #重新写入保存/var/lib/neutron/lbaas/3195b1f3-a453-4c35-a4a2-aa63b2678765/conf cmd = ['haproxy', '-f', conf_path, '-p', pid_path] cmd.extend(extra_cmd_args) ns = ip_lib.IPWrapper(self.root_helper, namespace) ns.netns.execute(cmd) # ip netns exec qlbaas-3195b1f3-a453-4c35-a4a2-aa63b2678765 haproxy -f /var/lib/neutron/lbaas/3195b1f3-a453-4c35-a4a2-aa63b2678765/conf -p /var/lib/neutron/lbaas/3195b1f3-a453-4c35-a4a2-aa63b2678765/pid # remember the pool<>port mapping self.pool_to_port_id[pool_id] = logical_config['vip']['port']['id']