Пример #1
0
    def test_deb_arch_migration_message(self):
        with self.assertRaises(EnvironmentError) as raised:
            common.get_arch()

        self.assertEqual(
            str(raised.exception),
            "This plugin is outdated, use 'project.deb_arch'")
Пример #2
0
    def test_snap_default(self):
        project_dir = 'assemble'
        self.run_snapcraft([], project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())
Пример #3
0
    def test_os_type_returned_by_lifecycle(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)

        self.make_snapcraft_yaml("""name: after
version: 0
summary: test stage
description: check and see if we return type 'os'
type: os

parts:
  part1:
    plugin: nil
  part2:
    plugin: nil
    after:
      - part1
""")
        open('icon.png', 'w').close()

        snap_info = lifecycle.execute('pull')

        expected_snap_info = {
            'name': 'after',
            'version': 0,
            'arch': [common.get_arch()],
            'type': 'os'
        }
        self.assertEqual(snap_info, expected_snap_info)
Пример #4
0
    def test_dependency_recursed_correctly(self):
        self.make_snapcraft_yaml(
            """parts:
  part1:
    plugin: nil
  part2:
    plugin: nil
    after:
      - part1
"""
        )

        snap_info = snapcraft.lifecycle.execute("pull", snapcraft.ProjectOptions())

        expected_snap_info = {"name": "test", "version": 0, "arch": [common.get_arch()], "type": ""}
        self.assertEqual(snap_info, expected_snap_info)

        self.assertEqual(
            "Preparing to pull part1 \n"
            "Pulling part1 \n"
            "'part2' has prerequisites that need to be staged: part1\n"
            "Skipping pull part1 (already ran)\n"
            "Preparing to build part1 \n"
            "Building part1 \n"
            "Staging part1 \n"
            "Preparing to pull part2 \n"
            "Pulling part2 \n",
            self.fake_logger.output,
        )
Пример #5
0
    def test_snap_default(self):
        project_dir = 'assemble'
        self.run_snapcraft([], project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())
Пример #6
0
def _setup_apt_cache(rootdir, sources, local=False):
    os.makedirs(os.path.join(rootdir, 'etc', 'apt'), exist_ok=True)
    srcfile = os.path.join(rootdir, 'etc', 'apt', 'sources.list')

    if not local:
        series = platform.linux_distribution()[2]
        sources = _format_sources_list(sources, common.get_arch(), series)

    with open(srcfile, 'w') as f:
        f.write(sources)

    # Do not install recommends
    apt.apt_pkg.config.set('Apt::Install-Recommends', 'False')

    # Make sure we always use the system GPG configuration, even with
    # apt.Cache(rootdir).
    for key in 'Dir::Etc::Trusted', 'Dir::Etc::TrustedParts':
        apt.apt_pkg.config.set(key, apt.apt_pkg.config.find_file(key))

    progress = apt.progress.text.AcquireProgress()
    if not os.isatty(1):
        # Make output more suitable for logging.
        progress.pulse = lambda owner: True
        progress._width = 0

    apt_cache = apt.Cache(rootdir=rootdir, memonly=True)
    apt.apt_pkg.config.clear("APT::Update::Post-Invoke-Success")
    apt_cache.update(fetch_progress=progress, sources_list=srcfile)
    apt_cache.open()

    return apt_cache, progress
Пример #7
0
 def _create_container(self):
     try:
         remote_tmp = petname.Generate(2, "-")
         check_call(["lxc", "remote", "add", remote_tmp, self._server])
         check_call(["lxc", "launch", "{}:ubuntu/xenial/{}".format(remote_tmp, get_arch()), self._container_name])
         yield
     finally:
         check_call(["lxc", "stop", self._container_name])
         check_call(["lxc", "remote", "remove", remote_tmp])
Пример #8
0
    def test_cleanbuild(self):
        self.skipTest("Fails to run correctly on travis.")
        project_dir = 'assemble'
        self.run_snapcraft('cleanbuild', project_dir)
        os.chdir(project_dir)

        snap_source_path = 'assemble_1.0_source.tar.bz2'
        self.assertThat(snap_source_path, FileExists())

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())
Пример #9
0
    def test_cleanbuild(self):
        self.skipTest("Fails to run correctly on travis.")
        project_dir = 'assemble'
        self.run_snapcraft('cleanbuild', project_dir)
        os.chdir(project_dir)

        snap_source_path = 'assemble_1.0_source.tar.bz2'
        self.assertThat(snap_source_path, FileExists())

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())
Пример #10
0
    def __init__(self, project_options=None):
        self.build_tools = []
        self.all_parts = []
        self._part_names = []
        self._project_options = project_options
        self.after_requests = {}

        self.data = _snapcraft_yaml_load()

        # To make the transition less painful
        self._remap_skills_to_interfaces()

        self._validator = Validator(self.data)
        self._validator.validate()

        self.build_tools = self.data.get('build-packages', [])

        self._wiki = wiki.Wiki()

        for part_name in self.data.get('parts', []):
            self._part_names.append(part_name)
            properties = self.data['parts'][part_name] or {}

            plugin_name = properties.pop('plugin', None)
            if not plugin_name:
                logger.info(
                    'Searching the wiki to compose part "{}"'.format(
                        part_name))
                with contextlib.suppress(KeyError):
                    properties = self._wiki.compose(part_name, properties)
                    plugin_name = properties.pop('plugin', None)
                    # The wiki still supports using 'type' for snapcraft 1.x
                    if 'type' in properties:
                        del properties['type']

            if not plugin_name:
                raise PluginNotDefinedError(part_name)

            if 'after' in properties:
                self.after_requests[part_name] = properties.pop('after')

            properties['stage'] = _expand_filesets_for('stage', properties)
            properties['snap'] = _expand_filesets_for('snap', properties)

            if 'filesets' in properties:
                del properties['filesets']

            self.load_plugin(part_name, plugin_name, properties)

        self._compute_part_dependencies()
        self.all_parts = self._sort_parts()

        if 'architectures' not in self.data:
            self.data['architectures'] = [common.get_arch(), ]
Пример #11
0
    def test_upload_without_login(self):
        project_dir = "assemble"
        self.run_snapcraft("snap", project_dir)
        snap_file_path = "assemble_1.0_{}.snap".format(get_arch())
        os.chdir(project_dir)
        self.assertThat(snap_file_path, FileExists())

        output = self.run_snapcraft(["upload", snap_file_path])

        self.assertIn("Upload failed", output)
        self.assertIn('No valid credentials found. Have you run "snapcraft ' 'login"?', output)
Пример #12
0
    def test_snap_directory(self):
        project_dir = 'assemble'
        self.run_snapcraft('snap', project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        os.remove(snap_file_path)

        # Verify that Snapcraft can snap its own snap directory (this will make
        # sure `snapcraft snap` and `snapcraft snap <directory>` are always in
        # sync).
        self.run_snapcraft(['snap', 'snap'])
        self.assertThat(snap_file_path, FileExists())
Пример #13
0
    def test_upload_without_login(self):
        project_dir = 'assemble'
        output = self.run_snapcraft('upload', project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())

        self.assertIn('Snap assemble_1.0_amd64.snap not found. Running snap '
                      'step to create it.', output)
        self.assertIn('Upload failed', output)
        self.assertIn('No valid credentials found. Have you run "snapcraft '
                      'login"?', output)
Пример #14
0
    def test_snap_directory(self):
        project_dir = 'assemble'
        self.run_snapcraft('snap', project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        os.remove(snap_file_path)

        # Verify that Snapcraft can snap its own snap directory (this will make
        # sure `snapcraft snap` and `snapcraft snap <directory>` are always in
        # sync).
        self.run_snapcraft(['snap', 'snap'])
        self.assertThat(snap_file_path, FileExists())
Пример #15
0
    def __init__(self):
        self.build_tools = []
        self.all_parts = []
        self._part_names = []
        self.after_requests = {}

        self.data = _snapcraft_yaml_load()

        # To make the transition less painful
        self._remap_skills_to_interfaces()

        _validate_snapcraft_yaml(self.data)

        self.build_tools = self.data.get('build-packages', [])

        self._wiki = wiki.Wiki()

        for part_name in self.data.get('parts', []):
            self._part_names.append(part_name)
            properties = self.data['parts'][part_name] or {}

            plugin_name = properties.pop('plugin', None)
            if not plugin_name:
                logger.info(
                    'Searching the wiki to compose part "{}"'.format(
                        part_name))
                with contextlib.suppress(KeyError):
                    properties = self._wiki.compose(part_name, properties)
                    plugin_name = properties.pop('plugin', None)

            if not plugin_name:
                raise PluginNotDefinedError(part_name)

            if 'after' in properties:
                self.after_requests[part_name] = properties.pop('after')

            properties['stage'] = _expand_filesets_for('stage', properties)
            properties['snap'] = _expand_filesets_for('snap', properties)

            if 'filesets' in properties:
                del properties['filesets']

            self.load_plugin(part_name, plugin_name, properties)

        self._compute_part_dependencies()
        self.all_parts = self._sort_parts()

        if 'architectures' not in self.data:
            self.data['architectures'] = [common.get_arch(), ]
Пример #16
0
    def test_os_type_returned_by_lifecycle(self):
        self.make_snapcraft_yaml(
            """parts:
  part1:
    plugin: nil
  part2:
    plugin: nil
    after:
      - part1
""",
            "type: os",
        )

        snap_info = snapcraft.lifecycle.execute("pull", snapcraft.ProjectOptions())

        expected_snap_info = {"name": "test", "version": 0, "arch": [common.get_arch()], "type": "os"}
        self.assertEqual(snap_info, expected_snap_info)
Пример #17
0
    def __init__(self):
        self.build_tools = []
        self.all_parts = []
        self._part_names = []
        self.after_requests = {}

        self.data = _snapcraft_yaml_load()
        _validate_snapcraft_yaml(self.data)

        self.build_tools = self.data.get('build-packages', [])

        self._wiki = wiki.Wiki()

        for part_name in self.data.get('parts', []):
            self._part_names.append(part_name)
            properties = self.data['parts'][part_name] or {}

            plugin_name = properties.pop('plugin', None)
            if not plugin_name:
                logger.info(
                    'Searching the wiki to compose part "{}"'.format(
                        part_name))
                with contextlib.suppress(KeyError):
                    properties = self._wiki.compose(part_name, properties)
                    plugin_name = properties.pop('plugin', None)

            if not plugin_name:
                raise PluginNotDefinedError(part_name)

            if 'after' in properties:
                self.after_requests[part_name] = properties.pop('after')

            properties['stage'] = _expand_filesets_for('stage', properties)
            properties['snap'] = _expand_filesets_for('snap', properties)

            if 'filesets' in properties:
                del properties['filesets']

            self.load_plugin(part_name, plugin_name, properties)

        self._compute_part_dependencies()
        self.all_parts = self._sort_parts()

        if 'architectures' not in self.data:
            self.data['architectures'] = [common.get_arch(), ]
Пример #18
0
    def test_upload_with_login(self):
        self.useFixture(fixture_setup.StagingStore())

        # Make a snap
        project_dir = "basic"
        self.addCleanup(self.logout)
        self.login()

        # Change to a random version.
        # The maximum size is 32 chars.
        new_version = str(uuid.uuid4().int)[:32]
        project_dir = self._update_version(project_dir, new_version)

        self.run_snapcraft("snap", project_dir)

        # Upload the snap
        snap_file_path = "basic_{}_{}.snap".format(new_version, get_arch())
        self.assertThat(os.path.join(project_dir, snap_file_path), FileExists())

        output = self.run_snapcraft(["upload", snap_file_path], project_dir)
        self.assertIn("Application uploaded successfully (as revision ", output)
        self.assertIn("Please check out the application at: ", output)
Пример #19
0
    def test_snap(self):
        project_dir = 'assemble'
        self.run_snapcraft('snap', project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())

        binary1_wrapper_path = os.path.join(
            'snap', 'command-assemble-bin.wrapper')
        with open('binary1.after', 'r') as file_:
            binary1_after = file_.read()
        expected_binary1_wrapper = binary1_after.replace(
            '@MULTIARCH@', get_arch_triplet())
        self.assertThat(
            binary1_wrapper_path, FileContains(expected_binary1_wrapper))

        self.useFixture(
           fixtures.EnvironmentVariable(
                'SNAP', os.path.join(os.getcwd(), 'snap')))
        binary_scenarios = (
            ('command-assemble-service.wrapper', 'service-start\n'),
            ('stop-command-assemble-service.wrapper', 'service-stop\n'),
            ('command-assemble-bin.wrapper', 'binary1\n'),
            ('command-binary2.wrapper', 'binary2\n'),
        )
        for binary, expected_output in binary_scenarios:
            output = subprocess.check_output(
                os.path.join('snap', binary), universal_newlines=True)
            self.assertEqual(expected_output, output)

        with testtools.ExpectedException(subprocess.CalledProcessError):
            subprocess.check_output(
                os.path.join('snap', 'bin', 'not-wrapped'),
                stderr=subprocess.STDOUT)

        self.assertThat(
            os.path.join('snap', 'bin', 'not-wrapped.wrapper'),
            Not(FileExists()))
Пример #20
0
    def test_dependency_recursed_correctly(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)

        self.make_snapcraft_yaml("""name: after
version: 0
summary: test stage
description: if the build is succesful the state file will be updated
icon: icon.png

parts:
  part1:
    plugin: nil
  part2:
    plugin: nil
    after:
      - part1
""")
        open('icon.png', 'w').close()

        snap_info = lifecycle.execute('pull')

        expected_snap_info = {
            'name': 'after',
            'version': 0,
            'arch': [common.get_arch()],
            'type': ''
        }
        self.assertEqual(snap_info, expected_snap_info)

        self.assertEqual(
            'Pulling part1 \n'
            '\'part2\' has prerequisites that need to be staged: part1\n'
            'Skipping pull part1  (already ran)\n'
            'Building part1 \n'
            'Staging part1 \n'
            'Pulling part2 \n',
            fake_logger.output)
Пример #21
0
    def test_snap(self):
        project_dir = 'assemble'
        self.run_snapcraft('snap', project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())

        binary1_wrapper_path = os.path.join('snap',
                                            'command-assemble-bin.wrapper')
        with open('binary1.after', 'r') as file_:
            binary1_after = file_.read()
        expected_binary1_wrapper = binary1_after.replace(
            '@MULTIARCH@', get_arch_triplet())
        self.assertThat(binary1_wrapper_path,
                        FileContains(expected_binary1_wrapper))

        self.useFixture(
            fixtures.EnvironmentVariable('SNAP',
                                         os.path.join(os.getcwd(), 'snap')))
        binary_scenarios = (
            ('command-assemble-service.wrapper', 'service-start\n'),
            ('stop-command-assemble-service.wrapper', 'service-stop\n'),
            ('command-assemble-bin.wrapper', 'binary1\n'),
            ('command-binary2.wrapper', 'binary2\n'),
        )
        for binary, expected_output in binary_scenarios:
            output = subprocess.check_output(os.path.join('snap', binary),
                                             universal_newlines=True)
            self.assertEqual(expected_output, output)

        with testtools.ExpectedException(subprocess.CalledProcessError):
            subprocess.check_output(os.path.join('snap', 'bin', 'not-wrapped'),
                                    stderr=subprocess.STDOUT)

        self.assertThat(os.path.join('snap', 'bin', 'not-wrapped.wrapper'),
                        Not(FileExists()))
Пример #22
0
 def test_get_arch_with_no_errors(self):
     common.get_arch()
Пример #23
0
 def test_get_arch_with_no_errors(self):
     common.get_arch()