Skip to content

Add profiles functionality #3

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions testrepository/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"""

from inspect import getdoc
from optparse import OptionParser
import optparse
import os
import sys

Expand Down Expand Up @@ -139,6 +139,7 @@ def execute(self):
"""
if not self.ui.set_command(self):
return 1
self.repository_factory._profile = self.ui.options.profile
try:
result = self.run()
except Exception:
Expand Down Expand Up @@ -201,7 +202,7 @@ def get_command_parser(cmd):

:return: An OptionParser instance.
"""
parser = OptionParser()
parser = optparse.OptionParser()
for option in cmd.options:
parser.add_option(option)
usage = _u('%%prog %(cmd)s [options] %(args)s\n\n%(help)s') % {
Expand Down
3 changes: 3 additions & 0 deletions testrepository/repository/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
class AbstractRepositoryFactory(object):
"""Interface for making or opening repositories."""

def __init__(self, profile='DEFAULT'):
self._profile = profile

def initialise(self, url):
"""Create a repository at URL.

Expand Down
7 changes: 4 additions & 3 deletions testrepository/repository/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialise(klass, url):
stream.write('1\n')
finally:
stream.close()
result = Repository(base)
result = Repository(base, self._profile)
result._write_next_stream(0)
return result

Expand All @@ -71,7 +71,7 @@ def open(self, url):
raise
if '1\n' != stream.read():
raise ValueError(url)
return Repository(base)
return Repository(base, self._profile)


class Repository(AbstractRepository):
Expand All @@ -85,12 +85,13 @@ class Repository(AbstractRepository):
likely to have an automatic upgrade process.
"""

def __init__(self, base):
def __init__(self, base, profile):
"""Create a file-based repository object for the repo at 'base'.

:param base: The path to the repository.
"""
self.base = base
self._profile = profile

def _allocate(self):
# XXX: lock the file. K?!
Expand Down
44 changes: 14 additions & 30 deletions testrepository/testcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def __init__(self, test_ids, cmd_template, listopt, idoption, ui,
self.parallel = parallel
self._listpath = listpath
self._parser = parser
self._option = lambda x: self._parser.get(repository._profile, x)
self.test_filters = test_filters
self._group_callback = group_callback
self._instance_source = instance_source
Expand All @@ -200,12 +201,12 @@ def setUp(self):
list_variables = {'LISTOPT': self.listopt}
cmd = self.template
try:
default_idstr = self._parser.get('DEFAULT', 'test_id_list_default')
default_idstr = self._option('test_id_list_default')
list_variables['IDLIST'] = default_idstr
# In theory we should also support casting this into IDFILE etc -
# needs this horrible class refactored.
except ConfigParser.NoOptionError as e:
if e.message != "No option 'test_id_list_default' in section: 'DEFAULT'":
if "No option 'test_id_list_default'" not in e.message:
raise
default_idstr = None
def list_subst(match):
Expand Down Expand Up @@ -327,8 +328,7 @@ def _per_instance_command(self, cmd):
instance = self._instance_source.obtain_instance(self.concurrency)
if instance is not None:
try:
instance_prefix = self._parser.get(
'DEFAULT', 'instance_execute')
instance_prefix = self._option('instance_execute')
variables = {
'INSTANCE_ID': instance.decode('utf8'),
'COMMAND': cmd,
Expand Down Expand Up @@ -447,8 +447,7 @@ def consume_queue(groups):
def callout_concurrency(self):
"""Callout for user defined concurrency."""
try:
concurrency_cmd = self._parser.get(
'DEFAULT', 'test_run_concurrency')
concurrency_cmd = self._option('test_run_concurrency')
except ConfigParser.NoOptionError:
return None
run_proc = self.ui.subprocess_Popen(concurrency_cmd, shell=True,
Expand Down Expand Up @@ -495,6 +494,7 @@ def __init__(self, ui, repository):
super(TestCommand, self).__init__()
self.ui = ui
self.repository = repository
self._option = lambda x: self.get_parser().get(repository._profile, x)
self._instances = None
self._allocated_instances = None

Expand All @@ -511,7 +511,7 @@ def _dispose_instances(self):
self._instances = None
self._allocated_instances = None
try:
dispose_cmd = self.get_parser().get('DEFAULT', 'instance_dispose')
dispose_cmd = self._option('instance_dispose')
except (ValueError, ConfigParser.NoOptionError):
return
variable_regex = '\$INSTANCE_IDS'
Expand Down Expand Up @@ -542,34 +542,19 @@ def get_run_command(self, test_ids=None, testargs=(), test_filters=None):
if self._instances is None:
raise TypeError('TestCommand not setUp')
parser = self.get_parser()
try:
command = parser.get('DEFAULT', 'test_command')
except ConfigParser.NoOptionError as e:
if e.message != "No option 'test_command' in section: 'DEFAULT'":
raise
raise ValueError("No test_command option present in .testr.conf")
command = self._option('test_command')
elements = [command] + list(testargs)
cmd = ' '.join(elements)
idoption = ''
if '$IDOPTION' in command:
# IDOPTION is used, we must have it configured.
try:
idoption = parser.get('DEFAULT', 'test_id_option')
except ConfigParser.NoOptionError as e:
if e.message != "No option 'test_id_option' in section: 'DEFAULT'":
raise
raise ValueError("No test_id_option option present in .testr.conf")
idoption = self._option('test_id_option')
listopt = ''
if '$LISTOPT' in command:
# LISTOPT is used, test_list_option must be configured.
try:
listopt = parser.get('DEFAULT', 'test_list_option')
except ConfigParser.NoOptionError as e:
if e.message != "No option 'test_list_option' in section: 'DEFAULT'":
raise
raise ValueError("No test_list_option option present in .testr.conf")
listopt = self._option('test_list_option')
try:
group_regex = parser.get('DEFAULT', 'group_regex')
group_regex = self._option('group_regex')
except ConfigParser.NoOptionError:
group_regex = None
if group_regex:
Expand All @@ -593,11 +578,10 @@ def group_callback(test_id, regex=re.compile(group_regex)):
return result

def get_filter_tags(self):
parser = self.get_parser()
try:
tags = parser.get('DEFAULT', 'filter_tags')
tags = self._option('filter_tags')
except ConfigParser.NoOptionError as e:
if e.message != "No option 'filter_tags' in section: 'DEFAULT'":
if "No option 'filter_tags'" not in e.message:
raise
return set()
return set([tag.strip() for tag in tags.split()])
Expand All @@ -610,7 +594,7 @@ def obtain_instance(self, concurrency):
"""
while len(self._instances) < concurrency:
try:
cmd = self.get_parser().get('DEFAULT', 'instance_provision')
cmd = self._option('instance_provision')
except ConfigParser.NoOptionError:
# Instance allocation not configured
return None
Expand Down
2 changes: 2 additions & 0 deletions testrepository/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ def _check_cmd(self):
parser.add_option("-q", "--quiet", action="store_true", default=False,
help="Turn off output other than the primary output for a command "
"and any errors.")
parser.add_option("-p", "--profile", action="store",
type='str', default='DEFAULT', help="Profile to use")
# yank out --, as optparse makes it silly hard to just preserve it.
try:
where_dashdash = self._argv.index('--')
Expand Down