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 30, 2020
1 parent 8ae9ba7 commit 3686c1e
Showing 1 changed file with 46 additions and 29 deletions.
75 changes: 46 additions & 29 deletions systemtests/tests/python-bareos-test/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 @@ -1192,8 +1207,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 @@ -1466,7 +1483,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 @@ -1513,7 +1530,7 @@ def test_execute_external_command(self):
)
)

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


def get_env():
Expand Down

0 comments on commit 3686c1e

Please sign in to comment.