示例#1
0
    def test_checkRemoteFolder_fail_can_not_create(self):
        ssh = sshtools.SSH(cfg = self.cfg)

        #can not create path
        with generic.mockPermissions(self.tmpDir.name, stat.S_IRUSR | stat.S_IXUSR):
            with self.assertRaisesRegex(MountException, r"Couldn't create remote path.+"):
                ssh.checkRemoteFolder()
示例#2
0
    def test_takeSnapshot_error_without_continue(self, sleep):
        with generic.mockPermissions(os.path.join(self.include.name, 'test')):
            self.cfg.setContinueOnErrors(False)
            now = datetime.today()
            sid1 = snapshots.SID(now, self.cfg)

            self.assertListEqual([False, True], self.sn.takeSnapshot(sid1, now, [(self.include.name, 0),]))
            self.assertFalse(sid1.exists())
    def test_takeSnapshot_fail_create_new_snapshot(self, sleep):
        with generic.mockPermissions(self.snapshotPath, 0o500):
            now = datetime.today()
            sid1 = snapshots.SID(now, self.cfg)

            self.assertListEqual([False, True],
                                 self.sn.takeSnapshot(sid1, now, [
                                     (self.include.name, 0),
                                 ]))
示例#4
0
    def test_checkRemoteFolder_fail_can_not_create(self):
        ssh = sshtools.SSH(cfg=self.cfg)

        #can not create path
        with generic.mockPermissions(self.tmpDir.name,
                                     stat.S_IRUSR | stat.S_IXUSR):
            with self.assertRaisesRegex(MountException,
                                        r"Couldn't create remote path.+"):
                ssh.checkRemoteFolder()
示例#5
0
    def test_checkRemoteFolder(self):
        ssh = sshtools.SSH(cfg = self.cfg)
        #create new directories
        ssh.checkRemoteFolder()
        self.assertIsDir(self.remotePath)

        #rerun check to test if it correctly recognize previous created folders
        ssh.checkRemoteFolder()

        #make folder read-only
        with generic.mockPermissions(self.remotePath, stat.S_IRUSR | stat.S_IXUSR):
            with self.assertRaisesRegex(MountException, r"Remote path is not writable.+"):
                ssh.checkRemoteFolder()

        #make folder not executable
        with generic.mockPermissions(self.remotePath, stat.S_IRUSR | stat.S_IWUSR):
            with self.assertRaisesRegex(MountException, r"Remote path is not executable.+"):
                ssh.checkRemoteFolder()
示例#6
0
    def test_fileInfoErrorRead(self, mock_logger):
        sid = snapshots.SID('20151219-010324-123', self.cfg)
        os.makedirs(os.path.join(self.snapshotPath, '20151219-010324-123'))
        infoFile = sid.path(sid.FILEINFO)
        # remove all permissions from file
        with open(infoFile, 'wt') as f:
            pass

        with generic.mockPermissions(infoFile):
            self.assertEqual(sid.fileInfo, snapshots.FileInfoDict())
            self.assertTrue(mock_logger.called)
    def test_takeSnapshot_error_without_continue(self, sleep):
        with generic.mockPermissions(os.path.join(self.include.name, 'test')):
            self.cfg.setContinueOnErrors(False)
            now = datetime.today()
            sid1 = snapshots.SID(now, self.cfg)

            self.assertListEqual([False, True],
                                 self.sn.takeSnapshot(sid1, now, [
                                     (self.include.name, 0),
                                 ]))
            self.assertFalse(sid1.exists())
示例#8
0
    def test_checkRemoteFolder(self):
        ssh = sshtools.SSH(cfg=self.cfg)
        #create new directories
        ssh.checkRemoteFolder()
        self.assertIsDir(self.remotePath)

        #rerun check to test if it correctly recognize previous created folders
        ssh.checkRemoteFolder()

        #make folder read-only
        with generic.mockPermissions(self.remotePath,
                                     stat.S_IRUSR | stat.S_IXUSR):
            with self.assertRaisesRegex(MountException,
                                        r"Remote path is not writable.+"):
                ssh.checkRemoteFolder()

        #make folder not executable
        with generic.mockPermissions(self.remotePath,
                                     stat.S_IRUSR | stat.S_IWUSR):
            with self.assertRaisesRegex(MountException,
                                        r"Remote path is not executable.+"):
                ssh.checkRemoteFolder()
示例#9
0
    def test_fileInfoErrorWrite(self, mock_logger):
        sid = snapshots.SID('20151219-010324-123', self.cfg)
        os.makedirs(os.path.join(self.snapshotPath, '20151219-010324-123'))
        infoFile = sid.path(sid.FILEINFO)
        # remove all permissions from file
        with open(infoFile, 'wt') as f:
            pass

        with generic.mockPermissions(infoFile):
            d = snapshots.FileInfoDict()
            d[b'/tmp']     = (123, b'foo', b'bar')
            d[b'/tmp/foo'] = (456, b'asdf', b'qwer')
            sid.fileInfo = d
            self.assertTrue(mock_logger.called)
示例#10
0
    def test_takeSnapshot_error(self, sleep):
        with generic.mockPermissions(os.path.join(self.include.name, 'test')):
            now = datetime.today()
            sid1 = snapshots.SID(now, self.cfg)

            self.assertListEqual([True, True], self.sn.takeSnapshot(sid1, now, [(self.include.name, 0),]))
            self.assertTrue(sid1.exists())
            self.assertTrue(sid1.canOpenPath(os.path.join(self.include.name, 'foo', 'bar', 'baz')))
            self.assertFalse(sid1.canOpenPath(os.path.join(self.include.name, 'test')))
            for f in ('config',
                      'fileinfo.bz2',
                      'info',
                      'takesnapshot.log.bz2',
                      'failed'):
                self.assertExists(sid1.path(f))
            self.assertNotExists(self.cfg.anacronSpoolFile())
    def test_takeSnapshot_error(self, sleep):
        with generic.mockPermissions(os.path.join(self.include.name, 'test')):
            now = datetime.today()
            sid1 = snapshots.SID(now, self.cfg)

            self.assertListEqual([True, True],
                                 self.sn.takeSnapshot(sid1, now, [
                                     (self.include.name, 0),
                                 ]))
            self.assertTrue(sid1.exists())
            self.assertTrue(
                sid1.canOpenPath(
                    os.path.join(self.include.name, 'foo', 'bar', 'baz')))
            self.assertFalse(
                sid1.canOpenPath(os.path.join(self.include.name, 'test')))
            for f in ('config', 'fileinfo.bz2', 'info', 'takesnapshot.log.bz2',
                      'failed'):
                self.assertExists(sid1.path(f))
            self.assertNotExists(self.cfg.anacronSpoolFile())
示例#12
0
 def test_set_snapshots_path_fails_on_ro(self):
     with TemporaryDirectory() as dirpath:
         # set directory to read only
         with generic.mockPermissions(
                 dirpath, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH):
             self.assertFalse(self.cfg.setSnapshotsPath(dirpath))
示例#13
0
    def test_takeSnapshot_fail_create_new_snapshot(self, sleep):
        with generic.mockPermissions(self.snapshotPath, 0o500):
            now = datetime.today()
            sid1 = snapshots.SID(now, self.cfg)

            self.assertListEqual([False, True], self.sn.takeSnapshot(sid1, now, [(self.include.name, 0),]))
示例#14
0
 def test_set_snapshots_path_fails_on_ro(self):
     with TemporaryDirectory() as dirpath:
         # set directory to read only
         with generic.mockPermissions(dirpath, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH):
             self.assertFalse(self.cfg.setSnapshotsPath(dirpath))