Skip to content

Commit a8aad73

Browse files
committed
test_guest: mock http_get_header so tests work with no network
Signed-off-by: Adam Williamson <[email protected]>
1 parent 7d53256 commit a8aad73

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Containerfile.tests.el7

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
FROM quay.io/centos/centos:7
55
RUN set -exo pipefail \
66
&& yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
7-
&& yum install -y python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic libvirt \
7+
&& yum install -y python-requests m2crypto libvirt-python python-lxml python-libguestfs pytest python-monotonic python-mock libvirt \
88
&& yum clean all \
99
&& rm -rf /var/cache/* /var/log/yum*
1010

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dnf install python3-requests python3-m2crypto python3-libvirt python3-lxml pytho
2828

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

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

3333
then run the tests:
3434

tests/guest/test_guest.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
from io import StringIO
1313
import logging
1414
import os
15+
try:
16+
from unittest import mock
17+
except ImportError:
18+
import mock
1519

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

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

7885
tdlxml = """

0 commit comments

Comments
 (0)