示例#1
0
    def test_write_to_tarball(self, temp_subvols):
        # create a subvol from a demo sendstream, tar it, untar into a new
        # subvol, then compare the two
        demo_sv_name = 'demo_sv'
        demo_sv = temp_subvols.caller_will_create(demo_sv_name)
        with open(Path(__file__).dirname() / 'create_ops.sendstream') as f, \
                demo_sv.receive(f):
            pass

        unpacked_sv = temp_subvols.create('subvol')
        with tempfile.NamedTemporaryFile() as tar_file:
            with demo_sv.write_tarball_to_file(tar_file):
                pass

            demo_sv.run_as_root([
                'tar',
                'xf',
                tar_file.name,
                '--xattrs',
                '-C',
                unpacked_sv.path(),
            ])

        demo_render = render_demo_as_corrupted_by_gnu_tar(
            create_ops=demo_sv_name)

        self.assertEqual(
            demo_render,
            render_sendstream(unpacked_sv.mark_readonly_and_get_sendstream()),
        )
示例#2
0
def _render_sendstream_path(path):
    if path.endswith('.zst'):
        data = subprocess.check_output(
            ['zstd', '--decompress', '--stdout', path])
    else:
        with open(path, 'rb') as infile:
            data = infile.read()
    return render_sendstream(data)
 def test_check_layers(self):
     meta = {'meta': ['(Dir)', {'private': ['(Dir)', {'opts': ['(Dir)', {
         'artifacts_may_require_repo': ['(File d2)'],
     }]}]}]}
     # The parent has a couple of directories.
     self.assertEqual(
         ['(Dir)', {'a': ['(Dir)', {'b': ['(Dir)', {}]}], **meta}],
         render_sendstream(find_built_subvol(
             self._resource_path('parent')
         ).mark_readonly_and_get_sendstream()),
     )
     # The child is near-empty because the `remove_paths` cleaned it up.
     self.assertEqual(
         ['(Dir)', {**meta}],
         render_sendstream(find_built_subvol(
             self._resource_path('child')
         ).mark_readonly_and_get_sendstream()),
     )
示例#4
0
 def test_receive(self, temp_subvols):
     new_subvol_name = 'differs_from_create_ops'
     sv = temp_subvols.caller_will_create(new_subvol_name)
     with open(Path(__file__).dirname() / 'create_ops.sendstream') as f, \
             sv.receive(f):
         pass
     self.assertEqual(
         render_demo_subvols(create_ops=new_subvol_name),
         render_sendstream(sv.mark_readonly_and_get_sendstream()),
     )
示例#5
0
def render_subvol(subvol: {'Subvol'}):
    # Determine the original ro/rw state of the subvol so we can put it back
    # the way it was after rendering.
    was_readonly = subvol.run_as_root([
        'btrfs', 'property', 'get', '-ts', subvol.path(), 'ro'
    ], text=True, stdout=subprocess.PIPE).stdout.strip() == 'ro=true'

    rendered = render_sendstream(subvol.mark_readonly_and_get_sendstream())
    subvol.set_readonly(was_readonly)
    return rendered
    def test_contents(self):
        self.maxDiff = None
        sv = layer_resource_subvol(__package__, 'install-toy-rpm')
        r = render_sendstream(sv.mark_readonly_and_get_sendstream())

        self.assertEqual([
            '(Dir)', {'bin': ['(Dir)', {'toy_src_file': ['(File m755 d40)']}]}
        ], pop_path(r, 'usr'))

        check_common_rpm_render(self, r, 'yum')
 def test_receive_sendstream(self):
     item = ReceiveSendstreamItem(
         from_target='t',
         source=Path(__file__).dirname() / 'create_ops.sendstream',
     )
     self.assertEqual(PhaseOrder.MAKE_SUBVOL, item.phase_order())
     with TempSubvolumes(sys.argv[0]) as temp_subvolumes:
         new_subvol_name = 'differs_from_create_ops'
         subvol = temp_subvolumes.caller_will_create(new_subvol_name)
         item.get_phase_builder([item], DUMMY_LAYER_OPTS)(subvol)
         self.assertEqual(
             render_demo_subvols(create_ops=new_subvol_name),
             render_sendstream(subvol.mark_readonly_and_get_sendstream()),
         )
def _render_subvol(subvol: {'Subvol'}):
    rendered = render_sendstream(subvol.mark_readonly_and_get_sendstream())
    subvol.set_readonly(False)  # YES, all our subvolumes are read-write.
    return rendered