def test_resource_graph(self): bank = bank_plugin.Bank(_InMemoryBankPlugin()) bank_lease = _InMemoryLeasePlugin() checkpoints_section = bank_plugin.BankSection(bank, "/checkpoints") indices_section = bank_plugin.BankSection(bank, "/indices") owner_id = bank.get_owner_id() plan = fake_protection_plan() cp = checkpoint.Checkpoint.create_in_section( checkpoints_section=checkpoints_section, indices_section=indices_section, bank_lease=bank_lease, owner_id=owner_id, plan=plan) resource_graph = graph.build_graph([A, B, C, D], resource_map.__getitem__) cp.resource_graph = resource_graph cp.commit() checkpoint_data = cp._md_cache self.assertEqual( checkpoint_data, bank._plugin.get_object( "/checkpoints/%s/%s" % (checkpoint_data["id"], checkpoint._INDEX_FILE_NAME))) self.assertEqual(len(resource_graph), len(cp.resource_graph)) for start_node in resource_graph: self.assertIn(start_node, cp.resource_graph)
def __init__(self, provider_config): super(PluggableProtectionProvider, self).__init__() self._config = provider_config self._id = self._config.provider.id self._name = self._config.provider.name self._description = self._config.provider.description self._extended_info_schema = { 'options_schema': {}, 'restore_schema': {}, 'saved_info_schema': {} } self.checkpoint_collection = None self._bank_plugin = None self._plugin_map = {} if hasattr(self._config.provider, 'bank') \ and not self._config.provider.bank: raise ImportError(_("Empty bank")) self._load_bank(self._config.provider.bank) self._bank = bank_plugin.Bank(self._bank_plugin) self.checkpoint_collection = CheckpointCollection(self._bank) if hasattr(self._config.provider, 'plugin'): for plugin_name in self._config.provider.plugin: if not plugin_name: raise ImportError(_("Empty protection plugin")) self._register_plugin(plugin_name)
def _get_checkpoint(self): fake_bank = bank_plugin.Bank(fakes.FakeBankPlugin()) fake_bank_section = bank_plugin.BankSection( bank=fake_bank, section="fake" ) return FakeCheckpoint(fake_bank_section)
def test_create_in_section(self): bank = bank_plugin.Bank(_InMemoryBankPlugin()) bank_lease = _InMemoryLeasePlugin() checkpoints_section = bank_plugin.BankSection(bank, "/checkpoints") indices_section = bank_plugin.BankSection(bank, "/indices") owner_id = bank.get_owner_id() plan = fake_protection_plan() cp = checkpoint.Checkpoint.create_in_section( checkpoints_section=checkpoints_section, indices_section=indices_section, bank_lease=bank_lease, owner_id=owner_id, plan=plan) checkpoint_data = cp._md_cache self.assertEqual( checkpoint_data, bank._plugin.get_object( "/checkpoints/%s/%s" % (checkpoint_data['id'], checkpoint._INDEX_FILE_NAME))) self.assertEqual(owner_id, cp.owner_id) self.assertEqual("protecting", cp.status)