def test_snapshot_network_error(self, mcompress, mexecute, mget): objs = [ { "type": "file", "path": "/remote_file1", "host": { "address": "remote_host1" }, }, { "type": "dir", "path": "/remote_dir1", "host": { "address": "remote_host1" }, }, { "type": "file", "path": "/remote_file1", "host": { "address": "remote_host2" }, }, ] drv = mock.MagicMock() drv.snapshot.side_effect = [ fabric.exceptions.NetworkError, None, fabric.exceptions.NetworkError, None, None, ] mget.return_value = drv conf = Config() conf.objs = deque(objs) offline_obj = { 'path': '/remote_file1', 'host': { 'address': 'remote_host1' }, 'type': 'offline', } processed_obj = { 'path': '/remote_file1', 'host': { 'address': 'remote_host2' }, 'type': 'file', } manager = Manager(conf) manager.snapshot() mget.assert_has_calls([ mock.call(offline_obj, conf), mock.call(processed_obj, conf), mock.call(offline_obj, conf), mock.call(offline_obj, conf) ], any_order=True) mexecute.assert_called_once_with('rm -rf /tmp')
def test_snapshot(self, mcompress, mexecute, mget): data = { "type": "file", "path": "/remote_dir/remote_file", "host": { "address": "remote_host", }, } conf = mock.MagicMock() conf.target = "/target/data" conf.objects = [data] conf.lastdump = tempfile.mkstemp()[1] manager = Manager(conf) manager.snapshot() mget.assert_called_once_with(data, conf) mexecute.assert_called_once_with('rm -rf /target')
def dump(): """Entry point dump script.""" from shotgun.config import Config as ShotgunConfig from shotgun.manager import Manager as ShotgunManager logger.debug("Starting snapshot procedure") conf = ShotgunConfig(DumpTask.conf()) manager = ShotgunManager(conf) print(manager.snapshot())
def test_snapshot(self, mcompress, mget): data = { "type": "file", "path": "/remote_dir/remote_file", "host": { "address": "remote_host", }, } conf = mock.MagicMock() conf.target = "/target/data" conf.objects = [data] conf.lastdump = tempfile.mkstemp()[1] conf.self_log_object = {"type": "file", "path": "/path"} manager = Manager(conf) manager.snapshot() calls = [mock.call(data, conf), mock.call(conf.self_log_object, conf)] mget.assert_has_calls(calls, any_order=True)
def make_snapshot(args): """Generates snapshot :param args: argparse object """ config_object = Config(read_config(args.config)) manager = Manager(config_object) snapshot_path = manager.snapshot() logger.info(u'Snapshot path: {0}'.format(snapshot_path))
def test_snapshot(self, mcompress, mexecute, mget): data = { "type": "file", "path": "/remote_dir/remote_file", "host": { "address": "remote_host", }, } conf = mock.MagicMock() conf.target = "/target/data" conf.objects = [data] conf.lastdump = tempfile.mkstemp()[1] conf.self_log_object = {"type": "file", "path": "/path"} manager = Manager(conf) manager.snapshot() calls = [mock.call(data, conf), mock.call(conf.self_log_object, conf)] mget.assert_has_calls(calls, any_order=True) mexecute.assert_called_once_with('rm -rf /target')
def test_snapshot_network_error(self, mcompress, mexecute, mget): objs = [ {"type": "file", "path": "/remote_file1", "host": {"address": "remote_host1"}, }, {"type": "dir", "path": "/remote_dir1", "host": {"address": "remote_host1"}, }, {"type": "file", "path": "/remote_file1", "host": {"address": "remote_host2"}, }, ] drv = mock.MagicMock() drv.snapshot.side_effect = [ fabric.exceptions.NetworkError, None, fabric.exceptions.NetworkError, None, None, ] mget.return_value = drv conf = Config() conf.objs = deque(objs) offline_obj = { 'path': '/remote_file1', 'host': {'address': 'remote_host1'}, 'type': 'offline', } processed_obj = { 'path': '/remote_file1', 'host': {'address': 'remote_host2'}, 'type': 'file', } manager = Manager(conf) manager.snapshot() mget.assert_has_calls([mock.call(offline_obj, conf), mock.call(processed_obj, conf), mock.call(offline_obj, conf), mock.call(offline_obj, conf)], any_order=True) mexecute.assert_called_once_with('rm -rf /tmp')
# a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json import logging import os import sys sys.path[:0] = [os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))] from shotgun.config import Config from shotgun.manager import Manager logging.basicConfig(level=logging.DEBUG) with open("snapshot.json", "r") as fo: data = json.loads(fo.read()) config = Config(data) manager = Manager(config) manager.snapshot()
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import json import logging import os import sys sys.path[:0] = [os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))] from shotgun.config import Config from shotgun.manager import Manager logging.basicConfig(level=logging.DEBUG) with open("snapshot.json", "r") as fo: data = json.loads(fo.read()) config = Config(data) manager = Manager(config) manager.snapshot()