Commit 889a7402 authored by Ekaterina's avatar Ekaterina

testForFluentd

parent c6efd62e
[buildout]
parts =
slapos-test-runner
directory
fluentdConfig
fluentd-service
caddy-service
publish-connection-information
runTest-instance
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
bin = $${buildout:directory}/bin
srv = $${buildout:directory}/srv
var = $${buildout:directory}/var
run = $${:var}/run
log = $${:var}/log
scripts = $${:etc}/run
services = $${:etc}/service
promise = $${:etc}/promise/
www = $${:srv}/www
home = $${:etc}/home
ssl = $${:etc}/ssl
[runTest-instance]
recipe = slapos.recipe.template
url = ${template-test:output}
output = $${directory:bin}/test.py
buildout-directory = $${buildout:directory}
mode = 0700
#################################
# fluentd service
#################################
[fluentdConfig]
recipe = slapos.recipe.template:jinja2
template = ${template-fluentdConfig:location}/${template-fluentdConfig:filename}
rendered = $${directory:etc}/fluentd-conf.cnf
mode = 0600
context =
key local_ip caddy-configuration:local_ip
[fluentd-service]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:services}/fluentd-service
path = ${fluentd:location}
command-line = ${fluentd:location}/bin/fluentd
-c $${directory:etc}/fluentd-conf.cnf -p ${fluentd-plugin-dev-repository:location}/lib/fluent/plugin/
environment =
GEM_PATH= ${fluentd:location}/lib/ruby/gems/1.8/
output = $${:wrapper-path}
#################################
# caddy service
#################################
[caddy-service]
recipe = slapos.recipe.template:jinja2
template = ${template-caddy-service:output}
rendered = $${directory:services}/caddy
mode = 0700
context =
key caddy_exec caddy-exec-dict:caddy-exec-file
key caddy_file caddy-configuration:rendered
key pidfile_dir directory:etc
[caddy-exec-dict]
caddy-exec-file = ${gowork:bin}/caddy
[caddy-configuration]
recipe = slapos.recipe.template:jinja2
template = ${template-caddyfile:output}
rendered = $${directory:etc}/Caddyfile
mode = 0600
access_log = $${directory:log}/caddy-access.log
error_log = $${directory:log}/caddy-error.log
local_ip = $${slap-network-information:local-ipv4}
context =
key local_ip caddy-configuration:local_ip
[publish-connection-information]
recipe = slapos.cookbook:publish
secure_access = http://$${caddy-configuration:local_ip}:4443}
[download-source]
recipe = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git
[slapos]
<= download-source
repository = ${slapos-repository:location}
[create-directory]
recipe = slapos.cookbook:mkdirectory
bin = $${buildout:directory}/bin
[slapos-test-runner]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:bin}/runTestSuite
command-line =
${buildout:bin-directory}/runTestSuite
--python_interpreter=${buildout:bin-directory}/${eggs:interpreter}
--source_code_path_list=$${slapos:location}/software/erp5testnode/testsuite/fluentTest/tests/
environment =
PATH=${buildout:bin-directory}:/usr/bin/:/bin/
LOCAL_IPV4=$${slap-network-information:local-ipv4}
GLOBAL_IPV6=$${slap-network-information:global-ipv6}
\ No newline at end of file
#############################
#
# Deploy caddy instance
#
#############################
[buildout]
parts =
switch-softwaretype
# publish-connection-parameter
# Define egg directories to be the one from Software Release
# (/opt/slapgrid/...)
# Always the same.
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[switch-softwaretype]
recipe = slapos.cookbook:softwaretype
default = $${:caddy}
caddy = $${dynamic-template-caddy-fluentd:rendered}
[dynamic-template-caddy-fluentd]
recipe = slapos.recipe.template:jinja2
template = ${template-caddy-fluentd:output}
rendered = $${buildout:parts-directory}/${:_buildout_section_name_}/${:filename}
filename = instance-caddy-fluentd.cfg
[slap-connection]
computer-id = $${slap_connection:computer_id}
partition-id = $${slap_connection:partition_id}
server-url = $${slap_connection:server_url}
software-release-url = $${slap_connection:software_release_url}
key-file = $${slap_connection:key_file}
cert-file = $${slap_connection:cert_file}
[instance-parameter]
# Fetch arbitrary parameters defined by the user in SlapOS Master for his instance.
# We use the slapconfiguration recipe with a few parameters (partition id,
# computer id, certificate, etc).
# It will then authenticate to SlapOS Master and fetch the instance parameters.
# The parameters are accessible from {instance-parameter:configuration.name-of-parameter}
# Always the same. Just copy/paste.
# See docstring of slapos.cookbook:slapconfiguration for more information.
recipe = slapos.cookbook:slapconfiguration
computer = $${slap_connection:computer_id}
partition = $${slap_connection:partition_id}
url = $${slap_connection:server_url}
key = $${slap_connection:key_file}
cert = $${slap_connection:cert_file}
\ No newline at end of file
[buildout]
extends =
../../../../stack/slapos.cfg
../../../../software/caddy/software.cfg
../../../../software/fluentd/software.cfg
index = https://pypi.python.org/simple/
parts =
slapos-cookbook
eggs
caddy
fluentd
fluentd-plugin-dev-repository
instance-profile
template-fluentdConfig
[setup-develop-egg]
recipe = zc.recipe.egg:develop
[slapos.test.fluentTest-setup]
<= setup-develop-egg
egg = slapos.test.fluentTest
setup = ${slapos-repository:location}/software/erp5testnode/testsuite/fluentTest/tests/
#setup = ${:_profile_base_location_}/tests/
[erp5.util-setup]
<= setup-develop-egg
egg = erp5.util[testnode]
setup = ${erp5.util-repository:location}
[eggs]
recipe = zc.recipe.egg
eggs =
${slapos.test.fluentTest-setup:egg}
${erp5.util-setup:egg}
slapos.core
entry-points =
runTestSuite=erp5.util.testsuite:runTestSuite
scripts =
runTestSuite
slapos
interpreter=
python_for_test
[git-clone-repository]
recipe = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git
forbid-download-cache = true
branch = testForFleuntdClean
[slapos-repository]
<= git-clone-repository
repository = https://lab.nexedi.com/Sokhoyan/slapos.git
# XXX we need an unreleased ( 0.4.51 ) version of erp5.util runTestSuite
# later we can stop fetching it from git and just use egg
[erp5.util-repository]
<= git-clone-repository
repository = https://lab.nexedi.com/nexedi/erp5.git
revision = 69013fa0fb67501089c776ab5e75d7bbf2e0e3bc
[versions]
# clear the version of tested eggs, to make sure we installed the developped ones
slapos.test.fluentTest =
erp5.util =
#erp5.util = 0.4.51
#[eggs]
#recipe = zc.recipe.egg
#eggs =
# erp5.util
# ${lxml-python:egg}
# requests
#interpreter = pythonwitheggs
[instance-profile]
recipe = slapos.recipe.template
md5sum = 45c4adaae557bed5c25c24f4c4506b3d
url = ${:_profile_base_location_}/instance.cfg.in
output = ${buildout:directory}/instance.cfg
mode = 0644
[template-test]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/tests/test.py
#md5sum = ff66d13f73982e8257eb5535cdb541c7
output = ${buildout:directory}/test.py
mode = 0644
[template-fluentdConfig]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/templates/fluentd-conf.cnf.in
md5sum = fd896793455e1d04082449212d285b55
filename = fluentd-conf.cnf.in
location = ${buildout:parts-directory}/${:_buildout_section_name_}
mode = 0644
[fluentd-plugin-dev-repository]
recipe = slapos.recipe.build:gitclone
repository = https://lab.nexedi.com/Sokhoyan/fluent-plugin-wendelin.git
branch = add-keep-alive
# dir is pretty name as top-level -dev recipe
git-executable = ${git:location}/bin/git
[fluentd]
gems =
fluentd
fluent-plugin-td
bundler
fluent-plugin-bin
[template-caddy-service]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/template-caddy-service.sh.in
md5sum = 3e09969c479931ca4df6546abbd1a117
output = ${buildout:directory}/template-caddy-service.sh.in
mode = 0644
[template-caddyfile]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/Caddyfile.in
md5sum = 8644e98038ab76a8e5a499e22f92660a
output = ${buildout:directory}/Caddyfile.in
mode = 0644
[template-caddy-fluentd]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-caddy-fluentd.cfg.in
md5sum = ee285ee5d2df708776d2b97a09499ef5
output = ${buildout:directory}/instance-caddy-fluentd.cfg.in
mode = 0644
[caddy]
recipe = slapos.recipe.cmmi
path = ${go_github.com_mholt_caddy:location}
go = ${gowork:golang}/bin/go
configure-command = :
make-targets =
make-binary = cd ${:path}/caddy && ${:go} install -v
environment =
PATH=${pkgconfig:location}/bin:${gowork:golang}/bin:${buildout:bin-directory}:%(PATH)s
GOPATH=${gowork:directory}
output = ${gowork:bin}/caddy
#versions]
#slapos.recipe.template = 4.3
#erp5.util = 0.4.50
\ No newline at end of file
<source>
@type forward
</source>
#<source>
# @type dummy
# tag dummy
# dummy {"message":"yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay"}
#</source>
# HTTP input
# http://localhost:8888/<tag>?json=<json>
#<source>
# @type http
# @id http_input
# port 8888
#</source>
## output tag=sensor.** to Wendelin
<match **>
@type wendelin
@id wendelin_out
streamtool_uri http://{{local_ip}}:4443
# all parameters of BufferedOutput & Output classes are supported too, e.g.
# `buffer_type`, `flush_interval`, `num_threads`, `log_level`, etc - see
# their code near:
#
# https://github.com/fluent/fluentd/blob/master/lib/fluent/output.rb#L182
#
# logging setup description:
#
# http://docs.fluentd.org/articles/logging
buffer_type memory
buffer_chunk_limit 1MB
#buffer_path "#{ENV['HOME']/var}"
flush_interval 1s
num_threads 1
</match>
# ---- monitoring & debugging ----
# Listen HTTP for monitoring
# http://localhost:24220/api/plugins
# http://localhost:24220/api/plugins?type=TYPE
# http://localhost:24220/api/plugins?tag=MYTAG
<source>
@type monitor_agent
@id monitor_agent_input
port 24220
</source>
# Listen DRb for debug
<source>
@type debug_agent
@id debug_agent_input
bind {{local_ip}}
port 24230
</source>
## match tag=debug.** and dump to console
<match debug.**>
@type stdout
@id stdout_output
</match>
## match fluent's internal events
#<match fluent.**>
# @type null
#</match>
## match not matched logs and write to file
#<match **>
# @type file
# path /var/log/fluent/else
# compress gz
#</match>
#!${dash-output:dash}
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
{{ caddy_exec }} -conf {{ caddy_file }} -pidfile {{pidfile_dir}}/caddy_pidfile
\ No newline at end of file
Test for fluentd wendelin plugin with keep-alive connection and caddy.
\ No newline at end of file
#!${buildout:directory}/bin/${eggs:interpreter}
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
import argparse, os, re, shutil, subprocess, sys, traceback
from erp5.util import taskdistribution
import sys
test_path = '$${runTest-instance:buildout-directory}/bin/'
sys.path.append(test_path)
import testIngestion
def main():
parser = argparse.ArgumentParser(description='Run a test suite.')
parser.add_argument('--test_suite', help='The test suite name')
parser.add_argument('--test_suite_title', help='The test suite title')
parser.add_argument('--test_node_title', help='The test node title')
parser.add_argument('--project_title', help='The project title')
parser.add_argument('--revision', help='The revision to test',
default='dummy_revision')
parser.add_argument('--node_quantity', help='ignored', type=int)
parser.add_argument('--master_url',
help='The Url of Master controling many suites')
parser.add_argument('--frontend_url',
help='The url of frontend of the test suite')
parser.add_argument('--target',
help='Target OS to run tests on',
type=str)
parser.add_argument('--target_version',
help='Target OS version to use',
type=str,)
parser.add_argument('--target_browser',
help='The desired browser of the target OS to be used. Example: Firefox if target is Android.',
type=str,)
parser.add_argument('--target_device',
help='The desired device running the target OS. Example: iPad Simulator, if target is iOS.',
type=str,)
parser.add_argument('--appium_server_auth',
help='Combination of user and token to access SauceLabs service. (i.e. user:token)',
type=str)
args = parser.parse_args()
try:
test_suite_title = args.test_suite_title or args.test_suite
test_suite = args.test_suite
revision = args.revision
test_line_dict = {}
num_of_tests, errors, failures, stdout = testIngestion.main()
result = testIngestion.main()
test_line_dict["testIngestion"] = {
'test_count': num_of_tests,
'error_count': len(errors),
'failure_count': len(failures),
'skip_count': 0,
'stdout': stdout,
'stderr': errors
}
tool = taskdistribution.TaskDistributor(portal_url=args.master_url)
test_result = tool.createTestResult(revision = revision,
test_name_list = test_line_dict.keys(),
node_title = args.test_node_title,
test_title = test_suite_title,
project_title = args.project_title)
if test_result is None or not hasattr(args, 'master_url'):
print("test_result is NONE")
return
# report test results
while 1:
test_result_line = test_result.start()
if not test_result_line:
print 'No test result anymore.'
break
print 'Submitting: "%s"' % test_result_line.name
# report status back to Nexedi ERP5
test_result_line.stop(**test_line_dict[test_result_line.name])
except:
# Catch any exception here, to warn user instead of being silent,
# by generating fake error result
print traceback.format_exc()
result = dict(status_code=-1,
command=url,
stderr=traceback.format_exc(),
stdout='')
# XXX: inform test node master of error
raise EnvironmentError(result)
if __name__ == "__main__":
main()
##############################################################################
#
# Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from setuptools import setup, find_packages
import glob
import os
version = '0.0.1.dev0'
name = 'slapos.test.fluentTest'
long_description = open("README.md").read()
setup(name=name,
version=version,
description="Test for fluentd wendelin plugin",
long_description=long_description,
long_description_content_type='text/markdown',
maintainer="Nexedi",
maintainer_email="info@nexedi.com",
url="https://lab.nexedi.com/nexedi/slapos",
packages=find_packages(),
install_requires=[
'slapos.core',
'erp5.util',
'requests',
],
zip_safe=True,
test_suite='test',
)
\ No newline at end of file
#!${buildout:directory}/bin/${eggs:interpreter}
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
import unittest
import requests
from StringIO import StringIO
import SimpleHTTPServer
import SocketServer
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import os
import time
import utils
import multiprocessing
test_msg = "dummyInputSimpleIngest"
#url = "http://$${caddy-configuration:local_ip}:8443"
url = "http://10.0.46.242:8443"
caddy_pidfile = "$${directory:etc}/caddy_pidfile"
posted_data = None
all_data = []
request_tag = ""
###################################################
class FluentdPluginTestCase(utils.SlapOSInstanceTestCase):
@classmethod
def getSoftwareURLList(cls):
return (os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'software.cfg')), )
###################################################
class TestServerHandler(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
self._set_headers()
self.wfile.write("<html><body><h1>hi!</h1></body></html>")
def do_HEAD(self):
self._set_headers()
def do_POST(self):
content_length = int(self.headers['Content-Length']) # <--- Gets the size of data
post_data = self.rfile.read(content_length) # <--- Gets the data itself
self._set_headers()
self.wfile.write(post_data)
global posted_data
posted_data = post_data
print("post data from do_POST")
print(posted_data)
global all_data
all_data.append(post_data.split(" ")[1])
global request_tag
request_tag = find_tag(self.requestline,"=", " ")
class TestIngestion(FluentdPluginTestCase):
@classmethod
def startServer(cls):
port=9443
#server_address = ('$${slap-network-information:local-ipv4}', port)
server_address = ('0.0.0.0', port)
#ip = os.environ.get('LOCAL_IPV4', '127.0.1.1')
server = HTTPServer(server_address, TestServerHandler)
cls.server_process = multiprocessing.Process(target=server.serve_forever)
cls.server_process.start()
print("Server started...")
print("local ipv4 = ")
print(os.environ.get('LOCAL_IPV4'))
@classmethod
def stopServer(cls):
cls.server_process.terminate()
def setUp(self):
self.startServer()
# port=9443
# server_address = ('$${slap-network-information:local-ipv4}', port)
# httpd = HTTPServer(server_address, TestServerHandler)
# thread = threading.Thread(target=httpd.serve_forever)
# thread.start()
# print 'Starting http...'
# time.sleep(15)
print("for fake commit")
def tearDown(self):
self.stopServer()
time.sleep(10)
# httpd.shutdown()
# print("all posted data : ")
# print(all_data)
def test_1_get(self):
print("############## TEST 1 ##############")
resp = requests.get(url)
self.assertEqual(resp.status_code, 200)
print (resp.status_code)
def test_2_ingest(self):
print("############## TEST 2 ##############")
start_fluentd_cat(test_msg, "tag_test_2")
time.sleep(10)
print("posted data from test 2")
print(posted_data)
if posted_data:
self.assertEqual(test_msg, posted_data.split(" ")[1])
else:
self.assertEqual(test_msg, posted_data)
time.sleep(10)
self.assertEqual(test_msg, posted_data.split(" ")[1])
'''
def test_3_keepAlive_on(self):
print("############## TEST 3 ##############")
s = requests.session()
print("check connection type ")
print(s.headers['Connection'])
self.assertEqual('keep-alive', s.headers['Connection'])
def test_4_delay_15_mins(self):
print("############## TEST 4 ##############")
# sleep 15mins to test that connections doesn't break after long delay
# and data is ingested correctly after the delay.
time.sleep(900)
start_fluentd_cat("dummyInputDelay", "tag_test_4")
time.sleep(15)
self.assertEqual("dummyInputDelay", posted_data.split(" ")[1])
def test_5_caddy_restart(self):
print("############## TEST 5 ##############")
with open(caddy_pidfile) as f:
caddy_pid = f.readline()
time.sleep(10)
start_fluentd_cat("dummyInputCaddyRestart1", "tag_test_5_1")
time.sleep(10)
kill_caddy(caddy_pid)
time.sleep(10)
start_fluentd_cat("dummyInputCaddyRestart2 ", "tag_test_5_2")
time.sleep(10)
start_fluentd_cat("dummyInputCaddyRestart3 ", "tag_test_5_3")
time.sleep(10)
start_fluentd_cat("dummyInputCaddyRestart4 ", "tag_test_5_4")
time.sleep(130)
start_caddy(caddy_pid)
time.sleep(15)
self.assertTrue("dummyInputCaddyRestart1" in all_data)
self.assertTrue("dummyInputCaddyRestart2" in all_data)
self.assertTrue("dummyInputCaddyRestart3" in all_data)
self.assertTrue("dummyInputCaddyRestart4" in all_data)
def test_6_check_diff_tags(self):
print("############## TEST 6 ##############")
start_fluentd_cat("dummyInputTags_6_1", "test_Tag_6_1")
time.sleep(2)
self.assertEqual("test_Tag_6_1", request_tag)
start_fluentd_cat("dummyInputTags_6_2", "test_Tag_6_2")
time.sleep(2)
self.assertEqual("test_Tag_6_2", request_tag)
start_fluentd_cat("dummyInputTags_6_3", "test_Tag_6_3")
time.sleep(2)
self.assertEqual("test_Tag_6_3", request_tag)
'''
def start_fluentd_cat(test_msg, tag):
os.environ["GEM_PATH"] ="$${fluentd-service:path}/lib/ruby/gems/1.8/"
fluentd_cat_exec_comand = '$${fluentd-service:path}/bin/fluent-cat --none ' + tag
os.system("echo + " + test_msg + " | " + fluentd_cat_exec_comand)
def kill_caddy(caddy_pid):
os.system("kill -TSTP %s" % caddy_pid)
print("Caddy is stopped.")
def start_caddy(caddy_pid):
os.system("kill -CONT %s" % caddy_pid)
print("Caddy is restarted.")
def find_tag(s, start, end):
return (s.split(start))[1].split(end)[0]
'''
def main():
port=9443
server_address = ('$${slap-network-information:local-ipv4}', port)
httpd = HTTPServer(server_address, TestServerHandler)
thread = threading.Thread(target=httpd.serve_forever)
thread.start()
print 'Starting http...'
time.sleep(15)
stream = StringIO()
runner = unittest.TextTestRunner(verbosity=2, stream=stream)
result = runner.run(unittest.makeSuite(TestPost))
print 'Tests run ', result.testsRun
print 'Errors ', result.errors
print "Failures ", result.failures
stream.seek(0)
print 'Test output\n', stream.read()
time.sleep(30)
httpd.shutdown()
print(posted_data)
print("all posted data : ")
print(all_data)
return result.testsRun, result.errors, result.failures, stream.getvalue()
if __name__ == "__main__":
main()
'''
\ No newline at end of file
##############################################################################
#
# Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
import os
import socket
from contextlib import closing
import logging
from erp5.util.testnode.SlapOSControler import SlapOSControler
from erp5.util.testnode.ProcessManager import ProcessManager
import slapos
def findFreeTCPPort(ip=''):
"""Find a free TCP port to listen to.
"""
family = socket.AF_INET6 if ':' in ip else socket.AF_INET
with closing(socket.socket(family, socket.SOCK_STREAM)) as s:
s.bind((ip, 0))
return s.getsockname()[1]
class SlapOSInstanceTestCase(unittest.TestCase):
@classmethod
def getSoftwareURLList(cls):
"""Return URL of software releases to install.
To be defined by subclasses.
"""
raise NotImplementedError()
@classmethod
def getInstanceParameterDict(cls):
"""Return instance parameters
To be defined by subclasses if they need to request instance with specific
parameters.
"""
return {}
# TODO: allow subclasses to request a specific software type ?
@classmethod
def setUpClass(cls):
working_directory = os.environ.get(
'SLAPOS_TEST_WORKING_DIR',
os.path.join(os.path.dirname(__file__), '.slapos'))
# To prevent error: Cannot open an HTTP server: socket.error reported
# AF_UNIX path too long This `working_directory` should not be too deep.
# Socket path is 108 char max on linux
# https://github.com/torvalds/linux/blob/3848ec5/net/unix/af_unix.c#L234-L238
# if len(working_directory + '/inst/supervisord.socket') > 108:
# raise RuntimeError('working directory too deep, try setting SLAPOS_TEST_WORKING_DIR')
if not os.path.exists(working_directory):
os.mkdir(working_directory)
cls.config = config = {
"working_directory": working_directory,
"slapos_directory": working_directory,
"log_directory": working_directory,
"computer_id": 'slapos.test', # XXX
'proxy_database': os.path.join(working_directory, 'proxy.db'),
'partition_reference': cls.__name__,
# "proper" slapos command must be in $PATH
'slapos_binary': 'slapos',
}
# Some tests are expecting that local IP is not set to 127.0.0.1
ipv4_address = os.environ.get('LOCAL_IPV4', '127.0.1.1')
ipv6_address = os.environ['GLOBAL_IPV6']
#ipv6_address = ''
config['proxy_host'] = config['ipv4_address'] = ipv4_address
config['ipv6_address'] = ipv6_address
config['proxy_port'] = findFreeTCPPort(ipv4_address)
config['master_url'] = 'http://{proxy_host}:{proxy_port}'.format(**config)
cls._process_manager = process_manager = ProcessManager()
# XXX this code is copied from testnode code
slapos_controler = SlapOSControler(
working_directory,
config
)
slapproxy_log = os.path.join(config['log_directory'], 'slapproxy.log')
logger = logging.getLogger(__name__)
logger.debug('Configured slapproxy log to %r', slapproxy_log)
software_url_list = cls.getSoftwareURLList()
slapos_controler.initializeSlapOSControler(
slapproxy_log=slapproxy_log,
process_manager=process_manager,
reset_software=False,
software_path_list=software_url_list)
process_manager.supervisord_pid_file = os.path.join(
slapos_controler.instance_root, 'var', 'run', 'supervisord.pid')
software_status_dict = slapos_controler.runSoftwareRelease(config, environment=os.environ)
# TODO: log more details in this case
# assert software_status_dict['status_code'] == 0
instance_parameter_dict = cls.getInstanceParameterDict()
instance_status_dict = slapos_controler.runComputerPartition(
config,
cluster_configuration=instance_parameter_dict,
environment=os.environ)
# TODO: log more details in this case
# assert instance_status_dict['status_code'] == 0
# FIXME: similar to test node, only one (root) partition is really supported for now.
computer_partition_list = []
for i in range(len(software_url_list)):
computer_partition_list.append(
slapos_controler.slap.registerOpenOrder().request(
software_url_list[i],
# This is how testnode's SlapOSControler name created partitions
partition_reference='testing partition {i}'.format(i=i, **config),
partition_parameter_kw=instance_parameter_dict))
# expose some class attributes so that tests can use them:
# the ComputerPartition instances, to getInstanceParmeterDict
cls.computer_partition = computer_partition_list[0]
# the path of the instance on the filesystem, for low level inspection
cls.computer_partition_root_path = os.path.join(
config['working_directory'],
'inst',
cls.computer_partition.getId())
@classmethod
def tearDownClass(cls):
# FIXME: if setUpClass fail, this is not called and leaks zombie processes
cls._process_manager.killPreviousRun()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment