def test_validate_ports_on_network_raise_network(self):
        mock_ports = [models.Port(id="1", network_id="2"), models.Port(id="2", network_id="3")]
        mock_addresses = [models.IPAddress(id="1", network_id="2"), models.IPAddress(id="2", network_id="3")]

        for i, ip_address in enumerate(mock_addresses):
            ip_address.subnet = models.Subnet(id="1", segment_id="2")
            mock_ports[i].ip_addresses.append(ip_address)

        with self.assertRaises(n_exc.BadRequest):
            ip_addresses.validate_and_fetch_segment(mock_ports, "2")
    def test_validate_ports_on_network_raise_segment_multiple_ips(self):
        mock_ports = [models.Port(id="1", network_id="2"), models.Port(id="2", network_id="2")]
        mock_subnets = [models.Subnet(id="1", segment_id="2"), models.Subnet(id="2", segment_id="3")]
        for i, subnet in enumerate(mock_subnets):
            mock_address = models.IPAddress(id="2", network_id="2")
            mock_address.subnet = subnet
            for x in xrange(i + 1):
                mock_ports[x].ip_addresses.append(mock_address)

        with self.assertRaises(n_exc.BadRequest):
            ip_addresses.validate_and_fetch_segment(mock_ports, "2")
Ejemplo n.º 3
0
    def test_validate_ports_on_network_raise_network(self):
        mock_ports = [models.Port(id="1", network_id="2"),
                      models.Port(id="2", network_id="3")]
        mock_addresses = [models.IPAddress(id="1", network_id="2"),
                          models.IPAddress(id="2", network_id="3")]

        for i, ip_address in enumerate(mock_addresses):
            ip_address.subnet = models.Subnet(id="1", segment_id="2")
            mock_ports[i].ip_addresses.append(ip_address)

        with self.assertRaises(n_exc.BadRequest):
            ip_addresses.validate_and_fetch_segment(
                mock_ports, "2")
Ejemplo n.º 4
0
    def test_validate_ports_on_network_raise_segment_multiple_ips(self):
        mock_ports = [models.Port(id="1", network_id="2"),
                      models.Port(id="2", network_id="2")]
        mock_subnets = [models.Subnet(id="1", segment_id="2"),
                        models.Subnet(id="2", segment_id="3")]
        for i, subnet in enumerate(mock_subnets):
            mock_address = models.IPAddress(id="2", network_id="2")
            mock_address.subnet = subnet
            for x in xrange(i + 1):
                mock_ports[x].ip_addresses.append(mock_address)

        with self.assertRaises(n_exc.BadRequest):
            ip_addresses.validate_and_fetch_segment(
                mock_ports, "2")
    def test_validate_ports_on_network_valid(self):
        mock_ports = [models.Port(id="1", network_id="2"), models.Port(id="2", network_id="2")]
        for p in mock_ports:
            p.ip_addresses.append(models.IPAddress(id="1", network_id="2"))
            p.ip_addresses[-1].subnet = models.Subnet(id="1", segment_id="1")

        r = ip_addresses.validate_and_fetch_segment(mock_ports, "2")
        self.assertEqual(r, "1")
Ejemplo n.º 6
0
    def test_validate_ports_on_network_valid(self):
        mock_ports = [models.Port(id="1", network_id="2"),
                      models.Port(id="2", network_id="2")]
        for p in mock_ports:
            p.ip_addresses.append(models.IPAddress(id="1", network_id="2"))
            p.ip_addresses[-1].subnet = models.Subnet(id="1", segment_id="1")

        r = ip_addresses.validate_and_fetch_segment(
            mock_ports, "2")
        self.assertEqual(r, "1")