

def create_port(self, body):
    p = body.get('port')
    ret = {
        'status': 'ACTIVE',
        'id': str(uuid.uuid4()),
        'mac_address': p.get('mac_address', 'fa:16:3e:b8:f5:fb'),
        'device_id': p.get('device_id', str(uuid.uuid4())),
        'admin_state_up': p.get('admin_state_up', True),
        'security_groups': p.get('security_groups', []),
        'network_id': p.get('network_id'),
        'binding:vnic_type': (p.get('binding:vnic_type') or model.VNIC_TYPE_NORMAL),
    }
    network = self._fake_networks[p['network_id']]
    if ('port_security_enabled' in p):
        ret['port_security_enabled'] = p['port_security_enabled']
    elif ('port_security_enabled' in network):
        ret['port_security_enabled'] = network['port_security_enabled']
    port_security = ret.get('port_security_enabled', True)
    if ((not port_security) and ret['security_groups']):
        raise exception.SecurityGroupCannotBeApplied()
    if network['subnets']:
        ret['fixed_ips'] = [{
            'subnet_id': network['subnets'][0],
            'ip_address': '10.0.0.1',
        }]
    if ((not ret['security_groups']) and ((port_security is None) or (port_security is True))):
        for security_group in self._fake_security_groups.values():
            if (security_group['name'] == 'default'):
                ret['security_groups'] = [security_group['id']]
                break
    self._fake_ports[ret['id']] = ret
    return {
        'port': ret,
    }

dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py MockClient.create_port/original