Beispiel #1
0
    def test_sleep_until_condition_already_fulfilled(self, mock_sleep, mock_update_status):
        """
        Check if sleep_until behaves correctly if condition to wait for
        is already fulfilled.
        """
        conditions = [
            lambda: server.status.is_steady_state,
            lambda: server.status.accepts_ssh_commands,
        ]
        for condition in conditions:
            server = OpenStackServerFactory()
            status_queue = [
                server._status_to_started,
                server._status_to_active,
                server._status_to_booted,
            ]
            # Transition to state fulfilling condition
            for state_transition in status_queue:
                server._transition(state_transition, progress=ServerProgress.Success)

            # Sleep until condition is fulfilled.
            # Use a small value for "timeout" to ensure that we can fail quickly
            # if server can not reach desired status because transition logic is broken:
            server.sleep_until(condition, timeout=5)
            self.assertEqual(server.status, ServerStatus.Booted)
            self.assertEqual(server.progress, ServerProgress.Success)
            self.assertEqual(mock_sleep.call_count, 0)