← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] lp:~harmw/cloud-init/freebsd into lp:cloud-init

 

The test that fails is the one you added.  it fails because I'm running it on linux, where there is no /etc/rc.conf.  I stuffed a 'raise Exception("FOO")' in to show the stack trace.

======================================================================
ERROR: test_simple_write_freebsd (tests.unittests.test_distros.test_netconfig.TestNetCfgDistro)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/mocker.py", line 146, in test_method_wrapper
    result = test_method()
  File "/home/smoser-public/src/cloud-init/freebsd.new/tests/unittests/test_distros/test_netconfig.py", line 200, in test_simple_write_freebsd
    fbsd_distro.apply_network(BASE_NET_CFG, False)
  File "/home/smoser-public/src/cloud-init/freebsd.new/cloudinit/distros/__init__.py", line 120, in apply_network
    dev_names = self._write_network(settings)
  File "/home/smoser-public/src/cloud-init/freebsd.new/cloudinit/distros/freebsd.py", line 261, in _write_network
    self.updatercconf('ifconfig_' + dev, ifconfig)
  File "/home/smoser-public/src/cloud-init/freebsd.new/cloudinit/distros/freebsd.py", line 52, in updatercconf
    conf = self.loadrcconf()
  File "/home/smoser-public/src/cloud-init/freebsd.new/cloudinit/distros/freebsd.py", line 72, in loadrcconf
    raise Exception("FOO")
Exception: FOO


You can use patchOS and patchUtils to provide consistent content for that file.

Regarding 're.compile', using 're.compile' basically caches the compiled regex, and then you can later re-use it more quickly.  Example:
$ python -m timeit --number=100000 --setup="import re; MY_RE=re.compile(r'^\"|\"$')" 'MY_RE.sub("", "abcd")'
100000 loops, best of 3: 1.07 usec per loop
$ python -m timeit --setup="import re;" "re.sub(r'^\"|\"$', \"\", \"abcd\")"
100000 loops, best of 3: 3.14 usec per loop


The quoting is annoying because of shell getting in the way, but essentially, see that re-using the output of re.compile is 3 x faster in this case on that code.

since both of your uses of re (re.match and re.compile) are on static input, you might as well re.compile them.

Thanks, other than test case and that (which is admittedly minor), i'm good with this.

again, thanks for your patience.

-- 
https://code.launchpad.net/~harmw/cloud-init/freebsd/+merge/231024
Your team cloud init development team is requested to review the proposed merge of lp:~harmw/cloud-init/freebsd into lp:cloud-init.


References