Example #1
0
 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")
Example #2
0
 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")
Example #3
0
 def test_delete_object(self):
     bank = self._create_test_bank()
     section = BankSection(bank, "/prefix", is_writable=True)
     bank.update_object("/prefix/a", "value")
     bank.update_object("/prefix/b", "value")
     bank.update_object("/prefix/c", "value")
     section.delete_object("a")
     section.delete_object("/b")
     section.delete_object("//c")
Example #4
0
    def test_nested_sections_list(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")
        keys = ["KeyA", "KeyB", "KeyC"]
        for key in keys:
            bottom_section.update_object(key, "value")

        list_result = set(bottom_section.list_objects(prefix="Key"))
        self.assertEqual(set(keys), list_result)
        self.assertEqual(
            keys[:2],
            list(bottom_section.list_objects("/", limit=2)))
        self.assertEqual(
            keys[2:4],
            list(bottom_section.list_objects("/", limit=2, marker="KeyB")))
Example #5
0
 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,
     )
Example #6
0
 def test_double_dot_key(self):
     bank = self._create_test_bank()
     section = BankSection(bank, "/prefix")
     self.assertRaises(
         exception.InvalidParameterValue,
         section.update_object,
         "/../../",
         "",
     )
Example #7
0
 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],
     )
Example #8
0
 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")
Example #9
0
 def test_list_objects_with_extra_prefix_and_marker(self):
     bank = self._create_test_bank()
     section = BankSection(bank, "/prefix", is_writable=True)
     section.update_object("prefix1/KeyA", "value")
     section.update_object("prefix2/KeyB", "value")
     section.update_object("prefix2/KeyC", "value")
     expected_result = ["prefix2/KeyC"]
     self.assertEqual(
         expected_result,
         list(section.list_objects('/prefix2/', marker="KeyB"))
     )
Example #10
0
 def test_empty_key(self):
     bank = self._create_test_bank()
     section = BankSection(bank, "/prefix", is_writable=True)
     self.assertRaises(
         exception.InvalidParameterValue,
         section.update_object,
         "",
         "value",
     )
     self.assertRaises(
         exception.InvalidParameterValue,
         section.update_object,
         None,
         "value",
     )
Example #11
0
 def test_read_only(self):
     bank = self._create_test_bank()
     section = BankSection(bank, "/prefix", is_writable=False)
     self.assertRaises(
         exception.BankReadonlyViolation,
         section.update_object,
         "object",
         "value",
     )
     bank.update_object("/prefix/object", "value")
     self.assertRaises(
         exception.BankReadonlyViolation,
         section.update_object,
         "object",
         "value",
     )
     self.assertRaises(
         exception.BankReadonlyViolation,
         section.delete_object,
         "object",
     )
Example #12
0
 def get_resource_bank_section(self, resource_id):
     bank = Bank(FakeBankPlugin())
     return BankSection(bank, resource_id)
Example #13
0
 def get_resource_bank_section(self, resource_id):
     return BankSection(
         bank=fake_bank,
         section="/resource_data/%s/%s" % (self.id, resource_id)
     )
Example #14
0
 def test_list_objects(self):
     bank = self._create_test_bank()
     section = BankSection(bank, "/prefix", is_writable=True)
     bank.update_object("/prefix/KeyA", "value")
     bank.update_object("/prefix", "value")
     bank.update_object("/prefixKeyD", "value")  # Should not appear
     section.update_object("/KeyB", "value")
     section.update_object("KeyC", "value")
     expected_result = ["KeyA", "KeyB", "KeyC"]
     self.assertEqual(expected_result, list(section.list_objects("/")))
     self.assertEqual(expected_result, list(section.list_objects("///")))
     self.assertEqual(expected_result, list(section.list_objects(None)))
     self.assertEqual(expected_result, list(section.list_objects("Key")))
     self.assertEqual(
         expected_result[:2],
         list(section.list_objects("/", limit=2)))
     self.assertEqual(
         expected_result[2:4],
         list(section.list_objects("/", limit=2, marker="KeyB")))
                    objects_name.append(key.lstrip(prefix))
        else:
            objects_name = self._objects.keys()
        return objects_name

    def delete_object(self, key):
        self._objects.pop(key)

    def get_owner_id(self):
        return


fake_checkpointid = "checkpoint_id"
fake_project_id = "abcd"
fake_bank = Bank(FakeBankPlugin())
fake_bank_section = BankSection(bank=fake_bank, section="fake")

ResourceNode = collections.namedtuple("ResourceNode", ["value"])


class FakeCheckpoint(object):
    def __init__(self):
        self.bank_section = fake_bank_section

    def get_resource_bank_section(self, resource_id):
        return self.bank_section


class NeutronProtectionPluginTest(base.TestCase):
    def setUp(self):
        super(NeutronProtectionPluginTest, self).setUp()
    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"])


class CheckpointCollection(object):
    def __init__(self):
        self.bank_section = fake_bank_section

    def get_resource_bank_section(self, resource_id):
        return self.bank_section

Example #17
0
 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],
     )