Skip to content

Commit

Permalink
Fix system tests running locally
Browse files Browse the repository at this point in the history
  • Loading branch information
macartur committed Oct 19, 2017
1 parent ae2526f commit 7023a42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ build:
python: 3.6.0
postgresql: false
redis: false
variables:
with_sudo: true
docker:
remote_engine: true
cache:
Expand Down
34 changes: 20 additions & 14 deletions tests/test_system/test_alpine.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
"""Test connectivity between to hosts in Mininet."""
import os
from unittest import TestCase

import pexpect

CONTAINER = 'kytos_tests'
IMAGE = 'alpine'
PROMPT = '/ # '
WITH_SUDO = os.environ.get('with_sudo', True)


class TestAlpine(TestCase):
"""Test the alpine container."""

@classmethod
def execute(cls, command, expected=None, timeout=60, with_sudo=True):
if with_sudo:
command = 'sudo '+ command
cls._kytos = pexpect.spawn(command)
if expected is not None:
cls._kytos.expect(expected, timeout=timeout)

@classmethod
def setUpClass(cls):
"""Setup the alpine container.
Download the alpine image and starts a new container.
"""
# Start the docker daemon
# cls._kytos = pexpect.spawn(f'sudo dockerd')
cls._kytos = pexpect.spawn(f'sudo service docker start')
cls._kytos.expect(pexpect.EOF)
cls.execute('dockerd', with_sudo=True)
cls.execute('service docker start', with_sudo=True)

# Download the alpine container
cls._kytos = pexpect.spawn(f'sudo docker pull alpine')
expected = ['Status: Downloaded newer image for alpine:latest']
cls._kytos.expect(expected, timeout=120)
cls.execute('docker pull alpine', 'alpine:latest', with_sudo=WITH_SUDO)

# Verify whether the alpine image is installed.
cls._kytos = pexpect.spawn(f'sudo docker images')
cls._kytos.expect('alpine', timeout=60)
cls.execute('docker images', 'alpine')

# Start the alpine container to run the tests
cls._kytos = pexpect.spawn(
f'sudo docker run --rm -it --privileged --name {CONTAINER} {IMAGE}'
)
cls._kytos.expect(PROMPT, timeout=60)
cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}'
cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO)

def test0000_uname_a(self):
"""Test expected 'uname -a' command using the container."""
Expand All @@ -47,6 +50,9 @@ def test0000_uname_a(self):
def tearDownClass(cls):
"""Stop container."""
bash = pexpect.spawn('/bin/bash')
bash.sendline(f'sudo docker kill {CONTAINER} && exit')
command = f'docker kill {CONTAINER} && exit'
if WITH_SUDO:
command = 'sudo '+ command
bash.sendline(command)
bash.expect(f'\r\n{CONTAINER}\r\n', timeout=120)
bash.wait()

0 comments on commit 7023a42

Please sign in to comment.