Python oslo_service.loopingcall.LoopingCallDone() Examples
The following are 30
code examples of oslo_service.loopingcall.LoopingCallDone().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_service.loopingcall
, or try the search function
.
Example #1
Source File: notification_base.py From masakari with Apache License 2.0 | 6 votes |
def check_notification_status(self, notification, wait_interval, wait_period): def wait_for_notification_status_finished(): result = self.admin_conn.ha.get_notification( notification.notification_uuid) if result.status == fields.NotificationStatus.FINISHED: raise loopingcall.LoopingCallDone() timer = loopingcall.FixedIntervalWithTimeoutLoopingCall( wait_for_notification_status_finished) try: timer.start(interval=wait_interval, initial_delay=1, timeout=wait_period).wait() except loopingcall.LoopingCallTimeOut: self.fail("Timed out: Notification is not processed and " "it's not in the finished status")
Example #2
Source File: utils.py From karbor with Apache License 2.0 | 6 votes |
def status_poll(get_status_func, interval, success_statuses=set(), failure_statuses=set(), ignore_statuses=set(), ignore_unexpected=False): def _poll(): status = get_status_func() if status in success_statuses: raise loopingcall.LoopingCallDone(retvalue=True) if status in failure_statuses: raise loopingcall.LoopingCallDone(retvalue=False) if status in ignore_statuses: return if ignore_unexpected is False: raise loopingcall.LoopingCallDone(retvalue=False) loop = loopingcall.FixedIntervalLoopingCall(_poll) return loop.start(interval=interval, initial_delay=interval).wait()
Example #3
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 6 votes |
def test_no_double_start(self): wait_ev = greenthreading.Event() def _run_forever_until_set(): if wait_ev.is_set(): raise loopingcall.LoopingCallDone(True) else: return 0.01 timer = loopingcall.DynamicLoopingCall(_run_forever_until_set) timer.start() self.assertRaises(RuntimeError, timer.start) wait_ev.set() timer.wait()
Example #4
Source File: notification_base.py From masakari with Apache License 2.0 | 6 votes |
def check_server_status(self, server, status): def wait_for_server_status_change(): instance = self.admin_conn.compute.get_server(server.id) if instance.status == status: raise loopingcall.LoopingCallDone() timer = loopingcall.FixedIntervalWithTimeoutLoopingCall( wait_for_server_status_change) try: timer.start(interval=self.SERVER_WAIT_INTERVAL, timeout=self.SERVER_WAIT_PERIOD).wait() except loopingcall.LoopingCallTimeOut: self.fail("Timed out: Instance is not in the expected" " status: %s" % status)
Example #5
Source File: aws_utils.py From openstack-omni with Apache License 2.0 | 6 votes |
def _create_sec_grp_rules(self, secgrp, rules): ingress, egress = self._convert_openstack_rules_to_vpc(rules) def _wait_for_state(start_time): current_time = time.time() if current_time - start_time > self._wait_time_sec: raise loopingcall.LoopingCallDone(False) try: self._refresh_sec_grp_rules(secgrp, ingress, egress) except Exception as ex: LOG.exception('Error creating security group rules. Retrying.') return raise loopingcall.LoopingCallDone(True) timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state, time.time()) return timer.start(interval=5).wait()
Example #6
Source File: ec2driver.py From openstack-omni with Apache License 2.0 | 6 votes |
def _wait_for_image_state(self, ami_id, desired_state): """Timer to wait for the image/snapshot to reach a desired state :params:ami_id: correspoding image id in Amazon :params:desired_state: the desired new state of the image to be in. """ def _wait_for_state(): """Called at an interval until the AMI image is available.""" try: images = self.ec2_conn.get_all_images(image_ids=[ami_id], owners=None, executable_by=None, filters=None, dry_run=None) state = images[0].state if state == desired_state: LOG.info("Image has changed state to %s." % desired_state) raise loopingcall.LoopingCallDone() except boto_exc.EC2ResponseError: pass timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state) timer.start(interval=0.5).wait()
Example #7
Source File: ebs.py From openstack-omni with Apache License 2.0 | 5 votes |
def _wait_for_create(self, id, final_state): def _wait_for_status(start_time): current_time = time.time() if current_time - start_time > self._wait_time_sec: raise loopingcall.LoopingCallDone(False) obj = self._conn.get_all_volumes([id])[0] if obj.status == final_state: raise loopingcall.LoopingCallDone(True) timer = loopingcall.FixedIntervalLoopingCall(_wait_for_status, time.time()) return timer.start(interval=5).wait()
Example #8
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_no_sleep(self, sleep_mock, random_mock): # Any call that executes properly the first time shouldn't sleep random_mock.return_value = 1 func = mock.Mock() # func.side_effect func.side_effect = loopingcall.LoopingCallDone(retvalue='return value') retvalue = loopingcall.BackOffLoopingCall(func).start().wait() self.assertFalse(sleep_mock.called) self.assertTrue(retvalue, 'return value')
Example #9
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_no_backoff(self, sleep_mock, random_mock): random_mock.return_value = 1 func = mock.Mock() # func.side_effect func.side_effect = [True, True, True, loopingcall.LoopingCallDone( retvalue='return value')] retvalue = loopingcall.BackOffLoopingCall(func).start().wait() expected_times = [mock.call(1), mock.call(1), mock.call(1)] self.assertEqual(expected_times, sleep_mock.call_args_list) self.assertTrue(retvalue, 'return value')
Example #10
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def _timeout_task_without_return_but_with_done(self): if self.num_runs == 0: raise loopingcall.LoopingCallDone(False) else: self.num_runs = self.num_runs - 1
Example #11
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def _wait_for_zero(self): """Called at an interval until num_runs == 0.""" if self.num_runs == 0: raise loopingcall.LoopingCallDone(False) else: self.num_runs = self.num_runs - 1 sleep_for = self.num_runs * 10 + 1 # dynamic duration return sleep_for
Example #12
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_return_false(self): def _raise_it(): raise loopingcall.LoopingCallDone(False) timer = loopingcall.DynamicLoopingCall(_raise_it) self.assertFalse(timer.start().wait())
Example #13
Source File: ec2driver.py From openstack-omni with Apache License 2.0 | 5 votes |
def _wait_for_state(self, instance, ec2_id, desired_state, desired_power_state): """Wait for the state of the corrosponding ec2 instance to be in completely available state. :params:ec2_id: the instance's corrosponding ec2 id. :params:desired_state: the desired state of the instance to be in. """ def _wait_for_power_state(): """Called at an interval until the VM is running again. """ ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id]) state = ec2_instance[0].state if state == desired_state: LOG.info("Instance has changed state to %s." % desired_state) raise loopingcall.LoopingCallDone() def _wait_for_status_check(): """Power state of a machine might be ON, but status check is the one which gives the real """ ec2_instance = self.ec2_conn.get_all_instance_status(instance_ids=[ec2_id])[0] if ec2_instance.system_status.status == 'ok': LOG.info("Instance status check is %s / %s" % (ec2_instance.system_status.status, ec2_instance.instance_status.status)) raise loopingcall.LoopingCallDone() #waiting for the power state to change timer = loopingcall.FixedIntervalLoopingCall(_wait_for_power_state) timer.start(interval=1).wait()
Example #14
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_monotonic_timer(self): def _raise_it(): clock = eventlet.hubs.get_hub().clock ok = (clock == time.monotonic) raise loopingcall.LoopingCallDone(ok) timer = loopingcall.DynamicLoopingCall(_raise_it) self.assertTrue(timer.start().wait())
Example #15
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_return_true(self): def _raise_it(): raise loopingcall.LoopingCallDone(True) timer = loopingcall.DynamicLoopingCall(_raise_it) self.assertTrue(timer.start().wait())
Example #16
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_no_double_stop(self): def _raise_it(): raise loopingcall.LoopingCallDone(False) timer = loopingcall.FixedIntervalLoopingCall(_raise_it) timer.start(interval=0.5) timer.stop() timer.stop()
Example #17
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def _wait_for_zero(self): """Called at an interval until num_runs == 0.""" if self.num_runs == 0: raise loopingcall.LoopingCallDone(False) else: self.num_runs = self.num_runs - 1
Example #18
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def _raise_and_then_done(self): if self.num_runs == 0: raise loopingcall.LoopingCallDone(False) else: self.num_runs = self.num_runs - 1 raise RuntimeError()
Example #19
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_return_false(self): def _raise_it(): raise loopingcall.LoopingCallDone(False) timer = loopingcall.FixedIntervalLoopingCall(_raise_it) self.assertFalse(timer.start(interval=0.5).wait())
Example #20
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_monotonic_timer(self): def _raise_it(): clock = eventlet.hubs.get_hub().clock ok = (clock == time.monotonic) raise loopingcall.LoopingCallDone(ok) timer = loopingcall.FixedIntervalLoopingCall(_raise_it) self.assertTrue(timer.start(interval=0.5).wait())
Example #21
Source File: test_loopingcall.py From oslo.service with Apache License 2.0 | 5 votes |
def test_return_true(self): def _raise_it(): raise loopingcall.LoopingCallDone(True) timer = loopingcall.FixedIntervalLoopingCall(_raise_it) self.assertTrue(timer.start(interval=0.5).wait())
Example #22
Source File: vmops.py From compute-hyperv with Apache License 2.0 | 5 votes |
def _wait_for_power_off(self, instance_name, time_limit): """Waiting for a VM to be in a disabled state. :return: True if the instance is shutdown within time_limit, False otherwise. """ desired_vm_states = [os_win_const.HYPERV_VM_STATE_DISABLED] def _check_vm_status(instance_name): if self._get_vm_state(instance_name) in desired_vm_states: raise loopingcall.LoopingCallDone() periodic_call = loopingcall.FixedIntervalLoopingCall(_check_vm_status, instance_name) try: # add a timeout to the periodic call. periodic_call.start(interval=SHUTDOWN_TIME_INCREMENT) etimeout.with_timeout(time_limit, periodic_call.wait) except etimeout.Timeout: # VM did not shutdown in the expected time_limit. return False finally: # stop the periodic call, in case of exceptions or Timeout. periodic_call.stop() return True
Example #23
Source File: process_failure.py From masakari with Apache License 2.0 | 5 votes |
def execute(self, process_name, host_name): def _wait_for_disable(): service_disabled = self.novaclient.is_service_down( self.context, host_name, process_name) if service_disabled: raise loopingcall.LoopingCallDone() periodic_call = loopingcall.FixedIntervalLoopingCall( _wait_for_disable) try: msg = "Confirming compute service is disabled on host: '%s'" % ( host_name) self.update_details(msg) # add a timeout to the periodic call. periodic_call.start(interval=CONF.verify_interval) etimeout.with_timeout( CONF.wait_period_after_service_update, periodic_call.wait) msg = "Confirmed compute service is disabled on host: '%s'" % ( host_name) self.update_details(msg, 1.0) except etimeout.Timeout: msg = "Failed to disable service %(process_name)s" % { 'process_name': process_name } self.update_details(msg, 1.0) raise exception.ProcessRecoveryFailureException( message=msg) finally: # stop the periodic call, in case of exceptions or Timeout. periodic_call.stop()
Example #24
Source File: instance_failure.py From masakari with Apache License 2.0 | 5 votes |
def execute(self, instance_uuid): def _wait_for_active(): new_instance = self.novaclient.get_server(self.context, instance_uuid) vm_state = getattr(new_instance, 'OS-EXT-STS:vm_state') if vm_state == 'active': raise loopingcall.LoopingCallDone() periodic_call = loopingcall.FixedIntervalLoopingCall( _wait_for_active) try: msg = "Confirming instance '%s' vm_state is ACTIVE" % instance_uuid self.update_details(msg) # add a timeout to the periodic call. periodic_call.start(interval=CONF.verify_interval) etimeout.with_timeout(CONF.wait_period_after_power_on, periodic_call.wait) msg = "Confirmed instance '%s' vm_state is ACTIVE" % instance_uuid self.update_details(msg, 1.0) except etimeout.Timeout: msg = "Failed to start instance %(instance)s" % { 'instance': instance_uuid } self.update_details(msg, 1.0) raise exception.InstanceRecoveryFailureException( message=msg) finally: # stop the periodic call, in case of exceptions or Timeout. periodic_call.stop()
Example #25
Source File: host_failure.py From masakari with Apache License 2.0 | 5 votes |
def _stop_after_evacuation(self, context, instance): def _wait_for_stop_confirmation(): old_vm_state, new_vm_state, instance_host = ( self._get_state_and_host_of_instance(context, instance)) if new_vm_state == 'stopped': raise loopingcall.LoopingCallDone() periodic_call_stopped = loopingcall.FixedIntervalLoopingCall( _wait_for_stop_confirmation) try: self.novaclient.stop_server(context, instance.id) # confirm instance is stopped after recovery periodic_call_stopped.start(interval=CONF.verify_interval) etimeout.with_timeout( CONF.wait_period_after_power_off, periodic_call_stopped.wait) except etimeout.Timeout: with excutils.save_and_reraise_exception(): periodic_call_stopped.stop() msg = ("Instance '%(uuid)s' is successfully evacuated but " "failed to stop.") % {'uuid': instance.id} LOG.warning(msg) else: periodic_call_stopped.stop()
Example #26
Source File: fakes.py From magnum with Apache License 2.0 | 5 votes |
def start(self, interval, **kwargs): initial_delay = kwargs.pop("initial_delay", 0) stop_on_exception = kwargs.pop("stop_on_exception", True) if initial_delay: time.sleep(initial_delay) while True: try: self.call_func() except loopingcall.LoopingCallDone: return 0 except Exception as exc: if stop_on_exception: raise exc if interval: time.sleep(interval)
Example #27
Source File: periodic.py From magnum with Apache License 2.0 | 5 votes |
def update_health_status(self): LOG.debug("Updating health status for cluster %s", self.cluster.id) self._update_health_status() LOG.debug("Status for cluster %s updated to %s (%s)", self.cluster.id, self.cluster.health_status, self.cluster.health_status_reason) # TODO(flwang): Health status update notifications? # end the "loop" raise loopingcall.LoopingCallDone()
Example #28
Source File: periodic.py From magnum with Apache License 2.0 | 5 votes |
def update_status(self): LOG.debug("Updating status for cluster %s", self.cluster.id) # get the driver for the cluster cdriver = driver.Driver.get_driver_for_cluster(self.ctx, self.cluster) # ask the driver to sync status cdriver.update_cluster_status(self.ctx, self.cluster) LOG.debug("Status for cluster %s updated to %s (%s)", self.cluster.id, self.cluster.status, self.cluster.status_reason) # status update notifications if self.cluster.status.endswith("_COMPLETE"): conductor_utils.notify_about_cluster_operation( self.ctx, self.status_to_event[self.cluster.status], taxonomy.OUTCOME_SUCCESS, self.cluster) if self.cluster.status.endswith("_FAILED"): conductor_utils.notify_about_cluster_operation( self.ctx, self.status_to_event[self.cluster.status], taxonomy.OUTCOME_FAILURE, self.cluster) # if we're done with it, delete it if self.cluster.status == objects.fields.ClusterStatus.DELETE_COMPLETE: # delete all the nodegroups that belong to this cluster for ng in objects.NodeGroup.list(self.ctx, self.cluster.uuid): ng.destroy() self.cluster.destroy() # end the "loop" raise loopingcall.LoopingCallDone()
Example #29
Source File: test_ebs.py From openstack-omni with Apache License 2.0 | 5 votes |
def test_volume_create_fails(self, mock_wait): def wait(*args): def _wait(): raise loopingcall.LoopingCallDone(False) timer = loopingcall.FixedIntervalLoopingCall(_wait) return timer.start(interval=1).wait() mock_wait.side_effect = wait self.assertRaises(APITimeout, self._driver.create_volume, self._stub_volume())
Example #30
Source File: aws_utils.py From openstack-omni with Apache License 2.0 | 5 votes |
def _create_sec_grp_tags(self, secgrp, tags): def _wait_for_state(start_time): current_time = time.time() if current_time - start_time > self._wait_time_sec: raise loopingcall.LoopingCallDone(False) try: secgrp.reload() secgrp.create_tags(Tags=tags) except Exception as ex: LOG.exception('Exception when adding tags to security groups.' ' Retrying.') return raise loopingcall.LoopingCallDone(True) timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state, time.time()) return timer.start(interval=5).wait()