Example #1
0
func processMachine(machine *state.Machine, instance environs.Instance) (map[string]interface{}, error) {
	r := m()
	r["instance-id"] = instance.Id()

	if dnsname, err := instance.DNSName(); err == nil {
		r["dns-name"] = dnsname
	}

	processVersion(r, machine)
	processAgentStatus(r, machine)

	// TODO(dfc) unit-status
	return r, nil
}
Example #2
0
// assertInstanceId asserts that the machine has an instance id
// that matches that of the given instance. If the instance is nil,
// It asserts that the instance id is unset.
func assertInstanceId(c *C, m *state.Machine, inst environs.Instance) {
	var wantId, gotId state.InstanceId
	var err error
	if inst != nil {
		wantId = inst.Id()
	}
	for a := waitAgent.Start(); a.Next(); {
		err := m.Refresh()
		c.Assert(err, IsNil)
		gotId, err = m.InstanceId()
		if state.IsNotFound(err) {
			if inst == nil {
				return
			}
			continue
		}
		c.Assert(err, IsNil)
		break
	}
	c.Assert(err, IsNil)
	c.Assert(gotId, Equals, wantId)
}
Example #3
0
// assertPorts retrieves the open ports of the instance and compares them
// to the expected.
func (s *FirewallerSuite) assertPorts(c *C, inst environs.Instance, machineId string, expected []state.Port) {
	s.State.StartSync()
	start := time.Now()
	for {
		got, err := inst.Ports(machineId)
		if err != nil {
			c.Fatal(err)
			return
		}
		state.SortPorts(got)
		state.SortPorts(expected)
		if reflect.DeepEqual(got, expected) {
			c.Succeed()
			return
		}
		if time.Since(start) > 5*time.Second {
			c.Fatalf("timed out: expected %q; got %q", expected, got)
			return
		}
		time.Sleep(50 * time.Millisecond)
	}
	panic("unreachable")
}
Example #4
0
// checkInstanceIdSet checks that the machine has an instance id
// that matches that of the given instance. If the instance is nil,
// It checks that the instance id is unset.
func (s *ProvisionerSuite) checkInstanceId(c *C, m *state.Machine, inst environs.Instance) {
	// TODO(dfc) add machine.Watch() to avoid having to poll.
	s.State.StartSync()
	var instId state.InstanceId
	if inst != nil {
		instId = inst.Id()
	}
	for a := veryShortAttempt.Start(); a.Next(); {
		err := m.Refresh()
		c.Assert(err, IsNil)
		_, err = m.InstanceId()
		if state.IsNotFound(err) {
			if inst == nil {
				return
			}
			continue
		}
		c.Assert(err, IsNil)
		break
	}
	id, err := m.InstanceId()
	c.Assert(err, IsNil)
	c.Assert(id, Equals, instId)
}