def test_create_toolchains_from_file_definition(self):
        with prepare_template(
                get_test_data('toolchain_definition_template.yaml'),
                URL1=get_toolchain_test_data('tgz_archive.tgz'),
                NAME1='zenterio-tgz-archive.',
                DEPENDS1='dpkg',
                URL2=get_toolchain_test_data('toolchain_dir'),
                NAME2='zenterio-toolchain-dir') as definition_file:
            command = 'zdeb-packer --verbose toolchain-list --file {file}'.format(
                file=definition_file)
            invoke_for_output(command, cwd=self.test_root)
            self.assert_file_exists(
                os.path.join(self.test_root, 'zenterio-tgz-archive*.deb'))
            self.assert_file_exists(
                os.path.join(self.test_root, 'zenterio-toolchain-dir*.deb'))
            debs = glob.glob(os.path.join(self.test_root, '*.deb'))
            debs.sort()
            self.assertEqual(2, len(debs))

            tgz_toolchain_files = map(
                lambda path: os.path.join(path, 'file'),
                ['/tmp/install/tool1', '/tmp/install/tools/tool1'])
            self.assert_correct_toolchain(debs[0], 'zenterio-tgz-archive',
                                          tgz_toolchain_files,
                                          'This is the tgz archive.\n')
            self.assert_correct_toolchain(
                debs[1], 'zenterio-toolchain-dir',
                ['/tmp/install/tool2/file', '/tmp/install/tool2_link/file'],
                'This is the file in toolchain_dir.')
Ejemplo n.º 2
0
    def test_create_toolchain_which_preserves_hardlinks(self):
        archive = os.path.join(self.test_root, 'archive_with_links')
        os.makedirs(archive)
        file = os.path.join(archive, 'file')
        create_file(file, 'content')
        os.link(file, os.path.join(archive, 'file_link'))
        install_path1 = '/tmp/test/archive_with_links'
        with TemporaryDirectory() as workspace:
            command = 'zdeb-packer toolchain --uri {uri} --installation-path {install_path1} ' \
                      '--workspace {workspace} --force' \
                .format(uri=archive, install_path1=install_path1, workspace=workspace)
            invoke_for_output(command,
                              cwd=self.test_root,
                              expected_exit_code=ANY)

            dir_for_files_in_package = os.path.join(
                workspace, 'output', 'debian', 'zenterio-archive-with-links',
                'tmp', 'test')
            self.assertTrue(
                is_hard_link(
                    os.path.join(dir_for_files_in_package,
                                 'archive_with_links', 'file'),
                    os.path.join(dir_for_files_in_package,
                                 'archive_with_links', 'file_link')))

            install(glob.glob(os.path.join(self.test_root, '*.deb'))[0])
            self.assertTrue(
                is_hard_link(os.path.join(install_path1, 'file'),
                             os.path.join(install_path1, 'file_link')))
Ejemplo n.º 3
0
 def test_create_metapackage(self):
     infile = get_test_data('metapackage_no_nonexisting_dependencies.yaml')
     command = 'zdeb-packer -v metapackage {infile}'.format(infile=infile)
     invoke_for_output(command, cwd=self.test_root)
     self.assert_metapackage_can_be_installed(
         self.test_root, 'Unpacking zenterio-metapackage2 (1.0.0) ...',
         'Setting up zenterio-metapackage2 (1.0.0) ...')
Ejemplo n.º 4
0
 def test_create_metapackage_with_one_unresolvable_dependency(self):
     infile = get_test_data('metapackage_one_nonexisting_dependency.yaml')
     command = 'zdeb-packer -v metapackage {infile}'.format(infile=infile)
     invoke_for_output(command, cwd=self.test_root)
     self.assert_metapackage_can_be_installed(
         self.test_root,
         'dpkg: error processing package zenterio-metapackage1 (--install):\n '
         'dependency problems - leaving unconfigured\n'
         'Errors were encountered while processing:\n '
         'zenterio-metapackage1',
         expected_exit_code=1)
Ejemplo n.º 5
0
 def test_to_create_multiple_metapackages(self):
     infile1 = get_test_data('metapackage_multiple_distributions_trusty_and_xenial.yaml')
     infile2 = get_test_data('metapackage_multiple_only_xenial_distribution.yaml')
     invoke_for_output(
         'zdeb-packer metapackage {infile}'.format(infile=infile1), cwd=self.test_root)
     invoke_for_output(
         'zdeb-packer metapackage {infile}'.format(infile=infile2), cwd=self.test_root)
     self.assert_file_exists(
         os.path.join(self.test_root, 'dist', 'trusty', 'metapackage-trusty-and-xenial*.deb'))
     self.assert_file_exists(
         os.path.join(self.test_root, 'dist', 'xenial', 'metapackage-trusty-and-xenial*.deb'))
     self.assert_file_exists(
         os.path.join(self.test_root, 'dist', 'xenial', 'metapackage-xenial*.deb'))
Ejemplo n.º 6
0
 def test_create_dummy_toolchain(self):
     install_path = '/tmp/test/dummy_archive'
     archive = os.path.join(self.test_root, 'dummy_archive')
     with TemporaryDirectory() as workspace:
         command = 'zdeb-packer toolchain --uri {uri} --installation-path {install_path} ' \
                   '--workspace {workspace} --force --dummy' \
                   .format(uri=archive, install_path=install_path, workspace=workspace)
         invoke_for_output(command,
                           cwd=self.test_root,
                           expected_exit_code=0)
         info_file_path = os.path.join(workspace, 'output', 'dummy',
                                       'info.txt')
         with open(info_file_path, 'r') as info_file:
             assert info_file.readline() == 'This is a dummy toolchain.'
Ejemplo n.º 7
0
 def test_create_toolchain_existing_outfile(self):
     with NamedTemporaryFile(dir=self.test_root) as existing_file:
         command = 'zdeb-packer toolchain --uri uri --installation-path path --output-dir {path}' \
             .format(path=existing_file.name)
         output = invoke_for_output(command, expected_exit_code=1)
         self.assertRegex(
             output, r'The output directory .* is a file not a directory')
Ejemplo n.º 8
0
    def test_create_toolchain_deb_package_from_local_archive(self):
        out_dir = os.path.join(self.test_root, 'out_dir')
        uri = get_toolchain_test_data('tgz_archive.tgz')
        install_path_1 = '/tmp/installation/path/tgz_archive'
        install_path_2 = '/tmp/installation/other/tgz_archive'
        link = '/tmp/installation/link'
        package_name = 'zenterio-tgz-archive'
        command = 'zdeb-packer -v toolchain --uri {uri} --output-dir {out} --workspace {workspace} ' \
                  '--installation-path {install_path_1} --installation-path {install_path_2} ' \
                  '--link {link} {install_path_1}/file --force' \
            .format(uri=uri, out=out_dir, workspace=self.test_root, install_path_1=install_path_1,
                    install_path_2=install_path_2, link=link)
        logger.debug(invoke_for_output(command))
        deb_path = glob.glob(
            os.path.join(out_dir,
                         '{package}_*.deb'.format(package=package_name)))[0]
        self.assert_file_exists(deb_path)
        debian_dir = os.path.join(self.test_root, 'output', 'debian')
        self.assert_file_regex(
            os.path.join(debian_dir, 'changelog'),
            r'{package} \(1.0.0\) unstable; urgency=low'.format(
                package=package_name))
        self.assert_file_regex(
            os.path.join(debian_dir, 'control'),
            r'Source: {package}'.format(package=package_name))

        toolchain_files = list(
            map(lambda path: os.path.join(path, 'file'),
                [install_path_1, install_path_2]))
        toolchain_files.append(link)
        self.assert_correct_toolchain(deb_path, package_name, toolchain_files,
                                      'This is the tgz archive.\n')
Ejemplo n.º 9
0
 def test_that_invalid_uri_gives_good_error_message(self):
     command = 'zdeb-packer toolchain --uri ftp://bad_url.se --installation-path /tmp/test '
     output = invoke_for_output(command,
                                cwd=self.test_root,
                                expected_exit_code=1)
     self.assertRegex(
         output,
         r'.*Problem with the connection while fetching the toolchains. Is the URI valid?'
     )
 def test_install_toolchain_with_broken_dependency_fails(self):
     with prepare_template(
             get_test_data('toolchain_definition_template.yaml'),
             URL1=get_toolchain_test_data('tgz_archive.tgz'),
             NAME1='zenterio-tgz-archive.',
             DEPENDS1='does-not-exist',
             URL2=get_toolchain_test_data('toolchain_dir'),
             NAME2='zenterio-toolchain-dir') as definition_file:
         command = 'zdeb-packer --verbose toolchain-list --file {file}'.format(
             file=definition_file)
         invoke_for_output(command, cwd=self.test_root)
         expected_deb = glob.glob(
             os.path.join(self.test_root, 'zenterio-tgz-archive*.deb'))[0]
         self.assert_file_exists(expected_deb)
         stdout = invoke_for_output(
             'sudo gdebi --non-interactive {deb}'.format(deb=expected_deb),
             expected_exit_code=1)
         self.assertIn('Dependency is not satisfiable: does-not-exist',
                       stdout)
 def test_create_dummy_toolchains_form_file_definition(self):
     with prepare_template(
             get_test_data('toolchain_definition_dummy_template.yaml'),
             URL1=get_toolchain_test_data('tgz_archive.tgz'),
             NAME1='zenterio-dummy-1.',
             DEPENDS1='dpkg',
             URL2=get_toolchain_test_data('tgz_archive.tgz'),
             NAME2='zenterio-dummy-2') as definition_file:
         command = 'zdeb-packer --verbose toolchain-list --file {file} --dummy'.format(
             file=definition_file)
         invoke_for_output(command, cwd=self.test_root)
         for deb in glob.glob(
                 os.path.join(self.test_root, 'zenterio-dummy-*.deb')):
             invoke_for_output(
                 'sudo gdebi --non-interactive {deb}'.format(deb=deb),
                 expected_exit_code=0)
         for path in ('/tmp/dummy/tool1/info.txt',
                      '/tmp/dummy/tool2/info.txt'):
             with open(path, 'r') as info_file:
                 assert info_file.readline() == 'This is a dummy toolchain.'
Ejemplo n.º 12
0
    def assert_metapackage_can_be_installed(
            self, package_root, *expected_outputs, expected_exit_code=0, deb_glob=None):
        if not deb_glob:
            deb_glob = os.path.join(package_root, 'dist', '*.deb')
        deb_file = glob.glob(deb_glob)[0]
        self.assertRegex(
            os.path.basename(deb_file), r'zenterio-.*_1\.0\.0.*_all\.deb',
            'Debian file name not correct formatted')
        command = 'sudo dpkg -i {debfile}'.format(debfile=deb_file)
        output = invoke_for_output(command, expected_exit_code=expected_exit_code, cwd=package_root)

        for expected_output in expected_outputs:
            self.assertIn(expected_output, output)
Ejemplo n.º 13
0
 def test_create_toolchain_deb_with_minimal_arguments(self):
     uri = get_toolchain_test_data('toolchain_dir')
     install_path = '/tmp/path/toolchain_dir/'
     package_name = 'zenterio-toolchain-dir'
     command = 'zdeb-packer toolchain --uri {uri} --installation-path {install_path}' \
         .format(uri=uri, install_path=install_path)
     with TemporaryDirectory() as cwd:
         logger.debug(invoke_for_output(command, cwd=cwd))
         deb_path = glob.glob(
             os.path.join(
                 cwd, '{package}_*.deb'.format(package=package_name)))[0]
         self.assert_file_exists(deb_path)
         self.assert_correct_toolchain(
             deb_path, package_name, [os.path.join(install_path, 'file')],
             'This is the file in toolchain_dir.')
Ejemplo n.º 14
0
 def test_create_toolchain_existing_workspace(self):
     command = 'zdeb-packer toolchain --uri uri --installation-path path --workspace {path}'.format(
         path=self.test_root)
     output = invoke_for_output(command, expected_exit_code=1)
     self.assertRegex(
         output, r'Workspace ".*" already exists and force was not given')