1 # py.test -v -s tests/test_buildpackages.py
3 from mock import patch, Mock
5 from .. import buildpackages
6 from teuthology import packaging
8 def test_get_tag_branch_sha1():
9 gitbuilder = packaging.GitbuilderProject(
15 (tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
18 assert sha1 is not None
20 gitbuilder = packaging.GitbuilderProject(
27 (tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
30 assert sha1 == 'asha1'
33 remote.arch = 'x86_64'
35 remote.os.name = 'ubuntu'
36 remote.os.version = '14.04'
37 remote.os.codename = 'trusty'
38 remote.system_type = 'deb'
41 ctx.cluster.remotes = {remote: ['client.0']}
43 expected_tag = 'v0.94.1'
44 expected_sha1 = 'expectedsha1'
45 def check_output(cmd, shell):
47 return expected_sha1 + " refs/tags/" + expected_tag
50 check_output=check_output,
52 gitbuilder = packaging.GitbuilderProject(
64 (tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
65 assert tag == expected_tag
67 assert sha1 == expected_sha1
69 expected_branch = 'hammer'
70 expected_sha1 = 'otherexpectedsha1'
71 def check_output(cmd, shell):
73 return expected_sha1 + " refs/heads/" + expected_branch
76 check_output=check_output,
78 gitbuilder = packaging.GitbuilderProject(
90 (tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
92 assert branch == expected_branch
93 assert sha1 == expected_sha1
95 def test_lookup_configs():
96 expected_system_type = 'deb'
99 remote.arch = 'x86_64'
101 remote.os.name = 'ubuntu'
102 remote.os.version = '14.04'
103 remote.os.codename = 'trusty'
104 remote.system_type = expected_system_type
108 remote1 = make_remote()
109 remote2 = make_remote()
111 remote1: ['client.0'],
112 remote2: ['mon.a','osd.0'],
114 def only(self, role):
116 if role in ('client.0',):
117 result.remotes = { cluster.remote1: None }
118 elif role in ('osd.0', 'mon.a'):
119 result.remotes = { cluster.remote2: None }
121 result.remotes = None
123 ctx.cluster = cluster()
125 'roles': [ ['client.0'], ['mon.a','osd.0'] ],
129 assert buildpackages.lookup_configs(ctx, {}) == []
130 assert buildpackages.lookup_configs(ctx, {1:[1,2,3]}) == []
131 assert buildpackages.lookup_configs(ctx, [[1,2,3]]) == []
132 assert buildpackages.lookup_configs(ctx, None) == []
135 # the overrides applies to install and to install.upgrade
136 # that have no tag, branch or sha1
142 'sha1': 'overridesha1',
143 'tag': 'overridetag',
144 'branch': 'overridebranch',
151 'sha1': 'installsha1',
159 'sha1': 'client0sha1',
166 expected_configs = [{'branch': 'overridebranch', 'sha1': 'overridesha1', 'tag': 'overridetag'},
167 {'project': 'ceph', 'branch': 'overridebranch', 'sha1': 'overridesha1', 'tag': 'overridetag'},
168 {'project': 'ceph', 'sha1': 'client0sha1'}]
170 assert buildpackages.lookup_configs(ctx, config) == expected_configs