forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format-2.0_whitebox_test.go
277 lines (188 loc) · 8.08 KB
/
format-2.0_whitebox_test.go
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// Copyright 2014 Canonical Ltd.
// Copyright 2014 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.
// The format tests are white box tests, meaning that the tests are in the
// same package as the code, as all the format details are internal to the
// package.
package agent
import (
"path/filepath"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2"
"github.com/juju/version/v2"
gc "gopkg.in/check.v1"
"github.com/juju/juju/core/model"
"github.com/juju/juju/testing"
)
type format_2_0Suite struct {
testing.BaseSuite
}
var _ = gc.Suite(&format_2_0Suite{})
func (s *format_2_0Suite) TestStatePortNotParsedWithoutSecret(c *gc.C) {
dataDir := c.MkDir()
configPath := filepath.Join(dataDir, AgentConfigFilename)
err := utils.AtomicWriteFile(configPath, []byte(agentConfig2_0NotStateMachine), 0600)
c.Assert(err, jc.ErrorIsNil)
readConfig, err := ReadConfig(configPath)
c.Assert(err, jc.ErrorIsNil)
_, available := readConfig.StateServingInfo()
c.Assert(available, jc.IsFalse)
}
func (*format_2_0Suite) TestReadConfWithExisting2_0ConfigFileContents(c *gc.C) {
dataDir := c.MkDir()
configPath := filepath.Join(dataDir, AgentConfigFilename)
err := utils.AtomicWriteFile(configPath, []byte(agentConfig2_0Contents), 0600)
c.Assert(err, jc.ErrorIsNil)
config, err := ReadConfig(configPath)
c.Assert(err, jc.ErrorIsNil)
c.Assert(config.UpgradedToVersion(), jc.DeepEquals, version.MustParse("1.17.5.1"))
c.Assert(config.Jobs(), jc.DeepEquals, []model.MachineJob{model.JobManageModel})
}
func (*format_2_0Suite) TestMarshalUnmarshal(c *gc.C) {
loggingConfig := "juju=INFO;unit=INFO"
config := newTestConfig(c)
// configFilePath is not serialized as it is the location of the file.
config.configFilePath = ""
config.SetLoggingConfig(loggingConfig)
data, err := format_2_0.marshal(config)
c.Assert(err, jc.ErrorIsNil)
newConfig, err := format_2_0.unmarshal(data)
c.Assert(err, jc.ErrorIsNil)
c.Check(newConfig, gc.DeepEquals, config)
c.Check(newConfig.LoggingConfig(), gc.Equals, loggingConfig)
}
var agentConfig2_0Contents = `
# format 2.0
controller: controller-deadbeef-1bad-500d-9000-4b1d0d06f00d
model: model-deadbeef-0bad-400d-8000-4b1d0d06f00d
tag: machine-0
datadir: /home/user/.local/share/juju/local
logdir: /var/log/juju-user-local
nonce: user-admin:bootstrap
jobs:
- JobManageModel
upgradedToVersion: 1.17.5.1
cacert: '-----BEGIN CERTIFICATE-----
MIICWzCCAcagAwIBAgIBADALBgkqhkiG9w0BAQUwQzENMAsGA1UEChMEanVqdTEy
MDAGA1UEAwwpanVqdS1nZW5lcmF0ZWQgQ0EgZm9yIGVudmlyb25tZW50ICJsb2Nh
bCIwHhcNMTQwMzA1MTQxOTA3WhcNMjQwMzA1MTQyNDA3WjBDMQ0wCwYDVQQKEwRq
dWp1MTIwMAYDVQQDDClqdWp1LWdlbmVyYXRlZCBDQSBmb3IgZW52aXJvbm1lbnQg
ImxvY2FsIjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwHsKV7fKfmSQt2QL
P4+hrqQJhDTMifgNkIY9nTlLHegV5jl5XJ8lRYjZBXJEMz0AzW/RbrDElkn5+4Do
pIWPNDAT0eztXBvVwL6qQOUtiBsA7vHQJMQaLVAmZNKvrHyuhcoG+hpf8EMaLdbA
iCGKifs+Y0MFt5AeriVDH5lGlzcCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgCkMA8G
A1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFB3Td3SP66UToZkOjVh3Wy8b6HR6MB8G
A1UdIwQYMBaAFB3Td3SP66UToZkOjVh3Wy8b6HR6MAsGCSqGSIb3DQEBBQOBgQB4
izvSRSpimi40aEOnZIsSMHVBiSCclpBg5cq7lGyiUSsDROTIbsRAKPBmrflB/qbf
J70rWFwh/d/5ssCAYrZviFL6WvpuLD3j3m4PYampNMmvJf2s6zVRIMotEY+bVwfU
z4jGaVpODac0i0bE0/Uh9qXK1UXcYY57vNNAgkaYAQ==
-----END CERTIFICATE-----
'
stateaddresses:
- localhost:37017
statepassword: NB5imrDaWCCRW/4akSSvUxhX
apiaddresses:
- localhost:17071
apipassword: NB5imrDaWCCRW/4akSSvUxhX
oldpassword: oBlMbFUGvCb2PMFgYVzjS6GD
values:
AGENT_SERVICE_NAME: juju-agent-user-local
CONTAINER_TYPE: ""
NAMESPACE: user-local
PROVIDER_TYPE: local
STORAGE_ADDR: 10.0.3.1:8040
STORAGE_DIR: /home/user/.local/share/juju/local/storage
controllercert: '-----BEGIN CERTIFICATE-----
MIICNzCCAaKgAwIBAgIBADALBgkqhkiG9w0BAQUwQzENMAsGA1UEChMEanVqdTEy
MDAGA1UEAwwpanVqdS1nZW5lcmF0ZWQgQ0EgZm9yIGVudmlyb25tZW50ICJsb2Nh
bCIwHh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s39kk4DuQtZNhmmBqfskkMPlZBfEmfJrxeqVKw0j56faPBU5cCQFYU
mP/8+VxwM2OPEZMmmaS7gR1E/BEznzh5S9iaNQSy0kuTkMhQuCnPJ/OsYiczEH08
lvnEyc/E/8bcPM09q4ECQCFwMWzw2Jx9VOBGm60yiOKIdLgdDZOY/tP0jigNCMJF
47/BJx3FCgW3io81a4KOc445LxgiPUJyyCNlY1dW70o=
-----END RSA PRIVATE KEY-----
'
apiport: 17070
controllerapiport: 17071
`[1:]
var agentConfig2_0NotStateMachine = `
# format 2.0
controller: controller-deadbeef-1bad-500d-9000-4b1d0d06f00d
model: model-deadbeef-0bad-400d-8000-4b1d0d06f00d
tag: machine-1
datadir: /home/user/.local/share/juju/local
logdir: /var/log/juju-user-local
nonce: user-admin:bootstrap
jobs:
- JobManageModel
upgradedToVersion: 1.17.5.1
cacert: '-----BEGIN CERTIFICATE-----
MIICWzCCAcagAwIBAgIBADALBgkqhkiG9w0BAQUwQzENMAsGA1UEChMEanVqdTEy
MDAGA1UEAwwpanVqdS1nZW5lcmF0ZWQgQ0EgZm9yIGVudmlyb25tZW50ICJsb2Nh
bCIwHhcNMTQwMzA1MTQxOTA3WhcNMjQwMzA1MTQyNDA3WjBDMQ0wCwYDVQQKEwRq
dWp1MTIwMAYDVQQDDClqdWp1LWdlbmVyYXRlZCBDQSBmb3IgZW52aXJvbm1lbnQg
ImxvY2FsIjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwHsKV7fKfmSQt2QL
P4+hrqQJhDTMifgNkIY9nTlLHegV5jl5XJ8lRYjZBXJEMz0AzW/RbrDElkn5+4Do
pIWPNDAT0eztXBvVwL6qQOUtiBsA7vHQJMQaLVAmZNKvrHyuhcoG+hpf8EMaLdbA
iCGKifs+Y0MFt5AeriVDH5lGlzcCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgCkMA8G
A1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFB3Td3SP66UToZkOjVh3Wy8b6HR6MB8G
A1UdIwQYMBaAFB3Td3SP66UToZkOjVh3Wy8b6HR6MAsGCSqGSIb3DQEBBQOBgQB4
izvSRSpimi40aEOnZIsSMHVBiSCclpBg5cq7lGyiUSsDROTIbsRAKPBmrflB/qbf
J70rWFwh/d/5ssCAYrZviFL6WvpuLD3j3m4PYampNMmvJf2s6zVRIMotEY+bVwfU
z4jGaVpODac0i0bE0/Uh9qXK1UXcYY57vNNAgkaYAQ==
-----END CERTIFICATE-----
'
stateaddresses:
- localhost:37017
statepassword: NB5imrDaWCCRW/4akSSvUxhX
apiaddresses:
- localhost:17070
apipassword: NB5imrDaWCCRW/4akSSvUxhX
oldpassword: oBlMbFUGvCb2PMFgYVzjS6GD
values:
AGENT_SERVICE_NAME: juju-agent-user-local
CONTAINER_TYPE: ""
MONGO_SERVICE_NAME: juju-db-user-local
NAMESPACE: user-local
PROVIDER_TYPE: local
STORAGE_ADDR: 10.0.3.1:8040
STORAGE_DIR: /home/user/.local/share/juju/local/storage
apiport: 17070
`[1:]