~jelmer/byoci/brz-git-tests

« back to all changes in this revision

Viewing changes to byoci/tests/host/test_monitor.py

  • Committer: Vincent Ladeuil
  • Date: 2018-02-16 18:34:49 UTC
  • mfrom: (156.1.19 split)
  • Revision ID: v.ladeuil+lp@free.fr-20180216183449-jb0l1xbvdcrv4xzw
The three main components can now be setup independently

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of Build Your Own CI
 
2
#
 
3
# Copyright 2018 Vincent Ladeuil
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
 
16
 
 
17
from __future__ import unicode_literals
 
18
 
 
19
import io
 
20
import unittest
 
21
 
 
22
from byoci.host import (
 
23
    commands,
 
24
    config,
 
25
)
 
26
from byoci.tests.host import fixtures
 
27
 
 
28
 
 
29
class TestMonitorConfig(unittest.TestCase):
 
30
    """Test master config."""
 
31
 
 
32
    def setUp(self):
 
33
        super().setUp()
 
34
        fixtures.isolate_from_disk_for_host(self)
 
35
 
 
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}'))
 
43
 
 
44
 
 
45
class TestMonitorSetup(unittest.TestCase):
 
46
 
 
47
    def setUp(self):
 
48
        super().setUp()
 
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)
 
54
 
 
55
    def test_setup_succeeds(self):
 
56
        fixtures.setup_master(self)
 
57
        fixtures.setup_monitor(self)
 
58
 
 
59
 
 
60
class TestMonitorUpdateJobs(unittest.TestCase):
 
61
 
 
62
    def setUp(self):
 
63
        super().setUp()
 
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)
 
69
 
 
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
 
76
        # -- vila 2018-02-09
 
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)
 
82
 
 
83
 
 
84
class TestMonitorUpdatePlugins(unittest.TestCase):
 
85
 
 
86
    def setUp(self):
 
87
        super().setUp()
 
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)
 
93
 
 
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
 
99
 
 
100
        # FIXME: Assert something about the file content after downloading it.
 
101
        # And/or assert something about the plugins being updated on master.
 
102
        # -- vila 2018-02-09
 
103
        shell_command.parse_args(
 
104
            [self.monitor_name,
 
105
             'cd /byoci && ./byo-ci-monitor update-plugins'])
 
106
        ret = shell_command.run()
 
107
        self.assertEqual(0, ret)