Example #1
0
 def test_storage_use_uri_conf(self):
     conf = {
         "DBAAS_MONGODB_ENDPOINT": "mongodb://127.0.0.1:27017/some_other_db",
         "MONGO_URI": "mongodb://127.0.0.1:27017/ignored",
     }
     storage.MongoDBStorage(conf)._hosts_collection().remove()
     host_config = {
         "HOST_ID": "fake-id-x"
     }
     host_config.update(conf)
     h1 = Host.create('fake', 'my-group1', host_config)
     stor = h1.storage()
     self.assertEqual(stor.mongo_database, "some_other_db")
     self.assertEqual(stor.db.name, "some_other_db")
     h1.destroy()
     db_host = Host.find('fake-id-x')
     self.assertIsNone(db_host)
     conf = {
         "MONGO_URI": "mongodb://127.0.0.1:27017/now_used",
     }
     storage.MongoDBStorage(conf)._hosts_collection().remove()
     host_config = {
         "HOST_ID": "fake-id-x"
     }
     host_config.update(conf)
     h1 = Host.create('fake', 'my-group1', host_config)
     stor = h1.storage()
     self.assertEqual(stor.mongo_database, "now_used")
     self.assertEqual(stor.db.name, "now_used")
     h1.destroy()
     db_host = Host.find('fake-id-x')
     self.assertIsNone(db_host)
Example #2
0
 def test_storage_use_uri_conf(self):
     conf = {
         "DBAAS_MONGODB_ENDPOINT":
         "mongodb://127.0.0.1:27017/some_other_db",
         "MONGO_URI": "mongodb://127.0.0.1:27017/ignored",
     }
     storage.MongoDBStorage(conf)._hosts_collection().remove()
     host_config = {"HOST_ID": "fake-id-x"}
     host_config.update(conf)
     h1 = Host.create('fake', 'my-group1', host_config)
     stor = h1.storage()
     self.assertEqual(stor.mongo_database, "some_other_db")
     self.assertEqual(stor.db.name, "some_other_db")
     h1.destroy()
     db_host = Host.find('fake-id-x')
     self.assertIsNone(db_host)
     conf = {
         "MONGO_URI": "mongodb://127.0.0.1:27017/now_used",
     }
     storage.MongoDBStorage(conf)._hosts_collection().remove()
     host_config = {"HOST_ID": "fake-id-x"}
     host_config.update(conf)
     h1 = Host.create('fake', 'my-group1', host_config)
     stor = h1.storage()
     self.assertEqual(stor.mongo_database, "now_used")
     self.assertEqual(stor.db.name, "now_used")
     h1.destroy()
     db_host = Host.find('fake-id-x')
     self.assertIsNone(db_host)
Example #3
0
 def test_destroy_ignores_manager_error(self, log):
     host = Host.create('fake', 'my-group', {"HOST_ID": "explode"})
     self.assertEqual(host.id, "explode")
     host.destroy()
     self.assertEqual(log.call_args, call("Error trying to destroy host 'explode' "
                                          "in 'fake': failure to destroy"))
     db_host = Host.find('explode')
     self.assertIsNone(db_host)
Example #4
0
 def test_restore_log_and_raises_exception_on_error(self, log):
     host = Host.create('fake', 'my-group', {"HOST_ID": "explode"})
     self.assertEqual(host.id, "explode")
     self.assertRaises(Exception, host.restore)
     self.assertEqual(log.call_args, call("Error trying to restore host 'explode' "
                                          "in 'fake': failure to restore"))
     db_host = Host.find('explode')
     self.assertEqual(db_host.id, "explode")
Example #5
0
 def test_start_log_and_raises_exception_on_error(self, log):
     host = Host.create('fake', 'my-group', {"HOST_ID": "explode"})
     self.assertEqual(host.id, "explode")
     self.assertRaises(Exception, host.start)
     self.assertEqual(log.call_args, call("Error trying to start host 'explode' "
                                          "in 'fake': failure to start"))
     db_host = Host.find('explode')
     self.assertEqual(db_host.id, "explode")
Example #6
0
 def test_destroy_ignores_manager_error(self, log):
     host = Host.create('fake', 'my-group', {"HOST_ID": "explode"})
     self.assertEqual(host.id, "explode")
     host.destroy()
     self.assertEqual(log.call_args, call("Error trying to destroy host 'explode' "
                                          "in 'fake': failure to destroy"))
     db_host = Host.find('explode')
     self.assertIsNone(db_host)
Example #7
0
 def test_storage_use_database_conf(self):
     storage.MongoDBStorage({"MONGO_DATABASE": "alternative_host_manager"})._hosts_collection().remove()
     h1 = Host.create('fake', 'my-group1', {
         "HOST_ID": "fake-id-x", "MONGO_DATABASE": "alternative_host_manager"
     })
     stor = h1.storage()
     self.assertEqual(stor.mongo_database, "alternative_host_manager")
     self.assertEqual(stor.db.name, "alternative_host_manager")
     h1.destroy()
     db_host = Host.find('fake-id-x')
     self.assertIsNone(db_host)
Example #8
0
 def test_storage_use_database_conf(self):
     storage.MongoDBStorage({"MONGO_DATABASE": "alternative_host_manager"})._hosts_collection().remove()
     h1 = Host.create('fake', 'my-group1', {
         "HOST_ID": "fake-id-x", "MONGO_DATABASE": "alternative_host_manager"
     })
     stor = h1.storage()
     self.assertEqual(stor.mongo_database, "alternative_host_manager")
     self.assertEqual(stor.db.name, "alternative_host_manager")
     h1.destroy()
     db_host = Host.find('fake-id-x')
     self.assertIsNone(db_host)
Example #9
0
 def test_create(self):
     conf = {"HOST_ID": "fake-id"}
     host = Host.create('fake', 'my-group', conf)
     self.assertEqual(host.id, "fake-id")
     self.assertEqual(host.dns_name, "fake-id.my-group.com")
     self.assertEqual(host.manager, "fake")
     self.assertEqual(host.group, "my-group")
     self.assertEqual(host.config, conf)
     self.assertEqual(host.alternative_id, 0)
     db_host = Host.find('fake-id', conf=conf)
     self.assertEqual(db_host.id, "fake-id")
     self.assertEqual(db_host.dns_name, "fake-id.my-group.com")
     self.assertEqual(db_host.manager, "fake")
     self.assertEqual(db_host.group, "my-group")
     self.assertEqual(db_host.config, conf)
     self.assertEqual(db_host.alternative_id, 0)
Example #10
0
 def test_create(self):
     conf = {"HOST_ID": "fake-id"}
     host = Host.create('fake', 'my-group', conf)
     self.assertEqual(host.id, "fake-id")
     self.assertEqual(host.dns_name, "fake-id.my-group.com")
     self.assertEqual(host.manager, "fake")
     self.assertEqual(host.group, "my-group")
     self.assertEqual(host.config, conf)
     self.assertEqual(host.alternative_id, 0)
     db_host = Host.find('fake-id', conf=conf)
     self.assertEqual(db_host.id, "fake-id")
     self.assertEqual(db_host.dns_name, "fake-id.my-group.com")
     self.assertEqual(db_host.manager, "fake")
     self.assertEqual(db_host.group, "my-group")
     self.assertEqual(db_host.config, conf)
     self.assertEqual(db_host.alternative_id, 0)
Example #11
0
 def test_destroy(self):
     host = Host.create('fake', 'my-group', {"HOST_ID": "fake-id"})
     self.assertEqual(host.id, "fake-id")
     host.destroy()
     db_host = Host.find('fake-id')
     self.assertIsNone(db_host)
Example #12
0
 def test_destroy(self):
     host = Host.create('fake', 'my-group', {"HOST_ID": "fake-id"})
     self.assertEqual(host.id, "fake-id")
     host.destroy()
     db_host = Host.find('fake-id')
     self.assertIsNone(db_host)
Example #13
0
 def test_destroy_ignores_manager_error(self):
     host = Host.create('fake', 'my-group', {"HOST_ID": "explode"})
     self.assertEqual(host.id, "explode")
     host.destroy()
     db_host = Host.find('explode')
     self.assertIsNone(db_host)