Skip to content

Commit

Permalink
First commit to start working on test coverage
Browse files Browse the repository at this point in the history
Main change is to tox.ini. Changed to give a coverage report when
the tests are run. Right now it looks pretty sad, but I am
planning to improve that. Also, changed the test environments to
only python2.7, python3.4, and pep8. The other changes were done to
get pep8 to pass.

Change-Id: Ia8b782c191325bbce4cac815998990d983f955ee
  • Loading branch information
John Trowbridge authored and strider committed Feb 4, 2015
1 parent ce684dc commit 764e4f8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 34 deletions.
2 changes: 1 addition & 1 deletion delorean/__init__.py
Expand Up @@ -16,4 +16,4 @@


__version__ = pbr.version.VersionInfo(
'delorean').version_string()
'delorean').version_string()
66 changes: 41 additions & 25 deletions delorean/shell.py
@@ -1,5 +1,18 @@
import ConfigParser
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


import argparse
import ConfigParser
import copy
import logging
import os
Expand All @@ -12,10 +25,9 @@

import sh

from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy import create_engine, Column, desc, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import desc

import rdoinfo

Expand Down Expand Up @@ -93,8 +105,12 @@ def main():
# saying "optional arguments" to just "arguments":
parser._optionals.title = 'arguments'

parser.add_argument('--config-file', help="Config file (required)", required=True)
parser.add_argument('--info-file', help="Package info file (required)", required=True)
parser.add_argument('--config-file',
help="Config file (required)",
required=True)
parser.add_argument('--info-file',
help="Package info file (required)",
required=True)
parser.add_argument('--build-env', action='append',
help="Variables for the build environment.")
parser.add_argument('--local', action="store_true",
Expand All @@ -104,8 +120,8 @@ def main():
parser.add_argument('--package-name',
help="Build a specific package name only.")
parser.add_argument('--dev', action="store_true",
help="Don't reset packaging git repo, force build "\
"and add public master repo for dependencies "\
help="Don't reset packaging git repo, force build "
"and add public master repo for dependencies "
"(dev mode).")

options, args = parser.parse_known_args(sys.argv[1:])
Expand All @@ -126,15 +142,13 @@ def main():
for package in package_info["packages"]:
project = package["name"]
since = "-1"
spec_hash = None
commit = session.query(Commit).filter(Commit.project_name == project).\
order_by(desc(Commit.dt_commit)).\
order_by(desc(Commit.id)).first()
if commit:
# This will return all commits since the last handled commit
# including the last handled commit, remove it later if needed.
since = "--after=%d" % (commit.dt_commit)
spec_hash = commit.spec_hash
repo = package["upstream"]
spec = package["master-distgit"]
if not options.package_name or package["name"] == options.package_name:
Expand Down Expand Up @@ -162,12 +176,12 @@ def main():
for commit in toprocess:
project = commit.project_name

project_info = session.query(Project).filter(Project.project_name == project).first()
project_info = session.query(Project).filter(
Project.project_name == project).first()
if not project_info:
project_info = Project(project_name=project, last_email=0)

commit_hash = commit.commit_hash
spec_hash = commit.spec_hash

logger.info("Processing %s %s" % (project, commit_hash))
notes = ""
Expand Down Expand Up @@ -256,8 +270,8 @@ def refreshrepo(url, path, branch="master", local=False):


def getinfo(cp, project, repo, spec, since, local, dev_mode):
spec_dir = os.path.join(cp.get("DEFAULT", "datadir"), project+"_spec")
# TODO : Add support for multiple distros
spec_dir = os.path.join(cp.get("DEFAULT", "datadir"), project + "_spec")
# TODO(someone) : Add support for multiple distros
spec_branch = cp.get("DEFAULT", "distros")

spec_hash = "dev"
Expand Down Expand Up @@ -290,12 +304,12 @@ def getinfo(cp, project, repo, spec, since, local, dev_mode):


def testpatches(cp, project, commit, datadir):
spec_dir = os.path.join(datadir, project+"_spec")
spec_dir = os.path.join(datadir, project + "_spec")
git = sh.git.bake(_cwd=spec_dir, _tty_out=False)
try:
# This remote mightn't exist yet
git.remote("rm", "upstream")
except:
except Exception:
pass

# If the upstream dir is not a git repo, it contains multiple git repos
Expand All @@ -305,13 +319,13 @@ def testpatches(cp, project, commit, datadir):
git.remote("add", "upstream", "-f", "file://%s/%s/" % (datadir, project))
try:
git.checkout("master-patches")
except:
except Exception:
# This project doesn't have a master-patches branch
return
git.reset("--hard", "origin/master-patches")
try:
git.rebase(commit)
except:
except Exception:
git.rebase("--abort")
raise Exception("Patches rebase failed")
spec_branch = cp.get("DEFAULT", "distros")
Expand All @@ -320,7 +334,7 @@ def testpatches(cp, project, commit, datadir):

def build(cp, package_info, commit, env_vars, dev_mode):
datadir = os.path.realpath(cp.get("DEFAULT", "datadir"))
# TODO : only working by convention need to improve
# TODO(trown) : only working by convention need to improve
scriptsdir = datadir.replace("data", "scripts")
target = cp.get("DEFAULT", "target")
yumrepodir = os.path.join("repos", commit.getshardedcommitdir())
Expand All @@ -344,14 +358,14 @@ def build(cp, package_info, commit, env_vars, dev_mode):
"--work-tree=%s" % repo_dir, "reset", "--hard", commit_hash)
try:
sh.docker("kill", "builder")
except:
except Exception:
pass

# looks like we need to give the container time to die
time.sleep(20)
try:
sh.docker("rm", "builder")
except:
except Exception:
pass

docker_run_cmd = []
Expand All @@ -372,7 +386,7 @@ def build(cp, package_info, commit, env_vars, dev_mode):
str(os.getgid())])
try:
sh.docker("run", docker_run_cmd)
except:
except Exception:
logger.error('Build failed. See logs at: ./data/%s/' % yumrepodir)
raise Exception("Error while building packages")

Expand Down Expand Up @@ -409,13 +423,14 @@ def build(cp, package_info, commit, env_vars, dev_mode):
fp = open(os.path.join(yumrepodir_abs, "delorean.repo"), "w")
fp.write("[delorean]\nname=delorean-%s-%s\nbaseurl=%s/%s\nenabled=1\n"
"gpgcheck=0\npriority=1" % (project_name, commit_hash,
cp.get("DEFAULT", "baseurl"), yumrepodir))
cp.get("DEFAULT", "baseurl"),
yumrepodir))
fp.close()

current_repo_dir = os.path.join(datadir, "repos", "current")
os.symlink(os.path.relpath(yumrepodir_abs, os.path.join(datadir, "repos")),
current_repo_dir+"_")
os.rename(current_repo_dir+"_", current_repo_dir)
current_repo_dir + "_")
os.rename(current_repo_dir + "_", current_repo_dir)
return built_rpms, notes


Expand Down Expand Up @@ -460,7 +475,8 @@ def genreports(cp, package_info):
last_success_dt = last_success.dt_commit

commits = session.query(Commit).filter(Commit.project_name == name).\
filter(Commit.status == "FAILED", Commit.dt_commit > last_success_dt)
filter(Commit.status == "FAILED",
Commit.dt_commit > last_success_dt)
if commits.count() == 0:
continue

Expand Down
2 changes: 1 addition & 1 deletion delorean/tests/__init__.py
Expand Up @@ -10,4 +10,4 @@
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# under the License.
2 changes: 1 addition & 1 deletion delorean/tests/base.py
Expand Up @@ -50,4 +50,4 @@ def setUp(self):
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

self.log_fixture = self.useFixture(fixtures.FakeLogger())
self.log_fixture = self.useFixture(fixtures.FakeLogger())
2 changes: 1 addition & 1 deletion delorean/tests/test_plattersplatter.py
Expand Up @@ -25,4 +25,4 @@
class TestPlattersplatter(base.TestCase):

def test_something(self):
pass
pass
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -19,4 +19,4 @@

setuptools.setup(
setup_requires=['pbr'],
pbr=True)
pbr=True)
14 changes: 10 additions & 4 deletions tox.ini
@@ -1,6 +1,6 @@
[tox]
minversion = 1.6
envlist = py26,py27,py33,pypy,pep8
envlist = py27,py34,pep8
skipsdist = True

[testenv]
Expand All @@ -10,7 +10,9 @@ setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}'
commands =
coverage run --branch --include 'delorean*' -m unittest discover delorean.tests
coverage report -m

[testenv:pep8]
commands = flake8
Expand All @@ -24,8 +26,12 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
[flake8]
# H803 skipped on purpose per list discussion.
# E123, E125 skipped as they are invalid PEP-8.
# F821 skipped for now, as flake8 is not recognizing session global.
# It would might be better to pass a session around rather than the global.
# rdoinfo skipped as we are changing to rdopkg
# https://review.gerrithub.io/#/c/214249/

show-source = True
ignore = E123,E125,H803
ignore = E123,E125,H803,F821
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,rdoinfo.py

0 comments on commit 764e4f8

Please sign in to comment.