def test_returns_builder_when_given_target_mount_point(self): tags = vmdb.Tags() tags.append("first") tags.set_builder_mount_point("first", "/mnt/foo") tags.set_target_mount_point("first", "/boot") self.assertEqual(tags.get_builder_from_target_mount_point("/boot"), "/mnt/foo")
def process_args(self, args): if len(args) != 1: sys.exit("No image specification was given on the command line.") vmdb.set_verbose_progress(self.settings['verbose']) spec = self.load_spec_file(args[0]) state = vmdb.State() state.tags = vmdb.Tags() params = self.create_template_vars(state) steps = spec.get_steps(params) # Check that we have step runners for each step for step in steps: self.step_runners.find(step) steps_taken, core_meltdown = self.run_steps(steps, state) if core_meltdown: vmdb.progress('Something went wrong, cleaning up!') else: vmdb.progress('All went fine, cleaning up.') self.run_teardowns(steps_taken, state) if core_meltdown: logging.error('An error occurred, exiting with non-zero exit code') sys.exit(1)
def test_adds_builder_mount_point(self): tags = vmdb.Tags() tags.append("first") tags.set_builder_mount_point("first", "/mnt/foo") self.assertEqual(tags.get_tags(), ["first"]) self.assertEqual(tags.get_dev("first"), None) self.assertEqual(tags.get_builder_mount_point("first"), "/mnt/foo")
def test_adds_mount_point(self): tags = vmdb.Tags() tags.append('first') tags.set_mount_point('first', '/mnt/foo') self.assertEqual(tags.get_tags(), ['first']) self.assertEqual(tags.get_dev('first'), None) self.assertEqual(tags.get_mount_point('first'), '/mnt/foo')
def build(self): spec = self.load_spec_file(self._specfile) state = vmdb.State() state.tags = vmdb.Tags() state.arch = vmdb.runcmd(["dpkg", "--print-architecture" ]).decode("UTF-8").strip() self.add_template_vars(state.as_dict()) steps = spec.get_steps(self._tvars) # Check that we have step runners for each step self.load_step_runners() for step in steps: self.step_runners.find(step) steps_taken, core_meltdown = self.run_steps(steps, state) if core_meltdown: vmdb.progress("Something went wrong, cleaning up!") self.run_teardowns(steps_taken, state) else: self.run_teardowns(steps_taken, state) vmdb.progress("All went fine.") if core_meltdown: logging.error("An error occurred, exiting") sys.exit(1)
def test_set_target_mount_point_raises_error_for_double_target_mount_point( self): tags = vmdb.Tags() tags.append("first") tags.set_target_mount_point("first", "/boot") with self.assertRaises(vmdb.AlreadyHasTargetMountPoint): tags.set_target_mount_point("first", "/")
def test_get_dev_raises_error_for_unknown_tag(self): tags = vmdb.Tags() with self.assertRaises(vmdb.UnknownTag): tags.get_dev("does-not-exist")
def test_remembers_order(self): tags = vmdb.Tags() tags.append("foo") tags.append("bar") self.assertTrue(tags.get_tags(), ["foo", "bar"])
def test_tells_if_tag_exists(self): tags = vmdb.Tags() self.assertFalse(tags.has_tag("foo")) tags.append("foo") self.assertTrue(tags.has_tag("foo")) self.assertEqual(tags.get_tags(), ["foo"])
def test_set_builder_mount_point_raises_error_for_unknown_tag(self): tags = vmdb.Tags() with self.assertRaises(vmdb.UnknownTag): tags.set_builder_mount_point("first", "/mnt/foo")
def test_builder_mount_point_can_be_made_cached(self): tags = vmdb.Tags() tags.append("first") tags.set_builder_mount_point("first", "/mnt/foo", cached=True) self.assertTrue(tags.is_cached("first"))
def test_set_target_mount_point(self): tags = vmdb.Tags() tags.append("first") tags.set_target_mount_point("first", "/boot") self.assertEqual(tags.get_target_mount_point("first"), "/boot")
def test_set_fstype_raises_error_for_double_fstype(self): tags = vmdb.Tags() tags.append("first") tags.set_fstype("first", "ext3") with self.assertRaises(vmdb.AlreadyHasFsType): tags.set_fstype("first", "ext4")
def test_set_fstype(self): tags = vmdb.Tags() tags.append("first") tags.set_fstype("first", "ext4") self.assertEqual(tags.get_fstype("first"), "ext4")
def test_set_dev_raises_error_for_double_dev(self): tags = vmdb.Tags() tags.append("first") tags.set_dev("first", "/dev/foo") with self.assertRaises(vmdb.AlreadyHasDev): tags.set_dev("first", "/dev/foo")
def test_set_mount_point_raises_error_for_double_mount(self): tags = vmdb.Tags() tags.append('first') tags.set_mount_point('first', '/mnt/foo') with self.assertRaises(vmdb.AlreadyMounted): tags.set_mount_point('first', '/mnt/foo')
def test_set_mount_point_raises_error_for_unknown_tag(self): tags = vmdb.Tags() with self.assertRaises(vmdb.UnknownTag): tags.set_mount_point('first', '/mnt/foo')
def test_getting_builder_mount_point_raises_error_for_unknown_tag(self): tags = vmdb.Tags() with self.assertRaises(vmdb.UnknownTag): tags.get_builder_mount_point("does-not-exist")
def test_raises_error_for_reused_tag(self): tags = vmdb.Tags() tags.append("tag") with self.assertRaises(vmdb.TagInUse): tags.append("tag")
def test_raises_error_if_both_mount_points_not_set(self): tags = vmdb.Tags() tags.append("first") tags.set_target_mount_point("first", "/boot") with self.assertRaises(vmdb.NeedBothMountPoints): tags.get_builder_from_target_mount_point("/")
def test_builder_mount_point_is_uncached_by_default(self): tags = vmdb.Tags() tags.append("first") tags.set_builder_mount_point("first", "/mnt/foo") self.assertFalse(tags.is_cached("first"))
def test_tells_if_tag_is_used(self): tags = vmdb.Tags() self.assertFalse(tags.has_tag('foo')) tags.append('foo') self.assertTrue(tags.has_tag('foo')) self.assertEqual(tags.get_tags(), ['foo'])
def test_set_dev_raises_error_for_unknown_tag(self): tags = vmdb.Tags() with self.assertRaises(vmdb.UnknownTag): tags.set_dev("first", "/mnt/foo")
def test_lists_no_tags_initially(self): tags = vmdb.Tags() self.assertEqual(tags.get_tags(), [])
def test_set_builder_mount_point_raises_error_for_double_mount(self): tags = vmdb.Tags() tags.append("first") tags.set_builder_mount_point("first", "/mnt/foo") with self.assertRaises(vmdb.AlreadyMounted): tags.set_builder_mount_point("first", "/mnt/foo")
def test_remembers_order(self): tags = vmdb.Tags() tags.append('foo') tags.append('bar') self.assertTrue(tags.get_tags(), ['foo', 'bar'])