| 32 |
32 |
|
from snapcraft import tests |
| 33 |
33 |
|
|
| 34 |
34 |
|
|
| 35 |
|
- |
class SnapCommandContainerized(tests.TestCase): |
| 36 |
|
- |
|
| 37 |
|
- |
yaml_template = """name: snap-test |
| 38 |
|
- |
version: 1.0 |
| 39 |
|
- |
summary: test containerized snap |
| 40 |
|
- |
description: if snap is succesful a snap package will be available |
| 41 |
|
- |
architectures: ['amd64'] |
| 42 |
|
- |
confinement: strict |
| 43 |
|
- |
grade: stable |
| 44 |
|
- |
|
| 45 |
|
- |
parts: |
| 46 |
|
- |
part1: |
| 47 |
|
- |
plugin: nil |
| 48 |
|
- |
""" |
| 49 |
|
- |
|
| 50 |
|
- |
scenarios = [ |
| 51 |
|
- |
('local', dict(args=[], remote='local')), |
| 52 |
|
- |
('remote', dict(args=['--remote=my-remote'], remote='my-remote')), |
| 53 |
|
- |
] |
| 54 |
|
- |
|
| 55 |
|
- |
def make_snapcraft_yaml(self, n=1): |
| 56 |
|
- |
super().make_snapcraft_yaml(self.yaml_template) |
| 57 |
|
- |
|
| 58 |
|
- |
def test_snap_defaults(self): |
| 59 |
|
- |
fake_lxd = tests.fixture_setup.FakeLXD() |
| 60 |
|
- |
self.useFixture(fake_lxd) |
| 61 |
|
- |
fake_logger = fixtures.FakeLogger(level=logging.INFO) |
| 62 |
|
- |
self.useFixture(fake_logger) |
| 63 |
|
- |
self.useFixture(fixtures.EnvironmentVariable( |
| 64 |
|
- |
'SNAPCRAFT_CONTAINER_BUILDS', '1')) |
| 65 |
|
- |
self.make_snapcraft_yaml() |
| 66 |
|
- |
|
| 67 |
|
- |
main(['snap', '--debug', *self.args]) |
| 68 |
|
- |
|
| 69 |
|
- |
source = os.path.realpath(os.path.curdir) |
| 70 |
|
- |
self.assertIn( |
| 71 |
|
- |
'Mounting {} into container\n' |
| 72 |
|
- |
'Waiting for a network connection...\n' |
| 73 |
|
- |
'Network connection established\n'.format(source), |
| 74 |
|
- |
fake_logger.output) |
| 75 |
|
- |
|
| 76 |
|
- |
container_name = '{}:snapcraft-snap-test'.format(self.remote) |
| 77 |
|
- |
project_folder = 'build_snap-test' |
| 78 |
|
- |
fake_lxd.check_call_mock.assert_has_calls([ |
| 79 |
|
- |
call(['lxc', 'start', container_name]), |
| 80 |
|
- |
call(['lxc', 'config', 'device', 'add', container_name, |
| 81 |
|
- |
project_folder, 'disk', 'source={}'.format(source), |
| 82 |
|
- |
'path=/{}'.format(project_folder)]), |
| 83 |
|
- |
call(['lxc', 'exec', container_name, |
| 84 |
|
- |
'--env', 'HOME=/{}'.format(project_folder), '--', |
| 85 |
|
- |
'python3', '-c', |
| 86 |
|
- |
'import urllib.request; ' |
| 87 |
|
- |
'urllib.request.urlopen(' |
| 88 |
|
- |
'"http://start.ubuntu.com/connectivity-check.html", ' |
| 89 |
|
- |
'timeout=5)']), |
| 90 |
|
- |
call(['lxc', 'exec', container_name, |
| 91 |
|
- |
'--env', 'HOME=/{}'.format(project_folder), '--', |
| 92 |
|
- |
'apt-get', 'update']), |
| 93 |
|
- |
call(['lxc', 'exec', container_name, |
| 94 |
|
- |
'--env', 'HOME=/{}'.format(project_folder), '--', |
| 95 |
|
- |
'apt-get', 'install', 'snapcraft', '-y']), |
| 96 |
|
- |
call(['lxc', 'exec', container_name, |
| 97 |
|
- |
'--env', 'HOME=/{}'.format(project_folder), '--', |
| 98 |
|
- |
'snapcraft', 'snap', '--output', |
| 99 |
|
- |
'snap-test_1.0_amd64.snap']), |
| 100 |
|
- |
call(['lxc', 'stop', '-f', container_name]), |
| 101 |
|
- |
]) |
| 102 |
|
- |
|
| 103 |
|
- |
|
| 104 |
35 |
|
class SnapCommandTestCase(tests.TestCase): |
| 105 |
36 |
|
|
| 106 |
37 |
|
yaml_template = """name: snap-test |
#12630ddf155#1263ad42d9e#1263638d028#12636239f7cb8648e4912016a0667868