Skip to content

Commit

Permalink
test_guest: mock http_get_header so tests work with no network
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Williamson <[email protected]>
  • Loading branch information
AdamWill committed Jan 26, 2024
1 parent 7d53256 commit a8aad73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Containerfile.tests.el7
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FROM quay.io/centos/centos:7
RUN set -exo pipefail \
&& yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& yum install -y python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic libvirt \
&& yum install -y python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic python-mock libvirt \
&& yum clean all \
&& rm -rf /var/cache/* /var/log/yum*

Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dnf install python3-requests python3-m2crypto python3-libvirt python3-lxml pytho

If you wish to test on EL 7, make that:

yum install python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic
yum install python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic python-mock

then run the tests:

Expand Down
9 changes: 8 additions & 1 deletion tests/guest/test_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from io import StringIO
import logging
import os
try:
from unittest import mock
except ImportError:
import mock

# Find oz library
prefix = '.'
Expand Down Expand Up @@ -72,7 +76,10 @@ def setup_guest(xml, macaddress=None):
config = configparser.ConfigParser()
config.read_file(StringIO("[libvirt]\nuri=qemu:///session\nbridge_name=%s" % route))

guest = oz.GuestFactory.guest_factory(tdl, config, None, macaddress=macaddress)
# mock this - it's used in RedHatLinuxCDYumGuest._check_url() -
# so the tests can run without a network connection
with mock.patch("oz.ozutil.http_get_header", return_value={}):
guest = oz.GuestFactory.guest_factory(tdl, config, None, macaddress=macaddress)
return guest

tdlxml = """
Expand Down

0 comments on commit a8aad73

Please sign in to comment.