blob: b274944a952182a3665611dcca63578c455a81ee [file] [log] [blame]
Clint Byrum5870cca2017-04-04 16:20:00 -07001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import fixtures
14import logging
15import subprocess
16import tempfile
17import testtools
18
19from zuul.driver import bubblewrap
20from zuul.executor.server import SshAgent
21
22
23class TestBubblewrap(testtools.TestCase):
24 def setUp(self):
25 super(TestBubblewrap, self).setUp()
26 self.log_fixture = self.useFixture(
27 fixtures.FakeLogger(level=logging.DEBUG))
28 self.useFixture(fixtures.NestedTempfile())
29
30 def test_bubblewrap_wraps(self):
31 bwrap = bubblewrap.BubblewrapDriver()
32 work_dir = tempfile.mkdtemp()
33 ansible_dir = tempfile.mkdtemp()
34 ssh_agent = SshAgent()
35 self.addCleanup(ssh_agent.stop)
36 ssh_agent.start()
37 po = bwrap.getPopen(work_dir=work_dir,
38 ansible_dir=ansible_dir,
39 ssh_auth_sock=ssh_agent.env['SSH_AUTH_SOCK'])
40 self.assertTrue(po.passwd_r > 2)
41 self.assertTrue(po.group_r > 2)
42 self.assertTrue(work_dir in po.command)
43 self.assertTrue(ansible_dir in po.command)
44 # Now run /usr/bin/id to verify passwd/group entries made it in
45 true_proc = po(['/usr/bin/id'], stdout=subprocess.PIPE,
46 stderr=subprocess.PIPE)
47 (output, errs) = true_proc.communicate()
48 # Make sure it printed things on stdout
49 self.assertTrue(len(output.strip()))
50 # And that it did not print things on stderr
51 self.assertEqual(0, len(errs.strip()))
52 # Make sure the _r's are closed
53 self.assertIsNone(po.passwd_r)
54 self.assertIsNone(po.group_r)