def test_being_mysql_install(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.begin_mysql_install() self.assertEquals(self.mySqlAppStatus.status, ServiceStatuses.BUILDING)
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_begin_mysql_restart(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.restart_mode = False self.mySqlAppStatus.begin_mysql_restart() self.assertTrue(self.mySqlAppStatus.restart_mode)
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=rd_instance.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_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(rd_instance.ServiceStatuses.RUNNING, status) def test_get_actual_db_status_error_shutdown(self): from trove.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(rd_instance.ServiceStatuses.SHUTDOWN, status) def test_get_actual_db_status_error_crashed(self): from trove.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(rd_instance.ServiceStatuses.BLOCKED, status)
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))
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_error_shutdown(self): from trove.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 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.')
def test_get_actual_db_status_error_crashed(self): from trove.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_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(rd_instance.ServiceStatuses.RUNNING, status)
def test_wait_for_real_status_to_change_to(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus._get_actual_db_status = \ Mock(return_value=rd_instance.ServiceStatuses.RUNNING) dbaas.time.sleep = Mock() self.assertTrue(self.mySqlAppStatus. wait_for_real_status_to_change_to (rd_instance.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))
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) enable_root_on_restore = (backup_id and MySqlAdmin().is_root_enabled()) if enable_root_on_restore: MySqlAdmin().report_root_enabled(context) app.secure_root(secure_remote_root=not enable_root_on_restore) 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.')
def test_get_actual_db_status_error_crashed(self): from trove.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(rd_instance.ServiceStatuses.BLOCKED, status)
def test_get_actual_db_status_error_shutdown(self): from trove.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(rd_instance.ServiceStatuses.SHUTDOWN, status)
def test_is_mysql_installed_new(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.status = ServiceStatuses.NEW self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
def start_db_with_conf_changes(self, context, config_contents): app = MySqlApp(MySqlAppStatus.get()) app.start_db_with_conf_changes(config_contents)
def update_status(self, context): """Update the status of the MySQL service""" MySqlAppStatus.get().update()
def test_is_mysql_running_not(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.status = ServiceStatuses.SHUTDOWN self.assertFalse(self.mySqlAppStatus.is_mysql_running)
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_installed_none(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.status = None 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 start_db_with_conf_changes(self, context, updated_memory_size): app = MySqlApp(MySqlAppStatus.get()) app.start_db_with_conf_changes(updated_memory_size)
def update_overrides(self, context, overrides, remove=False): app = MySqlApp(MySqlAppStatus.get()) app.update_overrides(overrides, remove=remove)
def reset_configuration(self, context, configuration): app = MySqlApp(MySqlAppStatus.get()) app.reset_configuration(configuration)
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)
def start_db_with_conf_changes(self, context, config_location, config_contents): app = MySqlApp(MySqlAppStatus.get()) app.start_db_with_conf_changes(config_location, config_contents)
def test_is_mysql_installed(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.status = rd_instance.ServiceStatuses.RUNNING self.assertTrue(self.mySqlAppStatus.is_mysql_installed)
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 trove.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 trove.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_new(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.status = ServiceStatuses.NEW 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))
def test_is_mysql_running(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.status = ServiceStatuses.RUNNING self.assertTrue(self.mySqlAppStatus.is_mysql_running)
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 trove.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 trove.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))
def restart(self, context): app = MySqlApp(MySqlAppStatus.get()) app.restart()
def test_is_mysql_installed_building(self): self.mySqlAppStatus = MySqlAppStatus() self.mySqlAppStatus.status = ServiceStatuses.BUILDING self.assertFalse(self.mySqlAppStatus.is_mysql_installed)
def apply_overrides(self, context, overrides): app = MySqlApp(MySqlAppStatus.get()) app.apply_overrides(overrides)