예제 #1
0
    def test_compose_missing_builder_id(self):
        def check_missing_id(cb, builders):
            # not ok to compose with builder_files that have no id assigned
            orig_version = cb.version
            no_id = random.randint(0, len(builders) - 1)
            # rewrite the builder files so that one has missing id
            self.save_builders(builders, missing_ids=[no_id])
            with self.assertRaises(ValueError) as cm:
                cb.compose()
            error_lines = cm.exception.message.split('\n')
            self.assertIn("Problem with builder at index %s" % no_id,
                          error_lines[0])
            self.assertIn("id attribute has not been initialised",
                          error_lines[0])
            self.assertFalse(error_lines[1:])
            self.assertEqual(orig_version, cb.version)

        # check with compose not previously called, cb has no existing metadata
        builders = self.create_sample_ringbuilders(3)
        builder_files = self.save_builders(builders)
        cb = CompositeRingBuilder(builder_files)
        check_missing_id(cb, builders)
        # now save good copies of builders and compose so this cb has
        # existing component metadata
        builder_files = self.save_builders(builders)
        cb = CompositeRingBuilder(builder_files)
        cb.compose()  # cb now has component metadata
        check_missing_id(cb, builders)
예제 #2
0
 def _make_composite_builder(self, builders):
     # helper to compose a ring, save it and sanity check it
     builder_files = self.save_builders(builders)
     cb = CompositeRingBuilder(builder_files)
     cb.compose().save(self.output_ring)
     self.check_composite_ring(self.output_ring, builders)
     return cb, builder_files
예제 #3
0
 def test_compose_duplicate_builder_ids(self):
     builders = self.create_sample_ringbuilders(3)
     builders[2]._id = builders[0]._id
     cb = CompositeRingBuilder(self.save_builders(builders))
     with self.assertRaises(ValueError) as cm:
         cb.compose()
     error_lines = cm.exception.message.split('\n')
     self.assertIn("Builder id %r used at indexes 0, 2" % builders[0].id,
                   error_lines[0])
     self.assertFalse(error_lines[1:])
     self.assertEqual(0, cb.version)
예제 #4
0
        def do_test(builder_files):
            cb = CompositeRingBuilder(builder_files)
            with self.assertRaises(ValueError) as cm:
                cb.compose()
            self.assertIn('Two or more component builders are required',
                          cm.exception.message)

            cb = CompositeRingBuilder()
            with self.assertRaises(ValueError) as cm:
                cb.compose(builder_files)
            self.assertIn('Two or more component builders are required',
                          cm.exception.message)
예제 #5
0
    def test_compose_with_builder_files(self):
        cb_file = os.path.join(self.tmpdir, 'test-composite-ring.json')
        builders = self.create_sample_ringbuilders(2)
        cb = CompositeRingBuilder(self.save_builders(builders))
        cb.compose().save(self.output_ring)
        self.check_composite_ring(self.output_ring, builders)
        cb.save(cb_file)

        for i, b in enumerate(builders):
            self.add_dev_and_rebalance(b)
        self.save_builders(builders)
        cb = CompositeRingBuilder.load(cb_file)
        cb.compose().save(self.output_ring)
        self.check_composite_ring(self.output_ring, builders)
예제 #6
0
 def test_abs_paths_persisted(self):
     cwd = os.getcwd()
     try:
         os.chdir(self.tmpdir)
         builders = self.create_sample_ringbuilders(2)
         builder_files = self.save_builders(builders)
         rel_builder_files = [os.path.basename(bf) for bf in builder_files]
         cb = CompositeRingBuilder(rel_builder_files)
         cb.compose().save(self.output_ring)
         self.check_composite_ring(self.output_ring, builders)
         cb_file = os.path.join(self.tmpdir, 'test-composite-ring.json')
         rel_cb_file = os.path.basename(cb_file)
         cb.save(rel_cb_file)
         self.check_composite_meta(rel_cb_file, rel_builder_files)
     finally:
         os.chdir(cwd)