Пример #1
0
    def test_si_without_valid_annotations(self):
        si_fqn = ['default-domain', 'default-project', 'si-' + self.id()]
        si_obj = ServiceInstance(fq_name=si_fqn)
        si_obj.fq_name = si_fqn
        si_obj.add_service_template(self.st_obj)
        kvp_array = []
        kvp = KeyValuePair("left-svc-vlan", "100")
        kvp_array.append(kvp)
        kvp = KeyValuePair("right-svc-vlan", "101")
        kvp_array.append(kvp)
        kvp = KeyValuePair("left-svc-asns", "66000,66001")
        kvp_array.append(kvp)
        # The below line is intentionllly commented out..
        # kvp = KeyValuePair("right-svc-asns", "66000,66002")
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        si_obj.set_annotations(kvps)
        props = ServiceInstanceType()
        props.set_service_virtualization_type('physical-device')
        props.set_ha_mode("active-standby")
        si_obj.set_service_instance_properties(props)

        # right-svc-asns missing, raise error
        self.assertRaises(BadRequest, self.api.service_instance_create, si_obj)
    def _create_kv_pairs(self, pi_fq_name, fabric_name, vpg_name,
                         tor_port_vlan_id=0):
        # Populate binding profile to be used in VMI create
        binding_profile = {'local_link_information': [
            {'port_id': pi_fq_name[2],
             'switch_id': pi_fq_name[2],
             'fabric': fabric_name[-1],
             'switch_info': pi_fq_name[1]}]}

        if tor_port_vlan_id != 0:
            kv_pairs = KeyValuePairs(
                [KeyValuePair(key='vpg', value=vpg_name[-1]),
                 KeyValuePair(key='vif_type', value='vrouter'),
                 KeyValuePair(key='tor_port_vlan_id', value=tor_port_vlan_id),
                 KeyValuePair(key='vnic_type', value='baremetal'),
                 KeyValuePair(key='profile',
                              value=json.dumps(binding_profile))])
        else:
            kv_pairs = KeyValuePairs(
                [KeyValuePair(key='vpg', value=vpg_name[-1]),
                 KeyValuePair(key='vif_type', value='vrouter'),
                 KeyValuePair(key='vnic_type', value='baremetal'),
                 KeyValuePair(key='profile',
                              value=json.dumps(binding_profile))])

        return kv_pairs
 def test_hbs_create_with_annotations(self):
     project2 = Project('project2-%s' % self.id())
     project2.set_quota(QuotaType(host_based_service=1))
     self.api.project_create(project2)
     vn1 = VirtualNetwork('vn1-%s' % self.id(), parent_obj=project2)
     self.api.virtual_network_create(vn1)
     hbs1 = HostBasedService('hbs1-%s' % self.id(), parent_obj=project2)
     hbs1.add_annotations(KeyValuePair(
         key='image', value='hub.juniper.net/security/csrx:19.2R1.8'))
     hbs1.add_annotations(KeyValuePair(key='imagePullSecrets', value='psd'))
     self.api.host_based_service_create(hbs1)
    def test_add_virtual_router(self):
        name = "localhost-%s" % self.id()
        physnet_mapping = {"physnet1": "eth0", "physnet2": "eth1"}
        prov_args = [
            "--host_ip 127.0.0.1",
            "--host_name %s" % name,
            "--ip_fabric_subnet 10.1.1.0/28",
            "--api_server_ip %s" % self._server_info['ip'],
            "--api_server_port %s" % self._server_info['service_port'],
            "--sriov_physnets %s" % ' '.join(
                [k + '=' + v for k, v in physnet_mapping.items()]),
        ]

        provision_vrouter.VrouterProvisioner(args_str=' '.join(prov_args))

        fq_name = ['default-global-system-config', name]
        vrouter_obj = self.api.virtual_router_read(fq_name)
        physnets = (vrouter_obj.get_virtual_router_sriov_physical_networks() or
                    KeyValuePairs())
        physnet_kvps = physnets.get_key_value_pair() or []
        for physnet, interface in physnet_mapping.items():
            kvp = KeyValuePair(key=physnet, value=interface)
            assert kvp in physnet_kvps,\
                "(%s) kv pair not found in physnet kvps (%s)" % (
                    kvp, physnet_kvps)
Пример #5
0
 def _create_kv_pairs(self, fabric_name, pi_fq_name):
     binding_profile = {'local_link_information': []}
     binding_profile['local_link_information'].append({
         'port_id':
         pi_fq_name[2],
         'switch_id':
         pi_fq_name[2],
         'fabric':
         fabric_name[-1],
         'switch_info':
         pi_fq_name[1]
     })
     kv_pairs = KeyValuePairs([
         KeyValuePair(key='vif_type', value='vrouter'),
         KeyValuePair(key='vnic_type', value='baremetal'),
         KeyValuePair(key='profile', value=json.dumps(binding_profile))
     ])
     return kv_pairs
    def _check_lb_members(self, *members):
        lb_pool = self._vnc_lib.loadbalancer_pool_read(
            id=self.pool_uid,
            fields=('loadbalancer-pool-loadbalancer-member', ))
        lb_members = lb_pool.get_loadbalancer_members() or ()

        self.assertEqual(len(lb_members), len(members))
        lb_members = [
            self._vnc_lib.loadbalancer_member_read(id=member['uuid'])
            for member in lb_members
        ]
        member_annotations = [member.annotations for member in lb_members]

        for vm_uid, vmi_uid in members:
            self.assertIn(
                KeyValuePairs(
                    [KeyValuePair('vm', vm_uid),
                     KeyValuePair('vmi', vmi_uid)]), member_annotations)
Пример #7
0
def set_job_transaction(device_obj, vnc_api, trans_info):
    trans_val = json.dumps(trans_info)
    annotations = device_obj.get_annotations()
    if not annotations:
        annotations = KeyValuePairs()
    annotations.add_key_value_pair(
        KeyValuePair(key='job_transaction', value=trans_val))
    device_obj.set_annotations(annotations)
    if vnc_api:
        vnc_api.physical_router_update(device_obj)
Пример #8
0
    def create_vmi_bindings(self,
                            pi_fq_name,
                            fabric_name,
                            vpg_name,
                            tor_port_vlan_id=0):
        # Populate binding profile to be used in VMI create
        binding_profile = {'local_link_information': []}
        if isinstance(pi_fq_name[0], type([])):
            for pi_name in pi_fq_name:
                binding_profile['local_link_information'].append({
                    'port_id':
                    pi_name[2],
                    'switch_id':
                    pi_name[2],
                    'fabric':
                    fabric_name[-1],
                    'switch_info':
                    pi_name[1]
                })
        else:
            binding_profile['local_link_information'].append({
                'port_id':
                pi_fq_name[2],
                'switch_id':
                pi_fq_name[2],
                'fabric':
                fabric_name[-1],
                'switch_info':
                pi_fq_name[1]
            })

        if tor_port_vlan_id != 0:
            kv_pairs = KeyValuePairs([
                KeyValuePair(key='vpg', value=vpg_name[-1]),
                KeyValuePair(key='vif_type', value='vrouter'),
                KeyValuePair(key='tor_port_vlan_id', value=tor_port_vlan_id),
                KeyValuePair(key='vnic_type', value='baremetal'),
                KeyValuePair(key='profile', value=json.dumps(binding_profile))
            ])
        else:
            kv_pairs = KeyValuePairs([
                KeyValuePair(key='vpg', value=vpg_name[-1]),
                KeyValuePair(key='vif_type', value='vrouter'),
                KeyValuePair(key='vnic_type', value='baremetal'),
                KeyValuePair(key='profile', value=json.dumps(binding_profile))
            ])

        return kv_pairs
    def test_get_hbs_template_no_json(self):
        project2 = Project('project2-%s' % self.id())
        project2.set_quota(QuotaType(host_based_service=1))

        kvp_array = []
        kvp = KeyValuePair("namespace", "k8test")
        kvp_array.append(kvp)
        kvp = KeyValuePair("cluster", "c1")
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)

        project2.set_annotations(kvps)

        self.api.project_create(project2)
        hbs = HostBasedService('hbs-%s' % self.id(), parent_obj=project2)
        self.api.host_based_service_create(hbs)

        (code, msg) = self._http_post('/hbs-get', None)
        self.assertEquals(code, 400)
Пример #10
0
 def test_more_than_one_sas_per_st(self):
     si_obj = self.api.service_instance_read(id=self.si_uuid)
     left_lr_obj = self.api.logical_router_read(id=self.left_lr_uuid)
     right_lr_obj = self.api.logical_router_read(id=self.right_lr_uuid)
     pt_obj = PortTuple('pt-' + self.id(), parent_obj=si_obj)
     pt_obj.add_logical_router(left_lr_obj)
     pt_obj.add_logical_router(right_lr_obj)
     kvp_array = []
     kvp = KeyValuePair("left-lr", self.left_lr_uuid)
     kvp_array.append(kvp)
     kvp = KeyValuePair("right-lr", self.right_lr_uuid)
     kvp_array.append(kvp)
     kvps = KeyValuePairs()
     kvps.set_key_value_pair(kvp_array)
     pt_obj.set_annotations(kvps)
     # Add another SAS to the ST
     gsc_obj = self.api.global_system_config_read(
         GlobalSystemConfig().fq_name)
     sas_obj = ServiceApplianceSet('sas1-' + self.id(), gsc_obj)
     sas_obj.set_service_appliance_set_virtualization_type(
         'physical-device')
     self.api.service_appliance_set_create(sas_obj)
     st_obj = self.api.service_template_read(id=self.st_uuid)
     st_obj.add_service_appliance_set(sas_obj)
     self.api.service_template_update(st_obj)
     st_obj = self.api.service_template_read(id=self.st_uuid)
     # Create PT
     self.api.port_tuple_create(pt_obj)
     #  Make sure no LI or IIP is created in this case
     li_list_len = \
         len(self.api.logical_interfaces_list().get('logical-interfaces'))
     self.assertEqual(li_list_len, 0)
     iip_list_len = \
         len(self.api.instance_ips_list().get('instance-ips'))
     self.assertEqual(iip_list_len, 0)
     # cleanup
     st_obj.del_service_appliance_set(sas_obj)
     self.api.service_template_update(st_obj)
     self.api.service_appliance_set_delete(id=sas_obj.uuid)
     self.api.port_tuple_delete(id=pt_obj.uuid)
     pass
Пример #11
0
    def test_sa_with_invalid_pr_role(self):
        sa_obj = ServiceAppliance('sa-' + self.id(), parent_obj=self.sas_obj)
        kvp_array = []
        kvp = KeyValuePair(
            "left-attachment-point",
            self.default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/1-' +
            self.id())
        kvp_array.append(kvp)
        kvp = KeyValuePair(
            "right-attachment-point",
            self.default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/2-' +
            self.id())
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        sa_obj.set_service_appliance_properties(kvps)
        sa_obj.set_service_appliance_virtualization_type('physical-device')

        # Add PNF PI refs
        attr = ServiceApplianceInterfaceType(interface_type='left')
        sa_obj.add_physical_interface(self.left_pnf_pi_obj, attr)
        attr = ServiceApplianceInterfaceType(interface_type='right')
        sa_obj.add_physical_interface(self.right_pnf_pi_obj, attr)

        # Overwrite the role as leaf instead of pnf
        self.pnf_obj.set_physical_router_role('leaf')
        self.api.physical_router_update(self.pnf_obj)
        # Create SA should raise exception
        self.assertRaises(BadRequest,
                          self.api.service_appliance_create,
                          sa_obj)
    def post_dbe_create(cls, tenant_name, obj_dict, db_conn):
        # Allocate unit number for service IRB interfaces, each for left and
        # right VRF on the service chaining device
        pnf_svc_inst = cls._check_svc_inst_belongs_to_pnf(obj_dict)
        if pnf_svc_inst:
            left_svc_fq_name = ':'.join(obj_dict['fq_name']) + 'left_svc'
            right_svc_fq_name = ':'.join(obj_dict['fq_name']) + 'right_svc'

            left_svc_unit = cls.vnc_zk_client.alloc_vn_id(left_svc_fq_name)

            def undo_left_svc_unit():
                cls.vnc_zk_client.free_vn_id(left_svc_unit, left_svc_fq_name)
                return True, ""

            get_context().push_undo(undo_left_svc_unit)

            right_svc_unit = cls.vnc_zk_client.alloc_vn_id(right_svc_fq_name)

            def undo_right_svc_unit():
                cls.vnc_zk_client.free_vn_id(right_svc_unit, right_svc_fq_name)
                return True, ""

            get_context().push_undo(undo_right_svc_unit)

            if left_svc_unit and right_svc_unit:
                # Store these unit-id's as key value pairs in
                # service_instance_bindings
                api_server = cls.server
                svc_inst_obj = ServiceInstance(obj_dict)
                svc_inst_obj.set_service_instance_bindings(
                    KeyValuePairs([
                        KeyValuePair('left-svc-unit', str(left_svc_unit)),
                        KeyValuePair('right-svc-unit', str(right_svc_unit))
                    ]))
                svc_inst_dict = json.dumps(svc_inst_obj,
                                           default=_obj_serializer_all)
                api_server.internal_request_update('service-instance',
                                                   obj_dict['uuid'],
                                                   json.loads(svc_inst_dict))
        return True, ''
Пример #13
0
 def _update_floating_ip(self,
                         name,
                         ns_name,
                         external_ip,
                         lb_obj,
                         specified_fip_pool_fq_name_str=None):
     proj_obj = self._get_project(ns_name)
     fip = self._allocate_floating_ip(lb_obj, name, ns_name, proj_obj,
                                      external_ip,
                                      specified_fip_pool_fq_name_str)
     if fip:
         lb_obj.add_annotations(
             KeyValuePair(key='externalIP', value=external_ip))
         self._vnc_lib.loadbalancer_update(lb_obj)
     return fip
Пример #14
0
def set_fabric_job_transaction(job_ctx, vnc_api, trans_info):
    try:
        fabric_info = job_ctx.get('job_input')
        fabric_fq_name = fabric_info.get('fabric_fq_name')
        fabric_obj = vnc_api.fabric_read(fq_name=fabric_fq_name)
        trans_val = json.dumps(trans_info)
        annotations = fabric_obj.get_annotations()
        if not annotations:
            annotations = KeyValuePairs()
        annotations.add_key_value_pair(
            KeyValuePair(key='job_transaction', value=trans_val))
        fabric_obj.set_annotations(annotations)
        vnc_api.fabric_update(fabric_obj)
    except Exception:
        pass
Пример #15
0
    def __call__(self, parser, args, values, option_string=None):
        if not values:
            return

        kvps = KeyValuePairs()
        kvp_list = []
        for value in values:
            try:
                (physnet, interface) = value.split("=", 2)
            except ValueError:
                raise argparse.ArgumentError(self,
                                             "could not parse argument: %s",
                                             value)
            kvp_list.append(KeyValuePair(key=physnet, value=interface))
        kvps.set_key_value_pair(kvp_list)
        setattr(args, self.dest, kvps)
Пример #16
0
    def create(self,
               ll_obj,
               proj_obj,
               port,
               lb_algorithm=None,
               annotations=None):
        """
        Create a loadbalancer_pool object.
        """
        pool_uuid = str(uuid.uuid4())
        props = LoadbalancerPoolType()
        if port['protocol'] == "TCP":
            props.set_protocol("TCP")
        elif port['protocol'] == "HTTP":
            props.set_protocol("HTTP")
        elif port['protocol'] == "HTTPS":
            props.set_protocol("HTTPS")
        else:
            props.set_protocol("UDP")
        if lb_algorithm:
            props.set_loadbalancer_method(lb_algorithm)
        id_perms = IdPermsType(enable=True)
        pool_obj = LoadbalancerPool(ll_obj.name,
                                    proj_obj,
                                    uuid=pool_uuid,
                                    loadbalancer_pool_properties=props,
                                    id_perms=id_perms)

        if ll_obj:
            pool_exists = ll_obj.get_loadbalancer_pool_back_refs()
            if pool_exists is not None:
                raise Exception("Pool {} already exists ".format(
                    pool_exists[0]['uuid']))
            pool_obj.set_loadbalancer_listener(ll_obj)

        if annotations:
            for key in annotations:
                pool_obj.add_annotations(
                    KeyValuePair(key=key, value=annotations[key]))
        try:
            self._vnc_lib.loadbalancer_pool_create(pool_obj)
        except RefsExistError:
            self._vnc_lib.loadbalancer_pool_update(pool_obj)

        return pool_obj
Пример #17
0
    def create(self, lb_obj, proj_obj, port):

        if not port:
            self.logger.error("Port is Missing for LB %s" % lb_obj.name)
            return None
        ll_uuid = str(uuid.uuid4())
        name = lb_obj.name + "-" + port['protocol'] + "-" + str(
            port['port']) + "-" + ll_uuid

        id_perms = IdPermsType(enable=True)
        ll_obj = LoadbalancerListener(name,
                                      proj_obj,
                                      id_perms=id_perms,
                                      display_name=name)
        ll_obj.uuid = ll_uuid

        if lb_obj:
            ll_obj.set_loadbalancer(lb_obj)

        props = LoadbalancerListenerType()
        default_protocol = 'UDP'
        supported_protocols = ['TCP', 'HTTP', 'HTTPS', 'TERMINATED_HTTPS']
        props.set_protocol(default_protocol)
        if 'protocol' in port:
            if port['protocol'] in supported_protocols:
                props.set_protocol(port['protocol'])
        if 'port' in port:
            props.set_protocol_port(port['port'])
        if 'default_tls_container' in port:
            setattr(props, 'default_tls_container',
                    port['default_tls_container'])
        if 'sni_containers' in port:
            setattr(props, 'sni_containers', port['sni_containers'])

        ll_obj.set_loadbalancer_listener_properties(props)
        if 'name' in port:
            ll_obj.add_annotations(
                KeyValuePair(key='portName', value=str(port['name'])))

        try:
            self._vnc_lib.loadbalancer_listener_create(ll_obj)
        except RefsExistError:
            self._vnc_lib.loadbalancer_listener_update(ll_obj)

        return ll_obj
    def test_hbs_default_vn_ref_add_with_annotations(self):
        hbs = HostBasedService('hbs-%s' % self.id(), parent_obj=self.project)
        self.api.host_based_service_create(hbs)
        vn1 = VirtualNetwork('vn1-%s' % self.id(), parent_obj=self.project)
        self.api.virtual_network_create(vn1)

        hbs.add_annotations(KeyValuePair(key='imagePullSecrets', value='psd'))
        for vn_type in ['left', 'right']:
            self.assertRaises(
                BadRequest,
                self.api.ref_update,
                hbs.resource_type,
                hbs.uuid,
                vn1.resource_type,
                vn1.uuid,
                None,
                'ADD',
                ServiceVirtualNetworkType(vn_type),
            )
Пример #19
0
    def create(self, pool_obj, address, port, annotations):
        """
        Create a loadbalancer_member object.
        """
        lm_uuid = str(uuid.uuid4())
        props = LoadbalancerMemberType(address=address, protocol_port=port)
        id_perms = IdPermsType(enable=True)

        member_obj = LoadbalancerMember(lm_uuid,
                                        pool_obj,
                                        loadbalancer_member_properties=props,
                                        id_perms=id_perms)
        member_obj.uuid = lm_uuid

        if annotations:
            for key in annotations:
                member_obj.add_annotations(
                    KeyValuePair(key=key, value=annotations[key]))
        self._vnc_lib.loadbalancer_member_create(member_obj)
        return member_obj
 def _store_default_advanced_params(self, fabric_obj, adv_param_cfg):
     # For now, use fabric object to store advanced params
     fabric_obj.set_annotations(KeyValuePairs([
         KeyValuePair(key='hitless_upgrade_input',
                      value=json.dumps(adv_param_cfg))]))
     self.vncapi.fabric_update(fabric_obj)
Пример #21
0
    def test_valid_pt(self):
        si_obj = self.api.service_instance_read(id=self.si_uuid)
        left_lr_obj = self.api.logical_router_read(id=self.left_lr_uuid)
        right_lr_obj = self.api.logical_router_read(id=self.right_lr_uuid)
        pt_obj = PortTuple('pt-' + self.id(), parent_obj=si_obj)
        pt_obj.add_logical_router(left_lr_obj)
        pt_obj.add_logical_router(right_lr_obj)
        kvp_array = []
        kvp = KeyValuePair("left-lr", self.left_lr_uuid)
        kvp_array.append(kvp)
        kvp = KeyValuePair("right-lr", self.right_lr_uuid)
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        pt_obj.set_annotations(kvps)
        # Create PT
        self.api.port_tuple_create(pt_obj)

        # Validate if LI's are created for PNF and spine
        left_pnf_pi_obj = self.api.physical_interface_read(
            id=self.left_pnf_pi_uuid)
        right_pnf_pi_obj = self.api.physical_interface_read(
            id=self.left_pnf_pi_uuid)
        left_spine_pi_obj = self.api.physical_interface_read(
            id=self.left_spine_pi_uuid)
        right_spine_pi_obj = self.api.physical_interface_read(
            id=self.right_spine_pi_uuid)
        lo_pnf_pi_obj = self.api.physical_interface_read(
            id=self.lo_pnf_pi_uuid)

        self.assertEqual(len(lo_pnf_pi_obj.get_logical_interfaces()), 1)
        self.assertEqual(len(left_pnf_pi_obj.get_logical_interfaces()), 1)
        self.assertEqual(len(right_pnf_pi_obj.get_logical_interfaces()), 1)
        self.assertEqual(len(left_spine_pi_obj.get_logical_interfaces()), 1)
        self.assertEqual(len(right_spine_pi_obj.get_logical_interfaces()), 1)

        # Validate if IIP objects are created for the above LI's
        left_pnf_li_uuid = left_pnf_pi_obj.get_logical_interfaces()[
            0].get('uuid')
        right_pnf_li_uuid = right_pnf_pi_obj.get_logical_interfaces()[
            0].get('uuid')
        left_spine_li_uuid = left_spine_pi_obj.get_logical_interfaces()[
            0].get('uuid')
        right_spine_li_uuid = right_spine_pi_obj.get_logical_interfaces()[
            0].get('uuid')
        lo_pnf_li_uuid = lo_pnf_pi_obj.get_logical_interfaces()[0].get('uuid')

        left_pnf_li_obj = self.api.logical_interface_read(id=left_pnf_li_uuid)
        right_pnf_li_obj = self.api.logical_interface_read(
            id=right_pnf_li_uuid)
        left_spine_li_obj = self.api.logical_interface_read(
            id=left_spine_li_uuid)
        right_spine_li_obj = self.api.logical_interface_read(
            id=right_spine_li_uuid)
        lo_pnf_li_obj = self.api.logical_interface_read(id=lo_pnf_li_uuid)

        self.assertEqual(len(left_pnf_li_obj.get_instance_ip_back_refs()), 1)
        self.assertEqual(len(right_pnf_li_obj.get_instance_ip_back_refs()), 1)
        self.assertEqual(len(left_spine_li_obj.get_instance_ip_back_refs()), 1)
        self.assertEqual(
            len(right_spine_li_obj.get_instance_ip_back_refs()), 1)
        self.assertEqual(len(lo_pnf_li_obj.get_instance_ip_back_refs()), 1)

        # Validate if the IIP's are valid
        left_pnf_iip_uuid = left_pnf_li_obj.get_instance_ip_back_refs()[
            0].get('uuid')
        right_pnf_iip_uuid = right_pnf_li_obj.get_instance_ip_back_refs()[
            0].get('uuid')
        left_spine_iip_uuid = left_spine_li_obj.get_instance_ip_back_refs()[
            0].get('uuid')
        right_spine_iip_uuid = right_spine_li_obj.get_instance_ip_back_refs()[
            0].get('uuid')
        lo_pnf_iip_uuid = lo_pnf_li_obj.get_instance_ip_back_refs()[
            0].get('uuid')

        self.assertIsNotNone(
            self.api.instance_ip_read(
                id=left_pnf_iip_uuid).instance_ip_address)
        self.assertIsNotNone(self.api.instance_ip_read(
            id=right_pnf_iip_uuid).instance_ip_address)
        self.assertIsNotNone(self.api.instance_ip_read(
            id=left_spine_iip_uuid).instance_ip_address)
        self.assertIsNotNone(self.api.instance_ip_read(
            id=right_spine_iip_uuid).instance_ip_address)
        self.assertIsNotNone(
            self.api.instance_ip_read(
                id=lo_pnf_iip_uuid).instance_ip_address)

        # Delete PT
        self.api.port_tuple_delete(id=pt_obj.uuid)
Пример #22
0
    def test_valid_sa(self):
        sa_obj = ServiceAppliance('sa-' + self.id(), parent_obj=self.sas_obj)
        kvp_array = []
        kvp = KeyValuePair(
            "left-attachment-point",
            self.default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/1-' +
            self.id())
        kvp_array.append(kvp)
        kvp = KeyValuePair(
            "right-attachment-point",
            self.default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/2-' +
            self.id())
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        sa_obj.set_service_appliance_properties(kvps)
        sa_obj.set_service_appliance_virtualization_type('physical-device')

        # Add PNF PI refs
        attr = ServiceApplianceInterfaceType(interface_type='left')
        sa_obj.add_physical_interface(self.left_pnf_pi_obj, attr)
        attr = ServiceApplianceInterfaceType(interface_type='right')
        sa_obj.add_physical_interface(self.right_pnf_pi_obj, attr)

        # Create SA
        self.api.service_appliance_create(sa_obj)
        self.left_pnf_pi_obj = self.api.physical_interface_read(
            id=self.left_pnf_pi_obj.uuid)
        self.right_pnf_pi_obj = self.api.physical_interface_read(
            id=self.right_pnf_pi_obj.uuid)

        # Check if spine PI <-> PNF PI link has been created
        self.assertEqual(
            self.left_pnf_pi_obj.physical_interface_refs[0].get('uuid'),
            self.left_spine_pi_obj.uuid)
        self.assertEqual(
            self.right_pnf_pi_obj.physical_interface_refs[0].get('uuid'),
            self.right_spine_pi_obj.uuid)

        # Delete service appliance
        self.api.service_appliance_delete(id=sa_obj.uuid)

        # Check if spine PI <-> PNF PI link got removed
        self.left_pnf_pi_obj = self.api.physical_interface_read(
            id=self.left_pnf_pi_obj.uuid)
        self.right_pnf_pi_obj = self.api.physical_interface_read(
            id=self.right_pnf_pi_obj.uuid)
        self.assertFalse(
            hasattr(
                self.left_pnf_pi_obj,
                "physical_interface_refs"))
        self.assertFalse(
            hasattr(
                self.right_pnf_pi_obj,
                "physical_interface_refs"))
Пример #23
0
    def setUp(self):
        def _carve_out_subnets(subnets, cidr):
            carved_subnets = []
            for subnet in subnets:
                slash_x_subnets = IPNetwork(subnet.get('cidr')).subnet(cidr)
                for slash_x_sn in slash_x_subnets:
                    carved_subnets.append({'cidr': str(slash_x_sn)})
            return carved_subnets
        # end _carve_out_subnets

        def _get_network_ipam(ipam_name, subnets, subnetting):
            def _new_subnet(cidr):
                split_cidr = cidr.split('/')
                return SubnetType(
                    ip_prefix=split_cidr[0],
                    ip_prefix_len=split_cidr[1])
            # end _new_subnet
            ipam = NetworkIpam(
                name=ipam_name,
                ipam_subnets=IpamSubnets([
                    IpamSubnetType(
                        subnet=_new_subnet(sn.get('cidr')),
                        default_gateway=sn.get('gateway'),
                        subnet_uuid=str(uuid.uuid1())
                    ) for sn in subnets if int(
                        sn.get('cidr').split('/')[-1]) < 31
                ]),
                ipam_subnet_method='flat-subnet',
                ipam_subnetting=subnetting
            )
            return ipam
        # end _add_network_ipam
        super(TestPnfPortTuple, self).setUp()
        logger.debug("setUp called")
        # Create Global objects
        default_gsc_name = 'default-global-system-config'
        gsc_obj = self.api.global_system_config_read(
            GlobalSystemConfig().fq_name)
        proj_obj = self.api.project_read(Project().fq_name)
        # Create PNF and spine Physical Router
        pnf_obj = PhysicalRouter('pnf-' + self.id(), gsc_obj)
        pnf_obj.set_physical_router_role('pnf')
        self.pnf_uuid = self.api.physical_router_create(pnf_obj)
        # Create spine Physical Router
        spine_obj = PhysicalRouter('spine-' + self.id(), gsc_obj)
        self.spine_uuid = self.api.physical_router_create(spine_obj)
        # Create left/right LR
        left_lr_name = 'left_lr-' + self.id()
        left_lr_obj = LogicalRouter(name=left_lr_name, parent_obj=proj_obj)
        left_lr_obj.add_physical_router(spine_obj)
        self.left_lr_uuid = self.api.logical_router_create(left_lr_obj)
        right_lr_name = 'right_lr-' + self.id()
        right_lr_obj = LogicalRouter(name=right_lr_name, parent_obj=proj_obj)
        right_lr_obj.add_physical_router(spine_obj)
        self.right_lr_uuid = self.api.logical_router_create(right_lr_obj)
        # create left, right PNF PI
        left_pnf_pi_obj = PhysicalInterface(
            'ge-0/0/1-' + self.id(), parent_obj=pnf_obj)
        right_pnf_pi_obj = PhysicalInterface(
            'ge-0/0/2-' + self.id(), parent_obj=pnf_obj)
        lo_pnf_pi_obj = PhysicalInterface('lo0', parent_obj=pnf_obj)
        self.left_pnf_pi_uuid = self.api.physical_interface_create(
            left_pnf_pi_obj)
        self.right_pnf_pi_uuid = self.api.physical_interface_create(
            right_pnf_pi_obj)
        self.lo_pnf_pi_uuid = self.api.physical_interface_create(lo_pnf_pi_obj)
        # create left, right spine PI
        left_spine_pi_obj = PhysicalInterface(
            'xe-0/0/1-' + self.id(), parent_obj=spine_obj)
        right_spine_pi_obj = PhysicalInterface(
            'xe-0/0/2-' + self.id(), parent_obj=spine_obj)
        self.left_spine_pi_uuid = self.api.physical_interface_create(
            left_spine_pi_obj)
        self.right_spine_pi_uuid = self.api.physical_interface_create(
            right_spine_pi_obj)
        # Create Service Appliance Set
        sas_obj = ServiceApplianceSet('sas-' + self.id(), gsc_obj)
        sas_obj.set_service_appliance_set_virtualization_type(
            'physical-device')
        self.sas_uuid = self.api.service_appliance_set_create(sas_obj)
        # Create Service template
        st_obj = ServiceTemplate(name='st-' + self.id())
        st_obj.set_service_appliance_set(sas_obj)
        svc_properties = ServiceTemplateType()
        svc_properties.set_service_virtualization_type('physical-device')
        if_type = ServiceTemplateInterfaceType()
        if_type.set_service_interface_type('left')
        svc_properties.add_interface_type(if_type)
        if_type = ServiceTemplateInterfaceType()
        if_type.set_service_interface_type('right')
        svc_properties.add_interface_type(if_type)
        st_obj.set_service_template_properties(svc_properties)
        self.st_uuid = self.api.service_template_create(st_obj)
        # Create Service Instance object
        si_fqn = ['default-domain', 'default-project', 'si-' + self.id()]
        si_obj = ServiceInstance(fq_name=si_fqn)
        si_obj.fq_name = si_fqn
        si_obj.add_service_template(st_obj)
        kvp_array = []
        kvp = KeyValuePair("left-svc-vlan", "100")
        kvp_array.append(kvp)
        kvp = KeyValuePair("right-svc-vlan", "101")
        kvp_array.append(kvp)
        kvp = KeyValuePair("left-svc-asns", "66000,66001")
        kvp_array.append(kvp)
        kvp = KeyValuePair("right-svc-asns", "66000,66002")
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        si_obj.set_annotations(kvps)
        props = ServiceInstanceType()
        props.set_service_virtualization_type('physical-device')
        props.set_ha_mode("active-standby")
        si_obj.set_service_instance_properties(props)
        self.si_uuid = self.api.service_instance_create(si_obj)
        # Create service appliance
        sa_obj = ServiceAppliance('sa-' + self.id(), parent_obj=sas_obj)
        kvp_array = []
        kvp = KeyValuePair(
            "left-attachment-point",
            default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/1-' +
            self.id())
        kvp_array.append(kvp)
        kvp = KeyValuePair(
            "right-attachment-point",
            default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/2-' +
            self.id())
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        sa_obj.set_service_appliance_properties(kvps)
        sa_obj.set_service_appliance_virtualization_type('physical-device')
        attr = ServiceApplianceInterfaceType(interface_type='left')
        sa_obj.add_physical_interface(left_pnf_pi_obj, attr)
        attr = ServiceApplianceInterfaceType(interface_type='right')
        sa_obj.add_physical_interface(right_pnf_pi_obj, attr)
        self.sa_uuid = self.api.service_appliance_create(sa_obj)
        # Create fabric and add it to spine and PNF
        fab_obj = Fabric('fab-' + self.id())
        self.fab_uuid = self.api.fabric_create(fab_obj)
        pnf_obj.add_fabric(fab_obj)
        self.api.physical_router_update(pnf_obj)
        spine_obj.add_fabric(fab_obj)
        self.api.physical_router_update(spine_obj)
        fab_obj = self.api.fabric_read(id=self.fab_uuid)
        # Create PNF service chain IPAM/network
        pnf_cidr = [{'cidr': "10.1.1.0/28"}]
        peer_subnets = _carve_out_subnets(pnf_cidr, 29)
        pnf_vn_obj = VirtualNetwork(
            name='fab-' + self.id() + '-pnf-servicechain-network',
            virtual_network_properties=VirtualNetworkType(
                forwarding_mode='l3'),
            address_allocation_mode='flat-subnet-only')
        self.pnf_vn_uuid = self.api.virtual_network_create(pnf_vn_obj)
        pnf_ipam_obj = _get_network_ipam(
            'fab-' +
            self.id() +
            '-pnf-servicechain-network-ipam',
            peer_subnets,
            True)
        self.pnf_ipam_uuid = self.api.network_ipam_create(pnf_ipam_obj)
        pnf_vn_obj.add_network_ipam(pnf_ipam_obj, VnSubnetsType([]))
        self.api.virtual_network_update(pnf_vn_obj)
        fab_obj = self.api.fabric_read(id=self.fab_uuid)
        fab_obj.add_virtual_network(
            pnf_vn_obj, FabricNetworkTag(
                network_type='pnf-servicechain'))
        self.api.fabric_update(fab_obj)
        # Create loopback IPAM/network
        lo_cidr = [{'cidr': "100.100.100.0/28"}]
        peer_subnets = _carve_out_subnets(lo_cidr, 28)
        lo_vn_obj = VirtualNetwork(
            name='fab-' + self.id() + '-loopback-network',
            virtual_network_properties=VirtualNetworkType(
                forwarding_mode='l3'),
            address_allocation_mode='flat-subnet-only')
        self.lo_vn_uuid = self.api.virtual_network_create(lo_vn_obj)
        lo_ipam_obj = _get_network_ipam(
            'fab-' +
            self.id() +
            '-loopback-network-ipam',
            peer_subnets,
            False)
        self.lo_ipam_uuid = self.api.network_ipam_create(lo_ipam_obj)
        lo_vn_obj.add_network_ipam(lo_ipam_obj, VnSubnetsType([]))
        self.api.virtual_network_update(lo_vn_obj)
        fab_obj = self.api.fabric_read(id=self.fab_uuid)
        fab_obj.add_virtual_network(
            lo_vn_obj, FabricNetworkTag(
                network_type='loopback'))
        self.api.fabric_update(fab_obj)
    def test_vmi_update(self):
        proj_obj, fabric_obj, pr_objs = self._create_prerequisites(
            enterprise_style_flag=False, create_second_pr=True)

        pr_obj_1 = pr_objs[0]
        pr_obj_2 = pr_objs[1]

        # Create first PI
        esi_id = '00:11:22:33:44:55:66:77:88:99'
        pi_name = self.id() + '_physical_interface1'
        pi_1 = PhysicalInterface(name=pi_name,
                                 parent_obj=pr_obj_1,
                                 ethernet_segment_identifier=esi_id)
        pi_uuid_1 = self._vnc_lib.physical_interface_create(pi_1)
        pi_obj_1 = self._vnc_lib.physical_interface_read(id=pi_uuid_1)

        fabric_name = fabric_obj.get_fq_name()
        pi_fq_name_1 = pi_obj_1.get_fq_name()

        # Create second PI
        pi_name = self.id() + '_physical_interface2'
        pi_2 = PhysicalInterface(name=pi_name,
                                 parent_obj=pr_obj_2,
                                 ethernet_segment_identifier=esi_id)
        pi_uuid_2 = self._vnc_lib.physical_interface_create(pi_2)
        pi_obj_2 = self._vnc_lib.physical_interface_read(id=pi_uuid_2)

        fabric_name = fabric_obj.get_fq_name()
        pi_fq_name_2 = pi_obj_2.get_fq_name()

        # Create VPG
        vpg_name = "vpg-1"
        vpg = VirtualPortGroup(vpg_name, parent_obj=fabric_obj)
        vpg_uuid = self.api.virtual_port_group_create(vpg)
        vpg_obj = self._vnc_lib.virtual_port_group_read(id=vpg_uuid)
        vpg_name = vpg_obj.get_fq_name()

        # Create single VN
        vn1 = VirtualNetwork('vn1-%s' % (self.id()), parent_obj=proj_obj)
        self.api.virtual_network_create(vn1)

        # Create a VMI that's attached to vpg-1 and having reference
        # to vn1
        vmi_obj = VirtualMachineInterface(self.id() + "1",
                                          parent_obj=proj_obj)
        vmi_obj.set_virtual_network(vn1)

        # Populate binding profile to be used in VMI create
        binding_profile = {'local_link_information': [
            {'port_id': pi_fq_name_1[2],
             'switch_id': pi_fq_name_1[2],
             'fabric': fabric_name[-1],
             'switch_info': pi_fq_name_1[1]},
            {'port_id': pi_fq_name_2[2],
             'switch_id': pi_fq_name_2[2],
             'fabric': fabric_name[-1],
             'switch_info': pi_fq_name_2[1]}]}

        kv_pairs = KeyValuePairs(
            [KeyValuePair(key='vpg', value=vpg_name[-1]),
             KeyValuePair(key='vif_type', value='vrouter'),
             KeyValuePair(key='vnic_type', value='baremetal'),
             KeyValuePair(key='profile',
                          value=json.dumps(binding_profile))])

        vmi_obj.set_virtual_machine_interface_bindings(kv_pairs)

        vmi_obj.set_virtual_machine_interface_properties(
            VirtualMachineInterfacePropertiesType(sub_interface_vlan_tag=42))
        vmi_uuid_1 = self.api.virtual_machine_interface_create(vmi_obj)
        # Read physical interface type, it should be set to access
        pi_obj_1 = self._vnc_lib.physical_interface_read(id=pi_uuid_1)
        pi_obj_2 = self._vnc_lib.physical_interface_read(id=pi_uuid_2)
        intf_type_pi_1 = pi_obj_1.get_physical_interface_type()
        self.assertEqual(intf_type_pi_1, 'access')
        intf_type_pi_2 = pi_obj_2.get_physical_interface_type()
        self.assertEqual(intf_type_pi_2, 'access')
        vpg_obj.add_virtual_machine_interface(vmi_obj)
        self.api.virtual_port_group_update(vpg_obj)

        # Now, remove one of the local_link_information
        binding_profile = {'local_link_information': [
            {'port_id': pi_fq_name_1[2],
             'switch_id': pi_fq_name_1[2],
             'fabric': fabric_name[-1],
             'switch_info': pi_fq_name_1[1]}]}
        vmi_obj.set_virtual_machine_interface_bindings(kv_pairs)
        self.api.virtual_machine_interface_update(vmi_obj)

        self.api.virtual_machine_interface_delete(id=vmi_uuid_1)
        self.api.virtual_port_group_delete(id=vpg_obj.uuid)
        # Read physical interface type again, it should be set to None
        pi_obj_1 = self._vnc_lib.physical_interface_read(id=pi_uuid_1)
        pi_obj_2 = self._vnc_lib.physical_interface_read(id=pi_uuid_2)
        intf_type_pi_1 = pi_obj_1.get_physical_interface_type()
        self.assertEqual(intf_type_pi_1, None)
        intf_type_pi_2 = pi_obj_2.get_physical_interface_type()
        self.assertEqual(intf_type_pi_2, None)
        self.api.physical_interface_delete(id=pi_uuid_1)
        self.api.physical_interface_delete(id=pi_uuid_2)
        self.api.physical_router_delete(id=pr_obj_1.uuid)
        self.api.physical_router_delete(id=pr_obj_2.uuid)
        self.api.fabric_delete(id=fabric_obj.uuid)
 def _cache_job_input(self):
     fabric_obj = self.vncapi.fabric_read(id=self.fabric_uuid)
     fabric_obj.set_annotations(KeyValuePairs([
         KeyValuePair(key='hitless_upgrade_input',
                      value=json.dumps(self.job_input))]))
     self.vncapi.fabric_update(fabric_obj)
    def _manage_lag_interface(cls,
                              vmi_id,
                              api_server,
                              db_conn,
                              phy_links,
                              lag_name=None):
        fabric_name = None
        phy_interface_uuids = []
        for link in phy_links:
            if fabric_name is not None and fabric_name != link['fabric']:
                msg = 'Physical interfaces in the same lag should belong to '\
                      'the same fabric'
                return (False, (400, msg))
            else:
                fabric_name = link['fabric']

            phy_interface_name = link['port_id']
            prouter_name = link['switch_info']
            pi_fq_name = [
                'default-global-system-config', prouter_name,
                phy_interface_name
            ]
            phy_interface_uuids.append(
                db_conn.fq_name_to_uuid('physical_interface', pi_fq_name))

        # check if new physical interfaces belongs to some other lag
        for uuid in set(phy_interface_uuids):
            ok, phy_interface_dict = db_conn.dbe_read(
                obj_type='physical-interface', obj_id=uuid)
            if not ok:
                return (ok, 400, phy_interface_dict)

            mac = phy_interface_dict['physical_interface_mac_addresses'][
                'mac_address']
            esi = "00:00:00:00:" + mac[0]
            lag_refs = phy_interface_dict.get('virtual_port_group_back_refs')
            if lag_refs and lag_refs[0]['to'][-1] != lag_name:
                msg = 'Physical interface %s already belong to the lag %s' %\
                      (phy_interface_dict.get('name'), lag_refs[0]['to'][-1])
                return (False, (400, msg))

        if lag_name:  # read the lag object
            lag_fq_name = [
                'default-global-system-config', fabric_name, lag_name
            ]
            try:
                lag_uuid = db_conn.fq_name_to_uuid('virtual_port_group',
                                                   lag_fq_name)
            except NoIdError:
                msg = 'Lag object %s is not found' % lag_name
                return (False, (404, msg))

            ok, lag_dict = db_conn.dbe_read(obj_type='virtual-port-group',
                                            obj_id=lag_uuid)

            if not ok:
                return (ok, 400, lag_dict)

            kvps = lag_dict['annotations']['key_value_pair']
            kvp_dict = cls._kvp_to_dict(kvps)
            lag_update_dict = {}
            if kvp_dict.get('esi') != esi:
                lag_dict['annotations']['key_value_pair'][1] = KeyValuePair(
                    'esi', esi)
                lag_update_dict['annotations'] = lag_dict['annotations']
                lag_update_dict = json.dumps(lag_update_dict,
                                             default=_obj_serializer_all)
                ok, resp = api_server.internal_request_update(
                    'virtual-port-group', lag_dict['uuid'],
                    json.loads(lag_update_dict))

        else:  # create lag object
            fabric_fq_name = [
                'default-global-system-config',
                fabric_name,
                phy_interface_uuids[0],
            ]
            ae_id = cls.vnc_zk_client.alloc_ae_id(':'.join(fabric_fq_name))

            def undo_ae_id():
                cls.vnc_zk_client.free_ae_id(':'.join(fabric_fq_name))
                return True, ""

            get_context().push_undo(undo_ae_id)

            lag_name = "lag" + str(ae_id)
            lag_obj = VirtualPortGroup(parent_type='fabric',
                                       fq_name=[
                                           'default-global-system-config',
                                           fabric_name, lag_name
                                       ],
                                       virtual_port_group_lacp_enabled=True)
            lag_obj.set_annotations(
                KeyValuePairs([
                    KeyValuePair('ae_if_name', str(ae_id)),
                    KeyValuePair('esi', esi)
                ]))
            lag_int_dict = json.dumps(lag_obj, default=_obj_serializer_all)

            ok, resp = api_server.internal_request_create(
                'virtual-port-group', json.loads(lag_int_dict))

            if not ok:
                return (ok, 400, resp)

            lag_dict = resp['virtual-port-group']
            lag_uuid = resp['virtual-port-group']['uuid']

            def undo_lag_create():
                cls.server.internal_request_delete('virtual-port-group',
                                                   lag_uuid)
                return True, ''

            get_context().push_undo(undo_lag_create)

        old_phy_interface_uuids = []
        old_phy_interface_refs = lag_dict.get('physical_interface_refs')
        for ref in old_phy_interface_refs or []:
            old_phy_interface_uuids.append(ref['uuid'])

        # add new physical interfaces to the lag
        for uuid in set(phy_interface_uuids) - set(old_phy_interface_uuids):
            api_server.internal_request_ref_update('virtual-port-group',
                                                   lag_uuid,
                                                   'ADD',
                                                   'physical-interface',
                                                   uuid,
                                                   relax_ref_for_delete=True)

        # delete old physical interfaces to the lag
        for uuid in set(old_phy_interface_uuids) - set(phy_interface_uuids):
            api_server.internal_request_ref_update('virtual-port-group',
                                                   lag_uuid, 'DELETE',
                                                   'physical-interface', uuid)

        return lag_uuid
Пример #27
0
 def cache_job_input(self, fabric_uuid, job_template_name, job_input):
     fabric_obj = self.vncapi.fabric_read(id=fabric_uuid)
     fabric_obj.add_annotations(
         KeyValuePair(key=job_template_name, value=json.dumps(job_input)))
     self.vncapi.fabric_update(fabric_obj)