class TestAdmin(object): @pytest.fixture(autouse=True) def setup_method(self, tmpadmindir): # Other setup self.cli = MockCLI() self.cli.dir = tmpadmindir self.cli.register("admin", AdminControl, "TEST") self.cli.register("config", PrefsControl, "TEST") def teardown_method(self, method): self.cli.teardown_method(method) def invoke(self, string, fails=False): try: self.cli.invoke(string, strict=True) if fails: assert False, "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/ome/ticket/10584 self.cli.addCall(0) self.cli.checksIceVersion() self.cli.checksStatus(1) # I.e. not running self.invoke("admin startasync") self.cli.assertCalled() self.cli.assertStderr( ['No descriptor given. Using etc/grid/default.xml']) def testStopAsyncNoConfig(self): self.invoke("admin stopasync", fails=True) self.cli.assertStderr([MISSING_CONFIGURATION_MSG + FORCE_REWRITE_MSG]) self.cli.assertStdout([]) def testStopAsyncRunning(self): self.invoke("admin rewrite") self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.invoke("admin stopasync") self.cli.assertStderr([]) self.cli.assertStdout([]) def testStopAsyncRunningForceRewrite(self): self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.invoke("admin stopasync --force-rewrite") self.cli.assertStderr([]) self.cli.assertStdout([]) def testStopAsyncNotRunning(self): self.invoke("admin rewrite") self.cli.checksStatus(1) # I.e. not running self.invoke("admin stopasync", fails=True) self.cli.assertStderr(["Server not running"]) self.cli.assertStdout([]) def testStopAsyncNotRunningForceRewrite(self): self.cli.checksStatus(1) # I.e. not running self.invoke("admin stopasync --force-rewrite", fails=True) self.cli.assertStderr(["Server not running"]) self.cli.assertStdout([]) def testStopNoConfig(self): self.invoke("admin stop", fails=True) self.cli.assertStderr([MISSING_CONFIGURATION_MSG + FORCE_REWRITE_MSG]) self.cli.assertStdout([]) def testStopNoConfigForceRewrite(self): self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.cli.checksStatus(1) # I.e. not running self.invoke("admin stop --force-rewrite") self.cli.assertStderr([]) self.cli.assertStdout(['Waiting on shutdown. Use CTRL-C to exit']) def testStop(self): self.invoke("admin rewrite") self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.cli.checksStatus(1) # I.e. not running self.invoke("admin stop") self.cli.assertStderr([]) self.cli.assertStdout(['Waiting on shutdown. Use CTRL-C to exit']) # # STATUS # def testDiagnostics(self): self.invoke("admin diagnostics") def testStatusNoConfig(self): self.invoke("admin status", fails=True) self.cli.assertStderr([MISSING_CONFIGURATION_MSG + REWRITE_MSG]) self.cli.assertStdout([]) def testStatusNodeFails(self): self.invoke("admin rewrite") # Setup the call to omero admin ice node popen = self.cli.createPopen() popen.wait().AndReturn(1) self.cli.mox.ReplayAll() pytest.raises(NonZeroReturnCode, self.invoke, "admin status") def testStatusSMFails(self): self.invoke("admin rewrite") # Setup the call to omero admin ice node popen = self.cli.createPopen() popen.wait().AndReturn(0) # Setup the call to session manager control = self.cli.controls["admin"] control._intcfg = lambda: "" def sm(*args): raise Exception("unknown") control.session_manager = sm self.cli.mox.ReplayAll() pytest.raises(NonZeroReturnCode, self.invoke, "admin status") def testStatusPasses(self, tmpdir, monkeypatch): self.invoke("admin rewrite") ice_config = old_div(tmpdir, 'ice.config') ice_config.write('omero.host=localhost\nomero.port=4064') monkeypatch.setenv("ICE_CONFIG", ice_config) # Setup the call to omero admin ice node popen = self.cli.createPopen() popen.wait().AndReturn(0) # Setup the call to session manager control = self.cli.controls["admin"] 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("admin status") assert 0 == self.cli.rv
class TestAdmin(object): @pytest.fixture(autouse=True) def setup_method(self, tmpadmindir): # Other setup self.cli = MockCLI() self.cli.dir = tmpadmindir self.cli.register("admin", AdminControl, "TEST") self.cli.register("config", PrefsControl, "TEST") def teardown_method(self, method): self.cli.teardown_method(method) def invoke(self, string, fails=False): try: self.cli.invoke(string, strict=True) if fails: assert False, "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("admin startasync") self.cli.assertCalled() self.cli.assertStderr( ['No descriptor given. Using etc/grid/default.xml']) def testStopAsyncNoConfig(self): self.invoke("admin stopasync", fails=True) self.cli.assertStderr([MISSING_CONFIGURATION_MSG + FORCE_REWRITE_MSG]) self.cli.assertStdout([]) def testStopAsyncRunning(self): self.invoke("admin rewrite") self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.invoke("admin stopasync") self.cli.assertStderr([]) self.cli.assertStdout([]) def testStopAsyncRunningForceRewrite(self): self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.invoke("admin stopasync --force-rewrite") self.cli.assertStderr([]) self.cli.assertStdout([]) def testStopAsyncNotRunning(self): self.invoke("admin rewrite") self.cli.checksStatus(1) # I.e. not running self.invoke("admin stopasync", fails=True) self.cli.assertStderr(["Server not running"]) self.cli.assertStdout([]) def testStopAsyncNotRunningForceRewrite(self): self.cli.checksStatus(1) # I.e. not running self.invoke("admin stopasync --force-rewrite", fails=True) self.cli.assertStderr(["Server not running"]) self.cli.assertStdout([]) def testStopNoConfig(self): self.invoke("admin stop", fails=True) self.cli.assertStderr([MISSING_CONFIGURATION_MSG + FORCE_REWRITE_MSG]) self.cli.assertStdout([]) def testStopNoConfigForceRewrite(self): self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.cli.checksStatus(1) # I.e. not running self.invoke("admin stop --force-rewrite") self.cli.assertStderr([]) self.cli.assertStdout(['Waiting on shutdown. Use CTRL-C to exit']) def testStop(self): self.invoke("admin rewrite") self.cli.checksStatus(0) # I.e. running self.cli.addCall(0) self.cli.checksStatus(1) # I.e. not running self.invoke("admin stop") self.cli.assertStderr([]) self.cli.assertStdout(['Waiting on shutdown. Use CTRL-C to exit']) # # STATUS # def testStatusNoConfig(self): self.invoke("admin status", fails=True) self.cli.assertStderr([MISSING_CONFIGURATION_MSG + REWRITE_MSG]) self.cli.assertStdout([]) def testStatusNodeFails(self): self.invoke("admin rewrite") # Setup the call to bin/omero admin ice node popen = self.cli.createPopen() popen.wait().AndReturn(1) self.cli.mox.ReplayAll() pytest.raises(NonZeroReturnCode, self.invoke, "admin status") def testStatusSMFails(self): self.invoke("admin rewrite") # 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["admin"] control._intcfg = lambda: "" def sm(*args): raise Exception("unknown") control.session_manager = sm self.cli.mox.ReplayAll() pytest.raises(NonZeroReturnCode, self.invoke, "admin status") def testStatusPasses(self, tmpdir, monkeypatch): self.invoke("admin rewrite") ice_config = tmpdir / 'ice.config' ice_config.write('omero.host=localhost\nomero.port=4064') monkeypatch.setenv("ICE_CONFIG", ice_config) # 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["admin"] 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("admin status") assert 0 == self.cli.rv
class TestAdmin(object): def setup_method(self, method): # 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 self.cli.register("admin", AdminControl, "TEST") self.cli.register("config", PrefsControl, "TEST") def teardown_method(self, method): self.cli.teardown_method(method) def invoke(self, string, fails=False): try: self.cli.invoke(string, strict=True) if fails: assert False, "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("admin 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("admin stopasync") self.cli.assertStderr([]) self.cli.assertStdout([]) def testStopAsyncNotRunning(self): self.cli.checksStatus(1) # I.e. not running self.invoke("admin 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("admin 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() pytest.raises(NonZeroReturnCode, self.invoke, "admin 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["admin"] control._intcfg = lambda: "" def sm(*args): raise Exception("unknown") control.session_manager = sm self.cli.mox.ReplayAll() pytest.raises(NonZeroReturnCode, self.invoke, "admin 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["admin"] 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("admin status") assert 0 == self.cli.rv
class TestAdmin(object): def setup_method(self, method): # 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 self.cli.register("a", AdminControl, "TEST") self.cli.register("config", PrefsControl, "TEST") def teardown_method(self, method): self.cli.teardown_method(method) def invoke(self, string, fails=False): try: self.cli.invoke(string, strict=True) if fails: assert False, "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() pytest.raises(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 Exception("unknown") control.session_manager = sm self.cli.mox.ReplayAll() pytest.raises(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") assert 0 == self.cli.rv