Ejemplo n.º 1
0
    def test_generate_download_requests(self, _working_directory_path):
        """
        Assert correct operation of the generate_download_requests() method.
        """
        _working_directory_path.return_value = self.working_dir
        repo = mock.MagicMock()
        conduit = mock.MagicMock()
        config = plugin_config.PluginCallConfiguration(
            {}, {
                'feed': 'https://registry.example.com',
                'upstream_name': 'busybox',
                importer_constants.KEY_MAX_DOWNLOADS: 25
            })
        step = sync.SyncStep(repo, conduit, config)
        step.step_get_local_blobs.units_to_download = [
            models.Blob(digest=i) for i in ['cool', 'stuff']
        ]

        requests = step.generate_download_requests()

        requests = list(requests)
        self.assertEqual(len(requests), 2)
        self.assertEqual(requests[0].url,
                         'https://registry.example.com/v2/busybox/blobs/cool')
        self.assertEqual(requests[0].destination,
                         os.path.join(self.working_dir, 'cool'))
        self.assertEqual(requests[0].data, None)
        self.assertEqual(requests[0].headers, None)
        self.assertEqual(
            requests[1].url,
            'https://registry.example.com/v2/busybox/blobs/stuff')
        self.assertEqual(requests[1].destination,
                         os.path.join(self.working_dir, 'stuff'))
        self.assertEqual(requests[1].data, None)
        self.assertEqual(requests[1].headers, None)
Ejemplo n.º 2
0
    def test__validate_success_case(self):
        """
        Assert that _validate() returns sucessfully when all required config keys are present.
        """
        config = plugin_config.PluginCallConfiguration(
            {}, {
                'feed': 'https://registry.example.com',
                'upstream_name': 'busybox',
                importer_constants.KEY_MAX_DOWNLOADS: 25
            })

        # This should not raise an Exception
        sync.SyncStep._validate(config)
Ejemplo n.º 3
0
    def test__validate_missing_two_keys(self):
        """
        Test the _validate() method when two required config keys are missing.
        """
        config = plugin_config.PluginCallConfiguration(
            {}, {importer_constants.KEY_MAX_DOWNLOADS: 25})

        try:
            sync.SyncStep._validate(config)
            self.fail('An Exception should have been raised, but was not!')
        except exceptions.MissingValue as e:
            self.assertEqual(set(e.property_names),
                             set(['upstream_name', 'feed']))
Ejemplo n.º 4
0
    def test___init___with_v2_registry(self, v1_api_check, api_version_check,
                                       _validate, _working_directory_path):
        """
        Test the __init__() method when the V2Repository does not raise a NotImplementedError with
        the api_version_check() method, indicating that the feed URL is a Docker v2 registry.
        """
        _working_directory_path.return_value = self.working_dir
        repo = mock.MagicMock()
        conduit = mock.MagicMock()
        config = plugin_config.PluginCallConfiguration(
            {}, {
                'feed': 'https://registry.example.com',
                'upstream_name': 'busybox',
                importer_constants.KEY_MAX_DOWNLOADS: 25
            })

        step = sync.SyncStep(repo=repo, conduit=conduit, config=config)

        self.assertEqual(step.description, _('Syncing Docker Repository'))
        # The config should get validated
        _validate.assert_called_once_with(config)
        # available_blobs should have been initialized to an empty list
        self.assertEqual(step.available_blobs, [])
        self.assertEqual(step.available_manifests, [])
        # Ensure that the index_repository was initialized correctly
        self.assertEqual(type(step.index_repository), registry.V2Repository)
        self.assertEqual(step.index_repository.name, 'busybox')
        self.assertEqual(step.index_repository.download_config.max_concurrent,
                         25)
        self.assertEqual(step.index_repository.registry_url,
                         'https://registry.example.com')
        self.assertEqual(step.index_repository.working_dir, self.working_dir)
        # The version check should have happened, and since we mocked it, it will not raise an error
        api_version_check.assert_called_once_with()
        # The correct children should be in place in the right order
        self.assertEqual([type(child) for child in step.children], [
            sync.DownloadManifestsStep, publish_step.GetLocalUnitsStep,
            publish_step.GetLocalUnitsStep, sync.TokenAuthDownloadStep,
            sync.SaveUnitsStep, sync.SaveTagsStep
        ])
        # Ensure the first step was initialized correctly
        self.assertEqual(step.children[0].repo, repo)
        self.assertEqual(step.children[0].conduit, conduit)
        self.assertEqual(step.children[0].config, config)
        # And the second step
        self.assertTrue(step.children[1] is step.step_get_local_manifests)
        self.assertEqual(step.children[1].plugin_type,
                         constants.IMPORTER_TYPE_ID)
        self.assertEqual(step.children[1].available_units,
                         step.available_manifests)
        # And the third step
        self.assertTrue(step.children[2] is step.step_get_local_blobs)
        self.assertEqual(step.children[2].plugin_type,
                         constants.IMPORTER_TYPE_ID)
        self.assertEqual(step.children[2].available_units,
                         step.available_blobs)
        # And the fourth
        self.assertEqual(step.children[3].step_type,
                         constants.SYNC_STEP_DOWNLOAD)
        self.assertEqual(step.children[3].repo, repo)
        self.assertEqual(step.children[3].config, config)
        self.assertEqual(step.children[3].description,
                         _('Downloading remote files'))