func (s *CLISuite) TestCluster(t *c.C) { // use a custom flynnrc to avoid disrupting other tests file, err := ioutil.TempFile("", "") t.Assert(err, c.IsNil) flynn := func(cmdArgs ...string) *CmdResult { cmd := exec.Command(args.CLI, cmdArgs...) cmd.Env = flynnEnv(file.Name()) return run(t, cmd) } // cluster add t.Assert(flynn("cluster", "add", "--no-git", "foo", "https://controller.foo.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds) t.Assert(flynn("cluster"), SuccessfulOutputContains, "foo") t.Assert(flynn("cluster", "add", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds) t.Assert(flynn("cluster"), SuccessfulOutputContains, "test") t.Assert(flynn("cluster", "add", "-f", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds) t.Assert(flynn("cluster"), SuccessfulOutputContains, "test") t.Assert(flynn("cluster", "add", "-f", "-d", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds) t.Assert(flynn("cluster"), SuccessfulOutputContains, "test") // make sure the cluster is present in the config cfg, err := config.ReadFile(file.Name()) t.Assert(err, c.IsNil) t.Assert(cfg.Default, c.Equals, "test") t.Assert(cfg.Clusters, c.HasLen, 2) t.Assert(cfg.Clusters[0].Name, c.Equals, "foo") t.Assert(cfg.Clusters[1].Name, c.Equals, "test") // overwriting with a conflicting name and a different conflicting url should error conflict := flynn("cluster", "add", "-f", "--no-git", "foo", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600") t.Assert(conflict, c.Not(Succeeds)) t.Assert(conflict, OutputContains, "conflict with") // overwriting (without --force) should not work t.Assert(flynn("cluster", "add", "test", "foo", "bar"), c.Not(Succeeds)) t.Assert(flynn("cluster"), SuccessfulOutputContains, "test") t.Assert(flynn("cluster"), SuccessfulOutputContains, "(default)") // change default cluster t.Assert(flynn("cluster", "default", "test"), SuccessfulOutputContains, "\"test\" is now the default cluster.") t.Assert(flynn("cluster", "default", "missing"), OutputContains, "Cluster \"missing\" does not exist and cannot be set as default.") t.Assert(flynn("cluster", "default"), SuccessfulOutputContains, "test") cfg, err = config.ReadFile(file.Name()) t.Assert(err, c.IsNil) t.Assert(cfg.Default, c.Equals, "test") // cluster remove t.Assert(flynn("cluster", "remove", "test"), Succeeds) t.Assert(flynn("cluster"), c.Not(SuccessfulOutputContains), "test") cfg, err = config.ReadFile(file.Name()) t.Assert(err, c.IsNil) t.Assert(cfg.Clusters, c.HasLen, 1) t.Assert(flynn("cluster", "remove", "foo"), Succeeds) // cluster remove default and set next available t.Assert(flynn("cluster", "add", "-d", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "test", "https://controller.test.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds) t.Assert(flynn("cluster", "add", "--no-git", "-p", "KGCENkp53YF5OvOKkZIry71+czFRkSw2ZdMszZ/0ljs=", "next", "https://controller.next.example.com", "e09dc5301d72be755a3d666f617c4600"), Succeeds) t.Assert(flynn("cluster", "remove", "test"), SuccessfulOutputContains, "Cluster \"test\" removed and \"next\" is now the default cluster.") t.Assert(flynn("cluster", "default"), SuccessfulOutputContains, "next") }
func (c *BaseCluster) configureCLI() error { config, err := cfg.ReadFile(cfg.DefaultPath()) if err != nil && !os.IsNotExist(err) { return err } cluster := c.ClusterConfig() if err := config.Add(cluster, true); err != nil { return err } config.SetDefault(c.Name) if err := config.SaveTo(cfg.DefaultPath()); err != nil { return err } caFile, err := cfg.CACertFile(cluster.Name) if err != nil { return err } defer caFile.Close() if _, err := caFile.Write([]byte(c.CACert)); err != nil { return err } if err := cfg.WriteGlobalGitConfig(cluster.GitURL, caFile.Name()); err != nil { return err } c.SendLog("CLI configured locally") return nil }
func (h *Helper) clusterConf(t *c.C) *config.Cluster { if h.config == nil { conf, err := config.ReadFile(flynnrc) t.Assert(err, c.IsNil) t.Assert(conf.Clusters, c.HasLen, 1) h.config = conf.Clusters[0] } return h.config }
func readConfig() (err error) { if config != nil { return nil } config, err = cfg.ReadFile(configPath()) if os.IsNotExist(err) { err = nil } return }
func (s *SchedulerSuite) SetUpSuite(t *c.C) { conf, err := config.ReadFile(flynnrc) t.Assert(err, c.IsNil) cluster := conf.Clusters[0] pin, err := base64.StdEncoding.DecodeString(cluster.TLSPin) t.Assert(err, c.IsNil) client, err := controller.NewClientWithPin(cluster.URL, cluster.Key, pin) t.Assert(err, c.IsNil) s.client = client }
func (c *BaseCluster) configureCLI() error { config, err := cfg.ReadFile(cfg.DefaultPath()) if err != nil && !os.IsNotExist(err) { return err } if err := config.Add(c.ClusterConfig(), true); err != nil { return err } config.SetDefault(c.Name) if err := config.SaveTo(cfg.DefaultPath()); err != nil { return err } c.SendLog("CLI configured locally") return nil }
func readConfig() (err error) { if config != nil { return nil } config, err = cfg.ReadFile(configPath()) if os.IsNotExist(err) { err = nil } if config.Upgrade() { if err := config.SaveTo(configPath()); err != nil { return fmt.Errorf("Error saving upgraded config: %s", err) } } return }
func setupDockerPush() error { conf, err := config.ReadFile(flynnrc) if err != nil { return err } url := strings.Replace(conf.Clusters[0].ControllerURL, "controller", "docker", 1) // TODO: remove this `set-push-url' call once CI configures DockerPushURL if out, err := flynnCmd("/", "docker", "set-push-url", url).CombinedOutput(); err != nil { return fmt.Errorf("%s: %q", err, out) } if out, err := flynnCmd("/", "docker", "login").CombinedOutput(); err != nil { return fmt.Errorf("%s: %q", err, out) } return nil }