コード例 #1
0
    def test_get_raw_data_with_context(self, swift_client, _get_raw_data, ctx,
                                       url_for):
        client_instance = mock.Mock()
        swift_client.return_value = client_instance
        test_context = mock.Mock()
        test_context.auth_token = 'testtoken'
        test_context.auth_plugin = None
        ctx.return_value = test_context
        url_for.return_value = 'url_for'
        job_binary = mock.Mock()
        job_binary.url = 'swift://container/object'

        job_binary.extra = dict(user='******', password='******')
        i_s.get_raw_data_with_context(job_binary)
        self.assertEqual([
            mock.call(auth_version='2.0',
                      cacert=None,
                      insecure=False,
                      max_backoff=10,
                      preauthtoken='testtoken',
                      preauthurl='url_for',
                      retries=5,
                      retry_on_ratelimit=True,
                      starting_backoff=10)
        ], swift_client.call_args_list)
        _get_raw_data.assert_called_with(job_binary, client_instance)
コード例 #2
0
    def test_get_raw_data_with_context(self, swift_client, _get_raw_data, ctx):
        client_instance = mock.Mock()
        swift_client.return_value = client_instance
        test_context = mock.Mock()
        test_context.auth_token = 'testtoken'
        ctx.return_value = test_context

        job_binary = mock.Mock()
        job_binary.url = 'swift://container/object'

        job_binary.extra = dict(user='******', password='******')
        i_s.get_raw_data_with_context(job_binary)
        swift_client.assert_called_with('testtoken')
        _get_raw_data.assert_called_with(job_binary, client_instance)
コード例 #3
0
    def test_get_raw_data_with_context(self, swift_client, _get_raw_data, ctx):
        client_instance = mock.Mock()
        swift_client.return_value = client_instance
        test_context = mock.Mock()
        test_context.auth_token = 'testtoken'
        ctx.return_value = test_context

        job_binary = mock.Mock()
        job_binary.url = 'swift://container/object'

        job_binary.extra = dict(user='******', password='******')
        i_s.get_raw_data_with_context(job_binary)
        swift_client.assert_called_with('testtoken')
        _get_raw_data.assert_called_with(job_binary, client_instance)
コード例 #4
0
ファイル: dispatch.py プロジェクト: crobby/sahara
def get_raw_binary(job_binary, proxy_configs=None,
                   with_context=False, remote=None):
    '''Get the raw data for a job binary

    This will retrieve the raw data for a job binary from it's source. In the
    case of Swift based binaries there is a precedence of credentials for
    authenticating the client. Requesting a context based authentication takes
    precendence over proxy user which takes precendence over embedded
    credentials.

    :param job_binary: The job binary to retrieve
    :param proxy_configs: Proxy user configuration to use as credentials
    :param with_context: Use the current context as credentials
    :param remote: The remote contains node group and cluster information
    :returns: The raw data from a job binary

    '''
    url = job_binary.url
    if url.startswith("internal-db://"):
        res = db.get_raw_data(context.ctx(), job_binary)

    if url.startswith(su.SWIFT_INTERNAL_PREFIX):
        if with_context:
            res = i_swift.get_raw_data_with_context(job_binary)
        else:
            res = i_swift.get_raw_data(job_binary, proxy_configs)

    if url.startswith(m.MANILA_PREFIX):
        res = manila.get_file_info(job_binary, remote)

    return res
コード例 #5
0
ファイル: dispatch.py プロジェクト: mastermind1981/sahara-1
def get_raw_binary(job_binary,
                   proxy_configs=None,
                   with_context=False,
                   remote=None):
    '''Get the raw data for a job binary

    This will retrieve the raw data for a job binary from it's source. In the
    case of Swift based binaries there is a precedence of credentials for
    authenticating the client. Requesting a context based authentication takes
    precedence over proxy user which takes precedence over embedded
    credentials.

    :param job_binary: The job binary to retrieve
    :param proxy_configs: Proxy user configuration to use as credentials
    :param with_context: Use the current context as credentials
    :param remote: The remote contains node group and cluster information
    :returns: The raw data from a job binary

    '''
    url = job_binary.url
    if url.startswith("internal-db://"):
        res = db.get_raw_data(context.ctx(), job_binary)

    if url.startswith(su.SWIFT_INTERNAL_PREFIX):
        if with_context:
            res = i_swift.get_raw_data_with_context(job_binary)
        else:
            res = i_swift.get_raw_data(job_binary, proxy_configs)

    if url.startswith(m.MANILA_PREFIX):
        res = manila.get_file_info(job_binary, remote)

    return res
コード例 #6
0
ファイル: test_internal_swift.py プロジェクト: Imperat/sahara
    def test_get_raw_data_with_context(self, swift_client, _get_raw_data, ctx,
                                       url_for):
        client_instance = mock.Mock()
        swift_client.return_value = client_instance
        test_context = mock.Mock()
        test_context.auth_token = 'testtoken'
        test_context.auth_plugin = None
        ctx.return_value = test_context
        url_for.return_value = 'url_for'
        job_binary = mock.Mock()
        job_binary.url = 'swift://container/object'

        job_binary.extra = dict(user='******', password='******')
        i_s.get_raw_data_with_context(job_binary)
        self.assertEqual([mock.call(
            auth_version='2.0',
            cacert=None, insecure=False,
            max_backoff=10,
            preauthtoken='testtoken',
            preauthurl='url_for', retries=5,
            retry_on_ratelimit=True, starting_backoff=10)],
            swift_client.call_args_list)
        _get_raw_data.assert_called_with(job_binary, client_instance)