Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bareosfd_test.py « test « python « filed « plugins « src « core - github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0149f6a5e9e6f8f9f36c861608976e7c9bb14f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#   BAREOS - Backup Archiving REcovery Open Sourced
#
#   Copyright (C) 2020-2022 Bareos GmbH & Co. KG
#
#   This program is Free Software; you can redistribute it and/or
#   modify it under the terms of version three of the GNU Affero General Public
#   License as published by the Free Software Foundation and included
#   in the file LICENSE.
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#   Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
#   02110-1301, USA.

import unittest
import bareosfd
import time
import types

# print dir(bareosfd)
# print "bareosfd.bJobMessageType:", str( bareosfd.bJobMessageType)
# print "bareosfd.bVariable:", str( bareosfd.bVariable)
# print "bareosfd.bEventType:", str( bareosfd.bEventType)
# print "bareosfd.bFileType:", str( bareosfd.bFileType)
# print "bareosfd.CoreFunctions:", str( bareosfd.CoreFunctions)
# print "bareosfd.bIOPS:", str( bareosfd.bIOPS)
# print "bareosfd.bLevels:", str( bareosfd.bLevels)
# print "bareosfd.bRCs:", str( bareosfd.bRCs)
# print "bareosfd.bVariable:", str( bareosfd.bVariable)
# print "bareosfd.bcfs:", str( bareosfd.bcfs)


class TestBareosFd(unittest.TestCase):
    def test_ModuleDicts(self):
        # help (bareosfd)
        print(bareosfd.bCFs)
        print(bareosfd.CF_ERROR)

    #     print bCFs
    #     bEventType
    #     bFileType
    #     CoreFunctions
    #     bIOPS
    #     bJobMessageType
    #     bLevels
    #     bRCs
    #     bVariable

    # def test_bJobMessageType(self):
    #     # bareosfd.DebugMessage( bareosfd.bJobMessageType['M_INFO'], "This is a Job message")
    #     self.assertEqual(str(bareosfd.bJobMessageType), """{'M_MOUNT': 10L, 'M_SECURITY': 14L, 'M_DEBUG': 2L, 'M_WARNING': 5L, 'M_SAVED': 7L, 'M_TERM': 12L, 'M_ABORT': 1L, 'M_INFO': 6L, 'M_ERROR': 4L, 'M_FATAL': 3L, 'M_NOTSAVED': 8L, 'M_RESTORED': 13L, 'M_ERROR_TERM': 11L, 'M_ALERT': 15L, 'M_VOLMGMT': 16L, 'M_SKIPPED': 9L}"""
    # )

    # def test_SetValue(self):
    #     self.assertRaises(RuntimeError, bareosfd.SetValue, 2)

    # def test_DebugMessage(self):
    #     self.assertRaises(RuntimeError, bareosfd.DebugMessage, 100, "This is a debug message")

    def test_RestoreObject(self):
        test_RestoreObject = bareosfd.RestoreObject()
        self.assertEqual(
            'RestoreObject(object_name="", object="", plugin_name="<NULL>", object_type=0, object_len=0, object_full_len=0, object_index=0, object_compression=0, stream=0, jobid=0)',
            str(test_RestoreObject),
        )
        r2 = bareosfd.RestoreObject()
        r2.object_name = "this is a very long object name"
        r2.object = "123456780"
        # r2.plugin_name="this is a plugin name"
        r2.object_type = 3
        r2.object_len = 111111
        r2.object_full_len = 11111111
        r2.object_index = 1234
        r2.object_compression = 1
        r2.stream = 4
        r2.jobid = 123123
        print(r2)
        # self.assertEqual(
        #   'RestoreObject(object_name="this is a very long object name", object="", plugin_name="<NULL>", object_type=3, object_len=111111, object_full_len=11111111, object_index=1234, object_compression=1, stream=4, jobid=123123)',
        #    str(test_RestoreObject),
        # )

    def test_StatPacket(self):
        timestamp = time.time()
        test_StatPacket = bareosfd.StatPacket()

        # check that the initialization of timestamps from current time stamp works
        self.assertAlmostEqual(test_StatPacket.st_atime, timestamp, delta=1)
        self.assertAlmostEqual(test_StatPacket.st_mtime, timestamp, delta=1)
        self.assertAlmostEqual(test_StatPacket.st_ctime, timestamp, delta=1)

        # set fixed values for comparison
        test_StatPacket.st_atime = 999
        test_StatPacket.st_mtime = 1000
        test_StatPacket.st_ctime = 1001
        self.assertEqual(
            "StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=999, mtime=1000, ctime=1001, blksize=4096, blocks=1)",
            str(test_StatPacket),
        )
        sp2 = bareosfd.StatPacket(
            dev=0,
            ino=0,
            mode=0o0700,
            nlink=0,
            uid=0,
            gid=0,
            rdev=0,
            size=-1,
            atime=1,
            mtime=1,
            ctime=1,
            blksize=4096,
            blocks=1,
        )
        self.assertEqual(
            "StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1)",
            str(sp2),
        )

    def test_SavePacket(self):
        test_SavePacket = bareosfd.SavePacket(fname="testfilename")
        self.assertEqual(
            'SavePacket(fname="testfilename", link="", type=0, flags=<NULL>, no_read=0, portable=0, accurate_found=0, cmd="<NULL>", save_time=0, delta_seq=0, object_name="", object="", object_len=0, object_index=0)',
            str(test_SavePacket),
        )

    def test_RestorePacket(self):
        test_RestorePacket = bareosfd.RestorePacket()
        self.assertEqual(
            'RestorePacket(stream=0, data_stream=0, type=0, file_index=0, linkFI=0, uid=0, statp="<NULL>", attrEx="<NULL>", ofname="<NULL>", olname="<NULL>", where="<NULL>", RegexWhere="<NULL>", replace=0, create_status=0)',
            str(test_RestorePacket),
        )

    def test_IoPacket(self):
        test_IoPacket = bareosfd.IoPacket()
        self.assertEqual(
            'IoPacket(func=0, count=0, flags=0, mode=0000, buf="", fname="<NULL>", status=0, io_errno=0, lerror=0, whence=0, offset=0, win32=0, filedes=-1, do_io_in_core=0)',
            str(test_IoPacket),
        )
        test_IoPacket2 = bareosfd.IoPacket()
        test_IoPacket2.do_io_in_core=True;
        self.assertEqual(
            'IoPacket(func=0, count=0, flags=0, mode=0000, buf="", fname="<NULL>", status=0, io_errno=0, lerror=0, whence=0, offset=0, win32=0, filedes=-1, do_io_in_core=1)',
            str(test_IoPacket2),
        )

    def test_AclPacket(self):
        test_AclPacket = bareosfd.AclPacket()
        self.assertEqual('AclPacket(fname="<NULL>", content="")', str(test_AclPacket))

    def test_XattrPacket(self):
        test_XattrPacket = bareosfd.XattrPacket()
        self.assertEqual(
            'XattrPacket(fname="<NULL>", name="", value="")', str(test_XattrPacket)
        )


if __name__ == "__main__":
    unittest.main()