Beispiel #1
0
func (s *PortsDocSuite) TestRemovePortsDoc(c *gc.C) {
	portRange := state.PortRange{
		FromPort: 100,
		ToPort:   200,
		UnitName: s.unit1.Name(),
		Protocol: "TCP",
	}
	err := s.ports.OpenPorts(portRange)
	c.Assert(err, gc.IsNil)

	ports, err := state.GetPorts(s.State, s.machine.Id(), network.DefaultPublic)
	c.Assert(err, gc.IsNil)
	c.Assert(ports, gc.NotNil)

	allPorts, err := s.machine.AllPorts()
	c.Assert(err, gc.IsNil)

	for _, prt := range allPorts {
		err := prt.Remove()
		c.Assert(err, gc.IsNil)
	}

	ports, err = state.GetPorts(s.State, s.machine.Id(), network.DefaultPublic)
	c.Assert(ports, gc.IsNil)
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
	c.Assert(err, gc.ErrorMatches, `ports for machine 0, network "juju-public" not found`)
}
Beispiel #2
0
func (s *PortsDocSuite) TestRemovePortsDoc(c *gc.C) {
	portRange := state.PortRange{
		FromPort: 100,
		ToPort:   200,
		UnitName: s.unit.Name(),
		Protocol: "TCP",
	}
	err := s.ports.OpenPorts(portRange)
	c.Assert(err, gc.IsNil)

	ports, err := state.GetPorts(s.State, s.machine.Id())
	c.Assert(err, gc.IsNil)
	c.Assert(ports, gc.NotNil)

	allPorts, err := s.machine.OpenedPorts(s.State)
	c.Assert(err, gc.IsNil)

	for _, prt := range allPorts {
		err := prt.Remove()
		c.Assert(err, gc.IsNil)
	}

	ports, err = state.GetPorts(s.State, s.machine.Id())
	c.Assert(ports, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "ports document for machine .* not found")
}
Beispiel #3
0
func (s *PortsDocSuite) TestRemovePortsDoc(c *gc.C) {
	portRange := state.PortRange{
		FromPort: 100,
		ToPort:   200,
		UnitName: s.unit1.Name(),
		Protocol: "TCP",
	}
	err := s.portsOnSubnet.OpenPorts(portRange)
	c.Assert(err, jc.ErrorIsNil)

	ports, err := state.GetPorts(s.State, s.machine.Id(), s.subnet.CIDR())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ports, gc.NotNil)

	allPorts, err := s.machine.AllPorts()
	c.Assert(err, jc.ErrorIsNil)

	for _, prt := range allPorts {
		err := prt.Remove()
		c.Assert(err, jc.ErrorIsNil)
	}

	ports, err = state.GetPorts(s.State, s.machine.Id(), s.subnet.CIDR())
	c.Assert(ports, gc.IsNil)
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
	c.Assert(err, gc.ErrorMatches, `ports for machine "0", subnet "0.1.2.0/24" not found`)
}
Beispiel #4
0
func (s *PortsDocSuite) TestCreatePorts(c *gc.C) {
	ports, err := state.GetOrCreatePorts(s.State, s.machine.Id(), network.DefaultPublic)
	c.Assert(err, gc.IsNil)
	c.Assert(ports, gc.NotNil)
	err = ports.OpenPorts(state.PortRange{
		FromPort: 100,
		ToPort:   200,
		UnitName: s.unit1.Name(),
		Protocol: "TCP",
	})
	c.Assert(err, gc.IsNil)

	ports, err = state.GetPorts(s.State, s.machine.Id(), network.DefaultPublic)
	c.Assert(err, gc.IsNil)
	c.Assert(ports, gc.NotNil)

	c.Assert(ports.PortsForUnit(s.unit1.Name()), gc.HasLen, 1)
}
Beispiel #5
0
func (s *PortsDocSuite) testCreatePortsWithSubnetID(c *gc.C, subnetID string) {
	ports, err := state.GetOrCreatePorts(s.State, s.machine.Id(), subnetID)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ports, gc.NotNil)
	err = ports.OpenPorts(state.PortRange{
		FromPort: 100,
		ToPort:   200,
		UnitName: s.unit1.Name(),
		Protocol: "TCP",
	})
	c.Assert(err, jc.ErrorIsNil)

	ports, err = state.GetPorts(s.State, s.machine.Id(), subnetID)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ports, gc.NotNil)

	c.Assert(ports.PortsForUnit(s.unit1.Name()), gc.HasLen, 1)
}