1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
"""Test es_repo_mgr script and functions"""
# pylint: disable=C0115, C0116, invalid-name
import logging
import os
from click import testing as clicktest
from curator import repo_mgr_cli
from curator.helpers.testers import repository_exists
from . import CuratorTestCase
from . import testvars
LOGGER = logging.getLogger(__name__)
REPO_PATH = '/media'
HOST = os.environ.get('TEST_ES_SERVER', 'http://127.0.0.1:9200')
# class TestLoggingModules(CuratorTestCase):
# def test_logger_without_null_handler(self):
# from unittest.mock import patch, Mock
# mock = Mock()
# modules = {'logger': mock, 'logger.NullHandler': mock.module}
# self.write_config(
# self.args['configfile'],
# testvars.client_conf_logfile.format(HOST, os.devnull)
# )
# with patch.dict('sys.modules', modules):
# self.create_repository()
# test = clicktest.CliRunner()
# result = test.invoke(
# repo_mgr_cli,
# ['--config', self.args['configfile'], 'show']
# )
# self.assertEqual(self.args['repository'], result.output.rstrip())
class TestCLIRepositoryCreate(CuratorTestCase):
def test_create_fs_repository_success(self):
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
result = test.invoke(
repo_mgr_cli,
[
'--config',
self.args['configfile'],
'create',
'fs',
'--name',
self.args['repository'],
'--location',
REPO_PATH,
'--verify',
],
)
assert 1 == len(
self.client.snapshot.get_repository(name=self.args['repository'])
)
assert 0 == result.exit_code
def test_create_fs_repository_fail(self):
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
result = test.invoke(
repo_mgr_cli,
[
'--config',
self.args['configfile'],
'create',
'fs',
'--name',
self.args['repository'],
'--location',
os.devnull,
'--verify',
],
)
assert 1 == result.exit_code
def test_create_s3_repository_fail(self):
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
result = test.invoke(
repo_mgr_cli,
[
'--config',
self.args['configfile'],
'create',
's3',
'--bucket',
'mybucket',
'--name',
self.args['repository'],
'--verify',
],
)
assert 1 == result.exit_code
def test_create_azure_repository_fail(self):
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
result = test.invoke(
repo_mgr_cli,
[
'--config',
self.args['configfile'],
'create',
'azure',
'--container',
'mybucket',
'--name',
self.args['repository'],
'--verify',
],
)
assert 1 == result.exit_code
def test_create_gcs_repository_fail(self):
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
result = test.invoke(
repo_mgr_cli,
[
'--config',
self.args['configfile'],
'create',
'gcs',
'--bucket',
'mybucket',
'--name',
self.args['repository'],
'--verify',
],
)
assert 1 == result.exit_code
class TestCLIDeleteRepository(CuratorTestCase):
def test_delete_repository_success(self):
self.create_repository()
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
_ = test.invoke(
repo_mgr_cli,
[
'--config',
self.args['configfile'],
'delete',
'--yes', # This ensures no prompting will happen
'--name',
self.args['repository'],
],
)
assert not repository_exists(self.client, self.args['repository'])
def test_delete_repository_notfound(self):
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
result = test.invoke(
repo_mgr_cli,
[
'--config',
self.args['configfile'],
'delete',
'--yes', # This ensures no prompting will happen
'--name',
self.args['repository'],
],
)
assert 1 == result.exit_code
class TestCLIShowRepositories(CuratorTestCase):
def test_show_repository(self):
self.create_repository()
self.write_config(
self.args['configfile'],
testvars.client_conf_logfile.format(HOST, os.devnull),
)
test = clicktest.CliRunner()
result = test.invoke(
repo_mgr_cli, ['--config', self.args['configfile'], 'show']
)
# The splitlines()[-1] allows me to only capture the last line and ignore
# other output
assert self.args['repository'] == result.output.splitlines()[-1]
|