Exemple #1
0
    def test_cmd_uninstall(self):
        self.assertEqual(self.list_xar_dir_paths(), [])

        exec_path = xars._get_exec_path(self.sample_xar_dir_path)
        self.install_sample()
        self.assertTrue(exec_path.exists())
        self.assertEqual(self.list_xar_dir_paths(), [self.sample_xar_name])
        self.assertTrue(self.sample_xar_runner_script_path.exists())

        with self.using_shared(
                xars._get_ref_path(self.sample_xar_dir_path,
                                   self.sample_image_id)):
            xars.cmd_uninstall(self.sample_xar_name)
        self.assertFalse(exec_path.exists())
        self.assertEqual(self.list_xar_dir_paths(), [self.sample_xar_name])
        self.assertFalse(self.sample_xar_runner_script_path.exists())

        xars.cmd_uninstall(self.sample_xar_name)
        self.assertFalse(exec_path.exists())
        self.assertEqual(self.list_xar_dir_paths(), [])
        self.assertFalse(self.sample_xar_runner_script_path.exists())

        # Okay to remove non-existent xar.
        xars.cmd_uninstall(self.sample_xar_name)
        self.assertFalse(exec_path.exists())
        self.assertEqual(self.list_xar_dir_paths(), [])
        self.assertFalse(self.sample_xar_runner_script_path.exists())
Exemple #2
0
 def assert_present(current_image_id, image_ids):
     self.assertTrue(self.sample_xar_dir_path.exists())
     self.assertEqual(
         xars._get_exec_path(self.sample_xar_dir_path).resolve(),
         images.get_rootfs_path(
             images.get_image_dir_path(current_image_id)) /
         self.sample_exec_relpath,
     )
     self.assertEqual(self.list_ref_image_ids(), image_ids)
     self.assertTrue(self.sample_xar_runner_script_path.exists())
     self.assertEqual(
         images._get_ref_count(image_dir_path_1),
         2 if image_id_1 in image_ids else 1,
     )
     self.assertEqual(
         images._get_ref_count(image_dir_path_2),
         2 if image_id_2 in image_ids else 1,
     )
Exemple #3
0
    def test_cmd_exec(self, os_mock):
        with self.assertRaisesRegex(AssertionError, r'expect.*is_dir.*foo.sh'):
            xars.cmd_exec(self.sample_xar_name, [])
        os_mock.execv.assert_not_called()
        os_mock.execv.reset_mock()

        self.install_sample()
        exec_abspath = xars._get_exec_path(self.sample_xar_dir_path).resolve()

        xars.cmd_exec(self.sample_xar_name, ['1', '2', '3'])
        os_mock.execv.assert_called_once_with(
            str(exec_abspath), [self.sample_xar_name, '1', '2', '3'])
        os_mock.execv.reset_mock()

        with self.using_shared(
                xars._get_ref_path(self.sample_xar_dir_path,
                                   self.sample_image_id)):
            xars.cmd_uninstall(self.sample_xar_name)

        with self.assertRaisesRegex(AssertionError, r'expect.*exists.*foo.sh'):
            xars.cmd_exec(self.sample_xar_name, ['4', '5', '6'])
        os_mock.execv.assert_not_called()
        os_mock.execv.reset_mock()
Exemple #4
0
    def test_repo_layout(self):
        for actual, expect in (
            (
                xars._get_xars_repo_path(),
                bases.get_repo_path() / 'xars',
            ),
            (
                xars._get_xar_dir_path('foo.sh'),
                xars._get_xars_repo_path() / 'foo.sh',
            ),
            (
                xars._get_name(xars._get_xar_dir_path('foo.sh')),
                'foo.sh',
            ),
            (
                xars._get_deps_path(xars._get_xar_dir_path('foo.sh')),
                xars._get_xar_dir_path('foo.sh') / 'deps',
            ),
            (
                xars._get_ref_path(
                    xars._get_xar_dir_path('foo.sh'),
                    self.sample_image_id,
                ),
                xars._get_deps_path(xars._get_xar_dir_path('foo.sh')) /
                self.sample_image_id,
            ),
            (
                xars._get_exec_path(xars._get_xar_dir_path('foo.sh')),
                xars._get_xar_dir_path('foo.sh') / 'exec',
            ),
            (
                xars._get_image_rootfs_abspath(self.sample_image_id),
                images.get_rootfs_path(self.sample_image_dir_path),
            ),
            (
                xars._get_xar_runner_script_path('foo.sh'),
                self.xar_runner_script_dir_path / 'foo.sh',
            ),
        ):
            self.assertEqual(actual, expect)

        exec_abspath = xars._get_exec_path(self.sample_xar_dir_path).absolute()
        with self.assertRaisesRegex(ValueError, r' does not start with '):
            xars._get_exec_relpath(exec_abspath, self.sample_image_id)
        with self.assertRaisesRegex(ValueError, r' does not start with '):
            xars._get_image_id(exec_abspath)

        self.install_sample()

        exec_abspath = xars._get_exec_path(self.sample_xar_dir_path).resolve()
        self.assertEqual(
            xars._get_exec_relpath(exec_abspath, self.sample_image_id),
            self.sample_exec_relpath,
        )
        self.assertEqual(
            xars._get_image_id(exec_abspath),
            self.sample_image_id,
        )
        exec_target = xars._get_exec_target(self.sample_image_id,
                                            self.sample_exec_relpath)
        self.assertEqual(
            exec_target,
            Path('../../images/trees') / self.sample_image_id / 'rootfs' /
            self.sample_exec_relpath,
        )
        self.assertTrue((self.sample_xar_dir_path / exec_target).exists())