Ejemplo n.º 1
0
    def setUp(self):
        # Non-temp directories
        build_dir = path() / "build"
        top_dir = path() / ".." / ".." / ".."
        etc_dir = top_dir / "etc"

        # Necessary fiels
        prefs_file = build_dir / "prefs.class"
        internal_cfg = etc_dir / "internal.cfg"
        master_cfg = etc_dir / "master.cfg"

        # Temp directories
        tmp_dir = create_path(folder=True)
        tmp_etc_dir = tmp_dir / "etc"
        tmp_grid_dir = tmp_etc_dir / "grid"
        tmp_lib_dir = tmp_dir / "lib"
        tmp_var_dir = tmp_dir / "var"

        # Setup tmp dir
        [x.makedirs() for x in (tmp_grid_dir, tmp_lib_dir, tmp_var_dir)]
        prefs_file.copy(tmp_lib_dir)
        master_cfg.copy(tmp_etc_dir)
        internal_cfg.copy(tmp_etc_dir)

        # Other setup
        self.cli = MockCLI()
        self.cli.dir = tmp_dir
        grid_dir = self.cli.dir / "etc" / "grid"
        self.cli.register("a", AdminControl, "TEST")
        self.cli.register("config", PrefsControl, "TEST")
Ejemplo n.º 2
0
 def setUp(self):
     self.cli = MockCLI()
     self.cli.register("db", DatabaseControl, "TEST")
     db = self.cli.controls["db"]
     data = db.loaddefaults()
     self.data = {}
     for x in ("version", "patch"):
         self.data[x] = data.properties.getProperty("omero.db." + x)
     self.file = create_path()
Ejemplo n.º 3
0
    def setUp(self):
        # Non-temp directories
        build_dir = path() / "build"
        top_dir = path() / ".." / ".." / ".."
        etc_dir = top_dir / "etc"

        # Necessary fiels
        prefs_file = build_dir / "prefs.class"
        internal_cfg = etc_dir / "internal.cfg"
        master_cfg = etc_dir / "master.cfg"

        # Temp directories
        tmp_dir = create_path(folder=True)
        tmp_etc_dir = tmp_dir / "etc"
        tmp_grid_dir = tmp_etc_dir / "grid"
        tmp_lib_dir = tmp_dir / "lib"
        tmp_var_dir = tmp_dir / "var"

        # Setup tmp dir
        [x.makedirs() for x in (tmp_grid_dir, tmp_lib_dir, tmp_var_dir)]
        prefs_file.copy(tmp_lib_dir)
        master_cfg.copy(tmp_etc_dir)
        internal_cfg.copy(tmp_etc_dir)

        # Other setup
        self.cli = MockCLI()
        self.cli.dir = tmp_dir
        grid_dir = self.cli.dir / "etc" / "grid"
        self.cli.register("a", AdminControl, "TEST")
        self.cli.register("config", PrefsControl, "TEST")
Ejemplo n.º 4
0
 def testStart(self):
     self.cli = MockCLI()
     c = NodeControl(omeroDir, self.cli)
     self.assert_(c._likes(None))
     self.assert_(c._likes("start"))
     c("start")
     self.assert_(self.cli.called == 1)
     c("start")
     self.assert_(self.cli.called == 2)
Ejemplo n.º 5
0
 def setUp(self):
     self.cli = MockCLI()
     self.cli.register("db", DatabaseControl, "TEST")
     db = self.cli.controls["db"]
     data = db.loaddefaults()
     self.data = {}
     for x in ("version", "patch"):
         self.data[x] = data.properties.getProperty("omero.db."+x)
     self.file = create_path()
Ejemplo n.º 6
0
    def testKill(self):
        self.cli = MockCLI()

        p = subprocess.Popen(["sleep", "100"])

        c = NodeControl(omeroDir, self.cli)
        f = file(c._pid(), "w")
        f.write(str(p.pid))
        f.close()
        c("kill")
        c.kill()
Ejemplo n.º 7
0
    def setUp(self):
        self.cli = MockCLI()
        self.cli.register("db", DatabaseControl, "TEST")

        dir = path(
            __file__
        ) / ".." / ".." / ".." / ".." / ".." / ".." / "dist"  # FIXME: should not be hard-coded
        dir = dir.abspath()
        cfg = dir / "etc" / "omero.properties"
        cfg = cfg.abspath()
        self.cli.dir = dir

        self.data = {}
        for line in cfg.text().split("\n"):
            line = line.strip()
            for x in ("version", "patch"):
                key = "omero.db." + x
                if line.startswith(key):
                    self.data[x] = line[len(key) + 1:]

        self.file = create_path()
Ejemplo n.º 8
0
    def setUp(self):
        self.cli = MockCLI()
        self.cli.register("db", DatabaseControl, "TEST")

        dir = path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." / "dist"  # FIXME: should not be hard-coded
        dir = dir.abspath()
        cfg = dir / "etc" / "omero.properties"
        cfg = cfg.abspath()
        self.cli.dir = dir

        self.data = {}
        for line in cfg.text().split("\n"):
            line = line.strip()
            for x in ("version", "patch"):
                key = "omero.db." + x
                if line.startswith(key):
                    self.data[x] = line[len(key)+1:]

        self.file = create_path()
Ejemplo n.º 9
0
class TestDatabase(unittest.TestCase):

    def setUp(self):
        self.cli = MockCLI()
        self.cli.register("db", DatabaseControl, "TEST")

        dir = path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." / "dist"  # FIXME: should not be hard-coded
        dir = dir.abspath()
        cfg = dir / "etc" / "omero.properties"
        cfg = cfg.abspath()
        self.cli.dir = dir

        self.data = {}
        for line in cfg.text().split("\n"):
            line = line.strip()
            for x in ("version", "patch"):
                key = "omero.db." + x
                if line.startswith(key):
                    self.data[x] = line[len(key)+1:]

        self.file = create_path()

    def tearDown(self):
        self.file.remove()

    def script(self, string, strict=True):
        string = string % self.data
        self.cli.invoke("db script -f %s %s" % (self.file, string), strict=strict)

    def password(self, string, strict=True):
        self.cli.invoke("db password " + string % self.data, strict=strict)

    def testBadVersionDies(self):
        self.expectPassword("pw")
        self.expectConfirmation("pw")
        self.assertRaises(NonZeroReturnCode, self.script, "NONE NONE pw")

    def testPasswordIsAskedForAgainIfDiffer(self):
        self.expectPassword("ome")
        self.expectConfirmation("bad")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("'' ''")

    def testPasswordIsAskedForAgainIfEmpty(self):
        self.expectPassword("")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testPassword(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.password("")

    def testAutomatedPassword(self):
        self.password("ome")

    def testScript(self):
        self.expectVersion(self.data["version"])
        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("")

    def testAutomatedScript1(self):

        # This should not be asked for, but ignoring for the moment
        self.expectVersion(self.data["version"])

        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s")

    def testAutomatedScript2(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testAutomatedScript3(self):
        self.script("%(version)s %(patch)s ome")

    def expectPassword(self, pw, user="******"):
        self.cli.expect("Please enter password for OMERO %s user: "******"root"):
        self.cli.expect("Please re-enter password for OMERO %s user: "******"Please enter omero.db.version [%s]: " % \
                self.data["version"], version)

    def expectPatch(self, patch):
        self.cli.expect("Please enter omero.db.patch [%s]: " % \
                self.data["patch"], patch)
Ejemplo n.º 10
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        self.cli = MockCLI()
        self.cli.register("db", DatabaseControl, "TEST")

        dir = path(
            __file__
        ) / ".." / ".." / ".." / ".." / ".." / ".." / "dist"  # FIXME: should not be hard-coded
        dir = dir.abspath()
        cfg = dir / "etc" / "omero.properties"
        cfg = cfg.abspath()
        self.cli.dir = dir

        self.data = {}
        for line in cfg.text().split("\n"):
            line = line.strip()
            for x in ("version", "patch"):
                key = "omero.db." + x
                if line.startswith(key):
                    self.data[x] = line[len(key) + 1:]

        self.file = create_path()

    def tearDown(self):
        self.file.remove()

    def script(self, string, strict=True):
        string = string % self.data
        self.cli.invoke("db script -f %s %s" % (self.file, string),
                        strict=strict)

    def password(self, string, strict=True):
        self.cli.invoke("db password " + string % self.data, strict=strict)

    def testBadVersionDies(self):
        self.expectPassword("pw")
        self.expectConfirmation("pw")
        self.assertRaises(NonZeroReturnCode, self.script, "NONE NONE pw")

    def testPasswordIsAskedForAgainIfDiffer(self):
        self.expectPassword("ome")
        self.expectConfirmation("bad")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("'' ''")

    def testPasswordIsAskedForAgainIfEmpty(self):
        self.expectPassword("")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testPassword(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.password("")

    def testAutomatedPassword(self):
        self.password("ome")

    def testScript(self):
        self.expectVersion(self.data["version"])
        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("")

    def testAutomatedScript1(self):

        # This should not be asked for, but ignoring for the moment
        self.expectVersion(self.data["version"])

        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s")

    def testAutomatedScript2(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testAutomatedScript3(self):
        self.script("%(version)s %(patch)s ome")

    def expectPassword(self, pw, user="******"):
        self.cli.expect("Please enter password for OMERO %s user: "******"root"):
        self.cli.expect("Please re-enter password for OMERO %s user: "******"Please enter omero.db.version [%s]: " % \
                self.data["version"], version)

    def expectPatch(self, patch):
        self.cli.expect("Please enter omero.db.patch [%s]: " % \
                self.data["patch"], patch)
Ejemplo n.º 11
0
class TestAdmin(unittest.TestCase):

    def setUp(self):
        # Non-temp directories
        build_dir = path() / "build"
        top_dir = path() / ".." / ".." / ".."
        etc_dir = top_dir / "etc"

        # Necessary fiels
        prefs_file = build_dir / "prefs.class"
        internal_cfg = etc_dir / "internal.cfg"
        master_cfg = etc_dir / "master.cfg"

        # Temp directories
        tmp_dir = create_path(folder=True)
        tmp_etc_dir = tmp_dir / "etc"
        tmp_grid_dir = tmp_etc_dir / "grid"
        tmp_lib_dir = tmp_dir / "lib"

        # Setup tmp dir
        [x.makedirs() for x in (tmp_grid_dir, tmp_lib_dir)]
        prefs_file.copy(tmp_lib_dir)
        master_cfg.copy(tmp_etc_dir)
        internal_cfg.copy(tmp_etc_dir)

        # Other setup
        self.cli = MockCLI()
        self.cli.dir = tmp_dir
        grid_dir = self.cli.dir / "etc" / "grid"
        self.cli.register("a", AdminControl, "TEST")
        self.cli.register("config", PrefsControl, "TEST")

    def tearDown(self):
        self.cli.tearDown()

    def invoke(self, string, fails=False):
        try:
            self.cli.invoke(string, strict=True)
            if fails: self.fail("Failed to fail")
        except:
            if not fails: raise

    def testMain(self):
        try:
            self.invoke("")
        except NonZeroReturnCode:
            # Command-loop not implemented
            pass

    #
    # Async first because simpler
    #

    def testStartAsync(self):
        self.cli.addCall(0)
        self.cli.checksIceVersion()
        self.cli.checksStatus(1) # I.e. not running

        self.invoke("a startasync")
        self.cli.assertCalled()
        self.cli.assertStderr(['No descriptor given. Using etc/grid/default.xml'])

    def testStopAsyncRunning(self):
        self.cli.checksStatus(0) # I.e. running
        self.cli.addCall(0)
        self.invoke("a stopasync")
        self.cli.assertStderr([])
        self.cli.assertStdout([])

    def testStopAsyncNotRunning(self):
        self.cli.checksStatus(1) # I.e. not running
        self.invoke("a stopasync", fails=True)
        self.cli.assertStderr(["Server not running"])
        self.cli.assertStdout([])

    def testStop(self):
        self.cli.checksStatus(0) # I.e. running
        self.cli.addCall(0)
        self.cli.checksStatus(1) # I.e. not running
        self.invoke("a stop")
        self.cli.assertStderr([])
        self.cli.assertStdout(['Waiting on shutdown. Use CTRL-C to exit'])

    #
    # STATUS
    #

    def testStatusNodeFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(1)

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusSMFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""
        def sm(*args):
            raise exceptions.Exception("unknown")
        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusPasses(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""
        def sm(*args):
            class A(object):
                def create(self, *args): raise omero.WrappedCreateSessionException()
            return A()
        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.invoke("a status")
        self.assertEquals(0, self.cli.rv)

    #
    # Bugs
    #

    """
    Issues with error handling in certain situations
    especially with changing networks interfaces.
    """

    def test7325NoWaitForShutdown(self):
        """
        First issue in the error reported in Will's description
        (ignoring the comments) is that if the master could
        not be reached, there should be no waiting on shutdown.
        """

        # Although later status says the servers not running
        # the node ping much return a 0 because otherwise
        # stopasync returns immediately
        self.cli.checksStatus(0)     # node ping

        # Then since "Was the server already stopped?" was
        # printed, the call to shutdown master must return 1
        self.cli.addCall(1)

        self.invoke("a restart")
        self.cli.assertStderr([])
        self.cli.assertStdout([])
Ejemplo n.º 12
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        self.cli = MockCLI()
        self.cli.register("db", DatabaseControl, "TEST")
        db = self.cli.controls["db"]
        data = db.loaddefaults()
        self.data = {}
        for x in ("version", "patch"):
            self.data[x] = data.properties.getProperty("omero.db." + x)
        self.file = create_path()

    def tearDown(self):
        self.file.remove()

    def script(self, string, strict=True):
        string = string % self.data
        self.cli.invoke("db script -f %s %s" % (self.file, string),
                        strict=strict)

    def password(self, string, strict=True):
        self.cli.invoke("db password " + string % self.data, strict=strict)

    def testBadVersionDies(self):
        self.assertRaises(NonZeroReturnCode, self.script, "NONE NONE pw")

    def testPasswordIsAskedForAgainIfDiffer(self):
        self.expectPassword("ome")
        self.expectConfirmation("bad")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("'' ''")

    def testPasswordIsAskedForAgainIfEmpty(self):
        self.expectPassword("")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testPassword(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.password("")

    def testAutomatedPassword(self):
        self.password("ome")

    def testScript(self):
        self.expectVersion(self.data["version"])
        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("")

    def testAutomatedScript1(self):

        # This should not be asked for, but ignoring for the moment
        self.expectVersion(self.data["version"])

        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s")

    def testAutomatedScript2(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testAutomatedScript3(self):
        self.script("%(version)s %(patch)s ome")

    def expectPassword(self, pw, user="******"):
        self.cli.expect("Please enter password for OMERO %s user: "******"root"):
        self.cli.expect("Please re-enter password for OMERO %s user: "******"Please enter omero.db.version [%s]: " % \
                self.data["version"], version)

    def expectPatch(self, patch):
        self.cli.expect("Please enter omero.db.patch [%s]: " % \
                self.data["patch"], patch)
Ejemplo n.º 13
0
class TestAdmin(unittest.TestCase):
    def setUp(self):
        # Non-temp directories
        build_dir = path() / "build"
        top_dir = path() / ".." / ".." / ".."
        etc_dir = top_dir / "etc"

        # Necessary fiels
        prefs_file = build_dir / "prefs.class"
        internal_cfg = etc_dir / "internal.cfg"
        master_cfg = etc_dir / "master.cfg"

        # Temp directories
        tmp_dir = create_path(folder=True)
        tmp_etc_dir = tmp_dir / "etc"
        tmp_grid_dir = tmp_etc_dir / "grid"
        tmp_lib_dir = tmp_dir / "lib"
        tmp_var_dir = tmp_dir / "var"

        # Setup tmp dir
        [x.makedirs() for x in (tmp_grid_dir, tmp_lib_dir, tmp_var_dir)]
        prefs_file.copy(tmp_lib_dir)
        master_cfg.copy(tmp_etc_dir)
        internal_cfg.copy(tmp_etc_dir)

        # Other setup
        self.cli = MockCLI()
        self.cli.dir = tmp_dir
        grid_dir = self.cli.dir / "etc" / "grid"
        self.cli.register("a", AdminControl, "TEST")
        self.cli.register("config", PrefsControl, "TEST")

    def tearDown(self):
        self.cli.tearDown()

    def invoke(self, string, fails=False):
        try:
            self.cli.invoke(string, strict=True)
            if fails: self.fail("Failed to fail")
        except:
            if not fails: raise

    def testMain(self):
        try:
            self.invoke("")
        except NonZeroReturnCode:
            # Command-loop not implemented
            pass

    #
    # Async first because simpler
    #

    def XtestStartAsync(self):
        # DISABLED: https://trac.openmicroscopy.org.uk/ome/ticket/10584
        self.cli.addCall(0)
        self.cli.checksIceVersion()
        self.cli.checksStatus(1)  # I.e. not running

        self.invoke("a startasync")
        self.cli.assertCalled()
        self.cli.assertStderr(
            ['No descriptor given. Using etc/grid/default.xml'])

    def testStopAsyncRunning(self):
        self.cli.checksStatus(0)  # I.e. running
        self.cli.addCall(0)
        self.invoke("a stopasync")
        self.cli.assertStderr([])
        self.cli.assertStdout([])

    def testStopAsyncNotRunning(self):
        self.cli.checksStatus(1)  # I.e. not running
        self.invoke("a stopasync", fails=True)
        self.cli.assertStderr(["Server not running"])
        self.cli.assertStdout([])

    def testStop(self):
        self.cli.checksStatus(0)  # I.e. running
        self.cli.addCall(0)
        self.cli.checksStatus(1)  # I.e. not running
        self.invoke("a stop")
        self.cli.assertStderr([])
        self.cli.assertStdout(['Waiting on shutdown. Use CTRL-C to exit'])

    #
    # STATUS
    #

    def testStatusNodeFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(1)

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusSMFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""

        def sm(*args):
            raise exceptions.Exception("unknown")

        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusPasses(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""

        def sm(*args):
            class A(object):
                def create(self, *args):
                    raise omero.WrappedCreateSessionException()

            return A()

        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.invoke("a status")
        self.assertEquals(0, self.cli.rv)
Ejemplo n.º 14
0
class TestDatabase(unittest.TestCase):

    def setUp(self):
        self.cli = MockCLI()
        self.cli.register("db", DatabaseControl, "TEST")
        db = self.cli.controls["db"]
        data = db.loaddefaults()
        self.data = {}
        for x in ("version", "patch"):
            self.data[x] = data.properties.getProperty("omero.db."+x)
        self.file = create_path()

    def tearDown(self):
        self.file.remove()

    def script(self, string, strict=True):
        string = string % self.data
        self.cli.invoke("db script -f %s %s" % (self.file, string), strict=strict)

    def password(self, string, strict=True):
        self.cli.invoke("db password " + string % self.data, strict=strict)

    def testBadVersionDies(self):
        self.assertRaises(NonZeroReturnCode, self.script, "NONE NONE pw")

    def testPasswordIsAskedForAgainIfDiffer(self):
        self.expectPassword("ome")
        self.expectConfirmation("bad")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("'' ''")

    def testPasswordIsAskedForAgainIfEmpty(self):
        self.expectPassword("")
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testPassword(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.password("")

    def testAutomatedPassword(self):
        self.password("ome")

    def testScript(self):
        self.expectVersion(self.data["version"])
        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("")

    def testAutomatedScript1(self):

        # This should not be asked for, but ignoring for the moment
        self.expectVersion(self.data["version"])

        self.expectPatch(self.data["patch"])
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s")

    def testAutomatedScript2(self):
        self.expectPassword("ome")
        self.expectConfirmation("ome")
        self.script("%(version)s %(patch)s")

    def testAutomatedScript3(self):
        self.script("%(version)s %(patch)s ome")

    def expectPassword(self, pw, user="******"):
        self.cli.expect("Please enter password for OMERO %s user: "******"root"):
        self.cli.expect("Please re-enter password for OMERO %s user: "******"Please enter omero.db.version [%s]: " % \
                self.data["version"], version)

    def expectPatch(self, patch):
        self.cli.expect("Please enter omero.db.patch [%s]: " % \
                self.data["patch"], patch)
Ejemplo n.º 15
0
 def testStop(self):
     self.cli = MockCLI()
     c = NodeControl(omeroDir, self.cli)
     c("stop")
     c.stop()
Ejemplo n.º 16
0
class TestAdmin(unittest.TestCase):

    def setUp(self):
        # Non-temp directories
        build_dir = path() / "build"
        top_dir = path() / ".." / ".." / ".."
        etc_dir = top_dir / "etc"

        # Necessary fiels
        prefs_file = build_dir / "prefs.class"
        internal_cfg = etc_dir / "internal.cfg"
        master_cfg = etc_dir / "master.cfg"

        # Temp directories
        tmp_dir = create_path(folder=True)
        tmp_etc_dir = tmp_dir / "etc"
        tmp_grid_dir = tmp_etc_dir / "grid"
        tmp_lib_dir = tmp_dir / "lib"
        tmp_var_dir = tmp_dir / "var"

        # Setup tmp dir
        [x.makedirs() for x in (tmp_grid_dir, tmp_lib_dir, tmp_var_dir)]
        prefs_file.copy(tmp_lib_dir)
        master_cfg.copy(tmp_etc_dir)
        internal_cfg.copy(tmp_etc_dir)

        # Other setup
        self.cli = MockCLI()
        self.cli.dir = tmp_dir
        grid_dir = self.cli.dir / "etc" / "grid"
        self.cli.register("a", AdminControl, "TEST")
        self.cli.register("config", PrefsControl, "TEST")

    def tearDown(self):
        self.cli.tearDown()

    def invoke(self, string, fails=False):
        try:
            self.cli.invoke(string, strict=True)
            if fails: self.fail("Failed to fail")
        except:
            if not fails: raise

    def testMain(self):
        try:
            self.invoke("")
        except NonZeroReturnCode:
            # Command-loop not implemented
            pass

    #
    # Async first because simpler
    #

    def XtestStartAsync(self):
        # DISABLED: https://trac.openmicroscopy.org.uk/ome/ticket/10584
        self.cli.addCall(0)
        self.cli.checksIceVersion()
        self.cli.checksStatus(1) # I.e. not running

        self.invoke("a startasync")
        self.cli.assertCalled()
        self.cli.assertStderr(['No descriptor given. Using etc/grid/default.xml'])

    def testStopAsyncRunning(self):
        self.cli.checksStatus(0) # I.e. running
        self.cli.addCall(0)
        self.invoke("a stopasync")
        self.cli.assertStderr([])
        self.cli.assertStdout([])

    def testStopAsyncNotRunning(self):
        self.cli.checksStatus(1) # I.e. not running
        self.invoke("a stopasync", fails=True)
        self.cli.assertStderr(["Server not running"])
        self.cli.assertStdout([])

    def testStop(self):
        self.cli.checksStatus(0) # I.e. running
        self.cli.addCall(0)
        self.cli.checksStatus(1) # I.e. not running
        self.invoke("a stop")
        self.cli.assertStderr([])
        self.cli.assertStdout(['Waiting on shutdown. Use CTRL-C to exit'])

    #
    # STATUS
    #

    def testStatusNodeFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(1)

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusSMFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""
        def sm(*args):
            raise exceptions.Exception("unknown")
        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusPasses(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""
        def sm(*args):
            class A(object):
                def create(self, *args): raise omero.WrappedCreateSessionException()
            return A()
        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.invoke("a status")
        self.assertEquals(0, self.cli.rv)
Ejemplo n.º 17
0
class TestAdmin(unittest.TestCase):
    def setUp(self):
        # Non-temp directories
        build_dir = path() / "build"
        top_dir = path() / ".." / ".." / ".."
        etc_dir = top_dir / "etc"

        # Necessary fiels
        prefs_file = build_dir / "prefs.class"
        internal_cfg = etc_dir / "internal.cfg"
        master_cfg = etc_dir / "master.cfg"

        # Temp directories
        tmp_dir = create_path(folder=True)
        tmp_etc_dir = tmp_dir / "etc"
        tmp_grid_dir = tmp_etc_dir / "grid"
        tmp_lib_dir = tmp_dir / "lib"

        # Setup tmp dir
        [x.makedirs() for x in (tmp_grid_dir, tmp_lib_dir)]
        prefs_file.copy(tmp_lib_dir)
        master_cfg.copy(tmp_etc_dir)
        internal_cfg.copy(tmp_etc_dir)

        # Other setup
        self.cli = MockCLI()
        self.cli.dir = tmp_dir
        grid_dir = self.cli.dir / "etc" / "grid"
        self.cli.register("a", AdminControl, "TEST")
        self.cli.register("config", PrefsControl, "TEST")

    def tearDown(self):
        self.cli.tearDown()

    def invoke(self, string, fails=False):
        try:
            self.cli.invoke(string, strict=True)
            if fails:
                self.fail("Failed to fail")
        except:
            if not fails:
                raise

    def testMain(self):
        try:
            self.invoke("")
        except NonZeroReturnCode:
            # Command-loop not implemented
            pass

    #
    # Async first because simpler
    #

    def testStartAsync(self):
        self.cli.addCall(0)
        self.cli.checksIceVersion()
        self.cli.checksStatus(1)  # I.e. not running

        self.invoke("a startasync")
        self.cli.assertCalled()
        self.cli.assertStderr(["No descriptor given. Using etc/grid/default.xml"])

    def testStopAsyncRunning(self):
        self.cli.addCall(0)
        self.invoke("a stopasync")
        self.cli.assertCalled()
        self.cli.assertStderr([])
        self.cli.assertStdout([])

    def testStopAsyncNotRunning(self):
        self.cli.addCall(1)
        self.invoke("a stopasync", fails=True)
        self.cli.assertCalled()
        self.cli.assertStderr([])
        self.cli.assertStdout(["Was the server already stopped?"])

    def testStop(self):
        self.invoke("a stop")

    def testComplete(self):
        c = AdminControl()
        t = ""
        l = "admin deploy "
        b = len(l)
        l = c._complete(t, l + "lib", b, b + 3)
        self.assert_("omero" in l, str(l))
        l = c._complete(t, l + "lib/", b, b + 4)
        self.assert_("omero" in l, str(l))

    def testProperMethodsUseConfigXml(self):
        self.fail("NYI")

    #
    # STATUS
    #

    def testStatusNodeFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(1)

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusSMFails(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""

        def sm(*args):
            raise exceptions.Exception("unknown")

        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.assertRaises(NonZeroReturnCode, self.invoke, "a status")

    def testStatusPasses(self):

        # Setup the call to bin/omero admin ice node
        popen = self.cli.createPopen()
        popen.wait().AndReturn(0)

        # Setup the call to session manager
        control = self.cli.controls["a"]
        control._intcfg = lambda: ""

        def sm(*args):
            class A(object):
                def create(self, *args):
                    raise omero.WrappedCreateSessionException()

            return A()

        control.session_manager = sm

        self.cli.mox.ReplayAll()
        self.invoke("a status")
        self.assertEquals(0, self.cli.rv)