def on_start(self): if iptables.enabled(): iptables.save() optparser = bus.optparser if self._flag_exists(self.FLAG_REBOOT): self._logger.info("Scalarizr resumed after reboot") self._clear_flag(self.FLAG_REBOOT) self._start_after_reboot() elif self._flag_exists(self.FLAG_HALT): self._logger.info("Scalarizr resumed after stop") self._clear_flag(self.FLAG_HALT) self._start_after_stop() elif optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info('Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start")
def on_start(self): if iptables.enabled(): iptables.save() optparser = bus.optparser if self._flag_exists(self.FLAG_REBOOT) or self._flag_exists( self.FLAG_HALT): self._logger.info("Scalarizr resumed after reboot") self._clear_flag(self.FLAG_REBOOT) self._clear_flag(self.FLAG_HALT) self._check_control_ports() self._start_after_reboot() elif optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info( 'Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def on_start(self): if iptables.enabled(): iptables.save() optparser = bus.optparser if Flag.exists(Flag.REBOOT) or Flag.exists(Flag.HALT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) Flag.clear(Flag.HALT) self._check_control_ports() self._start_after_reboot() elif optparser and optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info('Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def on_start(self): if iptables.enabled(): iptables.save() optparser = bus.optparser if os_dist['family'] != 'Windows': if os.path.exists(self.saved_boot_id_file): saved_boot_id = None current_boot_id = None with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'r') as fp: saved_boot_id = fp.read() if saved_boot_id and saved_boot_id != current_boot_id: Flag.set(Flag.REBOOT) with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'w') as saved_fp: saved_fp.write(current_boot_id) if Flag.exists(Flag.REBOOT) or Flag.exists(Flag.HALT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) Flag.clear(Flag.HALT) self._check_control_ports() self._start_after_reboot() elif optparser and optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info( 'Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def on_start(self): if iptables.enabled(): iptables.save() optparser = bus.optparser if os_dist['family'] != 'Windows': if os.path.exists(self.saved_boot_id_file): saved_boot_id = None current_boot_id = None with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'r') as fp: saved_boot_id = fp.read() if saved_boot_id and saved_boot_id != current_boot_id: Flag.set(Flag.REBOOT) with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'w') as saved_fp: saved_fp.write(current_boot_id) if Flag.exists(Flag.REBOOT) or Flag.exists(Flag.HALT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) Flag.clear(Flag.HALT) self._check_control_ports() self._start_after_reboot() elif optparser and optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info('Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def test_save(self, open, iptables_save): # 1 iptables.linux.os.__getitem__.return_value = "RedHat" iptables.save() assert not open.called iptables.linux.build_cmd_args.assert_called_once_with( executable='service', short=["iptables", "save"]) iptables.linux.system.assert_called_once_with( iptables.linux.build_cmd_args.return_value) # 2 iptables.linux.build_cmd_args.reset_mock() iptables.linux.system.reset_mock() iptables.linux.os.__getitem__.return_value = "Debian" iptables.save() open.assert_called_once_with('/etc/network/if-pre-up.d/iptables.sh', 'w') open.return_value.__enter__.return_value.write.assert_called_once_with( '#!/bin/bash\niptables-restore < /etc/iptables.rules') iptables_save.assert_called_once_with('/etc/iptables.rules')