func opClientDestroyServiceUnits(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().DestroyServiceUnits("wordpress/99") if err != nil && strings.HasPrefix(err.Error(), "no units were destroyed") { err = nil } return func() {}, err }
func opClientWatchAll(c *gc.C, st *api.State, mst *state.State) (func(), error) { watcher, err := st.Client().WatchAll() if err == nil { watcher.Stop() } return func() {}, err }
// testNamespace starts a worker and ensures that // the rsyslog config file has the expected filename, // and the appropriate log dir is used. func (s *RsyslogSuite) testNamespace(c *gc.C, st *api.State, tag, namespace, expectedFilename, expectedLogDir string) { restarted := make(chan struct{}, 2) // once for create, once for teardown s.PatchValue(rsyslog.RestartRsyslog, func() error { restarted <- struct{}{} return nil }) err := os.MkdirAll(expectedLogDir, 0755) c.Assert(err, gc.IsNil) worker, err := rsyslog.NewRsyslogConfigWorker(st.Rsyslog(), rsyslog.RsyslogModeForwarding, tag, namespace, []string{"0.1.2.3"}) c.Assert(err, gc.IsNil) defer func() { c.Assert(worker.Wait(), gc.IsNil) }() defer worker.Kill() // change the API HostPorts to trigger an rsyslog restart newHostPorts := instance.AddressesWithPort(instance.NewAddresses("127.0.0.1"), 6541) err = s.State.SetAPIHostPorts([][]instance.HostPort{newHostPorts}) c.Assert(err, gc.IsNil) // Wait for rsyslog to be restarted, so we can check to see // what the name of the config file is. waitForRestart(c, restarted) // Ensure that ca-cert.pem gets written to the expected log dir. waitForFile(c, filepath.Join(expectedLogDir, "ca-cert.pem")) dir, err := os.Open(*rsyslog.RsyslogConfDir) c.Assert(err, gc.IsNil) names, err := dir.Readdirnames(-1) dir.Close() c.Assert(err, gc.IsNil) c.Assert(names, gc.HasLen, 1) c.Assert(names[0], gc.Equals, expectedFilename) }
func opClientEnvironmentGet(c *gc.C, st *api.State, mst *state.State) (func(), error) { _, err := st.Client().EnvironmentGet() if err != nil { return func() {}, err } return func() {}, nil }
func opClientServiceSetYAML(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().ServiceSetYAML("wordpress", `"wordpress": {"blog-title": "foo"}`) if err != nil { return func() {}, err } return resetBlogTitle(c, st), nil }
func opClientServiceDestroy(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().ServiceDestroy("non-existent") if params.IsCodeNotFound(err) { err = nil } return func() {}, err }
func opClientServiceSetCharm(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().ServiceSetCharm("nosuch", "local:quantal/wordpress", false) if params.IsCodeNotFound(err) { err = nil } return func() {}, err }
func opClientServiceDeployWithNetworks(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().ServiceDeployWithNetworks("mad:bad/url-1", "x", 1, "", constraints.Value{}, "", nil, nil) if err.Error() == `charm URL has invalid schema: "mad:bad/url-1"` { err = nil } return func() {}, err }
func opClientDestroyRelation(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().DestroyRelation("nosuch1", "nosuch2") if params.IsCodeNotFound(err) { err = nil } return func() {}, err }
func opClientAddServiceUnits(c *gc.C, st *api.State, mst *state.State) (func(), error) { _, err := st.Client().AddServiceUnits("nosuch", 1, "") if params.IsCodeNotFound(err) { err = nil } return func() {}, err }
func opClientServiceUnexpose(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().ServiceUnexpose("wordpress") if err != nil { return func() {}, err } return func() {}, nil }
func opClientGetAnnotations(c *gc.C, st *api.State, mst *state.State) (func(), error) { ann, err := st.Client().GetAnnotations("service-wordpress") if err != nil { return func() {}, err } c.Assert(ann, gc.DeepEquals, make(map[string]string)) return func() {}, nil }
func resetBlogTitle(c *gc.C, st *api.State) func() { return func() { err := st.Client().ServiceSet("wordpress", map[string]string{ "blog-title": "", }) c.Assert(err, gc.IsNil) } }
func opClientSetEnvironmentConstraints(c *gc.C, st *api.State, mst *state.State) (func(), error) { nullConstraints := constraints.Value{} err := st.Client().SetEnvironmentConstraints(nullConstraints) if err != nil { return func() {}, err } return func() {}, nil }
func (s *keyupdaterSuite) SetUpTest(c *gc.C) { s.JujuConnSuite.SetUpTest(c) var stateAPI *api.State stateAPI, s.rawMachine = s.OpenAPIAsNewMachine(c) c.Assert(stateAPI, gc.NotNil) s.keyupdater = stateAPI.KeyUpdater() c.Assert(s.keyupdater, gc.NotNil) }
func opClientSetServiceConstraints(c *gc.C, st *api.State, mst *state.State) (func(), error) { nullConstraints := constraints.Value{} err := st.Client().SetServiceConstraints("wordpress", nullConstraints) if err != nil { return func() {}, err } return func() {}, nil }
func opClientStatus(c *gc.C, st *api.State, mst *state.State) (func(), error) { status, err := st.Client().Status(nil) if err != nil { c.Check(status, gc.IsNil) return func() {}, err } c.Assert(status, jc.DeepEquals, scenarioStatus) return func() {}, nil }
func opClientServiceSet(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().ServiceSet("wordpress", map[string]string{ "blog-title": "foo", }) if err != nil { return func() {}, err } return resetBlogTitle(c, st), nil }
func opClientServiceExpose(c *gc.C, st *api.State, mst *state.State) (func(), error) { err := st.Client().ServiceExpose("wordpress") if err != nil { return func() {}, err } return func() { svc, err := mst.Service("wordpress") c.Assert(err, gc.IsNil) svc.ClearExposed() }, nil }
func opClientCharmInfo(c *gc.C, st *api.State, mst *state.State) (func(), error) { info, err := st.Client().CharmInfo("local:quantal/wordpress-3") if err != nil { c.Check(info, gc.IsNil) return func() {}, err } c.Assert(info.URL, gc.Equals, "local:quantal/wordpress-3") c.Assert(info.Meta.Name, gc.Equals, "wordpress") c.Assert(info.Revision, gc.Equals, 3) return func() {}, nil }
func opClientSetAnnotations(c *gc.C, st *api.State, mst *state.State) (func(), error) { pairs := map[string]string{"key1": "value1", "key2": "value2"} err := st.Client().SetAnnotations("service-wordpress", pairs) if err != nil { return func() {}, err } return func() { pairs := map[string]string{"key1": "", "key2": ""} st.Client().SetAnnotations("service-wordpress", pairs) }, nil }
func opClientEnvironmentSet(c *gc.C, st *api.State, mst *state.State) (func(), error) { args := map[string]interface{}{"some-key": "some-value"} err := st.Client().EnvironmentSet(args) if err != nil { return func() {}, err } return func() { args["some-key"] = nil st.Client().EnvironmentSet(args) }, nil }
func opClientServiceUpdate(c *gc.C, st *api.State, mst *state.State) (func(), error) { args := params.ServiceUpdate{ ServiceName: "no-such-charm", CharmUrl: "cs:quantal/wordpress-42", ForceCharmUrl: true, SettingsStrings: map[string]string{"blog-title": "foo"}, SettingsYAML: `"wordpress": {"blog-title": "foo"}`, } err := st.Client().ServiceUpdate(args) if params.IsCodeNotFound(err) { err = nil } return func() {}, err }
func opClientResolved(c *gc.C, st *api.State, _ *state.State) (func(), error) { err := st.Client().Resolved("wordpress/0", false) // There are several scenarios in which this test is called, one is // that the user is not authorized. In that case we want to exit now, // letting the error percolate out so the caller knows that the // permission error was correctly generated. if err != nil && params.IsCodeUnauthorized(err) { return func() {}, err } // Otherwise, the user was authorized, but we expect an error anyway // because the unit is not in an error state when we tried to resolve // the error. Therefore, since it is complaining it means that the // call to Resolved worked, so we're happy. c.Assert(err, gc.NotNil) c.Assert(err.Error(), gc.Equals, `unit "wordpress/0" is not in an error state`) return func() {}, nil }
// updateSupportedContainers records in state that a machine can run the specified containers. // It starts a watcher and when a container of a given type is first added to the machine, // the watcher is killed, the machine is set up to be able to start containers of the given type, // and a suitable provisioner is started. func (a *MachineAgent) updateSupportedContainers( runner worker.Runner, st *api.State, tag string, containers []instance.ContainerType, agentConfig agent.Config, ) error { pr := st.Provisioner() machine, err := pr.Machine(tag) if err != nil { return fmt.Errorf("%s is not in state: %v", tag, err) } if len(containers) == 0 { if err := machine.SupportsNoContainers(); err != nil { return fmt.Errorf("clearing supported containers for %s: %v", tag, err) } return nil } if err := machine.SetSupportedContainers(containers...); err != nil { return fmt.Errorf("setting supported containers for %s: %v", tag, err) } initLock, err := hookExecutionLock(agentConfig.DataDir()) if err != nil { return err } // Start the watcher to fire when a container is first requested on the machine. watcherName := fmt.Sprintf("%s-container-watcher", machine.Id()) handler := provisioner.NewContainerSetupHandler( runner, watcherName, containers, machine, pr, agentConfig, initLock, ) a.startWorkerAfterUpgrade(runner, watcherName, func() (worker.Worker, error) { return worker.NewStringsWorker(handler), nil }) return nil }
func (s *workerSuite) SetUpTest(c *gc.C) { s.JujuConnSuite.SetUpTest(c) // Default ssh user is currently "ubuntu". c.Assert(authenticationworker.SSHUser, gc.Equals, "ubuntu") // Set the ssh user to empty (the current user) as required by the test infrastructure. s.PatchValue(&authenticationworker.SSHUser, "") // Replace the default dummy key in the test environment with a valid one. // This will be added to the ssh authorised keys when the agent starts. s.setAuthorisedKeys(c, sshtesting.ValidKeyOne.Key+" firstuser@host") // Record the existing key with its prefix for testing later. s.existingEnvKey = sshtesting.ValidKeyOne.Key + " Juju:firstuser@host" // Set up an existing key (which is not in the environment) in the ssh authorised_keys file. s.existingKeys = []string{sshtesting.ValidKeyTwo.Key + " existinguser@host"} err := ssh.AddKeys(authenticationworker.SSHUser, s.existingKeys...) c.Assert(err, gc.IsNil) var apiRoot *api.State apiRoot, s.machine = s.OpenAPIAsNewMachine(c) c.Assert(apiRoot, gc.NotNil) s.keyupdaterApi = apiRoot.KeyUpdater() c.Assert(s.keyupdaterApi, gc.NotNil) }
func opClientSetEnvironAgentVersion(c *gc.C, st *api.State, mst *state.State) (func(), error) { attrs, err := st.Client().EnvironmentGet() if err != nil { return func() {}, err } err = st.Client().SetEnvironAgentVersion(version.Current.Number) if err != nil { return func() {}, err } return func() { oldAgentVersion, found := attrs["agent-version"] if found { versionString := oldAgentVersion.(string) st.Client().SetEnvironAgentVersion(version.MustParse(versionString)) } }, nil }
func opClientGetServiceConstraints(c *gc.C, st *api.State, mst *state.State) (func(), error) { _, err := st.Client().GetServiceConstraints("wordpress") return func() {}, err }