diff options
author | Cole Robinson <crobinso@redhat.com> | 2020-09-02 11:22:02 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2020-09-02 12:59:25 -0400 |
commit | 29f866e6f35bab64e8bfb2e275a3a87b8ade5ae4 (patch) | |
tree | 71a82b60b780c38c075e01b20a1f263d13ce5b6c /virtManager | |
parent | a10d746c419b71d7621de765eeeee48235c61c08 (diff) | |
download | virt-manager-29f866e6f35bab64e8bfb2e275a3a87b8ade5ae4.tar.gz |
uitests: add connection object blacklist testing
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'virtManager')
-rw-r--r-- | virtManager/connection.py | 19 | ||||
-rw-r--r-- | virtManager/lib/testmock.py | 6 | ||||
-rw-r--r-- | virtManager/object/libvirtobject.py | 3 |
3 files changed, 17 insertions, 11 deletions
diff --git a/virtManager/connection.py b/virtManager/connection.py index 0f0db4fe..ff67981f 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -55,9 +55,8 @@ class _ObjectList(vmmGObject): :returns: number of added object to list """ key = self._blacklist_key(obj) - if self.in_blacklist(obj): - self._blacklist[key] += 1 - self._blacklist[key] = 1 + count = self._blacklist.get(key, 0) + self._blacklist[key] = count + 1 return self._blacklist[key] def remove_blacklist(self, obj): @@ -65,7 +64,8 @@ class _ObjectList(vmmGObject): :param obj: vmmLibvirtObject to remove from blacklist :returns: True if object was blacklisted or False otherwise. """ - return bool(self._blacklist.pop(self._blacklist_key(obj), 0)) + key = self._blacklist_key(obj) + return bool(self._blacklist.pop(key, 0)) def in_blacklist(self, obj): """ @@ -75,7 +75,8 @@ class _ObjectList(vmmGObject): :param obj: vmmLibvirtObject to check :returns: True if object is blacklisted """ - return self._blacklist.get(self._blacklist_key(obj), 0) > _ObjectList.BLACKLIST_COUNT + key = self._blacklist_key(obj) + return self._blacklist.get(key, 0) >= _ObjectList.BLACKLIST_COUNT def remove(self, obj): """ @@ -1042,14 +1043,10 @@ class vmmConnection(vmmGObject): if initialize_failed: log.debug("Blacklisting %s=%s", class_name, obj.get_name()) count = self._objects.add_blacklist(obj) - if count <= _ObjectList.BLACKLIST_COUNT: - log.debug("Object added in blacklist, count=%d", count) - else: - log.debug("Object already blacklisted?") + log.debug("Object added in blacklist, count=%d", count) return - else: - self._objects.remove_blacklist(obj) + self._objects.remove_blacklist(obj) if not self._objects.add(obj): log.debug("New %s=%s requested, but it's already tracked.", class_name, obj.get_name()) diff --git a/virtManager/lib/testmock.py b/virtManager/lib/testmock.py index 9349100e..8edfb61e 100644 --- a/virtManager/lib/testmock.py +++ b/virtManager/lib/testmock.py @@ -113,6 +113,10 @@ class CLITestOptionsClass: Spice doesn't return values here when we are just testing against seabios in uitests, this fakes it to hit more code paths * fake-systray: Enable the fake systray window + * object-blacklist=NAME: Make object initialize for that name + fail to test some connection code paths + * conn-crash: Test connection abruptly closing like when + libvirtd is restarted. """ def __init__(self, test_options_str): optset = set() @@ -151,6 +155,8 @@ class CLITestOptionsClass: self.fake_vnc_username = _get("fake-vnc-username") self.fake_console_resolution = _get("fake-console-resolution") self.fake_systray = _get("fake-systray") + self.object_blacklist = _get_value("object-blacklist") + self.conn_crash = _get("conn-crash") if optset: # pragma: no cover raise RuntimeError("Unknown --test-options keys: %s" % optset) diff --git a/virtManager/object/libvirtobject.py b/virtManager/object/libvirtobject.py index 0dfe68b3..0c35dd4e 100644 --- a/virtManager/object/libvirtobject.py +++ b/virtManager/object/libvirtobject.py @@ -174,6 +174,9 @@ class vmmLibvirtObject(vmmGObject): initialize_failed = False try: + if self.config.CLITestOptions.object_blacklist == self._name: + raise RuntimeError("fake initialization error") + self._init_libvirt_state() except Exception: # pragma: no cover log.debug("Error initializing libvirt state for %s", self, |