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("quantum.services.loadbalancer." "drivers.haproxy.cfg._build_global"), mock.patch("quantum.services.loadbalancer." "drivers.haproxy.cfg._build_defaults"), mock.patch("quantum.services.loadbalancer." "drivers.haproxy.cfg._build_frontend"), mock.patch("quantum.services.loadbalancer." "drivers.haproxy.cfg._build_backend"), mock.patch("quantum.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('quantum.services.loadbalancer.' 'drivers.haproxy.cfg._build_global'), mock.patch('quantum.services.loadbalancer.' 'drivers.haproxy.cfg._build_defaults'), mock.patch('quantum.services.loadbalancer.' 'drivers.haproxy.cfg._build_frontend'), mock.patch('quantum.services.loadbalancer.' 'drivers.haproxy.cfg._build_backend'), mock.patch('quantum.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))