14
15
# You should have received a copy of the GNU General Public License along with
15
16
# this program. If not, see <http://www.gnu.org/licenses/>.
17
from __future__ import unicode_literals
21
from olstests import features
22
from olsvms import subprocesses
23
from olsvms.tests import features as vms_features
20
from byot import features
25
22
HERE = os.path.abspath(os.path.dirname(__file__))
28
requires = features.requires
29
ssh_feature = vms_features.ssh_feature
32
ssh_agent_feature = features.ExecutableFeature('ssh-agent')
35
# FIXME: Should be backported to olstests -- vila 2017-01-04
36
def test_requires(test, feature):
37
"""Skip a test if a feature is not available."""
38
if not feature.available():
39
reason = '{} is not available'.format(feature.feature_name())
43
class QaStagingToken(features.Feature):
44
"""Credentials for qastaging launchpad."""
47
super(QaStagingToken, self).__init__()
48
# FIXME: This is not available in production -- vila 2016-11-25
49
# FIXME: This is a config option one way or the other. The /intent/ is
50
# for the dev to control whether he want to test against qastaging or
51
# not by providing (or not) a valid credentials file -- vila 2017-11-29
52
self.path = os.path.join(HERE, '..', '..', '..', 'my-secrets',
53
'launchpad', 'qastaging')
56
# We only test that the credentials file exists here, not its validity.
57
return os.path.exists(self.path)
59
def feature_name(self):
60
return 'An OAuth token in {} for qastaging launchpad'.format(self.path)
63
qastaging_token = QaStagingToken()
66
class BzrIdentity(features.Feature):
67
"""A feature capturing the current bzr whoami."""
70
super(BzrIdentity, self).__init__()
75
_, out, _ = subprocesses.run(['bzr', 'whoami'])
76
self.identity = out.strip()
78
except subprocesses.errors.CommandError:
81
def feature_name(self):
82
return 'An existing bazaar whoami'
85
bzr_identity = BzrIdentity()
88
class GitIdentity(features.Feature):
89
"""A feature capturing the current git user email."""
92
super(GitIdentity, self).__init__()
98
_, out, _ = subprocesses.run(['git', 'config', 'user.name'])
99
self.name = out.strip()
100
_, out, _ = subprocesses.run(['git', 'config', 'user.email'])
101
self.email = out.strip()
103
except subprocesses.errors.CommandError:
106
def feature_name(self):
107
return 'An existing git user name and email'
110
git_identity = GitIdentity()
113
class LaunchpadIdentity(features.Feature):
114
"""A feature capturing the current bzr launchpad login."""
117
super(LaunchpadIdentity, self).__init__()
122
_, out, _ = subprocesses.run(['bzr', 'launchpad-login'])
123
self.identity = out.strip()
125
except subprocesses.errors.CommandError:
128
def feature_name(self):
129
return 'An existing launchpad login'
132
launchpad_identity = LaunchpadIdentity()
24
lxd_client_feature = features.ExecutableFeature('lxc')
25
make_feature = features.ExecutableFeature('make')
135
28
# Features relying on an environment property should be checked before any test
136
29
# isolation is setup. Once this is done, they can be freely used to decorate
137
30
# tests [classes] or during setUp().
139
qastaging_token.available()
140
bzr_identity.available()
141
git_identity.available()
142
launchpad_identity.available()
32
lxd_client_feature.available()
33
make_feature.available()
36
# Useful shortcuts to export but not use internally
37
ExecutableFeature = features.ExecutableFeature
38
Feature = features.Feature
39
requires = features.requires
40
test_requires = features.test_requires