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

Added noserunner, tox and travis configuration #701

Closed
wants to merge 8 commits into from
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ client/tests/virt/virt_v2v/env
client/tests/virt/virt_v2v/*.cfg
client/tests/virt/virt_v2v/src
client/tmp
.tox*
logs/*
server/tmp
tko/parsers/test/site_scenarios
Expand All @@ -34,3 +35,7 @@ frontend/client/www/
tko/tko_pb2.py
documentation/build/*
build/*
coverage.xml
unit.xml
nosetests.xml
.cover*
9 changes: 9 additions & 0 deletions .nose.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[nosetests]
autotest-debug=1
verbosity=2
cover-erase=1
cover-package=autotest
with-xunit=1
xunit-file=xunit.xml
with-xcoverage=1
xcoverage-file=coverage.xml
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: python
python:
- "2.7"

branches:
only:
- master

install:
- pip install sphinx tox
- pip install -r requirements.txt --use-mirrors
- AUTOTEST_TOP_PATH=. python setup.py install

script:
AUTOTEST_DIR=. ./utils/unittest_suite_nose.py -c .nose.cfg -s autotest.client autotest.server autotest.utils
4 changes: 2 additions & 2 deletions client/fsinfo_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def tearDown(self):
self.god.unstub_all()


def create_test_file(self, filename, contents):
def _create_test_file(self, filename, contents):
test_file = StringIO.StringIO(contents)
fsinfo.open.expect_call(filename, 'r').and_return(test_file)

Expand Down Expand Up @@ -141,7 +141,7 @@ def test_mke2fs_conf(self):
' floppy = {\n'
' blocksize = 4096\n'
' }\n')
self.create_test_file('/etc/mke2fs.conf', content)
self._create_test_file('/etc/mke2fs.conf', content)

conf_opt = fsinfo.parse_mke2fs_conf('small')
mkfs_opt = fsinfo.convert_conf_opt(conf_opt)
Expand Down
4 changes: 2 additions & 2 deletions client/job_unittest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python

import logging, os, shutil, sys, StringIO
import logging, os, shutil, sys, StringIO, unittest
try:
import autotest.common as common
except ImportError:
Expand All @@ -12,7 +12,7 @@
from autotest.client.shared.settings import settings
from autotest.client.shared import logging_manager, logging_config
from autotest.client.shared import base_job_unittest
from autotest.client.shared.test_utils import mock, unittest
from autotest.client.shared.test_utils import mock


class job_test_case(unittest.TestCase):
Expand Down
22 changes: 12 additions & 10 deletions client/local_host_unittest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/python

import os
import unittest

try:
import autotest.common as common
except ImportError:
import common

from autotest.client.shared.test_utils import mock, unittest
from autotest.client.shared.test_utils import mock
from autotest.client.shared import autotemp
from autotest.client import local_host

Expand Down Expand Up @@ -100,9 +102,9 @@ def test_list_files_glob(self):
open(files[0], 'w').close()
open(files[1], 'w').close()

self.assertSameElements(
files,
host.list_files_glob(os.path.join(self.tmpdir.name, '*')))
self.assertTrue(
sorted(files) ==
sorted(host.list_files_glob(os.path.join(self.tmpdir.name, '*'))))


def test_symlink_closure_does_not_add_existent_file(self):
Expand All @@ -116,9 +118,9 @@ def test_symlink_closure_does_not_add_existent_file(self):

# test that when the symlinks point to already know files
# nothing is added
self.assertSameElements(
[fname, sname],
host.symlink_closure([fname, sname]))
self.assertTrue(
sorted([fname, sname]) ==
sorted(host.symlink_closure([fname, sname])))


def test_symlink_closure_adds_missing_files(self):
Expand All @@ -131,9 +133,9 @@ def test_symlink_closure_adds_missing_files(self):
os.symlink(fname, sname)

# test that when the symlinks point to unknown files they are added
self.assertSameElements(
[fname, sname],
host.symlink_closure([sname]))
self.assertTrue(
sorted([fname, sname]) ==
sorted(host.symlink_closure([sname])))


if __name__ == "__main__":
Expand Down
5 changes: 4 additions & 1 deletion client/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def get_filelist():
def get_packages():
return ['autotest.client.shared',
'autotest.client.shared.hosts',
'autotest.client.shared.backports',
'autotest.client.shared.backports.collections',
'autotest.client.shared.test_utils',
'autotest.client.net',
'autotest.client.tools',
Expand All @@ -55,7 +57,8 @@ def get_scripts():


def get_data_files():
return [('/etc/autotest', [autotest_dir + '/global_config.ini',
return [(os.environ.get('AUTOTEST_TOP_PATH', '/etc/autotest'),
[autotest_dir + '/global_config.ini',
autotest_dir + '/shadow_config.ini',]),]


Expand Down
5 changes: 3 additions & 2 deletions client/setup_job_unittest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python

import logging, os, shutil, sys, StringIO
import logging, os, shutil, sys, StringIO, unittest

try:
import autotest.common as common
except ImportError:
Expand All @@ -10,7 +11,7 @@
from autotest.client import utils
from autotest.client.shared import base_job, logging_manager, logging_config
from autotest.client.shared import base_job_unittest
from autotest.client.shared.test_utils import mock, unittest
from autotest.client.shared.test_utils import mock


class setup_job_test_case(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions client/shared/base_job_unittest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/python

import os, stat, tempfile, shutil, logging
import os, stat, tempfile, shutil, logging, unittest


try:
import autotest.common as common
except ImportError:
import common
from autotest.client.shared import base_job, error
from autotest.client.shared.test_utils import unittest

os.environ['AUTODIR'] = '/tmp/autotest'

Expand Down
22 changes: 11 additions & 11 deletions client/shared/base_utils_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,44 @@ def test_format_ip_with_mask(self):
'192.168.0.192/26')


def create_test_file(self, contents):
def _create_test_file(self, contents):
test_file = StringIO.StringIO(contents)
base_utils.open.expect_call("filename", "r").and_return(test_file)


def test_reads_one_line_file(self):
self.create_test_file("abc\n")
self._create_test_file("abc\n")
self.assertEqual("abc", base_utils.read_one_line("filename"))
self.god.check_playback()


def test_strips_read_lines(self):
self.create_test_file("abc \n")
self._create_test_file("abc \n")
self.assertEqual("abc ", base_utils.read_one_line("filename"))
self.god.check_playback()


def test_drops_extra_lines(self):
self.create_test_file("line 1\nline 2\nline 3\n")
self._create_test_file("line 1\nline 2\nline 3\n")
self.assertEqual("line 1", base_utils.read_one_line("filename"))
self.god.check_playback()


def test_works_on_empty_file(self):
self.create_test_file("")
self._create_test_file("")
self.assertEqual("", base_utils.read_one_line("filename"))
self.god.check_playback()


def test_works_on_file_with_no_newlines(self):
self.create_test_file("line but no newline")
self._create_test_file("line but no newline")
self.assertEqual("line but no newline",
base_utils.read_one_line("filename"))
self.god.check_playback()


def test_preserves_leading_whitespace(self):
self.create_test_file(" has leading whitespace")
self._create_test_file(" has leading whitespace")
self.assertEqual(" has leading whitespace",
base_utils.read_one_line("filename"))

Expand Down Expand Up @@ -204,15 +204,15 @@ def tearDown(self):
self.god.unstub_all()


def create_test_file(self, filename, contents):
def _create_test_file(self, filename, contents):
test_file = StringIO.StringIO(contents)
os.path.exists.expect_call(filename).and_return(True)
base_utils.open.expect_call(filename).and_return(test_file)


def read_keyval(self, contents):
os.path.isdir.expect_call("file").and_return(False)
self.create_test_file("file", contents)
self._create_test_file("file", contents)
keyval = base_utils.read_keyval("file")
self.god.check_playback()
return keyval
Expand All @@ -227,14 +227,14 @@ def test_returns_empty_when_file_doesnt_exist(self):

def test_accesses_files_directly(self):
os.path.isdir.expect_call("file").and_return(False)
self.create_test_file("file", "")
self._create_test_file("file", "")
base_utils.read_keyval("file")
self.god.check_playback()


def test_accesses_directories_through_keyval_file(self):
os.path.isdir.expect_call("dir").and_return(True)
self.create_test_file("dir/keyval", "")
self._create_test_file("dir/keyval", "")
base_utils.read_keyval("dir")
self.god.check_playback()

Expand Down
3 changes: 2 additions & 1 deletion client/shared/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class SettingsValueError(SettingsError):
shared_dir = os.path.dirname(sys.modules[__name__].__file__)
client_dir = os.path.dirname(shared_dir)
root_dir = os.path.dirname(client_dir)
system_wide_dir = '/etc/autotest'

system_wide_dir = os.environ.get('AUTOTEST_TOP_PATH', '/etc/autotest')

# Check if the config files are in the system wide directory
settings_path_system_wide = os.path.join(system_wide_dir,
Expand Down
3 changes: 2 additions & 1 deletion client/shared/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

_ROOT_PATH = os.path.join(sys.modules[__name__].__file__, "..", "..", "..")
_ROOT_PATH = os.path.abspath(_ROOT_PATH)

RELEASE_VERSION_PATH = os.path.join(_ROOT_PATH, 'RELEASE-VERSION')


Expand All @@ -49,7 +50,7 @@ def call_git_describe(abbrev=4):
os.chdir(_ROOT_PATH)
try:
try:
command = 'git describe --abbrev=%d' % abbrev
command = 'git describe --abbrev=%d --always' % abbrev
output = utils.system_output(command, verbose=False)
# Since github won't host arbitray uploads anymore,
# our new tags have to be prepended with autotest-
Expand Down
24 changes: 24 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#Jinja2==2.7
#MarkupSafe==0.18
#Pygments==1.6
Sphinx==1.2b1
#argparse==1.2.1
coverage==3.6
#distribute==0.6.24
#docutils==0.10
#ipython==0.13.2
nose==1.3.0
nosexcover==1.0.8
#py==1.4.15
tox==1.5.0
virtualenv==1.9.1
#wsgiref==0.1.2
#mysql-python==1.2.3
django==1.5.1
#numpy==1.3.0
#matplotlib==0.98.5
#atfork==0.1.2
#paramiko==1.7.5
#simplejson==2.0.9
#httplib2==0.6.0

3 changes: 1 addition & 2 deletions server/hosts/monitors/console_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

"""Tests for console.py"""

import os, shutil, signal, StringIO, tempfile
import os, shutil, signal, StringIO, tempfile, unittest

import common
from autotest.client.shared.test_utils import mock
from autotest.client.shared.test_utils import unittest
from autotest.server.hosts.monitors import console

class console_test(unittest.TestCase):
Expand Down
4 changes: 3 additions & 1 deletion server/server_job_unittest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/python

import unittest

try:
import autotest.common as common
except ImportError:
import common

from autotest.server import server_job
from autotest.client.shared import base_job_unittest
from autotest.client.shared.test_utils import mock, unittest
from autotest.client.shared.test_utils import mock


class test_find_base_directories(
Expand Down
19 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tox]
envlist = py24, py25, py26, py27

[testenv]
deps =
-r{toxinidir}/requirements.txt

setenv=
AUTOTEST_TOP_PATH={toxinidir}
AUTOTEST_DIR={toxinidir}
AUTOTEST_SERVER_DIR={toxinidir}
AUTOTEST_SCHEDULER_LOG_DIR={toxinidir}

commands=
{toxinidir}/utils/unittest_suite_nose.py -c {toxinidir}/.nose.cfg -s autotest.client autotest.server autotest.utils

[testenv:pylint]
deps=pylint
commands= {toxinidir}/utils/run_pylint.py