Multiple arches can be passed to yumrepoinfo directive, output has new format:
{'koji_tag': {'arch': 'URL'}}
Multiple arches can be passed to yumrepoinfo directive, output has new format:
{'koji_tag': {'arch': 'URL'}}
python runtask.py -t koji_tag -a i386 -a x86_64 -i f20-updates-pending yumrepoinfo.yml --debug
where yumrepoinfo.yml contains:
--- name: repoinfo desc: "blah blah" maintainer: nobody input: args: - koji_tag - arch environment: rpm: - libtaskotron actions: - name: get yum repos yumrepoinfo: koji_tag: ${koji_tag} arch: ${arch} export: yumrepos
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Can you please add a unit test that would test multiple arches being fed to this directive? Thanks.
libtaskotron/directives/yumrepoinfo_directive.py | ||
---|---|---|
26–28 | This is no longer true, is it? | |
30–43 | This starts to be complicated, I think including a simple example would help a lot. | |
91–92 | Please use concrete parameters here, instead of input_data and env_data. Add a docstring describing the purpose of this method. |
Looks good to me, please provide also patches (in separate reviews) for tasks using the directive (set as dependencies for this one) before pushing to develop.
Can you please add a unit test that would test multiple arches being fed to this directive? Thanks.
I cannot find this. The usual use case should be tested (multiple real arches passed in) as well the edge cases (one real arch with one "meta" arch, two real arches with one "meta" arch, several "meta" arches and no real arch, and maybe something else).
libtaskotron/directives/yumrepoinfo_directive.py | ||
---|---|---|
38–39 | This is a bit hard to read on a single line (and some of the quotes are doubled). What about: Example:: {'f20': {'x86_64': 'http://...', 'i386': ''http://...'}, 'f20-updates': {'x86_64': 'http://...', 'i386': 'http://...'}} This will keep formatting in the generated docs. | |
44–45 | This is no longer true. |
The patch looks OK in general, the unit tests look reasonable. If you can use tmpdir and adjust the few nitpicks, that would be great.
libtaskotron/directives/yumrepoinfo_directive.py | ||
---|---|---|
41 | One of the quotes is still doubled :-) | |
46 | For clarity, and should be replaced with or | |
90 | Is there a reason to not make this a docstring? | |
testing/test_yumrepoinfo_directive.py | ||
1 | Can you have a look at tmpdir [1] fixture from pytest, as used in other test modules? I think it should be able to give you what you need and it has many advantages, like rotating temp files and using a centralized temp directory. |
Path | Packages | |||
---|---|---|---|---|
M | libtaskotron/directives/yumrepoinfo_directive.py (80 lines) | |||
M | libtaskotron/yumrepoinfo.py (9 lines) | |||
A | M | testing/functest_yumrepoinfo_directive.py (178 lines) | ||
D | M | testing/test_yumrepoinfo_directive.py (127 lines) |
Commit | Tree | Parents | Author | Summary | Date |
---|---|---|---|---|---|
20ae1bfdd25d | 014f534651f7 | c19ad3b5ae1f | Lukas Brabec | code polishing | Mar 4 2015, 2:19 PM |
c19ad3b5ae1f | e691a2c07c63 | d6d51afc338a | Lukas Brabec | doc polishing, test addition | Mar 4 2015, 11:03 AM |
d6d51afc338a | 62cffd1dc4d2 | 9869d5b9589d | Lukas Brabec | pep polishing | Feb 27 2015, 10:23 AM |
9869d5b9589d | 774cfb69fe46 | d0b04fe3e19d | Lukas Brabec | code polishing, documentation | Feb 27 2015, 10:02 AM |
d0b04fe3e19d | 66144012f3d4 | 6ced71caddd9 | Lukas Brabec | yumrepoinfo directive now handles multiple arch (Show More…) | Aug 28 2014, 9:10 AM |
Show All 17 Lines | 17 | description: | | |||
---|---|---|---|---|---|
18 | name of the Koji tag, e.g. ``f20``, ``f20-updates``, | 18 | name of the Koji tag, e.g. ``f20``, ``f20-updates``, | ||
19 | ``f20-updates-testing``, or ``rawhide``. | 19 | ``f20-updates-testing``, or ``rawhide``. | ||
20 | 20 | | |||
21 | If the tag ends with ``-pending`` suffix, this suffix is stripped (because | 21 | If the tag ends with ``-pending`` suffix, this suffix is stripped (because | ||
22 | pending tags are not real repositories), and the resulting tag is used. | 22 | pending tags are not real repositories), and the resulting tag is used. | ||
23 | type: str | 23 | type: str | ||
24 | arch: | 24 | arch: | ||
25 | required: true | 25 | required: true | ||
26 | description: list of architectures. In this list, all "meta architectures" | 26 | description: list of architectures. In this list, all "meta architectures" | ||
27 | like ``all``, ``src`` and ``noarch`` are ignored, and only a single "real | 27 | like ``all``, ``src`` and ``noarch`` are ignored, list of "real | ||
28 | architecture" is expected there (e.g. ``x86_64`` or ``i386``). | 28 | architectures" is expected there (e.g. ``x86_64`` or ``i386``). | ||
29 | type: list of str | 29 | type: list of str | ||
30 | returns: | | 30 | returns: | | ||
31 | A dictionary. One of the keys is ``koji_tag`` and URL for the respective | 31 | A dictionary of dictionaries. Main key is ``koji_tag`` with value of | ||
32 | dictionary that contains ``arch`` as key and URL for the respective | ||||
32 | repository is its value. | 33 | repository is its value. | ||
33 | 34 | | |||
34 | If the repository in question has some parent repositories (e.g. | 35 | If the repository in question has some parent repositories (e.g. | ||
35 | ``f20-updates`` is a child of ``f20``), all its parents names and their | 36 | ``f20-updates`` is a child of ``f20``), all its parents names and their | ||
36 | repository URLs are returned in the dictionary as well as additional keys. | 37 | repository URLs are returned in the dictionary as well as additional keys. | ||
38 | Example:: | ||||
39 | | ||||
40 | {'f20': {'x86_64': 'http://...', | ||||
41 | 'i386': 'http://...'}, | ||||
42 | 'f20-updates': {'x86_64': 'http://...', | ||||
43 | 'i386': 'http://...'}} | ||||
37 | raises: | | 44 | raises: | | ||
38 | * :class:`.TaskotronDirectiveError`: if there are zero or more than one "real | 45 | * :class:`.TaskotronDirectiveError`: if there are zero "real architectures" | ||
39 | architectures" inside ``arch`` (e.g. both ``x86_64`` and ``i386``). Also | 46 | inside ``arch`` or when ``koji_tag`` is not found among known repositories. | ||
40 | when ``koji_tag`` is not found among known repositories. | | |||
41 | version_added: 0.4 | 47 | version_added: 0.4 | ||
42 | """ | 48 | """ | ||
43 | 49 | | |||
44 | EXAMPLES = """ | 50 | EXAMPLES = """ | ||
45 | For a koji tag received from the command line, get a list of its YUM | 51 | For a koji tag received from the command line, get a list of its YUM | ||
46 | repositories and save it to a variable:: | 52 | repositories and save it to a variable:: | ||
47 | 53 | | |||
48 | - name: get yum repos | 54 | - name: get yum repos | ||
Show All 19 Lines | |||||
68 | from libtaskotron.exceptions import TaskotronDirectiveError | 74 | from libtaskotron.exceptions import TaskotronDirectiveError | ||
69 | from libtaskotron.logger import log | 75 | from libtaskotron.logger import log | ||
70 | from libtaskotron.arch_utils import Arches | 76 | from libtaskotron.arch_utils import Arches | ||
71 | 77 | | |||
72 | directive_class = 'YumrepoinfoDirective' | 78 | directive_class = 'YumrepoinfoDirective' | ||
73 | 79 | | |||
74 | class YumrepoinfoDirective(BaseDirective): | 80 | class YumrepoinfoDirective(BaseDirective): | ||
75 | 81 | | |||
76 | def __init__(self, repoinfo = None): | 82 | def __init__(self, repoinfo=None, filelist=None): | ||
83 | """ | ||||
84 | :param repoinfo: if provided, get_yumrepoinfo() call is omitted and | ||||
85 | this info is used instead (for testing mainly) | ||||
86 | :param filelist: list of config files, default config file is used | ||||
87 | if None (for testing mainly) | ||||
88 | """ | ||||
77 | self.repoinfo = repoinfo | 89 | self.repoinfo = repoinfo | ||
90 | self.filelist = filelist | ||||
78 | 91 | | |||
79 | def process(self, input_data, env_data): | 92 | def run_yumrepoinfo(self, arch, koji_tag): | ||
80 | 93 | """Get yum repoinfo for given arch and koji tag""" | |||
81 | if 'koji_tag' not in input_data or 'arch' not in input_data: | | |||
82 | raise TaskotronDirectiveError("The yumrepoinfo directive requires " | | |||
83 | "koji_tag and arch arguments.") | | |||
84 | | ||||
85 | | ||||
86 | arches = input_data['arch'] | | |||
87 | | ||||
88 | processed_arches = [arch for arch in arches if arch in Arches.base] | | |||
89 | if len(processed_arches) == 0: | | |||
90 | raise TaskotronDirectiveError("No valid yumrepo arches supplied to " | | |||
91 | "yumrepoinfo directive. Recieved %r" % arches) | | |||
92 | | ||||
93 | if len(processed_arches) > 1: | | |||
94 | raise TaskotronDirectiveError("Yumrepoinfo requires a single base " | | |||
95 | "arch but multiple arches were submitted: %r" % arches) | | |||
96 | | ||||
97 | arch = processed_arches[0] | | |||
98 | | ||||
99 | koji_tag = input_data['koji_tag'] | | |||
100 | 94 | | |||
101 | output = {} | 95 | output = {} | ||
102 | 96 | | |||
103 | if self.repoinfo is None: | 97 | if self.repoinfo is None: | ||
104 | self.repoinfo = yumrepoinfo.get_yumrepoinfo(arch) | 98 | self.repoinfo = yumrepoinfo.get_yumrepoinfo(arch, self.filelist) | ||
105 | 99 | | |||
106 | if koji_tag.endswith('-pending'): | 100 | if koji_tag.endswith('-pending'): | ||
107 | koji_tag = koji_tag[:-len('-pending')] | 101 | koji_tag = koji_tag[:-len('-pending')] | ||
108 | 102 | | |||
109 | if koji_tag == 'rawhide': | 103 | if koji_tag == 'rawhide': | ||
110 | koji_tag = self.repoinfo.repo('rawhide')['tag'] | 104 | koji_tag = self.repoinfo.repo('rawhide')['tag'] | ||
111 | 105 | | |||
112 | while koji_tag: | 106 | while koji_tag: | ||
113 | repo = self.repoinfo.repo_by_tag(koji_tag) | 107 | repo = self.repoinfo.repo_by_tag(koji_tag) | ||
114 | if repo is None: | 108 | if repo is None: | ||
115 | raise TaskotronDirectiveError('Repo with tag'\ | 109 | raise TaskotronDirectiveError('Repo with tag'\ | ||
116 | '%r not found.' % koji_tag) | 110 | '%r not found.' % koji_tag) | ||
117 | 111 | | |||
118 | output[repo['name']] = repo['url'] | 112 | output[repo['name']] = repo['url'] | ||
119 | koji_tag = repo['parent'] | 113 | koji_tag = repo['parent'] | ||
120 | 114 | | |||
121 | log.debug("Found %s repos for %s: %r" % (len(output), | 115 | log.debug("Found %s repos for %s: %r" % (len(output), | ||
122 | input_data['koji_tag'], output)) | 116 | koji_tag, output)) | ||
123 | return output | 117 | return output | ||
124 | 118 | | |||
119 | def process(self, input_data, env_data): | ||||
120 | | ||||
121 | if 'koji_tag' not in input_data or 'arch' not in input_data: | ||||
122 | raise TaskotronDirectiveError("The yumrepoinfo directive requires " | ||||
123 | "koji_tag and arch arguments.") | ||||
124 | | ||||
125 | arches = input_data['arch'] | ||||
126 | | ||||
127 | processed_arches = [arch for arch in arches if arch in Arches.base] | ||||
128 | | ||||
129 | if len(processed_arches) == 0: | ||||
130 | raise TaskotronDirectiveError("No valid yumrepo arches supplied to " | ||||
131 | "yumrepoinfo directive. Recieved %r" | ||||
132 | % arches) | ||||
133 | | ||||
134 | # create output in format: | ||||
135 | # {'koji_tag' : {'arch' : 'URL'}} | ||||
136 | output = {} | ||||
137 | for arch in processed_arches: | ||||
138 | arch_output = self.run_yumrepoinfo(arch, input_data["koji_tag"]) | ||||
139 | self.repoinfo = None | ||||
140 | for tag in arch_output: | ||||
141 | output[tag] = output.get(tag, {}) | ||||
142 | output[tag][arch] = arch_output[tag] | ||||
143 | | ||||
144 | return output | ||||
145 | No newline at end of file |
1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- | ||
---|---|---|---|---|---|
2 | # Copyright 2009-2014, Red Hat, Inc. | 2 | # Copyright 2009-2014, Red Hat, Inc. | ||
3 | # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+> | 3 | # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+> | ||
4 | # See the LICENSE file for more details on Licensing | 4 | # See the LICENSE file for more details on Licensing | ||
5 | 5 | | |||
6 | '''A wrapper object for yumrepoinfo.conf to access its information easily''' | 6 | '''A wrapper object for yumrepoinfo.conf to access its information easily''' | ||
7 | 7 | | |||
8 | from __future__ import absolute_import | 8 | from __future__ import absolute_import | ||
9 | import ConfigParser | 9 | import ConfigParser | ||
10 | import os | 10 | import os | ||
11 | 11 | | |||
12 | from . import config | 12 | from . import config | ||
13 | from .logger import log | 13 | from .logger import log | ||
14 | from . import rpm_utils | | |||
15 | from . import arch_utils | 14 | from . import arch_utils | ||
16 | from . import exceptions as exc | 15 | from . import exceptions as exc | ||
17 | 16 | | |||
18 | 17 | | |||
19 | # a singleton instance of YumRepoInfo (a dict with arches as keys) | 18 | # a singleton instance of YumRepoInfo (a dict with arches as keys) | ||
20 | _yumrepoinfo = {} | 19 | _yumrepoinfo = {} | ||
21 | 20 | | |||
22 | 21 | | |||
23 | def get_yumrepoinfo(arch=None): | 22 | def get_yumrepoinfo(arch=None, filelist=None): | ||
24 | '''Get YumRepoInfo instance. This method is implemented using the singleton | 23 | '''Get YumRepoInfo instance. This method is implemented using the singleton | ||
25 | pattern - you will always receive the same instance, which will get | 24 | pattern - you will always receive the same instance, which will get | ||
26 | auto-initialized on the first method call. | 25 | auto-initialized on the first method call. | ||
27 | 26 | | |||
28 | :param str arch: architecture to return the YumRepoInfo for. It's always | 27 | :param str arch: architecture to return the YumRepoInfo for. It's always | ||
29 | converted to basearch. If ``None``, then local machine arch | 28 | converted to basearch. If ``None``, then local machine arch | ||
30 | is used. | 29 | is used. | ||
30 | :param filelist: list of config files to read information from. The | ||||
31 | first available config file is used. If ``None``, then | ||||
32 | the default list of locations is used. | ||||
31 | :return: shared :class:`YumRepoInfo` instance | 33 | :return: shared :class:`YumRepoInfo` instance | ||
32 | :raise TaskotronConfigError: if file config parsing and handling failed | 34 | :raise TaskotronConfigError: if file config parsing and handling failed | ||
33 | ''' | 35 | ''' | ||
34 | # converts to basearch, returns local arch for None | 36 | # converts to basearch, returns local arch for None | ||
35 | arch = arch_utils.basearch(arch) | 37 | arch = arch_utils.basearch(arch) | ||
36 | 38 | | |||
37 | if not arch in _yumrepoinfo: | 39 | if not arch in _yumrepoinfo: | ||
38 | _yumrepoinfo[arch] = YumRepoInfo(arch) | 40 | _yumrepoinfo[arch] = YumRepoInfo(arch, filelist) | ||
39 | return _yumrepoinfo[arch] | 41 | return _yumrepoinfo[arch] | ||
40 | 42 | | |||
41 | 43 | | |||
42 | class YumRepoInfo(object): | 44 | class YumRepoInfo(object): | ||
43 | '''This class is a wrapper for easily accessing repoinfo.conf file.''' | 45 | '''This class is a wrapper for easily accessing repoinfo.conf file.''' | ||
44 | 46 | | |||
45 | def __init__(self, arch=None, filelist=None): | 47 | def __init__(self, arch=None, filelist=None): | ||
46 | ''' | 48 | ''' | ||
Show All 10 Lines | 56 | :raise TaskotronConfigError: if no YUM repositories data is found (empty | |||
57 | to load (``filelist=[]``). | 59 | to load (``filelist=[]``). | ||
58 | ''' | 60 | ''' | ||
59 | if (config.get_config().profile == config.ProfileName.TESTING and | 61 | if (config.get_config().profile == config.ProfileName.TESTING and | ||
60 | filelist is None): | 62 | filelist is None): | ||
61 | # Under the testing profile we don't want to try to load any config | 63 | # Under the testing profile we don't want to try to load any config | ||
62 | # files, they might not be available at all (T163). The unit test | 64 | # files, they might not be available at all (T163). The unit test | ||
63 | # can provide its own with `filelist` - in that case, load it. | 65 | # can provide its own with `filelist` - in that case, load it. | ||
64 | return | 66 | return | ||
65 | | ||||
66 | self.arch = arch_utils.basearch(arch) | 67 | self.arch = arch_utils.basearch(arch) | ||
67 | self.filelist = (filelist if filelist is not None else | 68 | self.filelist = (filelist if filelist is not None else | ||
68 | [os.path.join(confdir, 'yumrepoinfo.conf') | 69 | [os.path.join(confdir, 'yumrepoinfo.conf') | ||
69 | for confdir in config.CONF_DIRS]) | 70 | for confdir in config.CONF_DIRS]) | ||
70 | self.parser = ConfigParser.SafeConfigParser(defaults= | 71 | self.parser = ConfigParser.SafeConfigParser(defaults= | ||
71 | {'arch': self.arch}) | 72 | {'arch': self.arch}) | ||
72 | 73 | | |||
73 | if not self.filelist: | 74 | if not self.filelist: | ||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |
1 | # -*- coding: utf-8 -*- | ||||
---|---|---|---|---|---|
2 | # Copyright 2009-2014, Red Hat, Inc. | ||||
3 | # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+> | ||||
4 | # See the LICENSE file for more details on Licensing | ||||
5 | | ||||
6 | import pytest | ||||
7 | import StringIO | ||||
8 | from dingus import Dingus | ||||
9 | | ||||
10 | from libtaskotron.directives import yumrepoinfo_directive | ||||
11 | from libtaskotron.exceptions import TaskotronDirectiveError | ||||
12 | | ||||
13 | from libtaskotron import yumrepoinfo | ||||
14 | | ||||
15 | | ||||
16 | TEST_CONF = '''\ | ||||
17 | [DEFAULT] | ||||
18 | baseurl = http://download.fedoraproject.org/pub/fedora/linux | ||||
19 | goldurl = %(baseurl)s/releases/%(path)s/Everything/%(arch)s/os | ||||
20 | updatesurl = %(baseurl)s/updates/%(path)s/%(arch)s | ||||
21 | rawhideurl = %(baseurl)s/%(path)s/%(arch)s/os | ||||
22 | arches = i386, x86_64 | ||||
23 | parent = | ||||
24 | tag = %(__name__)s | ||||
25 | supported = no | ||||
26 | | ||||
27 | [rawhide] | ||||
28 | path = development/rawhide | ||||
29 | url = %(rawhideurl)s | ||||
30 | tag = f21 | ||||
31 | | ||||
32 | [f20] | ||||
33 | url = %(goldurl)s | ||||
34 | path = 20 | ||||
35 | supported = yes | ||||
36 | | ||||
37 | [f20-updates] | ||||
38 | url = %(updatesurl)s | ||||
39 | path = 20 | ||||
40 | parent = f20 | ||||
41 | arches = x86_64 | ||||
42 | | ||||
43 | [f20-updates-testing] | ||||
44 | url = %(updatesurl)s | ||||
45 | path = testing/20 | ||||
46 | parent = f20-updates | ||||
47 | ''' | ||||
48 | | ||||
49 | | ||||
50 | class TestYumrepoinfoDirective(object): | ||||
51 | | ||||
52 | @classmethod | ||||
53 | @pytest.fixture(autouse=True) | ||||
54 | def setup_class(cls, tmpdir): | ||||
55 | '''One-time class initialization''' | ||||
56 | # create YumRepoInfo initialized with TEST_CONF | ||||
57 | cls.temp_conf = tmpdir.join("functest_yumrepoinfo.conf") | ||||
58 | cls.temp_conf.write(TEST_CONF) | ||||
59 | | ||||
60 | def test_missing_kojitag(self): | ||||
61 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
62 | ref_input = {"arch": ["x86_64"]} | ||||
63 | | ||||
64 | with pytest.raises(TaskotronDirectiveError): | ||||
65 | directive.process(ref_input, None) | ||||
66 | | ||||
67 | def test_missing_arch(self): | ||||
68 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
69 | ref_input = {"koji_tag": "rawhide"} | ||||
70 | | ||||
71 | with pytest.raises(TaskotronDirectiveError): | ||||
72 | directive.process(ref_input, None) | ||||
73 | | ||||
74 | def test_pending(self): | ||||
75 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
76 | ref_input = {"koji_tag": "f20-pending", "arch": ["x86_64"]} | ||||
77 | | ||||
78 | output = directive.process(ref_input, None) | ||||
79 | | ||||
80 | assert output == {"f20": {"x86_64": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os"}} | ||||
81 | | ||||
82 | def test_rawhide(self): | ||||
83 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
84 | ref_input = {"koji_tag": "rawhide", "arch": ["x86_64"]} | ||||
85 | | ||||
86 | output = directive.process(ref_input, None) | ||||
87 | | ||||
88 | assert output == {"rawhide": {"x86_64": "http://download.fedoraproject.org/pub/fedora/linux/development/rawhide/x86_64/os"}} | ||||
89 | | ||||
90 | def test_bad_kojitag(self): | ||||
91 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
92 | ref_input = {"koji_tag": "my random tag"} | ||||
93 | | ||||
94 | with pytest.raises(TaskotronDirectiveError): | ||||
95 | directive.process(ref_input, None) | ||||
96 | | ||||
97 | def test_repo_path(self): | ||||
98 | | ||||
99 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
100 | ref_input = {"koji_tag": "f20-updates", "arch": ["x86_64"]} | ||||
101 | | ||||
102 | output = directive.process(ref_input, None) | ||||
103 | | ||||
104 | assert output == { | ||||
105 | "f20": {"x86_64": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os"}, | ||||
106 | "f20-updates": {"x86_64": "http://download.fedoraproject.org/pub/fedora/linux/updates/20/x86_64"}, | ||||
107 | } | ||||
108 | | ||||
109 | def test_use_arch(self, monkeypatch): | ||||
110 | """Make sure that the arch passed in as an arg is used to create the | ||||
111 | yumrepoinfo object instead of falling back to the default system arch""" | ||||
112 | ref_arch = 'i386' | ||||
113 | repoinfo = yumrepoinfo.YumRepoInfo(filelist=[], arch=['x86_64']) | ||||
114 | repoinfo.parser.readfp(StringIO.StringIO(TEST_CONF)) | ||||
115 | | ||||
116 | stub_getrepoinfo = Dingus(return_value=repoinfo) | ||||
117 | monkeypatch.setattr(yumrepoinfo, 'get_yumrepoinfo', stub_getrepoinfo) | ||||
118 | | ||||
119 | # don't set the repoinfo object, we've stubbed out the code that would | ||||
120 | # hit the filesystem, so it's not a risk here | ||||
121 | directive = yumrepoinfo_directive.YumrepoinfoDirective() | ||||
122 | ref_input = {"koji_tag": "f20-updates", "arch": [ref_arch]} | ||||
123 | | ||||
124 | directive.process(ref_input, None) | ||||
125 | | ||||
126 | # check the first arg of the first call to the stub object | ||||
127 | assert stub_getrepoinfo.calls()[0][1][0] == ref_arch | ||||
128 | | ||||
129 | def test_only_meta_arches(self): | ||||
130 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
131 | ref_input = {"koji_tag": "f20", "arch": ["src", "noarch"]} | ||||
132 | | ||||
133 | with pytest.raises(TaskotronDirectiveError): | ||||
134 | directive.process(ref_input, None) | ||||
135 | | ||||
136 | def test_one_base_arch(self): | ||||
137 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
138 | ref_input = {"koji_tag": "f20", "arch": ["x86_64"]} | ||||
139 | | ||||
140 | output = directive.process(ref_input, None) | ||||
141 | | ||||
142 | assert output == { | ||||
143 | "f20": {"x86_64": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os"} | ||||
144 | } | ||||
145 | | ||||
146 | def test_base_meta_arch(self): | ||||
147 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
148 | ref_input = {"koji_tag": "f20", "arch": ["src", "noarch", "x86_64"]} | ||||
149 | | ||||
150 | output = directive.process(ref_input, None) | ||||
151 | | ||||
152 | assert output == { | ||||
153 | "f20": {"x86_64": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os"} | ||||
154 | } | ||||
155 | | ||||
156 | def test_multiple_base_arches(self): | ||||
157 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
158 | ref_input = {"koji_tag": "f20", "arch": ["i386", "x86_64"]} | ||||
159 | | ||||
160 | output = directive.process(ref_input, None) | ||||
161 | | ||||
162 | assert output == { | ||||
163 | "f20": { | ||||
164 | "i386": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/i386/os", | ||||
165 | "x86_64": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os"} | ||||
166 | } | ||||
167 | | ||||
168 | def test_multiple_base_meta_arches(self): | ||||
169 | directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath]) | ||||
170 | ref_input = {"koji_tag": "f20", "arch": ["src", "i386", "x86_64"]} | ||||
171 | | ||||
172 | output = directive.process(ref_input, None) | ||||
173 | | ||||
174 | assert output == { | ||||
175 | "f20": { | ||||
176 | "i386": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/i386/os", | ||||
177 | "x86_64": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os"} | ||||
178 | } |
1 | # -*- coding: utf-8 -*- | | |||
---|---|---|---|---|---|
2 | # Copyright 2009-2014, Red Hat, Inc. | | |||
3 | # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+> | | |||
4 | # See the LICENSE file for more details on Licensing | | |||
5 | | ||||
6 | import pytest | | |||
7 | import StringIO | | |||
8 | from dingus import Dingus | | |||
9 | | ||||
10 | from libtaskotron.directives import yumrepoinfo_directive | | |||
11 | from libtaskotron.exceptions import TaskotronDirectiveError | | |||
12 | | ||||
13 | from libtaskotron import yumrepoinfo | | |||
14 | | ||||
15 | | ||||
16 | TEST_CONF='''\ | | |||
17 | [DEFAULT] | | |||
18 | baseurl = http://download.fedoraproject.org/pub/fedora/linux | | |||
19 | goldurl = %(baseurl)s/releases/%(path)s/Everything/%(arch)s/os | | |||
20 | updatesurl = %(baseurl)s/updates/%(path)s/%(arch)s | | |||
21 | rawhideurl = %(baseurl)s/%(path)s/%(arch)s/os | | |||
22 | arches = i386, x86_64 | | |||
23 | parent = | | |||
24 | tag = %(__name__)s | | |||
25 | supported = no | | |||
26 | | ||||
27 | [rawhide] | | |||
28 | path = development/rawhide | | |||
29 | url = %(rawhideurl)s | | |||
30 | tag = f21 | | |||
31 | | ||||
32 | [f20] | | |||
33 | url = %(goldurl)s | | |||
34 | path = 20 | | |||
35 | supported = yes | | |||
36 | | ||||
37 | [f20-updates] | | |||
38 | url = %(updatesurl)s | | |||
39 | path = 20 | | |||
40 | parent = f20 | | |||
41 | arches = x86_64 | | |||
42 | | ||||
43 | [f20-updates-testing] | | |||
44 | url = %(updatesurl)s | | |||
45 | path = testing/20 | | |||
46 | parent = f20-updates | | |||
47 | ''' | | |||
48 | | ||||
49 | | ||||
50 | class TestYumrepoinfoDirective(object): | | |||
51 | | ||||
52 | @classmethod | | |||
53 | def setup_class(cls): | | |||
54 | '''One-time class initialization''' | | |||
55 | # create YumRepoInfo initialized with TEST_CONF | | |||
56 | cls.ref_arch = ['x86_64'] | | |||
57 | cls.repoinfo = yumrepoinfo.YumRepoInfo(filelist=[], arch=cls.ref_arch) | | |||
58 | cls.repoinfo.parser.readfp(StringIO.StringIO(TEST_CONF)) | | |||
59 | | ||||
60 | def test_missing_kojitag(self): | | |||
61 | directive = yumrepoinfo_directive.YumrepoinfoDirective(self.repoinfo) | | |||
62 | ref_input = {"arch": ["x86_64"]} | | |||
63 | | ||||
64 | with pytest.raises(TaskotronDirectiveError): | | |||
65 | directive.process(ref_input, None) | | |||
66 | | ||||
67 | def test_missing_arch(self): | | |||
68 | directive = yumrepoinfo_directive.YumrepoinfoDirective(self.repoinfo) | | |||
69 | ref_input = {"koji_tag":"rawhide"} | | |||
70 | | ||||
71 | with pytest.raises(TaskotronDirectiveError): | | |||
72 | directive.process(ref_input, None) | | |||
73 | | ||||
74 | def test_pending(self): | | |||
75 | directive = yumrepoinfo_directive.YumrepoinfoDirective(self.repoinfo) | | |||
76 | ref_input = {"koji_tag": "f20-pending", "arch": ["x86_64"]} | | |||
77 | | ||||
78 | output = directive.process(ref_input, None) | | |||
79 | | ||||
80 | assert output == {"f20": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os"} | | |||
81 | | ||||
82 | def test_rawhide(self): | | |||
83 | directive = yumrepoinfo_directive.YumrepoinfoDirective(self.repoinfo) | | |||
84 | ref_input = {"koji_tag": "rawhide", "arch": ["x86_64"]} | | |||
85 | | ||||
86 | output = directive.process(ref_input, None) | | |||
87 | | ||||
88 | assert output == {"rawhide": "http://download.fedoraproject.org/pub/fedora/linux/development/rawhide/x86_64/os"} | | |||
89 | | ||||
90 | def test_bad_kojitag(self): | | |||
91 | directive = yumrepoinfo_directive.YumrepoinfoDirective(self.repoinfo) | | |||
92 | ref_input = {"koji_tag": "my random tag"} | | |||
93 | | ||||
94 | with pytest.raises(TaskotronDirectiveError): | | |||
95 | directive.process(ref_input, None) | | |||
96 | | ||||
97 | def test_repo_path(self): | | |||
98 | | ||||
99 | directive = yumrepoinfo_directive.YumrepoinfoDirective(self.repoinfo) | | |||
100 | ref_input = {"koji_tag": "f20-updates", "arch": ["x86_64"]} | | |||
101 | | ||||
102 | output = directive.process(ref_input, None) | | |||
103 | | ||||
104 | assert output == { | | |||
105 | "f20": "http://download.fedoraproject.org/pub/fedora/linux/releases/20/Everything/x86_64/os", | | |||
106 | "f20-updates": "http://download.fedoraproject.org/pub/fedora/linux/updates/20/x86_64", | | |||
107 | } | | |||
108 | | ||||
109 | def test_use_arch(self, monkeypatch): | | |||
110 | """Make sure that the arch passed in as an arg is used to create the | | |||
111 | yumrepoinfo object instead of falling back to the default system arch""" | | |||
112 | ref_arch = 'i386' | | |||
113 | | ||||
114 | stub_getrepoinfo = Dingus(return_value=self.repoinfo) | | |||
115 | monkeypatch.setattr(yumrepoinfo, 'get_yumrepoinfo', stub_getrepoinfo) | | |||
116 | | ||||
117 | # don't set the repoinfo object, we've stubbed out the code that would | | |||
118 | # hit the filesystem, so it's not a risk here | | |||
119 | directive = yumrepoinfo_directive.YumrepoinfoDirective() | | |||
120 | ref_input = {"koji_tag": "f20-updates", "arch": [ref_arch]} | | |||
121 | | ||||
122 | directive.process(ref_input, None) | | |||
123 | | ||||
124 | # check the first arg of the first call to the stub object | | |||
125 | assert stub_getrepoinfo.calls()[0][1][0] == ref_arch | | |||
126 | | ||||
127 | |
This is no longer true, is it?