Example #1
0
    def wait_for_server_status(self,
                               server_id,
                               desired_status,
                               interval_time=None,
                               timeout=None):

        interval_time = int(interval_time
                            or self.servers_api_config.server_status_interval)
        timeout = int(timeout or self.servers_api_config.server_build_timeout)
        end_time = time.time() + timeout

        time.sleep(interval_time)
        while time.time() < end_time:
            resp = self.nova_cli_client.show_server(server_id)
            server = resp.entity

            if server.status.lower() == ServerStates.ERROR.lower():
                raise BuildErrorException(
                    'Build failed. Server with uuid "{0} entered ERROR status.'
                    .format(server.id))

            if server.status == desired_status:
                break
            time.sleep(interval_time)

        else:
            raise TimeoutException(
                "wait_for_server_status ran for {0} seconds and did not "
                "observe server {1} reach the {2} status.".format(
                    timeout, server_id, desired_status))

        return resp
Example #2
0
    def wait_for_task_status(self,
                             task_id,
                             desired_status,
                             interval_time=10,
                             timeout=1200,
                             response_entity_type=None):
        """
        @summary: Waits for a task to reach a desired status and if the import
        task is successful, adds the created image to the resource pool for
        tear down

        @param task_id: Task id to evaluate
        @type task_id: UUID
        @param desired_status: Expected final status of task
        @type desired_status: String
        @param interval_time: Amount of time in seconds to wait between polling
        @type interval_time: Integer
        @param timeout: Amount of time in seconds to wait before aborting
        @type timeout: Integer
        @param response_entity_type: Response entity type to be passed on to
        python requests
        @type response_entity_type: Type

        @return: Task
        @rtype: Object
        """

        interval_time = interval_time or self.config.task_status_interval
        timeout = timeout or self.config.task_timeout
        end_time = time.time() + timeout
        if not response_entity_type:
            response_entity_type = Task

        while time.time() < end_time:
            resp = self.client.get_task_details(
                task_id, response_entity_type=response_entity_type)
            task = self.verify_resp(resp, 'get task details', task_id)

            if ((task.status.lower() == TaskStatus.FAILURE
                 and desired_status != TaskStatus.FAILURE)
                    or (task.status.lower() == TaskStatus.SUCCESS
                        and desired_status != TaskStatus.SUCCESS)):
                raise BuildErrorException(
                    'Task with the uuid {0} entered the {1} status. Task '
                    'responded with the message {2}'.format(
                        task.id_, task.status, task.message.replace('\\', '')))

            if task.status == desired_status:
                break
            time.sleep(interval_time)
        else:
            raise TimeoutException(
                'Task with the uuid {0} did not reach the {1} status within '
                '{2} seconds.'.format(task_id, desired_status, timeout))

        if (task is not None and task.type_ == TaskTypes.IMPORT
                and task.status.lower() == TaskStatus.SUCCESS):
            self.resources.add(task.result.image_id, self.client.delete_image)

        return task
Example #3
0
    def wait_for_image_status(self, image_id, desired_status,
                              interval_time=None, timeout=None):
        """
        @summary: Waits for a image to reach a desired status
        @param image_id: The uuid of the image
        @type image_id: String
        @param desired_status: The desired final status of the image
        @type desired_status: String
        @param interval_time: The amount of time in seconds to wait
                              between polling
        @type interval_time: Integer
        @param interval_time: The amount of time in seconds to wait
                              before aborting
        @type interval_time: Integer
        @return: Response object containing response and the image
                 domain object
        @rtype: requests.Response
        """

        interval_time = interval_time or self.config.image_status_interval
        timeout = timeout or self.config.snapshot_timeout
        end_time = time.time() + timeout

        while time.time() < end_time:
            resp = self.images_client.get_image(image_id)
            image = resp.entity

            if image.status.lower() == ImageStates.ERROR.lower():
                raise BuildErrorException(
                    'Build failed. Image with UUID {0} '
                    'entered ERROR status.'.format(image.id))

            if image.status.lower() == ImageStates.DELETED.lower():
                raise BuildErrorException(
                    'Build failed. Image with UUID {0} '
                    'entered DELETED status.'.format(image.id))

            if image.status == desired_status:
                break
            time.sleep(interval_time)
        else:
            raise TimeoutException(
                "wait_for_image_status ran for {0} seconds and did not "
                "observe image {1} reach the {2} status.".format(
                    timeout, image_id, desired_status))

        return resp
Example #4
0
    def wait_for_server_task_state(self,
                                   server_id,
                                   state_to_wait_for,
                                   timeout,
                                   interval_time=None):
        """
        @summary: Polls server task state until state_to_wait_for is met
        @param server_id: The uuid of the server
        @type server_id: String
        @param state_to_wait_for: The desired final status of the server
        @type state_to_wait_for: String
        @param timeout: The amount of time in seconds to wait
                              before aborting
        @type timeout: Integer
        @param interval_time: The amount of time in seconds to wait
                              between polling
        @type interval_time: Integer
        """

        interval_time = interval_time or self.config.server_status_interval
        end_time = time.time() + timeout

        while time.time() < end_time:
            response = self.servers_client.get_server(server_id)

            if not response.ok:
                raise Exception("Failed to get server information: "
                                "{code} - {reason}".format(
                                    code=response.status_code,
                                    reason=response.reason))

            if response.entity is None:
                raise Exception("Response entity was not set. "
                                "Response was: {0}".format(response.content))

            task_state = response.entity.task_state.lower()

            if response.entity.status.lower() != ServerStates.ERROR.lower():
                raise BuildErrorException(
                    "Build failed. Server with uuid {server_id} entered "
                    "ERROR status.".format(server_id))

            if task_state == state_to_wait_for.lower():
                break
            time.sleep(interval_time)

        else:
            raise TimeoutException(
                "Wait for server task ran for {timeout} seconds and did not "
                "observe server {server_id} reach desired task state of "
                "{state_to_wait_for}.".format(
                    timeout=timeout,
                    server_id=server_id,
                    state_to_wait_for=state_to_wait_for))

        return response
Example #5
0
    def wait_for_server_status(self,
                               server_id,
                               desired_status,
                               interval_time=None,
                               timeout=None):
        """
        @summary: Waits for a server to reach a desired status
        @param server_id: The uuid of the server
        @type server_id: String
        @param desired_status: The desired final status of the server
        @type desired_status: String
        @param interval_time: The amount of time in seconds to wait
                              between polling
        @type interval_time: Integer
        @param timeout: The amount of time in seconds to wait
                              before aborting
        @type timeout: Integer
        @return: Response object containing response and the server
                 domain object
        @rtype: requests.Response
        """

        interval_time = interval_time or self.config.server_status_interval
        timeout = timeout or self.config.server_build_timeout
        end_time = time.time() + timeout

        time.sleep(interval_time)
        while time.time() < end_time:
            resp = self.servers_client.get_server(server_id)

            if not resp.ok:
                raise Exception("Failed to get server information: "
                                "{code} - {reason}".format(
                                    code=resp.status_code, reason=resp.reason))

            if resp.entity is None:
                raise Exception("Response entity was not set. "
                                "Response was: {0}".format(resp.content))

            server = resp.entity

            if server.status.lower() == ServerStates.ERROR.lower():
                raise BuildErrorException(
                    "Build failed. Server with uuid {server_id} entered "
                    "ERROR status.".format(server_id=server.id))

            if server.status == desired_status:
                break
            time.sleep(interval_time)
        else:
            raise TimeoutException(
                "wait_for_server_status ran for {0} seconds and did not "
                "observe server {1} reach the {2} status.".format(
                    timeout, server_id, desired_status))

        return resp
Example #6
0
    def wait_for_task_status(self,
                             task_id,
                             desired_status,
                             interval_time=10,
                             timeout=1200):
        """
        @summary: Waits for a task to reach a desired status

        @param task_id: Task id to evaluate
        @type task_id: UUID
        @param desired_status: Expected final status of task
        @type desired_status: String
        @param interval_time: Amount of time in seconds to wait between polling
        @type interval_time: Integer
        @param timeout: Amount of time in seconds to wait before aborting
        @type timeout: Integer

        @return: Task
        @rtype: Object
        """

        interval_time = interval_time or self.config.task_status_interval
        timeout = timeout or self.config.task_timeout
        end_time = time.time() + timeout

        while time.time() < end_time:
            resp = self.client.get_task_details(task_id)
            task = resp.entity

            if ((task.status.lower() == TaskStatus.FAILURE
                 and desired_status != TaskStatus.FAILURE)
                    or (task.status.lower() == TaskStatus.SUCCESS
                        and desired_status != TaskStatus.SUCCESS)):
                raise BuildErrorException(
                    'Task with uuid {0} entered {1} status. Task responded '
                    'with the message {2}'.format(
                        task.id_, task.status, task.message.replace('\\', '')))

            if task.status == desired_status:
                break
            time.sleep(interval_time)
        else:
            raise TimeoutException(
                'Failed to reach the {0} status after {1} seconds for task '
                'with uuid {2}'.format(desired_status, timeout, task_id))

        if (task is not None and task.type_ == TaskTypes.IMPORT
                and task.status.lower() == TaskStatus.SUCCESS):
            self.resources.add(task.result.image_id, self.client.delete_image)

        return task
Example #7
0
    def wait_for_image_status(self,
                              image_id,
                              desired_status,
                              interval_time=15,
                              timeout=900):
        """
        @summary: Wait for a image to reach a desired status

        @param image_id: Image id to evaluate
        @type image_id: UUID
        @param desired_status: Expected final status of image
        @type desired_status: String
        @param interval_time: Amount of time in seconds to wait between polling
        @type interval_time: Integer
        @param timeout: Amount of time in seconds to wait before aborting
        @type timeout: Integer

        @return: Resp
        @rtype: Object
        """

        interval_time = interval_time or self.config.image_status_interval
        timeout = timeout or self.config.snapshot_timeout
        end_time = time.time() + timeout

        while time.time() < end_time:
            resp = self.client.get_image_details(image_id)
            image = resp.entity

            if image.status.lower() == ImageStatus.ERROR.lower():
                raise BuildErrorException("Build failed. Image with uuid {0} "
                                          "entered ERROR status.".format(
                                              image.id))

            if image.status == desired_status:
                break

            time.sleep(interval_time)
        else:
            raise TimeoutException(
                "wait_for_image_status ran for {0} seconds and did not "
                "observe image {1} reach the {2} status.".format(
                    timeout, image_id, desired_status))

        return resp
Example #8
0
    def wait_for_image_status(self,
                              image_id,
                              desired_status,
                              interval_time=15,
                              timeout=900):
        """
        @summary: Wait for a image to reach a desired status

        @param image_id: Image id to evaluate
        @type image_id: UUID
        @param desired_status: Expected final status of image
        @type desired_status: String
        @param interval_time: Amount of time in seconds to wait between polling
        @type interval_time: Integer
        @param timeout: Amount of time in seconds to wait before aborting
        @type timeout: Integer

        @return: Resp
        @rtype: Object
        """

        interval_time = interval_time or self.config.image_status_interval
        timeout = timeout or self.config.snapshot_timeout
        end_time = time.time() + timeout

        while time.time() < end_time:
            resp = self.client.get_image_details(image_id)
            image = self.verify_resp(resp, 'get image details', image_id)

            if image.status.lower() == ImageStatus.ERROR.lower():
                raise BuildErrorException(
                    'Image with the uuid {0} entered ERROR '
                    'status.'.format(image_id))

            if image.status == desired_status:
                break

            time.sleep(interval_time)
        else:
            raise TimeoutException(
                'Image with the uuid {0} did not reach the {1} status within '
                '{2} seconds.'.format(image_id, desired_status, timeout))

        return resp
Example #9
0
    def wait_for_server_status(self, server_id, desired_status,
                               interval_time=None, timeout=None):
        """
        @summary: Waits for a server to reach a desired status
        @param server_id: The uuid of the server
        @type server_id: String
        @param desired_status: The desired final status of the server
        @type desired_status: String
        @param interval_time: The amount of time in seconds to wait
                              between polling
        @type interval_time: Integer
        @param interval_time: The amount of time in seconds to wait
                              before aborting
        @type interval_time: Integer
        @return: Response object containing response and the server
                 domain object
        @rtype: requests.Response
        """

        interval_time = interval_time or self.config.server_status_interval
        timeout = timeout or self.config.server_build_timeout
        end_time = time.time() + timeout

        while time.time() < end_time:
            resp = self.servers_client.get_server(server_id)
            server = resp.entity

            if server.status.lower() == ServerStates.ERROR.lower():
                raise BuildErrorException(
                    'Build failed. Server with uuid %s entered ERROR status.'
                    % server.id)

            if server.status == desired_status:
                break
            time.sleep(interval_time)
        else:
            raise TimeoutException(
                "wait_for_server_status ran for {0} seconds and did not "
                "observe the server achieving the {1} status.".format(
                    timeout, desired_status))

        return resp
Example #10
0
    def wait_for_task_status(self,
                             task_id,
                             desired_status,
                             interval_time=None,
                             timeout=None):
        """@summary: Waits for a task to reach a desired status"""

        interval_time = interval_time or self.config.task_status_interval
        timeout = timeout or self.config.task_timeout
        end_time = time.time() + timeout

        while time.time() < end_time:
            resp = self.client.get_task(task_id)
            task = resp.entity

            if ((task.status.lower() == TaskStatus.FAILURE
                 and desired_status != TaskStatus.FAILURE)
                    or (task.status.lower() == TaskStatus.SUCCESS
                        and desired_status != TaskStatus.SUCCESS)):
                raise BuildErrorException(
                    'Task with uuid {0} entered {1} status. Task responded '
                    'with the message {2}'.format(
                        task.id_, task.status, task.message.replace('\\', '')))

            if task.status == desired_status:
                break
            time.sleep(interval_time)
        else:
            raise TimeoutException(
                'Failed to reach the {0} status after {1} seconds for task '
                'with uuid {2}'.format(desired_status, timeout, task_id))

        if (task is not None and task.type_ == TaskTypes.IMPORT
                and task.status.lower() == TaskStatus.SUCCESS):
            self.resources.add(task.result.image_id, self.client.delete_image)

        return task