~jelmer/byoci/brz-git-tests

« back to all changes in this revision

Viewing changes to byoci/tests/features.py

  • Committer: Vincent Ladeuil
  • Date: 2018-02-20 17:25:56 UTC
  • mfrom: (158.1.6 lp-tests)
  • Revision ID: v.ladeuil+lp@free.fr-20180220172556-3ixv0oox23v1r1ig
Make launchpad tests pass (again) against production, on slave as well as host.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
import os
 
19
import re
19
20
 
20
21
from byot import features
21
22
 
23
24
 
24
25
lxd_client_feature = features.ExecutableFeature('lxc')
25
26
make_feature = features.ExecutableFeature('make')
 
27
flake8_feature = features.ExecutableFeature('flake8')
 
28
 
 
29
 
 
30
class OnHost(features.Feature):
 
31
    """Is the current process running on a host whose name matches a regexp."""
 
32
 
 
33
    def __init__(self, hostname_regexp):
 
34
        super().__init__()
 
35
        self.hostname_regexp = hostname_regexp
 
36
        self.compiled_re = re.compile(hostname_regexp)
 
37
 
 
38
    def _probe(self):
 
39
        return self.compiled_re.search(os.uname().nodename) is not None
 
40
 
 
41
    def feature_name(self):
 
42
        return 'Running on a hostname matching {}'.format(self.hostname_regexp)
 
43
 
 
44
on_monitor = OnHost('^brz-monitor')
 
45
on_slave = OnHost('^brz-slave-')
26
46
 
27
47
 
28
48
# Features relying on an environment property should be checked before any test
31
51
 
32
52
lxd_client_feature.available()
33
53
make_feature.available()
34
 
 
 
54
flake8_feature.available()
 
55
on_monitor.available()
 
56
on_slave.available()
35
57
 
36
58
# Useful shortcuts to export but not use internally
37
59
ExecutableFeature = features.ExecutableFeature