def setUp(self): super().setUp() self.fake_lxd = fixture_setup.FakeLXD() self.useFixture(self.fake_lxd) self.fake_lxd.kernel_arch = self.server self.fake_filesystem = fixture_setup.FakeFilesystem() self.useFixture(self.fake_filesystem) self.fake_logger = fixtures.FakeLogger(level=logging.INFO) self.useFixture(self.fake_logger) self.project_options = ProjectOptions(target_deb_arch=self.target_arch)
def test_refresh_fails_without_env_var(self, mock_container_run): mock_container_run.side_effect = lambda cmd, **kwargs: cmd fake_lxd = fixture_setup.FakeLXD() self.useFixture(fake_lxd) fake_filesystem = fixture_setup.FakeFilesystem() self.useFixture(fake_filesystem) self.make_snapcraft_yaml() self.assertRaises(SnapcraftEnvironmentError, self.run_command, ['refresh']) mock_container_run.assert_not_called()
def test_refresh(self, mock_container_run): mock_container_run.side_effect = lambda cmd, **kwargs: cmd fake_lxd = fixture_setup.FakeLXD() self.useFixture(fake_lxd) fake_filesystem = fixture_setup.FakeFilesystem() self.useFixture(fake_filesystem) self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT", "lxd")) self.make_snapcraft_yaml() self.run_command(["refresh"]) mock_container_run.assert_has_calls([ call(["apt-get", "update"]), call(["apt-get", "upgrade", "-y"]), call(["snap", "refresh"]), ]) self.assertThat(fake_lxd.name, Equals("local:snapcraft-snap-test"))
def test_refresh(self, mock_container_run): mock_container_run.side_effect = lambda cmd, **kwargs: cmd fake_lxd = fixture_setup.FakeLXD() self.useFixture(fake_lxd) fake_filesystem = fixture_setup.FakeFilesystem() self.useFixture(fake_filesystem) self.useFixture( fixtures.EnvironmentVariable('SNAPCRAFT_BUILD_ENVIRONMENT', 'lxd')) self.make_snapcraft_yaml() self.run_command(['refresh']) mock_container_run.assert_has_calls([ call(['apt-get', 'update']), call(['apt-get', 'upgrade', '-y']), call(['snap', 'refresh']), ]) self.assertThat(fake_lxd.name, Equals('local:snapcraft-snap-test'))
def test_snap_containerized_remote(self, mock_geteuid, mock_pipe, mock_container_run): mock_container_run.side_effect = lambda cmd, **kwargs: cmd mock_pipe.return_value = (9, 9) mock_geteuid.return_value = 1234 fake_lxd = fixture_setup.FakeLXD() self.useFixture(fake_lxd) fake_filesystem = fixture_setup.FakeFilesystem() self.useFixture(fake_filesystem) fake_logger = fixtures.FakeLogger(level=logging.INFO) self.useFixture(fake_logger) self.useFixture( fixtures.EnvironmentVariable('SNAPCRAFT_CONTAINER_BUILDS', 'myremote')) self.useFixture(fixtures.EnvironmentVariable('USER', 'user')) self.make_snapcraft_yaml() result = self.run_command(['--debug', 'snap']) self.assertThat(result.exit_code, Equals(0)) source = os.path.realpath(os.path.curdir) self.assertThat( fake_logger.output, Contains( "Using LXD remote 'myremote' from SNAPCRAFT_CONTAINER_BUILDS")) project_folder = '/home/user/build_snap-test' mock_container_run.assert_has_calls([ call(['apt-get', 'install', '-y', 'sshfs']), ]) fake_lxd.popen_mock.assert_has_calls([ call(['/usr/lib/sftp-server'], stdin=9, stdout=9), call([ 'lxc', 'exec', fake_lxd.name, '--', 'sudo', '-H', '-u', 'user', 'sshfs', '-o', 'slave', '-o', 'nonempty', ':{}'.format(source), project_folder ], stdin=9, stdout=9), ])