Exemplo n.º 1
0
def create_lqueue(cluster, queue_data):
    params = {
        'name': 'display_name',
        'qos_marking': 'qos_marking',
        'min': 'min_bandwidth_rate',
        'max': 'max_bandwidth_rate',
        'dscp': 'dscp'
    }
    queue_obj = dict(
        (nvp_name, queue_data.get(api_name))
        for api_name, nvp_name in params.iteritems()
        if attr.is_attr_set(queue_data.get(api_name))
    )
    if 'display_name' in queue_obj:
        queue_obj['display_name'] = utils.check_and_truncate(
            queue_obj['display_name'])

    queue_obj['tags'] = utils.get_tags()
    try:
        return do_request(HTTP_POST,
                          _build_uri_path(LQUEUE_RESOURCE),
                          jsonutils.dumps(queue_obj),
                          cluster=cluster)['uuid']
    except NvpApiClient.NvpApiException:
        # FIXME(salv-orlando): This should not raise NeutronException
        with excutils.save_and_reraise_exception():
            raise exception.NeutronException()
Exemplo n.º 2
0
def create_security_profile(cluster, tenant_id, security_profile):
    path = "/ws.v1/security-profile"
    # Allow all dhcp responses and all ingress traffic
    hidden_rules = {'logical_port_egress_rules':
                    [{'ethertype': 'IPv4',
                      'protocol': constants.PROTO_NUM_UDP,
                      'port_range_min': constants.DHCP_RESPONSE_PORT,
                      'port_range_max': constants.DHCP_RESPONSE_PORT,
                      'ip_prefix': '0.0.0.0/0'}],
                    'logical_port_ingress_rules':
                    [{'ethertype': 'IPv4'},
                     {'ethertype': 'IPv6'}]}
    display_name = utils.check_and_truncate(security_profile.get('name'))
    body = mk_body(
        tags=utils.get_tags(os_tid=tenant_id), display_name=display_name,
        logical_port_ingress_rules=(
            hidden_rules['logical_port_ingress_rules']),
        logical_port_egress_rules=hidden_rules['logical_port_egress_rules']
    )
    rsp = do_request(HTTP_POST, path, body, cluster=cluster)
    if security_profile.get('name') == 'default':
        # If security group is default allow ip traffic between
        # members of the same security profile is allowed and ingress traffic
        # from the switch
        rules = {'logical_port_egress_rules': [{'ethertype': 'IPv4',
                                                'profile_uuid': rsp['uuid']},
                                               {'ethertype': 'IPv6',
                                                'profile_uuid': rsp['uuid']}],
                 'logical_port_ingress_rules': [{'ethertype': 'IPv4'},
                                                {'ethertype': 'IPv6'}]}

        update_security_group_rules(cluster, rsp['uuid'], rules)
    LOG.debug(_("Created Security Profile: %s"), rsp)
    return rsp
Exemplo n.º 3
0
def update_port(cluster, lswitch_uuid, lport_uuid, neutron_port_id, tenant_id,
                display_name, device_id, admin_status_enabled,
                mac_address=None, fixed_ips=None, port_security_enabled=None,
                security_profiles=None, queue_id=None,
                mac_learning_enabled=None, allowed_address_pairs=None):
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=utils.check_and_truncate(display_name),
        tags=utils.get_tags(os_tid=tenant_id,
                            q_port_id=neutron_port_id,
                            vm_id=utils.device_id_to_vm_id(device_id)))

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles,
                          queue_id, mac_learning_enabled,
                          allowed_address_pairs)

    path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid
    try:
        result = do_request(HTTP_PUT, path, json.dumps(lport_obj),
                            cluster=cluster)
        LOG.debug(_("Updated logical port %(result)s "
                    "on logical switch %(uuid)s"),
                  {'result': result['uuid'], 'uuid': lswitch_uuid})
        return result
    except exception.NotFound as e:
        LOG.error(_("Port or Network not found, Error: %s"), str(e))
        raise exception.PortNotFoundOnNetwork(
            port_id=lport_uuid, net_id=lswitch_uuid)
Exemplo n.º 4
0
def create_l2_gw_service(cluster, tenant_id, display_name, devices):
    """Create a NSX Layer-2 Network Gateway Service.

        :param cluster: The target NSX cluster
        :param tenant_id: Identifier of the Openstack tenant for which
        the gateway service.
        :param display_name: Descriptive name of this gateway service
        :param devices: List of transport node uuids (and network
        interfaces on them) to use for the network gateway service
        :raise NvpApiException: if there is a problem while communicating
        with the NSX controller
    """
    # NOTE(salvatore-orlando): This is a little confusing, but device_id in
    # NSX is actually the identifier a physical interface on the gateway
    # device, which in the Neutron API is referred as interface_name
    gateways = [{"transport_node_uuid": device['id'],
                 "device_id": device['interface_name'],
                 "type": "L2Gateway"} for device in devices]
    gwservice_obj = {
        "display_name": utils.check_and_truncate(display_name),
        "tags": utils.get_tags(os_tid=tenant_id),
        "gateways": gateways,
        "type": "L2GatewayServiceConfig"
    }
    return do_request(
        "POST", _build_uri_path(GWSERVICE_RESOURCE),
        json.dumps(gwservice_obj), cluster=cluster)
Exemplo n.º 5
0
def create_lport(cluster, lswitch_uuid, tenant_id, neutron_port_id,
                 display_name, device_id, admin_status_enabled,
                 mac_address=None, fixed_ips=None, port_security_enabled=None,
                 security_profiles=None, queue_id=None,
                 mac_learning_enabled=None, allowed_address_pairs=None):
    """Creates a logical port on the assigned logical switch."""
    display_name = utils.check_and_truncate(display_name)
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=display_name,
        tags=utils.get_tags(os_tid=tenant_id,
                            q_port_id=neutron_port_id,
                            vm_id=utils.device_id_to_vm_id(device_id))
    )

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles,
                          queue_id, mac_learning_enabled,
                          allowed_address_pairs)

    path = _build_uri_path(LSWITCHPORT_RESOURCE,
                           parent_resource_id=lswitch_uuid)
    result = do_request(HTTP_POST, path, json.dumps(lport_obj),
                        cluster=cluster)

    LOG.debug(_("Created logical port %(result)s on logical switch %(uuid)s"),
              {'result': result['uuid'], 'uuid': lswitch_uuid})
    return result
Exemplo n.º 6
0
def create_l2_gw_service(cluster, tenant_id, display_name, devices):
    """Create a NSX Layer-2 Network Gateway Service.

        :param cluster: The target NSX cluster
        :param tenant_id: Identifier of the Openstack tenant for which
        the gateway service.
        :param display_name: Descriptive name of this gateway service
        :param devices: List of transport node uuids (and network
        interfaces on them) to use for the network gateway service
        :raise NvpApiException: if there is a problem while communicating
        with the NSX controller
    """
    # NOTE(salvatore-orlando): This is a little confusing, but device_id in
    # NSX is actually the identifier a physical interface on the gateway
    # device, which in the Neutron API is referred as interface_name
    gateways = [{
        "transport_node_uuid": device['id'],
        "device_id": device['interface_name'],
        "type": "L2Gateway"
    } for device in devices]
    gwservice_obj = {
        "display_name": utils.check_and_truncate(display_name),
        "tags": utils.get_tags(os_tid=tenant_id),
        "gateways": gateways,
        "type": "L2GatewayServiceConfig"
    }
    return do_request("POST",
                      _build_uri_path(GWSERVICE_RESOURCE),
                      json.dumps(gwservice_obj),
                      cluster=cluster)
Exemplo n.º 7
0
def create_lqueue(cluster, queue_data):
    params = {
        'name': 'display_name',
        'qos_marking': 'qos_marking',
        'min': 'min_bandwidth_rate',
        'max': 'max_bandwidth_rate',
        'dscp': 'dscp'
    }
    queue_obj = dict((nvp_name, queue_data.get(api_name))
                     for api_name, nvp_name in params.iteritems()
                     if attr.is_attr_set(queue_data.get(api_name)))
    if 'display_name' in queue_obj:
        queue_obj['display_name'] = utils.check_and_truncate(
            queue_obj['display_name'])

    queue_obj['tags'] = utils.get_tags()
    try:
        return do_request(HTTP_POST,
                          _build_uri_path(LQUEUE_RESOURCE),
                          jsonutils.dumps(queue_obj),
                          cluster=cluster)['uuid']
    except NvpApiClient.NvpApiException:
        # FIXME(salv-orlando): This should not raise NeutronException
        with excutils.save_and_reraise_exception():
            raise exception.NeutronException()
Exemplo n.º 8
0
def create_lswitch(cluster,
                   neutron_net_id,
                   tenant_id,
                   display_name,
                   transport_zones_config,
                   shared=None,
                   **kwargs):
    # The tag scope adopts a slightly different naming convention for
    # historical reasons
    lswitch_obj = {
        "display_name": utils.check_and_truncate(display_name),
        "transport_zones": transport_zones_config,
        "tags": utils.get_tags(os_tid=tenant_id, quantum_net_id=neutron_net_id)
    }
    # TODO(salv-orlando): Now that we have async status synchronization
    # this tag is perhaps not needed anymore
    if shared:
        lswitch_obj["tags"].append({"tag": "true", "scope": "shared"})
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    uri = _build_uri_path(LSWITCH_RESOURCE)
    lswitch = do_request(HTTP_POST,
                         uri,
                         json.dumps(lswitch_obj),
                         cluster=cluster)
    LOG.debug(_("Created logical switch: %s"), lswitch['uuid'])
    return lswitch
Exemplo n.º 9
0
def update_l2_gw_service(cluster, gateway_id, display_name):
    # TODO(salvatore-orlando): Allow updates for gateways too
    gwservice_obj = get_l2_gw_service(cluster, gateway_id)
    if not display_name:
        # Nothing to update
        return gwservice_obj
    gwservice_obj["display_name"] = utils.check_and_truncate(display_name)
    return do_request("PUT", _build_uri_path(GWSERVICE_RESOURCE,
                                             resource_id=gateway_id),
                      json.dumps(gwservice_obj), cluster=cluster)
Exemplo n.º 10
0
def update_l2_gw_service(cluster, gateway_id, display_name):
    # TODO(salvatore-orlando): Allow updates for gateways too
    gwservice_obj = get_l2_gw_service(cluster, gateway_id)
    if not display_name:
        # Nothing to update
        return gwservice_obj
    gwservice_obj["display_name"] = utils.check_and_truncate(display_name)
    return do_request("PUT",
                      _build_uri_path(GWSERVICE_RESOURCE,
                                      resource_id=gateway_id),
                      json.dumps(gwservice_obj),
                      cluster=cluster)
Exemplo n.º 11
0
def update_lswitch(cluster, lswitch_id, display_name,
                   tenant_id=None, **kwargs):
    uri = _build_uri_path(LSWITCH_RESOURCE, resource_id=lswitch_id)
    lswitch_obj = {"display_name": utils.check_and_truncate(display_name),
                   "tags": utils.get_tags(os_tid=tenant_id)}
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    try:
        return do_request(HTTP_PUT, uri, json.dumps(lswitch_obj),
                          cluster=cluster)
    except exception.NotFound as e:
        LOG.error(_("Network not found, Error: %s"), str(e))
        raise exception.NetworkNotFound(net_id=lswitch_id)
Exemplo n.º 12
0
    def create_lswitch(self, name, tz_config):
        lsconfig = {
            'display_name': utils.check_and_truncate(name),
            "tags": [],
            "type": "LogicalSwitchConfig",
            "_schema": "/ws.v1/schema/LogicalSwitchConfig",
            "port_isolation_enabled": False,
            "replication_mode": "service",
            "transport_zones": tz_config
        }

        response = self.vcns.create_lswitch(lsconfig)[1]
        return response
Exemplo n.º 13
0
    def create_lswitch(self, name, tz_config, tags=None, port_isolation=False, replication_mode="service"):
        lsconfig = {
            "display_name": utils.check_and_truncate(name),
            "tags": tags or [],
            "type": "LogicalSwitchConfig",
            "_schema": "/ws.v1/schema/LogicalSwitchConfig",
            "transport_zones": tz_config,
        }
        if port_isolation is bool:
            lsconfig["port_isolation_enabled"] = port_isolation
        if replication_mode:
            lsconfig["replication_mode"] = replication_mode

        response = self.vcns.create_lswitch(lsconfig)[1]
        return response
Exemplo n.º 14
0
def create_security_profile(cluster, tenant_id, security_profile):
    path = "/ws.v1/security-profile"
    # Allow all dhcp responses and all ingress traffic
    hidden_rules = {
        'logical_port_egress_rules': [{
            'ethertype': 'IPv4',
            'protocol': constants.PROTO_NUM_UDP,
            'port_range_min': constants.DHCP_RESPONSE_PORT,
            'port_range_max': constants.DHCP_RESPONSE_PORT,
            'ip_prefix': '0.0.0.0/0'
        }],
        'logical_port_ingress_rules': [{
            'ethertype': 'IPv4'
        }, {
            'ethertype': 'IPv6'
        }]
    }
    display_name = utils.check_and_truncate(security_profile.get('name'))
    body = mk_body(
        tags=utils.get_tags(os_tid=tenant_id),
        display_name=display_name,
        logical_port_ingress_rules=(
            hidden_rules['logical_port_ingress_rules']),
        logical_port_egress_rules=hidden_rules['logical_port_egress_rules'])
    rsp = do_request(HTTP_POST, path, body, cluster=cluster)
    if security_profile.get('name') == 'default':
        # If security group is default allow ip traffic between
        # members of the same security profile is allowed and ingress traffic
        # from the switch
        rules = {
            'logical_port_egress_rules': [{
                'ethertype': 'IPv4',
                'profile_uuid': rsp['uuid']
            }, {
                'ethertype': 'IPv6',
                'profile_uuid': rsp['uuid']
            }],
            'logical_port_ingress_rules': [{
                'ethertype': 'IPv4'
            }, {
                'ethertype': 'IPv6'
            }]
        }

        update_security_group_rules(cluster, rsp['uuid'], rules)
    LOG.debug(_("Created Security Profile: %s"), rsp)
    return rsp
Exemplo n.º 15
0
def _prepare_lrouter_body(name, neutron_router_id, tenant_id,
                          router_type, distributed=None, **kwargs):
    body = {
        "display_name": utils.check_and_truncate(name),
        "tags": utils.get_tags(os_tid=tenant_id,
                               q_router_id=neutron_router_id),
        "routing_config": {
            "type": router_type
        },
        "type": "LogicalRouterConfig"
    }
    # add the distributed key only if not None (ie: True or False)
    if distributed is not None:
        body['distributed'] = distributed
    if kwargs:
        body["routing_config"].update(kwargs)
    return body
Exemplo n.º 16
0
 def _nvp_lqueue(self, queue):
     """Convert fields to nvp fields."""
     nvp_queue = {}
     params = {'name': 'display_name',
               'qos_marking': 'qos_marking',
               'min': 'min_bandwidth_rate',
               'max': 'max_bandwidth_rate',
               'dscp': 'dscp'}
     nvp_queue = dict(
         (nvp_name, queue.get(api_name))
         for api_name, nvp_name in params.iteritems()
         if attr.is_attr_set(queue.get(api_name))
     )
     if 'display_name' in nvp_queue:
         nvp_queue['display_name'] = utils.check_and_truncate(
             nvp_queue['display_name'])
     return nvp_queue
Exemplo n.º 17
0
def update_implicit_routing_lrouter(cluster, r_id, display_name, nexthop):
    lrouter_obj = get_lrouter(cluster, r_id)
    if not display_name and not nexthop:
        # Nothing to update
        return lrouter_obj
    # It seems that this is faster than the doing an if on display_name
    lrouter_obj["display_name"] = (utils.check_and_truncate(display_name) or
                                   lrouter_obj["display_name"])
    if nexthop:
        nh_element = lrouter_obj["routing_config"].get(
            "default_route_next_hop")
        if nh_element:
            nh_element["gateway_ip_address"] = nexthop
    return do_request(HTTP_PUT, _build_uri_path(LROUTER_RESOURCE,
                                                resource_id=r_id),
                      jsonutils.dumps(lrouter_obj),
                      cluster=cluster)
Exemplo n.º 18
0
 def _nvp_lqueue(self, queue):
     """Convert fields to nvp fields."""
     nvp_queue = {}
     params = {
         'name': 'display_name',
         'qos_marking': 'qos_marking',
         'min': 'min_bandwidth_rate',
         'max': 'max_bandwidth_rate',
         'dscp': 'dscp'
     }
     nvp_queue = dict((nvp_name, queue.get(api_name))
                      for api_name, nvp_name in params.iteritems()
                      if attr.is_attr_set(queue.get(api_name)))
     if 'display_name' in nvp_queue:
         nvp_queue['display_name'] = utils.check_and_truncate(
             nvp_queue['display_name'])
     return nvp_queue
Exemplo n.º 19
0
def update_implicit_routing_lrouter(cluster, r_id, display_name, nexthop):
    lrouter_obj = get_lrouter(cluster, r_id)
    if not display_name and not nexthop:
        # Nothing to update
        return lrouter_obj
    # It seems that this is faster than the doing an if on display_name
    lrouter_obj["display_name"] = (utils.check_and_truncate(display_name)
                                   or lrouter_obj["display_name"])
    if nexthop:
        nh_element = lrouter_obj["routing_config"].get(
            "default_route_next_hop")
        if nh_element:
            nh_element["gateway_ip_address"] = nexthop
    return do_request(HTTP_PUT,
                      _build_uri_path(LROUTER_RESOURCE, resource_id=r_id),
                      jsonutils.dumps(lrouter_obj),
                      cluster=cluster)
Exemplo n.º 20
0
def update_port(cluster,
                lswitch_uuid,
                lport_uuid,
                neutron_port_id,
                tenant_id,
                display_name,
                device_id,
                admin_status_enabled,
                mac_address=None,
                fixed_ips=None,
                port_security_enabled=None,
                security_profiles=None,
                queue_id=None,
                mac_learning_enabled=None,
                allowed_address_pairs=None):
    lport_obj = dict(admin_status_enabled=admin_status_enabled,
                     display_name=utils.check_and_truncate(display_name),
                     tags=utils.get_tags(
                         os_tid=tenant_id,
                         q_port_id=neutron_port_id,
                         vm_id=utils.device_id_to_vm_id(device_id)))

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles, queue_id,
                          mac_learning_enabled, allowed_address_pairs)

    path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid
    try:
        result = do_request(HTTP_PUT,
                            path,
                            json.dumps(lport_obj),
                            cluster=cluster)
        LOG.debug(
            _("Updated logical port %(result)s "
              "on logical switch %(uuid)s"), {
                  'result': result['uuid'],
                  'uuid': lswitch_uuid
              })
        return result
    except exception.NotFound as e:
        LOG.error(_("Port or Network not found, Error: %s"), str(e))
        raise exception.PortNotFoundOnNetwork(port_id=lport_uuid,
                                              net_id=lswitch_uuid)
Exemplo n.º 21
0
def update_lswitch(cluster,
                   lswitch_id,
                   display_name,
                   tenant_id=None,
                   **kwargs):
    uri = _build_uri_path(LSWITCH_RESOURCE, resource_id=lswitch_id)
    lswitch_obj = {
        "display_name": utils.check_and_truncate(display_name),
        "tags": utils.get_tags(os_tid=tenant_id)
    }
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    try:
        return do_request(HTTP_PUT,
                          uri,
                          json.dumps(lswitch_obj),
                          cluster=cluster)
    except exception.NotFound as e:
        LOG.error(_("Network not found, Error: %s"), str(e))
        raise exception.NetworkNotFound(net_id=lswitch_id)
Exemplo n.º 22
0
    def create_lswitch(self,
                       name,
                       tz_config,
                       tags=None,
                       port_isolation=False,
                       replication_mode="service"):
        lsconfig = {
            'display_name': utils.check_and_truncate(name),
            "tags": tags or [],
            "type": "LogicalSwitchConfig",
            "_schema": "/ws.v1/schema/LogicalSwitchConfig",
            "transport_zones": tz_config
        }
        if port_isolation is bool:
            lsconfig["port_isolation_enabled"] = port_isolation
        if replication_mode:
            lsconfig["replication_mode"] = replication_mode

        response = self.vcns.create_lswitch(lsconfig)[1]
        return response
Exemplo n.º 23
0
def _prepare_lrouter_body(name,
                          neutron_router_id,
                          tenant_id,
                          router_type,
                          distributed=None,
                          **kwargs):
    body = {
        "display_name": utils.check_and_truncate(name),
        "tags": utils.get_tags(os_tid=tenant_id,
                               q_router_id=neutron_router_id),
        "routing_config": {
            "type": router_type
        },
        "type": "LogicalRouterConfig"
    }
    # add the distributed key only if not None (ie: True or False)
    if distributed is not None:
        body['distributed'] = distributed
    if kwargs:
        body["routing_config"].update(kwargs)
    return body
Exemplo n.º 24
0
def create_lport(cluster,
                 lswitch_uuid,
                 tenant_id,
                 neutron_port_id,
                 display_name,
                 device_id,
                 admin_status_enabled,
                 mac_address=None,
                 fixed_ips=None,
                 port_security_enabled=None,
                 security_profiles=None,
                 queue_id=None,
                 mac_learning_enabled=None,
                 allowed_address_pairs=None):
    """Creates a logical port on the assigned logical switch."""
    display_name = utils.check_and_truncate(display_name)
    lport_obj = dict(admin_status_enabled=admin_status_enabled,
                     display_name=display_name,
                     tags=utils.get_tags(
                         os_tid=tenant_id,
                         q_port_id=neutron_port_id,
                         vm_id=utils.device_id_to_vm_id(device_id)))

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles, queue_id,
                          mac_learning_enabled, allowed_address_pairs)

    path = _build_uri_path(LSWITCHPORT_RESOURCE,
                           parent_resource_id=lswitch_uuid)
    result = do_request(HTTP_POST,
                        path,
                        json.dumps(lport_obj),
                        cluster=cluster)

    LOG.debug(_("Created logical port %(result)s on logical switch %(uuid)s"),
              {
                  'result': result['uuid'],
                  'uuid': lswitch_uuid
              })
    return result
Exemplo n.º 25
0
def create_lswitch(cluster, neutron_net_id, tenant_id, display_name,
                   transport_zones_config,
                   shared=None,
                   **kwargs):
    # The tag scope adopts a slightly different naming convention for
    # historical reasons
    lswitch_obj = {"display_name": utils.check_and_truncate(display_name),
                   "transport_zones": transport_zones_config,
                   "tags": utils.get_tags(os_tid=tenant_id,
                                          quantum_net_id=neutron_net_id)}
    # TODO(salv-orlando): Now that we have async status synchronization
    # this tag is perhaps not needed anymore
    if shared:
        lswitch_obj["tags"].append({"tag": "true",
                                    "scope": "shared"})
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    uri = _build_uri_path(LSWITCH_RESOURCE)
    lswitch = do_request(HTTP_POST, uri, json.dumps(lswitch_obj),
                         cluster=cluster)
    LOG.debug(_("Created logical switch: %s"), lswitch['uuid'])
    return lswitch
Exemplo n.º 26
0
 def test_check_and_truncate_name_long_name(self):
     name = 'this_is_a_port_whose_name_is_longer_than_40_chars'
     result = utils.check_and_truncate(name)
     self.assertEqual(len(result), utils.MAX_DISPLAY_NAME_LEN)
Exemplo n.º 27
0
 def test_check_and_truncate_name_with_short_name(self):
     name = 'foo_port_name'
     result = utils.check_and_truncate(name)
     self.assertEqual(name, result)
Exemplo n.º 28
0
 def test_check_and_truncate_name_with_none(self):
     name = None
     result = utils.check_and_truncate(name)
     self.assertEqual('', result)
Exemplo n.º 29
0
 def test_check_and_truncate_name_with_none(self):
     name = None
     result = utils.check_and_truncate(name)
     self.assertEqual('', result)
Exemplo n.º 30
0
 def test_check_and_truncate_name_with_short_name(self):
     name = 'foo_port_name'
     result = utils.check_and_truncate(name)
     self.assertEqual(name, result)
Exemplo n.º 31
0
 def test_check_and_truncate_name_long_name(self):
     name = 'this_is_a_port_whose_name_is_longer_than_40_chars'
     result = utils.check_and_truncate(name)
     self.assertEqual(len(result), utils.MAX_DISPLAY_NAME_LEN)