summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-10-29 16:48:41 +0000
committerGerrit Code Review <review@openstack.org>2018-10-29 16:48:41 +0000
commit25dfde96e59f9eff2bb0aa66d244dd307c4b622f (patch)
treeee342aa1971ecf24d2415e3d0b9e20b009ad2fb8
parent420f7ae281557cbe5cdd426b86a8e6647a52fff3 (diff)
parent3b419c3bc41c6a3db84d4456e0d757709831e2ab (diff)
Merge "docs: Add docstring information for pegleg.config"
-rw-r--r--pegleg/cli.py4
-rw-r--r--pegleg/config.py46
-rw-r--r--pegleg/engine/repository.py2
-rw-r--r--tests/unit/engine/test_site_repository.py12
4 files changed, 48 insertions, 16 deletions
diff --git a/pegleg/cli.py b/pegleg/cli.py
index cd15660..78c31f8 100644
--- a/pegleg/cli.py
+++ b/pegleg/cli.py
@@ -215,7 +215,7 @@ def site(*, site_repository, clone_path, extra_repositories, repo_key,
215 215
216 config.set_site_repo(site_repository) 216 config.set_site_repo(site_repository)
217 config.set_clone_path(clone_path) 217 config.set_clone_path(clone_path)
218 config.set_extra_repo_store(extra_repositories or []) 218 config.set_extra_repo_overrides(extra_repositories or [])
219 config.set_repo_key(repo_key) 219 config.set_repo_key(repo_key)
220 config.set_repo_username(repo_username) 220 config.set_repo_username(repo_username)
221 221
@@ -341,7 +341,7 @@ def type(*, site_repository, clone_path, extra_repositories, repo_key,
341 """ 341 """
342 config.set_site_repo(site_repository) 342 config.set_site_repo(site_repository)
343 config.set_clone_path(clone_path) 343 config.set_clone_path(clone_path)
344 config.set_extra_repo_store(extra_repositories or []) 344 config.set_extra_repo_overrides(extra_repositories or [])
345 config.set_repo_key(repo_key) 345 config.set_repo_key(repo_key)
346 config.set_repo_username(repo_username) 346 config.set_repo_username(repo_username)
347 347
diff --git a/pegleg/config.py b/pegleg/config.py
index ffc09c1..8cf0a61 100644
--- a/pegleg/config.py
+++ b/pegleg/config.py
@@ -12,6 +12,10 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15# TODO(felipemonteiro): This pattern below should be swapped out for click
16# context passing but will require a somewhat heavy code refactor. See:
17# http://click.pocoo.org/5/commands/#nested-handling-and-contexts
18
15try: 19try:
16 if GLOBAL_CONTEXT: 20 if GLOBAL_CONTEXT:
17 pass 21 pass
@@ -26,81 +30,109 @@ except NameError:
26 30
27 31
28def get_site_repo(): 32def get_site_repo():
33 """Get the primary site repository specified via ``-r`` CLI flag."""
29 return GLOBAL_CONTEXT['site_repo'] 34 return GLOBAL_CONTEXT['site_repo']
30 35
31 36
32def set_site_repo(r): 37def set_site_repo(r):
38 """Set the primary site repository."""
33 GLOBAL_CONTEXT['site_repo'] = r.rstrip('/') + '/' 39 GLOBAL_CONTEXT['site_repo'] = r.rstrip('/') + '/'
34 40
35 41
36def get_clone_path(): 42def get_clone_path():
43 """Get specified clone path (corresponds to ``-p`` CLI flag)."""
37 return GLOBAL_CONTEXT['clone_path'] 44 return GLOBAL_CONTEXT['clone_path']
38 45
39 46
40def set_clone_path(p): 47def set_clone_path(p):
48 """Set specified clone path (corresponds to ``-p`` CLI flag)."""
41 GLOBAL_CONTEXT['clone_path'] = p 49 GLOBAL_CONTEXT['clone_path'] = p
42 50
43 51
44def get_extra_repo_store(): 52def get_extra_repo_overrides():
45 return GLOBAL_CONTEXT.get('extra_repo_store', []) 53 """Get extra repository overrides specified via ``-e`` CLI flag."""
54 return GLOBAL_CONTEXT.get('extra_repo_overrides', [])
55
46 56
57def set_extra_repo_overrides(r):
58 """Set extra repository overrides.
47 59
48def set_extra_repo_store(r): 60 .. note:: Only CLI should call this.
49 GLOBAL_CONTEXT['extra_repo_store'] = r 61 """
62 GLOBAL_CONTEXT['extra_repo_overrides'] = r
50 63
51 64
52def set_repo_key(k): 65def set_repo_key(k):
66 """Set additional repository key, like extra metadata to track."""
53 GLOBAL_CONTEXT['repo_key'] = k 67 GLOBAL_CONTEXT['repo_key'] = k
54 68
55 69
56def get_repo_key(): 70def get_repo_key():
71 """Get additional repository key."""
57 return GLOBAL_CONTEXT.get('repo_key', None) 72 return GLOBAL_CONTEXT.get('repo_key', None)
58 73
59 74
60def set_repo_username(u): 75def set_repo_username(u):
76 """Set repo username for SSH auth, corresponds to ``-u`` CLI flag."""
61 GLOBAL_CONTEXT['repo_username'] = u 77 GLOBAL_CONTEXT['repo_username'] = u
62 78
63 79
64def get_repo_username(): 80def get_repo_username():
81 """Get repo username for SSH auth."""
65 return GLOBAL_CONTEXT.get('repo_username', None) 82 return GLOBAL_CONTEXT.get('repo_username', None)
66 83
67 84
68def set_extra_repo_list(a): 85def set_extra_repo_list(a):
86 """Set the extra repository list to be used by ``pegleg.engine``."""
69 GLOBAL_CONTEXT['extra_repos'] = [r.rstrip('/') + '/' for r in a] 87 GLOBAL_CONTEXT['extra_repos'] = [r.rstrip('/') + '/' for r in a]
70 88
71 89
72def add_extra_repo(a): 90def get_extra_repo_list():
73 GLOBAL_CONTEXT['extra_repos'].append(a.rstrip('/') + '/') 91 """Get the extra repository list.
74 92
93 .. note::
75 94
76def get_extra_repo_list(): 95 Use this instead of ``get_extra_repo_overrides`` as it handles
96 both overrides and site-definition.yaml defaults.
97 """
77 return GLOBAL_CONTEXT['extra_repos'] 98 return GLOBAL_CONTEXT['extra_repos']
78 99
79 100
101def add_extra_repo(a):
102 """Add an extra repo to the extra repository list."""
103 GLOBAL_CONTEXT['extra_repos'].append(a.rstrip('/') + '/')
104
105
80def each_extra_repo(): 106def each_extra_repo():
107 """Iterate over each extra repo."""
81 for a in GLOBAL_CONTEXT['extra_repos']: 108 for a in GLOBAL_CONTEXT['extra_repos']:
82 yield a 109 yield a
83 110
84 111
85def all_repos(): 112def all_repos():
113 """Return the primary site repo, in addition to all extra ones."""
86 repos = [get_site_repo()] 114 repos = [get_site_repo()]
87 repos.extend(get_extra_repo_list()) 115 repos.extend(get_extra_repo_list())
88 return repos 116 return repos
89 117
90 118
91def get_rel_site_path(): 119def get_rel_site_path():
120 """Get the relative site path name, default is "site"."""
92 return GLOBAL_CONTEXT.get('site_path', 'site') 121 return GLOBAL_CONTEXT.get('site_path', 'site')
93 122
94 123
95def set_rel_site_path(p): 124def set_rel_site_path(p):
125 """Set the relative site path name."""
96 p = p or 'site' 126 p = p or 'site'
97 GLOBAL_CONTEXT['site_path'] = p 127 GLOBAL_CONTEXT['site_path'] = p
98 128
99 129
100def get_rel_type_path(): 130def get_rel_type_path():
131 """Get the relative type path name, default is "type"."""
101 return GLOBAL_CONTEXT.get('type_path', 'type') 132 return GLOBAL_CONTEXT.get('type_path', 'type')
102 133
103 134
104def set_rel_type_path(p): 135def set_rel_type_path(p):
136 """Set the relative type path name."""
105 p = p or 'type' 137 p = p or 'type'
106 GLOBAL_CONTEXT['type_path'] = p 138 GLOBAL_CONTEXT['type_path'] = p
diff --git a/pegleg/engine/repository.py b/pegleg/engine/repository.py
index c65e1b1..b71dfd8 100644
--- a/pegleg/engine/repository.py
+++ b/pegleg/engine/repository.py
@@ -228,7 +228,7 @@ def _process_repository_overrides(site_def_repos):
228 """ 228 """
229 229
230 # Extra repositories to process. 230 # Extra repositories to process.
231 provided_repo_overrides = config.get_extra_repo_store() 231 provided_repo_overrides = config.get_extra_repo_overrides()
232 # Map repository names to the associated URL/revision for cloning. 232 # Map repository names to the associated URL/revision for cloning.
233 repo_overrides = {} 233 repo_overrides = {}
234 234
diff --git a/tests/unit/engine/test_site_repository.py b/tests/unit/engine/test_site_repository.py
index 605f3a8..27df345 100644
--- a/tests/unit/engine/test_site_repository.py
+++ b/tests/unit/engine/test_site_repository.py
@@ -181,7 +181,7 @@ def _test_process_repositories(site_repo=None,
181 elif repo_overrides: 181 elif repo_overrides:
182 with mock.patch.object( 182 with mock.patch.object(
183 config, 183 config,
184 'get_extra_repo_store', 184 'get_extra_repo_overrides',
185 autospec=True, 185 autospec=True,
186 return_value=list(repo_overrides.values())): 186 return_value=list(repo_overrides.values())):
187 do_test() 187 do_test()
@@ -372,7 +372,7 @@ def test_process_repositiories_extraneous_user_repo_value(m_log, *_):
372 # Get rid of REPO_USERNAME through an override. 372 # Get rid of REPO_USERNAME through an override.
373 with mock.patch.object( 373 with mock.patch.object(
374 config, 374 config,
375 'get_extra_repo_store', 375 'get_extra_repo_overrides',
376 autospec=True, 376 autospec=True,
377 return_value=repo_overrides): 377 return_value=repo_overrides):
378 _test_process_repositories_inner( 378 _test_process_repositories_inner(
@@ -426,7 +426,7 @@ def test_process_repositiories_no_site_def_repos_with_extraneous_overrides(
426 # Provide repo overrides. 426 # Provide repo overrides.
427 with mock.patch.object( 427 with mock.patch.object(
428 config, 428 config,
429 'get_extra_repo_store', 429 'get_extra_repo_overrides',
430 autospec=True, 430 autospec=True,
431 return_value=repo_overrides): 431 return_value=repo_overrides):
432 _test_process_repositories_inner( 432 _test_process_repositories_inner(
@@ -466,12 +466,12 @@ def test_process_repositories_without_repositories_key_in_site_definition(
466 autospec=True, 466 autospec=True,
467 return_value=TEST_REPOSITORIES) 467 return_value=TEST_REPOSITORIES)
468@mock.patch.object(util.git, 'is_repository', autospec=True, return_value=True) 468@mock.patch.object(util.git, 'is_repository', autospec=True, return_value=True)
469@mock.patch.object(config, 'get_extra_repo_store', autospec=True) 469@mock.patch.object(config, 'get_extra_repo_overrides', autospec=True)
470def test_process_extra_repositories_malformed_format_raises_exception( 470def test_process_extra_repositories_malformed_format_raises_exception(
471 m_get_extra_repo_store, *_): 471 m_get_extra_repo_overrides, *_):
472 # Will fail since it doesn't contain "=". 472 # Will fail since it doesn't contain "=".
473 broken_repo_url = 'broken_url' 473 broken_repo_url = 'broken_url'
474 m_get_extra_repo_store.return_value = [broken_repo_url] 474 m_get_extra_repo_overrides.return_value = [broken_repo_url]
475 error = ("The repository %s must be in the form of " 475 error = ("The repository %s must be in the form of "
476 "name=repoUrl[@revision]" % broken_repo_url) 476 "name=repoUrl[@revision]" % broken_repo_url)
477 477