Beispiel #1
0
 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=ServiceStatuses.NEW)
     self.appStatus = FakeAppStatus(self.FAKE_ID, ServiceStatuses.NEW)
     self.mySqlApp = MySqlApp(self.appStatus)
     time.sleep = Mock()
Beispiel #2
0
    def test_secure_keep_root(self):
        mock_conn = mock_sql_connection()

        when(mock_conn).execute(any()).thenReturn(None)
        when(utils).execute_with_timeout("sudo", any(str),
                                         "stop").thenReturn(None)
        # skip writing the file for now
        when(os.path).isfile(any()).thenReturn(False)
        when(utils).execute_with_timeout("sudo", "chmod", any(),
                                         any()).thenReturn(None)
        mock_status = mock(MySqlAppStatus)
        when(mock_status).wait_for_real_status_to_change_to(
            any(), any(), any()).thenReturn(True)
        app = MySqlApp(mock_status)
        when(app)._write_mycnf(any(), any()).thenReturn(True)
        app.secure(MYCNF, 'foo')
        verify(mock_conn, never).execute(TextClauseMatcher('root'))
Beispiel #3
0
    def test_secure_with_mycnf_error(self):
        mock_conn = mock_sql_connection()
        when(mock_conn).execute(any()).thenReturn(None)
        when(utils).execute_with_timeout("sudo", any(str),
                                         "stop").thenReturn(None)
        # skip writing the file for now
        when(os.path).isfile(any()).thenReturn(False)
        mock_status = mock(MySqlAppStatus)
        when(mock_status).wait_for_real_status_to_change_to(
            any(), any(), any()).thenReturn(True)
        app = MySqlApp(mock_status)

        self.assertRaises(TypeError, app.secure, MYCNF, None)

        verify(mock_conn, atleast=2).execute(any())
        inorder.verify(mock_status).wait_for_real_status_to_change_to(
            ServiceStatuses.SHUTDOWN, any(), any())
        verifyNoMoreInteractions(mock_status)
Beispiel #4
0
    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.')
Beispiel #5
0
 def reset_configuration(self, context, configuration):
     app = MySqlApp(MySqlAppStatus.get())
     app.reset_configuration(configuration)
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 def restart(self, context):
     app = MySqlApp(MySqlAppStatus.get())
     app.restart()