def _create_prerequisites(self, enterprise_style_flag=True,
                              create_second_pr=False):
        # Create project first
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        # Create Fabric with enterprise style flag set to false
        fabric_obj = Fabric('%s-fabric' % (self.id()))
        fabric_obj.set_fabric_enterprise_style(enterprise_style_flag)
        fabric_uuid = self.api.fabric_create(fabric_obj)
        fabric_obj = self.api.fabric_read(id=fabric_uuid)

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self._vnc_lib.physical_router_create(pr)
        pr_obj = self._vnc_lib.physical_router_read(id=pr_uuid)

        if create_second_pr:
            pr_name_2 = self.id() + '_physical_router_2'
            pr = PhysicalRouter(pr_name_2)
            pr_uuid_2 = self._vnc_lib.physical_router_create(pr)
            pr_obj_2 = self._vnc_lib.physical_router_read(id=pr_uuid_2)
            return proj_obj, fabric_obj, [pr_obj, pr_obj_2]

        return proj_obj, fabric_obj, pr_obj
Exemplo n.º 2
0
 def mockPhysicalRouter(self, id):
     try:
         device = mock_physical_router_db[id]
         device_obj = PhysicalRouter(
             name=device['fq_name'][-1],
             display_name=device["display_name"],
             physical_router_role=device["physical_router_role"],
             routing_bridging_roles=RoutingBridgingRolesType(
                 rb_role=device['routing_bridging_roles']),
             physical_router_user_credentials=UserCredentials(
                 username='******',
                 password='******'),
             fq_name=device["fq_name"],
             physical_router_vendor_name=device[
                 "physical_router_vendor_name"],
             physical_router_device_family=device[
                 "physical_router_device_family"],
             physical_router_product_name=device[
                 "physical_router_product_name"],
             physical_router_serial_number=device[
                 "physical_router_serial_number"],
             physical_router_management_ip=device[
                 "physical_router_management_ip"],
             physical_router_os_version=device["physical_router_os_version"]
         )
         device_obj.uuid = id
         mock_prs[id]=device_obj
         self._vnc_lib.physical_router_create(device_obj)
     except RefsExistError:
         logger.info("Physical router {} already exists".format(id))
     except Exception as ex:
         logger.error("ERROR creating physical router {}: {}".format(id, ex))
Exemplo n.º 3
0
def physical_router_delete(name, **kwargs):
    '''
    Delete specific Contrail physical router

    CLI Example:

    .. code-block:: bash

        salt '*' contrail.physical_router_delete router_name
    '''
    vnc_client = _auth(**kwargs)
    gsc_obj = _get_config(vnc_client)
    prouter_obj = PhysicalRouter(name, gsc_obj)
    if __opts__['test']:
        return "Physical router " + name + " will be deleted"
    vnc_client.physical_router_delete(fq_name=prouter_obj.get_fq_name())
    return "Deleted"
Exemplo n.º 4
0
    def test_hardware_inventory_create(self):
        default_physical_router = PhysicalRouter()
        try:
            uuid = self.api.physical_router_create(default_physical_router)
        except RefsExistError:
            uuid = self.api.fq_name_to_id('physical_router',
                                          default_physical_router.fq_name)
        default_physical_router.set_uuid(uuid)

        prop_map = {'name': 'hi-{}'.format(self.id()),
                    'annotations': {},
                    'parent_obj': default_physical_router,
                    'parent_type': 'physical-router',
                    'display_name': 'hardware inventory',
                    'hardware_inventory_inventory_info':
                        '{"id": 123, "name": "fake"}'}

        obj = self.set_properties(HardwareInventory(), prop_map)
        self.assertSchemaObjCreateOrUpdate(obj)
Exemplo n.º 5
0
 def _pre_create_physical_router(self):
     physical_router = PhysicalRouter(name='test-physical-router')
     self.physical_router_hostname = 'test-physical-router-hostname'
     physical_router.set_fabric(self.fabric)
     physical_router.set_physical_router_hostname(
         self.physical_router_hostname)
     physical_router_uuid = self.api.physical_router_create(physical_router)
     self.physical_router = \
         self.api.physical_router_read(id=physical_router_uuid)
     # create physical_interface_red
     physical_interface_red = PhysicalInterface(
         name='test-physical-interface-red',
         parent_obj=self.physical_router)
     self.physical_interface_red_port_id = \
         'test-physical-interface-red-port-id'
     physical_interface_red.set_display_name(
         self.physical_interface_red_port_id)
     physical_interface_red_uuid = \
         self.api.physical_interface_create(physical_interface_red)
     self.physical_interface_red = \
         self.api.physical_interface_read(id=physical_interface_red_uuid)
     # create physical_interface_green
     physical_interface_green = PhysicalInterface(
         name='test-physical-interface-green',
         parent_obj=self.physical_router)
     self.physical_interface_green_port_id = \
         'test-physical-interface-green-port-id'
     physical_interface_green.set_display_name(
         self.physical_interface_green_port_id)
     physical_interface_green_uuid = \
         self.api.physical_interface_create(physical_interface_green)
     self.physical_interface_green = \
         self.api.physical_interface_read(id=physical_interface_green_uuid)
Exemplo n.º 6
0
 def _create_prs(self, dict_prs):
     self.physical_routers = []
     for prname in dict_prs.keys():
         phy_router_obj = PhysicalRouter(
             parent_type='global-system-config',
             fq_name=["default-global-system-config", prname],
             physical_router_management_ip="1.1.1.1",
             physical_router_vendor_name="juniper",
             physical_router_product_name="qfx5k",
             physical_router_user_credentials={
                 "username": "******",
                 "password": "******"
             },
             physical_router_device_family='junos-qfx')
         self._vnc_lib.physical_router_create(phy_router_obj)
         self.physical_routers.append(phy_router_obj)
         dict_prs[prname] = phy_router_obj
     return
Exemplo n.º 7
0
    def setUp(self):
        super(TestVMIVirtualPortGroupRelation, self).setUp()
        if six.PY3:
            self.assertItemsEqual = self.assertCountEqual

        # Create project
        self.proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(self.proj_obj)

        # Create Fabric
        self.fabric_obj = Fabric('%s-fabric' % (self.id()))
        _ = self.api.fabric_create(self.fabric_obj)
        self.fabric_name = self.fabric_obj.get_fq_name()

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self.api.physical_router_create(pr)
        self.pr_obj = self.api.physical_router_read(id=pr_uuid)

        # Create Physical interface
        esi_id = '00:11:22:33:44:55:66:77:88:99'
        pi_name = self.id() + '_physical_interface1'
        pi = PhysicalInterface(name=pi_name,
                               parent_obj=self.pr_obj,
                               ethernet_segment_identifier=esi_id)
        self.pi_uuid = self.api.physical_interface_create(pi)
        pi_obj = self.api.physical_interface_read(id=self.pi_uuid)
        self.pi_fq_name = pi_obj.get_fq_name()

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

        # Create VPG
        self.vpg_name = "vpg-%s" % self.id()
        vpg = VirtualPortGroup(self.vpg_name, parent_obj=self.fabric_obj)
        self.vpg_uuid = self.api.virtual_port_group_create(vpg)
        vpg_obj = self.api.virtual_port_group_read(id=self.vpg_uuid)
        self.vpg_name = vpg_obj.get_fq_name()
Exemplo n.º 8
0
    def _create_vpg_prerequisites(self,
                                  enterprise_style_flag=True,
                                  create_second_pr=False,
                                  disable_vlan_vn_uniqueness_check=False):
        # Create project first
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        # Create Fabric with enterprise style flag set to false
        fabric_obj = Fabric('%s-fabric' % (self.id()))
        fabric_obj.set_fabric_enterprise_style(enterprise_style_flag)
        fabric_obj.set_disable_vlan_vn_uniqueness_check(
            disable_vlan_vn_uniqueness_check)
        fabric_uuid = self.api.fabric_create(fabric_obj)
        fabric_obj = self.api.fabric_read(id=fabric_uuid)

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self._vnc_lib.physical_router_create(pr)
        pr_obj = self._vnc_lib.physical_router_read(id=pr_uuid)

        # Create physical interface
        esi_id = '00:11:22:33:44:55:66:77:88:99'
        pi_name = self.id() + '__phy_intf_1'
        pi = PhysicalInterface(name=pi_name,
                               parent_obj=pr_obj,
                               ethernet_segment_identifier=esi_id)
        pi_uuid = self.api.physical_interface_create(pi)
        pi_obj = self.api.physical_interface_read(id=pi_uuid)

        # Create VN
        vn_name = 'vn-%s-1' % self.id()
        vn = VirtualNetwork(vn_name, parent_obj=proj_obj)
        vn_uuid = self.api.virtual_network_create(vn)
        vn_obj = self.api.virtual_network_read(id=vn_uuid)

        return proj_obj, fabric_obj, pr_obj, pi_obj, vn_obj
Exemplo n.º 9
0
    def test_physical_router_create(self):
        dnsmasq = DnsmasqLeaseParameters(
            lease_expiry_time=100,
            client_id='4d972916-3204-11ea-a6fa-d7a3d77d36a2')
        auto_system = AutonomousSystemsType(asn=[294967295])
        junos_service_ports = JunosServicePorts(service_port=['2010'])
        snmp_credentials = SNMPCredentials(
            version=1,
            local_port=8081,
            retries=3,
            timeout=300,
            v2_community='some_string',
            v3_security_name='some_string',
            v3_security_level='some_string',
            v3_security_engine_id='some_string',
            v3_context='some_string',
            v3_context_engine_id='some_string',
            v3_authentication_protocol='some_string',
            v3_authentication_password='******',
            v3_privacy_protocol='some_string',
            v3_privacy_password='******',
            v3_engine_id='some_string',
            v3_engine_boots=3,
            v3_engine_time=300)
        user_credentials = UserCredentials(username='******', password='******')
        routing_bridging_roles = RoutingBridgingRolesType(rb_roles=['CRB'])
        telemetry_info = TelemetryStateInfo(server_ip='10.100.0.100',
                                            server_port='8080',
                                            resource=[TelemetryResourceInfo()])
        prop_map = {
            'name': 'pr-{}'.format(self.id()),
            'annotations': {},
            'parent_obj': self.gsc,
            'parent_type': 'global-system-config',
            'display_name': 'some_string',
            'physical_router_autonomous_system': auto_system,
            'physical_router_cli_commit_state': 'in_sync',
            'physical_router_dataplane_ip': 'some_string',
            'physical_router_device_family': 'some_string',
            'physical_router_dhcp_parameters': dnsmasq,
            'physical_router_encryption_type': 'none',
            'physical_router_hostname': 'some_string',
            'physical_router_junos_service_ports': junos_service_ports,
            'physical_router_lldp': False,
            'physical_router_loopback_ip': '127.0.0.1',
            'physical_router_managed_state': 'dhcp',
            'physical_router_management_ip': '10.100.100.255',
            'physical_router_management_mac': 'some_string',
            'physical_router_os_version': 'some_string',
            'physical_router_product_name': 'some_string',
            'physical_router_replicator_loopback_ip': 'some_string',
            'physical_router_role': 'spine',
            'physical_router_serial_number': 'some_string',
            'physical_router_snmp': False,
            'physical_router_snmp_credentials': snmp_credentials,
            'physical_router_supplemental_config': 'some_string',
            'physical_router_underlay_config': 'some_string',
            'physical_router_underlay_managed': False,
            'physical_router_user_credentials': user_credentials,
            'physical_router_vendor_name': 'some_string',
            'physical_router_vnc_managed': False,
            'routing_bridging_roles': routing_bridging_roles,
            'telemetry_info': telemetry_info
        }

        obj = self.set_properties(PhysicalRouter(), prop_map)
        self.assertSchemaObjCreateOrUpdate(obj)
Exemplo n.º 10
0
def physical_router_create(
        name,
        parent_type=None,
        management_ip=None,
        dataplane_ip=None,  # VTEP address in web GUI
        vendor_name=None,
        product_name=None,
        vnc_managed=None,
        junos_service_ports=None,
        agents=None,
        **kwargs):
    '''
    Create specific Contrail physical router

    CLI Example:

    .. code-block:: bash

        salt '*' contrail.physical_router_create OVSDB_router management_ip=10.167.4.202 dataplane_ip=172.16.20.15 vendor_name=MyVendor product_name=MyProduct agents="['tor01','tns01']"
    '''
    ret = {}
    vnc_client = _auth(**kwargs)
    gsc_obj = _get_config(vnc_client)
    prouter_objs = physical_router_list(**kwargs)
    if name in prouter_objs:
        prouter = physical_router_get(name)
        prouter_obj = vnc_client._object_read('physical-router',
                                              id=prouter[name]['_uuid'])
        if prouter_obj.physical_router_management_ip != management_ip:
            ret['management_ip'] = {
                'from': prouter_obj.physical_router_management_ip,
                "to": management_ip
            }
            prouter_obj.set_physical_router_management_ip(management_ip)
        if prouter_obj.physical_router_dataplane_ip != dataplane_ip:
            ret['dataplane_ip'] = {
                'from': prouter_obj.physical_router_dataplane_ip,
                "to": dataplane_ip
            }
            prouter_obj.set_physical_router_dataplane_ip(dataplane_ip)
        if prouter_obj.get_physical_router_vendor_name() != vendor_name:
            ret['vendor_name'] = {
                'from': prouter_obj.get_physical_router_vendor_name(),
                "to": vendor_name
            }
            prouter_obj.set_physical_router_vendor_name(vendor_name)
        if prouter_obj.get_physical_router_product_name() != product_name:
            ret['product_name'] = {
                'from': prouter_obj.get_physical_router_product_name(),
                "to": product_name
            }
            prouter_obj.set_physical_router_product_name(product_name)
        if prouter_obj.get_physical_router_vnc_managed() != vnc_managed:
            ret['vnc_managed'] = {
                'from': prouter_obj.get_physical_router_vnc_managed(),
                "to": vnc_managed
            }
            prouter_obj.set_physical_router_vnc_managed(vnc_managed)
        if prouter_obj.get_physical_router_junos_service_ports(
        ) != junos_service_ports:
            ret['junos_service_ports'] = {
                'from': prouter_obj.get_physical_router_junos_service_ports(),
                "to": junos_service_ports
            }
            prouter_obj.set_physical_router_junos_service_ports(
                junos_service_ports)

        if __opts__['test']:
            if len(ret) != 0:
                return "Physical router " + name + " will be updated"
            return {"OK": "Physical router exists and is updated"}

        vrouter_objs = vnc_client._objects_list(
            'virtual-router', detail=True)  # all vrouter objects
        c_agents = []  # referenced vrouters
        for c_agent in prouter_obj.get_virtual_router_refs():
            c_agents.append(c_agent['uuid'])
        agent_objs = []  # required state of references
        for vrouter_obj in vrouter_objs:
            if vrouter_obj._display_name in agents and vrouter_obj._uuid not in c_agents:
                prouter_obj.add_virtual_router(vrouter_obj)
                ret['vrouter ' + vrouter_obj._display_name] = "Reference added"
            if vrouter_obj._display_name not in agents and vrouter_obj._uuid in c_agents:
                prouter_obj.del_virtual_router(vrouter_obj)
                ret['vrouter ' +
                    vrouter_obj._display_name] = "Reference removed"
        vnc_client.physical_router_update(prouter_obj)

        if len(ret) == 0:
            return {"OK": "Physical router exists and is updated"}
        return ret
    else:
        if __opts__['test']:
            return "Physical router " + name + " will be created"
        prouter_obj = PhysicalRouter(
            name=name,
            parent_obj=None,
            physical_router_management_ip=management_ip,
            physical_router_dataplane_ip=dataplane_ip,
            physical_router_vendor_name=vendor_name,
            physical_router_product_name=product_name,
            physical_router_vnc_managed=vnc_managed,
            physical_router_junos_service_ports=junos_service_ports,
        )
        for agent in agents:
            vrouter = virtual_router_get(agent)
            vrouter_obj = vnc_client._object_read('virtual-router',
                                                  id=vrouter[agent]['uuid'])
            prouter_obj.add_virtual_router(vrouter_obj)
        vnc_client.physical_router_create(prouter_obj)
    return "Created"
Exemplo n.º 11
0
    def test_l2_dci_mode(self):
        """Validate l2 mode dci object create and edit operation.

        It executes following steps:
        - Create 3 fabric, each one with one PR, all PR except one PR
        should be marked not DCI-gateway.
        - Create 3 VN, two tenant VN and one routed VN

        Validate l2 mode dci create failure by doing following operation:
        - Remove two fabrics from dci and keep only one fabric in dci
        and verify create dci fails as not having two fabrics.
        - Remove all VN from dci and verify create dci fails as not
        having at least one VN.
        - Create l2 mode dci with 3 fabric and 2 tenant vn, verify it
        fails with Error of fabric does not have DCI-gateway RB role PR.
        - Remove faulty fabric. and add 3rd routed vn to dci. verify
        create operation fails with error routed vn not allowed.

        Create successfully l2 dci with 2 fabrics and 2 vn. execute
        following edit operation verification:
        - Add fabric to dci having no DCI-gw role PR, verify error.
        - Add routed vnto dci, verify error.
        : Args:
        : return:
        : it generates exception on failure
        :
        """
        dict_fabrics = {}
        dict_prs = {}
        dict_vns = {}
        non_dci_fabric_name = ''
        routed_vn_name = ''
        ipam_obj = self.create_vn_ipam(self.id())
        subnetmask = 24
        vn_starting_index = 21
        for i in range(1, 4):
            fabric_name = '%s-fabric%s' % (self.id(), str(i))
            fabric_obj = Fabric(fabric_name)
            dict_fabrics[fabric_name] = fabric_obj
            fabric_uuid = self._vnc_lib.fabric_create(fabric_obj)
            self._vnc_lib.fabric_read(id=fabric_uuid)

            pr_name = '%s-PR%s' % (self.id(), str(i))
            pr = PhysicalRouter(pr_name)
            pr.set_fabric(fabric_obj)
            if i != 3:
                pr.set_routing_bridging_roles(
                    RoutingBridgingRolesType(rb_roles=['DCI-Gateway']))
            else:
                non_dci_fabric_name = fabric_name
                pr.set_routing_bridging_roles(
                    RoutingBridgingRolesType(rb_roles=['DC-Gateway']))
            dict_prs[pr_name] = pr
            pr_uuid = self._vnc_lib.physical_router_create(pr)
            self._vnc_lib.physical_router_read(id=pr_uuid)

            subnet = "%s.0.0.0" % vn_starting_index
            vn_starting_index += 1
            vn_name = self.make_vn_name(i)
            vn_category = 'tenant'
            if i == 3:
                routed_vn_name = vn_name
                vn_category = 'routed'
            dict_vns[vn_name] = self.create_vn_with_subnets(
                i, vn_name, ipam_obj, subnet, subnetmask, vn_category)

        vn_list = []
        for vnname, obj in dict_vns.items():
            if vnname != routed_vn_name:
                vn_list.append(obj)
        fabric_list = []
        for fname, obj in dict_fabrics.items():
            if fname != non_dci_fabric_name:
                fabric_list.append(obj)

        dci_obj, dci_uuid = self._verify_l2_dci_create_edit(
            'l2_dci', dict_fabrics, dict_vns, non_dci_fabric_name,
            routed_vn_name, vn_list, fabric_list, None)

        # validate Edit Operation
        dci_obj, dci_uuid = self._verify_l2_dci_create_edit(
            'l2_dci', dict_fabrics, dict_vns, non_dci_fabric_name,
            routed_vn_name, vn_list, fabric_list, dci_obj)

        # cleanup
        self._vnc_lib.data_center_interconnect_delete(id=dci_uuid)
        for name, obj in dict_vns.items():
            self._vnc_lib.virtual_network_delete(id=obj.get_uuid())
        self._vnc_lib.network_ipam_delete(id=ipam_obj.uuid)
        for name, obj in dict_prs.items():
            self._vnc_lib.physical_router_delete(id=obj.get_uuid())
        for name, obj in dict_fabrics.items():
            self._vnc_lib.fabric_delete(id=obj.get_uuid())