Exemplo n.º 1
0
 def _check_cheese_removal(self, local_rpm_path: Path):
     parent_subvol = layer_resource_subvol(
         __package__,
         'test-with-one-local-rpm',
     )
     with TempSubvolumes(sys.argv[0]) as temp_subvolumes:
         # ensure cheese2 is installed in the parent from rpm-test-cheese-2-1
         assert os.path.isfile(parent_subvol.path('/rpm_test/cheese2.txt'))
         subvol = temp_subvolumes.snapshot(parent_subvol, 'remove_cheese')
         RpmActionItem.get_phase_builder(
             [
                 RpmActionItem(
                     from_target='t',
                     source=local_rpm_path,
                     action=RpmAction.remove_if_exists,
                 )
             ],
             self._opts(),
         )(subvol)
         subvol.run_as_root([
             'rm',
             '-rf',
             subvol.path('dev'),
             subvol.path('etc'),
             subvol.path('meta'),
             subvol.path('var'),
         ])
         self.assertEqual(
             [
                 '(Dir)',
                 {
                     # No more `rpm_test/cheese2.txt` here.
                 }
             ],
             render_subvol(subvol))
Exemplo n.º 2
0
 def _temp_resource_subvol(self, name: str):
     parent_sv = layer_resource_subvol(__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
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
 def test_clone_demo_sendstream(self):
     src_subvol = layer_resource_subvol(__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),
         )
Exemplo n.º 5
0
    def test_rpm_action_item_auto_downgrade(self):
        parent_subvol = layer_resource_subvol(
            __package__,
            'test-with-one-local-rpm',
        )
        src_rpm = Path(__file__).dirname() / "rpm-test-cheese-1-1.rpm"

        with TempSubvolumes(sys.argv[0]) as temp_subvolumes:
            # ensure cheese2 is installed in the parent from rpm-test-cheese-2-1
            assert os.path.isfile(parent_subvol.path('/rpm_test/cheese2.txt'))
            # make sure the RPM we are installing is older in order to
            # trigger the downgrade
            src_data = RpmMetadata.from_file(src_rpm)
            subvol_data = RpmMetadata.from_subvol(parent_subvol, src_data.name)
            assert compare_rpm_versions(src_data, subvol_data) < 0

            subvol = temp_subvolumes.snapshot(parent_subvol, 'rpm_action')
            RpmActionItem.get_phase_builder(
                [
                    RpmActionItem(
                        from_target='t',
                        source=src_rpm,
                        action=RpmAction.install,
                    )
                ],
                self._opts(),
            )(subvol)
            subvol.run_as_root([
                'rm',
                '-rf',
                subvol.path('dev'),
                subvol.path('etc'),
                subvol.path('meta'),
                subvol.path('var'),
            ])
            self.assertEqual([
                '(Dir)', {
                    'rpm_test': ['(Dir)', {
                        'cheese1.txt': ['(File d42)'],
                    }],
                }
            ], render_subvol(subvol))
Exemplo n.º 6
0
    def _test_rpm_action_item_install_local_setup(self):
        parent_subvol = layer_resource_subvol(__package__, 'test-with-no-rpm')
        local_rpm_path = Path(__file__).dirname() / 'rpm-test-cheese-2-1.rpm'
        with TempSubvolumes(sys.argv[0]) as temp_subvolumes:
            subvol = temp_subvolumes.snapshot(parent_subvol, 'add_cheese')

            RpmActionItem.get_phase_builder(
                [
                    RpmActionItem(
                        from_target='t',
                        source=local_rpm_path,
                        action=RpmAction.install,
                    )
                ],
                self._opts(),
            )(subvol)

            r = render_subvol(subvol)

            self.assertEqual(['(Dir)', {
                'cheese2.txt': ['(File d45)'],
            }], pop_path(r, 'rpm_test'))

            yield r
Exemplo n.º 7
0
from fs_image.compiler.requires_provides import (
    ProvidesDirectory,
    ProvidesDoNotAccess,
    ProvidesFile,
    require_directory,
)
from fs_image.tests.layer_resource import layer_resource_subvol
from fs_image.tests.temp_subvolumes import TempSubvolumes

from ..common import image_source_item
from ..clone import CloneItem

from .common import BaseItemTestCase, DUMMY_LAYER_OPTS, pop_path, render_subvol

_SRC_SUBVOL = layer_resource_subvol(__package__, 'src-layer')


class InstallFileItemTestCase(BaseItemTestCase):
    def _clone_item(
        self,
        src,
        dest,
        *,
        omit_outer_dir=False,
        pre_existing_dest=False,
        subvol=None,
    ):
        subvol = subvol or _SRC_SUBVOL
        # The dummy object works here because `subvolumes_dir` of `None`
        # runs `artifacts_dir` internally, while our "prod" path uses the
Exemplo n.º 8
0
 def test_rpm_action_item_build_appliance(self):
     self._check_rpm_action_item_build_appliance(
         layer_resource_subvol(
             __package__,
             'host-test-build-appliance',
         ))
Exemplo n.º 9
0
def _build_appliance() -> Subvol:
    return layer_resource_subvol(__package__, 'build-appliance')
Exemplo n.º 10
0
def get_dummy_layer_opts_ba():
    return DUMMY_LAYER_OPTS._replace(build_appliance=layer_resource_subvol(
        __package__,
        'host-test-build-appliance',
    ))