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 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 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] manager = Manager(conf) manager.snapshot() mget.assert_called_once_with(data, conf) mexecute.assert_called_once_with('rm -rf /target')
def test_report(self, mock_action): objs = ["o1", "o2"] mock_action.side_effect = [["r1", "r2"], ["r3"]] conf = mock.Mock() conf.objects = objs manager = Manager(conf) manager.action_single = mock_action reports = [] for rep in manager.report(): reports.append(rep) self.assertEqual(["r1", "r2", "r3"], reports) expected_calls = [ mock.call('o1', action='report'), mock.call('o2', action='report')] self.assertEqual(expected_calls, mock_action.call_args_list)
def test_report(self, mock_action): objs = ["o1", "o2"] mock_action.side_effect = [["r1", "r2"], ["r3"]] conf = mock.Mock() conf.objects = objs manager = Manager(conf) manager.action_single = mock_action reports = [] for rep in manager.report(): reports.append(rep) self.assertEqual(["r1", "r2", "r3"], reports) expected_calls = [ mock.call('o1', action='report'), mock.call('o2', action='report') ] self.assertEqual(expected_calls, mock_action.call_args_list)
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 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_action_single(self, mock_driver): mock_driver_instance = mock.Mock() mock_driver_instance.report = mock.Mock() mock_driver_instance.snapshot = mock.Mock() mock_driver.getDriver = mock.Mock(return_value=mock_driver_instance) manager = Manager('conf') manager.action_single('object', action='report') mock_driver.getDriver.assert_called_once_with('object', 'conf') mock_driver_instance.report.assert_called_once_with() self.assertFalse(mock_driver_instance.snapshot.called) mock_driver.getDriver.reset_mock() # default action should be 'snapshot' manager.action_single('object') mock_driver.getDriver.assert_called_once_with('object', 'conf') mock_driver_instance.report.mock_reset() mock_driver_instance.snapshot.assert_called_once_with() self.assertFalse(mock_driver_instance.report.called)
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')
# 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()
# 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()
def initialize_cmd(self, parsed_args): with open(parsed_args.config, "r") as f: self.config = Config(yaml.safe_load(f)) self.manager = Manager(self.config)