Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1179)

Side by Side Diff: environs/dummy/environs.go

Issue 8545043: environs: extract tools package
Patch Set: environs: extract tools package Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cmd/jujud/upgrade_test.go ('k') | environs/ec2/live_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // The dummy provider implements an environment provider for testing 1 // The dummy provider implements an environment provider for testing
2 // purposes, registered with environs under the name "dummy". 2 // purposes, registered with environs under the name "dummy".
3 // 3 //
4 // The configuration YAML for the testing environment 4 // The configuration YAML for the testing environment
5 // must specify a "state-server" property with a boolean 5 // must specify a "state-server" property with a boolean
6 // value. If this is true, a state server will be started 6 // value. If this is true, a state server will be started
7 // the first time StateInfo is called on a newly reset environment. 7 // the first time StateInfo is called on a newly reset environment.
8 // 8 //
9 // The configuration data also accepts a "broken" property 9 // The configuration data also accepts a "broken" property
10 // of type boolean. If this is non-empty, any operation 10 // of type boolean. If this is non-empty, any operation
11 // after the environment has been opened will return 11 // after the environment has been opened will return
12 // the error "broken environment", and will also log that. 12 // the error "broken environment", and will also log that.
13 // 13 //
14 // The DNS name of instances is the same as the Id, 14 // The DNS name of instances is the same as the Id,
15 // with ".dns" appended. 15 // with ".dns" appended.
16 // 16 //
17 // To avoid enumerating all possible series and architectures, 17 // To avoid enumerating all possible series and architectures,
18 // any series or architecture with the prefix "unknown" is 18 // any series or architecture with the prefix "unknown" is
19 // treated as bad when starting a new instance. 19 // treated as bad when starting a new instance.
20 package dummy 20 package dummy
21 21
22 import ( 22 import (
23 "errors" 23 "errors"
24 "fmt" 24 "fmt"
25 "launchpad.net/juju-core/constraints" 25 "launchpad.net/juju-core/constraints"
26 "launchpad.net/juju-core/environs" 26 "launchpad.net/juju-core/environs"
27 "launchpad.net/juju-core/environs/config" 27 "launchpad.net/juju-core/environs/config"
28 envtesting "launchpad.net/juju-core/environs/testing"
28 "launchpad.net/juju-core/log" 29 "launchpad.net/juju-core/log"
29 "launchpad.net/juju-core/schema" 30 "launchpad.net/juju-core/schema"
30 "launchpad.net/juju-core/state" 31 "launchpad.net/juju-core/state"
31 "launchpad.net/juju-core/state/api" 32 "launchpad.net/juju-core/state/api"
32 "launchpad.net/juju-core/state/api/params" 33 "launchpad.net/juju-core/state/api/params"
33 "launchpad.net/juju-core/state/apiserver" 34 "launchpad.net/juju-core/state/apiserver"
34 "launchpad.net/juju-core/testing" 35 "launchpad.net/juju-core/testing"
35 "launchpad.net/juju-core/trivial" 36 "launchpad.net/juju-core/trivial"
36 "launchpad.net/juju-core/version" 37 "launchpad.net/juju-core/version"
37 "net" 38 "net"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 func newState(name string, ops chan<- Operation, fwmode config.FirewallMode) *en vironState { 221 func newState(name string, ops chan<- Operation, fwmode config.FirewallMode) *en vironState {
221 s := &environState{ 222 s := &environState{
222 name: name, 223 name: name,
223 ops: ops, 224 ops: ops,
224 insts: make(map[state.InstanceId]*instance), 225 insts: make(map[state.InstanceId]*instance),
225 globalPorts: make(map[params.Port]bool), 226 globalPorts: make(map[params.Port]bool),
226 firewallMode: fwmode, 227 firewallMode: fwmode,
227 } 228 }
228 s.storage = newStorage(s, "/"+name+"/private") 229 s.storage = newStorage(s, "/"+name+"/private")
229 s.publicStorage = newStorage(s, "/"+name+"/public") 230 s.publicStorage = newStorage(s, "/"+name+"/public")
230 putFakeTools(s.publicStorage)
231 s.listen() 231 s.listen()
232 envtesting.MustUploadFakeTools(s.publicStorage)
232 return s 233 return s
233 } 234 }
234 235
235 // putFakeTools writes something
236 // that looks like a tools archive so Bootstrap can
237 // find some tools and initialise the state correctly.
238 func putFakeTools(s environs.StorageWriter) {
239 log.Infof("environs/dummy: putting fake tools")
240 toolsVersion := version.Current
241 path := environs.ToolsStoragePath(toolsVersion)
242 toolsContents := "tools archive, honest guv"
243 err := s.Put(path, strings.NewReader(toolsContents), int64(len(toolsCont ents)))
244 if err != nil {
245 panic(err)
246 }
247 if toolsVersion.Series != config.DefaultSeries {
248 toolsVersion.Series = config.DefaultSeries
249 path = environs.ToolsStoragePath(toolsVersion)
250 err = s.Put(path, strings.NewReader(toolsContents), int64(len(to olsContents)))
251 if err != nil {
252 panic(err)
253 }
254 }
255 }
256
257 // listen starts a network listener listening for http 236 // listen starts a network listener listening for http
258 // requests to retrieve files in the state's storage. 237 // requests to retrieve files in the state's storage.
259 func (s *environState) listen() { 238 func (s *environState) listen() {
260 l, err := net.Listen("tcp", "127.0.0.1:0") 239 l, err := net.Listen("tcp", "127.0.0.1:0")
261 if err != nil { 240 if err != nil {
262 panic(fmt.Errorf("cannot start listener: %v", err)) 241 panic(fmt.Errorf("cannot start listener: %v", err))
263 } 242 }
264 s.httpListener = l 243 s.httpListener = l
265 mux := http.NewServeMux() 244 mux := http.NewServeMux()
266 mux.Handle(s.storage.path+"/", http.StripPrefix(s.storage.path+"/", s.st orage)) 245 mux.Handle(s.storage.path+"/", http.StripPrefix(s.storage.path+"/", s.st orage))
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 // time.Durations into this value. 769 // time.Durations into this value.
791 var providerDelay time.Duration 770 var providerDelay time.Duration
792 771
793 // pause execution to simulate the latency of a real provider 772 // pause execution to simulate the latency of a real provider
794 func delay() { 773 func delay() {
795 if providerDelay > 0 { 774 if providerDelay > 0 {
796 log.Infof("environs/dummy: pausing for %v", providerDelay) 775 log.Infof("environs/dummy: pausing for %v", providerDelay)
797 <-time.After(providerDelay) 776 <-time.After(providerDelay)
798 } 777 }
799 } 778 }
OLDNEW
« no previous file with comments | « cmd/jujud/upgrade_test.go ('k') | environs/ec2/live_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b