Skip to content

Commit

Permalink
systemtests python-bareos: prevent warnings
Browse files Browse the repository at this point in the history
When trying an unsuccessful authentication,
Python issues a warning message about an unclosed SSL socket.
This change hides these warnings.

It also contain a workaround to prevent a Deprecation Warning in Python > 3.2.
  • Loading branch information
joergsteffens committed Nov 23, 2020
1 parent f54ea4b commit 6c5d6db
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion python-bareos/bareos/bsock/lowlevel.py
Expand Up @@ -314,7 +314,7 @@ def _init_connection(self):

def close(self):
"""disconnect"""
if self.socket:
if self.socket is not None:
self.socket.close()
self.socket = None

Expand Down
87 changes: 52 additions & 35 deletions systemtests/tests/python-bareos/python-bareos-unittest.py
Expand Up @@ -28,6 +28,7 @@
import re
from time import sleep
import unittest
import warnings

import bareos.bsock
from bareos.bsock.constants import Constants
Expand Down Expand Up @@ -67,6 +68,14 @@ def setUp(self):
logger = logging.getLogger()
if self.debug:
logger.setLevel(logging.DEBUG)

# assertRegexpMatches has been renamed
# to assertRegex in Python 3.2
# and is deprecated now.
# This prevents a deprecation warning.
if hasattr(self, "assertRegexpMatches") and not hasattr(self, "assertRegex"):
self.assertRegex = self.assertRegexpMatches

logger.debug("setUp")

def tearDown(self):
Expand Down Expand Up @@ -135,8 +144,7 @@ def test_protocol_message(self):
hello_message = ProtocolMessages().hello(name)
logger.debug(hello_message)

# with Python 3.2 assertRegexpMatches is renamed to assertRegex.
self.assertRegexpMatches(hello_message, expected_regex)
self.assertRegex(hello_message, expected_regex)

version = re.search(expected_regex, hello_message).group(1).decode("utf-8")
logger.debug(u"version: {} ({})".format(version, type(version)))
Expand Down Expand Up @@ -208,13 +216,15 @@ def test_login_with_not_existing_username(self):

bareos_password = bareos.bsock.Password(password)
with self.assertRaises(bareos.exceptions.AuthenticationError):
director = bareos.bsock.DirectorConsole(
address=self.director_address,
port=self.director_port,
name=username,
password=bareos_password,
**self.director_extra_options
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
director = bareos.bsock.DirectorConsole(
address=self.director_address,
port=self.director_port,
name=username,
password=bareos_password,
**self.director_extra_options
)

def test_login_with_wrong_password(self):
"""
Expand All @@ -227,13 +237,15 @@ def test_login_with_wrong_password(self):

bareos_password = bareos.bsock.Password(password)
with self.assertRaises(bareos.exceptions.AuthenticationError):
director = bareos.bsock.DirectorConsole(
address=self.director_address,
port=self.director_port,
name=username,
password=bareos_password,
**self.director_extra_options
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
director = bareos.bsock.DirectorConsole(
address=self.director_address,
port=self.director_port,
name=username,
password=bareos_password,
**self.director_extra_options
)

def test_no_autodisplay_command(self):
"""
Expand Down Expand Up @@ -528,15 +540,17 @@ def test_login_notls_tls_fixedprotocolversion(self):
password = self.get_operator_password(username)

with self.assertRaises(bareos.exceptions.AuthenticationError):
director = bareos.bsock.DirectorConsole(
address=self.director_address,
port=self.director_port,
tls_psk_enable=False,
protocolversion=ProtocolVersions.last,
name=username,
password=password,
**self.director_extra_options
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
director = bareos.bsock.DirectorConsole(
address=self.director_address,
port=self.director_port,
tls_psk_enable=False,
protocolversion=ProtocolVersions.last,
name=username,
password=password,
**self.director_extra_options
)

@unittest.skipUnless(
bareos.bsock.DirectorConsole.is_tls_psk_available(), "TLS-PSK is not available."
Expand Down Expand Up @@ -742,6 +756,7 @@ def _test_no_volume_in_pool(self, console, password, pool):
port=self.director_port,
name=console,
password=bareos_password,
**self.director_extra_options
)

result = console_poolbotfull.call("llist media all")
Expand Down Expand Up @@ -1207,8 +1222,10 @@ def test_json_list_media_with_pool_acl(self):
),
)

# TODO: IMHO this is a bug. This console should not see volumes in the Full pool.
# It needs to be fixed in the server side code.
# TODO:
# IMHO this is a bug.
# This console should not see volumes in the Full pool.
# It needs to be fixed in the server side code.
with self.assertRaises(AssertionError):
self._test_no_volume_in_pool(console_overwrite, console_password, "Full")

Expand Down Expand Up @@ -1533,9 +1550,6 @@ def test_delete_jobid(self):

def test_delete_jobids(self):
"""
Note:
If delete is called on a non existing jobid,
this jobid will neithertheless be returned as deleted.
"""
logger = logging.getLogger()

Expand All @@ -1550,6 +1564,9 @@ def test_delete_jobids(self):
**self.director_extra_options
)

# Note:
# If delete is called on a non existing jobid,
# this jobid will neithertheless be returned as deleted.
jobids = ["1001", "1002", "1003"]
result = director.call("delete jobid={}".format(",".join(jobids)))
logger.debug(str(result))
Expand All @@ -1560,9 +1577,6 @@ def test_delete_jobids(self):

def test_delete_jobid_paramter(self):
"""
Note:
If delete is called on a non existing jobid,
this jobid will neithertheless be returned as deleted.
"""
logger = logging.getLogger()

Expand All @@ -1577,6 +1591,9 @@ def test_delete_jobid_paramter(self):
**self.director_extra_options
)

# Note:
# If delete is called on a non existing jobid,
# this jobid will neithertheless be returned as deleted.
jobids = "jobid=1001,1002,1101-1110,1201 jobid=2001,2002,2101-2110,2201"
# 1 + 1 + 10 + 1 + 1 + 1 + 10 + 1
number = 26
Expand Down Expand Up @@ -1667,7 +1684,7 @@ def test_status(self):

# logger.debug(re.search(expected_regex, result).group(1).decode('utf-8'))

self.assertRegexpMatches(result, expected_regex)
self.assertRegex(result, expected_regex)

@unittest.skipUnless(
bareos.bsock.DirectorConsole.is_tls_psk_available(), "TLS-PSK is not available."
Expand Down Expand Up @@ -1714,7 +1731,7 @@ def test_execute_external_command(self):
)
)

self.assertRegexpMatches(result, expected_regex)
self.assertRegex(result, expected_regex)


class PythonBareosShowTest(PythonBareosJsonBase):
Expand Down

0 comments on commit 6c5d6db

Please sign in to comment.