2020-02-29 22:35:57 +00:00
|
|
|
import os
|
|
|
|
import testinfra.utils.ansible_runner
|
|
|
|
|
|
|
|
def test_packages(host):
|
2023-09-29 13:54:34 +00:00
|
|
|
package = host.package('elasticsearch')
|
|
|
|
assert package.is_installed
|
2020-02-29 22:35:57 +00:00
|
|
|
|
|
|
|
def test_config_file(host):
|
2023-09-29 13:54:34 +00:00
|
|
|
config = host.file('/etc/elasticsearch/elasticsearch.yml')
|
|
|
|
assert config.user == 'root'
|
|
|
|
assert config.group == 'elasticsearch'
|
|
|
|
assert config.mode == 0o640
|
|
|
|
assert config.contains('path.data: /var/lib/elasticsearch')
|
2020-02-29 22:35:57 +00:00
|
|
|
|
|
|
|
def test_service(host):
|
2023-09-29 13:54:34 +00:00
|
|
|
service = host.service('elasticsearch')
|
|
|
|
assert service.is_running
|
|
|
|
assert service.is_enabled
|
2020-02-29 22:35:57 +00:00
|
|
|
|
|
|
|
def test_socket(host):
|
2023-09-29 13:54:34 +00:00
|
|
|
for port in [9200, 9300]:
|
|
|
|
socket = host.socket('tcp://127.0.0.1:%d' % (port))
|
|
|
|
assert socket.is_listening
|
2020-02-29 22:35:57 +00:00
|
|
|
|
|
|
|
def test_java_memory(host):
|
2023-09-29 13:54:34 +00:00
|
|
|
process = host.process.filter(user='elasticsearch', comm='java')
|
|
|
|
assert '-Xms512m' in process[1].args
|
|
|
|
assert '-Xmx512m' in process[1].args
|
2020-02-29 22:35:57 +00:00
|
|
|
|
|
|
|
def test_elasticsearch_template(host):
|
2023-09-29 13:54:34 +00:00
|
|
|
result = host.check_output('curl -v -u elastic:mysecret http://127.0.0.1:9200/_template/test')
|
|
|
|
assert '"number_of_replicas":"1"' in result
|
|
|
|
|
|
|
|
def test_elasticsearch_user(host):
|
|
|
|
result = host.check_output('curl -v -u elastic:mysecret http://127.0.0.1:9200/_security/user/toto')
|
|
|
|
assert '"username":"toto"' in result
|
|
|
|
assert '"roles":["viewer"]' in result
|