~jelmer/byoci/setuptools

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2018-11-23 18:01:40 UTC
  • mto: This revision was merged to the branch mainline in revision 213.
  • Revision ID: v.ladeuil+lp@free.fr-20181123180140-vbs1sc0v2zjyy681
Test and implemebt 'byo-ci-monitor run-job'.

Replacing the she standalone testing/byo-ci-run which has no tests.

Rand into a weird test error caused by a lack of 'ldap.{user,password}'
options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
        ret, out, err = subprocesses.run(
98
98
            ['byovm', 'shell', self.monitor_name, test_cmd])
99
99
        assertions.assertShellSuccess(self, test_cmd, ret, out, err)
 
100
 
 
101
 
 
102
class TestMonitorRunJob(unittest.TestCase):
 
103
 
 
104
    def setUp(self):
 
105
        super().setUp()
 
106
        fixtures.isolate_from_disk_for_host(self)
 
107
        fixtures.setup_byoci_conf(self)
 
108
        self.out = io.StringIO()
 
109
        self.err = io.StringIO()
 
110
        fixtures.override_logging(self)
 
111
 
 
112
    def test_succeeds(self):
 
113
        fixtures.setup_master(self)
 
114
        fixtures.setup_monitor(self)
 
115
        # Inject jobs first
 
116
        test_cmd = 'cd /byoci && jenkins-jobs update jobs/'
 
117
        ret, out, err = subprocesses.run(
 
118
            ['byovm', 'shell', self.monitor_name, test_cmd])
 
119
        assertions.assertShellSuccess(self, test_cmd, ret, out, err)
 
120
        # Now run a known one
 
121
        test_cmd = ('cd /byoci &&'
 
122
                    ' ./byo-ci-monitor run-job byoci/info-brz-slave-selftest')
 
123
        ret, out, err = subprocesses.run(
 
124
            ['byovm', 'shell', self.monitor_name, test_cmd])
 
125
        assertions.assertShellSuccess(self, test_cmd, ret, out, err)
 
126
        # The job is waiting for a slave (not provisioned here)
 
127
        # FIXME: If/when jenkins handling is rewritten as requests-based
 
128
        # module, more assertions could be made. -- vila 2018-11-23
 
129
 
 
130
    def test_fails(self):
 
131
        fixtures.setup_master(self)
 
132
        fixtures.setup_monitor(self)
 
133
        with self.assertRaises(subprocesses.errors.CommandError) as cm:
 
134
            test_cmd = ('cd /byoci &&'
 
135
                        ' ./byo-ci-monitor run-job I-dont-exist')
 
136
            subprocesses.run(['byovm', 'shell', self.monitor_name, test_cmd])
 
137
        self.assertTrue(
 
138
            cm.exception.err.endswith('No job matches I-dont-exist\n'))