當前位置: 首頁>>代碼示例>>Python>>正文


Python MySqlApp.stop_db方法代碼示例

本文整理匯總了Python中trove.guestagent.manager.mysql_service.MySqlApp.stop_db方法的典型用法代碼示例。如果您正苦於以下問題:Python MySqlApp.stop_db方法的具體用法?Python MySqlApp.stop_db怎麽用?Python MySqlApp.stop_db使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在trove.guestagent.manager.mysql_service.MySqlApp的用法示例。


在下文中一共展示了MySqlApp.stop_db方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: prepare

# 需要導入模塊: from trove.guestagent.manager.mysql_service import MySqlApp [as 別名]
# 或者: from trove.guestagent.manager.mysql_service.MySqlApp import stop_db [as 別名]
    def prepare(
        self,
        context,
        databases,
        memory_mb,
        users,
        device_path=None,
        mount_point=None,
        backup_id=None,
        config_location=None,
        config_contents=None,
    ):
        """Makes ready DBAAS on a Guest container."""
        MySqlAppStatus.get().begin_mysql_install()
        # status end_mysql_install set with secure()
        app = MySqlApp(MySqlAppStatus.get())
        restart_mysql = False
        if device_path:
            device = volume.VolumeDevice(device_path)
            device.format()
            # if a /var/lib/mysql folder exists, back it up.
            if os.path.exists(CONF.mount_point):
                # stop and do not update database
                app.stop_db()
                # rsync exiting data
                if not backup_id:
                    restart_mysql = True
                    device.migrate_data(CONF.mount_point)
            # mount the volume
            device.mount(mount_point)
            LOG.debug(_("Mounted the volume."))
            # check mysql was installed and stopped
            if restart_mysql:
                app.start_mysql()
        app.install_if_needed()
        if backup_id:
            self._perform_restore(backup_id, context, CONF.mount_point, app)
        LOG.info(_("Securing mysql now."))
        app.secure(config_location, config_contents)
        if backup_id and MySqlAdmin().is_root_enabled():
            MySqlAdmin().report_root_enabled(context)
        else:
            app.secure_root()
        app.complete_install_or_restart()

        if databases:
            self.create_database(context, databases)

        if users:
            self.create_user(context, users)

        LOG.info('"prepare" call has finished.')
開發者ID:nilakhya-gl,項目名稱:trove,代碼行數:54,代碼來源:mysql.py

示例2: MySqlAppTest

# 需要導入模塊: from trove.guestagent.manager.mysql_service import MySqlApp [as 別名]
# 或者: from trove.guestagent.manager.mysql_service.MySqlApp import stop_db [as 別名]
class MySqlAppTest(testtools.TestCase):

    def setUp(self):
        super(MySqlAppTest, self).setUp()
        self.orig_utils_execute_with_timeout = dbaas.utils.execute_with_timeout
        self.orig_time_sleep = time.sleep
        util.init_db()
        self.FAKE_ID = randint(1, 10000)
        InstanceServiceStatus.create(instance_id=self.FAKE_ID,
                                     status=rd_instance.ServiceStatuses.NEW)
        self.appStatus = FakeAppStatus(self.FAKE_ID,
                                       rd_instance.ServiceStatuses.NEW)
        self.mySqlApp = MySqlApp(self.appStatus)
        time.sleep = Mock()

    def tearDown(self):
        super(MySqlAppTest, self).tearDown()
        dbaas.utils.execute_with_timeout = self.orig_utils_execute_with_timeout
        time.sleep = self.orig_time_sleep
        InstanceServiceStatus.find_by(instance_id=self.FAKE_ID).delete()

    def assert_reported_status(self, expected_status):
        service_status = InstanceServiceStatus.find_by(
            instance_id=self.FAKE_ID)
        self.assertEqual(expected_status, service_status.status)

    def mysql_starts_successfully(self):
        def start(update_db=False):
            self.appStatus.set_next_status(
                rd_instance.ServiceStatuses.RUNNING)

        self.mySqlApp.start_mysql.side_effect = start

    def mysql_starts_unsuccessfully(self):
        def start():
            raise RuntimeError("MySQL failed to start!")

        self.mySqlApp.start_mysql.side_effect = start

    def mysql_stops_successfully(self):
        def stop():
            self.appStatus.set_next_status(
                rd_instance.ServiceStatuses.SHUTDOWN)

        self.mySqlApp.stop_db.side_effect = stop

    def mysql_stops_unsuccessfully(self):
        def stop():
            raise RuntimeError("MySQL failed to stop!")

        self.mySqlApp.stop_db.side_effect = stop

    def test_stop_mysql(self):

        dbaas.utils.execute_with_timeout = Mock()
        self.appStatus.set_next_status(
            rd_instance.ServiceStatuses.SHUTDOWN)

        self.mySqlApp.stop_db()
        self.assert_reported_status(rd_instance.ServiceStatuses.NEW)

    def test_stop_mysql_with_db_update(self):

        dbaas.utils.execute_with_timeout = Mock()
        self.appStatus.set_next_status(
            rd_instance.ServiceStatuses.SHUTDOWN)

        self.mySqlApp.stop_db(True)
        self.assert_reported_status(rd_instance.ServiceStatuses.SHUTDOWN)

    def test_stop_mysql_error(self):

        dbaas.utils.execute_with_timeout = Mock()
        self.appStatus.set_next_status(rd_instance.ServiceStatuses.RUNNING)
        self.mySqlApp.state_change_wait_time = 1
        self.assertRaises(RuntimeError, self.mySqlApp.stop_db)

    def test_restart_is_successful(self):

        self.mySqlApp.start_mysql = Mock()
        self.mySqlApp.stop_db = Mock()
        self.mysql_stops_successfully()
        self.mysql_starts_successfully()

        self.mySqlApp.restart()

        self.assertTrue(self.mySqlApp.stop_db.called)
        self.assertTrue(self.mySqlApp.start_mysql.called)
        self.assert_reported_status(rd_instance.ServiceStatuses.RUNNING)

    def test_restart_mysql_wont_start_up(self):

        self.mySqlApp.start_mysql = Mock()
        self.mySqlApp.stop_db = Mock()
        self.mysql_stops_unsuccessfully()
        self.mysql_starts_unsuccessfully()

        self.assertRaises(RuntimeError, self.mySqlApp.restart)

        self.assertTrue(self.mySqlApp.stop_db.called)
#.........這裏部分代碼省略.........
開發者ID:dadu1688,項目名稱:trove,代碼行數:103,代碼來源:test_dbaas.py

示例3: stop_db

# 需要導入模塊: from trove.guestagent.manager.mysql_service import MySqlApp [as 別名]
# 或者: from trove.guestagent.manager.mysql_service.MySqlApp import stop_db [as 別名]
 def stop_db(self, context, do_not_start_on_reboot=False):
     app = MySqlApp(MySqlAppStatus.get())
     app.stop_db(do_not_start_on_reboot=do_not_start_on_reboot)
開發者ID:ReVolly,項目名稱:trove,代碼行數:5,代碼來源:mysql.py


注:本文中的trove.guestagent.manager.mysql_service.MySqlApp.stop_db方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。