Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Refactored gen_yum_config_file function with common defaults
Browse files Browse the repository at this point in the history
and required fields.

All references updated and tests passing:

```bash
$ git grep 'gen_yum_config_file('
pulp_2_tests/tests/rpm/api_v2/test_errata.py:        repo_path = gen_yum_config_file(
pulp_2_tests/tests/rpm/api_v2/test_modularity.py:        repo_path = gen_yum_config_file(
pulp_2_tests/tests/rpm/api_v2/test_rich_weak_dependencies.py:        repo_path = gen_yum_config_file(
pulp_2_tests/tests/rpm/cli/test_copy_units.py:        repo_path = gen_yum_config_file(

$ py.test --pyargs $(git grep 'gen_yum_config_file(')
collected 4 items
pulp_2_tests/tests/rpm/api_v2/test_errata.py::ApplyErratumTestCase::test_all PASSED
pulp_2_tests/tests/rpm/api_v2/test_modularity.py::PackageManagerModuleListTestCase::test_all PASSED
pulp_2_tests/tests/rpm/api_v2/test_rich_weak_dependencies.py::PackageManagerCosumeRPMTestCase::test_all PASSED
pulp_2_tests/tests/rpm/cli/test_copy_units.py::UpdateRpmTestCase::test_all PASSED
```
  • Loading branch information
rochacbruno authored and Kersom committed Sep 5, 2018
1 parent a517f7b commit a6439f9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
7 changes: 1 addition & 6 deletions pulp_2_tests/tests/rpm/api_v2/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def _create_repo_file(self, cfg, repo):
Also, schedule it for deletion. Return nothing.
"""
verify = cfg.get_hosts('api')[0].roles['api'].get('verify')
sudo = () if cli.is_root(cfg) else ('sudo',)
repo_path = gen_yum_config_file(
cfg,
Expand All @@ -84,11 +83,7 @@ def _create_repo_file(self, cfg, repo):
repo['distributors'][0]['config']['relative_url']
)),
name=repo['_href'],
enabled=1,
gpgcheck=0,
metadata_expire=0, # force metadata to load every time
repositoryid=repo['id'],
sslverify='yes' if verify else 'no',
repositoryid=repo['id']
)
self.addCleanup(cli.Client(cfg).run, sudo + ('rm', repo_path))

Expand Down
7 changes: 1 addition & 6 deletions pulp_2_tests/tests/rpm/api_v2/test_modularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def test_all(self):
sync_repo(cfg, repo)
publish_repo(cfg, repo)
repo = client.get(repo['_href'], params={'details': True})
verify = cfg.get_hosts('api')[0].roles['api'].get('verify')
sudo = () if cli.is_root(cfg) else ('sudo',)
repo_path = gen_yum_config_file(
cfg,
Expand All @@ -190,11 +189,7 @@ def test_all(self):
repo['distributors'][0]['config']['relative_url']
)),
name=repo['_href'],
enabled=1,
gpgcheck=0,
metadata_expire=0, # force metadata to load every time
repositoryid=repo['id'],
sslverify='yes' if verify else 'no',
repositoryid=repo['id']
)
cli_client = cli.Client(cfg)
self.addCleanup(cli_client.run, sudo + ('rm', repo_path))
Expand Down
7 changes: 1 addition & 6 deletions pulp_2_tests/tests/rpm/api_v2/test_rich_weak_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def test_all(self):
repo = client.get(repo['_href'], params={'details': True})
sync_repo(cfg, repo)
publish_repo(cfg, repo)
verify = cfg.get_hosts('api')[0].roles['api'].get('verify')
sudo = () if cli.is_root(cfg) else ('sudo',)
repo_path = gen_yum_config_file(
cfg,
Expand All @@ -130,11 +129,7 @@ def test_all(self):
repo['distributors'][0]['config']['relative_url']
)),
name=repo['_href'],
enabled=1,
gpgcheck=0,
metadata_expire=0, # force metadata to load every time
repositoryid=repo['id'],
sslverify='yes' if verify else 'no',
repositoryid=repo['id']
)
cli_client = cli.Client(cfg)
self.addCleanup(cli_client.run, sudo + ('rm', repo_path))
Expand Down
7 changes: 1 addition & 6 deletions pulp_2_tests/tests/rpm/cli/test_copy_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def test_all(self):
client = cli.Client(cfg)
pkg_mgr = cli.PackageManager(cfg)
sudo = () if cli.is_root(cfg) else ('sudo',)
verify = cfg.get_hosts('api')[0].roles['api'].get('verify')

# Create the second repository.
repo_id = self.create_repo(cfg)
Expand All @@ -239,12 +238,8 @@ def test_all(self):
repo_path = gen_yum_config_file(
cfg,
baseurl=urljoin(cfg.get_base_url(), 'pulp/repos/' + repo_id),
enabled=1,
gpgcheck=0,
metadata_expire=0, # force metadata to load every time
name=repo_id,
repositoryid=repo_id,
sslverify='yes' if verify else 'no',
repositoryid=repo_id
)
self.addCleanup(client.run, sudo + ('rm', repo_path))
pkg_mgr.install(rpm_name)
Expand Down
19 changes: 18 additions & 1 deletion pulp_2_tests/tests/rpm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def rpm_rich_weak_dependencies(cfg):
return Version(response.stdout.split()[2]) >= Version(RPM_PKG_RICH_WEAK_VERSION)


def gen_yum_config_file(cfg, repositoryid, **kwargs):
def gen_yum_config_file(cfg, repositoryid, baseurl, name, **kwargs):
"""Generate a yum configuration file and write it to ``/etc/yum.repos.d/``.
Generate a yum configuration file containing a single repository section,
Expand All @@ -189,10 +189,27 @@ def gen_yum_config_file(cfg, repositoryid, **kwargs):
:param repositoryid: The section's ``repositoryid``. Used when naming the
configuration file and populating the brackets at the head of the file.
For details, see yum.conf(5).
:param baseurl: The required option ``baseurl`` specifying the url of repo.
For details, see yum.conf(5)
:param name: The required option ``name`` specifying the name of repo.
For details, see yum.conf(5).
:param kwargs: Section options. Each kwarg corresponds to one option. For
details, see yum.conf(5).
:returns: The path to the yum configuration file.
"""
# required repo options
kwargs.setdefault('name', name)
kwargs.setdefault('baseurl', baseurl)
# assume some common used defaults
kwargs.setdefault('enabled', 1)
kwargs.setdefault('gpgcheck', 0)
kwargs.setdefault('metadata_expire', 0) # force metadata load every time
# if sslverify is not provided in kwargs it is inferred from cfg
kwargs.setdefault(
'sslverify',
'yes' if cfg.get_hosts('api')[0].roles['api'].get('verify') else 'no'
)

path = os.path.join('/etc/yum.repos.d/', repositoryid + '.repo')
with StringIO() as section:
section.write('[{}]\n'.format(repositoryid))
Expand Down

0 comments on commit a6439f9

Please sign in to comment.