1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# py.test -v -s tests/test_buildpackages.py
from mock import patch, Mock
from .. import buildpackages
from teuthology import packaging
def test_get_tag_branch_sha1():
gitbuilder = packaging.GitbuilderProject(
'ceph',
{
'os_type': 'centos',
'os_version': '7.0',
})
(tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
assert tag == None
assert branch == None
assert sha1 is not None
gitbuilder = packaging.GitbuilderProject(
'ceph',
{
'os_type': 'centos',
'os_version': '7.0',
'sha1': 'asha1',
})
(tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
assert tag == None
assert branch == None
assert sha1 == 'asha1'
remote = Mock
remote.arch = 'x86_64'
remote.os = Mock
remote.os.name = 'ubuntu'
remote.os.version = '14.04'
remote.os.codename = 'trusty'
remote.system_type = 'deb'
ctx = Mock
ctx.cluster = Mock
ctx.cluster.remotes = {remote: ['client.0']}
expected_tag = 'v0.94.1'
expected_sha1 = 'expectedsha1'
def check_output(cmd, shell):
assert shell == True
return expected_sha1 + " refs/tags/" + expected_tag
with patch.multiple(
buildpackages,
check_output=check_output,
):
gitbuilder = packaging.GitbuilderProject(
'ceph',
{
'os_type': 'centos',
'os_version': '7.0',
'sha1': 'asha1',
'all': {
'tag': tag,
},
},
ctx = ctx,
remote = remote)
(tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
assert tag == expected_tag
assert branch == None
assert sha1 == expected_sha1
expected_branch = 'hammer'
expected_sha1 = 'otherexpectedsha1'
def check_output(cmd, shell):
assert shell == True
return expected_sha1 + " refs/heads/" + expected_branch
with patch.multiple(
buildpackages,
check_output=check_output,
):
gitbuilder = packaging.GitbuilderProject(
'ceph',
{
'os_type': 'centos',
'os_version': '7.0',
'sha1': 'asha1',
'all': {
'branch': branch,
},
},
ctx = ctx,
remote = remote)
(tag, branch, sha1) = buildpackages.get_tag_branch_sha1(gitbuilder)
assert tag == None
assert branch == expected_branch
assert sha1 == expected_sha1
def test_lookup_configs():
expected_system_type = 'deb'
def make_remote():
remote = Mock()
remote.arch = 'x86_64'
remote.os = Mock()
remote.os.name = 'ubuntu'
remote.os.version = '14.04'
remote.os.codename = 'trusty'
remote.system_type = expected_system_type
return remote
ctx = Mock()
class cluster:
remote1 = make_remote()
remote2 = make_remote()
remotes = {
remote1: ['client.0'],
remote2: ['mon.a','osd.0'],
}
def only(self, role):
result = Mock()
if role in ('client.0',):
result.remotes = { cluster.remote1: None }
elif role in ('osd.0', 'mon.a'):
result.remotes = { cluster.remote2: None }
else:
result.remotes = None
return result
ctx.cluster = cluster()
ctx.config = {
'roles': [ ['client.0'], ['mon.a','osd.0'] ],
}
# nothing -> nothing
assert buildpackages.lookup_configs(ctx, {}) == []
assert buildpackages.lookup_configs(ctx, {1:[1,2,3]}) == []
assert buildpackages.lookup_configs(ctx, [[1,2,3]]) == []
assert buildpackages.lookup_configs(ctx, None) == []
#
# the overrides applies to install and to install.upgrade
# that have no tag, branch or sha1
#
config = {
'overrides': {
'install': {
'ceph': {
'sha1': 'overridesha1',
'tag': 'overridetag',
'branch': 'overridebranch',
},
},
},
'tasks': [
{
'install': {
'sha1': 'installsha1',
},
},
{
'install.upgrade': {
'osd.0': {
},
'client.0': {
'sha1': 'client0sha1',
},
},
}
],
}
ctx.config = config
expected_configs = [{'branch': 'overridebranch', 'sha1': 'overridesha1', 'tag': 'overridetag'},
{'project': 'ceph', 'branch': 'overridebranch', 'sha1': 'overridesha1', 'tag': 'overridetag'},
{'project': 'ceph', 'sha1': 'client0sha1'}]
assert buildpackages.lookup_configs(ctx, config) == expected_configs
|