except Exception as e: logger.info( "No backup found (probably the first) or already initialized" ) pass else: logger.info("Duplicity disabled...") # We dump the databases services if needed if settings['module']['databases'] is True: logger.info("Start to dump databases...") listServices = rancherService.getServices() listDump = backupService.searchDump( settings['duplicity']['source-path'] + '/dump', listServices) backupService.runDump(listDump) logger.info("The dumping databases is finished.") # We dump the rancher stack settings if needed if settings['module']['stack'] is True: logger.info("Start to export stack as json...") listStacks = rancherService.getStacks() backupService.dumpStacksSettings( settings['duplicity']['source-path'] + '/rancher', listStacks) logger.info("The exporting of stack if finished") # We dump the rancher database if needed if settings['module']['rancher-db'] is True: logger.info("Start to dump Rancher database...") backupService.dumpRancherDatabase(
def testRunDump(self, mock_runCmd): backupService = Backup() listServices = [{ 'type': 'service', 'name': 'test', 'state': 'active', 'launchConfig': { 'imageUuid': 'test/postgres:latest', 'environment': { 'POSTGRES_USER': '******', 'POSTGRES_DB': 'test', 'POSTGRES_PASSWORD': '******' } }, 'links': { 'environment': 'https://fake/environment', 'instances': 'https://fake/instances', }, 'stack': { 'name': 'stack-test' }, 'instances': [{ 'state': 'disabled', 'primaryIpAddress': '10.0.0.1', 'host': { 'name': 'host-1' }, 'links': { 'hosts': 'https://fake/hosts' } }, { 'state': 'running', 'primaryIpAddress': '10.0.0.2', 'host': { 'name': 'host-1' }, 'links': { 'hosts': 'https://fake/hosts' } }, { 'state': 'running', 'primaryIpAddress': '10.0.0.3', 'host': { 'name': 'host-1' }, 'links': { 'hosts': 'https://fake/hosts' } }], }, { 'type': 'service', 'name': 'test2', 'state': 'active', 'launchConfig': { 'imageUuid': 'test/mysql:latest', 'environment': { 'MYSQL_USER': '******', 'MYSQL_DB': 'test', 'MYSQL_PASSWORD': '******' } }, 'links': { 'environment': 'https://fake/environment', 'instances': 'https://fake/instances', }, 'stack': { 'name': 'stack-test' }, 'instances': [{ 'state': 'disabled', 'primaryIpAddress': '10.1.0.1', 'host': { 'name': 'host-1' }, 'links': { 'hosts': 'https://fake/hosts' } }, { 'state': 'running', 'primaryIpAddress': '10.1.0.2', 'host': { 'name': 'host-1' }, 'links': { 'hosts': 'https://fake/hosts' } }, { 'state': 'running', 'primaryIpAddress': '10.1.0.3', 'host': { 'name': 'host-1' }, 'links': { 'hosts': 'https://fake/hosts' } }], }] listDump = [{ 'service': listServices[0], 'target_dir': '/tmp/backup/stack-test/test', 'commands': [ 'pg_dump -h 10.0.0.2 -U user -d test -f /tmp/backup/stack-test/test/test.dump' ], 'entrypoint': "sh -c", 'environments': ['PGPASSWORD:pass'], 'image': 'postgres:latest' }, { 'service': listServices[1], 'target_dir': '/tmp/backup/stack-test/test2', 'commands': [ 'mysqldump -h 10.1.0.2 -U user -d test -f /tmp/backup/stack-test/test2/test.dump', 'fake_cmd2 -h 10.1.0.2 -U user' ], 'environments': ['MYSQLPASSWORD:pass'], 'image': 'mysql:latest' }] backupService.runDump(listDump) #print("Nb call %s" % mock_runCmd.call_args_list) mock_runCmd.assert_any_call(mock.ANY, 'docker pull postgres:latest') mock_runCmd.assert_any_call( mock.ANY, "docker run --rm --entrypoint='sh -c' -v /tmp/backup/stack-test/test:/tmp/backup/stack-test/test -e 'PGPASSWORD=pass' postgres:latest pg_dump -h 10.0.0.2 -U user -d test -f /tmp/backup/stack-test/test/test.dump" ) mock_runCmd.assert_any_call(mock.ANY, 'docker pull mysql:latest') mock_runCmd.assert_any_call( mock.ANY, "docker run --rm -v /tmp/backup/stack-test/test2:/tmp/backup/stack-test/test2 -e 'MYSQLPASSWORD=pass' mysql:latest mysqldump -h 10.1.0.2 -U user -d test -f /tmp/backup/stack-test/test2/test.dump" )