Ejemplo n.º 1
0
    def test_database_initializing(self, task_register_mock):
        DatabaseHelper.create(status=Database.INITIALIZING)
        task_register_mock.return_value = self.task_history
        check_databases_status()

        self.assertEqual(self.task_history.task_status, 'SUCCESS')
        self.assertIn('All databases were checked.', self.task_history.details)
 def test_current_hour_with_pending_backup(self, get_worker_name_mock,
                                           task_register, save_backup_group,
                                           make_instance_snapshot_backup):
     infra_mock = InfraHelper.create(name='pending_backup_test',
                                     backup_hour=self.backup_hour - 1,
                                     plan__has_persistence=True,
                                     environment=self.dev_env,
                                     plan=self.plan)
     DatabaseHelper.create(databaseinfra=infra_mock,
                           environment=self.dev_env)
     instance_mock = mommy.make('Instance', databaseinfra=infra_mock)
     get_worker_name_mock.return_value = 'test'
     group = BackupGroup()
     save_backup_group.return_value = group
     make_instance_snapshot_backup.return_value.status.return_value = (
         Snapshot.SUCCESS)
     make_databases_backup()
     calls = [
         call(current_hour=self.backup_hour,
              instance=self.instance,
              error={},
              group=group),
         call(current_hour=self.backup_hour,
              instance=instance_mock,
              error={},
              group=group)
     ]
     make_instance_snapshot_backup.assert_has_calls(calls, any_order=True)
Ejemplo n.º 3
0
    def test_database_alive(self, task_register_mock):
        DatabaseHelper.create(status=Database.ALIVE, _quantity=4)
        task_register_mock.return_value = self.task_history
        check_databases_status()

        self.assertEqual(self.task_history.task_status, 'SUCCESS')
        self.assertIn('All databases are alive.', self.task_history.details)
 def test_current_hour_without_pending_backup(
         self, get_worker_name_mock, task_register, save_backup_group,
         make_instance_snapshot_backup):
     infra_mock = InfraHelper.create(
         name='backup_test',
         backup_hour=self.backup_hour - 1,
         plan__has_persistence=True,
         environment=self.dev_env,
         plan=self.plan,
     )
     DatabaseHelper.create(databaseinfra=infra_mock,
                           environment=self.dev_env)
     instance_mock = mommy.make('Instance', databaseinfra=infra_mock)
     get_worker_name_mock.return_value = 'test'
     group = BackupGroup()
     save_backup_group.return_value = group
     snapshot = mommy.make('Snapshot',
                           instance=instance_mock,
                           group=group,
                           status=Snapshot.SUCCESS,
                           end_at=FAKE_NOW - timedelta(hours=1))
     make_instance_snapshot_backup.return_value = snapshot
     make_databases_backup()
     make_instance_snapshot_backup.assert_called_once_with(
         current_hour=self.backup_hour,
         instance=self.instance,
         error={},
         group=group)
Ejemplo n.º 5
0
    def test_database_dead(self, task_register_mock):
        DatabaseHelper.create(
            name=seq('test'), status=Database.DEAD, _quantity=4
        )
        task_register_mock.return_value = self.task_history
        check_databases_status()

        self.assertEqual(self.task_history.task_status, 'ERROR')
        self.assertIn('Dead', self.task_history.details)
        self.assertIn('test1', self.task_history.details)
        self.assertIn('test2', self.task_history.details)
        self.assertIn('test3', self.task_history.details)
        self.assertIn('test4', self.task_history.details)
    def test_database_dead(self, task_register_mock):
        database = DatabaseHelper.create(name='test', status=Database.DEAD)
        task_register_mock.return_value = self.task_history
        check_database_is_alive(database, wait=0)

        self.assertEqual(self.task_history.task_status, 'ERROR')
        self.assertIn('Database test is Dead', self.task_history.details)
    def test_database_alive(self, task_register_mock):
        database = DatabaseHelper.create(name='test', status=Database.ALIVE)
        task_register_mock.return_value = self.task_history
        check_database_is_alive(database, wait=0)

        self.assertEqual(self.task_history.task_status, 'SUCCESS')
        self.assertIn('Database test is Alive', self.task_history.details)
    def test_database_alert(self, task_register_mock):
        database = DatabaseHelper.create(name='test', status=Database.ALERT)
        task_register_mock.return_value = self.task_history
        check_database_is_alive(database)

        self.assertEqual(self.task_history.task_status, 'ERROR')
        self.assertIn('Database test is Alert', self.task_history.details)
Ejemplo n.º 9
0
    def test_database_dead(self, check_database_is_alive, task_register_mock):
        database = DatabaseHelper.create(status=Database.DEAD)
        task_register_mock.return_value = self.task_history
        check_databases_status()

        check_database_is_alive.assert_called_with(database)
        self.assertEqual(self.task_history.task_status, 'SUCCESS')
        self.assertIn('All databases were checked.', self.task_history.details)
    def setUp(self):
        self.backup_hour = 5
        self.year = 2020
        self.month = 1
        self.day = 1

        mommy.make(
            'Configuration', name='backup_hour', value=str(self.backup_hour)
        )
        mommy.make(
            'Configuration', name='make_database_backup_hour',
            value=','.join(map(str, FAKE_MAKE_DATABASE_BACKUP_HOUR))
        )
        self.dev_env = mommy.make(
            'Environment', name='dev', stage=Environment.DEV
        )
        mommy.make('Environment', name='prod', stage=Environment.PROD)
        self.engine_type = mommy.make(
            'EngineType', name='mysql'
        )
        self.engine = mommy.make(
            'Engine', engine_type=self.engine_type
        )
        self.replication_topology = mommy.make(
            'ReplicationTopology',
            name='MySQL Single 5.7.25',
            class_path='drivers.replication_topologies.mysql.MySQLSingle'
        )
        self.plan = mommy.make(
            'Plan', engine=self.engine,
            replication_topology=self.replication_topology
        )
        self.infra = mommy.make(
            'DatabaseInfra', backup_hour=self.backup_hour,
            plan__has_persistence=True,
            environment=self.dev_env,
            plan=self.plan,
            endpoint='127.0.0.1:1111'
        )
        self.host = mommy.make_recipe(
              'physical.host',
       )
        self.instance = mommy.make(
            'Instance', databaseinfra=self.infra,
            hostname=self.host
        )
        self.volume = mommy.make(
            'Volume', host=self.host
        )
        self.database = DatabaseHelper.create(
            environment=self.dev_env,
            databaseinfra=self.infra
        )
        self.group = BackupGroup()
    def test_database_initializing(self, task_register_mock):
        database = DatabaseHelper.create(
            name='test', status=Database.INITIALIZING
        )
        task_register_mock.return_value = self.task_history
        check_database_is_alive(database)

        self.assertEqual(self.task_history.task_status, 'SUCCESS')
        self.assertIn('Database test is Initializing',
                      self.task_history.details
                      )
Ejemplo n.º 12
0
    def test_databases_with_different_status(self, task_register_mock):
        DatabaseHelper.create(status=Database.INITIALIZING)
        DatabaseHelper.create(status=Database.ALIVE)
        database_alert = DatabaseHelper.create(status=Database.ALERT)
        database_dead = DatabaseHelper.create(status=Database.DEAD)
        task_register_mock.return_value = self.task_history
        check_databases_status()

        self.assertEqual(self.task_history.task_status, 'ERROR')
        self.assertIn('Alert', self.task_history.details)
        self.assertIn('Dead', self.task_history.details)
        self.assertIn(database_dead.name, self.task_history.details)
        self.assertIn(database_alert.name, self.task_history.details)
Ejemplo n.º 13
0
 def setUp(self):
     self.fake_request = MagicMock()
     self.database = DatabaseHelper.create()
     self.fake_task_schedule = mommy.make(
         'maintenance.TaskSchedule',
         database=self.database
     )
     self.fake_previous_step_manager = mommy.make(
         'maintenance.UpdateSsl',
         database=self.database,
         current_step=9,
         can_do_retry=1,
         task_schedule=self.fake_task_schedule
     )
     self.fake_task = mommy.make(
         'TaskHistory',
         task_name='fake.task.name'
     )
     self._configure_job()
Ejemplo n.º 14
0
    def test_databases_with_different_status(self, check_database_is_alive,
                                             task_register_mock):
        DatabaseHelper.create(status=Database.INITIALIZING)
        DatabaseHelper.create(status=Database.ALIVE)
        database_alert = DatabaseHelper.create(status=Database.ALERT)
        database_dead = DatabaseHelper.create(status=Database.DEAD)
        task_register_mock.return_value = self.task_history

        calls = [call(database_dead), call(database_alert)]

        check_databases_status()

        check_database_is_alive.assert_has_calls(calls)
        self.assertEqual(self.task_history.task_status, 'SUCCESS')
        self.assertIn('All databases were checked.', self.task_history.details)
    def setUp(self):
        self.backup_hour = 5
        self.year = 2020
        self.month = 1
        self.day = 1

        mommy.make('Configuration',
                   name='backup_hour',
                   value=str(self.backup_hour))
        self.dev_env = mommy.make('Environment',
                                  name='dev',
                                  stage=Environment.DEV)
        mommy.make('Environment', name='prod', stage=Environment.PROD)
        _, _, _, self.plan = PlanHelper.create()
        self.infra = InfraHelper.create(backup_hour=self.backup_hour,
                                        plan__has_persistence=True,
                                        environment=self.dev_env,
                                        plan=self.plan)
        self.instance = mommy.make('Instance', databaseinfra=self.infra)
        self.database = DatabaseHelper.create(databaseinfra=self.infra,
                                              environment=self.dev_env)
Ejemplo n.º 16
0
    def setUp(self):
        cache.clear()
        mail.outbox = []

        self.email_from = Configuration(name='email_addr_from',
                                        value='*****@*****.**')
        self.email_from.save()

        self.email_adm = Configuration(name='new_user_notify_email',
                                       value='*****@*****.**')
        self.email_adm.save()
        self.team = mommy.make('Team',
                               name='team_1',
                               email='*****@*****.**',
                               contacts='contact_1',
                               role__name='fake_role',
                               organization__name='fake_organization')
        self.database = DatabaseHelper.create(name='fake_db_name',
                                              team=self.team)
        self.task_schedule = mommy.make('TaskSchedule',
                                        method_path=self.action,
                                        database=self.database)
Ejemplo n.º 17
0
 def _create_database(self,
                      env_name='fake_env',
                      infra_name='__test__ mysqlinfra2'):
     environment = mommy.make('Environment', name=env_name)
     databaseinfra = InfraHelper.create(name=infra_name,
                                        user="******",
                                        password='******',
                                        engine=self.engine,
                                        plan=self.plan,
                                        ssl_configured=True,
                                        environment=environment)
     hostname = mommy.make('Host',
                           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 = DatabaseHelper.create(
         name='test_db_1',
         databaseinfra=databaseinfra,
     )
     return environment, databaseinfra, hostname, database
 def setUp(self):
     self.now = FAKE_NOW
     self.one_hour_later = self.now + timedelta(hours=1)
     self.databases = DatabaseHelper.create(
         name=seq('fake_db_name'), _quantity=3
     )