From 06c658d8ba3f86415a84c2efe6a21928554301e3 Mon Sep 17 00:00:00 2001 From: "Houqi (Nick) Zuo" Date: Tue, 14 Nov 2023 13:44:15 +0800 Subject: [PATCH] vt_iothread: New class added Add new support to the parameter: iothread_scheme. Signed-off-by: Houqi (Nick) Zuo --- virttest/vt_iothread.py | 64 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/virttest/vt_iothread.py b/virttest/vt_iothread.py index f2a4b730409..f1951422253 100644 --- a/virttest/vt_iothread.py +++ b/virttest/vt_iothread.py @@ -99,4 +99,66 @@ def request_iothread(self, iothread): self._iothread_finder[iothread.get_aid()] = iothread return iothread else: - raise ValueError("Not support request specific iothread") \ No newline at end of file + raise ValueError("Not support request specific iothread") + + +class MultiImagesRoundRobinManager(IOThreadManagerBase): + """ + Dispatch iothread object in new round-robin way. + Each iothreads will be allocated in round-robin way to the images. + """ + + def __init__(self, iothreads=None): + """ + Initialize iothread manager. + + :param iothreads: list of iothread objects, its id must conform with + ID_PATTERN. + :type iothreads: List + """ + super().__init__(iothreads) + self.__length = len(iothreads) + self.__current_index = 0 + + def request_iothread(self, iothread): + """Return iothread. + + :param iothread: iothread. + :type iothread: QIOThread + :return: iothread. + :rtype: QIOThread + """ + if iothread == "AUTO" or iothread == "auto": + iothread_aid = self.ID_PATTERN % ( + self.__current_index % self.__length) + iothread = self.find_iothread(iothread_aid) + self.__current_index += 1 + return iothread + raise ValueError("Not support request specific iothread!") + + +class FullManager(IOThreadManagerBase): + """Dispatch all iothread objects to an image device.""" + + def __init__(self, iothreads=None): + """ + Initialize iothread manager. + + :param iothreads: list of iothread objects, its id must conform with + ID_PATTERN. + :type iothreads: List + """ + super().__init__(iothreads) + self.__iothreads_list = iothreads + + def request_iothread(self, iothread): + """Return iothreads. + + :param iothread: iothread. + :type iothread: QIOThread + :return: the list of the iothreads. + :rtype: List + """ + if iothread == "AUTO" or iothread == "auto": + return self.__iothreads_list + raise ValueError("Not support request specific iothread!")