Example #1
0
    def test_get_file_info(self, mount_shares, cluster_update, f_manilaclient):
        cluster_shares = [{'id': 'the_share_id', 'path': '/mnt/mymountpoint'}]

        ng_shares = [{
            'id': 'the_share_id',
            'path': '/mnt/othermountpoint'
        }, {
            'id': '123456',
            'path': '/mnt/themountpoint'
        }]

        job_binary = mock.Mock()
        job_binary.url = 'manila://the_share_id/the_path'

        remote = mock.Mock()
        remote.instance.node_group.cluster.shares = cluster_shares
        remote.instance.node_group.shares = ng_shares

        info = ms.get_file_info(job_binary, remote)
        self.assertItemsEqual(
            {
                'path': '/mnt/mymountpoint/the_path',
                'type': 'path'
            }, info)
        self.assertEqual(0, mount_shares.call_count)
        self.assertEqual(0, cluster_update.call_count)

        job_binary.url = 'manila://123456/the_path'
        info = ms.get_file_info(job_binary, remote)
        self.assertItemsEqual(
            {
                'path': '/mnt/themountpoint/the_path',
                'type': 'path'
            }, info)
        self.assertEqual(0, mount_shares.call_count)
        self.assertEqual(0, cluster_update.call_count)

        # This should return a default path, and should cause
        # a mount at the default location
        share = _FakeShare("missing_id")
        f_manilaclient.return_value = mock.Mock(shares=mock.Mock(get=mock.Mock(
            return_value=share)))

        job_binary.url = 'manila://missing_id/the_path'
        info = ms.get_file_info(job_binary, remote)
        self.assertItemsEqual(
            {
                'path': '/mnt/missing_id/the_path',
                'type': 'path'
            }, info)
        self.assertEqual(1, mount_shares.call_count)
        self.assertEqual(1, cluster_update.call_count)
Example #2
0
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
Example #3
0
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
Example #4
0
    def test_get_file_info(self, mount_shares, cluster_update, f_manilaclient):
        cluster_shares = [
            {'id': 'the_share_id',
             'path': '/mnt/mymountpoint'}
        ]

        ng_shares = [
            {'id': 'the_share_id',
             'path': '/mnt/othermountpoint'},
            {'id': '123456',
             'path': '/mnt/themountpoint'}
        ]

        job_binary = mock.Mock()
        job_binary.url = 'manila://the_share_id/the_path'

        remote = mock.Mock()
        remote.instance.node_group.cluster.shares = cluster_shares
        remote.instance.node_group.shares = ng_shares

        info = ms.get_file_info(job_binary, remote)
        self.assertItemsEqual({'path': '/mnt/mymountpoint/the_path',
                               'type': 'path'}, info)
        self.assertEqual(0, mount_shares.call_count)
        self.assertEqual(0, cluster_update.call_count)

        job_binary.url = 'manila://123456/the_path'
        info = ms.get_file_info(job_binary, remote)
        self.assertItemsEqual({'path': '/mnt/themountpoint/the_path',
                               'type': 'path'}, info)
        self.assertEqual(0, mount_shares.call_count)
        self.assertEqual(0, cluster_update.call_count)

        # This should return a default path, and should cause
        # a mount at the default location
        share = _FakeShare("missing_id")
        f_manilaclient.return_value = mock.Mock(
            shares=mock.Mock(
                get=mock.Mock(return_value=share)))

        job_binary.url = 'manila://missing_id/the_path'
        info = ms.get_file_info(job_binary, remote)
        self.assertItemsEqual({'path': '/mnt/missing_id/the_path',
                               'type': 'path'}, info)
        self.assertEqual(1, mount_shares.call_count)
        self.assertEqual(1, cluster_update.call_count)