Skip to content

Commit

Permalink
meta: add base as a type and top level property (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 authored and sergiusens committed Aug 15, 2017
1 parent e68d25a commit 024b920
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 2 deletions.
18 changes: 18 additions & 0 deletions demos/base-example-consumer/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: base-example-consumer
version: 1.0
summary: Example snap that consumes a different base snap
description:
This example snap uses the base-example base snap instead of
the regular "core" snap.
confinement: strict
base: base-example

apps:
hello:
command: usr/bin/hello

parts:
libc:
plugin: dump
source: .
stage-packages: [hello]
17 changes: 17 additions & 0 deletions demos/base-example/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: base-example
version: 1.0
summary: Example base snap
description:
A base snap is a special kind of snap that can be used by
other snaps as an alternative base. This base will then
be used as the root filesystem instead of the traditional
core snap.

This example base snap only contains a basic libc6.
type: base

parts:
libc:
plugin: dump
source: .
stage-packages: [libc6]
4 changes: 4 additions & 0 deletions schema/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ properties:
description: the snap type, the implicit type is 'app'
enum:
- app
- base
- gadget
- kernel
- os
Expand All @@ -104,6 +105,9 @@ properties:
enum:
- stable
- devel
base:
type: string
description: the base snap to use
epoch:
description: the snap epoch, used to specify upgrade paths
format: epoch
Expand Down
1 change: 1 addition & 0 deletions snapcraft/internal/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
_OPTIONAL_PACKAGE_KEYS = [
'architectures',
'assumes',
'base',
'environment',
'type',
'plugs',
Expand Down
3 changes: 2 additions & 1 deletion snapcraft/tests/commands/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def test_snap_fails_with_bad_type(self):
self.run_command, ['snap'])

self.assertThat(str(raised), Contains(
"bad-type' is not one of ['app', 'gadget', 'kernel', 'os']"))
"bad-type' is not one of ['app', 'base', 'gadget', "
"'kernel', 'os']"))

def test_snap_is_the_default(self):
self.make_snapcraft_yaml()
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/tests/test_project_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ def test_invalid_types(self):
expected_message = (
"The 'type' property does not match the required "
"schema: '{}' is not one of "
"['app', 'gadget', 'kernel', 'os']").format(self.type_)
"['app', 'base', 'gadget', 'kernel', 'os']").format(self.type_)
self.assertEqual(raised.message, expected_message,
message=data)

Expand Down
29 changes: 29 additions & 0 deletions snaps_tests/demos_tests/test_base-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2017 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import snaps_tests


class BaseExampleTestCase(snaps_tests.SnapsTestCase):

snap_content_dir = 'base-example'

def test_base_example(self):
# Build snap will raise an exception in case of error.
snap_path = self.build_snap(self.snap_content_dir)
# Install snap will raise an exception in case of error.
self.install_snap(snap_path, 'base-example', '1.0')
# more testing is done in test_base-consumer
33 changes: 33 additions & 0 deletions snaps_tests/demos_tests/test_base-example_consumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2017 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import snaps_tests


class BaseExampleConsumerTestCase(snaps_tests.SnapsTestCase):

base_content_dir = 'base-example'
base_consumer_content_dir = 'base-example-consumer'

def test_base_example(self):
# build/install the alternative base
snap_path = self.build_snap(self.base_content_dir)
self.install_snap(snap_path, 'base-example', '1.0')
# build the consumer
snap_path = self.build_snap(self.base_consumer_content_dir)
self.install_snap(snap_path, 'base-example-consumer', '1.0')
# FIXME: once snapd supports bases fully run hello against
# the alternative base

0 comments on commit 024b920

Please sign in to comment.