def _temp_resource_subvol(self, name: str): parent_sv = find_built_subvol(load_location(__package__, name)) with TempSubvolumes(sys.argv[0]) as temp_subvols: # Cannot use `.snapshot()` since that doesn't handle mounts. child_sv = temp_subvols.caller_will_create(name) ParentLayerItem.get_phase_builder([ ParentLayerItem(from_target='t', subvol=parent_sv), ], DUMMY_LAYER_OPTS)(child_sv) yield child_sv
def test_contents(self): self.maxDiff = None sv = find_built_subvol(load_location(__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 spec(self): format_kwargs = { **self._asdict(), 'quoted_contents': shlex.quote(f'{self.name} {self.version} {self.release}' if self. override_contents is None else self.override_contents), 'quoted_busybox_path': shlex.quote(load_location('rpm', 'busybox-path')) } common_spec = textwrap.dedent('''\ Summary: The "{name}" package. Name: rpm-test-{name} Version: {version} Release: {release} License: BSD Group: Facebook/Script Vendor: Facebook, Inc. Packager: [email protected] %description %install mkdir -p "$RPM_BUILD_ROOT"/usr/share/rpm_test echo {quoted_contents} > "$RPM_BUILD_ROOT"/usr/share/rpm_test/{name}.txt mkdir -p "$RPM_BUILD_ROOT"/bin ''').format(**format_kwargs) return common_spec + textwrap.dedent(('''\ %files /usr/share/rpm_test/{name}.txt ''') if not self.test_post_install else ( '''\ cp {quoted_busybox_path} "$RPM_BUILD_ROOT"/bin/sh %post ''' # yum-from-snapshot prepares /dev in a subtle way to protect host # system from side-effects of rpm post-install scripts. The command # below lets us test that /dev/null is prepared properly: if # "echo > /dev/null" fails, tests will catch the absence of post.txt '''\ echo > /dev/null && echo 'stuff' > \ "$RPM_BUILD_ROOT"/usr/share/rpm_test/post.txt %files /bin/sh /usr/share/rpm_test/{name}.txt ''')).format(**format_kwargs)
def yum_from_test_snapshot( install_root: AnyStr, protected_paths: List[AnyStr], yum_args: List[AnyStr], ): snapshot_dir = Path(load_location('rpm', 'repo-snapshot')) yum_from_snapshot( storage_cfg=json.dumps({ 'key': 'test', 'kind': 'filesystem', 'base_dir': (snapshot_dir / 'storage').decode(), }), snapshot_dir=snapshot_dir / 'repos', install_root=Path(install_root), protected_paths=protected_paths, yum_args=yum_args, )
def test_clone_demo_sendstream(self): src_subvol = find_built_subvol(load_location(__package__, 'create_ops')) ci = self._clone_item( '/', '/', omit_outer_dir=True, pre_existing_dest=True, subvol=src_subvol, ) self.assertEqual({require_directory('/')}, set(ci.requires())) self.assertGreater(len(set(ci.provides())), 1) with TempSubvolumes(sys.argv[0]) as temp_subvols: dest_subvol = temp_subvols.create('create_ops') ci.build(dest_subvol, DUMMY_LAYER_OPTS) self.assertEqual( render_subvol(src_subvol), render_subvol(dest_subvol), )
def _subvol_from_resource(cls, module, name): return find_built_subvol(load_location(module, name))
def get_dummy_layer_opts_ba(): return DUMMY_LAYER_OPTS._replace( build_appliance=find_built_subvol(load_location( __package__, 'host-test-build-appliance', )) )
def _build_appliance() -> Subvol: return find_built_subvol(load_location(__package__, 'build-appliance'))
def setUpClass(cls): cls.src_layer = find_built_subvol( load_location(__package__, 'src-layer'))