class TestCase(unittest.TestCase): def setUp(self): self.directory = tempfile.mkdtemp() self.ctx = VagrantContext(self.directory) self.ctx.rewrite_vagrantfile(self.vagrantfile) def tearDown(self): self.ctx.destroy() shutil.rmtree(self.directory)
def setUpClass(cls): '''Create and launch context''' ensure_test_base_box() cls.directory = tempfile.mkdtemp() cls.ctx = VagrantContext(cls.directory) cls.ctx.rewrite_vagrantfile(cls.vagrantfile) cls.ctx.up()
def testSimpleBaseBox(self): ensure_test_base_box() # Build a base box, installing some packages boxname = 'test-box-%s' % uuid.uuid4() test_packages = ['sl'] test_file = '~/.basebox-test' test_file_content = 'testing box building' @basebox(name=boxname, base=TEST_BASE_BOX) def buildbox(): for pkg in test_packages: sudo('apt-get install -y %s' % pkg) run('echo "%s" > %s' % (test_file_content, test_file)) buildbox() # Ensure that the box got installed self.assertIn(boxname, run('vagrant box list').splitlines()) # Bring up a box based on the newly installed box, and test it for # the things we just installed tempdir = tempfile.mkdtemp() ctx = VagrantContext(tempdir) ctx.rewrite_vagrantfile(''' Vagrant::Config.run do |config| config.vm.box = '%s' end ''' % boxname) with ctx.connect(), settings(warn_only=True): for pkg in test_packages: self.assertIn('installed', run('dpkg -s %s | grep Status' % pkg)) self.assertEqual(run('cat %s' % test_file), test_file_content)
def setUp(self): self.directory = tempfile.mkdtemp() self.ctx = VagrantContext(self.directory) self.ctx.rewrite_vagrantfile(self.vagrantfile)