예제 #1
0
    def test_specific_target(self, INotifyRecursive, SyncWorker):
        INotifyRecursive.return_value = FakeINotify(events={
            Event(wd=1, mask=flags.CREATE, cookie=None, name="hello.txt"),
            Event(wd=2, mask=flags.CREATE, cookie=None, name="bar.txt"),
        },
                                                    wd_map={
                                                        1: '/home/jon/code/',
                                                        2:
                                                        '/home/jon/code/hoot',
                                                    })

        args = argparse.Namespace(targets=['foo'],
                                  conflicts='ignore',
                                  read_delay=0)
        config = {
            'targets': {
                'foo': {
                    'local_folder': '/home/jon/code',
                    's3_uri': 's3://bucket/code',
                    'aws_secret_access_key': '23232323',
                    'aws_access_key_id': '########',
                    'region_name': 'eu-west-2',
                },
                'bar': {},
            }
        }
        cli.daemon_command(args,
                           config,
                           create_logger(),
                           terminator=self.single_term)

        assert SyncWorker.call_count == 2
        assert INotifyRecursive.call_count == 1
예제 #2
0
    def test_specific_target(self, INotifyRecursive, SyncWorker):
        INotifyRecursive.return_value = FakeINotify(
            events={
                Event(wd=1, mask=flags.CREATE, cookie=None, name="hello.txt"),
                Event(wd=2, mask=flags.CREATE, cookie=None, name="bar.txt"),
            },
            wd_map={
                1: "/home/jon/code/",
                2: "/home/jon/code/hoot"
            },
        )

        args = argparse.Namespace(targets=["foo"],
                                  conflicts="ignore",
                                  read_delay=0)
        config = {
            "targets": {
                "foo": {
                    "local_folder": "/home/jon/code",
                    "s3_uri": "s3://bucket/code",
                    "aws_secret_access_key": "23232323",
                    "aws_access_key_id": "########",
                    "region_name": "eu-west-2",
                },
                "bar": {},
            }
        }
        command = DaemonCommand(args, config, create_logger())
        command.run(terminator=self.single_term)

        assert SyncWorker.call_count == 2
        assert INotifyRecursive.call_count == 1
예제 #3
0
    def check_subfolders(self, watch_descriptor: int, all_events: List[Event]):
        """Summary

        Args:
            watch_descriptor (int): Description
            all_events (List[Event]): Description

        Returns:
            List[Event]: Description
        """
        for root, folders, files in os.walk(
                self.directories[watch_descriptor]):
            for folder in folders:
                watch_descriptor = self.inotify.add_watch(
                    os.path.join(root, folder), self.watched_flags)
                self.directories[watch_descriptor] = os.path.join(root, folder)
                self.watch_descriptors[
                    self.directories[watch_descriptor]] = watch_descriptor
            for file in files:
                all_events += [
                    Event(wd=self.watch_descriptors[root],
                          mask=256,
                          cookie=0,
                          name=file)
                ]
                logger.info(f"Adding untracked event for file : {root}/{file}")
        return all_events
예제 #4
0
def test_non_write_ignored(process_mock, upload_file, inotify_mock, copy2):
    process = process_mock.return_value
    inotify = inotify_mock.return_value

    inotify.add_watch.return_value = 1
    mask = flags.CREATE
    for flag in flags:
        if flag is not flags.CLOSE_WRITE and flag is not flags.ISDIR:
            mask = mask | flag
    inotify.read.return_value = [Event(1, mask, 'cookie', 'file_name')]

    def watch():
        call = process_mock.call_args
        args, kwargs = call
        _intermediate_output._watch(kwargs['args'][0], kwargs['args'][1],
                                    kwargs['args'][2], kwargs['args'][3])

    process.start.side_effect = watch

    _files.write_success_file()
    _intermediate_output.start_sync(S3_BUCKET, REGION)

    inotify.add_watch.assert_called()
    inotify.read.assert_called()
    copy2.assert_not_called()
    upload_file.assert_not_called()
예제 #5
0
def test_new_folders_are_watched(process_mock, upload_file, inotify_mock, copy2):
    process = process_mock.return_value
    inotify = inotify_mock.return_value

    new_dir = 'new_dir'
    new_dir_path = os.path.join(_env.output_intermediate_dir, new_dir)
    inotify.add_watch.return_value = 1
    inotify.read.return_value = [Event(1, flags.CREATE | flags.ISDIR, 'cookie', new_dir)]

    def watch():
        os.makedirs(new_dir_path)

        call = process_mock.call_args
        args, kwargs = call
        _intermediate_output._watch(kwargs['args'][0], kwargs['args'][1],
                                    kwargs['args'][2], kwargs['args'][3])

    process.start.side_effect = watch

    _files.write_success_file()
    _intermediate_output.start_sync(S3_BUCKET, REGION)

    watch_flags = flags.CLOSE_WRITE | flags.CREATE
    inotify.add_watch.assert_any_call(_env.output_intermediate_dir, watch_flags)
    inotify.add_watch.assert_any_call(new_dir_path, watch_flags)
    inotify.read.assert_called()
    copy2.assert_not_called()
    upload_file.assert_not_called()
def test_modification_triggers_upload(process_mock, upload_file, inotify_mock,
                                      copy2):
    process = process_mock.return_value
    inotify = inotify_mock.return_value

    inotify.add_watch.return_value = 'wd'
    inotify.read.return_value = [
        Event('wd', flags.CLOSE_WRITE, 'cookie', 'file_name')
    ]

    def watch():
        call = process_mock.call_args
        args, kwargs = call
        _intermediate_output._watch(kwargs['args'][0], kwargs['args'][1],
                                    kwargs['args'][2], kwargs['args'][3])

    process.start.side_effect = watch

    _files.write_success_file()
    _intermediate_output.start_sync(S3_BUCKET, REGION)

    inotify.add_watch.assert_called()
    inotify.read.assert_called()
    copy2.assert_called()
    upload_file.assert_called()