Beispiel #1
0
    def __init__(self, server_instance_settings):
        AppView.__init__(self, False, "admin", True)

        server_profile = ServerProfile(server_instance_settings, False)

        self.ctrl_be = wb_admin_control.WbAdminControl(server_profile,
                                                       connect_sql=True)

        self.ctrl_be.init()

        version = self.ctrl_be.get_server_version()
        if type(version) is tuple:
            valid_versions = ((4, 0), (4, 1), (5, 0), (5, 1), (5, 2), (5, 4),
                              (5, 5), (5, 6), (6, 0))
            if version[:2] not in valid_versions:
                print version, "UNSUPPORTED"
                log_warning(
                    _this_file, "%s: Server version %s is NOT supported\n" %
                    (self.__class__.__name__, str(version)))
            else:
                log_info(
                    _this_file, "%s: Server version %s is supported\n" %
                    (self.__class__.__name__, str(version)))

        self.on_close(wb_admin_utils.weakcb(self, "handle_on_close"))

        # Create sections and add them to the admin page.
        self.configuration = wb_admin_main.WbAdminMainView(
            server_profile, self.ctrl_be, self.monitor)
        self.add(self.configuration, True, True)
    def _dock_admin_tab(self):
        app = mforms.App.get()
        try:
            self.ctrl_be = wb_admin_control.WbAdminControl(self.server_profile, self.editor, connect_sql=True)
            self.ctrl_be.init()

            self.admin_tab = wb_admin_main.AdministratorTab(self.ctrl_be, self.server_profile, self, self.editor)
        except MySQLError, exc:
            if exc.message:
                Utilities.show_error("Error Connecting to MySQL Server (%s)" % exc.location, str(exc), "OK", "", "")
            app.set_status_text("Could not Open WB Admin")
            return None
Beispiel #3
0
def testInstanceSettingByName(what, server_instance):
    global test_ssh_connection
    profile = ServerProfile(server_instance)

    if what == "connect_to_host":
        if test_ssh_connection:
            test_ssh_connection = None

        print "Connecting to %s" % profile.ssh_hostname

        try:
            test_ssh_connection = wb_admin_control.WbAdminControl(
                profile, connect_sql=False)
            test_ssh_connection.init()
            grt.send_info("connected.")
        except Exception, exc:
            import traceback
            traceback.print_exc()
            return "ERROR " + str(exc)
        except:
Beispiel #4
0
    def _dock_admin_tab(self):
        app = mforms.App.get()
        try:
            self.ctrl_be = wb_admin_control.WbAdminControl(self.server_profile,
                                                           self.editor,
                                                           connect_sql=True)
            self.ctrl_be.init()

            self.admin_tab = wb_admin_main.AdministratorTab(
                self.ctrl_be, self.server_profile, self, self.editor)
        except MySQLError as exc:
            if str(exc):
                Utilities.show_error(
                    "Error Connecting to MySQL Server (%s)" % exc.location,
                    str(exc), "OK", "", "")
            app.set_status_text("Could not Open WB Admin")
            return None
        except OperationCancelledError as exc:
            app.set_status_text("Cancelled (%s)" % exc)
            return None
        except NoDriverInConnection as exc:
            Utilities.show_error('Missing connection driver', str(exc), 'OK',
                                 '', '')
            app.set_status_text("Could not Open WB Admin")
            return None
        except Exception as exc:
            import traceback
            traceback.print_exc()
            Utilities.show_error("Error Starting Workbench Administrator",
                                 "%s: %s" % (type(exc).__name__, exc), "OK",
                                 "", "")
            app.set_status_text("Could not Open WB Admin")
            return None

        dp = mforms.fromgrt(self.editor.dockingPoint)
        dp.dock_view(self.admin_tab, "", 0)
        dp.select_view(self.admin_tab)
        self.admin_tab.set_title("Administrator")

        return self.admin_tab
def testInstanceSettingByName(what, connection, server_instance):
    global test_ssh_connection
    log_debug("Test %s in %s\n" % (what, connection.name))

    profile = ServerProfile(connection, server_instance)
    if what == "connect_to_host":
        if test_ssh_connection:
            test_ssh_connection = None

        log_info("Instance test: Connecting to %s\n" % profile.ssh_hostname)

        try:
            test_ssh_connection = wb_admin_control.WbAdminControl(profile, None, connect_sql=False, test_only=True)
            test_ssh_connection.init()

            grt.send_info("connected.")
        except Exception, exc:
            log_error("Exception: %s\n" % exc.message)
            import traceback
            log_debug2("Backtrace was: ", traceback.format_stack())
            return "ERROR "+str(exc)
        except:
def testInstanceSettingByName(what, connection, server_instance):
    global test_ssh_connection

    log_debug(_this_file, "Test %s in %s\n" % (what, connection.name))

    profile = ServerProfile(connection, server_instance)

    if what == "connect_to_host":
        if test_ssh_connection:
            test_ssh_connection = None

        log_info(_this_file, "Instance test: Connecting to %s\n" % profile.ssh_hostname)

        try:
            test_ssh_connection = wb_admin_control.WbAdminControl(profile, connect_sql=False)
            test_ssh_connection.init()
            grt.send_info("connected.")
        except Exception, exc:
            import traceback
            traceback.print_exc()
            return "ERROR "+str(exc)
        except:
Beispiel #7
0
                path=config_file)
        except Exception, exc:
            import traceback
            traceback.print_exc()
            return "ERROR " + str(exc)

        if ("[" + section + "]") in cfg_file_content:
            return "OK"
        return "ERROR Couldn't find section %s in the remote config file %s" % (
            section, config_file)

    elif what in ("find_config_file/local", "check_config_path/local",
                  "check_config_section/local"):
        config_file = profile.config_file_path
        config_file = wb_admin_control.WbAdminControl(
            profile, None,
            connect_sql=False).expand_path_variables(config_file)
        print "Check if %s can be accessed" % config_file
        if os.path.exists(config_file):
            print "File was found at the expected location"
        else:
            return "ERROR File %s doesn't exist" % config_file

        if what == "check_config_path/local":
            return "OK"

        section = profile.config_file_section
        print "Check if section for instance %s exists in %s" % (section,
                                                                 config_file)
        if check_if_config_file_has_section(open(config_file, "r"), section):
            print "[%s] section found in configuration file" % section
Beispiel #8
0
def testInstanceSettingByName(what, connection, server_instance):
    global test_ssh_connection
    log_debug("Test %s in %s\n" % (what, connection.name))

    profile = ServerProfile(connection, server_instance)
    if what == "connect_to_host":
        if test_ssh_connection:
            test_ssh_connection = None

        log_info("Instance test: Connecting to %s\n" % profile.ssh_hostname)

        try:
            test_ssh_connection = wb_admin_control.WbAdminControl(
                profile, None, connect_sql=False, test_only=True)
            test_ssh_connection.init()

            grt.send_info("connected.")
        except Exception as exc:
            log_error("Exception: %s\n" % str(exc))
            import traceback
            log_debug2("Backtrace was: ", traceback.format_stack())
            return "ERROR " + str(exc)
        except:
            return "ERROR"

        try:
            test_ssh_connection.acquire_admin_access()
        except Exception as exc:

            log_error("Exception: %s\n" % str(exc))
            import traceback
            log_debug2("Backtrace was: " % traceback.format_stack())
            return "ERROR " + str(exc)

        os_info = test_ssh_connection.detect_operating_system_version()
        if os_info:
            os_type, os_name, os_variant, os_version = os_info
            log_info("Instance test: detected remote OS: %s (%s), %s, %s\n" %
                     (os_info))

            # check if the admin access error was because of wrong OS set
            if os_type != profile.target_os:
                return "ERROR Wrong Remote OS configured for connection. Set to %s, but was detected as %s" % (
                    profile.target_os, os_type)
        else:
            log_warning(
                "Instance test: could not determine OS version information\n")

            return "ERROR Could not determine remote OS details"

        return "OK"

    elif what == "disconnect":
        if test_ssh_connection:
            test_ssh_connection = None
        return "OK"

    elif what == "check_privileges":
        return "ERROR"

    elif what in ("find_config_file", "check_config_path",
                  "check_config_section"):
        config_file = profile.config_file_path
        print("Check if %s exists in remote host" % config_file)
        try:
            if not test_ssh_connection.ssh.fileExists(config_file):
                return "ERROR File %s doesn't exist" % config_file
            else:
                print("File was found in expected location")
        except IOError:
            return 'ERROR Could not verify the existence of the file %s' % config_file

        if what == "check_config_path":
            return "OK"

        section = profile.config_file_section
        cfg_file_content = ""
        print("Check if %s section exists in %s" % (section, config_file))
        try:
            #local_file = test_ssh_connection.fetch_file(config_file)
            cfg_file_content = test_ssh_connection.server_helper.get_file_content(
                path=config_file)
        except Exception as exc:
            import traceback
            traceback.print_exc()
            return "ERROR " + str(exc)

        if ("[" + section + "]") in cfg_file_content:
            return "OK"
        return "ERROR Couldn't find section %s in the remote config file %s" % (
            section, config_file)

    elif what in ("find_config_file/local", "check_config_path/local",
                  "check_config_section/local"):
        config_file = profile.config_file_path
        config_file = wb_admin_control.WbAdminControl(
            profile, None,
            connect_sql=False).expand_path_variables(config_file)
        print("Check if %s can be accessed" % config_file)
        if os.path.exists(config_file):
            print("File was found at the expected location")
        else:
            return "ERROR File %s doesn't exist" % config_file

        if what == "check_config_path/local":
            return "OK"

        section = profile.config_file_section
        print("Check if section for instance %s exists in %s" %
              (section, config_file))
        if check_if_config_file_has_section(open(config_file, "r"), section):
            print("[%s] section found in configuration file" % section)
            return "OK"
        return "ERROR Couldn't find section [%s] in the config file %s" % (
            section, config_file)

    elif what == "find_error_files":
        return "ERROR"

    elif what == "check_admin_commands":
        path = profile.start_server_cmd
        cmd_start = None
        if path.startswith("/"):
            cmd_start = path.split()[0]
            if not test_ssh_connection.ssh.fileExists(cmd_start):
                return "ERROR %s is invalid" % path

        path = profile.stop_server_cmd
        if path.startswith("/"):
            cmd = path.split()[0]
            if cmd != cmd_start and not test_ssh_connection.ssh.fileExists(
                    cmd):
                return "ERROR %s is invalid" % path

        return "OK"

    elif what == "check_admin_commands/local":
        path = profile.start_server_cmd
        cmd_start = None
        if path.startswith("/"):
            cmd_start = path.split()[0]
            if not os.path.exists(cmd_start):
                return "ERROR %s is invalid" % path

        path = profile.stop_server_cmd
        if path.startswith("/"):
            cmd = path.split()[0]
            if cmd != cmd_start and not os.path.exists(cmd):
                return "ERROR %s is invalid" % path

        return "OK"

    return "ERROR bad command"
Beispiel #9
0
class AdminTestCase(unittest.TestCase):
    local_server_profile = wb_server_control.ServerProfile(
        create_instance(**test_params_local))
    local_ctrl_be = wb_admin_control.WbAdminControl(local_server_profile)
    local_ctrl_be.init()
    local_db_fixtures = db_test_fixtures.DBFixtures(test_params_local)