Example #1
0
    def test_one_pt_prov_cons(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info.return_value = {
            'provider': [{}],
            'consumer': [{}]
        }
        provider, consumer, node = self._create_simple_chain()

        # Verify Service PT created and correctly placed
        prov_cons = {'provider': provider, 'consumer': consumer}
        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
        old_relationship = None
        for target in targets:
            self.assertEqual(node['id'], target.servicechain_node_id)
            pt = self.show_policy_target(
                target.policy_target_id)['policy_target']
            self.assertEqual(prov_cons[target.relationship]['id'],
                             pt['policy_target_group_id'])
            self.assertNotEqual(old_relationship, target.relationship)
            old_relationship = target.relationship

        self.update_policy_target_group(provider['id'],
                                        provided_policy_rule_sets={})
        # With chain deletion, also the Service PTs are deleted
        new_targets = model.get_service_targets(context.session)
        self.assertEqual(0, len(new_targets))
        for target in targets:
            self.show_policy_target(target.policy_target_id,
                                    expected_res_status=404)
    def test_one_pt_prov_cons(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info.return_value = {'provider': [{}],
                                                      'consumer': [{}]}
        provider, consumer, node = self._create_simple_chain()

        # Verify Service PT created and correctly placed
        prov_cons = {'provider': provider, 'consumer': consumer}
        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
        old_relationship = None
        for target in targets:
            self.assertEqual(node['id'], target.servicechain_node_id)
            pt = self.show_policy_target(
                target.policy_target_id)['policy_target']
            self.assertEqual(prov_cons[target.relationship]['id'],
                             pt['policy_target_group_id'])
            self.assertNotEqual(old_relationship, target.relationship)
            old_relationship = target.relationship

        self.update_policy_target_group(
            provider['id'], provided_policy_rule_sets={})
        # With chain deletion, also the Service PTs are deleted
        new_targets = model.get_service_targets(context.session)
        self.assertEqual(0, len(new_targets))
        for target in targets:
            self.show_policy_target(
                target.policy_target_id, expected_res_status=404)
    def test_one_gateway_pt_prov_cons(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info.return_value = {
            'provider': [{}],
            'consumer': [{}],
            'plumbing_type': 'gateway'
        }
        provider, consumer, node = self._create_simple_chain()
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        # Verify Service PT created and correctly placed
        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
        old_relationship = None
        for target in targets:
            self.assertEqual(node['id'], target.servicechain_node_id)
            pt = self.show_policy_target(
                target.policy_target_id)['policy_target']
            if target.relationship == 'provider':
                self.assertEqual(provider['id'], pt['policy_target_group_id'])
                self.assertTrue(pt['group_default_gateway'])
                self.assertFalse(pt['proxy_gateway'])
            else:
                # Consumer side a proxy group exists
                self.assertEqual(provider['proxy_group_id'],
                                 pt['policy_target_group_id'])
                self.assertFalse(pt['group_default_gateway'])
                self.assertTrue(pt['proxy_gateway'])

            self.assertNotEqual(old_relationship, target.relationship)
            old_relationship = target.relationship
            port = self._get_object('ports', pt['port_id'], self.api)['port']
            self.assertTrue(
                port['name'].startswith('pt_service_target_'),
                "Port name doesn't start with 'pt_service_target_"
                "'.\nport:\n%s\n" % port)

        self.update_policy_target_group(provider['id'],
                                        provided_policy_rule_sets={})
        # With chain deletion, also the Service PTs are deleted
        new_targets = model.get_service_targets(context.session)
        self.assertEqual(0, len(new_targets))
        for target in targets:
            self.show_policy_target(target.policy_target_id,
                                    expected_res_status=404)
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        self.assertIsNone(provider['proxy_group_id'])
Example #4
0
def get_node_driver_context(sc_plugin, context, sc_instance,
                            current_node, original_node=None,
                            management_group=None, service_targets=None):
    specs = sc_plugin.get_servicechain_specs(
        context, filters={'id': sc_instance['servicechain_specs']})
    position = _calculate_node_position(specs, current_node['id'])
    provider = _get_ptg_or_ep(context, sc_instance['provider_ptg_id'])
    consumer = _get_ptg_or_ep(context, sc_instance['consumer_ptg_id'])
    current_profile = sc_plugin.get_service_profile(
        context, current_node['service_profile_id'])
    original_profile = sc_plugin.get_service_profile(
        context,
        original_node['service_profile_id']) if original_node else None
    if not service_targets:
        service_targets = model.get_service_targets(
            context.session, servicechain_instance_id=sc_instance['id'],
            position=position, servicechain_node_id=current_node['id'])

    return NodeDriverContext(sc_plugin=sc_plugin,
                             context=context,
                             service_chain_instance=sc_instance,
                             service_chain_specs=specs,
                             current_service_chain_node=current_node,
                             current_service_profile=current_profile,
                             provider_group=provider,
                             consumer_group=consumer,
                             management_group=management_group,
                             original_service_chain_node=original_node,
                             original_service_profile=original_profile,
                             service_targets=service_targets,
                             position=position)
    def test_one_gateway_pt_prov_cons(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info.return_value = {
            'provider': [{}], 'consumer': [{}], 'plumbing_type': 'gateway'}
        provider, consumer, node = self._create_simple_chain()
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        # Verify Service PT created and correctly placed
        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
        old_relationship = None
        for target in targets:
            self.assertEqual(node['id'], target.servicechain_node_id)
            pt = self.show_policy_target(
                target.policy_target_id)['policy_target']
            if target.relationship == 'provider':
                self.assertEqual(provider['id'],
                                 pt['policy_target_group_id'])
                self.assertTrue(pt['group_default_gateway'])
                self.assertFalse(pt['proxy_gateway'])
            else:
                # Consumer side a proxy group exists
                self.assertEqual(provider['proxy_group_id'],
                                 pt['policy_target_group_id'])
                self.assertFalse(pt['group_default_gateway'])
                self.assertTrue(pt['proxy_gateway'])

            self.assertNotEqual(old_relationship, target.relationship)
            old_relationship = target.relationship
            port = self._get_object('ports', pt['port_id'], self.api)['port']
            self.assertTrue(port['name'].startswith('pt_service_target_'),
                            "Port name doesn't start with 'pt_service_target_"
                            "'.\nport:\n%s\n" % port)

        self.update_policy_target_group(
            provider['id'], provided_policy_rule_sets={})
        # With chain deletion, also the Service PTs are deleted
        new_targets = model.get_service_targets(context.session)
        self.assertEqual(0, len(new_targets))
        for target in targets:
            self.show_policy_target(
                target.policy_target_id, expected_res_status=404)
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        self.assertIsNone(provider['proxy_group_id'])
    def test_multiple_endpoint_pt_provider(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info.return_value = {
            'provider': [{}, {}],
            'consumer': [],
            'plumbing_type': 'endpoint'
        }
        provider, consumer, node = self._create_simple_chain()
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        # Verify Service PT created and contains proper name, description
        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
        for target in targets:
            pt = self.show_policy_target(
                target.policy_target_id)['policy_target']
            self.assertEqual(provider['id'], pt['policy_target_group_id'])
            self.assertTrue(
                pt['name'].startswith('tscp_endpoint_service'),
                "Policy Target name doesn't start with "
                "'tscp_endpoint_service'.\npt:\n%s\n" % pt)
            self.assertTrue(
                node['id'] in pt['description'],
                "Policy Target description doesn't contains "
                " node id.\nnode:\n%s\n" % node)

            port = self._get_object('ports', pt['port_id'], self.api)['port']
            self.assertTrue(
                port['name'].startswith('pt_tscp_endpoint_service'),
                "Port name doesn't start with "
                "'pt_tscp_endpoint_service'.\nport:\n%s\n" % port)

        self.update_policy_target_group(provider['id'],
                                        provided_policy_rule_sets={})
        # With chain deletion, also the Service PTs are deleted
        new_targets = model.get_service_targets(context.session)
        self.assertEqual(0, len(new_targets))
        for target in targets:
            self.show_policy_target(target.policy_target_id,
                                    expected_res_status=404)
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        self.assertIsNone(provider['proxy_group_id'])
 def test_pt_override(self):
     context = n_context.get_admin_context()
     test_name = 'test_name'
     self.driver.get_plumbing_info.return_value = {
         'provider': [{'name': test_name}]}
     self._create_simple_chain()
     targets = model.get_service_targets(context.session)
     self.assertEqual(1, len(targets))
     pt = self.show_policy_target(
         targets[0].policy_target_id)['policy_target']
     self.assertEqual(test_name, pt['name'])
 def test_endpoint_target_vif_details(self):
     context = n_context.get_admin_context()
     self._create_simple_service_chain(service_type='LOADBALANCER')
     targets = model.get_service_targets(context.session)
     self.assertTrue(len(targets) > 0)
     for target in targets:
         pt = self.show_policy_target(
             target.policy_target_id)['policy_target']
         # Being service targets, port filter and hybrid plug will be false
         port = self._bind_port_to_host(pt['port_id'], 'host')['port']
         self.assertTrue(port['binding:vif_details']['port_filter'])
         self.assertTrue(port['binding:vif_details']['ovs_hybrid_plug'])
 def test_service_targets_vif_details(self):
     context = n_context.get_admin_context()
     self._create_simple_service_chain(service_type='TRANSPARENT_FIREWALL')
     targets = model.get_service_targets(context.session)
     self.assertTrue(len(targets) > 0)
     for target in targets:
         pt = self.show_policy_target(
             target.policy_target_id)['policy_target']
         # Being service targets, port filter and hybrid plug will be false
         port = self._bind_port_to_host(pt['port_id'], 'host')['port']
         self.assertFalse(port['binding:vif_details']['port_filter'])
         self.assertFalse(port['binding:vif_details']['ovs_hybrid_plug'])
    def test_multiple_endpoint_pt_provider(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info.return_value = {
            'provider': [{}, {}], 'consumer': [], 'plumbing_type': 'endpoint'}
        provider, consumer, node = self._create_simple_chain()
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        # Verify Service PT created and contains proper name, description
        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
        for target in targets:
            pt = self.show_policy_target(
                target.policy_target_id)['policy_target']
            self.assertEqual(provider['id'],
                             pt['policy_target_group_id'])
            self.assertTrue(pt['name'].startswith('tscp_endpoint_service'),
                            "Policy Target name doesn't start with "
                            "'tscp_endpoint_service'.\npt:\n%s\n" % pt)
            self.assertTrue(node['id'] in pt['description'],
                            "Policy Target description doesn't contains "
                            " node id.\nnode:\n%s\n" % node)

            port = self._get_object('ports', pt['port_id'], self.api)['port']
            self.assertTrue(port['name'].startswith(
                            'pt_tscp_endpoint_service'),
                            "Port name doesn't start with "
                            "'pt_tscp_endpoint_service'.\nport:\n%s\n" % port)

        self.update_policy_target_group(
            provider['id'], provided_policy_rule_sets={})
        # With chain deletion, also the Service PTs are deleted
        new_targets = model.get_service_targets(context.session)
        self.assertEqual(0, len(new_targets))
        for target in targets:
            self.show_policy_target(
                target.policy_target_id, expected_res_status=404)
        provider = self.show_policy_target_group(
            provider['id'])['policy_target_group']
        self.assertIsNone(provider['proxy_group_id'])
Example #11
0
 def test_pt_override(self):
     context = n_context.get_admin_context()
     test_name = 'test_name'
     self.driver.get_plumbing_info.return_value = {
         'provider': [{
             'name': test_name
         }]
     }
     self._create_simple_chain()
     targets = model.get_service_targets(context.session)
     self.assertEqual(1, len(targets))
     pt = self.show_policy_target(
         targets[0].policy_target_id)['policy_target']
     self.assertEqual(test_name, pt['name'])
 def test_endpoint_target_vif_details(self):
     context = n_context.get_admin_context()
     self._create_simple_service_chain(service_type='LOADBALANCERV2')
     targets = model.get_service_targets(context.session)
     self.assertTrue(len(targets) > 0)
     for target in targets:
         pt = self.show_policy_target(
             target.policy_target_id)['policy_target']
         port = self._bind_port_to_host(pt['port_id'], 'host')['port']
         self.assertTrue(port['binding:vif_details']['port_filter'])
         # This change sets hybrid VIF plugging to True by default again
         # https://github.com/openstack/neutron/commit/
         # eca893be5b770c41cfc570dc016a41c30c2cdf23
         self.assertTrue(port['binding:vif_details']['ovs_hybrid_plug'])
 def test_endpoint_target_vif_details(self):
     context = n_context.get_admin_context()
     self._create_simple_service_chain(service_type='LOADBALANCERV2')
     targets = model.get_service_targets(context.session)
     self.assertTrue(len(targets) > 0)
     for target in targets:
         pt = self.show_policy_target(
             target.policy_target_id)['policy_target']
         port = self._bind_port_to_host(pt['port_id'], 'host')['port']
         self.assertTrue(port['binding:vif_details']['port_filter'])
         # This change sets hybrid VIF plugging to True by default again
         # https://github.com/openstack/neutron/commit/
         # eca893be5b770c41cfc570dc016a41c30c2cdf23
         self.assertTrue(port['binding:vif_details']['ovs_hybrid_plug'])
    def _delete_service_targets(self, context, part):
        part_context = part['context']
        node = part_context.current_node
        instance = part_context.instance
        gbp_plugin = part_context.gbp_plugin
        pts = model.get_service_targets(
            context.session, servicechain_instance_id=instance['id'],
            servicechain_node_id=node['id'])

        for pt in pts:
            try:
                gbp_plugin.delete_policy_target(
                    context.elevated(), pt.policy_target_id, notify_sc=False)
            except group_policy.PolicyTargetNotFound as ex:
                LOG.debug(ex.message)
Example #15
0
 def get_service_targets(self, update=False):
     """ Returns the service targets assigned for this service if any.
     The result looks like the following:
     {
         "provider": [pt_uuids],
         "consumer": [pt_uuids],
         "management": [pt_uuids],
     }
     """
     if update:
         self._service_targets = model.get_service_targets(
             self.session, servicechain_instance_id=self.instance['id'],
             position=self.current_position,
             servicechain_node_id=self.current_node['id'])
     return self._service_targets
Example #16
0
    def _delete_service_targets(self, context, part):
        part_context = part['context']
        node = part_context.current_node
        instance = part_context.instance
        gbp_plugin = part_context.gbp_plugin
        pts = model.get_service_targets(
            context.session, servicechain_instance_id=instance['id'],
            servicechain_node_id=node['id'])

        for pt in pts:
            try:
                gbp_plugin.delete_policy_target(context, pt.policy_target_id,
                                                notify_sc=False)
            except group_policy.PolicyTargetNotFound as ex:
                LOG.debug(ex.message)
 def test_endpoint_target_vif_details(self):
     context = n_context.get_admin_context()
     self._create_simple_service_chain(service_type='LOADBALANCER')
     targets = model.get_service_targets(context.session)
     self.assertTrue(len(targets) > 0)
     for target in targets:
         pt = self.show_policy_target(
             target.policy_target_id)['policy_target']
         port = self._bind_port_to_host(pt['port_id'], 'host')['port']
         self.assertTrue(port['binding:vif_details']['port_filter'])
         # REVISIT: On account of the following commit:
         # https://git.io/v2czD
         # the hybrid plugging is disabled. Assuming that we are just
         # checking for the default value here, this should be fine. Else we
         # need to revisit.
         self.assertFalse(port['binding:vif_details']['ovs_hybrid_plug'])
 def test_endpoint_target_vif_details(self):
     context = n_context.get_admin_context()
     self._create_simple_service_chain(service_type='LOADBALANCER')
     targets = model.get_service_targets(context.session)
     self.assertTrue(len(targets) > 0)
     for target in targets:
         pt = self.show_policy_target(
             target.policy_target_id)['policy_target']
         port = self._bind_port_to_host(pt['port_id'], 'host')['port']
         self.assertTrue(port['binding:vif_details']['port_filter'])
         # REVISIT: On account of the following commit:
         # https://git.io/v2czD
         # the hybrid plugging is disabled. Assuming that we are just
         # checking for the default value here, this should be fine. Else we
         # need to revisit.
         self.assertFalse(port['binding:vif_details']['ovs_hybrid_plug'])
Example #19
0
def get_node_driver_context(sc_plugin,
                            context,
                            sc_instance,
                            current_node,
                            original_node=None,
                            management_group=None,
                            service_targets=None):
    admin_context = utils.admin_context(context)
    specs = sc_plugin.get_servicechain_specs(
        admin_context, filters={'id': sc_instance['servicechain_specs']})
    position = _calculate_node_position(specs, current_node['id'])
    provider, _ = _get_ptg_or_ep(admin_context, sc_instance['provider_ptg_id'])
    consumer, is_consumer_external = _get_ptg_or_ep(
        admin_context, sc_instance['consumer_ptg_id'])
    management, _ = _get_ptg_or_ep(admin_context,
                                   sc_instance['management_ptg_id'])
    classifier = get_gbp_plugin().get_policy_classifier(
        admin_context, sc_instance['classifier_id'])
    current_profile = sc_plugin.get_service_profile(
        admin_context, current_node['service_profile_id'])
    original_profile = sc_plugin.get_service_profile(
        admin_context,
        original_node['service_profile_id']) if original_node else None
    if not service_targets:
        service_targets = model.get_service_targets(
            admin_context.session,
            servicechain_instance_id=sc_instance['id'],
            position=position,
            servicechain_node_id=current_node['id'])

    return NodeDriverContext(sc_plugin=sc_plugin,
                             context=context,
                             service_chain_instance=sc_instance,
                             service_chain_specs=specs,
                             current_service_chain_node=current_node,
                             current_service_profile=current_profile,
                             provider_group=provider,
                             consumer_group=consumer,
                             management_group=management,
                             original_service_chain_node=original_node,
                             original_service_profile=original_profile,
                             service_targets=service_targets,
                             position=position,
                             classifier=classifier,
                             is_consumer_external=is_consumer_external)
    def test_get_service_targets_in_chain(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info = self.get_plumbing_info_base
        lb_prof = self._create_service_profile(
            service_type='LOADBALANCER',
            vendor=self.SERVICE_PROFILE_VENDOR)['service_profile']
        lb_node = self.create_servicechain_node(
            service_profile_id=lb_prof['id'],
            config=self.DEFAULT_LB_CONFIG)['servicechain_node']
        fw_prof = self._create_service_profile(
            service_type='FIREWALL',
            vendor=self.SERVICE_PROFILE_VENDOR)['service_profile']
        fw_node = self.create_servicechain_node(
            service_profile_id=fw_prof['id'], config='{}')['servicechain_node']

        self._create_chain_with_nodes([fw_node['id'], lb_node['id']])

        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
    def test_get_service_targets_in_chain(self):
        context = n_context.get_admin_context()
        self.driver.get_plumbing_info = self.get_plumbing_info_base
        lb_prof = self._create_service_profile(
            service_type='LOADBALANCER',
            vendor=self.SERVICE_PROFILE_VENDOR)['service_profile']
        lb_node = self.create_servicechain_node(
            service_profile_id=lb_prof['id'],
            config=self.DEFAULT_LB_CONFIG)['servicechain_node']
        fw_prof = self._create_service_profile(
            service_type='FIREWALL',
            vendor=self.SERVICE_PROFILE_VENDOR)['service_profile']
        fw_node = self.create_servicechain_node(
            service_profile_id=fw_prof['id'],
            config='{}')['servicechain_node']

        self._create_chain_with_nodes([fw_node['id'], lb_node['id']])

        targets = model.get_service_targets(context.session)
        self.assertEqual(2, len(targets))
def get_node_driver_context(sc_plugin, context, sc_instance,
                            current_node, original_node=None,
                            management_group=None, service_targets=None):
    admin_context = utils.admin_context(context)
    specs = sc_plugin.get_servicechain_specs(
        admin_context, filters={'id': sc_instance['servicechain_specs']})
    position = _calculate_node_position(specs, current_node['id'])
    provider, _ = _get_ptg_or_ep(
        admin_context, sc_instance['provider_ptg_id'])
    consumer, is_consumer_external = _get_ptg_or_ep(
        admin_context, sc_instance['consumer_ptg_id'])
    management, _ = _get_ptg_or_ep(admin_context,
                                   sc_instance['management_ptg_id'])
    classifier = get_gbp_plugin().get_policy_classifier(
        admin_context, sc_instance['classifier_id'])
    current_profile = sc_plugin.get_service_profile(
        admin_context, current_node['service_profile_id'])
    original_profile = sc_plugin.get_service_profile(
        admin_context,
        original_node['service_profile_id']) if original_node else None
    if not service_targets:
        service_targets = model.get_service_targets(
            admin_context.session, servicechain_instance_id=sc_instance['id'],
            position=position, servicechain_node_id=current_node['id'])

    return NodeDriverContext(sc_plugin=sc_plugin,
                             context=context,
                             service_chain_instance=sc_instance,
                             service_chain_specs=specs,
                             current_service_chain_node=current_node,
                             current_service_profile=current_profile,
                             provider_group=provider,
                             consumer_group=consumer,
                             management_group=management,
                             original_service_chain_node=original_node,
                             original_service_profile=original_profile,
                             service_targets=service_targets,
                             position=position,
                             classifier=classifier,
                             is_consumer_external=is_consumer_external)
 def _sc_head_gateway_node_service_targets(self, context, service_type,
                                           relationships):
     current_specs = context.relevant_specs
     service_targets = []
     for spec in current_specs:
         filters = {'id': spec['nodes']}
         nodes = context.sc_plugin.get_servicechain_nodes(
             context.plugin_context, filters)
         for node in nodes:
             profile = context.sc_plugin.get_service_profile(
                 context.plugin_context, node['service_profile_id'])
             if (profile['service_type'] != service_type
                     and profile['service_type'] in GATEWAY_PLUMBER_TYPE):
                 for relationship in relationships:
                     service_targets.extend(
                         ncp_model.get_service_targets(
                             context.session,
                             servicechain_instance_id=context.
                             instance['id'],
                             servicechain_node_id=node['id'],
                             relationship=relationship))
     return service_targets