def _create_database(self, env_name='fake_env', infra_name='__test__ mysqlinfra2'): environment = factory_physical.EnvironmentFactory( name=env_name ) databaseinfra = factory_physical.DatabaseInfraFactory( name=infra_name, user="******", password='******', engine=self.engine, plan=self.plan, ssl_configured=True, environment=environment ) hostname = factory_physical.HostFactory( ssl_expire_at=FAKE_TODAY + timedelta(days=16) ) self.instance_helper.create_instances_by_quant( instance_type=Instance.MYSQL, qt=1, infra=databaseinfra, hostname=hostname ) database = factory_logical.DatabaseFactory( name='test_db_1', databaseinfra=databaseinfra, ) return environment, databaseinfra, hostname, database
def _create_database_structure(cls): mysql_host = settings.DB_HOST mysql_port = settings.DB_PORT or 3306 cls.mysql_endpoint = '{}:{}'.format(mysql_host, mysql_port) cls.engine_type = factory_physical.EngineTypeFactory(name=cls.ENGINE) cls.engine = factory_physical.EngineFactory( engine_type=cls.engine_type) cls.disk_offering = factory_physical.DiskOfferingFactory( size_kb=524288) cls.plan = factory_physical.PlanFactory( disk_offering=cls.disk_offering, engine=cls.engine) cls.databaseinfra = factory_physical.DatabaseInfraFactory( name="__test__ mysqlinfra2", user="******", password=settings.DB_PASSWORD, endpoint=cls.mysql_endpoint, engine=cls.engine, disk_offering=cls.disk_offering, plan=cls.plan) cls.hostname = factory_physical.HostFactory() cls.instances = cls.instance_helper.create_instances_by_quant( instance_type=Instance.MYSQL, qt=cls.instances_quantity, infra=cls.databaseinfra, hostname=cls.hostname) cls.instance = cls.instances[0] cls.database = factory_logical.DatabaseFactory( name='test_db_1', databaseinfra=cls.databaseinfra, ) cls.volume = factory_physical.VolumeFactory( host=cls.hostname, used_size_kb=cls.database.used_size_in_kb)
def test_cannot_upgrade_dead(self): database = factory.DatabaseFactory() database.status = database.DEAD can_do_upgrade, error = database.can_do_upgrade() self.assertFalse(can_do_upgrade) self.assertEqual(error, ERROR_UPGRADE_IS_DEAD)
def test_connection_with_database(self): self.database = factory_logical.DatabaseFactory( name="my_db_url_name", databaseinfra=self.databaseinfra) self.assertEqual( "mysql://<user>:<password>@{}/my_db_url_name".format( self.mysql_endpoint), self.driver.get_connection(database=self.database))
def test_cannot_update_volume_used_disk_size_host_not_volume(self): database = factory.DatabaseFactory() database.databaseinfra = self.databaseinfra volume = database.update_host_disk_used_size( host_address=self.instance.address, used_size_kb=300) self.assertIsNone(volume)
def setUp(self): self.today = FAKE_TODAY self.engine_type = factory_physical.EngineTypeFactory(name='mysql') self.engine = factory_physical.EngineFactory( engine_type=self.engine_type) self.plan = factory_physical.PlanFactory(engine=self.engine) self.databaseinfra = factory_physical.DatabaseInfraFactory( name="__test__ mysqlinfra2", user="******", password='******', engine=self.engine, plan=self.plan, ssl_configured=True) self.hostname = factory_physical.HostFactory(ssl_expire_at=FAKE_TODAY + timedelta(days=16)) self.instances = self.instance_helper.create_instances_by_quant( instance_type=Instance.MYSQL, qt=1, infra=self.databaseinfra, hostname=self.hostname) self.instance = self.instances[0] self.database = factory_logical.DatabaseFactory( name='test_db_1', databaseinfra=self.databaseinfra, ) self.one_month_later = self.today + timedelta(days=30)
def setUp(self): super(ManageDatabaseRedisTestCase, self).setUp() self.database = factory_logical.DatabaseFactory(databaseinfra=self.databaseinfra) # ensure database is dropped #get fake driver driver = self.databaseinfra.get_driver() driver.remove_database(self.database)
def setUp(self): super(ManageCredentialsMongoDBTestCase, self).setUp() self.database = factory_logical.DatabaseFactory( databaseinfra=self.databaseinfra) self.credential = factory_logical.CredentialFactory( database=self.database) self.driver.create_database(self.database)
def test_cannot_delete_dead(self): database = factory.DatabaseFactory() database.status = database.DEAD can_be_deleted, error = database.can_be_deleted() self.assertFalse(can_be_deleted) self.assertEqual(error, ERROR_DELETE_DEAD.format(database.name))
def test_can_delete(self): database = factory.DatabaseFactory() database.status = database.ALIVE can_be_deleted, error = database.can_be_deleted() self.assertTrue(can_be_deleted) self.assertIsNone(error)
def test_mongodb_create_user(self, call_script): database_base1 = factory_logical.DatabaseFactory(databaseinfra=self.databaseinfra, name="base1") results = [ ' { "host": "xxx", \n"version": "2.4.6", "localTime" : ISODate("2013-09-26T20:47:56.766Z") } ', ' { "databases": [ { "name": "base1", "sizeOnDisk": 67108864 } ], "totalSize": 100663296 } ' ] def sequence_calls(*a, **kw): return results.pop(0) call_script.side_effect = sequence_calls databaseinfra_status = self.driver.info() required_envs={ "INSTANCE_CONNECTION": self.driver.get_connection(), "INSTANCE_USER": self.driver.get_user(), "INSTANCE_PASSWORD": self.driver.get_password(), } call_script.assert_any_call(MongoDB.SCRIPT, ["serverstatus"], envs=match_equality(has_entries(required_envs))) call_script.assert_any_call(MongoDB.SCRIPT, ["listdatabases"], envs=match_equality(has_entries(required_envs))) self.assertEquals("2.4.6", databaseinfra_status.version) self.assertEquals(100663296, databaseinfra_status.used_size_in_bytes) base1_status = databaseinfra_status.get_database_status("base1") self.assertEquals(database_base1, base1_status.database_model) self.assertEquals(67108864, base1_status.used_size_in_bytes)
def test_cannot_update_nfsaas_used_disk_size_host_not_nfsaas(self): database = factory.DatabaseFactory() database.databaseinfra = self.databaseinfra nfsaas_host = database.update_host_disk_used_size( host_address=self.instance.address, used_size_kb=300) self.assertIsNone(nfsaas_host)
def test_cannot_upgrade_no_equivalent_plan(self): database = factory.DatabaseFactory() database.status = database.ALIVE can_do_upgrade, error = database.can_do_upgrade() self.assertFalse(can_do_upgrade) self.assertEqual(error, ERROR_UPGRADE_NO_EQUIVALENT_PLAN)
def _create_database_structure(cls): mysql_host = settings.DB_HOST mysql_port = settings.DB_PORT or 3306 cls.mysql_endpoint = '{}:{}'.format(mysql_host, mysql_port) cls.engine_type = factory_physical.EngineTypeFactory(name='mysql') cls.engine = factory_physical.EngineFactory( engine_type=cls.engine_type) cls.disk_offering = factory_physical.DiskOfferingFactory( size_kb=524288) cls.plan = factory_physical.PlanFactory( disk_offering=cls.disk_offering, engine=cls.engine) cls.databaseinfra = factory_physical.DatabaseInfraFactory( name="__test__ mysqlinfra2", user="******", password=settings.DB_PASSWORD, endpoint=cls.mysql_endpoint, engine=cls.engine, disk_offering=cls.disk_offering, plan=cls.plan) cls.hostname = factory_physical.HostFactory() cls.instance = factory_physical.InstanceFactory( address="new_instance.localinstance", port=123, is_active=True, instance_type=Instance.MYSQL, databaseinfra=cls.databaseinfra, hostname=cls.hostname) cls.database = factory_logical.DatabaseFactory( name='test_db_1', databaseinfra=cls.databaseinfra, ) cls.nfsaas_host_attr = factory_physical.NFSaaSHostAttr( host=cls.hostname, # nfsaas_size_kb=cls.database.total_size_in_kb, nfsaas_used_size_kb=cls.database.used_size_in_kb)
def test_can_delete_in_quarantine(self): database = factory.DatabaseFactory() database.status = database.ALIVE database.is_in_quarantine = True can_be_deleted, error = database.can_be_deleted() self.assertTrue(can_be_deleted) self.assertIsNone(error)
def test_cannot_delete_protected(self): database = factory.DatabaseFactory() database.status = database.ALIVE database.is_protected = True can_be_deleted, error = database.can_be_deleted() self.assertFalse(can_be_deleted) self.assertEqual(error, ERROR_DELETE_PROTECTED.format(database.name))
def test_cannot_clone_dead(self): database = factory.DatabaseFactory() database.status = database.DEAD database.database_status = None can_be_cloned, error = database.can_be_cloned() self.assertFalse(can_be_cloned) self.assertEqual(error, ERROR_CLONE_NOT_ALIVE)
def test_cannot_clone_in_quarantine(self): database = factory.DatabaseFactory() database.status = database.ALIVE database.is_in_quarantine = True can_be_cloned, error = database.can_be_cloned() self.assertFalse(can_be_cloned) self.assertEqual(error, ERROR_CLONE_IN_QUARANTINE)
def test_cannot_clone_no_persistence(self): database = factory.DatabaseFactory() database.status = database.ALIVE database.plan.has_persistence = False can_be_cloned, error = database.can_be_cloned() self.assertFalse(can_be_cloned) self.assertEqual(error, ERROR_CLONE_WITHOUT_PERSISTENCE)
def test_can_upgrade(self): database = factory.DatabaseFactory() database.status = database.ALIVE database.databaseinfra.plan.engine_equivalent_plan = self.plan_upgrade can_do_upgrade, error = database.can_do_upgrade() self.assertTrue(can_do_upgrade) self.assertIsNone(error)
def test_cannot_upgrade_dead(self): database = factory.DatabaseFactory() database.databaseinfra.plan.engine_equivalent_plan = self.plan_upgrade database.status = database.DEAD can_do_upgrade, error = database.can_do_upgrade() self.assertFalse(can_do_upgrade) self.assertEqual(error, ERROR_UPGRADE_IS_DEAD)
def setUp(self): self.task = TaskHistoryFactory() self.instance = physical_factory.InstanceFactory() self.databaseinfra = self.instance.databaseinfra self.database = logical_factory.DatabaseFactory() self.database.databaseinfra = self.databaseinfra self.database.save()
def setUp(self): super(ManageDatabaseMongoDBTestCase, self).setUp() self.database = factory_logical.DatabaseFactory( databaseinfra=self.databaseinfra) self.instance.address = os.getenv('TESTS_MONGODB_HOST', '127.0.0.1') self.instance.save() # ensure database is dropped self.driver_client.drop_database(self.database.name)
def test_current_task_lock(self): database = factory.DatabaseFactory() task1 = TaskHistoryFactory() task2 = TaskHistoryFactory() database.pin_task(task1) self.assertFalse(database.pin_task(task2)) database.unpin_task() self.assertTrue(database.pin_task(task2))
def test_cannot_upgrade_in_quarantine(self): database = factory.DatabaseFactory() database.status = database.ALIVE database.is_in_quarantine = True can_do_upgrade, error = database.can_do_upgrade() self.assertFalse(can_do_upgrade) self.assertEqual(error, ERROR_UPGRADE_IN_QUARANTINE)
def test_connection_with_database(self): self.database = factory_logical.DatabaseFactory( name="my_db_url_name", databaseinfra=self.databaseinfra) expected_conn = ("mongodb://<user>:<password>" "@{}/my_db_url_name").format(self.instance_endpoint) self.assertEqual(expected_conn, self.driver.get_connection(database=self.database))
def test_connection_with_database_and_replica(self, get_replica_name): self.instance = factory_physical.InstanceFactory( databaseinfra=self.databaseinfra, address='127.0.0.2', port=27018) get_replica_name.return_value = 'my_repl' self.database = factory_logical.DatabaseFactory( name="my_db_url_name", databaseinfra=self.databaseinfra) self.assertEqual( "mongodb://<user>:<password>@127.0.0.1:27017,127.0.0.2:27018/my_db_url_name?replicaSet=my_repl", self.driver.get_connection(database=self.database))
def setUp(self): super(ManageDatabaseMySQLTestCase, self).setUp() self.database = factory_logical.DatabaseFactory( databaseinfra=self.databaseinfra) # ensure database is dropped # get fake driver self.instance.address = settings.DB_HOST self.instance.save() driver = self.databaseinfra.get_driver() driver.remove_database(self.database)
def setUp(self): super(ManageCredentialsMongoDBTestCase, self).setUp() self.database = factory_logical.DatabaseFactory( databaseinfra=self.databaseinfra) self.credential = factory_logical.CredentialFactory( database=self.database) self.instance.address = os.getenv('TESTS_MONGODB_HOST', '127.0.0.1') # self.instance.address = '127.0.0.1' self.instance.save() self.driver.create_database(self.database)
def test_cannot_edit_database_name(self): database = factory.DatabaseFactory(name="w h a t", databaseinfra=self.databaseinfra, environment=self.environment) self.assertTrue(database.id) database.name = "super3" self.assertRaises(AttributeError, database.save)