Example #1
0
func (s *runSuite) TestBlockRunMachineAndService(c *gc.C) {
	// Make three machines.
	s.addMachineWithAddress(c, "10.3.2.1")

	charm := s.AddTestingCharm(c, "dummy")
	owner := s.Factory.MakeUser(c, nil).Tag()
	magic, err := s.State.AddService("magic", owner.String(), charm, nil, nil)
	c.Assert(err, jc.ErrorIsNil)
	s.addUnit(c, magic)
	s.addUnit(c, magic)

	s.mockSSH(c, echoInput)

	// hmm... this seems to be going through the api client, and from there
	// through to the apiserver implementation. Not ideal, but it is how the
	// other client tests are written.
	client := s.APIState.Client()

	// block all changes
	s.BlockAllChanges(c, "TestBlockRunMachineAndService")
	_, err = client.Run(
		params.RunParams{
			Commands: "hostname",
			Timeout:  testing.LongWait,
			Machines: []string{"0"},
			Services: []string{"magic"},
		})
	s.AssertBlocked(c, err, "TestBlockRunMachineAndService")
}
Example #2
0
func (s *runSuite) TestRunMachineAndService(c *gc.C) {
	// Make three machines.
	s.addMachineWithAddress(c, "10.3.2.1")

	charm := s.AddTestingCharm(c, "dummy")
	owner := s.Factory.MakeUser(c, nil).Tag()
	magic, err := s.State.AddService("magic", owner.String(), charm, nil, nil)
	c.Assert(err, jc.ErrorIsNil)
	s.addUnit(c, magic)
	s.addUnit(c, magic)

	s.mockSSH(c, echoInput)

	// hmm... this seems to be going through the api client, and from there
	// through to the apiserver implementation. Not ideal, but it is how the
	// other client tests are written.
	client := s.APIState.Client()
	results, err := client.Run(
		params.RunParams{
			Commands: "hostname",
			Timeout:  testing.LongWait,
			Machines: []string{"0"},
			Services: []string{"magic"},
		})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(results, gc.HasLen, 3)

	expectedResults := []params.RunResult{
		{
			ExecResponse: exec.ExecResponse{Stdout: []byte(expectedCommand[0])},
			MachineId:    "0",
		},
		{
			ExecResponse: exec.ExecResponse{Stdout: []byte(expectedCommand[1])},
			MachineId:    "1",
			UnitId:       "magic/0",
		},
		{
			ExecResponse: exec.ExecResponse{Stdout: []byte(expectedCommand[2])},
			MachineId:    "2",
			UnitId:       "magic/1",
		},
	}

	c.Assert(results, jc.DeepEquals, expectedResults)
}