def test_move_files(self, mock_index):
        with tempfile.TemporaryDirectory() as tmpdir:
            work_dir = self._generate_files('20180620_12:28', tmpdir)

            with open(str(Path(tmpdir, 'images.json')), 'w') as image_file:
                json.dump(INDEX, image_file)

            new_index = copy.deepcopy(INDEX)
            new_index['products']['ubuntu:xenial:amd64:default'][
                'versions'].update(EXTRA)
            del new_index['products']['ubuntu:xenial:amd64:default'][
                'versions']['20180620_12:18']
            images = Images(tmpdir)
            images.update([
                Operation(
                    str(Path(work_dir).parent / '20180620_12:18'),
                    OperationType.DELETE,
                    tmpdir),
                Operation(
                    str(Path(work_dir).parent / '20180620_12:28'),
                    OperationType.ADD_MOD,
                    tmpdir)
            ])
            assert '20180620_12:28' in images.root['products'][
                'ubuntu:xenial:amd64:default']['versions']
            assert '20180620_12:18' not in images.root['products'][
                'ubuntu:xenial:amd64:default']['versions']
Example #2
0
    def test_move_root(self, mock_index):
        with tempfile.TemporaryDirectory() as tmpdir:
            work_dir = self._generate_files('20180620_12:18', tmpdir)
            other_dir = os.path.join(tmpdir, 'ubuntu', 'focal', 'amd64',
                                     'other')
            shutil.move(str(Path(work_dir).parent), other_dir)

            with open(str(Path(tmpdir, 'images.json')), 'w') as image_file:
                json.dump(INDEX, image_file)

            images = Images(tmpdir)
            images.update([
                Operation(str(Path(other_dir, '20180620_12:18')),
                          OperationType.ADD_MOD, tmpdir),
                Operation(str(Path(work_dir).parent), OperationType.DELETE,
                          tmpdir, True)
            ])
            assert 'ubuntu:focal:amd64:default' not in images.root['products']
            assert 'ubuntu:focal:amd64:other' in images.root['products']
 def test_move_root(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
         path = str(Path(tmpdir, 'iats/focal/amd64/default'))
         other_path = str(
             Path(tmpdir, 'iats/focal/amd64/other/20210430_12:00'))
         os.makedirs(other_path)
         Path(other_path, 'lxd.tar.xz').touch()
         Path(other_path, 'rootfs.squashfs').touch()
         events = [(None, ['IN_ISDIR', 'IN_MOVED_FROM'],
                    str(Path(path).parent), 'default'),
                   (None, ['IN_ISDIR', 'IN_MOVED_TO'],
                    str(Path(other_path).parent.parent), 'other')]
         operations = Operations(events, tmpdir)
         assert len(operations.ops) == 2
         assert any(
             Operation(path, OperationType.DELETE, tmpdir) == k
             for k in operations.ops)
         assert any(
             Operation(other_path, OperationType.ADD_MOD, tmpdir) == k
             for k in operations.ops)
 def test_add_all(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
         path = str(Path(tmpdir, 'iats/focal/amd64/default/20210430_12:00'))
         os.makedirs(path)
         Path(path, 'lxd.tar.xz').touch()
         Path(path, 'rootfs.squashfs').touch()
         events = [(None, ['IN_ISDIR',
                           'IN_CREATE'], '/tmp', str(Path(tmpdir).name))]
         operations = Operations(events, '/tmp')
         assert len(operations.ops) == 1
         assert any(
             Operation(path, OperationType.ADD_MOD, tmpdir) == k
             for k in operations.ops)
 def test_move_one_file_from(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
         path = str(Path(tmpdir, 'iats/focal/amd64/default/20210430_12:00'))
         os.makedirs(path)
         Path(path, 'lxd.tar.xz').touch()
         events = [
             (None, ['IN_MOVED_FROM'], path, 'rootfs.squashfs'),
         ]
         operations = Operations(events, tmpdir)
         assert len(operations.ops) == 1
         assert any(
             Operation(path, OperationType.ADD_MOD, tmpdir) == k
             for k in operations.ops)
 def test_remove_only_files(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
         path = str(Path(tmpdir, 'iats/focal/amd64/default'))
         os.makedirs(path)
         events = [(None, ['IN_DELETE'], path + '/20210430_12:00',
                    'lxd.tar.xz'),
                   (None, ['IN_DELETE'], path + '/20210430_12:00',
                    'rootfs.squashfs')]
         operations = Operations(events, tmpdir)
         assert len(operations.ops) == 1
         assert any(
             Operation(path +
                       '/20210430_12:00', OperationType.DELETE, tmpdir) == k
             for k in operations.ops)
 def test_move_empty(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
         path = str(Path(tmpdir, 'iats/focal/amd64/default'))
         other_path = str(Path(tmpdir, 'iats/focal/amd64/other'))
         os.makedirs(other_path)
         events = [(None, ['IN_ISDIR', 'IN_MOVED_FROM'],
                    str(Path(path).parent), 'default'),
                   (None, ['IN_ISDIR', 'IN_MOVED_TO'],
                    str(Path(other_path).parent), 'other')]
         operations = Operations(events, tmpdir)
         assert len(operations.ops) == 1
         assert any(
             Operation(path, OperationType.DELETE, tmpdir) == k
             for k in operations.ops)
 def test_delete_root(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
         path = str(Path(tmpdir, 'iats/focal/amd64/default/20210430_12:00'))
         events = [(None, ['IN_DELETE'], path, 'lxd.tar.xz'),
                   (None, ['IN_DELETE'], path, 'rootfs.squashfs'),
                   (None, ['IN_ISDIR', 'IN_DELETE'], str(Path(path).parent),
                    '20210430_12:00'),
                   (None, ['IN_ISDIR', 'IN_DELETE'],
                    str(Path(path).parent.parent), 'default')]
         operations = Operations(events, tmpdir)
         assert len(operations.ops) == 1
         assert any(
             Operation(path, OperationType.DELETE, tmpdir) == k
             for k in operations.ops)
Example #9
0
    def test_delete_files(self, mock_index):
        with tempfile.TemporaryDirectory() as tmpdir:
            work_dir = self._generate_files('20180620_12:18', tmpdir)
            new_index = copy.deepcopy(INDEX)
            new_index['products']['ubuntu:focal:amd64:default'][
                'versions'].update(EXTRA)
            with open(str(Path(tmpdir, 'images.json')), 'w') as image_file:
                json.dump(new_index, image_file)

            images = Images(tmpdir)
            images.update([
                Operation(str(Path(work_dir).parent / '20180620_12:28'),
                          OperationType.ADD_MOD, tmpdir)
            ])
            assert_that(images.root, is_(equal_to(INDEX)))
 def test_add_files(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
         path = str(Path(tmpdir,
                         'iats/xenial/amd64/default/20180710_12:00'))
         os.makedirs(path)
         Path(path, 'lxd.tar.xz').touch()
         Path(path, 'rootfs.squashfs').touch()
         events = [(None, ['IN_ISDIR', 'IN_CREATE'], str(Path(path).parent),
                    '20180710_12:00'),
                   (None, ['IN_CLOSE_WRITE'], path, 'lxd.tar.xz'),
                   (None, ['IN_CLOSE_WRITE'], path, 'rootfs.squashfs')]
         operations = Operations(events, tmpdir)
         assert len(operations.ops) == 1
         assert any(
             Operation(path, OperationType.ADD_MOD, tmpdir) == k
             for k in operations.ops)
Example #11
0
    def test_add_files(self, index_mock):
        with tempfile.TemporaryDirectory() as tmpdir:
            self._generate_files('20180620_12:18', tmpdir)
            extra_dir = self._generate_files('20180620_12:28', tmpdir)
            new_index = copy.deepcopy(INDEX)
            new_index['products']['ubuntu:focal:amd64:default'][
                'versions'].update(EXTRA)

            with open(str(Path(tmpdir, 'images.json')), 'w') as image_file:
                json.dump(INDEX, image_file)

            images = Images(tmpdir)
            images.update(
                [Operation(extra_dir, OperationType.ADD_MOD, tmpdir)])

            assert '20180620_12:28' in images.root['products'][
                'ubuntu:focal:amd64:default']['versions']
            assert '20180620_12:18' in images.root['products'][
                'ubuntu:focal:amd64:default']['versions']