コード例 #1
0
    def write_vm_data_locally(
        x=dict_(
            keys=str_(of='abc123-', min_length=36, max_length=36),
            values=list_(of=int_(min=0, max=3000),
                         min_length=0, max_length=10),
            min_length=0, max_length=3
        ),
        data_length=int_(min=0, max=10)
    ):
        path = os.path.join(os.path.dirname(__file__),
                            '..', 'resources', 'vms', 'tmp')
        shutil.rmtree(path, True)
        os.mkdir(path)
        collector.write_vm_data_locally(path, x, data_length)
        files = os.listdir(path)

        result = {}
        for uuid in x.keys():
            file = os.path.join(path, uuid)
            with open(file, 'r') as f:
                result[uuid] = [int(a)
                                for a in f.read().strip().splitlines()]

        shutil.rmtree(path)

        assert set(files) == set(x.keys())
        for uuid, values in x.items():
            if data_length > 0:
                assert result[uuid] == values[-data_length:]
            else:
                assert result[uuid] == []
コード例 #2
0
    def write_vm_data_locally(x=dict_(keys=str_(of='abc123-',
                                                min_length=36,
                                                max_length=36),
                                      values=list_(of=int_(min=0, max=3000),
                                                   min_length=0,
                                                   max_length=10),
                                      min_length=0,
                                      max_length=3),
                              data_length=int_(min=0, max=10)):
        path = os.path.join(os.path.dirname(__file__), '..', 'resources',
                            'vms', 'tmp')
        shutil.rmtree(path, True)
        os.mkdir(path)
        collector.write_vm_data_locally(path, x, data_length)
        files = os.listdir(path)

        result = {}
        for uuid in x.keys():
            file = os.path.join(path, uuid)
            with open(file, 'r') as f:
                result[uuid] = [int(a) for a in f.read().strip().splitlines()]

        shutil.rmtree(path)

        assert set(files) == set(x.keys())
        for uuid, values in x.items():
            if data_length > 0:
                assert result[uuid] == values[-data_length:]
            else:
                assert result[uuid] == []
コード例 #3
0
    def get_local_vm_data(data=dict_(keys=str_(of='abc123-',
                                               min_length=36,
                                               max_length=36),
                                     values=list_(of=int_(min=1, max=3000),
                                                  min_length=0,
                                                  max_length=10),
                                     min_length=0,
                                     max_length=5)):
        path = os.path.join(os.path.dirname(__file__), '..', 'resources',
                            'vms', 'tmp')
        shutil.rmtree(path, True)
        os.mkdir(path)
        collector.write_vm_data_locally(path, data, 10)

        assert manager.get_local_vm_data(path) == data
        shutil.rmtree(path)
コード例 #4
0
    def get_local_vm_data(
        data=dict_(
            keys=str_(of='abc123-', min_length=36, max_length=36),
            values=list_(of=int_(min=1, max=3000),
                         min_length=0, max_length=10),
            min_length=0, max_length=5
        )
    ):
        path = os.path.join(os.path.dirname(__file__),
                            '..', 'resources', 'vms', 'tmp')
        shutil.rmtree(path, True)
        os.mkdir(path)
        collector.write_vm_data_locally(path, data, 10)

        assert manager.get_local_vm_data(path) == data
        shutil.rmtree(path)
コード例 #5
0
    def append_vm_data_locally(
        x=dict_(
            keys=str_(of='abc123-', min_length=36, max_length=36),
            values=tuple_(list_(of=int_(min=0, max=3000),
                                min_length=0, max_length=10),
                          int_(min=0, max=3000)),
            min_length=0, max_length=3
        ),
        data_length=int_(min=0, max=10)
    ):
        path = os.path.join(os.path.dirname(__file__),
                            '..', 'resources', 'vms', 'tmp')
        shutil.rmtree(path, True)
        os.mkdir(path)
        original_data = {}
        to_append = {}
        after_appending = {}
        for uuid, data in x.items():
            original_data[uuid] = data[0]
            to_append[uuid] = data[1]
            if data_length > 0:
                after_appending[uuid] = list(data[0])
                after_appending[uuid].append(data[1])
                after_appending[uuid] = after_appending[uuid][-data_length:]
            else:
                after_appending[uuid] = []

        collector.write_vm_data_locally(path, original_data, data_length)
        collector.append_vm_data_locally(path, to_append, data_length)

        files = os.listdir(path)

        result = {}
        for uuid in x.keys():
            file = os.path.join(path, uuid)
            with open(file, 'r') as f:
                result[uuid] = [int(a)
                                for a in f.read().strip().splitlines()]

        shutil.rmtree(path)

        assert set(files) == set(x.keys())
        for uuid in x.keys():
            assert result[uuid] == after_appending[uuid]
コード例 #6
0
    def append_vm_data_locally(x=dict_(keys=str_(of='abc123-',
                                                 min_length=36,
                                                 max_length=36),
                                       values=tuple_(
                                           list_(of=int_(min=0, max=3000),
                                                 min_length=0,
                                                 max_length=10),
                                           int_(min=0, max=3000)),
                                       min_length=0,
                                       max_length=3),
                               data_length=int_(min=0, max=10)):
        path = os.path.join(os.path.dirname(__file__), '..', 'resources',
                            'vms', 'tmp')
        shutil.rmtree(path, True)
        os.mkdir(path)
        original_data = {}
        to_append = {}
        after_appending = {}
        for uuid, data in x.items():
            original_data[uuid] = data[0]
            to_append[uuid] = data[1]
            if data_length > 0:
                after_appending[uuid] = list(data[0])
                after_appending[uuid].append(data[1])
                after_appending[uuid] = after_appending[uuid][-data_length:]
            else:
                after_appending[uuid] = []

        collector.write_vm_data_locally(path, original_data, data_length)
        collector.append_vm_data_locally(path, to_append, data_length)

        files = os.listdir(path)

        result = {}
        for uuid in x.keys():
            file = os.path.join(path, uuid)
            with open(file, 'r') as f:
                result[uuid] = [int(a) for a in f.read().strip().splitlines()]

        shutil.rmtree(path)

        assert set(files) == set(x.keys())
        for uuid in x.keys():
            assert result[uuid] == after_appending[uuid]