anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: spritelink/nipap
Issue: Not possible to view the default VRF

It's not possible to view the details of the default VRF;

```
kll@lingloi320 ~/kod/NIPAP/nipap-cli $ ./nipap vrf list 
VRF RT           Name                   Description                             
--------------------------------------------------------------------------------
-                default                The default VRF, typically the Internet.
123:123          foo                                                            
kll@lingloi320 ~/kod/NIPAP/nipap-cli $ ./nipap vrf view -
VRF with [RT: -] not found.
kll@lingloi320 ~/kod/NIPAP/nipap-cli $ ./nipap vrf view default
VRF with [RT: default] not found.
kll@lingloi320 ~/kod/NIPAP/nipap-cli $ 
```


Changed files:
nipap-cli/nipap_cli/nipap_cli.py

diff --git a/nipap-cli/nipap_cli/nipap_cli.py b/nipap-cli/nipap_cli/nipap_cli.py
index d14045f8..4a402335 100755
--- a/nipap-cli/nipap_cli/nipap_cli.py
+++ b/nipap-cli/nipap_cli/nipap_cli.py
@@ -577,12 +577,23 @@ def view_vrf(arg, opts, shell_opts):
     """ View a single VRF
     """
 
-    res = VRF.list({ 'rt': arg })
-    if len(res) < 1:
-        print >> sys.stderr, "VRF with [RT: %s] not found." % arg
+    if arg is None:
+        print >> sys.stderr, "ERROR: Please specify the RT of the VRF to view."
         sys.exit(1)
 
-    v = res[0]
+    # interpret as default VRF (ie, RT = None)
+    if arg.lower() in ('-', 'none'):
+        arg = None
+
+    try:
+        v = VRF.search({
+            'val1': 'rt',
+            'operator': 'equals',
+            'val2': arg }
+            )['result'][0]
+    except (KeyError, IndexError):
+        print >> sys.stderr, "VRF with [RT: %s] not found." % str(arg)
+        sys.exit(1)
 
     print "-- VRF"
     print "  %-12s : %d" % ("ID", v.id)
Repository: spritelink/nipap
Issue: Broken prefix list page web UI

Check out nipap-demo.spritelink.net - I'm just getting a big ugly error message: "undefined".

I ran nipapd with -d -f and it appears to work OK.

Could this be that the web-UI expects the interpretation result to look differently? 


Changed files:
nipap-www/nipapwww/controllers/xhr.py

diff --git a/nipap-www/nipapwww/controllers/xhr.py b/nipap-www/nipapwww/controllers/xhr.py
index 27fd7bf8..96e141ee 100644
--- a/nipap-www/nipapwww/controllers/xhr.py
+++ b/nipap-www/nipapwww/controllers/xhr.py
@@ -109,6 +109,12 @@ class XhrController(BaseController):
             result = VRF.smart_search(request.params['query_string'],
                 search_options, extra_query
                 )
+            # Remove error key in result from backend as it interferes with the
+            # error handling of the web interface.
+            # TODO: Reevaluate how to deal with different types of errors; soft
+            # errors like query string parser errors and hard errors like lost
+            # database.
+            del result['error']
         except NipapError, e:
             return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
 
@@ -233,6 +239,12 @@ class XhrController(BaseController):
             result = Pool.smart_search(request.params['query_string'],
                 search_options
                 )
+            # Remove error key in result from backend as it interferes with the
+            # error handling of the web interface.
+            # TODO: Reevaluate how to deal with different types of errors; soft
+            # errors like query string parser errors and hard errors like lost
+            # database.
+            del result['error']
         except NipapError, e:
             return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
 
@@ -496,6 +508,12 @@ class XhrController(BaseController):
         try:
             result = Prefix.smart_search(request.params['query_string'],
                 search_options, extra_query)
+            # Remove error key in result from backend as it interferes with the
+            # error handling of the web interface.
+            # TODO: Reevaluate how to deal with different types of errors; soft
+            # errors like query string parser errors and hard errors like lost
+            # database.
+            del result['error']
         except NipapError, e:
             return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
Repository: spritelink/nipap
Issue: Prefix smart parser lacks the prefix_length attribute

The prefix smart parser lacks the prefix_length attribute.

Perhaps we could use the list of attributes in backend.py to populate the attribute lists in the smart parser classes?


Changed files:
nipap/nipap/smart_parsing.py

diff --git a/nipap/nipap/smart_parsing.py b/nipap/nipap/smart_parsing.py
index 5dc510f3..d910567a 100644
--- a/nipap/nipap/smart_parsing.py
+++ b/nipap/nipap/smart_parsing.py
@@ -406,6 +406,7 @@ class PrefixSmartParser(SmartParser):
         'order_id': True,
         'pool': True,
         'prefix': True,
+        'prefix_length': True,
         'status': True,
         'total_addresses': True,
         'type': True,
Repository: spritelink/nipap
Issue: Not specifying status results in error

Creating a prefix with pynipap results in an error being thrown from the back end if 'status' is not explicitly specified:

```
In [4]: p = pynipap.Prefix()
In [5]: p.prefix = '1.3.3.0/24'
In [6]: p.type = 'reservation'
In [7]: p.description = 'Test'
In [8]: p.save()
---------------------------------------------------------------------------
NipapError                                Traceback (most recent call last)
<ipython-input-8-395e325a0c83> in <module>()
----> 1 p.save()

/home/lukagarb/dev/venv/lib/python2.7/site-packages/pynipap.pyc in save(self, args)
   1029                     })
   1030             except xmlrpclib.Fault as xml_fault:
-> 1031                 raise _fault_to_exception(xml_fault)
   1032
   1033         # Old object, edit

NipapError: null value in column "status" violates not-null constraint
DETAIL:  Failing row contains (5625, 0, 1.3.3.0/24, 1.3.3.0/24, Test, null, null, null, reservation, 0, null, null, null, null, asdf, null, null, 0, null, {}, {}, 2014-11-07 11:04:21.945863+01, 2014-11-07 11:04:21.945863+01, 256, 0, 256, , null, infinity).
In [9]:
```

The expected behavior would IMHO be to have the prefix added with a sane default, such as 'assigned'. I'd say that the backend handles this correctly by throwing an error; pynipap should not pass the 'status' attribute to the add_prefix function when it's not been set.


Changed files:
pynipap/pynipap.py

diff --git a/pynipap/pynipap.py b/pynipap/pynipap.py
index 01ab3c94..e52979f4 100644
--- a/pynipap/pynipap.py
+++ b/pynipap/pynipap.py
@@ -981,10 +981,13 @@ class Prefix(Pynipap):
             'alarm_priority': self.alarm_priority,
             'monitor': self.monitor,
             'vlan': self.vlan,
-            'status': self.status,
             'avps': self.avps,
             'expires': self.expires
         }
+
+        if self.status is not None:
+            data['status'] = self.status
+
         for tag_name in self.tags:
             data['tags'].append(tag_name)
Repository: spritelink/nipap
Issue: pynipap.NipapError: <type 'exceptions.UnboundLocalError'>:local variable 'q' referenced before assignment

I believe I've found a bug - I'm not entirely sure how I'm triggering it, and what I'm doing is likely wrong, but I don't think it should be returning this response

I've tracked down the erroring code to https://github.com/SpriteLink/NIPAP/blob/master/nipap/nipap/backend.py#L991


Changed files:
nipap/nipap/backend.py

diff --git a/nipap/nipap/backend.py b/nipap/nipap/backend.py
index b6d023a1..4f08ace4 100644
--- a/nipap/nipap/backend.py
+++ b/nipap/nipap/backend.py
@@ -987,16 +987,19 @@ class Nipap:
                 }
             )
 
-        # We can have zero modified rows. Deal with it.
-        if len(qps) > 0:
-            q = qps[0]
-
-            for qp in qps[1:]:
-                q = {
-                    'operator': 'or',
-                    'val1': q,
-                    'val2': qp
-                }
+        # if we didn't update anything return empty list
+        if len(qps) == 0:
+            return []
+
+        # fetch list of objects based on IDs
+        q = qps[0]
+
+        for qp in qps[1:]:
+            q = {
+                'operator': 'or',
+                'val1': q,
+                'val2': qp
+            }
 
         updated = function(auth, q, { 'max_result': 10000 })['result']
Repository: spritelink/nipap
Issue: Invalid IP address causes exception

A search for 10.18.01.1 in the web UI will pop up an exception:

```
invalid IP4R value: "10.18.01.1" LINE .....
```

I guess the socket check is more forgiving than ip4r.


Changed files:
nipap/nipap/smart_parsing.py

diff --git a/nipap/nipap/smart_parsing.py b/nipap/nipap/smart_parsing.py
index f85de005..3187100a 100644
--- a/nipap/nipap/smart_parsing.py
+++ b/nipap/nipap/smart_parsing.py
@@ -564,9 +564,10 @@ class PrefixSmartParser(SmartParser):
             # search
             elif self._get_afi(part[0]) == 4 and len(part[0].split('.')) == 4:
                 self._logger.debug("Query part '" + part[0] + "' interpreted as prefix")
+                address = str(IPy.IP(part[0]))
                 dictsql = {
                     'interpretation': {
-                        'string': part[0],
+                        'string': address,
                         'interpretation': 'IPv4 address',
                         'attribute': 'prefix',
                         'operator': 'contains_equals',
@@ -574,7 +575,7 @@ class PrefixSmartParser(SmartParser):
                     },
                     'operator': 'contains_equals',
                     'val1': 'prefix',
-                    'val2': part[0]
+                    'val2': address
                 }
 
             else:
Repository: spritelink/nipap
Issue: Impossible to change the monitor flag from the web UI

It's not possible to change the prefix monitor flag from the web UI.

Changed files:
nipap-www/nipapwww/controllers/xhr.py

diff --git a/nipap-www/nipapwww/controllers/xhr.py b/nipap-www/nipapwww/controllers/xhr.py
index d908f83a..2e23fd84 100644
--- a/nipap-www/nipapwww/controllers/xhr.py
+++ b/nipap-www/nipapwww/controllers/xhr.py
@@ -589,10 +589,7 @@ class XhrController(BaseController):
         if 'alarm_priority' in request.json:
             p.alarm_priority = validate_string(request.json, 'alarm_priority')
         if 'monitor' in request.json:
-            if request.json['monitor'] == 'true':
-                p.monitor = True
-            else:
-                p.monitor = False
+            p.monitor = request.json['monitor']
 
         if 'vlan' in request.json:
             p.vlan = request.json['vlan']
@@ -664,11 +661,7 @@ class XhrController(BaseController):
             if 'alarm_priority' in request.json:
                 p.alarm_priority = validate_string(request.json, 'alarm_priority')
             if 'monitor' in request.json:
-                if request.json['monitor'] == 'true':
-                    p.monitor = True
-                else:
-                    p.monitor = False
-
+                p.monitor = request.json['monitor']
             if 'country' in request.json:
                 p.country = validate_string(request.json, 'country')
             if 'order_id' in request.json:
Repository: spritelink/nipap
Issue: Assignment from empty pool gives weird error message

```
kll@lingloi320 ~ $ nipap address add family ipv6 from-pool FOO description "BAR"
Could not add prefix to NIPAP: VRF must be the same as the pools implied VRF
```

After adding a prefix to the pool it all works well. This is not the error message I would expect from an empty pool!


Changed files:
nipap/nipap/backend.py

diff --git a/nipap/nipap/backend.py b/nipap/nipap/backend.py
index f2eb90d2..b3d761fe 100644
--- a/nipap/nipap/backend.py
+++ b/nipap/nipap/backend.py
@@ -2291,6 +2291,12 @@ class Nipap:
 
             if 'from-pool' in args:
                 from_pool = self._get_pool(auth, args['from-pool'])
+
+                # make sure there are prefixes in pool, if any prefix is present
+                # than the implied-vrf is set, otherwise the pool is empty
+                if from_pool['vrf_id'] is None:
+                    raise NipapInputError('No prefixes in pool')
+
                 # set default type from pool if missing
                 if 'type' not in attr:
                     attr['type'] = from_pool['default_type']
Repository: spritelink/nipap
Issue: Remove optparse default values in boilerplate.py

The default values for username, password and port passed to optparse in boilerplate.py essentially disables reading these values from ~/.cloginrc. Due to the default values the `options`-object generated by optparse will always have values set and thus will the statements `options.xxx or cfg.get('xxx')` always evaluate to `options.xxx`.


Changed files:
utilities/boilerplate.py

diff --git a/utilities/boilerplate.py b/utilities/boilerplate.py
index eaf9b9c7..11636af1 100644
--- a/utilities/boilerplate.py
+++ b/utilities/boilerplate.py
@@ -26,10 +26,10 @@ if __name__ == '__main__':
 
     import optparse
     parser = optparse.OptionParser()
-    parser.add_option('--username', default='', help="Username")
-    parser.add_option('--password', default='', help="Password")
+    parser.add_option('--username', help="NIPAP backend username")
+    parser.add_option('--password', help="NIPAP backend password")
     parser.add_option('--host', help="NIPAP backend host")
-    parser.add_option('--port', default=1337, help="NIPAP backend port")
+    parser.add_option('--port', help="NIPAP backend port")
     (options, args) = parser.parse_args()
 
     auth_uri = "%s:%s@" % (options.username or cfg.get('global', 'username'),