Ejemplo n.º 1
0
    def get_job(self, job_id):
        """
        Get an object representing a job in progress.

        :type job_id: str
        :param job_id: The ID of the job

        :rtype: :class:`boto.glacier.job.Job`
        :return: A Job object representing the job.
        """
        response_data = self.layer1.describe_job(self.name, job_id)
        return Job(self, response_data)
Ejemplo n.º 2
0
class TestJob(unittest.TestCase):
    def setUp(self):
        self.api = mock.Mock(spec=Layer1)
        self.vault = mock.Mock()
        self.vault.layer1 = self.api
        self.job = Job(self.vault)

    def test_get_job_validate_checksum_success(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.get_output(byte_range=(1, 1024), validate_checksum=True)

    def test_get_job_validation_fails(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'BAD_TREE_HASH_VALUE'
            with self.assertRaises(TreeHashDoesNotMatchError):
                # With validate_checksum set to True, this call fails.
                self.job.get_output(byte_range=(1, 1024),
                                    validate_checksum=True)
            # With validate_checksum set to False, this call succeeds.
            self.job.get_output(byte_range=(1, 1024), validate_checksum=False)
Ejemplo n.º 3
0
class TestJob(unittest.TestCase):
    def setUp(self):
        self.api = mock.Mock(spec=Layer1)
        self.vault = mock.Mock()
        self.vault.layer1 = self.api
        self.job = Job(self.vault)

    def test_get_job_validate_checksum_success(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.get_output(byte_range=(1, 1024), validate_checksum=True)

    def test_get_job_validation_fails(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'BAD_TREE_HASH_VALUE'
            with self.assertRaises(TreeHashDoesNotMatchError):
                # With validate_checksum set to True, this call fails.
                self.job.get_output(byte_range=(1, 1024), validate_checksum=True)
            # With validate_checksum set to False, this call succeeds.
            self.job.get_output(byte_range=(1, 1024), validate_checksum=False)
Ejemplo n.º 4
0
    def list_jobs(self, completed=None, status_code=None):
        """
        Return a list of Job objects related to this vault.

        :type completed: boolean
        :param completed: Specifies the state of the jobs to return.
            If a value of True is passed, only completed jobs will
            be returned.  If a value of False is passed, only
            uncompleted jobs will be returned.  If no value is
            passed, all jobs will be returned.

        :type status_code: string
        :param status_code: Specifies the type of job status to return.
            Valid values are: InProgress|Succeeded|Failed.  If not
            specified, jobs with all status codes are returned.

        :rtype: list of :class:`boto.glacier.job.Job`
        :return: A list of Job objects related to this vault.
        """
        response_data = self.layer1.list_jobs(self.name, completed,
                                              status_code)
        return [Job(self, jd) for jd in response_data['JobList']]
Ejemplo n.º 5
0
 def setUp(self):
     self.api = mock.Mock(spec=Layer1)
     self.vault = mock.Mock()
     self.vault.layer1 = self.api
     self.job = Job(self.vault)
Ejemplo n.º 6
0
 def setUp(self):
     self.api = mock.Mock(spec=Layer1)
     self.vault = mock.Mock()
     self.vault.layer1 = self.api
     self.job = Job(self.vault)
Ejemplo n.º 7
0
class TestJob(unittest.TestCase):
    def setUp(self):
        self.api = mock.Mock(spec=Layer1)
        self.vault = mock.Mock()
        self.vault.layer1 = self.api
        self.job = Job(self.vault)

    def test_get_job_validate_checksum_success(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.get_output(byte_range=(1, 1024), validate_checksum=True)

    def test_get_job_validation_fails(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'BAD_TREE_HASH_VALUE'
            with self.assertRaises(TreeHashDoesNotMatchError):
                # With validate_checksum set to True, this call fails.
                self.job.get_output(byte_range=(1, 1024), validate_checksum=True)
            # With validate_checksum set to False, this call succeeds.
            self.job.get_output(byte_range=(1, 1024), validate_checksum=False)

    def test_download_to_fileobj(self):
        http_response=mock.Mock(read=mock.Mock(return_value='xyz'))
        response = GlacierResponse(http_response, None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        fileobj = StringIO()
        self.job.archive_size = 3
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.download_to_fileobj(fileobj)
        fileobj.seek(0)
        self.assertEqual(http_response.read.return_value, fileobj.read())

    def test_calc_num_chunks(self):
        self.job.archive_size = 0
        self.assertEqual(self.job._calc_num_chunks(self.job.DefaultPartSize), 0)
        self.job.archive_size = 1
        self.assertEqual(self.job._calc_num_chunks(self.job.DefaultPartSize), 1)
        self.job.archive_size = self.job.DefaultPartSize + 1
        self.assertEqual(self.job._calc_num_chunks(self.job.DefaultPartSize), 2)
Ejemplo n.º 8
0
class TestJob(unittest.TestCase):
    def setUp(self):
        self.api = mock.Mock(spec=Layer1)
        self.vault = mock.Mock()
        self.vault.layer1 = self.api
        self.job = Job(self.vault)

    def test_get_job_validate_checksum_success(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.get_output(byte_range=(1, 1024), validate_checksum=True)

    def test_get_job_validation_fails(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'BAD_TREE_HASH_VALUE'
            with self.assertRaises(TreeHashDoesNotMatchError):
                # With validate_checksum set to True, this call fails.
                self.job.get_output(byte_range=(1, 1024),
                                    validate_checksum=True)
            # With validate_checksum set to False, this call succeeds.
            self.job.get_output(byte_range=(1, 1024), validate_checksum=False)

    def test_download_to_fileobj(self):
        http_response = mock.Mock(read=mock.Mock(return_value='xyz'))
        response = GlacierResponse(http_response, None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        fileobj = StringIO()
        self.job.archive_size = 3
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.download_to_fileobj(fileobj)
        fileobj.seek(0)
        self.assertEqual(http_response.read.return_value, fileobj.read())

    def test_calc_num_chunks(self):
        self.job.archive_size = 0
        self.assertEqual(self.job._calc_num_chunks(self.job.DefaultPartSize),
                         0)
        self.job.archive_size = 1
        self.assertEqual(self.job._calc_num_chunks(self.job.DefaultPartSize),
                         1)
        self.job.archive_size = self.job.DefaultPartSize + 1
        self.assertEqual(self.job._calc_num_chunks(self.job.DefaultPartSize),
                         2)