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 reboot(self): try: LOG.debug("Instance %s calling stop_mysql..." % self.id) self.guest.stop_mysql() LOG.debug("Rebooting instance %s" % self.id) self.server.reboot() # Poll nova until instance is active reboot_time_out = int(config.Config.get("reboot_time_out", 60 * 2)) def update_server_info(): self._refresh_compute_server_info() return self.server.status == 'ACTIVE' utils.poll_until( update_server_info, sleep_time=2, time_out=reboot_time_out) # Set the status to PAUSED. The guest agent will reset the status # when the reboot completes and MySQL is running. status = InstanceServiceStatus.find_by(instance_id=self.id) status.set_status(inst_models.ServiceStatuses.PAUSED) status.save() LOG.debug("Successfully rebooted instance %s" % self.id) except Exception, e: LOG.error("Failed to reboot instance %s: %s" % (self.id, str(e)))
def _service_is_active(self): """ Check that the database guest is active. This function is meant to be called with poll_until to check that the guest is alive before sending a 'create' message. This prevents over billing a customer for a instance that they can never use. Returns: boolean if the service is active. Raises: ReddwarfError if the service is in a failure state. """ service = InstanceServiceStatus.find_by(instance_id=self.id) status = service.get_status() if status == ServiceStatuses.RUNNING: return True elif status not in [ServiceStatuses.NEW, ServiceStatuses.BUILDING]: raise ReddwarfError("Service not active, status: %s" % status) c_id = self.db_info.compute_instance_id nova_status = self.nova_client.servers.get(c_id).status if nova_status in [InstanceStatus.ERROR, InstanceStatus.FAILED]: raise ReddwarfError("Server not active, status: %s" % nova_status) return False
def reboot(self): try: LOG.debug("Instance %s calling stop_mysql..." % self.id) self.guest.stop_mysql() LOG.debug("Rebooting instance %s" % self.id) self.server.reboot() # Poll nova until instance is active reboot_time_out = int(config.Config.get("reboot_time_out", 60 * 2)) def update_server_info(): self._refresh_compute_server_info() return self.server.status == 'ACTIVE' utils.poll_until(update_server_info, sleep_time=2, time_out=reboot_time_out) # Set the status to PAUSED. The guest agent will reset the status # when the reboot completes and MySQL is running. status = InstanceServiceStatus.find_by(instance_id=self.id) status.set_status(inst_models.ServiceStatuses.PAUSED) status.save() LOG.debug("Successfully rebooted instance %s" % self.id) except Exception, e: LOG.error("Failed to reboot instance %s: %s" % (self.id, str(e)))
def update_db(): status = InstanceServiceStatus.find_by(instance_id=self.id) if instance_name.endswith('GUEST_ERROR'): status.status = ServiceStatuses.FAILED else: status.status = ServiceStatuses.RUNNING status.save() AgentHeartBeat.create(instance_id=self.id)
def set_server_running(): from reddwarf.instance.models import DBInstance from reddwarf.instance.models import InstanceServiceStatus from reddwarf.instance.models import ServiceStatuses instance = DBInstance.find_by(compute_instance_id=id) LOG.debug("Setting server %s to running" % instance.id) status = InstanceServiceStatus.find_by(instance_id=instance.id) status.status = ServiceStatuses.RUNNING status.save()
def _set_status(self, new_status="RUNNING"): from reddwarf.instance.models import InstanceServiceStatus from reddwarf.instance.models import ServiceStatuses print ("Setting status to %s" % new_status) states = {"RUNNING": ServiceStatuses.RUNNING, "SHUTDOWN": ServiceStatuses.SHUTDOWN} status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = states[new_status] status.save()
def restart(self): from reddwarf.instance.models import InstanceServiceStatus from reddwarf.instance.models import ServiceStatuses # All this does is restart, and shut off the status updates while it # does so. So there's actually nothing to do to fake this out except # take a nap. time.sleep(1) status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = ServiceStatuses.RUNNING status.save()
def __call__(self): audit_start, audit_end = NotificationTransformer._get_audit_period() messages = [] db_infos = instance_models.DBInstance.find_all(deleted=False) for db_info in db_infos: service_status = InstanceServiceStatus.find_by( instance_id=db_info.id) instance = SimpleMgmtInstance(None, db_info, None, service_status) message = self.transform_instance(instance, audit_start, audit_end) messages.append(message) return messages
def _set_status(self, new_status='RUNNING'): from reddwarf.instance.models import InstanceServiceStatus from reddwarf.instance.models import ServiceStatuses print("Setting status to %s" % new_status) states = { 'RUNNING': ServiceStatuses.RUNNING, 'SHUTDOWN': ServiceStatuses.SHUTDOWN, } status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = states[new_status] status.save()
def __init__(self, host_info): self.name = host_info.name self.percent_used = host_info.percentUsed self.total_ram = host_info.totalRAM self.used_ram = host_info.usedRAM self.instances = host_info.instances for instance in self.instances: instance['server_id'] = instance['uuid'] del instance['uuid'] try: db_info = DBInstance.find_by( compute_instance_id=instance['server_id']) instance['id'] = db_info.id instance['tenant_id'] = db_info.tenant_id status = InstanceServiceStatus.find_by(instance_id=db_info.id) instance_info = SimpleInstance(None, db_info, status) instance['status'] = instance_info.status except exception.ReddwarfError as re: LOG.error(re) LOG.error("Compute Instance ID found with no associated RD " "instance: %s" % instance['server_id']) instance['id'] = None
def __init__(self, host_info): self.name = host_info.name self.percent_used = host_info.percentUsed self.total_ram = host_info.totalRAM self.used_ram = host_info.usedRAM self.instances = host_info.instances for instance in self.instances: instance['server_id'] = instance['uuid'] del instance['uuid'] try: db_info = DBInstance.find_by( compute_instance_id=instance['server_id']) instance['id'] = db_info.id instance['tenant_id'] = db_info.tenant_id status = InstanceServiceStatus.find_by( instance_id=db_info.id) instance_info = SimpleInstance(None, db_info, status) instance['status'] = instance_info.status except exception.ReddwarfError as re: LOG.error(re) LOG.error("Compute Instance ID found with no associated RD " "instance: %s" % instance['server_id']) instance['id'] = None
def _set_service_status_to_paused(self): status = InstanceServiceStatus.find_by(instance_id=self.id) status.set_status(inst_models.ServiceStatuses.PAUSED) status.save()
def set_server_running(): instance = DBInstance.find_by(compute_instance_id=id) LOG.debug("Setting server %s to running" % instance.id) status = InstanceServiceStatus.find_by(instance_id=instance.id) status.status = ServiceStatuses.RUNNING status.save()
def _refresh_compute_service_status(self): """Refreshes the service status info for an instance.""" service = InstanceServiceStatus.find_by(instance_id=self.id) self.service_status = service.get_status()
def _load_status(self): return InstanceServiceStatus.find_by(instance_id=self.id)
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 start_mysql_with_conf_changes(self, updated_memory_size): from reddwarf.instance.models import InstanceServiceStatus from reddwarf.instance.models import ServiceStatuses status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = ServiceStatuses.RUNNING status.save()
def stop_mysql(self): from reddwarf.instance.models import InstanceServiceStatus from reddwarf.instance.models import ServiceStatuses status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = ServiceStatuses.SHUTDOWN status.save()
def update_db(): status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = ServiceStatuses.SHUTDOWN status.save()
def update_db(): status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = ServiceStatuses.RUNNING status.save() AgentHeartBeat.create(instance_id=self.id)
def update_db(): status = InstanceServiceStatus.find_by(instance_id=self.id) status.status = ServiceStatuses.RUNNING status.save()
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)