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

Remove ports config, add no-start option, convert boolean-string-args to flags #69

Merged
merged 4 commits into from
Feb 9, 2016
Merged
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
4 changes: 2 additions & 2 deletions omego/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class EnvDefault(argparse.Action):
argparse Action which can be used to also read values
from the current environment. Additionally, it will
replace any values in string replacement syntax that
have already been set in the environment (e.g. %%(prefix)4064
becomes 14064 if --prefix=1 was set)
have already been set in the environment (e.g. %%(xxx)234
becomes 1234 if --xxx=1 was set)

Usage:

Expand Down
46 changes: 22 additions & 24 deletions omego/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def stop(self):
except Exception as e:
log.error('Error whilst stopping server: %s', e)

if self.web():
if not self.args.no_web:
try:
log.info("Stopping web")
self.stopweb()
Expand Down Expand Up @@ -156,14 +156,6 @@ def samecontents(a, b):
ftype, f))
self.run(['load', fpath])

self.configure_ports()

def configure_ports(self):
# Set registry, TCP and SSL ports
self.run(["admin", "ports", "--skipcheck", "--registry",
self.args.registry, "--tcp",
self.args.tcp, "--ssl", self.args.ssl])

def archive_logs(self):
if self.args.archivelogs:
logdir = os.path.join(self.args.sym, 'var', 'log')
Expand All @@ -185,14 +177,14 @@ def directories(self):
target = None
targetzip = None

if "false" == self.args.skipdelete.lower() and target:
if self.args.delete_old and target:
try:
log.info("Deleting %s", target)
shutil.rmtree(target)
except OSError as e:
log.error("Failed to delete %s: %s", target, e)

if "false" == self.args.skipdeletezip.lower() and targetzip:
if not self.args.keep_old_zip and targetzip:
try:
log.info("Deleting %s", targetzip)
os.unlink(targetzip)
Expand All @@ -213,8 +205,12 @@ def upgrade_db(self):
DbAdmin(self.dir, 'upgrade', self.args, self.external)

def start(self):
if self.args.no_start:
log.debug('Not starting OMERO')
return

self.run("admin start")
if self.web():
if not self.args.no_web:
log.info("Starting web")
self.startweb()

Expand All @@ -238,9 +234,6 @@ def bin(self, command):
command = command.split()
self.external.omero_bin(command)

def web(self):
return "false" == self.args.skipweb.lower()


class UnixInstall(Install):

Expand Down Expand Up @@ -371,17 +364,22 @@ def __init__(self, sub_parsers):

Add = EnvDefault.add

# Ports
Add(self.parser, "prefix", "")
Add(self.parser, "registry", "%(prefix)s4061")
Add(self.parser, "tcp", "%(prefix)s4063")
Add(self.parser, "ssl", "%(prefix)s4064")

Add(self.parser, "sym", "OMERO-CURRENT")

Add(self.parser, "skipweb", "false")
Add(self.parser, "skipdelete", "true")
Add(self.parser, "skipdeletezip", "false")
self.parser.add_argument(
"--no-start", action="store_true",
help="Don't start any omero components")

self.parser.add_argument(
"--no-web", action="store_true",
help="Ignore OMERO.web, don't start or stop")

self.parser.add_argument(
"--delete-old", action="store_true",
help="Delete the old server directory")
self.parser.add_argument(
"--keep-old-zip", action="store_true",
help="Don't delete the old server zip")

# Record the values of these environment variables in a file
envvars = "ICE_HOME PATH DYLD_LIBRARY_PATH LD_LIBRARY_PATH PYTHONPATH"
Expand Down
66 changes: 23 additions & 43 deletions test/unit/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ class TestUpgrade(object):
class Args(object):
def __init__(self, args):
self.sym = 'sym'
self.registry = '12'
self.tcp = '34'
self.ssl = '56'
self.skipweb = 'false'
self.skipdelete = 'false'
self.skipdeletezip = 'false'
self.no_start = False
self.no_web = False
self.delete_old = False
self.keep_old_zip = False
self.verbose = False
for k, v in args.iteritems():
setattr(self, k, v)
Expand Down Expand Up @@ -103,38 +101,25 @@ def test_get_server_dir(self, server):

self.mox.VerifyAll()

@pytest.mark.parametrize('skipweb', [True, False])
def test_stop(self, skipweb):
@pytest.mark.parametrize('noweb', [True, False])
def test_stop(self, noweb):
ext = self.mox.CreateMock(External)
ext.omero_bin(['admin', 'status', '--nodeonly'])
ext.omero_bin(['admin', 'stop'])
if not skipweb:
if not noweb:
ext.omero_bin(['web', 'stop'])
self.mox.ReplayAll()

args = self.Args({'skipweb': str(skipweb)})
args = self.Args({'no_web': noweb})
upgrade = self.PartialMockUnixInstall(args, ext)
print '*** %s' % upgrade.args.__dict__
print upgrade.web()
upgrade.stop()
self.mox.VerifyAll()

@pytest.mark.skipif(True, reason='Untestable: dynamic module import')
def test_configure(self):
pass

def test_configure_ports(self):
ext = self.mox.CreateMock(External)
args = self.Args({})
ext.omero_cli(
['admin', 'ports', '--skipcheck', '--registry', args.registry,
'--tcp', args.tcp, '--ssl', args.ssl])
self.mox.ReplayAll()

upgrade = self.PartialMockUnixInstall(args, ext)
upgrade.configure_ports()
self.mox.VerifyAll()

@pytest.mark.parametrize('archivelogs', [None, 'archivelogs.zip'])
def test_archive_logs(self, archivelogs):
self.mox.StubOutWithMock(fileutils, 'zip')
Expand All @@ -149,15 +134,17 @@ def test_archive_logs(self, archivelogs):
upgrade.archive_logs()
self.mox.VerifyAll()

@pytest.mark.parametrize('skipweb', [True, False])
def test_start(self, skipweb):
@pytest.mark.parametrize('nostart', [True, False])
@pytest.mark.parametrize('noweb', [True, False])
def test_start(self, nostart, noweb):
ext = self.mox.CreateMock(External)
ext.omero_cli(['admin', 'start'])
if not skipweb:
ext.omero_cli(['web', 'start'])
if not nostart:
ext.omero_cli(['admin', 'start'])
if not noweb:
ext.omero_cli(['web', 'start'])
self.mox.ReplayAll()

args = self.Args({'skipweb': str(skipweb)})
args = self.Args({'no_web': noweb, 'no_start': nostart})
upgrade = self.PartialMockUnixInstall(args, ext)
upgrade.start()
self.mox.VerifyAll()
Expand All @@ -184,18 +171,11 @@ def test_bin(self):
upgrade.bin(['a', 'b'])
self.mox.VerifyAll()

@pytest.mark.parametrize('skipweb', [True, False])
def test_web(self, skipweb):
args = self.Args({'skipweb': str(skipweb)})
upgrade = self.PartialMockUnixInstall(args, None)
assert upgrade.web() != skipweb
self.mox.VerifyAll()

@pytest.mark.parametrize('skipdelete', [True, False])
@pytest.mark.parametrize('skipdeletezip', [True, False])
def test_directories(self, skipdelete, skipdeletezip):
args = self.Args({'skipdelete': str(skipdelete),
'skipdeletezip': str(skipdeletezip)})
@pytest.mark.parametrize('deleteold', [True, False])
@pytest.mark.parametrize('keepoldzip', [True, False])
def test_directories(self, deleteold, keepoldzip):
args = self.Args({'delete_old': deleteold,
'keep_old_zip': keepoldzip})
upgrade = self.PartialMockUnixInstall(args, None)
upgrade.dir = 'new'

Expand All @@ -207,9 +187,9 @@ def test_directories(self, skipdelete, skipdeletezip):

os.path.samefile('new', 'sym').AndReturn(False)
os.readlink('sym').AndReturn('old/')
if not skipdelete:
if deleteold:
shutil.rmtree('old')
if not skipdeletezip:
if not keepoldzip:
os.unlink('old.zip')
os.unlink('sym')
upgrade.symlink('new', 'sym')
Expand Down