Esempio n. 1
0
def _set_modify_transfer(modify_transfer, config):
    if modify_transfer is None:
        if not config.use_local_files:
            if config.features.supports_latest_client:
                modify_transfer = transfer_composable.VoTransfer()
            else:
                modify_transfer = transfer_composable.CadcTransfer()
    return modify_transfer
Esempio n. 2
0
def test_data_execute_v(test_config):
    test_config.features.supports_latest_client = True
    test_obs_id = 'test_obs_id'
    test_dir = os.path.join(tc.THIS_DIR, test_obs_id)
    test_fits_fqn = os.path.join(test_dir, tc.TestStorageName().file_name)
    try:
        if not os.path.exists(test_dir):
            os.mkdir(test_dir, mode=0o755)
        # precondition = open(test_fits_fqn, 'w')
        # precondition.close()

        test_data_visitors = [TestVisit]
        repo_client_mock = Mock(autospec=True)
        cadc_client_mock = Mock(autospec=True)
        cadc_client_mock.copy.side_effect = tc.mock_copy_md5
        test_observer = Mock(autospec=True)
        test_cred = ''
        test_transferrer = transfer_composable.VoTransfer()
        test_transferrer.cadc_client = cadc_client_mock

        ec.CaomExecute._data_cmd_info = Mock(side_effect=_get_fname)
        repo_client_mock.read.side_effect = tc.mock_read

        # run the test
        test_executor = ec.DataVisit(
            test_config,
            tc.TestStorageName(),
            test_cred,
            cadc_client_mock,
            repo_client_mock,
            test_data_visitors,
            mc.TaskType.MODIFY,
            test_observer,
            test_transferrer,
        )
        test_executor.execute(None)

        # check that things worked as expected
        assert repo_client_mock.read.called, 'read call missed'
        assert repo_client_mock.update.called, 'update call missed'
        assert test_observer.metrics.observe.called, 'observe not called'
        assert cadc_client_mock.copy.called, 'copy not called'
        cadc_client_mock.copy.assert_called_with(
            'ad:TEST/test_obs_id.fits.gz', test_fits_fqn, send_md5=True
        ), 'wrong call args'
    finally:
        if os.path.exists(test_fits_fqn):
            os.unlink(test_fits_fqn)
        if os.path.exists(test_dir):
            os.rmdir(test_dir)
Esempio n. 3
0
def test_vo_transfer():
    cadc_client_mock = Mock(autospec=True)
    test_config = mc.Config()
    test_config.working_directory = test_conf.TEST_DATA_DIR
    test_config.proxy_file_name = 'proxy.pem'
    test_subject = tc.VoTransfer()
    assert test_subject is not None, 'expect a result'
    test_subject.cadc_client = cadc_client_mock
    test_source = 'vault:goliaths/test_file.fits'
    test_dest = '/tmp/test_file.fits'
    test_subject.get(test_source, test_dest)
    assert cadc_client_mock.copy.called, 'should have been called'
    args, kwargs = cadc_client_mock.copy.call_args
    assert args[0] == test_source, 'wrong source'
    assert args[1] == test_dest, 'wrong source'
Esempio n. 4
0
def test_data_execute(test_config):
    test_obs_id = 'test_obs_id'
    test_dir = os.path.join(tc.THIS_DIR, test_obs_id)
    test_fits_fqn = os.path.join(test_dir, tc.TestStorageName().file_name)
    try:
        if not os.path.exists(test_dir):
            os.mkdir(test_dir, mode=0o755)
        precondition = open(test_fits_fqn, 'w')
        precondition.close()
        logging.error(test_fits_fqn)

        test_data_visitors = [TestVisit]
        repo_client_mock = Mock()
        data_client_mock = Mock()
        test_observer = Mock()
        test_cred = ''
        test_transferrer = transfer_composable.VoTransfer()
        test_transferrer.cadc_client = data_client_mock

        ec.CaomExecute._data_cmd_info = Mock(side_effect=_get_fname)
        repo_client_mock.read.side_effect = tc.mock_read

        # run the test
        test_executor = ec.DataVisit(
            test_config,
            tc.TestStorageName(),
            test_cred,
            data_client_mock,
            repo_client_mock,
            test_data_visitors,
            mc.TaskType.MODIFY,
            test_observer,
            test_transferrer,
        )
        test_executor.execute(None)

        # check that things worked as expected
        assert repo_client_mock.read.called, 'read call missed'
        assert repo_client_mock.update.called, 'update call missed'
        assert test_observer.metrics.observe.called, 'observe not called'
    finally:
        if os.path.exists(test_fits_fqn):
            os.unlink(test_fits_fqn)
        if os.path.exists(test_dir):
            os.rmdir(test_dir)