From bc9bf90b34df5f6a13e5cc7ce567fddc089bce98 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 18 Oct 2017 16:21:53 -0200 Subject: [PATCH 01/17] Add system tests with scrutinizer --- .scrutinizer.yml | 5 +++ tests/test_system/__init__.py | 1 + tests/test_system/test_alpine.py | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/test_system/__init__.py create mode 100644 tests/test_system/test_alpine.py diff --git a/.scrutinizer.yml b/.scrutinizer.yml index b4c11545d..f925de3e7 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -11,6 +11,11 @@ build: python: 3.6.0 postgresql: false redis: false + docker: + remote_engine: true + cache: + images: + - "alpine" dependencies: before: - pip install coverage git+git://github.com/diraol/watchdog.git#egg=watchdog diff --git a/tests/test_system/__init__.py b/tests/test_system/__init__.py new file mode 100644 index 000000000..47be16f8c --- /dev/null +++ b/tests/test_system/__init__.py @@ -0,0 +1 @@ +"""Module with system tests.""" diff --git a/tests/test_system/test_alpine.py b/tests/test_system/test_alpine.py new file mode 100644 index 000000000..56939be15 --- /dev/null +++ b/tests/test_system/test_alpine.py @@ -0,0 +1,52 @@ +"""Test connectivity between to hosts in Mininet.""" +from unittest import TestCase + +import pexpect + +CONTAINER = 'kytos_tests' +IMAGE = 'alpine' +PROMPT = '/ # ' + + +class TestAlpine(TestCase): + """Test the alpine container.""" + + @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) + + # 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) + + # Verify whether the alpine image is installed. + cls._kytos = pexpect.spawn(f'sudo docker images') + cls._kytos.expect('alpine', timeout=60) + + # 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) + + def test0000_uname_a(self): + """Test expected 'uname -a' command using the container.""" + expected = ["Linux", "4.13.0-1-amd64", "#1 SMP Debian 4.13.4-2"] + self._kytos.sendline('uname -a') + self._kytos.expect(expected) + + @classmethod + def tearDownClass(cls): + """Stop container.""" + bash = pexpect.spawn('/bin/bash') + bash.sendline(f'sudo docker kill {CONTAINER} && exit') + bash.expect(f'\r\n{CONTAINER}\r\n', timeout=120) + bash.wait() From 7c7cd65e89a0de3f573e80033016ab3ae279459f Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 20:20:36 -0200 Subject: [PATCH 02/17] Fix alpine run locally --- tests/test_system/test_alpine.py | 36 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/test_system/test_alpine.py b/tests/test_system/test_alpine.py index 56939be15..ab8bbe685 100644 --- a/tests/test_system/test_alpine.py +++ b/tests/test_system/test_alpine.py @@ -1,4 +1,6 @@ """Test connectivity between to hosts in Mininet.""" +import os +import sys from unittest import TestCase import pexpect @@ -6,36 +8,39 @@ CONTAINER = 'kytos_tests' IMAGE = 'alpine' PROMPT = '/ # ' +WITH_SUDO = False if os.geteuid() != 0 else True class TestAlpine(TestCase): """Test the alpine container.""" + @classmethod + def execute(cls, command, expected=None, timeout=60, with_sudo=False): + """Execute command inside the bash""" + 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.""" @@ -47,6 +52,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() From dfbcb267c99c4c062fda9570b5cea1c7aec53b03 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 20:29:43 -0200 Subject: [PATCH 03/17] Add struct --- tests/test_system/struct.py | 54 +++++++++++++++++++++++++++++ tests/test_system/test_container.py | 12 +++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/test_system/struct.py create mode 100644 tests/test_system/test_container.py diff --git a/tests/test_system/struct.py b/tests/test_system/struct.py new file mode 100644 index 000000000..bf54fe992 --- /dev/null +++ b/tests/test_system/struct.py @@ -0,0 +1,54 @@ +"""Test connectivity between to hosts in Mininet.""" +import os +from unittest import TestCase + +import pexpect + +CONTAINER = 'kytos_tests' +IMAGE = 'kytos/systests' +PROMPT = 'root@.*:/usr/local/src/kytos# ' +WITH_SUDO = False if os.geteuid() else True + + +class TestStruct(TestCase): + """Test the alpine container.""" + + @classmethod + def execute(cls, command, expected=None, timeout=60, with_sudo=False): + """Execute command inside the bash""" + if with_sudo: + command = 'sudo ' + command + terminal = pexpect.spawn(command) + if expected is not None: + terminal.expect(expected, timeout=timeout) + return terminal + + @classmethod + def setUpClass(cls): + """Setup the container. + + Download the image and starts a new container. + """ + cls.execute('dockerd', with_sudo=True) + cls.execute('service docker start', with_sudo=True) + + # Download the container + cls.execute(f'docker pull {IMAGE}', f'{IMAGE}:latest', with_sudo=WITH_SUDO) + + # Verify whether the image is installed. + cls.execute('docker images', f'{IMAGE}') + + # Start the container to run the tests + cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' + cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + + @classmethod + def tearDownClass(cls): + """Stop container.""" + bash = pexpect.spawn('/bin/bash') + 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() diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py new file mode 100644 index 000000000..3b80f21a1 --- /dev/null +++ b/tests/test_system/test_container.py @@ -0,0 +1,12 @@ +"""Test container module.""" +from .struct import TestStruct + + +class TestContainer(TestStruct): + """Container class.""" + + def test_uname_a(self): + """Test expected 'uname -a' command using the container.""" + expected = ["Linux", "4.13.0-1-amd64", "#1 SMP Debian 4.13.4-2"] + self._kytos.sendline('uname -a') + self._kytos.expect(expected) From c83aaab1563ad97fd05dbaa2cb2a130405a60c14 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 20:30:25 -0200 Subject: [PATCH 04/17] remove alpine --- tests/test_system/test_alpine.py | 60 -------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 tests/test_system/test_alpine.py diff --git a/tests/test_system/test_alpine.py b/tests/test_system/test_alpine.py deleted file mode 100644 index ab8bbe685..000000000 --- a/tests/test_system/test_alpine.py +++ /dev/null @@ -1,60 +0,0 @@ -"""Test connectivity between to hosts in Mininet.""" -import os -import sys -from unittest import TestCase - -import pexpect - -CONTAINER = 'kytos_tests' -IMAGE = 'alpine' -PROMPT = '/ # ' -WITH_SUDO = False if os.geteuid() != 0 else True - - -class TestAlpine(TestCase): - """Test the alpine container.""" - - @classmethod - def execute(cls, command, expected=None, timeout=60, with_sudo=False): - """Execute command inside the bash""" - 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. - """ - cls.execute('dockerd', with_sudo=True) - cls.execute('service docker start', with_sudo=True) - - # Download the alpine container - cls.execute('docker pull alpine', 'alpine:latest', with_sudo=WITH_SUDO) - - # Verify whether the alpine image is installed. - cls.execute('docker images', 'alpine') - - # Start the alpine container to run the tests - 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.""" - expected = ["Linux", "4.13.0-1-amd64", "#1 SMP Debian 4.13.4-2"] - self._kytos.sendline('uname -a') - self._kytos.expect(expected) - - @classmethod - def tearDownClass(cls): - """Stop container.""" - bash = pexpect.spawn('/bin/bash') - 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() From 66e9e3b3eed480daf3a2a8e73ea21a9d70dbdca9 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 20:36:56 -0200 Subject: [PATCH 05/17] Fix test --- tests/test_system/struct.py | 54 --------------------------- tests/test_system/test_container.py | 58 ++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 59 deletions(-) delete mode 100644 tests/test_system/struct.py diff --git a/tests/test_system/struct.py b/tests/test_system/struct.py deleted file mode 100644 index bf54fe992..000000000 --- a/tests/test_system/struct.py +++ /dev/null @@ -1,54 +0,0 @@ -"""Test connectivity between to hosts in Mininet.""" -import os -from unittest import TestCase - -import pexpect - -CONTAINER = 'kytos_tests' -IMAGE = 'kytos/systests' -PROMPT = 'root@.*:/usr/local/src/kytos# ' -WITH_SUDO = False if os.geteuid() else True - - -class TestStruct(TestCase): - """Test the alpine container.""" - - @classmethod - def execute(cls, command, expected=None, timeout=60, with_sudo=False): - """Execute command inside the bash""" - if with_sudo: - command = 'sudo ' + command - terminal = pexpect.spawn(command) - if expected is not None: - terminal.expect(expected, timeout=timeout) - return terminal - - @classmethod - def setUpClass(cls): - """Setup the container. - - Download the image and starts a new container. - """ - cls.execute('dockerd', with_sudo=True) - cls.execute('service docker start', with_sudo=True) - - # Download the container - cls.execute(f'docker pull {IMAGE}', f'{IMAGE}:latest', with_sudo=WITH_SUDO) - - # Verify whether the image is installed. - cls.execute('docker images', f'{IMAGE}') - - # Start the container to run the tests - cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' - cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) - - @classmethod - def tearDownClass(cls): - """Stop container.""" - bash = pexpect.spawn('/bin/bash') - 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() diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index 3b80f21a1..894b3e0e2 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -1,12 +1,60 @@ -"""Test container module.""" -from .struct import TestStruct +"""Test connectivity between to hosts in Mininet.""" +import os +from unittest import TestCase +import pexpect -class TestContainer(TestStruct): - """Container class.""" +CONTAINER = 'kytos_tests' +IMAGE = 'kytos/systests' +PROMPT = 'root@.*:/usr/local/src/kytos# ' +WITH_SUDO = True if os.geteuid() == 0 else False - def test_uname_a(self): + +class TestStruct(TestCase): + """Test the alpine container.""" + + @classmethod + def execute(cls, command, expected=None, timeout=60, with_sudo=False): + """Execute command inside the bash""" + 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 container. + + Download the image and starts a new container. + """ + cls.execute('dockerd', with_sudo=True) + cls.execute('service docker start', with_sudo=True) + + # Download the container + cls.execute(f'docker pull {IMAGE}', f'{IMAGE}:latest', + with_sudo=WITH_SUDO) + + # Verify whether the image is installed. + cls.execute('docker images', f'{IMAGE}') + + # Start the container to run the tests + cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' + cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + + def test000_uname_a(self): """Test expected 'uname -a' command using the container.""" expected = ["Linux", "4.13.0-1-amd64", "#1 SMP Debian 4.13.4-2"] self._kytos.sendline('uname -a') self._kytos.expect(expected) + + @classmethod + def tearDownClass(cls): + """Stop container.""" + bash = pexpect.spawn('/bin/bash') + 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() From ac5a8b7c6418ab63f18c7f54befb94b9400bb310 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 21:09:42 -0200 Subject: [PATCH 06/17] Update timeout --- tests/test_system/test_container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index 894b3e0e2..dfa6f20ef 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -14,7 +14,7 @@ class TestStruct(TestCase): """Test the alpine container.""" @classmethod - def execute(cls, command, expected=None, timeout=60, with_sudo=False): + def execute(cls, command, expected=None, timeout=120, with_sudo=False): """Execute command inside the bash""" if with_sudo: command = 'sudo ' + command From a7f8e80a8ab91f78ba0185dd451ba6e200eaf7d6 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 21:45:07 -0200 Subject: [PATCH 07/17] ADd sudo --- tests/test_system/test_container.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index dfa6f20ef..d6421d72e 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -1,5 +1,4 @@ """Test connectivity between to hosts in Mininet.""" -import os from unittest import TestCase import pexpect @@ -7,14 +6,14 @@ CONTAINER = 'kytos_tests' IMAGE = 'kytos/systests' PROMPT = 'root@.*:/usr/local/src/kytos# ' -WITH_SUDO = True if os.geteuid() == 0 else False +WITH_SUDO = True class TestStruct(TestCase): """Test the alpine container.""" @classmethod - def execute(cls, command, expected=None, timeout=120, with_sudo=False): + def execute(cls, command, expected=None, timeout=60, with_sudo=False): """Execute command inside the bash""" if with_sudo: command = 'sudo ' + command @@ -36,7 +35,7 @@ def setUpClass(cls): with_sudo=WITH_SUDO) # Verify whether the image is installed. - cls.execute('docker images', f'{IMAGE}') + cls.execute('docker images', f'{IMAGE}', with_sudo=WITH_SUDO) # Start the container to run the tests cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' From 38128cdea830c3463d8f342672faf5a98bf782ae Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 22:25:46 -0200 Subject: [PATCH 08/17] Add test to test python-openflow instalation --- tests/test_system/test_container.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index d6421d72e..ed9d58191 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -1,4 +1,5 @@ """Test connectivity between to hosts in Mininet.""" +import os from unittest import TestCase import pexpect @@ -6,7 +7,7 @@ CONTAINER = 'kytos_tests' IMAGE = 'kytos/systests' PROMPT = 'root@.*:/usr/local/src/kytos# ' -WITH_SUDO = True +WITH_SUDO = True if os.geteuid() == 0 else False class TestStruct(TestCase): @@ -17,9 +18,10 @@ def execute(cls, command, expected=None, timeout=60, with_sudo=False): """Execute command inside the bash""" if with_sudo: command = 'sudo ' + command - cls._kytos = pexpect.spawn(command) + terminal = pexpect.spawn(command) if expected is not None: - cls._kytos.expect(expected, timeout=timeout) + terminal.expect(expected, timeout=timeout) + return terminal @classmethod def setUpClass(cls): @@ -39,13 +41,29 @@ def setUpClass(cls): # Start the container to run the tests cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' - cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) def test000_uname_a(self): """Test expected 'uname -a' command using the container.""" expected = ["Linux", "4.13.0-1-amd64", "#1 SMP Debian 4.13.4-2"] self._kytos.sendline('uname -a') self._kytos.expect(expected) + self._kytos.expect(PROMPT) + + def test00_update_repositories(self): + """Update all repositories.""" + self._kytos.sendline('kytos-update') + self._kytos.expect(['Fast-forward', 'up-to-date']) + self._kytos.expect(PROMPT) + + def test01_install_projects(self): + """Install Kytos projects from cloned repository in safe order.""" + pip = 'pip install --no-index --find-links $KYTOSDEPSDIR .' + PROJECTS = ['python-openflow'] + for project in PROJECTS: + self._kytos.sendline(f'cd $KYTOSDIR/{project}; {pip}; cd -') + self._kytos.expect(f'Successfully installed .*{project}', timeout=30) + self._kytos.expect(PROMPT) @classmethod def tearDownClass(cls): From e63ef3c46a356d1996badb6dcb8ec28492498ba7 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 22:28:53 -0200 Subject: [PATCH 09/17] Add True --- tests/test_system/test_container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index ed9d58191..fcb8fc041 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -7,7 +7,7 @@ CONTAINER = 'kytos_tests' IMAGE = 'kytos/systests' PROMPT = 'root@.*:/usr/local/src/kytos# ' -WITH_SUDO = True if os.geteuid() == 0 else False +WITH_SUDO = True class TestStruct(TestCase): From d8ba75d5265a076179c5cd472e8d26ae9ab93bbe Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 28 Nov 2017 22:36:03 -0200 Subject: [PATCH 10/17] Add new feature --- tests/test_system/test_container.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index fcb8fc041..f35333698 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -56,15 +56,6 @@ def test00_update_repositories(self): self._kytos.expect(['Fast-forward', 'up-to-date']) self._kytos.expect(PROMPT) - def test01_install_projects(self): - """Install Kytos projects from cloned repository in safe order.""" - pip = 'pip install --no-index --find-links $KYTOSDEPSDIR .' - PROJECTS = ['python-openflow'] - for project in PROJECTS: - self._kytos.sendline(f'cd $KYTOSDIR/{project}; {pip}; cd -') - self._kytos.expect(f'Successfully installed .*{project}', timeout=30) - self._kytos.expect(PROMPT) - @classmethod def tearDownClass(cls): """Stop container.""" From f7427d07cca0d4d0925151a2eec355ba493633a6 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 29 Nov 2017 10:54:13 -0200 Subject: [PATCH 11/17] Test works fine --- tests/test_system/test_container.py | 39 +++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index f35333698..5c29d806a 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -7,8 +7,9 @@ CONTAINER = 'kytos_tests' IMAGE = 'kytos/systests' PROMPT = 'root@.*:/usr/local/src/kytos# ' -WITH_SUDO = True - +WITH_SUDO = True if (os.geteuid() == 0) else False +PROJECTS = ['python-openflow', 'kytos-utils', 'kytos'] +NAPPS = ['kytos/of_core', 'kytos/of_lldp'] class TestStruct(TestCase): """Test the alpine container.""" @@ -42,6 +43,11 @@ def setUpClass(cls): # Start the container to run the tests cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + cmd = f'docker exec -it --privileged {CONTAINER} /bin/bash' + cls._mininet = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + + cls._kytos.sendline("pip install ruamel.yaml") + cls._kytos.expect("Successfully installed ruamel.yaml") def test000_uname_a(self): """Test expected 'uname -a' command using the container.""" @@ -56,6 +62,35 @@ def test00_update_repositories(self): self._kytos.expect(['Fast-forward', 'up-to-date']) self._kytos.expect(PROMPT) + def test01_install_projects(self): + """Install Kytos projects from cloned repository in safe order.""" + pip = 'pip install --no-index --find-links $KYTOSDEPSDIR .' + + for project in PROJECTS: + self._kytos.sendline(f'cd $KYTOSDIR/{project}; {pip}; cd -') + self._kytos.expect(f'Successfully installed .*{project}', + timeout=60) + self._kytos.expect(PROMPT) + + def test02_launch_kytosd(self): + """kytos-utils requires kytosd to be running.""" + self._kytos.sendline('kytosd -f') + # Regex is for color codes + self._kytos.expect(r'kytos \$> ') + + def test03_install_napps(self): + """Install NApps for the ping to work. + + + As self._kytos is blocked in kytosd shell, we use mininet terminal. + """ + for napp in NAPPS: + self._mininet.sendline(f'kytos napps install {napp}') + self._mininet.expect('INFO Enabled.') + napp_name = napp.split('/')[0] + self._kytos.expect(napp_name +'.+Running NApp') + self._mininet.expect(PROMPT) + @classmethod def tearDownClass(cls): """Stop container.""" From c43732514603fde10b8815ec200507055c485aee Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 29 Nov 2017 11:27:33 -0200 Subject: [PATCH 12/17] Fix start docker --- tests/test_system/test_container.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index 5c29d806a..1b85908c4 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -30,8 +30,8 @@ def setUpClass(cls): Download the image and starts a new container. """ - cls.execute('dockerd', with_sudo=True) - cls.execute('service docker start', with_sudo=True) + cls.execute('service docker start', 'docker start/running', with_sudo=True) + print(WITH_SUDO) # Download the container cls.execute(f'docker pull {IMAGE}', f'{IMAGE}:latest', @@ -43,6 +43,7 @@ def setUpClass(cls): # Start the container to run the tests cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + cmd = f'docker exec -it --privileged {CONTAINER} /bin/bash' cls._mininet = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) From 8151143c2e9b8d9e9274a84b81e15325f03a5a65 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 29 Nov 2017 12:21:31 -0200 Subject: [PATCH 13/17] Add true value --- tests/test_system/test_container.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index 1b85908c4..4d781f10e 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -7,7 +7,7 @@ CONTAINER = 'kytos_tests' IMAGE = 'kytos/systests' PROMPT = 'root@.*:/usr/local/src/kytos# ' -WITH_SUDO = True if (os.geteuid() == 0) else False +WITH_SUDO = True PROJECTS = ['python-openflow', 'kytos-utils', 'kytos'] NAPPS = ['kytos/of_core', 'kytos/of_lldp'] @@ -30,22 +30,23 @@ def setUpClass(cls): Download the image and starts a new container. """ + cls.execute('dockerd', with_sudo=True) + cls.execute('service docker start', 'docker start/running', with_sudo=True) - print(WITH_SUDO) # Download the container cls.execute(f'docker pull {IMAGE}', f'{IMAGE}:latest', - with_sudo=WITH_SUDO) + with_sudo=True) # Verify whether the image is installed. - cls.execute('docker images', f'{IMAGE}', with_sudo=WITH_SUDO) + cls.execute('docker images', f'{IMAGE}', with_sudo=True) # Start the container to run the tests cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' - cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + cls._kytos = cls.execute(cmd, PROMPT, with_sudo=True) cmd = f'docker exec -it --privileged {CONTAINER} /bin/bash' - cls._mininet = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + cls._mininet = cls.execute(cmd, PROMPT, with_sudo=True) cls._kytos.sendline("pip install ruamel.yaml") cls._kytos.expect("Successfully installed ruamel.yaml") From 5394b73d388760c8270991684b5d175cf94bdd8d Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 29 Nov 2017 12:57:38 -0200 Subject: [PATCH 14/17] Remove mininet commands --- tests/test_system/test_container.py | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index 4d781f10e..797d354bb 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -7,7 +7,7 @@ CONTAINER = 'kytos_tests' IMAGE = 'kytos/systests' PROMPT = 'root@.*:/usr/local/src/kytos# ' -WITH_SUDO = True +WITH_SUDO = True if (os.environ.get('USER') is None) else False PROJECTS = ['python-openflow', 'kytos-utils', 'kytos'] NAPPS = ['kytos/of_core', 'kytos/of_lldp'] @@ -36,17 +36,17 @@ def setUpClass(cls): # Download the container cls.execute(f'docker pull {IMAGE}', f'{IMAGE}:latest', - with_sudo=True) + with_sudo=WITH_SUDO) # Verify whether the image is installed. - cls.execute('docker images', f'{IMAGE}', with_sudo=True) + cls.execute('docker images', f'{IMAGE}', with_sudo=WITH_SUDO) # Start the container to run the tests cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' - cls._kytos = cls.execute(cmd, PROMPT, with_sudo=True) + cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) - cmd = f'docker exec -it --privileged {CONTAINER} /bin/bash' - cls._mininet = cls.execute(cmd, PROMPT, with_sudo=True) +# cmd = f'docker exec -it --privileged {CONTAINER} /bin/bash' +# cls._mininet = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) cls._kytos.sendline("pip install ruamel.yaml") cls._kytos.expect("Successfully installed ruamel.yaml") @@ -80,18 +80,18 @@ def test02_launch_kytosd(self): # Regex is for color codes self._kytos.expect(r'kytos \$> ') - def test03_install_napps(self): - """Install NApps for the ping to work. - - - As self._kytos is blocked in kytosd shell, we use mininet terminal. - """ - for napp in NAPPS: - self._mininet.sendline(f'kytos napps install {napp}') - self._mininet.expect('INFO Enabled.') - napp_name = napp.split('/')[0] - self._kytos.expect(napp_name +'.+Running NApp') - self._mininet.expect(PROMPT) +# def test03_install_napps(self): +# """Install NApps for the ping to work. +# +# +# As self._kytos is blocked in kytosd shell, we use mininet terminal. +# """ +# for napp in NAPPS: +# self._mininet.sendline(f'kytos napps install {napp}') +# self._mininet.expect('INFO Enabled.') +# napp_name = napp.split('/')[0] +# self._kytos.expect(napp_name +'.+Running NApp') +# self._mininet.expect(PROMPT) @classmethod def tearDownClass(cls): From 0920dc65682405b68f639c31999fc744c7184110 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 29 Nov 2017 13:05:27 -0200 Subject: [PATCH 15/17] Add mininet command --- tests/test_system/test_container.py | 36 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index 797d354bb..40d726e8e 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -11,6 +11,7 @@ PROJECTS = ['python-openflow', 'kytos-utils', 'kytos'] NAPPS = ['kytos/of_core', 'kytos/of_lldp'] + class TestStruct(TestCase): """Test the alpine container.""" @@ -30,9 +31,10 @@ def setUpClass(cls): Download the image and starts a new container. """ - cls.execute('dockerd', with_sudo=True) - - cls.execute('service docker start', 'docker start/running', with_sudo=True) + if WITH_SUDO: + cls.execute('dockerd', with_sudo=True) + cls.execute('service docker start', 'docker start/running', + with_sudo=True) # Download the container cls.execute(f'docker pull {IMAGE}', f'{IMAGE}:latest', @@ -45,8 +47,8 @@ def setUpClass(cls): cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) -# cmd = f'docker exec -it --privileged {CONTAINER} /bin/bash' -# cls._mininet = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) + cmd = f'docker exec -it {CONTAINER} /bin/bash' + cls._mininet = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) cls._kytos.sendline("pip install ruamel.yaml") cls._kytos.expect("Successfully installed ruamel.yaml") @@ -80,18 +82,18 @@ def test02_launch_kytosd(self): # Regex is for color codes self._kytos.expect(r'kytos \$> ') -# def test03_install_napps(self): -# """Install NApps for the ping to work. -# -# -# As self._kytos is blocked in kytosd shell, we use mininet terminal. -# """ -# for napp in NAPPS: -# self._mininet.sendline(f'kytos napps install {napp}') -# self._mininet.expect('INFO Enabled.') -# napp_name = napp.split('/')[0] -# self._kytos.expect(napp_name +'.+Running NApp') -# self._mininet.expect(PROMPT) + def test03_install_napps(self): + """Install NApps for the ping to work. + + + As self._kytos is blocked in kytosd shell, we use mininet terminal. + """ + for napp in NAPPS: + self._mininet.sendline(f'kytos napps install {napp}') + self._mininet.expect('INFO Enabled.') + napp_name = napp.split('/')[0] + self._kytos.expect(napp_name + '.+Running NApp') + self._mininet.expect(PROMPT) @classmethod def tearDownClass(cls): From bcaa821aef013d5606d7f9c6d4abb24c942a83fd Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 29 Nov 2017 13:53:48 -0200 Subject: [PATCH 16/17] Add launch mininet --- tests/test_system/test_container.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index 40d726e8e..a8e64d374 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -95,6 +95,13 @@ def test03_install_napps(self): self._kytos.expect(napp_name + '.+Running NApp') self._mininet.expect(PROMPT) + def test04_launch_mininet(self): + """Start mininet with OF 1.0 and Kytos as controller.""" + self._mininet.sendline( + 'mn --topo linear,2 --mac --controller=remote,ip=127.0.0.1' + ' --switch ovsk,protocols=OpenFlow10') + self._mininet.expect('mininet> ', timeout=120) + @classmethod def tearDownClass(cls): """Stop container.""" From a94eacd18ec6d4cde717e799cb6495e5a46b3895 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Thu, 30 Nov 2017 09:06:20 -0200 Subject: [PATCH 17/17] Add --privileged --- tests/test_system/test_container.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_system/test_container.py b/tests/test_system/test_container.py index a8e64d374..d5a50a0aa 100644 --- a/tests/test_system/test_container.py +++ b/tests/test_system/test_container.py @@ -44,10 +44,10 @@ def setUpClass(cls): cls.execute('docker images', f'{IMAGE}', with_sudo=WITH_SUDO) # Start the container to run the tests - cmd = f'docker run --rm -it --name {CONTAINER} {IMAGE}' + cmd = f'docker run --rm -it --privileged --name {CONTAINER} {IMAGE}' cls._kytos = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) - cmd = f'docker exec -it {CONTAINER} /bin/bash' + cmd = f'docker exec -it --privileged {CONTAINER} /bin/bash' cls._mininet = cls.execute(cmd, PROMPT, with_sudo=WITH_SUDO) cls._kytos.sendline("pip install ruamel.yaml")