コード例 #1
0
 def __init__(self, inputs, vnc, logger):
     self._inputs = inputs
     self._vnc = vnc
     self.logger = logger
     self._ipam_obj = self._get_ipam_object()
     self._gw = self._process_vcenter_gateway_info()
     self.vnc_h = ContrailVncApi(self._vnc, self.logger)
コード例 #2
0
    def test_rp_interface_static_matrix(self):
        '''
        1. Create a routing policy with interface-static match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.intf_table_to_right_obj = self.static_table_handle.create_route_table(
            prefixes=[random_cidr],
            name=get_random_name('int_table_right'),
            parent_obj=self.project.project_obj,
        )
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + vn_fixture.vn_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(test_vm.get_vmi_ids()[id_entry]),
            self.intf_table_to_right_obj)
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)
コード例 #3
0
class VirtualRouterBase(vnc_api_test.VncLibFixture):

    """Fixture to manage virtual router objects

    Mandatory:
    :param name   : name of the device
    :param virtual_router_type  : virtual router type('embedded','hypervisor' etc)
    """

    def __init__(self, *args, **kwargs):
        super(VirtualRouterBase, self).__init__(*args, **kwargs)
        self.name = args[0]
        self.virtual_router_type = args[1]
        self.vr = None
        self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)

    # end __init__
    def setUp(self):
        super(VirtualRouterBase, self).setUp()

    def cleanUp(self):
        super(VirtualRouterBase, self).cleanUp()

    def create(self):
        pass

    def delete(self):
        pass

    def update(self):
        self.vnc_api_h.virtual_router_update(self.vr)

    def read(self, id):
        self.vr = self.vnc_api_h.virtual_router_read(id=id)

    def update_virtual_router_type(self, vrouter_type=None):
        if not vrouter_type:
            self.vnc_h.update_virtual_router_type(self.name, self.virtual_router_type)
        else:
            self.vnc_h.update_virtual_router_type(self.name, vrouter_type)
コード例 #4
0
 def create_interface_static_routes(self):
     ret_dict = self.config_basic()
     self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
     random_cidr = get_random_cidr()
     self.intf_table_to_right_obj = self.static_table_handle.create_route_table(
         prefixes=[random_cidr],
         name=get_random_name('int_table_right'),
         parent_obj=self.project.project_obj,
     )
     id_entry = self.inputs.project_fq_name[0] + ':' + \
         self.inputs.project_fq_name[1] + ':' + ret_dict['vn_fixture'].vn_name
     self.static_table_handle.bind_vmi_to_interface_route_table(
         str(ret_dict['test_vm'].get_vmi_ids()[id_entry]),
         self.intf_table_to_right_obj)
     return ret_dict,random_cidr
コード例 #5
0
    def test_rp_network_static_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.nw_handle_to_right = self.static_table_handle.create_route_table(
                prefixes=[random_cidr],
                name="network_table_left_to_right",
                next_hop=test_vm.vm_ip,
                parent_obj=self.project.project_obj,
                next_hop_type='ip-address',
                route_table_type='network',
            )
        self.static_table_handle.bind_network_route_table_to_vn(
                vn_uuid=vn_fixture.uuid,
                nw_route_table_obj=self.nw_handle_to_right)

        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'community', 'sub_to':'64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '55555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'add_ext_community', 'sub_to':'target:64512:44444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = 'target:64512:44444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'set_ext_community', 'sub_to':'target:64512:33333'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = 'target:64512:33333'), 'Search term not found in introspect'
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)
コード例 #6
0
    def setUp(self):
        super(PortFixture, self).setUp()
        self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
        self.vn_obj = self.vnc_api_h.virtual_network_read(id=self.vn_id)

        if self.api_type == 'neutron':
            self._neutron_create_port()
        else:
            self._contrail_create_port()
        #Sandipd:This code was crashing while creating port as part of 
        #vcenter gateway testing.Hence handled the exception as the mac 
        #not needed to be obtained always,its passed as an argument to the fixture 
        try:
            self.neutron_handle = self.get_neutron_handle()
            self.obj = self.neutron_handle.get_port(self.uuid)
            self.mac_address = self.obj['mac_address']
        except Exception as e:
            pass
        self.vmi_obj = self.vnc_api_h.virtual_machine_interface_read(
            id=self.uuid)
        self.logger.debug('Created port %s' % (self.uuid))
コード例 #7
0
ファイル: alarm_test.py プロジェクト: Ankitja/contrail-test
 def __init__(self, connections, alarm_name=None, uve_keys=[], alarm_severity=None,
              alarm_rules=None, operand1=None, operand2=None, description=None, variables=None,
              id_perms=None, perms2=None, display_name=None, parent_obj_type='project',
              clean_up=True, project_name=None, project_fixture=None):
     self.connections = connections
     self.inputs = connections.inputs
     self.logger = self.connections.logger
     self.vnc_lib_h = self.connections.get_vnc_lib_h()
     self.vnc_h = ContrailVncApi(self.vnc_lib_h, self.logger)
     self.api_s_inspect = self.connections.api_server_inspect
     self.analytics_obj = self.connections.analytics_obj
     self.alarm_name = alarm_name
     self.alarm_id = None
     self.alarm_fq_name = [self.inputs.domain_name, self.alarm_name]
     self.uve_keys = uve_keys
     self.alarm_severity = alarm_severity
     self.alarm_rules = alarm_rules
     self.operand1 = operand1
     self.operand2 = operand2
     self.description = description
     self.variables = variables
     self.id_perms = id_perms
     self.perms2 = perms2
     self.display_name = display_name
     self.parent_obj_type = parent_obj_type
     self.domain_name = self.connections.domain_name
     self.project_name = project_name or self.connections.project_name
     self.project_fixture = project_fixture
     if self.project_fixture:
         self.project_name = self.project_fixture.project_name
     self.project_id = self.connections.get_project_id()
     self.parent_obj = None
     self.clean_up = clean_up
     self.obj = None
     self.created = False
     if self.inputs.verify_thru_gui():
         from webui_test import WebuiTest
         self.webui = WebuiTest(self.connections, self.inputs)
コード例 #8
0
class Orchestrator:
   """Base class for orchestrator."""

   __metaclass__ = ABCMeta

   def __init__(self, inputs, vnc_api_h, logger=None):
       self.inputs = inputs
       self.logger = logger or logging.getLogger(__name__)
       self.vnc_h = ContrailVncApi(vnc_api_h, logger)

   def is_feature_supported(self, feature):
       return True

   @abstractmethod
   def get_image_account(self, image_name):
       '''Returns username, password for the image.'''
       pass

   @abstractmethod
   def get_image_name_for_zone(self, image_name='ubuntu', zone='nova'):
       '''Get image name compatible with zone '''
       pass

   @abstractmethod
   def get_flavor(self, flavor):
       '''Installs and Returns Flavor ID.'''
       pass

   @abstractmethod
   def get_default_image_flavor(self, image_name):
       '''Returns Flavor ID for an image.'''
       pass

   @abstractmethod
   def get_image(self, image):
       '''Installs and Returns Image ID.'''
       pass

   @abstractmethod
   def get_hosts(self, zone=None):
       '''Returns a list of computes.'''
       pass

   @abstractmethod
   def get_zones(self):
       '''Returns a list of zones/clusters into which computes are grouped.'''
       pass

   @abstractmethod
   def create_vm(self, vm_name, image_name, vn_objs, count=1, zone=None, node_name=None, **kwargs):
       '''Returns a list of VM objects else None.'''
       pass

   @abstractmethod
   def delete_vm(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def get_host_of_vm(self, vm_obj, **kwargs):
       '''Returns name of the compute, on which the VM was created.'''
       pass

   @abstractmethod
   def get_networks_of_vm(self, vm_obj, **kwargs):
       '''Returns names of the networks, associated with the VM.'''
       pass

   @abstractmethod
   def get_vm_if_present(self, vm_name, **kwargs):
       pass

   @abstractmethod
   def get_vm_by_id(self, vm_id, **kwargs):
       pass

   @abstractmethod
   def get_vm_list(self, name_pattern='', **kwargs):
       '''Returns a list of VM object matching pattern.'''
       pass 
   
   @abstractmethod
   def get_vm_detail(self, vm_obj, **kwargs):
       '''Refreshes VM object.'''
       pass

   @abstractmethod
   def get_vm_ip(self, vm_obj, vn_name, **kwargs):
       '''Returns a list of IP of VM in VN.'''
       pass

   @abstractmethod
   def is_vm_deleted(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def wait_till_vm_is_active(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def wait_till_vm_status(self, vm_obj, status, **kwargs):
       pass

   @abstractmethod
   def get_console_output(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def get_key_file(self):
       '''Returns the key file path.'''
       pass

   @abstractmethod
   def put_key_file_to_host(self, host_ip):
       '''Copy RSA key to host.'''
       pass

   @abstractmethod
   def create_vn(self, vn_name, subnets, **kwargs):
       pass

   @abstractmethod
   def delete_vn(self, vn_obj, **kwargs):
       pass

   @abstractmethod
   def get_vn_obj_if_present(self, vn_name, **kwargs):
       pass

   @abstractmethod
   def get_vn_name(self, vn_obj, **kwargs):
       pass

   @abstractmethod
   def get_vn_id(self, vn_obj, **kwargs):
       pass

   def get_vn_list(self, **kwargs):
       return self.vnc_h.get_vn_list(**kwargs)

   def get_policy(self, fq_name, **kwargs):
       return self.vnc_h.get_policy(fq_name, **kwargs)

   def get_floating_ip(self, fip_id, **kwargs):
       return self.vnc_h.get_floating_ip(fip_id, **kwargs)

   def create_floating_ip(self, pool_vn_id, pool_obj, project_obj, **kwargs):
       return self.vnc_h.create_floating_ip( pool_obj, project_obj,
                                            **kwargs)

   def delete_floating_ip(self, fip_id, **kwargs):
       return self.vnc_h.delete_floating_ip(fip_id, **kwargs)

   def assoc_floating_ip(self, fip_id, vm_id, **kwargs):
       return self.vnc_h.assoc_floating_ip(fip_id, vm_id, **kwargs)

   def disassoc_floating_ip(self, fip_id, **kwargs):
       return self.vnc_h.disassoc_floating_ip(fip_id, **kwargs)

   def add_security_group(self, vm_id, sg_id, **kwargs):
       return self.vnc_h.add_security_group(vm_id, sg_id, **kwargs)

   def remove_security_group(self, vm_id, sg_id, **kwargs):
       return self.vnc_h.remove_security_group(vm_id, sg_id, **kwargs)

   def create_security_group(self, sg_name, parent_fqname, sg_entries, **kwargs):
       return self.vnc_h.create_security_group(sg_name, parent_fqname,
                                               sg_entries, **kwargs)

   def delete_security_group(self, sg_id, **kwargs):
       return self.vnc_h.delete_security_group(sg_id, **kwargs)

   def get_security_group(self, sg_id, **kwargs):
       return self.vnc_h.get_security_group(sg_id, **kwargs)

   def get_security_group_rules(self, sg_id, **kwargs):
       return self.vnc_h.get_security_group_rules(sg_id, **kwargs)

   def delete_security_group_rules(self, sg_id, **kwargs):
       return self.vnc_h.delete_security_group_rules(sg_id, **kwargs)

   def set_security_group_rules(self, sg_id, **kwargs):
       return self.vnc_h.set_security_group_rules(sg_id, **kwargs)
コード例 #9
0
class PortFixture(vnc_api_test.VncLibFixture):

    '''Fixture to handle Port/VMI objects

    Mandatory:
    :param vn_id    : UUID of the VN

    Optional:
    :param fixed_ips : list of fixed ip dict
    :param mac_address
    :param security_groups
    :params extra_dhcp_opts
    :param api_type     : one of 'neutron'(default) or 'contrail'
    :param project_obj   : Project object which is to be the parent
                          object of this port
    :param vlan_id     : vlan id of sub-interface if any
    :param parent_vmi  : If this is sub-interface, instance of parent
                               VirtualMachineInterface

    Inherited parameters:
    :param domain   : default is default-domain
    :param project_name  : default is admin
    :param cfgm_ip  : default is 127.0.0.1
    :param api_port : default is 8082
    :param connections   : ContrailConnections object. default is None
    :param username : default is admin
    :param password : default is contrail123
    :param auth_server_ip : default is 127.0.0.1
    '''

    def __init__(self, *args, **kwargs):
        super(PortFixture, self).__init__(self, *args, **kwargs)
        self.vn_id = args[0]
        self.fixed_ips = kwargs.get('fixed_ips', [])
        self.mac_address = kwargs.get('mac_address', [])
        self.security_groups = kwargs.get('security_groups', [])
        self.extra_dhcp_opts = kwargs.get('extra_dhcp_opts', [])
        self.api_type = kwargs.get('api_type', 'neutron')
        self.project_obj = kwargs.get('project_obj', None)
        self.binding_profile = kwargs.get('binding_profile', None)
        self.vlan_id = kwargs.get('vlan_id', None)
        self.parent_vmi = kwargs.get('parent_vmi', None)
        self.vn_obj = None
     # end __init__

    def setUp(self):
        super(PortFixture, self).setUp()
        self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
        self.vn_obj = self.vnc_api_h.virtual_network_read(id=self.vn_id)

        if self.api_type == 'neutron':
            self._neutron_create_port()
        else:
            self._contrail_create_port()
        #Sandipd:This code was crashing while creating port as part of 
        #vcenter gateway testing.Hence handled the exception as the mac 
        #not needed to be obtained always,its passed as an argument to the fixture 
        try:
            self.neutron_handle = self.get_neutron_handle()
            self.obj = self.neutron_handle.get_port(self.uuid)
            self.mac_address = self.obj['mac_address']
        except Exception as e:
            pass
        self.vmi_obj = self.vnc_api_h.virtual_machine_interface_read(
            id=self.uuid)
        self.logger.debug('Created port %s' % (self.uuid))

    def _neutron_create_port(self):
        if not self.neutron_handle:
            self.neutron_handle = self.get_neutron_handle()
        neutron_obj = self.neutron_handle.create_port(
            self.vn_id,
            fixed_ips=self.fixed_ips,
            mac_address=self.mac_address,
            security_groups=self.security_groups,
            extra_dhcp_opts=self.extra_dhcp_opts,
            binding_profile=self.binding_profile)
        self.neutron_obj = neutron_obj
        self.uuid = neutron_obj['id']

    def _contrail_create_port(self):
        vmi_props = vnc_api_test.VirtualMachineInterfacePropertiesType()

        if not self.project_obj:
            self.project_obj = self.vnc_api_h.project_read(id=self.project_id)
        vmi_id = str(uuid.uuid4())
        vmi_obj = vnc_api_test.VirtualMachineInterface(name=vmi_id,
            parent_obj=self.project_obj)
        if self.mac_address:
            mac_address_obj = vnc_api_test.MacAddressesType()
            mac_address_obj.set_mac_address([str(EUI(self.mac_address))])
            vmi_obj.set_virtual_machine_interface_mac_addresses(
                mac_address_obj)
        vmi_obj.uuid = vmi_id
        vmi_obj.add_virtual_network(self.vn_obj)

        if self.security_groups:
            for sg_id in self.security_groups:
                sg_obj = self.vnc_api_h.security_group_read(id=sg_id)
                vmi_obj.add_security_group(sg_obj)
        else:
            # Associate default SG
            default_sg_fq_name = self.project_obj.fq_name[:]
            default_sg_fq_name.append('default')
            sg_obj = self.vnc_api_h.security_group_read(
                fq_name=default_sg_fq_name)
            vmi_obj.add_security_group(sg_obj)

        if self.extra_dhcp_opts:
            # TODO
            pass

        if self.vlan_id:
            vmi_props.set_sub_interface_vlan_tag(int(self.vlan_id))

        if self.parent_vmi:
            vmi_obj.add_virtual_machine_interface(self.parent_vmi)

        if self.binding_profile:
            bind_kv = vnc_api_test.KeyValuePair(key='profile', value=str(self.binding_profile))
            kv_pairs = vmi_obj.get_virtual_machine_interface_bindings() or\
                       vnc_api_test.KeyValuePairs()
            kv_pairs.add_key_value_pair(bind_kv)
            vmi_obj.set_virtual_machine_interface_bindings(kv_pairs)

        vmi_obj.set_virtual_machine_interface_properties(vmi_props)
        self.vmi_obj = self.vnc_api_h.virtual_machine_interface_create(vmi_obj)
        self.uuid = vmi_id

        if self.fixed_ips:
            for fixed_ip in self.fixed_ips:
                iip_id = str(uuid.uuid4())
                iip_obj = vnc_api_test.InstanceIp(name=iip_id,
                                     subnet_id=fixed_ip['subnet_id'])
                iip_obj.uuid = iip_id
                iip_obj.add_virtual_machine_interface(vmi_obj)
                iip_obj.add_virtual_network(self.vn_obj)
                iip_obj.set_instance_ip_address(fixed_ip['ip_address'])
                self.vnc_api_h.instance_ip_create(iip_obj)
        else:
            iip_id = str(uuid.uuid4())
            iip_obj = vnc_api_test.InstanceIp(name=iip_id)
            iip_obj.uuid = iip_id
            iip_obj.add_virtual_machine_interface(vmi_obj)
            iip_obj.add_virtual_network(self.vn_obj)
            self.vnc_api_h.instance_ip_create(iip_obj)
    # end _contrail_create_port

    def cleanUp(self):
        super(PortFixture, self).cleanUp()
        if self.api_type == 'neutron':
            self._neutron_delete_port()
        else:
            self._contrail_delete_port()
        self.logger.info('Deleted port %s' % (self.uuid))

    def _neutron_delete_port(self):
        self.neutron_handle.delete_port(self.uuid)

    def _contrail_delete_port(self):
        vmi_iips = self.vmi_obj.get_instance_ip_back_refs()
        for vmi_iip in vmi_iips:
            vmi_iip_uuid = vmi_iip['uuid']
            self.vnc_api_h.instance_ip_delete(id=vmi_iip_uuid)
        self.vnc_api_h.virtual_machine_interface_delete(id=self.uuid)

    def verify_on_setup(self):
        if not self.verify_port_in_api_server():
            self.logger.error('VMI %s verification in API Server failed'%self.uuid)
            return False
        else:
            self.logger.info('VMI %s verification in API Server passed'%self.uuid)
        return True

    @retry(delay=2, tries=5)
    def verify_port_in_api_server(self):
        api_h = self.connections.api_server_inspect
        vmi = api_h.get_cs_vmi(self.uuid)
        if not vmi:
            self.logger.warn('Unable to fetch VMI %s from API server'%self.uuid)
            return False
        if self.binding_profile:
            bindings = vmi.get_bindings()
            if bindings['profile'] != json.dumps(self.binding_profile):
                self.logger.warn('VMI binding profile doesnt match.'
                                 'Expected %s actual %s for VMI %s'%(
                                 self.binding_profile, bindings['profile'], self.uuid))
                return False
        return True

    def verify_port_in_control_node_ifmap(self):
        pass

    def verify_port_in_control_node(self):
        pass

    def verify_port_in_agent(self):
        pass

    def verify_port_in_agent_ifmap(self):
        pass

    def add_fat_flow(self, fat_flow_config):
        '''
        fat_flow_config: dictionary of format {'proto':<string>,'port':<int>}
        '''
        self.vnc_h.add_fat_flow_to_vmi(self.uuid, fat_flow_config)

        return True

    def remove_fat_flow(self, fat_flow_config):
        '''
        fat_flow_config: dictionary of format {'proto':<string>,'port':<int>}
        '''
        self.vnc_h.remove_fat_flow_on_vmi(self.uuid, fat_flow_config)

        return True

    def add_interface_route_table(self, intf_route_table_obj):
        '''
        Adds interface static routes to a port

        Args:
        intf_route_table_obj:  InterfaceRouteTable instance
        '''
        self.vnc_h.bind_vmi_to_interface_route_table(self.uuid,
                                                     intf_route_table_obj)
    # end add_interface_route_table

    def del_interface_route_table(self, intf_route_table_uuid):
        '''Unbind intf_route_table_obj from port
        intf_route_table_obj is InterfaceRouteTable instance
        '''
        self.vnc_h.unbind_vmi_from_interface_route_table(
            self.uuid, intf_route_table_uuid)
    # end del_interface_route_table

    def get_ip(self, subnet_id):
        fixed_ips = self.obj['fixed_ips']
        ip = [x['ip_address'] for x in fixed_ips if x['subnet_id'] == subnet_id]
        if ip:
            return ip[0]
        else :
            return None
コード例 #10
0
 def __init__(self, *args, **kwargs):
     super(VirtualRouterBase, self).__init__(*args, **kwargs)
     self.name = args[0]
     self.virtual_router_type = args[1]
     self.vr = None
     self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
コード例 #11
0
    def setUpClass(cls):
        super(ECMPTestBase, cls).setUpClass()
        cls.inputs.set_af(cls.get_af())
        cls.vnc_h = ContrailVncApi(cls.vnc_lib, cls.logger)

        try:
            # Mgmt VN
            cls.mgmt_vn_name = get_random_name('mgmt_%s' % (
                                               cls.inputs.project_name))
            cls.mgmt_vn_subnets = [get_random_cidr(af=cls.inputs.get_af())]
            cls.mgmt_vn_fixture = cls.create_only_vn(
                    cls.mgmt_vn_name, cls.mgmt_vn_subnets)

            # Left VN
            cls.left_vn_name = get_random_name('left_%s' % (
                                              cls.inputs.project_name))
            cls.left_vn_subnets = [get_random_cidr(af=cls.inputs.get_af())]
            cls.left_vn_fixture = cls.create_only_vn(cls.left_vn_name,
                                                     cls.left_vn_subnets)

            # Right VN
            cls.right_vn_name = get_random_name('right_%s' % (
                                                 cls.inputs.project_name))
            cls.right_vn_subnets = [get_random_cidr(af=cls.inputs.get_af())]
            cls.right_vn_fixture = cls.create_only_vn(cls.right_vn_name,
                                                      cls.right_vn_subnets)
            #if cls.inputs.get_af() == 'v6':
            #    cls.left_vn_subnets += [get_random_cidr()]
            #    cls.right_vn_subnets += [get_random_cidr()]

            if not  hasattr(cls, 'image_name'):
                if cls.inputs.is_ci_setup() and cls.inputs.get_af() == 'v4':
                    cls.image_name = cls.inputs.get_ci_image()
                else:
                    cls.image_name = 'cirros-traffic'

            # End Vms
            cls.left_vm_name = get_random_name('left_vm_%s' % (
                                                cls.inputs.project_name))
            cls.left_vm_fixture = cls.create_only_vm(cls.left_vn_fixture,
                                                     vm_name=cls.left_vm_name,
                                                     image_name=cls.image_name)
            cls.right_vm_name = get_random_name('right_vm_%s' % (
                                                 cls.inputs.project_name))
            cls.right_vm_fixture = cls.create_only_vm(cls.right_vn_fixture,
                                                      vm_name=cls.right_vm_name,
                                                      image_name=cls.image_name)
        except:
            cls.tearDownClass()
            raise

        cls.common_args = { 'mgmt_vn_name' : cls.mgmt_vn_name,
                            'mgmt_vn_subnets' : cls.mgmt_vn_subnets,
                            'mgmt_vn_fixture' : cls.mgmt_vn_fixture,
                            'left_vn_name' : cls.left_vn_name,
                            'left_vn_subnets' : cls.left_vn_subnets,
                            'left_vn_fixture' : cls.left_vn_fixture,
                            'left_vm_name' : cls.left_vm_name,
                            'left_vm_fixture' : cls.left_vm_fixture,
                            'right_vn_name' : cls.right_vn_name,
                            'right_vn_subnets' : cls.right_vn_subnets,
                            'right_vn_fixture' : cls.right_vn_fixture,
                            'right_vm_name' : cls.right_vm_name,
                            'right_vm_fixture' : cls.right_vm_fixture,
                            'image_name' : cls.image_name }
コード例 #12
0
class PortFixture(vnc_api_test.VncLibFixture):
    '''Fixture to handle Port/VMI objects

    Mandatory:
    :param vn_id    : UUID of the VN

    Optional:
    :param fixed_ips : list of fixed ip dict
    :param mac_address
    :param security_groups
    :params extra_dhcp_opts
    :param api_type     : one of 'neutron'(default) or 'contrail'
    :param project_obj   : Project object which is to be the parent
                          object of this port
    :param vlan_id     : vlan id of sub-interface if any
    :param parent_vmi  : If this is sub-interface, instance of parent
                               VirtualMachineInterface

    Inherited parameters:
    :param domain   : default is default-domain
    :param project_name  : default is admin
    :param cfgm_ip  : default is 127.0.0.1
    :param api_port : default is 8082
    :param connections   : ContrailConnections object. default is None
    :param username : default is admin
    :param password : default is contrail123
    :param auth_server_ip : default is 127.0.0.1
    '''
    def __init__(self, *args, **kwargs):
        super(PortFixture, self).__init__(self, *args, **kwargs)
        self.vn_id = args[0]
        self.fixed_ips = kwargs.get('fixed_ips', [])
        self.mac_address = kwargs.get('mac_address', [])
        self.security_groups = kwargs.get('security_groups', [])
        self.extra_dhcp_opts = kwargs.get('extra_dhcp_opts', [])
        self.api_type = kwargs.get('api_type', 'neutron')
        self.project_obj = kwargs.get('project_obj', None)
        self.binding_profile = kwargs.get('binding_profile', None)
        self.vlan_id = kwargs.get('vlan_id', None)
        self.parent_vmi = kwargs.get('parent_vmi', None)
        self.vn_obj = None

    # end __init__

    def setUp(self):
        super(PortFixture, self).setUp()
        self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
        self.vn_obj = self.vnc_api_h.virtual_network_read(id=self.vn_id)

        if self.api_type == 'neutron':
            self._neutron_create_port()
        else:
            self._contrail_create_port()
        #Sandipd:This code was crashing while creating port as part of
        #vcenter gateway testing.Hence handled the exception as the mac
        #not needed to be obtained always,its passed as an argument to the fixture
        try:
            self.neutron_handle = self.get_neutron_handle()
            self.obj = self.neutron_handle.get_port(self.uuid)
            self.mac_address = self.obj['mac_address']
        except Exception as e:
            pass
        self.vmi_obj = self.vnc_api_h.virtual_machine_interface_read(
            id=self.uuid)
        self.logger.debug('Created port %s' % (self.uuid))

    def _neutron_create_port(self):
        if not self.neutron_handle:
            self.neutron_handle = self.get_neutron_handle()
        neutron_obj = self.neutron_handle.create_port(
            self.vn_id,
            fixed_ips=self.fixed_ips,
            mac_address=self.mac_address,
            security_groups=self.security_groups,
            extra_dhcp_opts=self.extra_dhcp_opts,
            binding_profile=self.binding_profile)
        self.neutron_obj = neutron_obj
        self.uuid = neutron_obj['id']

    def _contrail_create_port(self):
        vmi_props = vnc_api_test.VirtualMachineInterfacePropertiesType()

        if not self.project_obj:
            self.project_obj = self.vnc_api_h.project_read(id=self.project_id)
        vmi_id = str(uuid.uuid4())
        vmi_obj = vnc_api_test.VirtualMachineInterface(
            name=vmi_id, parent_obj=self.project_obj)
        if self.mac_address:
            mac_address_obj = vnc_api_test.MacAddressesType()
            mac_address_obj.set_mac_address([str(EUI(self.mac_address))])
            vmi_obj.set_virtual_machine_interface_mac_addresses(
                mac_address_obj)
        vmi_obj.uuid = vmi_id
        vmi_obj.add_virtual_network(self.vn_obj)

        if self.security_groups:
            for sg_id in self.security_groups:
                sg_obj = self.vnc_api_h.security_group_read(id=sg_id)
                vmi_obj.add_security_group(sg_obj)
        else:
            # Associate default SG
            default_sg_fq_name = self.project_obj.fq_name[:]
            default_sg_fq_name.append('default')
            sg_obj = self.vnc_api_h.security_group_read(
                fq_name=default_sg_fq_name)
            vmi_obj.add_security_group(sg_obj)

        if self.extra_dhcp_opts:
            # TODO
            pass

        if self.vlan_id:
            vmi_props.set_sub_interface_vlan_tag(int(self.vlan_id))

        if self.parent_vmi:
            vmi_obj.add_virtual_machine_interface(self.parent_vmi)

        if self.binding_profile:
            bind_kv = vnc_api_test.KeyValuePair(key='profile',
                                                value=str(
                                                    self.binding_profile))
            kv_pairs = vmi_obj.get_virtual_machine_interface_bindings() or\
                       vnc_api_test.KeyValuePairs()
            kv_pairs.add_key_value_pair(bind_kv)
            vmi_obj.set_virtual_machine_interface_bindings(kv_pairs)

        vmi_obj.set_virtual_machine_interface_properties(vmi_props)
        self.vmi_obj = self.vnc_api_h.virtual_machine_interface_create(vmi_obj)
        self.uuid = vmi_id

        if self.fixed_ips:
            for fixed_ip in self.fixed_ips:
                iip_id = str(uuid.uuid4())
                iip_obj = vnc_api_test.InstanceIp(
                    name=iip_id, subnet_id=fixed_ip['subnet_id'])
                iip_obj.uuid = iip_id
                iip_obj.add_virtual_machine_interface(vmi_obj)
                iip_obj.add_virtual_network(self.vn_obj)
                iip_obj.set_instance_ip_address(fixed_ip['ip_address'])
                self.vnc_api_h.instance_ip_create(iip_obj)
        else:
            iip_id = str(uuid.uuid4())
            iip_obj = vnc_api_test.InstanceIp(name=iip_id)
            iip_obj.uuid = iip_id
            iip_obj.add_virtual_machine_interface(vmi_obj)
            iip_obj.add_virtual_network(self.vn_obj)
            self.vnc_api_h.instance_ip_create(iip_obj)

    # end _contrail_create_port

    def cleanUp(self):
        super(PortFixture, self).cleanUp()
        if self.api_type == 'neutron':
            self._neutron_delete_port()
        else:
            self._contrail_delete_port()
        self.logger.info('Deleted port %s' % (self.uuid))

    def _neutron_delete_port(self):
        self.neutron_handle.delete_port(self.uuid)

    def _contrail_delete_port(self):
        vmi_iips = self.vmi_obj.get_instance_ip_back_refs()
        for vmi_iip in vmi_iips:
            vmi_iip_uuid = vmi_iip['uuid']
            self.vnc_api_h.instance_ip_delete(id=vmi_iip_uuid)
        self.vnc_api_h.virtual_machine_interface_delete(id=self.uuid)

    def verify_on_setup(self):
        if not self.verify_port_in_api_server():
            self.logger.error('VMI %s verification in API Server failed' %
                              self.uuid)
            return False
        else:
            self.logger.info('VMI %s verification in API Server passed' %
                             self.uuid)
        return True

    @retry(delay=2, tries=5)
    def verify_port_in_api_server(self):
        api_h = self.connections.api_server_inspect
        vmi = api_h.get_cs_vmi(self.uuid)
        if not vmi:
            self.logger.warn('Unable to fetch VMI %s from API server' %
                             self.uuid)
            return False
        if self.binding_profile:
            bindings = vmi.get_bindings()
            if bindings['profile'] != json.dumps(self.binding_profile):
                self.logger.warn(
                    'VMI binding profile doesnt match.'
                    'Expected %s actual %s for VMI %s' %
                    (self.binding_profile, bindings['profile'], self.uuid))
                return False
        return True

    def verify_port_in_control_node_ifmap(self):
        pass

    def verify_port_in_control_node(self):
        pass

    def verify_port_in_agent(self):
        pass

    def verify_port_in_agent_ifmap(self):
        pass

    def add_fat_flow(self, fat_flow_config):
        '''
        fat_flow_config: dictionary of format {'proto':<string>,'port':<int>}
        '''
        self.vnc_h.add_fat_flow_to_vmi(self.uuid, fat_flow_config)

        return True

    def remove_fat_flow(self, fat_flow_config):
        '''
        fat_flow_config: dictionary of format {'proto':<string>,'port':<int>}
        '''
        self.vnc_h.remove_fat_flow_on_vmi(self.uuid, fat_flow_config)

        return True

    def add_interface_route_table(self, intf_route_table_obj):
        '''
        Adds interface static routes to a port

        Args:
        intf_route_table_obj:  InterfaceRouteTable instance
        '''
        self.vnc_h.bind_vmi_to_interface_route_table(self.uuid,
                                                     intf_route_table_obj)

    # end add_interface_route_table

    def del_interface_route_table(self, intf_route_table_uuid):
        '''Unbind intf_route_table_obj from port
        intf_route_table_obj is InterfaceRouteTable instance
        '''
        self.vnc_h.unbind_vmi_from_interface_route_table(
            self.uuid, intf_route_table_uuid)

    # end del_interface_route_table

    def get_ip(self, subnet_id):
        fixed_ips = self.obj['fixed_ips']
        ip = [
            x['ip_address'] for x in fixed_ips if x['subnet_id'] == subnet_id
        ]
        if ip:
            return ip[0]
        else:
            return None
コード例 #13
0
ファイル: qos_fixture.py プロジェクト: sagarkchitnis/windows
 def setUp(self):
     super(QosBaseFixture, self).setUp()
     self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
     if self.connections:
         self.agent_inspect = self.connections.agent_inspect
コード例 #14
0
class TestRP(RPBase, BaseBGPaaS, BaseHC, VerifySvcFirewall):

    @classmethod
    def setUpClass(cls):
        super(TestRP, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestRP, cls).tearDownClass()

    def is_test_applicable(self):
        return (True, None)

    def setUp(self):
        super(TestRP, self).setUp()
        result = self.is_test_applicable()

    @test.attr(type=['sanity'])
    @preposttest_wrapper
    def test_rp_interface(self):
        '''
        1. Create a routing policy with interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'to_term':'community', 'sub_to':'64512:55555'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '55555'), 'Search term not found in introspect'
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)
         
    @test.attr(type=['sanity'])
    @preposttest_wrapper
    def test_rp_interface_static(self):
        '''
        1. Create a routing policy with interface-static match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict,random_cidr = self.create_interface_static_routes()
        config_dicts = {'vn_fixture':ret_dict['vn_fixture'], 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'community', 'sub_to':'64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(ret_dict['vn_fixture'], ret_dict['test_vm'], search_value = '55555', search_ip = random_cidr), 'Search term not found in introspect'
        assert ret_dict['test_vm'].ping_with_certainty(ret_dict['test2_vm'].vm_ip) 

    @preposttest_wrapper
    def test_rp_service_interface(self):
        '''
        1. Create a routing policy with service-interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        
        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True, max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {'vn_fixture':left_vn_fixture, 'from_term':'protocol', 'sub_from':'service-interface', 'to_term':'community', 'sub_to':'64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(self.vnc_lib.routing_instance_read(id = str(self.vnc_lib.virtual_network_read(id = left_vn_fixture.uuid).get_routing_instances()[1]['uuid'])).get_service_chain_information().service_chain_address), search_value = '55555')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)

    @preposttest_wrapper
    def test_rp_service_chain(self):
        '''
        1. Create a routing policy with service-chain match.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True, max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {'vn_fixture':left_vn_fixture, 'si_fixture':si_fixture, 'from_term':'protocol', 'sub_from':'service-chain', 'to_term':'community', 'sub_to':'64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(right_vm_fixture.vm_ip), search_value = '55555')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)

    @preposttest_wrapper
    def test_rp_bgpaas(self):
        '''
        1. Create a routing policy with bgpaas match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        
        ret_dict = self.create_bgpaas_routes()
        config_dicts = {'vn_fixture':ret_dict['vn_fixture'], 'from_term':'protocol', 'sub_from':'bgpaas', 'to_term':'community', 'sub_to':'64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        #will have to wait for bgp hold timer
        sleep(90)
        assert self.verify_policy_in_control(ret_dict['vn_fixture'], ret_dict['test_vm'], search_ip = str(ret_dict['vn_fixture'].get_subnets()[0]['cidr']), search_value = '55555')

    @test.attr(type=['sanity'])
    @preposttest_wrapper
    def test_rp_interface_ext_community(self):
        '''
        1. Create a routing policy with interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'to_term':'add_ext_community', 'sub_to':'target:64512:44444'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = 'target:64512:44444'), 'Search term not found in introspect'
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'to_term':'set_ext_community', 'sub_to':'target:64512:33333'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = 'target:64512:33333'), 'Search term not found in introspect'

    @preposttest_wrapper
    def test_rp_interface_static_ext_community(self):
        '''
        1. Create a routing policy with interface-static match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict,random_cidr = self.create_interface_static_routes()
        config_dicts = {'vn_fixture':ret_dict['vn_fixture'], 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'add_ext_community', 'sub_to':'target:64512:44444'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(ret_dict['vn_fixture'], ret_dict['test_vm'], search_value = 'target:64512:44444',search_ip = random_cidr), 'Search term not found in introspect'
        assert ret_dict['test_vm'].ping_with_certainty(ret_dict['test2_vm'].vm_ip) 
        config_dicts = {'vn_fixture':ret_dict['vn_fixture'], 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'set_ext_community', 'sub_to':'target:64512:33333'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(ret_dict['vn_fixture'], ret_dict['test_vm'], search_value = 'target:64512:33333',search_ip = random_cidr), 'Search term not found in introspect'
    
    @preposttest_wrapper
    def test_rp_service_interface_ext_community(self):
        '''
        1. Create a routing policy with service-interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        
        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True, max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {'vn_fixture':left_vn_fixture, 'from_term':'protocol', 'sub_from':'service-interface', 'to_term':'add_ext_community', 'sub_to':'target:64512:44444'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(self.vnc_lib.routing_instance_read(id = str(self.vnc_lib.virtual_network_read(id = left_vn_fixture.uuid).get_routing_instances()[1]['uuid'])).get_service_chain_information().service_chain_address), search_value = 'target:64512:44444')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)
        config_dicts = {'vn_fixture':left_vn_fixture, 'from_term':'protocol', 'sub_from':'service-interface', 'to_term':'set_ext_community', 'sub_to':'target:64512:33333'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(self.vnc_lib.routing_instance_read(id = str(self.vnc_lib.virtual_network_read(id = left_vn_fixture.uuid).get_routing_instances()[1]['uuid'])).get_service_chain_information().service_chain_address), search_value = 'target:64512:33333')
    
    @preposttest_wrapper
    def test_rp_service_chain_ext_community(self):
        '''
        1. Create a routing policy with service-chain match.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True, max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {'vn_fixture':left_vn_fixture, 'si_fixture':si_fixture, 'from_term':'protocol', 'sub_from':'service-chain', 'to_term':'add_ext_community', 'sub_to':'target:64512:44444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(right_vm_fixture.vm_ip), search_value = 'target:64512:44444')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)
        config_dicts = {'vn_fixture':left_vn_fixture, 'si_fixture':si_fixture, 'from_term':'protocol', 'sub_from':'service-chain', 'to_term':'set_ext_community', 'sub_to':'target:64512:33333'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(right_vm_fixture.vm_ip), search_value = 'target:64512:33333'), 'Search term not found in introspect'

    @preposttest_wrapper
    def test_rp_bgpaas_ext_community(self):
        '''
        1. Create a routing policy with bgpaas match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        
        ret_dict = self.create_bgpaas_routes()
        config_dicts = {'vn_fixture':ret_dict['vn_fixture'], 'from_term':'protocol', 'sub_from':'bgpaas', 'to_term':'add_ext_community', 'sub_to':'target:64512:44444'}
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(ret_dict['vn_fixture'], ret_dict['test_vm'], search_ip = str(ret_dict['vn_fixture'].get_subnets()[0]['cidr']), search_value = 'target:64512:44444')
        config_dicts = {'vn_fixture':ret_dict['vn_fixture'], 'from_term':'protocol', 'sub_from':'bgpaas', 'to_term':'set_ext_community', 'sub_to':'target:64512:44444'} 
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(ret_dict['vn_fixture'], ret_dict['test_vm'], search_ip = str(ret_dict['vn_fixture'].get_subnets()[0]['cidr']), search_value = 'target:64512:44444'), 'Search term not found in introspect'

    @preposttest_wrapper
    def test_rp_interface_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_interface_static_matrix(self):
        '''
        1. Create a routing policy with interface-static match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.intf_table_to_right_obj = self.static_table_handle.create_route_table(
            prefixes=[random_cidr],
            name=get_random_name('int_table_right'),
            parent_obj=self.project.project_obj,
        )
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + vn_fixture.vn_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(test_vm.get_vmi_ids()[id_entry]),
            self.intf_table_to_right_obj)
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface-static', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_service_interface_matrix(self):
        '''
        1. Create a routing policy with service-interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True, max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']

        config_dicts = {'vn_fixture':left_vn_fixture, 'from_term':'protocol', 'sub_from':'service-interface', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(self.vnc_lib.routing_instance_read(id = str(self.vnc_lib.virtual_network_read(id = left_vn_fixture.uuid).get_routing_instances()[1]['uuid'])).get_service_chain_information().service_chain_address), search_value = '444')
        config_dicts = {'vn_fixture':left_vn_fixture, 'from_term':'protocol', 'sub_from':'service-interface', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(self.vnc_lib.routing_instance_read(id = str(self.vnc_lib.virtual_network_read(id = left_vn_fixture.uuid).get_routing_instances()[1]['uuid'])).get_service_chain_information().service_chain_address), search_value = '555')
        config_dicts = {'vn_fixture':left_vn_fixture, 'from_term':'protocol', 'sub_from':'service-interface', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(self.vnc_lib.routing_instance_read(id = str(self.vnc_lib.virtual_network_read(id = left_vn_fixture.uuid).get_routing_instances()[1]['uuid'])).get_service_chain_information().service_chain_address), search_value = '666')

    @preposttest_wrapper
    def test_rp_bgpaas_matrix(self):
        '''
        1. Create a routing policy with bgpaas match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        vn_name = get_random_name('bgpaas_vn')
        vn_subnets = [get_random_cidr()]
        vn_fixture = self.create_vn(vn_name, vn_subnets)
        test_vm = self.create_vm(vn_fixture, 'test_vm',
                                 image_name='ubuntu-traffic')
        assert test_vm.wait_till_vm_is_up()
        bgpaas_vm1 = self.create_vm(vn_fixture, 'bgpaas_vm1',image_name='vsrx')
        assert bgpaas_vm1.wait_till_vm_is_up()
        bgpaas_fixture = self.create_bgpaas(bgpaas_shared=True, autonomous_system=64500, bgpaas_ip_address=bgpaas_vm1.vm_ip)
        bgpaas_vm1.wait_for_ssh_on_vm()
        port1 = {}
        port1['id'] = bgpaas_vm1.vmi_ids[bgpaas_vm1.vn_fq_name]
        address_families = []
        address_families = ['inet', 'inet6']
        autonomous_system = 64500
        gw_ip = vn_fixture.get_subnets()[0]['gateway_ip']
        dns_ip = vn_fixture.get_subnets()[0]['dns_server_address']
        neighbors = []
        neighbors = [gw_ip, dns_ip]
        self.logger.info('We will configure BGP on the two vSRX')
        self.config_bgp_on_vsrx(src_vm=test_vm, dst_vm=bgpaas_vm1, bgp_ip=bgpaas_vm1.vm_ip, lo_ip=bgpaas_vm1.vm_ip,
                                address_families=address_families, autonomous_system=autonomous_system, neighbors=neighbors, bfd_enabled=False)
        bgpaas_vm1.wait_for_ssh_on_vm()
        self.attach_vmi_to_bgpaas(port1['id'], bgpaas_fixture)
        self.addCleanup(self.detach_vmi_from_bgpaas,port1['id'], bgpaas_fixture)
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'bgpaas', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = str(vn_fixture.get_subnets()[0]['cidr']), search_value = '444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'bgpaas', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = str(vn_fixture.get_subnets()[0]['cidr']), search_value = '555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'bgpaas', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = str(vn_fixture.get_subnets()[0]['cidr']), search_value = '666')

    @preposttest_wrapper
    def test_rp_service_chain_matrix(self):
        '''
        1. Create a routing policy with service-chain match.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True, max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {'vn_fixture':left_vn_fixture, 'si_fixture':si_fixture, 'si_fixture':si_fixture, 'from_term':'protocol', 'sub_from':'service-chain', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(right_vm_fixture.vm_ip), search_value = '444')
        config_dicts = {'vn_fixture':left_vn_fixture, 'si_fixture':si_fixture, 'si_fixture':si_fixture, 'from_term':'protocol', 'sub_from':'service-chain', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(right_vm_fixture.vm_ip), search_value = '555')
        config_dicts = {'vn_fixture':left_vn_fixture, 'si_fixture':si_fixture, 'si_fixture':si_fixture, 'from_term':'protocol', 'sub_from':'service-chain', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture, left_vm_fixture, search_ip = str(right_vm_fixture.vm_ip), search_value = '666')

    @preposttest_wrapper
    def test_rp_xmpp_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'xmpp', 'to_term':'community', 'sub_to':'64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '55555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'xmpp', 'to_term':'add_ext_community', 'sub_to':'target:64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = 'target:64512:55555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'xmpp', 'to_term':'set_ext_community', 'sub_to':'target:64512:44444'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = 'target:64512:44444'), 'Search term not found in introspect'
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'xmpp', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'xmpp', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'xmpp', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = '666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_network_static_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.nw_handle_to_right = self.static_table_handle.create_route_table(
                prefixes=[random_cidr],
                name="network_table_left_to_right",
                next_hop=test_vm.vm_ip,
                parent_obj=self.project.project_obj,
                next_hop_type='ip-address',
                route_table_type='network',
            )
        self.static_table_handle.bind_network_route_table_to_vn(
                vn_uuid=vn_fixture.uuid,
                nw_route_table_obj=self.nw_handle_to_right)

        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'community', 'sub_to':'64512:55555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '55555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'add_ext_community', 'sub_to':'target:64512:44444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = 'target:64512:44444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'set_ext_community', 'sub_to':'target:64512:33333'} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = 'target:64512:33333'), 'Search term not found in introspect'
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'med', 'sub_to':'444'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '444')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'local-preference', 'sub_to':'555'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '555')
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'static', 'to_term':'as-path', 'sub_to':'666'}
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_ip = random_cidr, search_value = '666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_ext_community_list_match_all_reject(self):
        '''
        1. Create a routing policy with ext_community_list ,interface match and then reject.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'from_term_community':'ext_community_list', 'sub_from_community':['encapsulation:gre','encapsulation:udp'], 'action': 'reject', 'to_term': None} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = 'RoutingPolicyReject'), 'Search term not found in introspect'
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'from_term_community':'ext_community_list', 'sub_from_community':['encapsulation:gre','encapsulation:udp'], 'action': 'reject', 'to_term': None, 'match_all': True} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture, test_vm, search_value = 'RoutingPolicyReject'), 'Search term not found in introspect'
        #give wrong communinty value and check match_all
        config_dicts = {'vn_fixture':vn_fixture, 'from_term':'protocol', 'sub_from':'interface', 'from_term_community':'ext_community_list', 'sub_from_community':['encapsulation:gre','encapsulation:uuup'], 'action': 'reject', 'to_term': None, 'match_all': True} 
        rp = self.configure_term_routing_policy(config_dicts)
        assert not self.verify_policy_in_control(vn_fixture, test_vm, search_value = 'RoutingPolicyReject'), 'Search term found in introspect'

    def create_interface_static_routes(self):
        ret_dict = self.config_basic()
        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.intf_table_to_right_obj = self.static_table_handle.create_route_table(
            prefixes=[random_cidr],
            name=get_random_name('int_table_right'),
            parent_obj=self.project.project_obj,
        )
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + ret_dict['vn_fixture'].vn_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(ret_dict['test_vm'].get_vmi_ids()[id_entry]),
            self.intf_table_to_right_obj)
        return ret_dict,random_cidr

    def create_bgpaas_routes(self):
        ret_dict = {}
        vn_name = get_random_name('bgpaas_vn')
        vn_subnets = [get_random_cidr()]
        ret_dict['vn_fixture'] = self.create_vn(vn_name, vn_subnets)
        ret_dict['test_vm'] = self.create_vm(ret_dict['vn_fixture'], 'test_vm',
                                 image_name='ubuntu-traffic')
        assert ret_dict['test_vm'].wait_till_vm_is_up()
        bgpaas_vm1 = self.create_vm(ret_dict['vn_fixture'], 'bgpaas_vm1',image_name='vsrx')
        assert bgpaas_vm1.wait_till_vm_is_up()
        bgpaas_fixture = self.create_bgpaas(bgpaas_shared=True, autonomous_system=64500, bgpaas_ip_address=bgpaas_vm1.vm_ip)
        bgpaas_vm1.wait_for_ssh_on_vm()
        port1 = {}
        port1['id'] = bgpaas_vm1.vmi_ids[bgpaas_vm1.vn_fq_name]
        address_families = []
        address_families = ['inet', 'inet6']
        autonomous_system = 64500
        gw_ip = ret_dict['vn_fixture'].get_subnets()[0]['gateway_ip']
        dns_ip = ret_dict['vn_fixture'].get_subnets()[0]['dns_server_address']
        neighbors = []
        neighbors = [gw_ip, dns_ip]
        self.logger.info('We will configure BGP on the two vSRX')
        self.config_bgp_on_vsrx(src_vm=ret_dict['test_vm'], dst_vm=bgpaas_vm1, bgp_ip=bgpaas_vm1.vm_ip, lo_ip=bgpaas_vm1.vm_ip,
                                address_families=address_families, autonomous_system=autonomous_system, neighbors=neighbors, bfd_enabled=False)
        bgpaas_vm1.wait_for_ssh_on_vm()
        self.attach_vmi_to_bgpaas(port1['id'], bgpaas_fixture)
        self.addCleanup(self.detach_vmi_from_bgpaas,port1['id'], bgpaas_fixture)
        return ret_dict
コード例 #15
0
ファイル: orchestrator.py プロジェクト: Ankitja/contrail-test
class Orchestrator:
   """Base class for orchestrator."""

   __metaclass__ = ABCMeta

   def __init__(self, inputs, vnc_api_h, logger=None):
       self.inputs = inputs
       self.logger = logger or logging.getLogger(__name__)
       self.vnc_h = ContrailVncApi(vnc_api_h, logger)

   def is_feature_supported(self, feature):
       return True

   @abstractmethod
   def get_image_account(self, image_name):
       '''Returns username, password for the image.'''
       pass

   @abstractmethod
   def get_image_name_for_zone(self, image_name='ubuntu', zone='nova'):
       '''Get image name compatible with zone '''
       pass

   @abstractmethod
   def get_flavor(self, flavor):
       '''Installs and Returns Flavor ID.'''
       pass

   @abstractmethod
   def get_default_image_flavor(self, image_name):
       '''Returns Flavor ID for an image.'''
       pass

   @abstractmethod
   def get_image(self, image):
       '''Installs and Returns Image ID.'''
       pass

   @abstractmethod
   def get_hosts(self, zone=None):
       '''Returns a list of computes.'''
       pass

   @abstractmethod
   def get_zones(self):
       '''Returns a list of zones/clusters into which computes are grouped.'''
       pass

   @abstractmethod
   def create_vm(self, vm_name, image_name, vn_objs, count=1, zone=None, node_name=None, **kwargs):
       '''Returns a list of VM objects else None.'''
       pass

   @abstractmethod
   def delete_vm(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def get_host_of_vm(self, vm_obj, **kwargs):
       '''Returns name of the compute, on which the VM was created.'''
       pass

   @abstractmethod
   def get_networks_of_vm(self, vm_obj, **kwargs):
       '''Returns names of the networks, associated with the VM.'''
       pass

   @abstractmethod
   def get_vm_if_present(self, vm_name, **kwargs):
       pass

   @abstractmethod
   def get_vm_by_id(self, vm_id, **kwargs):
       pass

   @abstractmethod
   def get_vm_list(self, name_pattern='', **kwargs):
       '''Returns a list of VM object matching pattern.'''
       pass 
   
   @abstractmethod
   def get_vm_detail(self, vm_obj, **kwargs):
       '''Refreshes VM object.'''
       pass

   @abstractmethod
   def get_vm_ip(self, vm_obj, vn_name, **kwargs):
       '''Returns a list of IP of VM in VN.'''
       pass

   @abstractmethod
   def is_vm_deleted(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def wait_till_vm_is_active(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def wait_till_vm_status(self, vm_obj, status, **kwargs):
       pass

   @abstractmethod
   def get_console_output(self, vm_obj, **kwargs):
       pass

   @abstractmethod
   def get_key_file(self):
       '''Returns the key file path.'''
       pass

   @abstractmethod
   def put_key_file_to_host(self, host_ip):
       '''Copy RSA key to host.'''
       pass

   @abstractmethod
   def create_vn(self, vn_name, subnets, **kwargs):
       pass

   @abstractmethod
   def delete_vn(self, vn_obj, **kwargs):
       pass

   @abstractmethod
   def get_vn_obj_if_present(self, vn_name, **kwargs):
       pass

   @abstractmethod
   def get_vn_name(self, vn_obj, **kwargs):
       pass

   @abstractmethod
   def get_vn_id(self, vn_obj, **kwargs):
       pass

   def get_vn_list(self, **kwargs):
       return self.vnc_h.get_vn_list(**kwargs)

   def get_policy(self, fq_name, **kwargs):
       return self.vnc_h.get_policy(fq_name, **kwargs)

   def get_floating_ip(self, fip_id, **kwargs):
       return self.vnc_h.get_floating_ip(fip_id, **kwargs)

   def create_floating_ip(self, pool_vn_id, pool_obj, project_obj, **kwargs):
       return self.vnc_h.create_floating_ip( pool_obj, project_obj,
                                            **kwargs)

   def delete_floating_ip(self, fip_id, **kwargs):
       return self.vnc_h.delete_floating_ip(fip_id, **kwargs)

   def assoc_floating_ip(self, fip_id, vm_id, **kwargs):
       return self.vnc_h.assoc_floating_ip(fip_id, vm_id, **kwargs)

   def disassoc_floating_ip(self, fip_id, **kwargs):
       return self.vnc_h.disassoc_floating_ip(fip_id, **kwargs)

   def add_security_group(self, vm_id, sg_id, **kwargs):
       return self.vnc_h.add_security_group(vm_id, sg_id, **kwargs)

   def set_security_group(self, vm_id, sg_ids, **kwargs):
       return self.vnc_h.set_security_group(vm_id, sg_ids, **kwargs)

   def remove_security_group(self, vm_id, sg_id, **kwargs):
       return self.vnc_h.remove_security_group(vm_id, sg_id, **kwargs)

   def create_security_group(self, sg_name, parent_fqname, sg_entries, **kwargs):
       return self.vnc_h.create_security_group(sg_name, parent_fqname,
                                               sg_entries, **kwargs)

   def delete_security_group(self, sg_id, **kwargs):
       return self.vnc_h.delete_security_group(sg_id, **kwargs)

   def get_security_group(self, sg_id, **kwargs):
       return self.vnc_h.get_security_group(sg_id, **kwargs)

   def get_security_group_rules(self, sg_id, **kwargs):
       return self.vnc_h.get_security_group_rules(sg_id, **kwargs)

   def delete_security_group_rules(self, sg_id, **kwargs):
       return self.vnc_h.delete_security_group_rules(sg_id, **kwargs)

   def set_security_group_rules(self, sg_id, **kwargs):
       return self.vnc_h.set_security_group_rules(sg_id, **kwargs)
コード例 #16
0
class ContrailPlugApi(object):
    def __init__(self, inputs, vnc, logger):
        self._inputs = inputs
        self._vnc = vnc
        self.logger = logger
        self._ipam_obj = self._get_ipam_object()
        self._gw = self._process_vcenter_gateway_info()
        self.vnc_h = ContrailVncApi(self._vnc, self.logger)

    def _get_project_object(self):
        return self._vnc.project_read(fq_name = self._inputs.project_fq_name)

    def _get_ipam_object(self):
        return self._vnc.network_ipam_read(
                fq_name=['default-domain', 'default-project', 'default-network-ipam'])

    def create_network_in_contrail_cluster(self,name,subnet,**kwargs):
        self.vn_uuid = self._create_vn(name,subnet)
        return self.vn_uuid

    def delete_network_from_contrail_cluster(self,vn_name,**kwargs):
        return self._delete_vn(vn_name)

    def delete_vmi_and_detach_vmi_to_lif(self,vm):
        self.delete_lif(vm)        
        self._delete_vmi(vm) 

    def delete_lif(self,vm):
        self._delete_lif(vm)

    def create_vmobj_in_api_server(self,vm_obj):
        vm_uuid = vm_obj.id 
        try:
            self.vnc_h.create_virtual_machine(vm_uuid=vm_uuid)
        except Exception as e:
            self.logger.error("VM object create in api failed for vm id %s"%(vm_uuid)) 
            raise
        vm_api_obj = self._vnc.virtual_machine_read(id=vm_obj.id)
        for port in vm_obj.ports:
            port_uuid = port.uuid
            port_obj = self._vnc.virtual_machine_interface_read(id=port_uuid)
            port_obj.set_virtual_machine(vm_api_obj)
            self._vnc.virtual_machine_interface_update(port_obj)
    
    def delete_vmobj_in_api_server(self,vm_obj):
        vm_uuid = vm_obj.id 
        try:
            self.vnc_h.delete_virtual_machine(vm_uuid=vm_uuid)
        except Exception as e:
            self.logger.error("VM object delete in api failed for vm id %s"%(vm_uuid)) 

    def create_vmi_lif_and_attach_vmi_to_lif(self,vn_name,mac_address,vlan,vm=None):
        vn_obj = self._read_vn(vn_name) 
        vn_id = vn_obj.uuid
        #create vmi
        port = self._create_vmi(vn_id=vn_id,mac_address=mac_address,
                    vm=vm )
        #for each vrouter gateway port , create lif 
        for gw in self._gw:
            for phy_port in gw.ports:
                lif_name = phy_port + '.' + str(vlan)
                pif_id = gw.get_port_uuid(phy_port,inputs=self._inputs)  
                self._create_lif(lif_name,vlan,pif_id,vm=vm,vmi_ids = [port.uuid])

    def _create_vn(self, vn_name, vn_subnet):

        self._proj_obj = self._get_project_object()
        vn_obj = VirtualNetwork(vn_name, parent_obj=self._proj_obj)
        for pfx in vn_subnet:
            px = pfx['cidr'].split('/')[0]
            pfx_len = int(pfx['cidr'].split('/')[1])
            subnet_vnc = IpamSubnetType(subnet=SubnetType(px, pfx_len))
            vnsn_data = VnSubnetsType([subnet_vnc])
            vn_obj.add_network_ipam(self._ipam_obj, vnsn_data)
        try:
            return self._vnc.virtual_network_create(vn_obj)
        except RefsExistError:
            pass

    def _delete_vn(self, vn_name):
        self._proj_obj = self._get_project_object()
        vn_fq_name = VirtualNetwork(vn_name, self._proj_obj).get_fq_name()
        try:
            self._vnc.virtual_network_delete(fq_name=vn_fq_name)
            return True
        except cfgm_common.exceptions.NoIdError:
            return True
    # end _delete_vn
 
    def _read_vn(self,vn_name):
        self._proj_obj = self._get_project_object()
        vn_fq_name = VirtualNetwork(vn_name, self._proj_obj).get_fq_name()
        try:
            vn_obj = self._vnc.virtual_network_read(fq_name=vn_fq_name)
        except cfgm_common.exceptions.NoIdError:
            pass
        return vn_obj

    def _create_lif(self,name,vlan,pif_id,vmi_ids=[],vm=None):
        lif_obj = LogicalInterfaceFixture(
        name, pif_id=pif_id, vlan_id=vlan,vmi_ids=vmi_ids,inputs=self._inputs)
        lif_obj.setUp()
        if vm:
            vm.lifs.append(lif_obj)

    def _delete_lif(self,vm):
        for lif in vm.lifs:
            lif.cleanUp()

    def _create_vmi(self,vn_id,mac_address,
                     fixed_ips=[],security_groups=[],
                     extra_dhcp_opts=[],
                     project_obj=None,vm=None):
        self._proj_obj = self._get_project_object()
        port = PortFixture(vn_id=vn_id,
                                api_type='contrail',
                                mac_address=mac_address,
                                fixed_ips=fixed_ips,
                                extra_dhcp_opts=extra_dhcp_opts,
                                project_obj=self._proj_obj,
                                security_groups=security_groups,inputs=self._inputs)
        port.setUp()
        if vm:
            vm.ports.append(port)
        return port

    def _delete_vmi(self,vm):
        for port in vm.ports:
            port.cleanUp()

    def _process_vcenter_gateway_info(self):
        return [VcenterGateway(gw) for gw in self._inputs.vcenter_gateway]
コード例 #17
0
ファイル: alarm_test.py プロジェクト: Ankitja/contrail-test
class AlarmFixture(fixtures.Fixture):

    ''' Fixture to create and verify and delete alarms.
        Create AlarmFixture object
    '''

    def __init__(self, connections, alarm_name=None, uve_keys=[], alarm_severity=None,
                 alarm_rules=None, operand1=None, operand2=None, description=None, variables=None,
                 id_perms=None, perms2=None, display_name=None, parent_obj_type='project',
                 clean_up=True, project_name=None, project_fixture=None):
        self.connections = connections
        self.inputs = connections.inputs
        self.logger = self.connections.logger
        self.vnc_lib_h = self.connections.get_vnc_lib_h()
        self.vnc_h = ContrailVncApi(self.vnc_lib_h, self.logger)
        self.api_s_inspect = self.connections.api_server_inspect
        self.analytics_obj = self.connections.analytics_obj
        self.alarm_name = alarm_name
        self.alarm_id = None
        self.alarm_fq_name = [self.inputs.domain_name, self.alarm_name]
        self.uve_keys = uve_keys
        self.alarm_severity = alarm_severity
        self.alarm_rules = alarm_rules
        self.operand1 = operand1
        self.operand2 = operand2
        self.description = description
        self.variables = variables
        self.id_perms = id_perms
        self.perms2 = perms2
        self.display_name = display_name
        self.parent_obj_type = parent_obj_type
        self.domain_name = self.connections.domain_name
        self.project_name = project_name or self.connections.project_name
        self.project_fixture = project_fixture
        if self.project_fixture:
            self.project_name = self.project_fixture.project_name
        self.project_id = self.connections.get_project_id()
        self.parent_obj = None
        self.clean_up = clean_up
        self.obj = None
        self.created = False
        if self.inputs.verify_thru_gui():
            from webui_test import WebuiTest
            self.webui = WebuiTest(self.connections, self.inputs)
    # end __init__

    def read(self):
        if self.alarm_id:
            self.alarm_obj = self.vnc_h.get_alarm(self.alarm_id)
            self.alarm_fq_name = self.get_fq_name()
            self.alarm_name = self.alarm_obj.name
    # end read

    def setUp(self):
        super(AlarmFixture, self).setUp()
    # end setup

    def create(self, alarm_rules):
        self.alarm_rules = alarm_rules
        self.alarm_id = self.alarm_id or self.get_alarm_id()
        if self.alarm_id:
            self.read()
            self.logger.debug("alarm already present not creating" %
                              (self.alarm_name, self.alarm_id))
        else:
            self.logger.debug(" creating alarm : %s", self.alarm_name)
            if self.parent_obj_type == 'global':
                self.parent_obj = self.vnc_h.get_global_config_obj()
            if self.parent_obj_type == 'project':
                if not self.project_fixture:
                    self.project_fixture = self.useFixture(
                        ProjectFixture(project_name=self.project_name,
                                       connections=self.connections))
                self.parent_obj = self.project_fixture.getObj()
            if not self.parent_obj:
                raise AmbiguousParentError(
                    "[[u'default-global-system-config'], [u'default-domain', u'default-project']]")
            if not self.alarm_rules:
                self.alarm_rules = self.create_alarm_rules()
            uve_keys_type = UveKeysType(self.uve_keys)
            if self.inputs.is_gui_based_config():
                self.alarms = self.webui.create_alarms(self)
            else:
                self.alarm_id = self.vnc_h.create_alarm(name=self.alarm_name, parent_obj=self.parent_obj,
                                   alarm_rules=self.alarm_rules, alarm_severity=self.alarm_severity,
                                   uve_keys=uve_keys_type)
                # need to set rules and other parameters before passing alarm_obj
                self.alarm_obj = self.vnc_h.get_alarm(self.alarm_id)
                self.alarm_fq_name = self.get_fq_name()
            self.created = True
    # end create

    def create_expression(self, params_dict):
        return AlarmExpression(params_dict=params_dict)
    # end create_expression

    def create_and_list(self, and_list):
        return AlarmAndList(and_list=and_list)
    # end create_and_list

    def create_or_list(self, or_list):
        return AlarmOrList(or_list=or_list)
    # end create_or_list

    def configure_alarm_rules(self, params_dict_list, multi_or_conditions=False):
        '''configure single or multiple rules'''
        self.alarm_exp_list = []
        self.alarm_and_list = []
        self.alarm_or_list = []
        try:
            for params_dict in params_dict_list:
                alarm_exp = self.create_expression(params_dict)
                self.alarm_exp_list.append(alarm_exp)
            if multi_or_conditions:
                for alarm_exp in self.alarm_exp_list:
                    alarm_and = self.create_and_list([alarm_exp])
                    self.alarm_and_list.append(alarm_and)
            else:
                self.alarm_and_list.append(
                    self.create_and_list(self.alarm_exp_list))
            self.alarm_or_list = self.create_or_list(self.alarm_and_list)
            return self.alarm_or_list
        except:
            self.logger.warn('error configuring alarm')
    # end configure_alarm_rules

    def getObj(self):
        return self.alarm_obj
    # end getObj

    def set_display_name(self, display_name):
        self.display_name = display_name
        self.alarm_obj.set_display_name(display_name)
        self.vnc_h.update_alarm(self.alarm_obj)
    # end set_display_name

    def get_display_name(self):
        return self.alarm_obj.get_display_name()
    # end get_display_name

    def get_alarm_id(self):
        if not self.alarm_id:
            try:
                alarm_obj = self.vnc_h.get_alarm(self.alarm_fq_name)
                if alarm_obj:
                    self.alarm_id = alarm_obj.uuid
                    return self.alarm_id
            except:
                return None
    # end get_alarm_id


    def set_alarm_rules(self, exp_list, multi_or_conditions=False):
        rules = self.configure_alarm_rules(
            exp_list, multi_or_conditions=multi_or_conditions)
        try:
            if rules:
                self.alarm_obj.set_alarm_rules(rules)
                self.vnc_h.update_alarm(self.alarm_obj)
                return True
        except:
            self.logger.warn('Setting alarm_rules Failed')
            return None
    # end set_alarm_rules

    def set_alarm_enable(self, enable):
        pass

    def set_alarm_disable(self):
        pass

    def get_alarm_severity(self):
        return self.alarm_severity
    # end get_alarm_severity

    def set_alarm_severity(self, severity):
        try:
            self.alarm_severity = severity
            self.alarm_obj.set_alarm_severity(severity)
            self.vnc_h.update_alarm(self.alarm_obj)
            return True
        except :
            self.logger.warn('Setting alarm Severity Failed')
            return None
    # set_alarm_severity

    def set_uve_keys(self, uve_key):
        try:
            self.uve_keys = uve_key
            uve_key_type = UveKeysType(uve_key)
            self.alarm_obj.set_uve_keys(uve_key_type)
            self.vnc_h.update_alarm(self.alarm_obj)
            return True
        except :
            self.logger.warn('Setting UVE keys Failed')
            return None
    # set_uve_keys

    def get_uve_keys(self):
        return self.uve_keys
    # end get_uve_keys
    
    def get_fq_name(self):
        obj = self.getObj()
        fq_name = obj.get_fq_name()
        return ':'.join(fq_name)

    def verify_alarm_in_api_server(self):
        self.cs_alarm = self.api_s_inspect.get_cs_alarm(
                alarm_id=self.alarm_id)
        if not self.cs_alarm:
            self.logger.warn(
                'Alarm config of %s not present in api server' % self.alarm_name)
            return False
        self.logger.info(
            'Alarm config of %s present in the api-server' % self.alarm_name)
        return True
    # end verify_alarm_in_api_server

    def verify_alarm_configuration(self):
        alarm_config = self.cs_alarm
        alarm = alarm_config.get('alarm')
        name = alarm.get('display_name')
        if not (name == self.alarm_name):
            self.logger.warn('Alarm name is missing in the config')
            return False
        uve_keys_dict = alarm.get('uve_keys')
        uve_keys = uve_keys_dict.get('uve_key')
        if not (uve_keys == self.uve_keys):
            self.logger.warn('Uve_keys not present or doesn\'t match %s %s' % (
                uve_keys, self.uve_keys))
            return False
        rules = alarm.get('alarm_rules')
        if not rules:
            self.logger.warn('Rules are not present in config')
            return False
        self.logger.info('Alarm %s configured properly ' %self.alarm_name)
        return True
    # end verify_alarm_configuration

    @retry(delay=3, tries=10)
    def verify_alarm_not_in_api_server(self):
        cs_alarm = self.api_s_inspect.get_cs_alarm(
            alarm_id=self.alarm_id)
        if cs_alarm:
            errmsg = 'Alarm %s not removed from api-server' % self.alarm_name
            self.logger.warn(errmsg)
            return False
        self.logger.info('Alarm %s removed from api-server' % self.alarm_name)
        return True
    # end verify_alarm_not_in_api_server

    def verify_on_setup(self):
        '''Verify alarm in configuration '''
        result = True
        result = self.verify_alarm_in_api_server()
        if not result:
            self.logger.error(
                'Verification of %s config in api-server failed' % self.alarm_name)
            return result
        result = self.verify_alarm_configuration()
        if not result:
            self.logger.error('Alarm %s not configured properly' %self.alarm_name)
            return result
        return True
    # end verify_alarm_setup

    def cleanUp(self):
        super(AlarmFixture, self).cleanUp()
        do_cleanup = True
        if self.inputs.fixture_cleanup == 'no':
            do_cleanup = False
        if not self.created:
            do_cleanup = False
        if self.inputs.fixture_cleanup == 'force':
            do_cleanup = True
        if self.clean_up == False:
            do_cleanup = False
        if do_cleanup:
            if self.inputs.is_gui_based_config():
                self.webui.delete_alarms(self)
            else:
                self._delete_alarm()
                self.logger.info('Deleted alarm %s' % self.alarm_name)
                assert self.verify_alarm_not_in_api_server()
        else:
            self.logger.debug('Skippping deletion of alarm %s' %
                              self.alarm_name)
    # end cleanup

    def _delete_alarm(self, verify=False):
        self.vnc_h.delete_alarm(self.alarm_id)
コード例 #18
0
class ContrailPlugApi(object):
    def __init__(self, inputs, vnc, logger):
        self._inputs = inputs
        self._vnc = vnc
        self.logger = logger
        self._proj_obj = self._get_project_object()
        self._ipam_obj = self._get_ipam_object()
        self._gw = self._process_vcenter_gateway_info()
        self.vnc_h = ContrailVncApi(self._vnc, self.logger)

    def _get_project_object(self):
        return self._vnc.project_read(fq_name = self._inputs.project_fq_name)

    def _get_ipam_object(self):
        return self._vnc.network_ipam_read(
                fq_name=['default-domain', 'default-project', 'default-network-ipam'])

    def create_network_in_contrail_cluster(self,name,subnet,**kwargs):
        self.vn_uuid = self._create_vn(name,subnet)
        pass

    def delete_network_from_contrail_cluster(self,vn_name,**kwargs):
        self._delete_vn(vn_name)
        pass

    def delete_vmi_and_detach_vmi_to_lif(self,vm):
        self.delete_lif(vm)        
        self._delete_vmi(vm) 

    def delete_lif(self,vm):
        self._delete_lif(vm)

    def create_vmobj_in_api_server(self,vm_obj):
        vm_uuid = vm_obj.id 
        try:
            self.vnc_h.create_virtual_machine(vm_uuid=vm_uuid)
        except Exception as e:
            self.logger.error("VM object create in api failed for vm id %s"%(vm_uuid)) 
            raise
        vm_api_obj = self._vnc.virtual_machine_read(id=vm_obj.id)
        for port in vm_obj.ports:
            port_uuid = port.uuid
            port_obj = self._vnc.virtual_machine_interface_read(id=port_uuid)
            port_obj.set_virtual_machine(vm_api_obj)
            self._vnc.virtual_machine_interface_update(port_obj)
    
    def delete_vmobj_in_api_server(self,vm_obj):
        vm_uuid = vm_obj.id 
        try:
            self.vnc_h.delete_virtual_machine(vm_uuid=vm_uuid)
        except Exception as e:
            self.logger.error("VM object delete in api failed for vm id %s"%(vm_uuid)) 

    def create_vmi_lif_and_attach_vmi_to_lif(self,vn_name,mac_address,vlan,vm=None):
        vn_obj = self._read_vn(vn_name) 
        vn_id = vn_obj.uuid
        #create vmi
        port = self._create_vmi(vn_id=vn_id,mac_address=mac_address,
                    vm=vm )
        #for each vrouter gateway port , create lif 
        for gw in self._gw:
            for phy_port in gw.ports:
                lif_name = phy_port + '.' + str(vlan)
                pif_id = gw.get_port_uuid(phy_port)  
                self._create_lif(lif_name,vlan,pif_id,vm=vm,vmi_ids = [port.uuid])

    def _create_vn(self, vn_name, vn_subnet):

        vn_obj = VirtualNetwork(vn_name, parent_obj=self._proj_obj)
        for pfx in vn_subnet:
            px = pfx['cidr'].split('/')[0]
            pfx_len = int(pfx['cidr'].split('/')[1])
            subnet_vnc = IpamSubnetType(subnet=SubnetType(px, pfx_len))
            vnsn_data = VnSubnetsType([subnet_vnc])
            vn_obj.add_network_ipam(self._ipam_obj, vnsn_data)
        try:
            self._vnc.virtual_network_create(vn_obj)
        except RefsExistError:
            pass

    def _delete_vn(self, vn_name):
        vn_fq_name = VirtualNetwork(vn_name, self._proj_obj).get_fq_name()
        try:
            self._vnc.virtual_network_delete(fq_name=vn_fq_name)
        except cfgm_common.exceptions.NoIdError:
            pass
    # end _delete_vn
 
    def _read_vn(self,vn_name):
        vn_fq_name = VirtualNetwork(vn_name, self._proj_obj).get_fq_name()
        try:
            vn_obj = self._vnc.virtual_network_read(fq_name=vn_fq_name)
        except cfgm_common.exceptions.NoIdError:
            pass
        return vn_obj

    def _create_lif(self,name,vlan,pif_id,vmi_ids=[],vm=None):
        lif_obj = LogicalInterfaceFixture(
        name, pif_id=pif_id, vlan_id=vlan,vmi_ids=vmi_ids)
        lif_obj.setUp()
        if vm:
            vm.lifs.append(lif_obj)

    def _delete_lif(self,vm):
        for lif in vm.lifs:
            lif.cleanUp()

    def _create_vmi(self,vn_id,mac_address,
                     fixed_ips=[],security_groups=[],
                     extra_dhcp_opts=[],
                     project_obj=None,vm=None):
        port = PortFixture(vn_id,
                                api_type='contrail',
                                mac_address=mac_address,
                                fixed_ips=fixed_ips,
                                extra_dhcp_opts=extra_dhcp_opts,
                                project_obj=self._proj_obj,
                                security_groups=security_groups)
        port.setUp()
        if vm:
            vm.ports.append(port)
        return port

    def _delete_vmi(self,vm):
        for port in vm.ports:
            port.cleanUp()

    def _process_vcenter_gateway_info(self):
        return [VcenterGateway(gw) for gw in self._inputs.vcenter_gateway]
コード例 #19
0
ファイル: base.py プロジェクト: Ankitja/contrail-test
 def setUp(self):
     super(StaticRouteTableBase, self).setUp()
     self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
コード例 #20
0
 def __init__(self, inputs, vnc_api_h, logger=None):
     self.inputs = inputs
     self.logger = logger or logging.getLogger(__name__)
     self.vnc_h = ContrailVncApi(vnc_api_h, logger)
コード例 #21
0
 def __init__(self, *args, **kwargs):
     super(VirtualRouterBase, self).__init__(*args, **kwargs)
     self.name = args[0]
     self.virtual_router_type = args[1]
     self.vr = None
     self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
コード例 #22
0
    def test_rp_network_static_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.nw_handle_to_right = self.static_table_handle.create_route_table(
            prefixes=[random_cidr],
            name="network_table_left_to_right",
            next_hop=test_vm.vm_ip,
            parent_obj=self.project.project_obj,
            next_hop_type='ip-address',
            route_table_type='network',
        )
        self.static_table_handle.bind_network_route_table_to_vn(
            vn_uuid=vn_fixture.uuid,
            nw_route_table_obj=self.nw_handle_to_right)

        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='55555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='target:64512:44444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:33333'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture,
            test_vm,
            search_ip=random_cidr,
            search_value='target:64512:33333'
        ), 'Search term not found in introspect'
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)
コード例 #23
0
class TestRP(RPBase, BaseBGPaaS, BaseHC, VerifySvcFirewall):
    @classmethod
    def setUpClass(cls):
        super(TestRP, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestRP, cls).tearDownClass()

    def is_test_applicable(self):
        return (True, None)

    def setUp(self):
        super(TestRP, self).setUp()
        result = self.is_test_applicable()

    @test.attr(type=['sanity'])
    @preposttest_wrapper
    def test_rp_interface(self):
        '''
        1. Create a routing policy with interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture, test_vm,
            search_value='55555'), 'Search term not found in introspect'
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @test.attr(type=['sanity'])
    @preposttest_wrapper
    def test_rp_interface_static(self):
        '''
        1. Create a routing policy with interface-static match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict, random_cidr = self.create_interface_static_routes()
        config_dicts = {
            'vn_fixture': ret_dict['vn_fixture'],
            'from_term': 'protocol',
            'sub_from': 'interface-static',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            ret_dict['vn_fixture'],
            ret_dict['test_vm'],
            search_value='55555',
            search_ip=random_cidr), 'Search term not found in introspect'
        assert ret_dict['test_vm'].ping_with_certainty(
            ret_dict['test2_vm'].vm_ip)

    @preposttest_wrapper
    def test_rp_service_interface(self):
        '''
        1. Create a routing policy with service-interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True,
                                         max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-interface',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            left_vn_fixture,
            left_vm_fixture,
            search_ip=str(
                self.vnc_lib.routing_instance_read(id=str(
                    self.vnc_lib.virtual_network_read(id=left_vn_fixture.uuid).
                    get_routing_instances()[1]['uuid'])).
                get_service_chain_information().service_chain_address),
            search_value='55555')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)

    @preposttest_wrapper
    def test_rp_service_chain(self):
        '''
        1. Create a routing policy with service-chain match.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True,
                                         max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'si_fixture': si_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-chain',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture,
                                             left_vm_fixture,
                                             search_ip=str(
                                                 right_vm_fixture.vm_ip),
                                             search_value='55555')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)

    @test.attr(type=['sanity'])
    @skip_because(mx_gw=False)
    @preposttest_wrapper
    def test_rp_secondary_routes(self):
        '''
        Maintainer: [email protected]
        Description: CEM-6735 - Enhanced import policy extended to MP-BGP route type
        To verify: routing-policy to change routing-parameters for secondary routes ( routes from External Devices )
        1. Create VN and add MXs route-target to VN , to import route from MX into VN.
        2. Retrieve the local-preference advertised by MX.
        3. Create routing-policy to change local-preference and attach to VN
        4. Verify updated routing-policy is applied to secondary routes from MX and local-preference value is set to new value mentioned through routing-policy.
        '''

        vm1_name = get_random_name('vm_private')
        vn1_name = get_random_name('vn_private')
        vn1_subnets = [get_random_cidr()]
        self.allow_default_sg_to_allow_all_on_project(self.inputs.project_name)
        vn1_fixture = self.create_vn(vn1_name, vn1_subnets)
        mx_rt = self.inputs.mx_rt

        if self.inputs.config['test_configuration'].get('router_asn', False):
            router_asn = self.inputs.config['test_configuration'].get(
                'router_asn')
        else:
            router_asn = self.inputs.bgp_asn

        vn1_fixture.add_route_target(routing_instance_name=vn1_fixture.ri_name,
                                     router_asn=router_asn,
                                     route_target_number=mx_rt)
        vn1_fixture.verify_on_setup()
        vm1_fixture = self.create_vm(vn1_fixture,
                                     vm1_name,
                                     image_name='ubuntu')
        vm1_fixture.wait_till_vm_is_up()
        initial_local_pref = -1
        new_local_pref = -1
        for cn in self.inputs.bgp_control_ips:
            cn_entries = self.cn_inspect[cn].get_cn_route_table_entry(
                prefix="0.0.0.0/0",
                table="inet.0",
                ri_name=vn1_fixture.ri_name)
            if cn_entries:
                initial_local_pref = int(cn_entries[0]['local_preference'])
        if initial_local_pref == -1:
            assert False, "Default route 0.0.0.0/0 is not advertised by MX.Check the MX routing-instance configurations."
        config_dicts = {
            'vn_fixture': vn1_fixture,
            'from_term': 'protocol',
            'sub_from': 'bgp',
            'to_term': 'local-preference',
            'sub_to': initial_local_pref + 10
        }
        rp = self.configure_term_routing_policy(config_dicts)
        time.sleep(10)
        for cn in self.inputs.bgp_control_ips:
            cn_entries = self.cn_inspect[cn].get_cn_route_table_entry(
                prefix="0.0.0.0/0",
                table="inet.0",
                ri_name=vn1_fixture.ri_name)
            if cn_entries:
                new_local_pref = int(cn_entries[0]['local_preference'])
        self.logger.info(
            "Old local-preference: %d , New local-preference: %d" %
            (initial_local_pref, new_local_pref))
        if new_local_pref != initial_local_pref + 10:
            assert False, "Error: Routing-Policy not applied on Secondary routes from MX and Local Preference is not updated"
        self.logger.info(
            "PASS: routing-policy is applied correctly for secondary-routes from MX"
        )

    @skip_because(mx_gw=False)
    @preposttest_wrapper
    def test_rp_secondary_routes_si(self):
        '''
        Maintainer: [email protected]
        Description: CEM-6735 - Enhanced import policy extended to MP-BGP route type. Policy should not be applied on MP-BGP external routes in SC scenario.
        To verify:
            Apply rp to update local_preference and attach to SI.Verify only primary routes are updated with local_preference value in RP and secondary SC routes
            are not affected.
        1. Create in-network SC and attach MX's RT to left-vn , to import route from MX to VN.
        2. Create Routing Policy to modify local_preference and attach to SI.
        3. Verify SC secondary routes ( routes from MX ) are not updated with local_preference from RP.
        4. Verify SC Primary routes ( right-vm route on left-service instance vrf ) is updated with local_preference from RP.
        '''

        self.allow_default_sg_to_allow_all_on_project(self.inputs.project_name)
        mx_rt = self.inputs.mx_rt

        if self.inputs.config['test_configuration'].get('router_asn', False):
            router_asn = self.inputs.config['test_configuration'].get(
                'router_asn')
        else:
            router_asn = self.inputs.bgp_asn

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True,
                                         max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        left_svn_fixture = ret_dict['si_left_vn_fixture']
        left_vn_fixture.add_route_target(
            routing_instance_name=left_vn_fixture.ri_name,
            router_asn=router_asn,
            route_target_number=mx_rt)
        right_vm_ip = ret_dict['right_vm_fixture'].vm_ip
        left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip, count='3')

        initial_local_pref_bgp_route = -1
        new_local_pref_bgp_route = -1
        initial_local_pref_sc_route = -1
        new_local_pref_sc_route = -1
        for cn in self.inputs.bgp_control_ips:
            cn_entries = self.cn_inspect[cn].get_cn_route_table_entry(
                prefix="0.0.0.0/0",
                table="inet.0",
                ri_name=left_svn_fixture.ri_name)
            if cn_entries:
                initial_local_pref_bgp_route = int(
                    cn_entries[0]['local_preference'])
            cn_entries = self.cn_inspect[cn].get_cn_route_table_entry(
                prefix=right_vm_ip + "/32",
                table="inet.0",
                ri_name=left_svn_fixture.ri_name)
            if cn_entries:
                initial_local_pref_sc_route = int(
                    cn_entries[0]['local_preference'])
        if initial_local_pref_bgp_route == -1:
            assert False, "Default route 0.0.0.0/0 is not advertised by MX.Check the MX routing-instance configurations."

        local_pref_config = initial_local_pref_bgp_route + 10
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'si_rp_interface_type': ['left_vn', 'right_vn'],
            'si_fixture': si_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-chain',
            'to_term': 'local-preference',
            'sub_to': local_pref_config
        }
        rp = self.configure_term_routing_policy(config_dicts)
        time.sleep(10)
        for cn in self.inputs.bgp_control_ips:
            cn_entries = self.cn_inspect[cn].get_cn_route_table_entry(
                prefix="0.0.0.0/0",
                table="inet.0",
                ri_name=left_svn_fixture.ri_name)
            if cn_entries:
                new_local_pref_bgp_route = int(
                    cn_entries[0]['local_preference'])
            cn_entries = self.cn_inspect[cn].get_cn_route_table_entry(
                prefix=right_vm_ip + "/32",
                table="inet.0",
                ri_name=left_svn_fixture.ri_name)
            if cn_entries:
                new_local_pref_sc_route = int(
                    cn_entries[0]['local_preference'])

        self.logger.info(
            "BGP Route: Old local-preference: %d , New local-preference: %d" %
            (initial_local_pref_bgp_route, new_local_pref_bgp_route))
        self.logger.info(
            "Primary Route: Old local-preference: %d , New local-preference: %d"
            % (initial_local_pref_sc_route, new_local_pref_sc_route))
        if new_local_pref_bgp_route != initial_local_pref_bgp_route:
            assert False, "Error: Routing-Policy applied on SI-Secondary routes from MX and Local Preference is updated.Expected not to apply rp on Secondary routes in SC."

        if new_local_pref_sc_route != local_pref_config:
            assert False, "Error: Routing-Policy NOT applied on SC-Primary routes."

        self.logger.info(
            "PASS: routing-policy is NOT applied ,as expected , for SC secondary-routes from MX."
        )
        self.logger.info(
            "PASS: routing-policy is applied ,as expected , for SC Primary-routes."
        )

    @preposttest_wrapper
    def test_rp_bgpaas(self):
        '''
        1. Create a routing policy with bgpaas match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.create_bgpaas_routes()
        config_dicts = {
            'vn_fixture': ret_dict['vn_fixture'],
            'from_term': 'protocol',
            'sub_from': 'bgpaas',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        #will have to wait for bgp hold timer
        sleep(90)
        assert self.verify_policy_in_control(
            ret_dict['vn_fixture'],
            ret_dict['test_vm'],
            search_ip=str(ret_dict['vn_fixture'].get_subnets()[0]['cidr']),
            search_value='55555')

    @test.attr(type=['sanity'])
    @preposttest_wrapper
    def test_rp_interface_ext_community(self):
        '''
        1. Create a routing policy with interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture, test_vm, search_value='target:64512:44444'
        ), 'Search term not found in introspect'
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:33333'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture, test_vm, search_value='target:64512:33333'
        ), 'Search term not found in introspect'

    @preposttest_wrapper
    def test_rp_interface_static_ext_community(self):
        '''
        1. Create a routing policy with interface-static match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict, random_cidr = self.create_interface_static_routes()
        config_dicts = {
            'vn_fixture': ret_dict['vn_fixture'],
            'from_term': 'protocol',
            'sub_from': 'interface-static',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            ret_dict['vn_fixture'],
            ret_dict['test_vm'],
            search_value='target:64512:44444',
            search_ip=random_cidr), 'Search term not found in introspect'
        assert ret_dict['test_vm'].ping_with_certainty(
            ret_dict['test2_vm'].vm_ip)
        config_dicts = {
            'vn_fixture': ret_dict['vn_fixture'],
            'from_term': 'protocol',
            'sub_from': 'interface-static',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:33333'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            ret_dict['vn_fixture'],
            ret_dict['test_vm'],
            search_value='target:64512:33333',
            search_ip=random_cidr), 'Search term not found in introspect'

    @preposttest_wrapper
    def test_rp_service_interface_ext_community(self):
        '''
        1. Create a routing policy with service-interface match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True,
                                         max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-interface',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            left_vn_fixture,
            left_vm_fixture,
            search_ip=str(
                self.vnc_lib.routing_instance_read(id=str(
                    self.vnc_lib.virtual_network_read(id=left_vn_fixture.uuid).
                    get_routing_instances()[1]['uuid'])).
                get_service_chain_information().service_chain_address),
            search_value='target:64512:44444')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-interface',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:33333'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            left_vn_fixture,
            left_vm_fixture,
            search_ip=str(
                self.vnc_lib.routing_instance_read(id=str(
                    self.vnc_lib.virtual_network_read(id=left_vn_fixture.uuid).
                    get_routing_instances()[1]['uuid'])).
                get_service_chain_information().service_chain_address),
            search_value='target:64512:33333')

    @preposttest_wrapper
    def test_rp_service_chain_ext_community(self):
        '''
        1. Create a routing policy with service-chain match.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True,
                                         max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'si_fixture': si_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-chain',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture,
                                             left_vm_fixture,
                                             search_ip=str(
                                                 right_vm_fixture.vm_ip),
                                             search_value='target:64512:44444')
        assert left_vm_fixture.ping_with_certainty(right_vm_fixture.vm_ip)
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'si_fixture': si_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-chain',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:33333'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            left_vn_fixture,
            left_vm_fixture,
            search_ip=str(right_vm_fixture.vm_ip),
            search_value='target:64512:33333'
        ), 'Search term not found in introspect'

    @preposttest_wrapper
    def test_rp_bgpaas_ext_community(self):
        '''
        1. Create a routing policy with bgpaas match.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.create_bgpaas_routes()
        config_dicts = {
            'vn_fixture': ret_dict['vn_fixture'],
            'from_term': 'protocol',
            'sub_from': 'bgpaas',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(
            ret_dict['vn_fixture'],
            ret_dict['test_vm'],
            search_ip=str(ret_dict['vn_fixture'].get_subnets()[0]['cidr']),
            search_value='target:64512:44444')
        config_dicts = {
            'vn_fixture': ret_dict['vn_fixture'],
            'from_term': 'protocol',
            'sub_from': 'bgpaas',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(
            ret_dict['vn_fixture'],
            ret_dict['test_vm'],
            search_ip=str(ret_dict['vn_fixture'].get_subnets()[0]['cidr']),
            search_value='target:64512:44444'
        ), 'Search term not found in introspect'

    @preposttest_wrapper
    def test_rp_interface_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_interface_static_matrix(self):
        '''
        1. Create a routing policy with interface-static match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.intf_table_to_right_obj = self.static_table_handle.create_route_table(
            prefixes=[random_cidr],
            name=get_random_name('int_table_right'),
            parent_obj=self.project.project_obj,
        )
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + vn_fixture.vn_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(test_vm.get_vmi_ids()[id_entry]), self.intf_table_to_right_obj)
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface-static',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface-static',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface-static',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_service_interface_matrix(self):
        '''
        1. Create a routing policy with service-interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True,
                                         max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']

        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-interface',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            left_vn_fixture,
            left_vm_fixture,
            search_ip=str(
                self.vnc_lib.routing_instance_read(id=str(
                    self.vnc_lib.virtual_network_read(id=left_vn_fixture.uuid).
                    get_routing_instances()[1]['uuid'])).
                get_service_chain_information().service_chain_address),
            search_value='444')
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-interface',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            left_vn_fixture,
            left_vm_fixture,
            search_ip=str(
                self.vnc_lib.routing_instance_read(id=str(
                    self.vnc_lib.virtual_network_read(id=left_vn_fixture.uuid).
                    get_routing_instances()[1]['uuid'])).
                get_service_chain_information().service_chain_address),
            search_value='555')
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-interface',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            left_vn_fixture,
            left_vm_fixture,
            search_ip=str(
                self.vnc_lib.routing_instance_read(id=str(
                    self.vnc_lib.virtual_network_read(id=left_vn_fixture.uuid).
                    get_routing_instances()[1]['uuid'])).
                get_service_chain_information().service_chain_address),
            search_value='666')

    @preposttest_wrapper
    def test_rp_bgpaas_matrix(self):
        '''
        1. Create a routing policy with bgpaas match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.create_bgpaas_routes()
        vn_fixture = ret_dict["vn_fixture"]
        test_vm = ret_dict["test_vm"]
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'bgpaas',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(
            vn_fixture,
            test_vm,
            search_ip=str(vn_fixture.get_subnets()[0]['cidr']),
            search_value='444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'bgpaas',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(
            vn_fixture,
            test_vm,
            search_ip=str(vn_fixture.get_subnets()[0]['cidr']),
            search_value='555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'bgpaas',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        sleep(90)
        assert self.verify_policy_in_control(
            vn_fixture,
            test_vm,
            search_ip=str(vn_fixture.get_subnets()[0]['cidr']),
            search_value='666')

    @preposttest_wrapper
    def test_rp_service_chain_matrix(self):
        '''
        1. Create a routing policy with service-chain match.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.verify_svc_chain(service_mode='in-network',
                                         create_svms=True,
                                         max_inst=1)
        si_fixture = ret_dict['si_fixture']
        left_vm_fixture = ret_dict['left_vm_fixture']
        right_vm_fixture = ret_dict['right_vm_fixture']
        left_vn_fixture = ret_dict['left_vn_fixture']
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'si_fixture': si_fixture,
            'si_fixture': si_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-chain',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture,
                                             left_vm_fixture,
                                             search_ip=str(
                                                 right_vm_fixture.vm_ip),
                                             search_value='444')
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'si_fixture': si_fixture,
            'si_fixture': si_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-chain',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture,
                                             left_vm_fixture,
                                             search_ip=str(
                                                 right_vm_fixture.vm_ip),
                                             search_value='555')
        config_dicts = {
            'vn_fixture': left_vn_fixture,
            'si_fixture': si_fixture,
            'si_fixture': si_fixture,
            'from_term': 'protocol',
            'sub_from': 'service-chain',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(left_vn_fixture,
                                             left_vm_fixture,
                                             search_ip=str(
                                                 right_vm_fixture.vm_ip),
                                             search_value='666')

    @preposttest_wrapper
    def test_rp_xmpp_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'xmpp',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='55555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'xmpp',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='target:64512:55555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'xmpp',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture, test_vm, search_value='target:64512:44444'
        ), 'Search term not found in introspect'
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'xmpp',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'xmpp',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'xmpp',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_value='666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_network_static_matrix(self):
        '''
        1. Create a routing policy with interface match and different "to" conditions:med, as-path, local-pref, community.
        2. Launch VMs.
        3. Attach policy to VN and confirm if policy takes hold.
        '''

        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']

        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.nw_handle_to_right = self.static_table_handle.create_route_table(
            prefixes=[random_cidr],
            name="network_table_left_to_right",
            next_hop=test_vm.vm_ip,
            parent_obj=self.project.project_obj,
            next_hop_type='ip-address',
            route_table_type='network',
        )
        self.static_table_handle.bind_network_route_table_to_vn(
            vn_uuid=vn_fixture.uuid,
            nw_route_table_obj=self.nw_handle_to_right)

        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'community',
            'sub_to': '64512:55555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='55555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'add_ext_community',
            'sub_to': 'target:64512:44444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='target:64512:44444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'set_ext_community',
            'sub_to': 'target:64512:33333'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture,
            test_vm,
            search_ip=random_cidr,
            search_value='target:64512:33333'
        ), 'Search term not found in introspect'
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'med',
            'sub_to': '444'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='444')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'local-preference',
            'sub_to': '555'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='555')
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'static',
            'to_term': 'as-path',
            'sub_to': '666'
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(vn_fixture,
                                             test_vm,
                                             search_ip=random_cidr,
                                             search_value='666')
        assert test_vm.ping_with_certainty(test2_vm.vm_ip)

    @preposttest_wrapper
    def test_rp_ext_community_list_match_all_reject(self):
        '''
        1. Create a routing policy with ext_community_list ,interface match and then reject.
        2. Launch VMs. 
        3. Attach policy to VN and confirm if policy takes hold. 
        '''
        ret_dict = self.config_basic()
        vn_fixture = ret_dict['vn_fixture']
        test_vm = ret_dict['test_vm']
        test2_vm = ret_dict['test2_vm']
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'from_term_community': 'ext_community_list',
            'sub_from_community': ['encapsulation:gre', 'encapsulation:udp'],
            'action': 'reject',
            'to_term': None
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture, test_vm, search_value='RoutingPolicyReject'
        ), 'Search term not found in introspect'
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'from_term_community': 'ext_community_list',
            'sub_from_community': ['encapsulation:gre', 'encapsulation:udp'],
            'action': 'reject',
            'to_term': None,
            'match_all': True
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert self.verify_policy_in_control(
            vn_fixture, test_vm, search_value='RoutingPolicyReject'
        ), 'Search term not found in introspect'
        #give wrong communinty value and check match_all
        config_dicts = {
            'vn_fixture': vn_fixture,
            'from_term': 'protocol',
            'sub_from': 'interface',
            'from_term_community': 'ext_community_list',
            'sub_from_community': ['encapsulation:gre', 'encapsulation:uuup'],
            'action': 'reject',
            'to_term': None,
            'match_all': True
        }
        rp = self.configure_term_routing_policy(config_dicts)
        assert not self.verify_policy_in_control(
            vn_fixture, test_vm, search_value='RoutingPolicyReject'
        ), 'Search term found in introspect'

    def create_interface_static_routes(self):
        ret_dict = self.config_basic()
        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)
        random_cidr = get_random_cidr()
        self.intf_table_to_right_obj = self.static_table_handle.create_route_table(
            prefixes=[random_cidr],
            name=get_random_name('int_table_right'),
            parent_obj=self.project.project_obj,
        )
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + ret_dict['vn_fixture'].vn_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(ret_dict['test_vm'].get_vmi_ids()[id_entry]),
            self.intf_table_to_right_obj)
        return ret_dict, random_cidr

    def create_bgpaas_routes(self):
        ret_dict = {}
        vn_name = get_random_name('bgpaas_vn')
        vn_subnets = [get_random_cidr()]
        ret_dict['vn_fixture'] = self.create_vn(vn_name, vn_subnets)
        ret_dict['test_vm'] = self.create_vm(ret_dict['vn_fixture'],
                                             'test_vm',
                                             image_name='ubuntu-traffic')
        assert ret_dict['test_vm'].wait_till_vm_is_up()
        bgpaas_vm1 = self.create_vm(ret_dict['vn_fixture'],
                                    'bgpaas_vm1',
                                    image_name='ubuntu-bird')
        assert bgpaas_vm1.wait_till_vm_is_up()
        bgpaas_fixture = self.create_bgpaas(bgpaas_shared=True,
                                            autonomous_system=64500,
                                            bgpaas_ip_address=bgpaas_vm1.vm_ip)
        bgpaas_vm1.wait_for_ssh_on_vm()
        port1 = {}
        port1['id'] = bgpaas_vm1.vmi_ids[bgpaas_vm1.vn_fq_name]
        address_families = []
        address_families = ['inet', 'inet6']
        autonomous_system = 64500
        gw_ip = ret_dict['vn_fixture'].get_subnets()[0]['gateway_ip']
        dns_ip = ret_dict['vn_fixture'].get_subnets()[0]['dns_server_address']
        neighbors = []
        neighbors = [gw_ip, dns_ip]
        self.logger.info('Configuring BGP on the bird vm')
        static_routes = []
        static_routes.append({
            "network":
            ret_dict['vn_fixture'].get_subnets()[0]['cidr'],
            "nexthop":
            "blackhole"
        })
        self.config_bgp_on_bird(bgpaas_vm=bgpaas_vm1,
                                local_ip=bgpaas_vm1.vm_ip,
                                peer_ip=gw_ip,
                                peer_as=self.inputs.bgp_asn,
                                local_as=autonomous_system,
                                static_routes=static_routes)
        self.attach_vmi_to_bgpaas(port1['id'], bgpaas_fixture)
        self.addCleanup(self.detach_vmi_from_bgpaas, port1['id'],
                        bgpaas_fixture)
        return ret_dict
コード例 #24
0
ファイル: base.py プロジェクト: Ankitja/contrail-test
class StaticRouteTableBase(BaseNeutronTest):

    @classmethod
    def setUpClass(cls):
        super(StaticRouteTableBase, cls).setUpClass()
        cls.quantum_h = cls.connections.quantum_h
        cls.nova_h = cls.connections.nova_h
        cls.vnc_lib = cls.connections.vnc_lib
        cls.agent_inspect = cls.connections.agent_inspect
        cls.cn_inspect = cls.connections.cn_inspect
        cls.analytics_obj = cls.connections.analytics_obj
        #cls.vnc = ContrailVncApi(cls.vnc_lib, cls.logger)
    # end setUpClass

    @classmethod
    def tearDownClass(cls):
        super(StaticRouteTableBase, cls).tearDownClass()
    # end tearDownClass

    def setUp(self):
        super(StaticRouteTableBase, self).setUp()
        self.static_table_handle = ContrailVncApi(self.vnc_lib, self.logger)

    def tearDown(self):
        super(StaticRouteTableBase, self).tearDown()

    # create 3 vms, left, right middle. middle should sit in both vns
    def config_basic(self):
        self.vn1_fixture = self.create_vn(disable_dns=True)
        self.vn2_fixture = self.create_vn(disable_dns=True)
        self.vn1_name = self.vn1_fixture.vn_name
        self.vn2_name = self.vn2_fixture.vn_name
        self.left_vm_fixture = self.create_vm(self.vn1_fixture)
        self.right_vm_fixture = self.create_vm(self.vn2_fixture)
        self.left_vm_fixture.wait_till_vm_is_up()
        self.right_vm_fixture.wait_till_vm_is_up()

        vm1_name = 'middle_vm1'

        self.vm1_fixture = self.useFixture(VMFixture(
            project_name=self.inputs.project_name, connections=self.connections,
            vn_objs=[self.vn1_fixture.obj,
                     self.vn2_fixture.obj], vm_name=vm1_name, node_name=None,
            image_name='ubuntu', flavor='m1.tiny'))
        self.vm1_fixture.wait_till_vm_is_up()
        cmd = 'echo 1 > /proc/sys/net/ipv4/ip_forward'
        self.vm1_fixture.run_cmd_on_vm(cmds=[cmd], as_sudo=True)

    # create int route table and bind it to the middle vm's vmi's
    def add_interface_route_table(self, src_vn_fix, dst_vn_fix, port1_fix):
        self.intf_table_to_right_obj = self.static_table_handle.create_route_table(
            prefixes=[str(dst_vn_fix.get_cidrs()[0])],
            name="int_table_right",
            parent_obj=self.project.project_obj,
        )
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + self.vn1_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(port1_fix.get_vmi_ids()[id_entry]),
            self.intf_table_to_right_obj)

        self.intf_table_to_left_obj = self.static_table_handle.create_route_table(
            prefixes=[str(src_vn_fix.get_cidrs()[0])],
            name="int_table_left",
            parent_obj=self.project.project_obj,
        )
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + self.vn2_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(port1_fix.get_vmi_ids()[id_entry]),
            self.intf_table_to_left_obj)

    # delete the created int route table
    def delete_int_route_table(self):
        self.unbind_interface_table(self.vn1_fixture, self.vn2_fixture, self.vm1_fixture)
        self.static_table_handle.delete_interface_route_table(
            self.intf_table_to_right_obj.uuid)
        self.static_table_handle.delete_interface_route_table(
            self.intf_table_to_left_obj.uuid)

    # attach the net route table to vn provided
    def add_network_table_to_vn(self, vn1_fix, vn2_fix):

        if str(self.vm1_fixture.vm_ips[0])[:-1] == str(self.right_vm_fixture.vm_ip)[:-1]:
            self.nw_handle_to_left = self.static_table_handle.create_route_table(
                prefixes=[str(self.vn1_fixture.get_cidrs()[0])],
                name="network_table_left_to_right",
                next_hop=self.vm1_fixture.vm_ips[0],
                parent_obj=self.project.project_obj,
                next_hop_type='ip-address',
                route_table_type='network',
            )
            self.static_table_handle.bind_network_route_table_to_vn(
                vn_uuid=vn2_fix.uuid,
                nw_route_table_obj=self.nw_handle_to_left)
        else:
            self.nw_handle_to_right = self.static_table_handle.create_route_table(
                prefixes=[str(self.vn2_fixture.get_cidrs()[0])],
                name="network_table_left_to_right",
                next_hop=self.vm1_fixture.vm_ips[
                    0],
                parent_obj=self.project.project_obj,
                next_hop_type='ip-address',
                route_table_type='network',
            )
            self.static_table_handle.bind_network_route_table_to_vn(
                vn_uuid=vn1_fix.uuid,
                nw_route_table_obj=self.nw_handle_to_right)
        if str(self.vm1_fixture.vm_ips[1])[:-1] == str(self.right_vm_fixture.vm_ip)[:-1]:
            self.nw_handle_to_left = self.static_table_handle.create_route_table(
                prefixes=[str(self.vn1_fixture.get_cidrs()[0])],
                name="network_table_right_to_left",
                next_hop=self.vm1_fixture.vm_ips[
                    1],
                parent_obj=self.project.project_obj,
                next_hop_type='ip-address',
                route_table_type='network',
            )
            self.static_table_handle.bind_network_route_table_to_vn(
                vn_uuid=vn2_fix.uuid,
                nw_route_table_obj=self.nw_handle_to_left)
        else:
            self.nw_handle_to_right = self.static_table_handle.create_route_table(
                prefixes=[str(self.vn2_fixture.get_cidrs()[0])],
                name="network_table_right_to_left",
                next_hop=self.vm1_fixture.vm_ips[
                    1],
                parent_obj=self.project.project_obj,
                next_hop_type='ip-address',
                route_table_type='network',
            )
            self.static_table_handle.bind_network_route_table_to_vn(
                vn_uuid=vn1_fix.uuid,
                nw_route_table_obj=self.nw_handle_to_right)

    # delete net route table
    def del_nw_route_table(self):

        self.unbind_network_table(self.vn1_fixture, self.vn2_fixture)
        self.static_table_handle.delete_network_route_table(
            self.nw_handle_to_right.uuid)
        self.static_table_handle.delete_network_route_table(
            self.nw_handle_to_left.uuid)

    # unbind the int route table from the port provided
    def unbind_interface_table(self, src_vn_fix, dst_vn_fix, port1_fix):

        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + self.vn1_name
        self.static_table_handle.unbind_vmi_from_interface_route_table(
            str(port1_fix.get_vmi_ids()[id_entry]),
            self.intf_table_to_right_obj)

        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + self.vn2_name
        self.static_table_handle.unbind_vmi_from_interface_route_table(
            str(port1_fix.get_vmi_ids()[id_entry]),
            self.intf_table_to_left_obj)

    # bind a int route table to the port provided
    def bind_interface_table(self, src_vn_fix, dst_vn_fix, port1_fix):
        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + self.vn1_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(port1_fix.get_vmi_ids()[id_entry]),
            self.intf_table_to_right_obj)

        id_entry = self.inputs.project_fq_name[0] + ':' + \
            self.inputs.project_fq_name[1] + ':' + self.vn2_name
        self.static_table_handle.bind_vmi_to_interface_route_table(
            str(port1_fix.get_vmi_ids()[id_entry]),
            self.intf_table_to_left_obj)

    # unbind the net route table from the vn provided
    def unbind_network_table(self, src_vn_fix, dst_vn_fix):
        self.static_table_handle.unbind_vn_from_network_route_table(
            src_vn_fix.uuid,
            self.nw_handle_to_right)
        self.static_table_handle.unbind_vn_from_network_route_table(
            dst_vn_fix.uuid,
            self.nw_handle_to_left)

    # bind the net route table to the vn provided
    def bind_network_table(self, src_vn_fix, dst_vn_fix):
        self.static_table_handle.bind_network_route_table_to_vn(
            vn_uuid=src_vn_fix.uuid,
            nw_route_table_obj=self.nw_handle_to_right)
        self.static_table_handle.bind_network_route_table_to_vn(
            vn_uuid=dst_vn_fix.uuid,
            nw_route_table_obj=self.nw_handle_to_left)

    # create a neutron router in addition to the static tables
    def neutron_router_test(self):
        router_dict = self.create_router('neutron_router')
        self.add_vn_to_router(router_dict['id'], self.vn1_fixture)
        self.add_vn_to_router(router_dict['id'], self.vn2_fixture)
        router_ports = self.quantum_h.get_router_interfaces(
            router_dict['id'])
        router_port_ips = [item['fixed_ips'][0]['ip_address']
                           for item in router_ports]
        assert self.left_vm_fixture.ping_with_certainty(
            self.right_vm_fixture.vm_ip)
        self.delete_vn_from_router(router_dict['id'], self.vn1_fixture)
        assert self.left_vm_fixture.ping_with_certainty(
            self.right_vm_fixture.vm_ip)
        self.add_vn_to_router(
            router_dict['id'],
            self.vn1_fixture,
            cleanup=False)
        assert self.left_vm_fixture.ping_with_certainty(
            self.right_vm_fixture.vm_ip)

    # check the number of nexthops for the right route in left table
    def check_route_in_agent(self, expected_next_hops):

        (domain, project, vn) = self.vn1_fixture.vn_fq_name.split(':')
        inspect_h = self.agent_inspect[self.left_vm_fixture.vm_node_ip]
        agent_vrf_objs = inspect_h.get_vna_vrf_objs(domain, project, vn)
        agent_vrf_obj = self.left_vm_fixture.get_matching_vrf(
            agent_vrf_objs['vrf_list'], self.vn1_fixture.vrf_name)
        vn_vrf_id = agent_vrf_obj['ucindex']
        cidr_prefix = str(self.vn2_fixture.get_cidrs()[0]).split('/')
        next_hops = inspect_h.get_vna_active_route(
            vrf_id=vn_vrf_id, ip=cidr_prefix[0], prefix=cidr_prefix[1])['path_list'][0]['nh']
        if not next_hops:
            result = False
            assert result, 'Route not found in the Agent'
        else:
            self.logger.info('Route found in the Agent')
        number_of_nh = re.findall('nh_index', str(next_hops))
        if (len(number_of_nh) != expected_next_hops):
            result = False
            assert result, 'Agent does not reflect the static route addition'
        else:
            self.logger.info('Agent reflects the static route addition')
コード例 #25
0
 def setUp(self):
     super(InterfaceRouteTableFixture, self).setUp()
     self.vnc_h = ContrailVncApi(self.vnc_api_h, self.logger)
     self.create()
コード例 #26
0
ファイル: orchestrator.py プロジェクト: Ankitja/contrail-test
 def __init__(self, inputs, vnc_api_h, logger=None):
     self.inputs = inputs
     self.logger = logger or logging.getLogger(__name__)
     self.vnc_h = ContrailVncApi(vnc_api_h, logger)
コード例 #27
0
ファイル: alarm_test.py プロジェクト: vvelpula/contrail-test
class AlarmFixture(fixtures.Fixture):

    ''' Fixture to create and verify and delete alarms.
        Create AlarmFixture object
    '''

    def __init__(self, connections, alarm_name=None, uve_keys=[], alarm_severity=None,
                 alarm_rules=None, operand1=None, operand2=None, description=None, variables=None,
                 id_perms=None, perms2=None, display_name=None, parent_obj_type='project',
                 clean_up=True, project_name=None, project_fixture=None):
        self.connections = connections
        self.inputs = connections.inputs
        self.logger = self.connections.logger
        self.vnc_lib_h = self.connections.get_vnc_lib_h()
        self.vnc_h = ContrailVncApi(self.vnc_lib_h, self.logger)
        self.api_s_inspect = self.connections.api_server_inspect
        self.analytics_obj = self.connections.analytics_obj
        self.alarm_name = alarm_name
        self.alarm_id = None
        self.alarm_fq_name = [self.inputs.domain_name, self.alarm_name]
        self.uve_keys = uve_keys
        self.alarm_severity = alarm_severity
        self.alarm_rules = alarm_rules
        self.operand1 = operand1
        self.operand2 = operand2
        self.description = description
        self.variables = variables
        self.id_perms = id_perms
        self.perms2 = perms2
        self.display_name = display_name
        self.parent_obj_type = parent_obj_type
        self.domain_name = self.connections.domain_name
        self.project_name = project_name or self.connections.project_name
        self.project_fixture = project_fixture
        if self.project_fixture:
            self.project_name = self.project_fixture.project_name
        self.project_id = self.connections.get_project_id()
        self.parent_obj = None
        self.clean_up = clean_up
        self.obj = None
        self.created = False
        if self.inputs.verify_thru_gui():
            from webui_test import WebuiTest
            self.webui = WebuiTest(self.connections, self.inputs)
    # end __init__

    def read(self):
        if self.alarm_id:
            self.alarm_obj = self.vnc_h.get_alarm(self.alarm_id)
            self.alarm_fq_name = self.get_fq_name()
            self.alarm_name = self.alarm_obj.name
    # end read

    def setUp(self):
        super(AlarmFixture, self).setUp()
    # end setup

    def create(self, alarm_rules):
        self.alarm_rules = alarm_rules
        self.alarm_id = self.alarm_id or self.get_alarm_id()
        if self.alarm_id:
            self.read()
            self.logger.debug("alarm already present not creating" %
                              (self.alarm_name, self.alarm_id))
        else:
            self.logger.debug(" creating alarm : %s", self.alarm_name)
            if self.parent_obj_type == 'global':
                self.parent_obj = self.vnc_h.get_global_config_obj()
            if self.parent_obj_type == 'project':
                if not self.project_fixture:
                    self.project_fixture = self.useFixture(
                        ProjectFixture(project_name=self.project_name,
                                       connections=self.connections))
                self.parent_obj = self.project_fixture.getObj()
            if not self.parent_obj:
                raise AmbiguousParentError(
                    "[[u'default-global-system-config'], [u'default-domain', u'default-project']]")
            if not self.alarm_rules:
                self.alarm_rules = self.create_alarm_rules()
            uve_keys_type = UveKeysType(self.uve_keys)
            if self.inputs.is_gui_based_config():
                self.alarms = self.webui.create_alarms(self)
            else:
                self.alarm_id = self.vnc_h.create_alarm(name=self.alarm_name, parent_obj=self.parent_obj,
                                   alarm_rules=self.alarm_rules, alarm_severity=self.alarm_severity,
                                   uve_keys=uve_keys_type)
                # need to set rules and other parameters before passing alarm_obj
                self.alarm_obj = self.vnc_h.get_alarm(self.alarm_id)
                self.alarm_fq_name = self.get_fq_name()
            self.created = True
    # end create

    def create_expression(self, params_dict):
        return AlarmExpression(params_dict=params_dict)
    # end create_expression

    def create_and_list(self, and_list):
        return AlarmAndList(and_list=and_list)
    # end create_and_list

    def create_or_list(self, or_list):
        return AlarmOrList(or_list=or_list)
    # end create_or_list

    def configure_alarm_rules(self, params_dict_list, multi_or_conditions=False):
        '''configure single or multiple rules'''
        self.alarm_exp_list = []
        self.alarm_and_list = []
        self.alarm_or_list = []
        try:
            for params_dict in params_dict_list:
                alarm_exp = self.create_expression(params_dict)
                self.alarm_exp_list.append(alarm_exp)
            if multi_or_conditions:
                for alarm_exp in self.alarm_exp_list:
                    alarm_and = self.create_and_list([alarm_exp])
                    self.alarm_and_list.append(alarm_and)
            else:
                self.alarm_and_list.append(
                    self.create_and_list(self.alarm_exp_list))
            self.alarm_or_list = self.create_or_list(self.alarm_and_list)
            return self.alarm_or_list
        except:
            self.logger.warn('error configuring alarm')
    # end configure_alarm_rules

    def getObj(self):
        return self.alarm_obj
    # end getObj

    def set_display_name(self, display_name):
        self.display_name = display_name
        self.alarm_obj.set_display_name(display_name)
        self.vnc_h.update_alarm(self.alarm_obj)
    # end set_display_name

    def get_display_name(self):
        return self.alarm_obj.get_display_name()
    # end get_display_name

    def get_alarm_id(self):
        if not self.alarm_id:
            try:
                alarm_obj = self.vnc_h.get_alarm(self.alarm_fq_name)
                if alarm_obj:
                    self.alarm_id = alarm_obj.uuid
                    return self.alarm_id
            except:
                return None
    # end get_alarm_id


    def set_alarm_rules(self, exp_list, multi_or_conditions=False):
        rules = self.configure_alarm_rules(
            exp_list, multi_or_conditions=multi_or_conditions)
        try:
            if rules:
                self.alarm_obj.set_alarm_rules(rules)
                self.vnc_h.update_alarm(self.alarm_obj)
                return True
        except:
            self.logger.warn('Setting alarm_rules Failed')
            return None
    # end set_alarm_rules

    def set_alarm_enable(self, enable):
        pass

    def set_alarm_disable(self):
        pass

    def get_alarm_severity(self):
        return self.alarm_severity
    # end get_alarm_severity

    def set_alarm_severity(self, severity):
        try:
            self.alarm_severity = severity
            self.alarm_obj.set_alarm_severity(severity)
            self.vnc_h.update_alarm(self.alarm_obj)
            return True
        except :
            self.logger.warn('Setting alarm Severity Failed')
            return None
    # set_alarm_severity

    def set_uve_keys(self, uve_key):
        try:
            self.uve_keys = uve_key
            uve_key_type = UveKeysType(uve_key)
            self.alarm_obj.set_uve_keys(uve_key_type)
            self.vnc_h.update_alarm(self.alarm_obj)
            return True
        except :
            self.logger.warn('Setting UVE keys Failed')
            return None
    # set_uve_keys

    def get_uve_keys(self):
        return self.uve_keys
    # end get_uve_keys
    
    def get_fq_name(self):
        obj = self.getObj()
        fq_name = obj.get_fq_name()
        return ':'.join(fq_name)

    def verify_alarm_in_api_server(self):
        self.cs_alarm = self.api_s_inspect.get_cs_alarm(
                alarm_id=self.alarm_id)
        if not self.cs_alarm:
            self.logger.warn(
                'Alarm config of %s not present in api server' % self.alarm_name)
            return False
        self.logger.info(
            'Alarm config of %s present in the api-server' % self.alarm_name)
        return True
    # end verify_alarm_in_api_server

    def verify_alarm_configuration(self):
        alarm_config = self.cs_alarm
        alarm = alarm_config.get('alarm')
        name = alarm.get('display_name')
        if not (name == self.alarm_name):
            self.logger.warn('Alarm name is missing in the config')
            return False
        uve_keys_dict = alarm.get('uve_keys')
        uve_keys = uve_keys_dict.get('uve_key')
        if not (uve_keys == self.uve_keys):
            self.logger.warn('Uve_keys not present or doesn\'t match %s %s' % (
                uve_keys, self.uve_keys))
            return False
        rules = alarm.get('alarm_rules')
        if not rules:
            self.logger.warn('Rules are not present in config')
            return False
        self.logger.info('Alarm %s configured properly ' %self.alarm_name)
        return True
    # end verify_alarm_configuration

    @retry(delay=3, tries=10)
    def verify_alarm_not_in_api_server(self):
        cs_alarm = self.api_s_inspect.get_cs_alarm(
            alarm_id=self.alarm_id)
        if cs_alarm:
            errmsg = 'Alarm %s not removed from api-server' % self.alarm_name
            self.logger.warn(errmsg)
            return False
        self.logger.info('Alarm %s removed from api-server' % self.alarm_name)
        return True
    # end verify_alarm_not_in_api_server

    def verify_on_setup(self):
        '''Verify alarm in configuration '''
        result = True
        result = self.verify_alarm_in_api_server()
        if not result:
            self.logger.error(
                'Verification of %s config in api-server failed' % self.alarm_name)
            return result
        result = self.verify_alarm_configuration()
        if not result:
            self.logger.error('Alarm %s not configured properly' %self.alarm_name)
            return result
        return True
    # end verify_alarm_setup

    def cleanUp(self):
        do_cleanup = True
        if self.inputs.fixture_cleanup == 'no':
            do_cleanup = False
        if not self.created:
            do_cleanup = False
        if self.inputs.fixture_cleanup == 'force':
            do_cleanup = True
        if self.clean_up == False:
            do_cleanup = False
        if do_cleanup:
            if self.inputs.is_gui_based_config():
                self.webui.delete_alarms(self)
            else:
                self._delete_alarm()
                self.logger.info('Deleted alarm %s' % self.alarm_name)
                assert self.verify_alarm_not_in_api_server()
        else:
            self.logger.debug('Skippping deletion of alarm %s' %
                              self.alarm_name)
        super(AlarmFixture, self).cleanUp()
    # end cleanup

    def _delete_alarm(self, verify=False):
        self.vnc_h.delete_alarm(self.alarm_id)