Skip to content

Commit

Permalink
systemtest python-bareos: adapted for show command in JSON mode
Browse files Browse the repository at this point in the history
Skip the test "test_json_backend_with_invalid_json_output",
as most commands now produce valid JSON output.

Add the test "PythonBareosShowTest.test_fileset" to check,
if a fileset content is written correctly into the catalog.

Add the test PythonBareosJsonConfigTest.test_show_command.
Verifies that the "show" command delivers valid JSON.
  • Loading branch information
joergsteffens committed Aug 27, 2020
1 parent 6764cf9 commit 9586741
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 12 deletions.
113 changes: 104 additions & 9 deletions systemtests/tests/python-bareos/python-bareos-unittest.py
Expand Up @@ -72,7 +72,7 @@ def get_operator_password(self, username=None):

class PythonBareosModuleTest(PythonBareosBase):
def versiontuple(self, versionstring):
version, separator, suffix = versionstring.partition('~')
version, separator, suffix = versionstring.partition("~")
return tuple(map(int, (version.split("."))))

def test_exception_connection_error(self):
Expand Down Expand Up @@ -623,14 +623,14 @@ def run_job(self, director, jobname, level=None, wait=False):
if wait:
result = director.call("wait jobid={}".format(jobId))
# "result": {
# "Job": {
# "job": {
# "jobid": 1,
# "jobstatuslong": "OK",
# "jobstatus": "T",
# "exitstatus": 0
# }
# }
self.assertEqual(result["Job"]["jobstatuslong"], u"OK")
self.assertEqual(result["job"]["jobstatuslong"], u"OK")

return jobId

Expand Down Expand Up @@ -775,9 +775,19 @@ def test_json_whoami(self):
logger.debug(str(result))
self.assertEqual(username, result["whoami"])

def test_json_backend_without_json_input(self):
@unittest.skip("Most commands do return valid JSON")
def test_json_backend_with_invalid_json_output(self):
logger = logging.getLogger()

# This command sends additional plain (none JSON) output.
# Therefore the result is not valid JSON.
# Used "show clients" earlier,
# however, this now produces valid output.
# Commands like 'status storage' (and 'status client') only produces empty output.
# The "messages" command shows plain outout in JSON mode,
# but only if there are pending messages.
bcmd = "show clients"

username = self.get_operator_username()
password = self.get_operator_password(username)

Expand All @@ -788,7 +798,7 @@ def test_json_backend_without_json_input(self):
password=password,
)

result = director_plain.call("show clients")
result = director_plain.call(bcmd)
logger.debug(str(result))

director_json = bareos.bsock.DirectorConsoleJson(
Expand All @@ -798,16 +808,14 @@ def test_json_backend_without_json_input(self):
password=password,
)

# The 'show' command does not deliver JSON output.

# The JsonRpcInvalidJsonReceivedException
# is inherited from JsonRpcErrorReceivedException,
# so both exceptions could by tried.
with self.assertRaises(bareos.exceptions.JsonRpcInvalidJsonReceivedException):
result = director_json.call("show clients")
result = director_json.call(bcmd)

with self.assertRaises(bareos.exceptions.JsonRpcErrorReceivedException):
result = director_json.call("show clients")
result = director_json.call(bcmd)

def test_json_no_api_command(self):
"""
Expand Down Expand Up @@ -1332,6 +1340,58 @@ def test_admin_runscript_client(self):
)


class PythonBareosJsonConfigTest(PythonBareosJsonBase):
def test_show_command(self):
"""
Verify, that the "show" command delivers valid JSON.
If the JSON is not valid, the "call" command would raise an exception.
"""
logger = logging.getLogger()

username = self.get_operator_username()
password = self.get_operator_password(username)

director = bareos.bsock.DirectorConsoleJson(
address=self.director_address,
port=self.director_port,
name=username,
password=password,
)

resourcesname = "clients"
newclient = "test-client-fd"
newpassword = "secret"

director.call("show all")

try:
os.remove("etc/bareos/bareos-dir.d/client/{}.conf".format(newclient))
director.call("reload")
except OSError:
pass

self.assertFalse(
self.check_resource(director, resourcesname, newclient),
u"Resource {} in {} already exists.".format(newclient, resourcesname),
)

with self.assertRaises(bareos.exceptions.JsonRpcErrorReceivedException):
director.call("show client={}".format(newclient))

self.configure_add(
director,
resourcesname,
newclient,
u"client={} password={} address=127.0.0.1".format(newclient, newpassword),
)

director.call("show all")
director.call("show all verbose")
result = director.call("show client={}".format(newclient))
logger.debug(str(result))
director.call("show client={} verbose".format(newclient))


class PythonBareosFiledaemonTest(PythonBareosBase):
@unittest.skipUnless(
bareos.bsock.DirectorConsole.is_tls_psk_available(), "TLS-PSK is not available."
Expand Down Expand Up @@ -1409,6 +1469,41 @@ def test_execute_external_command(self):
self.assertRegexpMatches(result, expected_regex)


class PythonBareosShowTest(PythonBareosJsonBase):
def test_fileset(self):
"""
Filesets are stored in the database,
as soon as a job using them did run.
We want to verify, that the catalog content is correct.
As comparing the full content is difficult,
we only check if the "Description" is stored in the catalog.
"""
logger = logging.getLogger()

username = self.get_operator_username()
password = self.get_operator_password(username)

jobname = u"backup-bareos-fd"

director = bareos.bsock.DirectorConsoleJson(
address=self.director_address,
port=self.director_port,
name=username,
password=password,
)

jobid = self.run_job(director, jobname, wait=True)
result = director.call("llist jobid={}".format(jobid))
fileset = result["jobs"][0]["fileset"]
result = director.call("list fileset jobid={} limit=1".format(jobid))
fileset_content_list = result["filesets"][0]["filesettext"]

result = director.call("show fileset={}".format(fileset))
fileset_show_description = result["fileset"][fileset]["description"]

self.assertIn(fileset_show_description, fileset_content_list)


def get_env():
"""
Get attributes as environment variables,
Expand Down
3 changes: 0 additions & 3 deletions systemtests/tests/python-bareos/testrunner
Expand Up @@ -2,9 +2,6 @@
set -e
set -u
#
# Run a simple backup
# then restore it.
#
TestName="$(basename "$(pwd)")"
export TestName

Expand Down

0 comments on commit 9586741

Please sign in to comment.