1
# This file is part of Build Your Own CI
3
# Copyright 2018 Vincent Ladeuil
5
# This program is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License version 3, as published by the
7
# Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# General Public License for more details.
14
# You should have received a copy of the GNU General Public License along with
15
# this program. If not, see <http://www.gnu.org/licenses/>.
17
from __future__ import unicode_literals
22
from byoci.host import (
26
from byoci.tests.host import fixtures
29
class TestMonitorConfig(unittest.TestCase):
30
"""Test master config."""
34
fixtures.isolate_from_disk_for_host(self)
36
def test_defaults(self):
37
conf = config.VmStack(None)
38
self.assertEqual('selftest', conf.get('byoci'))
39
self.assertEqual(self.monitor_name,
40
conf.expand_options('{{byoci}.monitor}'))
41
self.assertEqual('/byoci',
42
conf.expand_options('{{byoci}.definition}'))
45
class TestMonitorSetup(unittest.TestCase):
49
fixtures.isolate_from_disk_for_host(self)
50
fixtures.setup_byoci_conf(self)
51
self.out = io.StringIO()
52
self.err = io.StringIO()
53
fixtures.override_logging(self)
55
def test_setup_succeeds(self):
56
fixtures.setup_master(self)
57
fixtures.setup_monitor(self)
60
class TestMonitorUpdateJobs(unittest.TestCase):
64
fixtures.isolate_from_disk_for_host(self)
65
fixtures.setup_byoci_conf(self)
66
self.out = io.StringIO()
67
self.err = io.StringIO()
68
fixtures.override_logging(self)
70
def test_succeeds(self):
71
fixtures.setup_master(self)
72
fixtures.setup_monitor(self)
73
shell_command = commands.Shell(out=self.out, err=self.err)
74
# We can't capture :-/ So redirect to a file
75
# FIXME: Assert something about the file content after downloading it
77
shell_command.parse_args([self.monitor_name,
78
'cd /byoci && jenkins-jobs update jobs/'
79
' > ~/jobs.log 2>&1'])
80
ret = shell_command.run()
81
self.assertEqual(0, ret)
84
class TestMonitorUpdatePlugins(unittest.TestCase):
88
fixtures.isolate_from_disk_for_host(self)
89
fixtures.setup_byoci_conf(self)
90
self.out = io.StringIO()
91
self.err = io.StringIO()
92
fixtures.override_logging(self)
94
def test_succeeds(self):
95
fixtures.setup_master(self)
96
fixtures.setup_monitor(self)
97
shell_command = commands.Shell(out=self.out, err=self.err)
98
# We can't capture :-/ So redirect to a file
100
# FIXME: Assert something about the file content after downloading it.
101
# And/or assert something about the plugins being updated on master.
103
shell_command.parse_args(
105
'cd /byoci && ./byo-ci-monitor update-plugins'])
106
ret = shell_command.run()
107
self.assertEqual(0, ret)