Ejemplo n.º 1
0
    def test_being_mysql_install(self):

        self.mySqlAppStatus = MySqlAppStatus()

        self.mySqlAppStatus.begin_mysql_install()

        self.assertEquals(self.mySqlAppStatus.status, ServiceStatuses.BUILDING)
Ejemplo n.º 2
0
    def test_get_actual_db_status(self):

        dbaas.utils.execute_with_timeout = Mock(return_value=(None, None))

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.RUNNING, status)
Ejemplo n.º 3
0
    def test_begin_mysql_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = False

        self.mySqlAppStatus.begin_mysql_restart()

        self.assertTrue(self.mySqlAppStatus.restart_mode)
Ejemplo n.º 4
0
    def test_end_install_or_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.SHUTDOWN)

        self.mySqlAppStatus.end_install_or_restart()

        self.assertEqual(ServiceStatuses.SHUTDOWN, self.mySqlAppStatus.status)
        self.assertFalse(self.mySqlAppStatus.restart_mode)
Ejemplo n.º 5
0
    def test_wait_for_real_status_to_change_to_timeout(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.RUNNING)
        dbaas.time.sleep = Mock()

        self.assertFalse(
            self.mySqlAppStatus.wait_for_real_status_to_change_to(
                ServiceStatuses.SHUTDOWN, 10))
Ejemplo n.º 6
0
    def test_get_actual_db_status_error_shutdown(self):

        from reddwarf.common.exception import ProcessExecutionError
        mocked = Mock(side_effect=ProcessExecutionError())
        dbaas.utils.execute_with_timeout = mocked
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=False)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.SHUTDOWN, status)
Ejemplo n.º 7
0
    def test_get_actual_db_status_error_crashed(self):

        from reddwarf.common.exception import ProcessExecutionError
        dbaas.utils.execute_with_timeout = \
            MagicMock(side_effect=[ProcessExecutionError(),
                                   ("some output", None)])
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=True)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.BLOCKED, status)
Ejemplo n.º 8
0
    def test_being_mysql_install(self):

        self.mySqlAppStatus = MySqlAppStatus()

        self.mySqlAppStatus.begin_mysql_install()

        self.assertEquals(self.mySqlAppStatus.status, ServiceStatuses.BUILDING)
Ejemplo n.º 9
0
    def test_wait_for_real_status_to_change_to_timeout(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = Mock(return_value=ServiceStatuses.RUNNING)
        dbaas.time.sleep = Mock()

        self.assertFalse(self.mySqlAppStatus.wait_for_real_status_to_change_to(ServiceStatuses.SHUTDOWN, 10))
Ejemplo n.º 10
0
    def test_begin_mysql_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = False

        self.mySqlAppStatus.begin_mysql_restart()

        self.assertTrue(self.mySqlAppStatus.restart_mode)
Ejemplo n.º 11
0
    def test_get_actual_db_status(self):

        dbaas.utils.execute_with_timeout = Mock(return_value=(None, None))

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.RUNNING, status)
Ejemplo n.º 12
0
    def test_end_install_or_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = Mock(return_value=ServiceStatuses.SHUTDOWN)

        self.mySqlAppStatus.end_install_or_restart()

        self.assertEqual(ServiceStatuses.SHUTDOWN, self.mySqlAppStatus.status)
        self.assertFalse(self.mySqlAppStatus.restart_mode)
Ejemplo n.º 13
0
    def test_get_actual_db_status_error_shutdown(self):

        from reddwarf.common.exception import ProcessExecutionError
        dbaas.utils.execute_with_timeout = Mock(side_effect=
                                                ProcessExecutionError())
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=False)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.SHUTDOWN, status)
Ejemplo n.º 14
0
    def test_get_actual_db_status_error_crashed(self):

        from reddwarf.common.exception import ProcessExecutionError

        dbaas.utils.execute_with_timeout = MagicMock(side_effect=[ProcessExecutionError(), ("some output", None)])
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=True)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.BLOCKED, status)
Ejemplo n.º 15
0
    def test_is_mysql_installed_building(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.BUILDING

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
Ejemplo n.º 16
0
class MySqlAppStatusTest(testtools.TestCase):
    def setUp(self):
        super(MySqlAppStatusTest, self).setUp()
        util.init_db()
        self.orig_utils_execute_with_timeout = dbaas.utils.execute_with_timeout
        self.orig_load_mysqld_options = dbaas.load_mysqld_options
        self.orig_dbaas_os_path_exists = dbaas.os.path.exists
        self.orig_dbaas_time_sleep = dbaas.time.sleep
        self.FAKE_ID = randint(1, 10000)
        InstanceServiceStatus.create(instance_id=self.FAKE_ID,
                                     status=ServiceStatuses.NEW)
        dbaas.CONF.guest_id = self.FAKE_ID

    def tearDown(self):
        super(MySqlAppStatusTest, self).tearDown()
        dbaas.utils.execute_with_timeout = self.orig_utils_execute_with_timeout
        dbaas.load_mysqld_options = self.orig_load_mysqld_options
        dbaas.os.path.exists = self.orig_dbaas_os_path_exists
        dbaas.time.sleep = self.orig_dbaas_time_sleep
        InstanceServiceStatus.find_by(instance_id=self.FAKE_ID).delete()
        dbaas.CONF.guest_id = None

    def test_being_mysql_install(self):

        self.mySqlAppStatus = MySqlAppStatus()

        self.mySqlAppStatus.begin_mysql_install()

        self.assertEquals(self.mySqlAppStatus.status, ServiceStatuses.BUILDING)

    def test_begin_mysql_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = False

        self.mySqlAppStatus.begin_mysql_restart()

        self.assertTrue(self.mySqlAppStatus.restart_mode)

    def test_end_install_or_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.SHUTDOWN)

        self.mySqlAppStatus.end_install_or_restart()

        self.assertEqual(ServiceStatuses.SHUTDOWN, self.mySqlAppStatus.status)
        self.assertFalse(self.mySqlAppStatus.restart_mode)

    def test_get_actual_db_status(self):

        dbaas.utils.execute_with_timeout = Mock(return_value=(None, None))

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.RUNNING, status)

    def test_get_actual_db_status_error_shutdown(self):

        from reddwarf.common.exception import ProcessExecutionError
        mocked = Mock(side_effect=ProcessExecutionError())
        dbaas.utils.execute_with_timeout = mocked
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=False)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.SHUTDOWN, status)

    def test_get_actual_db_status_error_crashed(self):

        from reddwarf.common.exception import ProcessExecutionError
        dbaas.utils.execute_with_timeout = \
            MagicMock(side_effect=[ProcessExecutionError(),
                                   ("some output", None)])
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=True)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.BLOCKED, status)

    def test_is_mysql_installed(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.RUNNING

        self.assertTrue(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_installed_none(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = None

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_installed_building(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.BUILDING

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_installed_failed(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.FAILED

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_restarting(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = True

        self.assertTrue(self.mySqlAppStatus._is_mysql_restarting)

    def test_is_mysql_running(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.RUNNING

        self.assertTrue(self.mySqlAppStatus.is_mysql_running)

    def test_is_mysql_running_not(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.SHUTDOWN

        self.assertFalse(self.mySqlAppStatus.is_mysql_running)

    def test_wait_for_real_status_to_change_to(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.RUNNING)
        dbaas.time.sleep = Mock()

        self.assertTrue(
            self.mySqlAppStatus.wait_for_real_status_to_change_to(
                ServiceStatuses.RUNNING, 10))

    def test_wait_for_real_status_to_change_to_timeout(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.RUNNING)
        dbaas.time.sleep = Mock()

        self.assertFalse(
            self.mySqlAppStatus.wait_for_real_status_to_change_to(
                ServiceStatuses.SHUTDOWN, 10))
Ejemplo n.º 17
0
    def test_is_mysql_installed_none(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = None

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
Ejemplo n.º 18
0
    def test_is_mysql_installed_none(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = None

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
Ejemplo n.º 19
0
class MySqlAppStatusTest(testtools.TestCase):

    def setUp(self):
        super(MySqlAppStatusTest, self).setUp()
        util.init_db()
        self.orig_utils_execute_with_timeout = dbaas.utils.execute_with_timeout
        self.orig_load_mysqld_options = dbaas.load_mysqld_options
        self.orig_dbaas_os_path_exists = dbaas.os.path.exists
        self.orig_dbaas_time_sleep = dbaas.time.sleep
        self.FAKE_ID = randint(1, 10000)
        InstanceServiceStatus.create(instance_id=self.FAKE_ID,
                                     status=ServiceStatuses.NEW)
        dbaas.CONF.guest_id = self.FAKE_ID

    def tearDown(self):
        super(MySqlAppStatusTest, self).tearDown()
        dbaas.utils.execute_with_timeout = self.orig_utils_execute_with_timeout
        dbaas.load_mysqld_options = self.orig_load_mysqld_options
        dbaas.os.path.exists = self.orig_dbaas_os_path_exists
        dbaas.time.sleep = self.orig_dbaas_time_sleep
        InstanceServiceStatus.find_by(instance_id=self.FAKE_ID).delete()
        dbaas.CONF.guest_id = None

    def test_being_mysql_install(self):

        self.mySqlAppStatus = MySqlAppStatus()

        self.mySqlAppStatus.begin_mysql_install()

        self.assertEquals(self.mySqlAppStatus.status, ServiceStatuses.BUILDING)

    def test_begin_mysql_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = False

        self.mySqlAppStatus.begin_mysql_restart()

        self.assertTrue(self.mySqlAppStatus.restart_mode)

    def test_end_install_or_restart(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.SHUTDOWN)

        self.mySqlAppStatus.end_install_or_restart()

        self.assertEqual(ServiceStatuses.SHUTDOWN, self.mySqlAppStatus.status)
        self.assertFalse(self.mySqlAppStatus.restart_mode)

    def test_get_actual_db_status(self):

        dbaas.utils.execute_with_timeout = Mock(return_value=(None, None))

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.RUNNING, status)

    def test_get_actual_db_status_error_shutdown(self):

        from reddwarf.common.exception import ProcessExecutionError
        dbaas.utils.execute_with_timeout = Mock(side_effect=
                                                ProcessExecutionError())
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=False)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.SHUTDOWN, status)

    def test_get_actual_db_status_error_crashed(self):

        from reddwarf.common.exception import ProcessExecutionError
        dbaas.utils.execute_with_timeout = \
            MagicMock(side_effect=[ProcessExecutionError(),
                                   ("some output", None)])
        dbaas.load_mysqld_options = Mock()
        dbaas.os.path.exists = Mock(return_value=True)

        self.mySqlAppStatus = MySqlAppStatus()
        status = self.mySqlAppStatus._get_actual_db_status()

        self.assertEqual(ServiceStatuses.BLOCKED, status)

    def test_is_mysql_installed(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.RUNNING

        self.assertTrue(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_installed_none(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = None

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_installed_building(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.BUILDING

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_installed_failed(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.FAILED

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)

    def test_is_mysql_restarting(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = True

        self.assertTrue(self.mySqlAppStatus._is_mysql_restarting)

    def test_is_mysql_running(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.RUNNING

        self.assertTrue(self.mySqlAppStatus.is_mysql_running)

    def test_is_mysql_running_not(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.SHUTDOWN

        self.assertFalse(self.mySqlAppStatus.is_mysql_running)

    def test_wait_for_real_status_to_change_to(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.RUNNING)
        dbaas.time.sleep = Mock()

        self.assertTrue(self.mySqlAppStatus.
                        wait_for_real_status_to_change_to
                        (ServiceStatuses.RUNNING, 10))

    def test_wait_for_real_status_to_change_to_timeout(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus._get_actual_db_status = \
            Mock(return_value=ServiceStatuses.RUNNING)
        dbaas.time.sleep = Mock()

        self.assertFalse(self.mySqlAppStatus.
                         wait_for_real_status_to_change_to
                         (ServiceStatuses.SHUTDOWN, 10))
Ejemplo n.º 20
0
    def test_is_mysql_installed_failed(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.FAILED

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
Ejemplo n.º 21
0
    def test_is_mysql_running_not(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.SHUTDOWN

        self.assertFalse(self.mySqlAppStatus.is_mysql_running)
Ejemplo n.º 22
0
    def test_is_mysql_running(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.RUNNING

        self.assertTrue(self.mySqlAppStatus.is_mysql_running)
Ejemplo n.º 23
0
    def test_is_mysql_installed_building(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.BUILDING

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
Ejemplo n.º 24
0
    def test_is_mysql_installed_failed(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.FAILED

        self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
Ejemplo n.º 25
0
    def test_is_mysql_restarting(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = True

        self.assertTrue(self.mySqlAppStatus._is_mysql_restarting)
Ejemplo n.º 26
0
    def test_is_mysql_restarting(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.restart_mode = True

        self.assertTrue(self.mySqlAppStatus._is_mysql_restarting)
Ejemplo n.º 27
0
    def test_is_mysql_running_not(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.SHUTDOWN

        self.assertFalse(self.mySqlAppStatus.is_mysql_running)
Ejemplo n.º 28
0
    def test_is_mysql_running(self):

        self.mySqlAppStatus = MySqlAppStatus()
        self.mySqlAppStatus.status = ServiceStatuses.RUNNING

        self.assertTrue(self.mySqlAppStatus.is_mysql_running)