Example #1
0
 def _get_service(self):
     if self.status._is_query_router() is True:
         return (operating_system.service_discovery(
             system.MONGOS_SERVICE_CANDIDATES))
     else:
         return (operating_system.service_discovery(
             system.MONGOD_SERVICE_CANDIDATES))
Example #2
0
 def _disable_db_on_boot(self):
     LOG.info(_("Disabling Couchbase Server on boot"))
     try:
         couchbase_service = operating_system.service_discovery(system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(couchbase_service["cmd_disable"], shell=True)
     except KeyError:
         raise RuntimeError("Command to disable Couchbase Server on boot not found.")
Example #3
0
 def _enable_mysql_on_boot(self):
     LOG.info("Enabling mysql on boot.")
     try:
         mysql_service = operating_system.service_discovery(MYSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(mysql_service["cmd_enable"], shell=True)
     except KeyError:
         raise RuntimeError("Service is not discovered.")
Example #4
0
    def start_mysql(self, update_db=False):
        LOG.info(_("Starting mysql..."))
        # This is the site of all the trouble in the restart tests.
        # Essentially what happens is that mysql start fails, but does not
        # die. It is then impossible to kill the original, so

        self._enable_mysql_on_boot()

        try:
            mysql_service = operating_system.service_discovery(
                MYSQL_SERVICE_CANDIDATES)
            utils.execute_with_timeout(mysql_service['cmd_start'], shell=True)
        except KeyError:
            raise RuntimeError("Service is not discovered.")
        except exception.ProcessExecutionError:
            # it seems mysql (percona, at least) might come back with [Fail]
            # but actually come up ok. we're looking into the timing issue on
            # parallel, but for now, we'd like to give it one more chance to
            # come up. so regardless of the execute_with_timeout() response,
            # we'll assume mysql comes up and check it's status for a while.
            pass
        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of MySQL failed!"))
            # If it won't start, but won't die either, kill it by hand so we
            # don't let a rouge process wander around.
            try:
                utils.execute_with_timeout("sudo", "pkill", "-9", "mysql")
            except exception.ProcessExecutionError as p:
                LOG.error("Error killing stalled mysql start command.")
                LOG.error(p)
                # There's nothing more we can do...
            self.status.end_install_or_restart()
            raise RuntimeError("Could not start MySQL!")
Example #5
0
    def start_mysql(self, update_db=False):
        LOG.info(_("Starting MySQL."))
        # This is the site of all the trouble in the restart tests.
        # Essentially what happens is that mysql start fails, but does not
        # die. It is then impossible to kill the original, so

        self._enable_mysql_on_boot()

        try:
            mysql_service = operating_system.service_discovery(
                MYSQL_SERVICE_CANDIDATES)
            utils.execute_with_timeout(mysql_service['cmd_start'], shell=True)
        except KeyError:
            raise RuntimeError("Service is not discovered.")
        except exception.ProcessExecutionError:
            # it seems mysql (percona, at least) might come back with [Fail]
            # but actually come up ok. we're looking into the timing issue on
            # parallel, but for now, we'd like to give it one more chance to
            # come up. so regardless of the execute_with_timeout() response,
            # we'll assume mysql comes up and check it's status for a while.
            pass
        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of MySQL failed."))
            # If it won't start, but won't die either, kill it by hand so we
            # don't let a rouge process wander around.
            try:
                utils.execute_with_timeout("sudo", "pkill", "-9", "mysql")
            except exception.ProcessExecutionError:
                LOG.exception(_("Error killing stalled MySQL start command."))
                # There's nothing more we can do...
            self.status.end_install_or_restart()
            raise RuntimeError("Could not start MySQL!")
Example #6
0
    def start_db(self, update_db=False):
        """
        Start the Couchbase Server.
        """
        LOG.info(_("Starting Couchbase Server..."))

        self._enable_db_on_boot()
        try:
            couchbase_service = operating_system.service_discovery(
                system.SERVICE_CANDIDATES)
            utils.execute_with_timeout(
                couchbase_service['cmd_start'], shell=True)
        except exception.ProcessExecutionError:
            pass
        except KeyError:
            raise RuntimeError("Command to start Couchbase Server not found.")

        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of Couchbase Server failed!"))
            try:
                utils.execute_with_timeout(system.cmd_kill)
            except exception.ProcessExecutionError as p:
                LOG.error('Error killing stalled Couchbase start command.')
                LOG.error(p)
            self.status.end_install_or_restart()
            raise RuntimeError("Could not start Couchbase Server")
Example #7
0
    def start_db(self, update_db=False):
        """
        Start the Couchbase Server.
        """
        LOG.info(_("Starting Couchbase Server..."))

        self._enable_db_on_boot()
        try:
            couchbase_service = operating_system.service_discovery(
                system.SERVICE_CANDIDATES)
            utils.execute_with_timeout(couchbase_service['cmd_start'],
                                       shell=True)
        except exception.ProcessExecutionError:
            pass
        except KeyError:
            raise RuntimeError("Command to start Couchbase Server not found.")

        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of Couchbase Server failed!"))
            try:
                utils.execute_with_timeout(system.cmd_kill)
            except exception.ProcessExecutionError as p:
                LOG.error('Error killing stalled Couchbase start command.')
                LOG.error(p)
            self.status.end_install_or_restart()
            raise RuntimeError("Could not start Couchbase Server")
Example #8
0
    def start_db(self, update_db=False):
        LOG.info(_("Starting MongoDB"))

        self._enable_db_on_boot()

        try:
            mongodb_service = operating_system.service_discovery(
                system.SERVICE_CANDIDATES)
            utils.execute_with_timeout(mongodb_service['cmd_start'],
                                       shell=True)
        except ProcessExecutionError:
            pass
        except KeyError:
            raise RuntimeError("MongoDB service is not discovered.")

        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of MongoDB failed"))
            # If it won't start, but won't die either, kill it by hand so we
            # don't let a rouge process wander around.
            try:
                out, err = utils.execute_with_timeout(
                    system.FIND_PID, shell=True)
                pid = "".join(out.split(" ")[1:2])
                utils.execute_with_timeout(
                    system.MONGODB_KILL % pid, shell=True)
            except exception.ProcessExecutionError as p:
                LOG.error("Error killing stalled MongoDB start command.")
                LOG.error(p)
                # There's nothing more we can do...
            self.status.end_install_or_restart()
            raise RuntimeError("Could not start MongoDB")
Example #9
0
 def _disable_db_on_boot(self):
     try:
         LOG.debug("Disable CouchDB on boot.")
         couchdb_service = operating_system.service_discovery(system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(couchdb_service["cmd_disable"], shell=True)
     except KeyError:
         raise RuntimeError("Command to disable CouchDB server on boot not found.")
Example #10
0
    def start_db(self, update_db=False):
        LOG.info(_("Starting MongoDB"))

        self._enable_db_on_boot()

        try:
            mongodb_service = operating_system.service_discovery(
                system.SERVICE_CANDIDATES)
            utils.execute_with_timeout(mongodb_service['cmd_start'],
                                       shell=True)
        except ProcessExecutionError:
            pass
        except KeyError:
            raise RuntimeError("MongoDB service is not discovered.")

        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of MongoDB failed"))
            # If it won't start, but won't die either, kill it by hand so we
            # don't let a rouge process wander around.
            try:
                out, err = utils.execute_with_timeout(
                    system.FIND_PID, shell=True)
                pid = "".join(out.split(" ")[1:2])
                utils.execute_with_timeout(
                    system.MONGODB_KILL % pid, shell=True)
            except exception.ProcessExecutionError as p:
                LOG.error("Error killing stalled MongoDB start command.")
                LOG.error(p)
                # There's nothing more we can do...
            self.status.end_install_or_restart()
            raise RuntimeError("Could not start MongoDB")
Example #11
0
 def _disable_mysql_on_boot(self):
     try:
         mysql_service = operating_system.service_discovery(
             MYSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(mysql_service['cmd_disable'],
                                    shell=True)
     except KeyError:
         raise RuntimeError("Service is not discovered.")
Example #12
0
 def _disable_mysql_on_boot(self):
     try:
         mysql_service = operating_system.service_discovery(
             MYSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(mysql_service['cmd_disable'],
                                    shell=True)
     except KeyError:
         raise RuntimeError("Service is not discovered.")
Example #13
0
 def _enable_pgsql_on_boot(self):
     try:
         pgsql_service = operating_system.service_discovery(
             PGSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(pgsql_service['cmd_enable'], shell=True)
     except KeyError:
         LOG.exception(_("Error enabling PostgreSQL start on boot."))
         raise RuntimeError("Service is not discovered.")
Example #14
0
 def _disable_db_on_boot(self):
     LOG.info(_("Disabling MongoDB on boot"))
     try:
         mongodb_service = operating_system.service_discovery(
             system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(mongodb_service['cmd_disable'],
                                    shell=True)
     except KeyError:
         raise RuntimeError("MongoDB service is not discovered.")
Example #15
0
 def _enable_mysql_on_boot(self):
     LOG.debug("Enabling MySQL on boot.")
     try:
         mysql_service = operating_system.service_discovery(
             MYSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(mysql_service['cmd_enable'], shell=True)
     except KeyError:
         LOG.exception(_("Error enabling MySQL start on boot."))
         raise RuntimeError("Service is not discovered.")
Example #16
0
 def _enable_mysql_on_boot(self):
     LOG.debug("Enabling MySQL on boot.")
     try:
         mysql_service = operating_system.service_discovery(
             MYSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(mysql_service['cmd_enable'], shell=True)
     except KeyError:
         LOG.exception(_("Error enabling MySQL start on boot."))
         raise RuntimeError("Service is not discovered.")
Example #17
0
 def _disable_db_on_boot(self):
     LOG.info(_("Disabling MongoDB on boot"))
     try:
         mongodb_service = operating_system.service_discovery(
             system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(mongodb_service['cmd_disable'],
                                    shell=True)
     except KeyError:
         raise RuntimeError("MongoDB service is not discovered.")
Example #18
0
 def _disable_pgsql_on_boot(self):
     try:
         pgsql_service = operating_system.service_discovery(
             PGSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(pgsql_service['cmd_disable'],
                                    shell=True)
     except KeyError:
         LOG.exception(_("Error disabling PostgreSQL start on boot."))
         raise RuntimeError("Service is not discovered.")
Example #19
0
 def _disable_db_on_boot(self):
     LOG.info(_("Disabling Couchbase Server on boot"))
     try:
         couchbase_service = operating_system.service_discovery(
             system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(couchbase_service['cmd_disable'],
                                    shell=True)
     except KeyError:
         raise RuntimeError(
             "Command to disable Couchbase Server on boot not found.")
Example #20
0
 def stop_db(self, context):
     """Stop the PgSql service."""
     cmd = operating_system.service_discovery(PGSQL_SERVICE_CANDIDATES)
     LOG.info(
         _("{guest_id}: Stopping database engine with command ({command})."
           ).format(
               guest_id=CONF.guest_id,
               command=cmd['cmd_stop'],
           ))
     utils.execute_with_timeout(*cmd['cmd_stop'].split(), timeout=30)
Example #21
0
def service_discovery(service_candidates):
    result = operating_system.service_discovery(service_candidates)
    if result['type'] == 'sysvinit':
        result['cmd_bootstrap_pxc_cluster'] = ("sudo service %s bootstrap-pxc"
                                               % result['service'])
    elif result['type'] == 'systemd':
        result['cmd_bootstrap_pxc_cluster'] = ("sudo systemctl start "
                                               "*****@*****.**"
                                               % result['service'])
    return result
Example #22
0
def service_discovery(service_candidates):
    result = operating_system.service_discovery(service_candidates)
    if result['type'] == 'sysvinit':
        result['cmd_bootstrap_pxc_cluster'] = (
            "sudo service %s bootstrap-pxc" % result['service'])
    elif result['type'] == 'systemd':
        result['cmd_bootstrap_pxc_cluster'] = ("systemctl start "
                                               "*****@*****.**" %
                                               result['service'])
    return result
Example #23
0
 def _disable_redis_on_boot(self):
     """
     Disables redis on boot.
     """
     LOG.info(_("Disabling Redis on boot."))
     try:
         redis_service = operating_system.service_discovery(system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(redis_service["cmd_disable"], shell=True)
     except KeyError:
         raise RuntimeError("Command to disable Redis on boot not found.")
Example #24
0
 def _enable_db_on_boot(self):
     try:
         LOG.debug("Enable CouchDB on boot.")
         couchdb_service = operating_system.service_discovery(
             system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(couchdb_service['cmd_enable'],
                                    shell=True)
     except KeyError:
         raise RuntimeError(
             "Command to disable CouchDB server on boot not found.")
Example #25
0
 def _enable_redis_on_boot(self):
     """
     Enables redis on boot.
     """
     LOG.info(_('Enabling Redis on boot.'))
     try:
         redis_service = operating_system.service_discovery(
             system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(redis_service['cmd_enable'], shell=True)
     except KeyError:
         raise RuntimeError(_("Command to enable Redis on boot not found."))
Example #26
0
 def _enable_db_on_boot(self):
     """
     Enables Couchbase Server on boot.
     """
     LOG.info(_('Enabling Couchbase Server on boot.'))
     try:
         couchbase_service = operating_system.service_discovery(
             system.SERVICE_CANDIDATES)
         utils.execute_with_timeout(
             couchbase_service['cmd_enable'], shell=True)
     except KeyError:
         raise RuntimeError(_(
             "Command to enable Couchbase Server on boot not found."))
Example #27
0
 def stop_db(self, context):
     """Stop the PgSql service."""
     cmd = operating_system.service_discovery(PGSQL_SERVICE_CANDIDATES)
     LOG.info(
         _("{guest_id}: Stopping database engine with command ({command}).")
         .format(
             guest_id=CONF.guest_id,
             command=cmd['cmd_stop'],
         )
     )
     utils.execute_with_timeout(
         *cmd['cmd_stop'].split(),
         timeout=30
     )
Example #28
0
 def stop_db(self, update_db=False, do_not_start_on_reboot=False):
     LOG.info(_("Stopping mysql..."))
     if do_not_start_on_reboot:
         self._disable_mysql_on_boot()
     try:
         mysql_service = operating_system.service_discovery(MYSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(mysql_service["cmd_stop"], shell=True)
     except KeyError:
         raise RuntimeError("Service is not discovered.")
     if not self.status.wait_for_real_status_to_change_to(
         rd_instance.ServiceStatuses.SHUTDOWN, self.state_change_wait_time, update_db
     ):
         LOG.error(_("Could not stop MySQL!"))
         self.status.end_install_or_restart()
         raise RuntimeError("Could not stop MySQL!")
Example #29
0
 def stop_db(self, update_db=False, do_not_start_on_reboot=False):
     LOG.info(_("Stopping mysql..."))
     if do_not_start_on_reboot:
         self._disable_mysql_on_boot()
     try:
         mysql_service = operating_system.service_discovery(
             MYSQL_SERVICE_CANDIDATES)
         utils.execute_with_timeout(mysql_service['cmd_stop'], shell=True)
     except KeyError:
         raise RuntimeError("Service is not discovered.")
     if not self.status.wait_for_real_status_to_change_to(
             rd_instance.ServiceStatuses.SHUTDOWN,
             self.state_change_wait_time, update_db):
         LOG.error(_("Could not stop MySQL!"))
         self.status.end_install_or_restart()
         raise RuntimeError("Could not stop MySQL!")
Example #30
0
    def stop_db(self, update_db=False, do_not_start_on_reboot=False):
        """
        Stops Couchbase Server on the trove instance.
        """
        LOG.info(_("Stopping Couchbase Server..."))
        if do_not_start_on_reboot:
            self._disable_db_on_boot()

        try:
            couchbase_service = operating_system.service_discovery(system.SERVICE_CANDIDATES)
            utils.execute_with_timeout(couchbase_service["cmd_stop"], shell=True)
        except KeyError:
            raise RuntimeError("Command to stop Couchbase Server not found")

        if not self.status.wait_for_real_status_to_change_to(
            rd_instance.ServiceStatuses.SHUTDOWN, self.state_change_wait_time, update_db
        ):
            LOG.error(_("Could not stop Couchbase Server!"))
            self.status.end_install_or_restart()
            raise RuntimeError(_("Could not stop Couchbase Server"))
Example #31
0
    def stop_db(self, update_db=False, do_not_start_on_reboot=False):
        """
        Stops Couchbase Server on the trove instance.
        """
        LOG.info(_('Stopping Couchbase Server...'))
        if do_not_start_on_reboot:
            self._disable_db_on_boot()

        try:
            couchbase_service = operating_system.service_discovery(
                system.SERVICE_CANDIDATES)
            utils.execute_with_timeout(couchbase_service['cmd_stop'],
                                       shell=True)
        except KeyError:
            raise RuntimeError("Command to stop Couchbase Server not found")

        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.SHUTDOWN,
                self.state_change_wait_time, update_db):
            LOG.error(_('Could not stop Couchbase Server!'))
            self.status.end_install_or_restart()
            raise RuntimeError(_("Could not stop Couchbase Server"))
 def test_systemd_not_symlinked_type_service_discovery(self):
     with patch.object(os.path, 'isfile', side_effect=[False, False, True]):
         with patch.object(os.path, 'islink', return_value=False):
             mysql_service = operating_system.service_discovery(["mysql"])
     self.assertIsNotNone(mysql_service['cmd_start'])
     self.assertIsNotNone(mysql_service['cmd_enable'])
 def test_sysvinit_chkconfig_type_service_discovery(self):
     with patch.object(os.path, 'isfile',
                       side_effect=[False, True, False, True]):
         mysql_service = operating_system.service_discovery(["mysql"])
     self.assertIsNotNone(mysql_service['cmd_start'])
     self.assertIsNotNone(mysql_service['cmd_enable'])
Example #34
0
 def mysql_service(self):
     MYSQL_SERVICE_CANDIDATES = ["mysql", "mysqld", "mysql-server"]
     return operating_system.service_discovery(MYSQL_SERVICE_CANDIDATES)
Example #35
0
 def mysql_service(self):
     service_candidates = self.service_candidates
     return operating_system.service_discovery(service_candidates)
Example #36
0
 def _get_service(self):
     if self.is_query_router:
         return operating_system.service_discovery(system.MONGOS_SERVICE_CANDIDATES)
     else:
         return operating_system.service_discovery(system.MONGOD_SERVICE_CANDIDATES)
Example #37
0
 def test_upstart_type_service_discovery(self):
     with patch.object(os.path, "isfile", side_effect=[True]):
         mysql_service = operating_system.service_discovery(["mysql"])
     self.assertIsNotNone(mysql_service["cmd_start"])
     self.assertIsNotNone(mysql_service["cmd_enable"])
Example #38
0
 def test_systemd_symlinked_type_service_discovery(self, mock_base, mock_path, mock_islink):
     with patch.object(os.path, "isfile", side_effect=[False, False, True]):
         mysql_service = operating_system.service_discovery(["mysql"])
     self.assertIsNotNone(mysql_service["cmd_start"])
     self.assertIsNotNone(mysql_service["cmd_enable"])
 def test_sysvinit_chkconfig_type_service_discovery(self):
     with patch.object(os.path, 'isfile',
                       side_effect=[False, True, False, True]):
         mysql_service = operating_system.service_discovery(["mysql"])
     self.assertIsNotNone(mysql_service['cmd_start'])
     self.assertIsNotNone(mysql_service['cmd_enable'])
 def test_systemd_not_symlinked_type_service_discovery(self):
     with patch.object(os.path, 'isfile', side_effect=[False, False, True]):
         with patch.object(os.path, 'islink', return_value=False):
             mysql_service = operating_system.service_discovery(["mysql"])
     self.assertIsNotNone(mysql_service['cmd_start'])
     self.assertIsNotNone(mysql_service['cmd_enable'])
Example #41
0
 def mysql_service(self):
     service_candidates = self.service_candidates
     return operating_system.service_discovery(service_candidates)
Example #42
0
 def mysql_service(self):
     MYSQL_SERVICE_CANDIDATES = ["mysql", "mysqld", "mysql-server"]
     return operating_system.service_discovery(MYSQL_SERVICE_CANDIDATES)