Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment support to the discover step #145

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/env/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
summary: Check environment variables handling
tier: 2
environment:
TESTING: WORKS
13 changes: 13 additions & 0 deletions tests/env/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE="tmt"

rlJournalStart
rlPhaseStartTest
rlRun "echo $TESTING | grep WORKS"
rlPhaseEnd
rlJournalEnd
16 changes: 14 additions & 2 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def lint(self):
elif len(self.summary) > 50:
echo(verdict(2, 'summary should not exceed 50 characters'))

def export(self, format_='yaml', keys=None):
def export(self, format_='yaml', keys=None, environment=None):
"""
Export test data into requested format

Expand All @@ -210,7 +210,13 @@ def export(self, format_='yaml', keys=None):
data['path'] = self.path
if self.duration is not None:
data['duration'] = self.duration
if self.environment is not None:
# Combine environment variables (plan overrides test)
if self.environment is not None or environment is not None:
combined_environment = dict()
if self.environment:
combined_environment.update(self.environment)
if environment:
combined_environment.update(environment)
data['environment'] = ' '.join(
tmt.utils.shell_variables(self.environment))
return name, data
Expand Down Expand Up @@ -249,6 +255,9 @@ def __init__(self, node, run=None):
if not isinstance(gates, list):
gates = [gates]

# Environment variables
self.environment = node.get('environment')

@staticmethod
def overview(tree):
""" Show overview of available plans """
Expand Down Expand Up @@ -300,6 +309,9 @@ def show(self):
self.ls(summary=True)
for step in self.steps(disabled=True):
step.show()
if self.environment is not None:
echo(tmt.utils.format(
'environment', self.environment, key_color='blue'))
if self.opt('verbose'):
self._sources()

Expand Down
4 changes: 3 additions & 1 deletion tmt/steps/discover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def save(self):
""" Save step data to the workdir """
super(Discover, self).save()
# Create 'tests.yaml' with the list of tests for the executor
tests = dict([test.export(format_='execute') for test in self.tests()])
tests = dict([
test.export(format_='execute', environment=self.plan.environment)
for test in self.tests()])
self.write('tests.yaml', tmt.utils.dictionary_to_yaml(tests))

def wake(self):
Expand Down
5 changes: 5 additions & 0 deletions tmt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ def format(
# Otherwise just place each item on a new line
else:
output += ('\n' + indent_string).join(value)
# Dictionary
elif isinstance(value, dict):
# Place each key value pair on a separate line
output += ('\n' + indent_string).join(
f'{item[0]}: {item[1]}' for item in value.items())
# Text
elif isinstance(value, str):
# In 'auto' mode enable wrapping when long lines present
Expand Down