Commit d7f71813 authored by chrissi^'s avatar chrissi^
Browse files

parker: move fixtures into conftest.py

parent 8b0e9c17
import pytest
import yaml
import re
def pytest_configure(config):
config.addinivalue_line("markers", "config_mode")
config.addinivalue_line("markers", "running_mode")
......@@ -11,3 +13,31 @@ def pytest_addoption(parser):
def fw_good(request):
return request.config.getoption("--good")
@pytest.fixture(scope="session")
def config():
with open("parker_test_config.yaml") as fh:
config = yaml.safe_load(fh)
return config
@pytest.fixture(scope="function")
def in_uboot(strategy):
strategy.transition("uboot")
@pytest.fixture(scope="function")
def in_good_config(strategy):
strategy.transition("good_config")
@pytest.fixture(scope="function")
def in_good_running(strategy):
strategy.transition("good_running")
def ipv6_link_local(target):
command = target.get_driver("ShellDriver")
stdout, _, code = command.run('ip address show br-client')
if code != 0:
raise Exception('Failed to get address from br-client:\n{}'.format(''.join(stdout)))
match = re.search('fe80::[^/]+', ''.join(stdout))
if not match:
raise Exception('Failed to get address from br-client: Interface does not have a link-local address')
return match[0]
......@@ -13,35 +13,7 @@ l = logging.Logger("pytest")
from labgrid import StepReporter
StepReporter()
@pytest.fixture(scope="session")
def config():
with open("parker_test_config.yaml") as fh:
config = yaml.load(fh)
return config
@pytest.fixture(scope="function")
def in_uboot(strategy):
strategy.transition("uboot")
@pytest.fixture(scope="function")
def in_good_config(strategy):
strategy.transition("good_config")
@pytest.fixture(scope="function")
def in_good_running(strategy):
strategy.transition("good_running")
@pytest.fixture(scope="function")
def ipv6_link_local(target):
command = target.get_driver("ShellDriver")
stdout, _, code = command.run('ip address show br-client')
if code != 0:
return pytest.exit('Failed to get address from br-client:\n{}'.format(''.join(stdout)))
match = re.search('fe80::[^/]+', ''.join(stdout))
if not match:
return pytest.exit('Failed to get address from br-client: Interface does not have a link-local address')
return match[0]
from conftest import ipv6_link_local
def assert_web(url, text_to_find):
r = requests.get(url)
......@@ -154,8 +126,9 @@ def test_transition_to_running_mode(in_good_running):
@pytest.mark.running_mode
@pytest.mark.flaky(reruns=10, reruns_delay=10)
def test_good_running_ssh(target, in_good_running, config, ipv6_link_local):
r = subprocess.run(["ssh", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no", "-o", "PreferredAuthentications=publickey", "-i", config["ssh_key_file"], 'root@{}%dut'.format(ipv6_link_local), "echo 1"])
def test_good_running_ssh(target, in_good_running, config):
ip = ipv6_link_local(target)
r = subprocess.run(["ssh", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no", "-o", "PreferredAuthentications=publickey", "-i", config["ssh_key_file"], 'root@{}%dut'.format(ip), "echo 1"])
assert r.returncode == 0, "SSH connection during run mode failed"
@pytest.mark.running_mode
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment