def test_nested_sections(self): bank = self._create_test_bank() top_section = BankSection(bank, "/top") mid_section = top_section.get_sub_section("/mid") bottom_section = mid_section.get_sub_section("/bottom") bottom_section.create_object("key", "value") self.assertEqual(bank.get_object("/top/mid/bottom/key"), "value")
class CheckpointCollection(object): def __init__(self, bank, bank_lease=None): super(CheckpointCollection, self).__init__() self._bank = bank self._bank_lease = bank_lease self._checkpoints_section = BankSection(bank, "/checkpoints") def list_ids(self, limit=None, marker=None): if marker is not None: marker = _checkpoint_id_to_index_file(marker) return [key[:-len(_INDEX_FILE_SUFFIX)] for key in self._checkpoints_section.list_objects( limit=limit, marker=marker) ] def get(self, checkpoint_id): # TODO(saggi): handle multiple instances of the same checkpoint return Checkpoint.get_by_section(self._checkpoints_section, self._bank_lease, checkpoint_id) def create(self, plan): # TODO(saggi): Serialize plan to checkpoint. Will be done in # future patches. return Checkpoint.create_in_section(self._checkpoints_section, self._bank_lease, self._bank.get_owner_id(), plan)
def test_delete_object(self): bank = self._create_test_bank() section = BankSection(bank, "/prefix", is_writable=True) bank.create_object("/prefix/a", "value") bank.create_object("/prefix/b", "value") bank.create_object("/prefix/c", "value") section.delete_object("a") section.delete_object("/b") section.delete_object("//c")
def test_nested_sections_read_only(self): bank = self._create_test_bank() section = BankSection(bank, "/top", is_writable=False) self.assertRaises( exception.BankReadonlyViolation, section.get_sub_section, "/mid", is_writable=True, )
def test_double_dot_key(self): bank = self._create_test_bank() section = BankSection(bank, "/prefix") self.assertRaises( exception.InvalidParameterValue, section.create_object, "/../../", "", )
def test_empty_key(self): bank = self._create_test_bank() section = BankSection(bank, "/prefix", is_writable=True) self.assertRaises( exception.InvalidParameterValue, section.create_object, "", "value", ) self.assertRaises( exception.InvalidParameterValue, section.create_object, None, "value", )
def test_read_only(self): bank = self._create_test_bank() section = BankSection(bank, "/prefix", is_writable=False) self.assertRaises( exception.BankReadonlyViolation, section.create_object, "object", "value", ) bank.create_object("/prefix/object", "value") self.assertRaises( exception.BankReadonlyViolation, section.update_object, "object", "value", ) self.assertRaises( exception.BankReadonlyViolation, section.delete_object, "object", )
def test_list_objects(self): bank = self._create_test_bank() section = BankSection(bank, "/prefix", is_writable=True) bank.create_object("/prefix/a", "value") bank.create_object("/prefixd", "value") # Should not appear section.create_object("/b", "value") section.create_object("c", "value") expected_result = ["a", "b", "c"] self.assertEqual(list(section.list_objects("/")), expected_result) self.assertEqual(list(section.list_objects("///")), expected_result) self.assertEqual(list(section.list_objects(None)), expected_result) self.assertEqual( list(section.list_objects("/", limit=2)), expected_result[:2], ) self.assertEqual( list(section.list_objects("/", limit=2, marker="b")), expected_result[2:4], )
def __init__(self, bank, bank_lease=None): super(CheckpointCollection, self).__init__() self._bank = bank self._bank_lease = bank_lease self._checkpoints_section = BankSection(bank, "/checkpoints")
def get_resource_bank_section(self, resource_id): prefix = "/resource-data/%s/%s/" % (self._id, resource_id) return BankSection(self._bank_section.bank, prefix)
def get_resource_bank_section(self, resource_id): bank = Bank(FakeBankPlugin()) return BankSection(bank, resource_id)
return def get_object(self, key): return def list_objects(self, prefix=None, limit=None, marker=None): return def delete_object(self, key): return def get_owner_id(self): return fake_bank = Bank(FakeBankPlugin()) fake_bank_section = BankSection(bank=fake_bank, prefix="fake") ResourceNode = collections.namedtuple( "ResourceNode", ["value", "child_nodes"] ) Image = collections.namedtuple( "Image", ["disk_format", "container_format", "status"] )