Esempio n. 1
0
    def test_gather_sg_ports(self):
        """Checking if gather ports works as designed. """
        cidr = "192.168.1.0/24"
        network = dict(id='1',
                       name="public",
                       tenant_id="make",
                       network_plugin="BASE",
                       ipam_strategy="ANY")
        network = {"network": network}
        subnet_v4 = dict(id='1', ip_version=4, cidr=cidr, tenant_id="fake")
        subnet_v4_info = {"subnet": subnet_v4}

        with self._stubs(network, subnet_v4_info) as (net, sub_v4, update):
            port1 = port_api.create_port(self.context, self._make_body(net))
            self.assertIsNotNone(port1)
            port2 = port_api.create_port(self.context, self._make_body(net))
            self.assertIsNotNone(port2)

            sg_body = dict(tenant_id="derp",
                           name="test sg",
                           description="none")
            sg_body = dict(security_group=sg_body)

            sg = sg_api.create_security_group(self.context, sg_body)
            self.assertIsNotNone(sg)
            sgid = sg['id']
            self.assertIsNotNone(sgid)

            assoc_ports = self._get_assoc_ports(sgid)
            self.assertEqual(0, len(assoc_ports))

            port_body = {'security_groups': [sgid]}
            port_body = dict(port=port_body)

            port1 = port_api.update_port(self.context, port1['id'], port_body)
            self.assertIsNotNone(port1)

            assoc_ports = self._get_assoc_ports(sgid)
            self.assertEqual(1, len(assoc_ports))

            # NOTE: this is duplicated because update_port modifies the params
            port_body = {'security_groups': [sgid]}
            port_body = dict(port=port_body)

            port2 = port_api.update_port(self.context, port2['id'], port_body)
            self.assertIsNotNone(port2)

            assoc_ports = self._get_assoc_ports(sgid)
            self.assertEqual(2, len(assoc_ports))
Esempio n. 2
0
    def test_update_port_multiple_fixed_ipv4(self):
        with self._stubs(self.net_info, self.sub_info) as (network, subnet):
            fixed_ips = [dict(subnet_id=subnet['id'], enabled=True,
                         ip_address="192.168.10.45"),
                         dict(subnet_id=subnet['id'], enabled=True,
                         ip_address="192.168.10.199")]
            port = dict(port=dict(network_id=network['id'],
                                  tenant_id=self.context.tenant_id,
                                  device_id=2,
                                  fixed_ips=fixed_ips))
            expected = {'status': "ACTIVE",
                        'device_owner': None,
                        'network_id': network["id"],
                        'tenant_id': self.context.tenant_id,
                        'admin_state_up': True,
                        'fixed_ips': fixed_ips,
                        'device_id': '2'}
            result = port_api.create_port(self.context, port)

            fixed_ips = [dict(subnet_id=subnet['id'], enabled=True,
                         ip_address="192.168.10.236"),
                         dict(subnet_id=subnet['id'], enabled=True,
                         ip_address="192.168.10.42")]
            new_port = dict(port=dict(fixed_ips=fixed_ips))
            result = port_api.update_port(self.context, result['id'], new_port)
            for key in expected.keys():
                if key != 'fixed_ips':
                    self.assertEqual(result[key], expected[key],
                                     "Mismatch on %s" % key)
            for ip in result['fixed_ips']:
                self.assertTrue(ip in fixed_ips,
                                '%s not in %s' % (ip, expected['fixed_ips']))
Esempio n. 3
0
    def test_gather_sg_ports(self):
        """Checking if gather ports works as designed. """
        cidr = "192.168.1.0/24"
        network = dict(id='1', name="public", tenant_id="make",
                       network_plugin="BASE",
                       ipam_strategy="ANY")
        network = {"network": network}
        subnet_v4 = dict(id='1', ip_version=4, cidr=cidr,
                         tenant_id="fake")
        subnet_v4_info = {"subnet": subnet_v4}

        with self._stubs(network, subnet_v4_info) as (net, sub_v4, update):
            port1 = port_api.create_port(self.context, self._make_body(net))
            self.assertIsNotNone(port1)
            port2 = port_api.create_port(self.context, self._make_body(net))
            self.assertIsNotNone(port2)

            sg_body = dict(tenant_id="derp", name="test sg",
                           description="none")
            sg_body = dict(security_group=sg_body)

            sg = sg_api.create_security_group(self.context, sg_body)
            self.assertIsNotNone(sg)
            sgid = sg['id']
            self.assertIsNotNone(sgid)

            assoc_ports = self._get_assoc_ports(sgid)
            self.assertEqual(0, len(assoc_ports))

            port_body = {'security_groups': [sgid]}
            port_body = dict(port=port_body)

            port1 = port_api.update_port(self.context, port1['id'], port_body)
            self.assertIsNotNone(port1)

            assoc_ports = self._get_assoc_ports(sgid)
            self.assertEqual(1, len(assoc_ports))

            # NOTE: this is duplicated because update_port modifies the params
            port_body = {'security_groups': [sgid]}
            port_body = dict(port=port_body)

            port2 = port_api.update_port(self.context, port2['id'], port_body)
            self.assertIsNotNone(port2)

            assoc_ports = self._get_assoc_ports(sgid)
            self.assertEqual(2, len(assoc_ports))
Esempio n. 4
0
    def test_env_caps_off_sg_async_update(self):
        """This test ensures that envcaps off works as designed."""
        env_set = [
            env.Capabilities.SECURITY_GROUPS,
            env.Capabilities.TENANT_NETWORK_SG,
            env.Capabilities.EGRESS,
        ]
        override = ','.join(env_set)
        old_override = cfg.CONF.QUARK.environment_capabilities
        cfg.CONF.set_override("environment_capabilities", override, "QUARK")
        cidr = "192.168.1.0/24"
        network = dict(id='1',
                       name="public",
                       tenant_id="make",
                       network_plugin="BASE",
                       ipam_strategy="ANY")
        network = {"network": network}
        subnet_v4 = dict(id='1', ip_version=4, cidr=cidr, tenant_id="fake")
        subnet_v4_info = {"subnet": subnet_v4}

        try:
            with self._stubs(network, subnet_v4_info) as (net, sub_v4, update):
                port1 = port_api.create_port(self.context,
                                             self._make_body(net))
                self.assertIsNotNone(port1)

                sg_body = dict(tenant_id="derp",
                               name="test sg",
                               description="none")
                sg_body = dict(security_group=sg_body)

                sg = sg_api.create_security_group(self.context, sg_body)
                self.assertIsNotNone(sg)
                sgid = sg['id']
                self.assertIsNotNone(sgid)

                port_body = {'security_groups': [sgid]}
                port_body = dict(port=port_body)

                port1 = port_api.update_port(self.context, port1['id'],
                                             port_body)
                self.assertIsNotNone(port1)

                sgr_body = {
                    'protocol': 'tcp',
                    'security_group_id': sgid,
                    'tenant_id': "derp",
                    'direction': 'ingress'
                }
                sgr_body = dict(security_group_rule=sgr_body)
                sgr = sg_api.create_security_group_rule(self.context, sgr_body)
                self.assertIsNotNone(sgr)
                self.assertFalse(update.called)
        finally:
            cfg.CONF.set_override("environment_capabilities", old_override,
                                  "QUARK")
Esempio n. 5
0
    def test_env_caps_on_sg_async_update(self):
        """This test ensures that envcaps on works as designed."""
        env_set = [
            env.Capabilities.SECURITY_GROUPS,
            env.Capabilities.TENANT_NETWORK_SG,
            env.Capabilities.EGRESS,
            env.Capabilities.SG_UPDATE_ASYNC
        ]
        override = ','.join(env_set)
        old_override = cfg.CONF.QUARK.environment_capabilities
        cfg.CONF.set_override("environment_capabilities",
                              override,
                              "QUARK")
        cidr = "192.168.1.0/24"
        network = dict(id='1', name="public", tenant_id="make",
                       network_plugin="BASE",
                       ipam_strategy="ANY")
        network = {"network": network}
        subnet_v4 = dict(id='1', ip_version=4, cidr=cidr,
                         tenant_id="fake")
        subnet_v4_info = {"subnet": subnet_v4}

        try:
            with self._stubs(network, subnet_v4_info) as (net, sub_v4, update):
                port1 = port_api.create_port(
                    self.context, self._make_body(net))
                self.assertIsNotNone(port1)

                sg_body = dict(tenant_id="derp", name="test sg",
                               description="none")
                sg_body = dict(security_group=sg_body)

                sg = sg_api.create_security_group(self.context, sg_body)
                self.assertIsNotNone(sg)
                sgid = sg['id']
                self.assertIsNotNone(sgid)

                port_body = {'security_groups': [sgid]}
                port_body = dict(port=port_body)

                port1 = port_api.update_port(self.context, port1['id'],
                                             port_body)

                sgr_body = {'protocol': 'tcp', 'security_group_id': sgid,
                            'tenant_id': "derp",
                            'direction': 'ingress'}
                sgr_body = dict(security_group_rule=sgr_body)
                sgr = sg_api.create_security_group_rule(self.context, sgr_body)
                self.assertIsNotNone(sgr)
                self.assertTrue(update.called)
        finally:
            cfg.CONF.set_override("environment_capabilities",
                                  old_override,
                                  "QUARK")
Esempio n. 6
0
    def test_update_fixed_ips_regression_RM9097(self):
        cidr = "192.168.1.0/24"
        ip_network = netaddr.IPNetwork(cidr)
        network = dict(name="public", tenant_id="fake", network_plugin="BASE")
        network = {"network": network}
        subnet = dict(id=1,
                      ip_version=4,
                      next_auto_assign_ip=2,
                      cidr=cidr,
                      first_ip=ip_network.first,
                      last_ip=ip_network.last,
                      ip_policy=None,
                      tenant_id="fake")
        subnet = {"subnet": subnet}
        port = {"port": dict()}

        def _make_body(ip):
            fix_ip = dict(ip_address=ip, subnet_id=sub['id'])
            port_info = {"port": dict(fixed_ips=[fix_ip])}
            return port_info

        with self._stubs(network, subnet, port) as (net, sub, port):
            id = port['id']

            ip = "192.168.1.50"
            port = port_api.update_port(self.context, id, _make_body(ip))
            self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])

            with self.assertRaises(exceptions.IPAddressNotInSubnet):
                ip = "192.168.2.50"
                port = port_api.update_port(self.context, id, _make_body(ip))
                self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])

            ip = "192.168.1.75"
            port = port_api.update_port(self.context, id, _make_body(ip))
            self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])

            ip = "192.168.1.50"
            port = port_api.update_port(self.context, id, _make_body(ip))
            self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])
Esempio n. 7
0
    def test_update_fixed_ips_regression_RM9097(self):
        cidr = "192.168.1.0/24"
        ip_network = netaddr.IPNetwork(cidr)
        network = dict(name="public", tenant_id="fake", network_plugin="BASE")
        network = {"network": network}
        subnet = dict(id=1, ip_version=4, next_auto_assign_ip=2,
                      cidr=cidr, first_ip=ip_network.first,
                      last_ip=ip_network.last, ip_policy=None,
                      tenant_id="fake")
        subnet = {"subnet": subnet}
        port = {"port": dict()}

        def _make_body(ip):
            fix_ip = dict(ip_address=ip, subnet_id=sub['id'])
            port_info = {"port": dict(fixed_ips=[fix_ip])}
            return port_info

        with self._stubs(network, subnet, port) as (net, sub, port):
            id = port['id']

            ip = "192.168.1.50"
            port = port_api.update_port(self.context, id, _make_body(ip))
            self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])

            with self.assertRaises(exceptions.IPAddressNotInSubnet):
                ip = "192.168.2.50"
                port = port_api.update_port(self.context, id, _make_body(ip))
                self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])

            ip = "192.168.1.75"
            port = port_api.update_port(self.context, id, _make_body(ip))
            self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])

            ip = "192.168.1.50"
            port = port_api.update_port(self.context, id, _make_body(ip))
            self.assertEqual(ip, port['fixed_ips'][0]['ip_address'])
Esempio n. 8
0
    def test_update_port_multiple_fixed_ipv4(self):
        with self._stubs(self.net_info, self.sub_info) as (network, subnet):
            fixed_ips = [
                dict(subnet_id=subnet['id'],
                     enabled=True,
                     ip_address="192.168.10.45"),
                dict(subnet_id=subnet['id'],
                     enabled=True,
                     ip_address="192.168.10.199")
            ]
            port = dict(port=dict(network_id=network['id'],
                                  tenant_id=self.context.tenant_id,
                                  device_id=2,
                                  fixed_ips=fixed_ips))
            expected = {
                'status': "ACTIVE",
                'device_owner': None,
                'network_id': network["id"],
                'tenant_id': self.context.tenant_id,
                'admin_state_up': True,
                'fixed_ips': fixed_ips,
                'device_id': '2'
            }
            result = port_api.create_port(self.context, port)

            fixed_ips = [
                dict(subnet_id=subnet['id'],
                     enabled=True,
                     ip_address="192.168.10.236"),
                dict(subnet_id=subnet['id'],
                     enabled=True,
                     ip_address="192.168.10.42")
            ]
            new_port = dict(port=dict(fixed_ips=fixed_ips))
            result = port_api.update_port(self.context, result['id'], new_port)
            for key in expected.keys():
                if key != 'fixed_ips':
                    self.assertEqual(result[key], expected[key],
                                     "Mismatch on %s" % key)
            for ip in result['fixed_ips']:
                self.assertTrue(ip in fixed_ips,
                                '%s not in %s' % (ip, expected['fixed_ips']))
Esempio n. 9
0
 def update_port(self, context, id, port):
     return ports.update_port(context, id, port)
Esempio n. 10
0
 def update_port(self, context, id, port):
     return ports.update_port(context, id, port)