def testStopVersion_CurrentModule(self): self.request_data.get_dispatcher().AndReturn(self.dispatcher) self.request_data.get_module(None).AndReturn('default') self.dispatcher.stop_version('default', '1').AndReturn(5) self.mox.ReplayAll() modules.stop_version(version='1') self.mox.VerifyAll()
def cron_stop_non_default_instances(): # core logic (inside a cron or other handler) for m in modules.get_modules(): dv = modules.get_default_version(m) for v in modules.get_versions(m): if v != dv: modules.stop_version(m, v) return "Success!"
def cron_stop_non_default_instances(): # core logic (inside a cron or other handler) for m in modules.get_modules(): dv = modules.get_default_version(m) for v in modules.get_versions(m): if v != dv: modules.stop_version(m, v) return "Success!"
def testStopVersion_CurrentVersionDifferentModule(self): self.request_data.get_dispatcher().AndReturn(self.dispatcher) self.request_data.get_version(None).AndReturn('1') self.dispatcher.get_versions('other').AndReturn(['1']) self.dispatcher.stop_version('other', '1').AndReturn(5) self.mox.ReplayAll() modules.stop_version(module='other') self.mox.VerifyAll()
def testStopVersion_CurrentVersionDoesNotExistInOtherModule(self): self.request_data.get_dispatcher().AndReturn(self.dispatcher) self.request_data.get_version(None).AndReturn('1') self.dispatcher.get_versions('other').AndReturn(['2']) self.dispatcher.get_default_version('other').AndReturn('2') self.dispatcher.stop_version('other', '2').AndReturn(5) self.mox.ReplayAll() modules.stop_version(module='other') self.mox.VerifyAll()
def testStopVersion_NoVersion(self): """Test we pass through the expected args.""" expected_request = modules_service_pb2.StopModuleRequest() expected_request.module = 'module1' service_response = modules_service_pb2.StopModuleResponse() self.SetSuccessExpectations('StopModule', expected_request, service_response) modules.stop_version('module1')
def testStopVersion_AlreadyStopped(self): """Tests that no error is raised if the version is already stopped.""" self.request_data.get_dispatcher().AndReturn(self.dispatcher) self.dispatcher.stop_version('default', '1').AndRaise( request_info.VersionAlreadyStoppedError) self.mox.StubOutWithMock(logging, 'info') logging.info('The specified module: default, version: 1 is already ' 'stopped.') self.mox.ReplayAll() modules.stop_version('default', '1') self.mox.VerifyAll()
def testStopVersion_AlreadyStopped(self): """Test we don't raise an error if the version is already stopped.""" expected_request = modules_service_pb2.StopModuleRequest() expected_request.module = 'module1' expected_request.version = 'v1' self.mox.StubOutWithMock(logging, 'info') logging.info('The specified module: module1, version: v1 is already ' 'stopped.') self.SetExceptionExpectations( 'StopModule', expected_request, modules_service_pb2.ModulesServiceError.UNEXPECTED_STATE) modules.stop_version('module1', 'v1')