Exemplo n.º 1
0
 def test_deleteRepo(self, pulp, publish):
     repo = 'foobar'
     flexmock(Pulp)
     if publish:
         (Pulp.should_receive('emptyRepo').with_args(
             repo).once().and_return(None))
         (Pulp.should_receive('crane').with_args(
             repo, force_refresh=True).twice().and_return(None))
     flexmock(RequestsHttpCaller)
     (RequestsHttpCaller.should_receive('__call__').with_args(
         'delete',
         '/pulp/api/v2/repositories/%s/' % repo).once().and_return(123))
     (Pulp.should_receive('watch').with_args(123).once().and_return(None))
     pulp.deleteRepo(repo, publish)
Exemplo n.º 2
0
def pulp(tmpdir):
    with nested(NamedTemporaryFile(mode='wt'), NamedTemporaryFile(mode='wt'),
                NamedTemporaryFile(mode='wt')) as (fp, df, dn):
        name = 'test'
        fp.write(dedent("""
            [pulps]
            {name} = foo
            [registries]
            {name} = foo
            [filers]
            {name} = foo
            [redirect]
            {name} = no
            [distributors]
            {name} = foo,docker_rsync
            [release_order]
            {name} = foo,docker_rsync
            [retries]
            {name} = 2
            [signatures]
            foobar = foo
            [sig_exception]
            {name} = barfoo78
            """).format(name=name))
        fp.flush()

        df.write(dedent("""
            {
                "foo":{
                    "distributor_type_id": "docker_distributor_web",
                    "distributor_config": {}
                },
                "docker_rsync":{
                    "distributor_type_id": "docker_rsync_distributor",
                    "distributor_config": {}
                }
            }
            """))
        df.flush()

        dn.write(dedent("""
            {
                "beta":{
                    "signature": "foobar",
                    "name_enforce": "",
                    "content_enforce": "",
                    "name_restrict": ["-test"]
                },
                "test":{
                    "signature": "foobar",
                    "name_enforce": "-test",
                    "content_enforce": "/content/test",
                    "name_restrict": []
                }
            }
            """))
        dn.flush()
        pulp = Pulp(env=name, config_file=fp.name, config_distributors=df.name,
                    config_distributions=dn.name)
    return pulp
Exemplo n.º 3
0
def pulp(tmpdir):
    with nested(NamedTemporaryFile(mode='wt'),
                NamedTemporaryFile(mode='wt')) as (fp, df):
        name = 'test'
        fp.write(
            dedent("""
            [pulps]
            {name} = foo
            [registries]
            {name} = foo
            [filers]
            {name} = foo
            [redirect]
            {name} = no
            [distributors]
            {name} = foo
            [release_order]
            {name} = foo
            [retries]
            {name} = 2
            """).format(name=name))
        fp.flush()

        df.write(dedent("""
            {}
            """))
        df.flush()
        pulp = Pulp(env=name, config_file=fp.name, config_distributors=df.name)
    return pulp
Exemplo n.º 4
0
def core_pulp(tmpdir):
    # No optional fields in dockpulp.conf
    with nested(NamedTemporaryFile(mode='wt'), NamedTemporaryFile(mode='wt'),
                NamedTemporaryFile(mode='wt')) as (fp, df, dn):
        name = 'test'
        fp.write(
            dedent("""
            [pulps]
            {name} = foo
            [registries]
            {name} = foo
            [filers]
            {name} = foo
            [redirect]
            {name} = no
            [distributors]
            {name} = foo
            [release_order]
            {name} = foo
            """).format(name=name))
        fp.flush()

        df.write(
            dedent("""
            {
                "foo":{
                    "distributor_type_id": "docker_distributor_web",
                    "distributor_config": {}
                }
            }
            """))
        df.flush()

        dn.write(
            dedent("""
            {
                "foo":{
                    "signature": "",
                    "name_enforce": "",
                    "content_enforce": "",
                    "name_restrict": []
                }
            }
            """))
        dn.flush()
        core_pulp = Pulp(env=name,
                         config_file=fp.name,
                         config_distributors=df.name,
                         config_distributions=dn.name)
    return core_pulp
Exemplo n.º 5
0
 def test_remove_filters(self, pulp):
     repo = 'foobar'
     type_ids = [
         'docker_image', 'docker_manifest', 'docker_blob', 'docker_tag',
         'docker_manifest_list'
     ]
     data = {
         'criteria': {
             'type_ids': type_ids,
             'filters': {},
         },
         'override_config': {},
         'limit': 1
     }
     flexmock(RequestsHttpCaller)
     (RequestsHttpCaller.should_receive('__call__').with_args(
         'post',
         '/pulp/api/v2/repositories/%s/actions/unassociate/' % repo,
         data=json.dumps(data)).once().and_return(123))
     flexmock(Pulp)
     (Pulp.should_receive('watch').with_args(123).once().and_return(None))
     pulp.remove_filters(repo)
Exemplo n.º 6
0
def pulp(tmpdir):
    with nested(NamedTemporaryFile(mode='wt'),
                NamedTemporaryFile(mode='wt')) as (fp, df):
        name = 'test'
        fp.write(
            dedent("""
            [pulps]
            {name} = foo
            [registries]
            {name} = foo
            [filers]
            {name} = foo
            [redirect]
            {name} = no
            [distributors]
            {name} = foo
            [release_order]
            {name} = foo
            [retries]
            {name} = 2
            [signatures]
            foobar = foo
            [distribution]
            distributions = beta,ga
            """).format(name=name))
        fp.flush()

        df.write(
            dedent("""
            {
                "foo":{
                    "distributor_type_id": "docker_distributor_web",
                    "distributor_config": {}
                }
            }
            """))
        df.flush()
        pulp = Pulp(env=name, config_file=fp.name, config_distributors=df.name)
    return pulp
Exemplo n.º 7
0
 def test_emptyRepo(self, pulp):
     repo = 'foobar'
     flexmock(Pulp)
     (Pulp.should_receive('remove_filters').with_args(
         repo).once().and_return(None))
     pulp.emptyRepo(repo)
Exemplo n.º 8
0
 def test_createRepo(self, pulp, repo_id, url, registry_id, distributors,
                     productline, library, distribution, repotype,
                     importer_type_id, rel_url, download):
     if distribution == 'test':
         if (url != '/content/test/foo-test/bar' and url is not None) or \
            ((productline is not None or library) and productline != 'foo-test'):
             with pytest.raises(errors.DockPulpError):
                 pulp.createRepo(repo_id=repo_id,
                                 url=url,
                                 registry_id=registry_id,
                                 distributors=distributors,
                                 productline=productline,
                                 library=library,
                                 distribution=distribution,
                                 repotype=repotype,
                                 importer_type_id=importer_type_id,
                                 rel_url=rel_url,
                                 download=download)
             return
     if distribution == 'beta' and productline and productline.endswith(
             'test'):
         with pytest.raises(errors.DockPulpError):
             pulp.createRepo(repo_id=repo_id,
                             url=url,
                             registry_id=registry_id,
                             distributors=distributors,
                             productline=productline,
                             library=library,
                             distribution=distribution,
                             repotype=repotype,
                             importer_type_id=importer_type_id,
                             rel_url=rel_url,
                             download=download)
         return
     if not registry_id and (repo_id == 'tags' or productline == 'blobs'):
         with pytest.raises(errors.DockPulpError):
             pulp.createRepo(repo_id=repo_id,
                             url=url,
                             registry_id=registry_id,
                             distributors=distributors,
                             productline=productline,
                             library=library,
                             distribution=distribution,
                             repotype=repotype,
                             importer_type_id=importer_type_id,
                             rel_url=rel_url,
                             download=download)
         return
     flexmock(Pulp)
     (Pulp.should_receive('createOriginRepo').once().and_return(None))
     flexmock(RequestsHttpCaller)
     (RequestsHttpCaller.should_receive('__call__').once().and_return(None))
     response = pulp.createRepo(repo_id=repo_id,
                                url=url,
                                registry_id=registry_id,
                                distributors=distributors,
                                productline=productline,
                                library=library,
                                distribution=distribution,
                                repotype=repotype,
                                importer_type_id=importer_type_id,
                                rel_url=rel_url,
                                download=download)
     if not repo_id.startswith(pulp.getPrefix()):
         repo_id = pulp.getPrefix() + repo_id
     if registry_id is None:
         if productline:
             pindex = repo_id.find(productline)
             registry_id = productline + '/' + repo_id[pindex +
                                                       len(productline) +
                                                       1:]
         elif library:
             registry_id = repo_id.replace(pulp.getPrefix(), '')
         else:
             registry_id = repo_id.replace(pulp.getPrefix(),
                                           '').replace('-', '/', 1)
     rurl = url
     if rurl and not rurl.startswith('http'):
         rurl = pulp.cdnhost + url
     assert response['id'] == repo_id
     assert response['display_name'] == repo_id
     if distribution:
         assert response['notes']['distribution'] == distribution
         sig = pulp.getDistributionSig(distribution)
         assert response['notes']['signatures'] == pulp.getSignature(sig)
     if distributors:
         for distributor in response['distributors']:
             if distributor[
                     'distributor_type_id'] == 'docker_distributor_web':
                 assert distributor['distributor_config'][
                     'repo-registry-id'] == registry_id
                 assert distributor['distributor_config'][
                     'redirect-url'] == rurl
     if repotype:
         assert response['notes']['_repo-type'] == repotype
     if importer_type_id:
         assert response['importer_type_id'] == importer_type_id
     if rel_url:
         assert response['notes']['relative_url'] == rel_url
         if distributors:
             for distributor in response['distributors']:
                 if distributor[
                         'distributor_type_id'] == 'docker_rsync_distributor':
                     assert distributor['distributor_config'][
                         'repo_relative_path'] == rel_url
     if download is not None:
         if download:
             assert response['notes'][
                 'include_in_download_service'] == "True"
         else:
             assert response['notes'][
                 'include_in_download_service'] == "False"
Exemplo n.º 9
0
    def test_switched_pulp(self):
        # Test for dockpulp switchover
        with nested(NamedTemporaryFile(mode='wt'),
                    NamedTemporaryFile(mode='wt'),
                    NamedTemporaryFile(mode='wt')) as (fp, df, dn):
            name = 'test'
            fp.write(
                dedent("""
                [pulps]
                {name} = foo
                [registries]
                {name} = foo
                [filers]
                {name} = foo
                [redirect]
                {name} = no
                [distributors]
                {name} = foo
                [release_order]
                {name} = foo
                [switch_ver]
                version = 10.0
                [switch_release]
                {name} = bar
            """).format(name=name))
            fp.flush()

            df.write(
                dedent("""
            {
                "foo":{
                    "distributor_type_id": "docker_distributor_web",
                    "distributor_config": {}
                },
                "switch":{
                    "distributor_type_id": "docker_distributor_web",
                    "distributor_config": {}
                }
            }
            """))
            df.flush()

            dn.write(
                dedent("""
            {
                "foo":{
                    "signature": "",
                    "name_enforce": "",
                    "content_enforce": "",
                    "name_restrict": []
                }
            }
            """))
            dn.flush()
            url = '/pulp/api/v2/status'
            response = {'versions': {'platform_version': '10.0'}}
            flexmock(RequestsHttpCaller)
            (RequestsHttpCaller.should_receive('__call__').with_args(
                'get', url).and_return(response))
            switched_pulp = Pulp(env=name,
                                 config_file=fp.name,
                                 config_distributors=df.name,
                                 config_distributions=dn.name)
            assert switched_pulp.release_order == switched_pulp.switch_release
            response = {'versions': {'platform_version': '1.0'}}

            (RequestsHttpCaller.should_receive('__call__').with_args(
                'get', url).and_return(response))
            switched_pulp = Pulp(env=name,
                                 config_file=fp.name,
                                 config_distributors=df.name,
                                 config_distributions=dn.name)
            assert switched_pulp.release_order != switched_pulp.switch_release