Files
patroni/tests/test_cli.py
T
Feike Steenbergen e2aff13d3e Patronictl: Create commandline tool that can manage clusters.
For managing Patroni clusters, the Patroni api can be used. For many tasks, a command line interface for
this api would be a useful addition. This commit adds patroncli (The name is still under debate).
The command line interface needs access to the DCS; this is required for any operation. For some tasks it is required
to have access to the Patroni api.

A small summary of the additions to get the cli/ctl started:

* Updated Docker image to use 'true' as the archive_command, to ensure disk not filling up during failover
  testing.
* The cli currently can list members, failover a master and remove a given cluster from DCS.
* The cli can be configured with a command, for repeated access to the same DCS
* Added some simple tests for the cli, code coverage is very low
2015-10-26 14:57:59 +01:00

52 lines
1.2 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import pytest
from click.testing import CliRunner
from patroni.cli import cli, members, store_config, load_config, output_members
from test_ha import get_cluster_initialized_with_leader
CONFIG_FILE_PATH = './test-cli.yaml'
def test_output_members():
cluster = get_cluster_initialized_with_leader()
output_members(cluster, name='abc', format='pretty')
output_members(cluster, name='abc', format='json')
def test_rw_config():
runner = CliRunner()
config = 'a:b'
with runner.isolated_filesystem():
os.mkdir(CONFIG_FILE_PATH)
with pytest.raises(Exception):
result = load_config(CONFIG_FILE_PATH, None)
assert 'Could not load configuration file' in result.output
with pytest.raises(Exception):
store_config(config, CONFIG_FILE_PATH)
os.rmdir(CONFIG_FILE_PATH)
store_config(config, 'abc/CONFIG_FILE_PATH')
load_config(CONFIG_FILE_PATH, None)
def test_cli():
runner = CliRunner()
runner.invoke(cli, ['list'])
result = runner.invoke(cli, ['--help'])
assert 'Usage:' in result.output
def test_members():
runner = CliRunner()
runner.invoke(members)