-
Notifications
You must be signed in to change notification settings - Fork 0
/
environ.go
135 lines (116 loc) · 4.42 KB
/
environ.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
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package testing
import (
"github.com/juju/collections/set"
"github.com/juju/names/v4"
gitjujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v3"
"github.com/juju/utils/v3/ssh"
"github.com/juju/version/v2"
gc "gopkg.in/check.v1"
"github.com/juju/juju/charmhub"
"github.com/juju/juju/controller"
"github.com/juju/juju/environs/config"
jujuversion "github.com/juju/juju/version"
)
// FakeAuthKeys holds the authorized key used for testing
// purposes in FakeConfig. It is valid for parsing with the utils/ssh
// authorized-key utilities.
const FakeAuthKeys = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAYQDP8fPSAMFm2PQGoVUks/FENVUMww1QTK6m++Y2qX9NGHm43kwEzxfoWR77wo6fhBhgFHsQ6ogE/cYLx77hOvjTchMEP74EVxSce0qtDjI7SwYbOpAButRId3g/Ef4STz8= [email protected]`
func init() {
_, err := ssh.ParseAuthorisedKey(FakeAuthKeys)
if err != nil {
panic("FakeAuthKeys does not hold a valid authorized key: " + err.Error())
}
}
var (
// FakeSupportedJujuSeries is used to provide a series of canned results
// of series to test bootstrap code against.
FakeSupportedJujuSeries = set.NewStrings("precise", "trusty", "quantal", "bionic", "focal", jujuversion.DefaultSupportedLTS())
)
// FakeVersionNumber is a valid version number that can be used in testing.
var FakeVersionNumber = version.MustParse("2.99.0")
// ModelTag is a defined known valid UUID that can be used in testing.
var ModelTag = names.NewModelTag("deadbeef-0bad-400d-8000-4b1d0d06f00d")
// ControllerTag is a defined known valid UUID that can be used in testing.
var ControllerTag = names.NewControllerTag("deadbeef-1bad-500d-9000-4b1d0d06f00d")
// FakeControllerConfig returns an environment configuration
// that is expected to be found in state for a fake controller.
func FakeControllerConfig() controller.Config {
return controller.Config{
"controller-uuid": ControllerTag.Id(),
"ca-cert": CACert,
"state-port": 1234,
"api-port": 17777,
"set-numa-control-policy": false,
"model-logfile-max-backups": 1,
"model-logfile-max-size": "1M",
"model-logs-size": "1M",
"max-txn-log-size": "10M",
"auditing-enabled": false,
"audit-log-capture-args": true,
"audit-log-max-size": "200M",
"audit-log-max-backups": 5,
}
}
// FakeConfig returns an environment configuration for a
// fake provider with all required attributes set.
func FakeConfig() Attrs {
return Attrs{
"type": "someprovider",
"name": "testmodel",
"uuid": ModelTag.Id(),
"authorized-keys": FakeAuthKeys,
"firewall-mode": config.FwInstance,
"ssl-hostname-verification": true,
"development": false,
"default-series": jujuversion.DefaultSupportedLTS(),
}
}
// ModelConfig returns a default environment configuration suitable for
// setting in the state.
func ModelConfig(c *gc.C) *config.Config {
uuid := mustUUID()
return CustomModelConfig(c, Attrs{"uuid": uuid})
}
// mustUUID returns a stringified uuid or panics
func mustUUID() string {
uuid, err := utils.NewUUID()
if err != nil {
panic(err)
}
return uuid.String()
}
// CustomModelConfig returns an environment configuration with
// additional specified keys added.
func CustomModelConfig(c *gc.C, extra Attrs) *config.Config {
attrs := FakeConfig().Merge(Attrs{
"agent-version": "2.0.0",
"charmhub-url": charmhub.CharmHubServerURL,
}).Merge(extra).Delete("admin-secret")
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
return cfg
}
const DefaultMongoPassword = "conn-from-name-secret"
// FakeJujuXDGDataHomeSuite isolates the user's home directory and
// sets up a Juju home with a sample environment and certificate.
type FakeJujuXDGDataHomeSuite struct {
JujuOSEnvSuite
gitjujutesting.FakeHomeSuite
}
func (s *FakeJujuXDGDataHomeSuite) SetUpTest(c *gc.C) {
s.JujuOSEnvSuite.SetUpTest(c)
s.FakeHomeSuite.SetUpTest(c)
}
func (s *FakeJujuXDGDataHomeSuite) TearDownTest(c *gc.C) {
s.FakeHomeSuite.TearDownTest(c)
s.JujuOSEnvSuite.TearDownTest(c)
}
// AssertConfigParameterUpdated updates environment parameter and
// asserts that no errors were encountered.
func (s *FakeJujuXDGDataHomeSuite) AssertConfigParameterUpdated(c *gc.C, key, value string) {
s.PatchEnvironment(key, value)
}