def restore(self, basedir): """run restore on the snapfile""" # if files record file isn't found, simply return if not os.path.isfile(basedir + "/services.xml"): return record = ServicesRecordFile(basedir + "/services.xml") services = record.read() for sservice in services: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring service " + sservice.name) service_instance = self.load_service(sservice.name) # install the prerequisites if the services is not available if not service_instance.is_available(): service_instance.install_prereqs() if service_instance.is_available(): service_instance.restore(basedir) # if service is still not available, log this and skip it elif snap.config.options.log_level_at_least('normal'): snap.callback.snapcallback.message("Could not restore " + sservice.name + " service")
def testWriteServicesRecordFile(self): file_path = os.path.join(os.path.dirname(__file__), "data/services-out.xml") services = [Service(name="foo"), Service(name="baz")] service_record_file = ServicesRecordFile(file_path) service_record_file.write(services) contents = FileManager.read_file(file_path) self.assertEqual("<services><service>foo</service><service>baz</service></services>", contents) os.remove(file_path)
def testWriteServicesRecordFile(self): file_path = os.path.join(os.path.dirname(__file__), "data/services-out.xml") services = [Service(name='foo'), Service(name='baz')] service_record_file = ServicesRecordFile(file_path) service_record_file.write(services) contents = FileManager.read_file(file_path) self.assertEqual("<services><service>foo</service><service>baz</service></services>", contents) os.remove(file_path)
def backup(self, basedir, include=[], exclude=[]): """run backup on each of the services included""" services = [] for service in include: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Backing up service " + service); service_instance = self.load_service(service) # check if service is running / available on machine b4 backing up if service_instance.is_available(): sservice = service_instance.backup(basedir) services.append(Service(name=service)) record = ServicesRecordFile(basedir + "/services.xml") record.write(services)
def backup(self, basedir, include=[], exclude=[]): """run backup on each of the services included""" services = [] for service in include: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Backing up service " + service) service_instance = self.load_service(service) # check if service is running / available on machine b4 backing up if service_instance.is_available(): sservice = service_instance.backup(basedir) services.append(Service(name=service)) record = ServicesRecordFile(basedir + "/services.xml") record.write(services)
def testReadServicesRecordFile(self): file_path = os.path.join(os.path.dirname(__file__), "data/servicesfile.xml") services = ServicesRecordFile(file_path).read() service_names = [] for service in services: service_names.append(service.name) self.assertIn('iptables', service_names) self.assertIn('mysql', service_names) self.assertIn('postgresql', service_names)
def testDispatcherBackup(self): snap.backends.services.adapters.mock.Mock.mock_is_available = True snap.backends.services.adapters.mock.Mock.is_available_called = False snap.backends.services.adapters.mock.Mock.backup_called = False dispatcher = snap.backends.services.dispatcher.Dispatcher() dispatcher.backup(self.basedir, include=["mock"]) self.assertTrue(snap.backends.services.adapters.mock.Mock.is_available_called) self.assertTrue(snap.backends.services.adapters.mock.Mock.backup_called) self.assertTrue(os.path.isfile(os.path.join(self.basedir, "services.xml"))) record = ServicesRecordFile(os.path.join(self.basedir, "services.xml")) services = record.read() service_names = [] for service in services: service_names.append(service.name) self.assertIn("mock", service_names)
def testDispatcherBackup(self): snap.backends.services.adapters.mock.Mock.mock_is_available = True snap.backends.services.adapters.mock.Mock.is_available_called = False snap.backends.services.adapters.mock.Mock.backup_called = False dispatcher = snap.backends.services.dispatcher.Dispatcher() dispatcher.backup(self.basedir, include=['mock']) self.assertTrue( snap.backends.services.adapters.mock.Mock.is_available_called) self.assertTrue( snap.backends.services.adapters.mock.Mock.backup_called) self.assertTrue( os.path.isfile(os.path.join(self.basedir, "services.xml"))) record = ServicesRecordFile(os.path.join(self.basedir, "services.xml")) services = record.read() service_names = [] for service in services: service_names.append(service.name) self.assertIn("mock", service_names)
def restore(self, basedir): """run restore on the snapfile""" # if files record file isn't found, simply return if not os.path.isfile(basedir + "/services.xml"): return record = ServicesRecordFile(basedir + "/services.xml") services = record.read() for sservice in services: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring service " + sservice.name); service_instance = self.load_service(sservice.name) # install the prerequisites if the services is not available if not service_instance.is_available(): service_instance.install_prereqs() if service_instance.is_available(): service_instance.restore(basedir) # if service is still not available, log this and skip it elif snap.config.options.log_level_at_least('normal'): snap.callback.snapcallback.message("Could not restore " + sservice.name + " service")