def test_with_args(self): # A callback with args is correctly called. def callback(arg1, arg2, future): self.result = [arg1, arg2, future.result()] utils.add_future(self.io_loop, self.future, callback, 1, 2) self.future.set_result(3) yield self.assert_done([1, 2, 3])
def test_without_args(self): # A callback without args is correctly called. def callback(future): self.result = 'future said: ' + future.result() utils.add_future(self.io_loop, self.future, callback) self.future.set_result('I am done') yield self.assert_done('future said: I am done')
def test_with_args(self): # A callback with args is correctly called. def callback(arg1, arg2, future): self.result = [arg1, arg2, future.result()] self.stop() utils.add_future(self.io_loop, self.future, callback, 1, 2) self.future.set_result(3) yield self.assert_done([1, 2, 3])
def test_without_args(self): # A callback without args is correctly called. def callback(future): self.result = 'future said: ' + future.result() self.stop() utils.add_future(self.io_loop, self.future, callback) self.future.set_result('I am done') yield self.assert_done('future said: I am done')
def import_bundle(self, user, name, bundle, version, bundle_id, test_callback=None): """Schedule a deployment bundle import process. The deployment is executed in a separate process. The following arguments are required: - user: the current authenticated user; - name: the name of the bundle to be imported; - bundle: a YAML decoded object representing the bundle contents. - version: the version of the bundle syntax as an integer number; - bundle_id: the ID of the bundle. May be None. It is possible to also provide an optional test_callback that will be called when the deployment is completed. Note that this functionality is present only for tests: clients should not consider the test_callback argument part of the API, and should instead use the watch/next methods to observe the progress of a deployment (see below). Return the deployment identifier assigned to this deployment process. """ # Start observing this deployment, retrieve the next available # deployment id and notify its position at the end of the queue. deployment_id = self._observer.add_deployment() self._observer.notify_position(deployment_id, len(self._queue)) # Add this deployment to the queue. self._queue.append(deployment_id) # Add the import bundle job to the run executor, and set up a callback # to be called when the import process completes. future = self._run_executor.submit(blocking.import_bundle, self._apiurl, user.username, user.password, name, bundle, version, self.importer_options) add_future(self._io_loop, future, self._import_callback, deployment_id, bundle_id) self._futures[deployment_id] = future # If a customized callback is provided, schedule it as well. if test_callback is not None: add_future(self._io_loop, future, test_callback) # Submit a sleeping job in order to avoid the next deployment job to be # immediately put in the executor's call queue. This allows for # cancelling scheduled jobs, even if the job is the next to be started. self._run_executor.submit(time.sleep, 1) return deployment_id
def import_bundle( self, user, name, bundle, version, bundle_id, test_callback=None): """Schedule a deployment bundle import process. The deployment is executed in a separate process. The following arguments are required: - user: the current authenticated user; - name: the name of the bundle to be imported; - bundle: a YAML decoded object representing the bundle contents. - version: the version of the bundle syntax as an integer number; - bundle_id: the ID of the bundle. May be None. It is possible to also provide an optional test_callback that will be called when the deployment is completed. Note that this functionality is present only for tests: clients should not consider the test_callback argument part of the API, and should instead use the watch/next methods to observe the progress of a deployment (see below). Return the deployment identifier assigned to this deployment process. """ # Start observing this deployment, retrieve the next available # deployment id and notify its position at the end of the queue. deployment_id = self._observer.add_deployment() self._observer.notify_position(deployment_id, len(self._queue)) # Add this deployment to the queue. self._queue.append(deployment_id) # Add the import bundle job to the run executor, and set up a callback # to be called when the import process completes. future = self._run_executor.submit( blocking.import_bundle, self._apiurl, user.username, user.password, name, bundle, version, self.importer_options) add_future(self._io_loop, future, self._import_callback, deployment_id, bundle_id) self._futures[deployment_id] = future # If a customized callback is provided, schedule it as well. if test_callback is not None: add_future(self._io_loop, future, test_callback) # Submit a sleeping job in order to avoid the next deployment job to be # immediately put in the executor's call queue. This allows for # cancelling scheduled jobs, even if the job is the next to be started. self._run_executor.submit(time.sleep, 1) return deployment_id