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']
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_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_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']
def update(ctx, img_dir, streams_dir): logger.info('Updating server') images = Images(str(Path(streams_dir).resolve()), rebuild=True) # Generate a fake event to update all tree fake_events = [(None, ['IN_ISDIR', 'IN_CREATE'], str(img_dir.parent), str(img_dir.name))] operations = Operations(fake_events, str(img_dir)) images.update(operations.ops) images.save() logger.info('Server updated')
def update_metadata(img_dir, streams_dir): MirrorManager.img_dir = img_dir MirrorManager.update_mirror_list() while True: events = event_queue.get() ops = Operations(events, str(Path(img_dir).resolve())) if ops: logger.info('Updating server: %s', ','.join(str(x) for x in ops.ops)) images = Images(str(Path(streams_dir).resolve()), logger=logger) images.update(ops.ops) images.save() MirrorManager.update() logger.info('Server updated')