[15:07] <meena> falcojr: https://github.com/canonical/cloud-init/pull/1779#issuecomment-1292195028 I'm not seing travis tests running the unit tests
[15:07] -ubottu:#cloud-init- Pull 1779 in canonical/cloud-init "Net: add BSD ifconfig(8) parser" [Open]
[15:16] <minimal> folcojr, blackboxsw, rharper: wondering if a PR to change cloudinit/util.py's udevadm_settle function to add a "if not subp.which("udevadm"):\nreturn" would be accepted?
[15:17] <minimal> this would be to handle the situation where udev is not installed (i.e. a Linux distro not using udev, specifically Alpine in my case)
[15:18] <minimal> I don't believe udevadm_settle is called at all for BSD systems (though not sure about cc_disk_setup.py)
[15:18] <falcojr> meena: You don't get something like this? https://i.imgur.com/E9avfYC.png
[15:19] <minimal> falcojr: ^^^
[15:19] <falcojr> minimal: I think that'd be reasonable, though you might want an alternative
[15:20] <falcojr> is there anything similar that alpine uses?
[15:20] <minimal> falcojr: Alpine has mdev and mdevd as alternatives to udev but they don' have the equivalent of a settle command
[15:21] <minimal> actually looking at cc_disk_setup.py I don't see anything code to prevent udevadm_settle being called for BSDs - meena, have you ever tested cc_disk_setup with BSDs?
[15:27] <minimal> falcojr: many months ago growpart (in cloud-utils) was modified to also only run "udevadm settle" if udevadm was present
[16:11] <rharper> minimal: one thought is, if we're on linux where udevadm should be, then we might silently skip calling it, rather than failing.  Not sure the best way to have the distro object tell the code path whether to expect udevadm or not. 
[16:20] <minimal> rharper: I'd guess if udevadm is missing when it shouldn't be then you've got (other) bigger problems ;-)
[16:20] <rharper> possibly
[16:21] <minimal> I can wrap it with a condition for Alpine, just wasn't sure if udevadm_settle was ever called for BSDs
[16:22] <meena> minimal: not yet. I have a plan, and going thru all modules is part of that
[16:22] <rharper> I'm not saying you have to do it that way, was just a thought.
[16:22] <minimal> as I mentione earlier from a quick look at cc_disk_setup I see nothing to prevent it being called for BSDs
[16:22] <meena> falcojr: I couldn't see any tests that… aren't lint tests there
[16:23] <minimal> yet cc_disk_setup is enabled for all distros (i.e. including [Free/Open/Net]BSD
[16:25] <minimal> that seems to be the obly module using udevadm_settle that doesn't seem to check for non-Linux OSes
[17:05] <falcojr> meena: in the image, there's a Travis line that's used to click through to the unit tests. You don't see the Travis line?
[17:11] <meena> falcojr: oh. that's another 9 checks that i haven't noticed so far
[17:11] <meena> but any way, this build is is failing for everyone, not just me
[17:12] <meena> right?
[17:12] <falcojr> yes, https://app.travis-ci.com/github/canonical/cloud-init/jobs/586661364
[17:14] <meena> minimal: I'm not sure disk_setup can work on BSD, I'll need to properly read thru
[17:14] <meena> it's not enabled in the config anyway
[17:18] <minimal> meena: I was referring to the "distros": [ALL_DISTROS] in its code
[17:18] <minimal> yeah I wasn't sure if the various utils it uses (sfdisk, sgdisk, etc) were present in BSDs
[17:22] <meena> not without additional installation.
[17:23] <meena> it would be better to use base system utilities to… you know… manipulate disks and partitions
[17:24] <minimal> meena: so I guess that line should be changed (as it is used to populate the "Supported distros:" entry in the online docs for modules
[17:24] <meena> can you open a bug?
[17:25] <meena> I would actually like to support disk_setup for at least FreeBSD
[17:27] <meena> falcojr: any idea how to get these tests fixed?
[17:28] <minimal> meena: better still I can do a PR for it ;-) There's no to do "all distros EXCEPT x" so guess will just need to define the full list of all non-BSDs distros
[17:29] <falcojr> meena: looks like they're all subp mocking related
[17:29] <meena> minimal: there's also no distros=Linux, which is true… sometimes… 
[17:29] <falcojr> except maybe
[17:29] <falcojr> > ifs_txt, _ = subp.subp(["ifconfig", "-a"])
[17:29] <falcojr> E ValueError: not enough values to unpack (expected 2, got 0)
[17:29] <meena> falcojr: that's the whole point of the mock i committed
[17:36] <falcojr> meena: I'm seeing a common traceback in a lot of tests
[17:36] <falcojr> https://paste.ubuntu.com/p/4DMwHcj6vx/plain/
[17:36] <falcojr> they're not BSD-related tests, yet it's trying to return a BSD distro
[17:37] <falcojr> that shouldn't be happening, so might be worth checking if you accidentally changed something to make that happen
[17:37] <falcojr> cls = distros.fetch(distro) if distro else MockDistro
[17:37] <falcojr> yet somehow BSD is coming back there for a number of tests?
[17:38] <meena> falcojr: I've fixed at least two functions that now can run on BSDs, and a third one that can run on FreeBSD
[17:39] <meena> 18:37 <@falcojr> cls = distros.fetch(distro) if distro else MockDistro ⬅️ which commit is that? and which function is it?
[17:39] <falcojr> look at the traceback...though...now that I look a little closer those tests do all seems to specifically requesting a BSD distro
[17:42] <meena> https://github.com/canonical/cloud-init/pull/1779/commits/bd5c1de7f1829e1e7407e606b1ef6c2fbbfd739e here's the commit that tries to fix this, and seems to have no effect
[17:42] -ubottu:#cloud-init- Pull 1779 in canonical/cloud-init "Net: add BSD ifconfig(8) parser" [Open]
[17:42] <falcojr> the mock will be popped as soon as the context manager exits
[17:42] <falcojr> so you're right...it has no effect
[17:43] <falcojr> actually, not 100% sure on that...but it's worth double checking
[17:44] <meena> oh
[17:46] <meena> i figured from… this https://github.com/canonical/cloud-init/blob/main/tests/unittests/distros/test_networking.py#L20 i figured it should just work
[17:47] <meena> but I reckon i should be using yield then, and return
[17:47] <falcojr> yeah, this is a fixture, so the entire test is going to run within that context manager
[17:48] <meena> well, if i knew how use fixtures
[17:49] <falcojr> pytest docs are pretty good
[17:49] <falcojr> I'd start with the example and then move up/down from there https://docs.pytest.org/en/6.2.x/fixture.html#quick-example
[17:50] <falcojr> it's the standard way to do setup/teardown in pytest, so worth understanding
[19:07] <Rick14> Hello
[19:09] <Rick14> I need a hand with getting Cloudinit working on freebsd. I am getting logs of cloud-init.log and cloud-init-output.log and its taking the script but its not making any changes. It runs the modules but no changes
[19:19] <meena> Rick14: hi! I'm the main developer for the FreeBSD bits
[19:20] <meena> what cloud are you running on, and what does your user-data look like, exactly?
[19:26] <Rick14> Hi Mina! Im running on a private openstack
[19:26] <Rick14> #cloud-config
[19:26] <Rick14> users:
[19:26] <Rick14>   - name: user
[19:26] <Rick14>     ssh-authorized-keys:
[19:26] <Rick14>       - KEY
[19:26] <Rick14>     gecos: user
[19:26] <Rick14>     groups: [adm, wheel]
[19:26] <Rick14>     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
[19:26] <Rick14>     shell: /bin/csh
[19:26] <Rick14>     passwd: "$6$ hash"
[19:26] <Rick14>     lock_passwd: false
[19:26] <Rick14> ssh_pwauth: yes
[19:26] <Rick14> timezone: US/Eastern
[19:26] <Rick14> I can see in the logs that cloud init is doing something. Just not making any chnages
[19:26] <meena> Rick14: you… could've used a pastebin for that…
[19:27] <Rick14> Sorry
[19:27] <meena> anyway, do you have /usr/local/etc/cloud/cloud.cfg.d/99_freebsd.cfg enabled? or even customized?
[19:28] <falcojr> IRC doesn't have any kind of auto-text formatting options. It's customary to share code/snippets using a pastebin service. paste.ubuntu.com is a common one here
[19:30] <Rick14> Sorry about that and noted. Never used IRC before today.
[19:31] <Rick14> And There is a 99_freebsd.cfg in that path. But its just the default
[19:33] <meena> okay, so, let's start fresh: cloud-init clean -slr (cleans logs, seed, and reboot)
[19:35] <Rick14> Ok Done
[19:38] <Rick14> Cloud init just ran and injected the user
[19:38] <meena> Rick14: so… it thought before that it had already ran?
[19:39] <Rick14> The user that I was injecting didnt exist till after I ran the command you sent
[19:41] <meena> Rick14: no, i meant: cloud-init thought it had already ran, so when it was reading its configuration and user-data, it determined it had nothing to do (most modules are per-once)
[19:43] <meena> https://cloudinit.readthedocs.io/en/latest/topics/modules.html#users-and-groups Module frequency: once-per-instance
[19:44] <meena> Rick14: so, maybe the way the image was created, cloud-init clean wasn't called.
[19:45] <Rick14> I see ok
[19:46] <Rick14> So when creating the golden image, I should run cloud-init clean before turning it into a template? Sorry for the dumb question, im just trying to figure this out as this is all new
[19:47] <skull-skrimp> do everything you need before booting the guest
[19:48] <skull-skrimp> that is to say, if you're using packer you should have a "provision" stage
[19:48] <skull-skrimp> when the guest boots it'll run cloud-init as you'd expect
[19:48] <Rick14> ok Noted
[19:49] <skull-skrimp> https://developer.hashicorp.com/packer/tutorials/docker-get-started/docker-get-started-provision what are you using to build the images?
[19:53] <Rick14> So we had a freebsd image on our stack and Im just updating it and something happened from the previous image where could-init was just gone. So I was tasked with getting it running again
[19:59] <meena> Rick14: was it uninstalled in a conflict? pkg logs to /var/log/messages
[20:02] <Rick14> Based on what logs are from the previous image, it was uninstalled but nothing much more I could see. So im just trying to reinstall it
[20:03] <Rick14> if I hit a conflict I will mention it here
[20:05] <meena> Rick14: which FreeBSD version is this? and which cloud-init version is it? Are you using quarterly or latest?
[20:07] <Rick14> This is freebsd 13.1 and Release 22.3.4
[20:18] <meena> Rick14: I'm not seeing 22.3.4 anywhere here: https://www.freshports.org/net/cloud-init/
[20:19] <Rick14> I installed from https://github.com/canonical/cloud-init/releases/tag/22.3.4
[20:19] <meena> Rick14: whyyyyyyyyy
[20:21]  * meena should submit a port upgrade…
[20:21] <meena> Rick14: this is my port: https://www.freshports.org/net/cloud-init-devel/
[20:21] <Rick14> So I should install from freshports?
[20:22] <meena> Rick14: freshports is just an interface. you should install from `pkg`, and if you're not getting the latest version of a port you're expecting, you should file a bug / submit a patch for a port-upgrade.
[20:23] <Rick14> Ok noted.
[20:24] <meena> Rick14: you can join #freebsd for help on FreeBSD. You can join #bsdports on EFNet to talk with porters.
[20:24] <Rick14> Ok Cool Ill save those for later if I come into port issues
[20:24]  * meena should update net/cloud-init… not just net/cloud-init-devel…
[20:25] <meena> jrm: ping
[20:25] <Rick14> So after I install from net/cloud-init, Do I have to run any commands to stage cloud init before turning it into an image?
[20:27] <meena> Rick14: you should check the config files, and you need to enable it via service cloudinit enable / sysrc cloudinit_enable=YES
[20:28] <meena> the net/cloud-init port doesn't enable logging, some people like it that way…
[20:33] <Rick14> Ok. Im installing it fresh now
[20:34] <meena> Rick14: there's a bunch of fixes in net/cloud-init-devel, like we can configure ntp now, but, they're not released yet.
[20:37]  * meena still can't get over how FreeBSD's cloud-init runs on more platforms than Linux'
[20:37] <meena> (this is because we eliminated dmidecode)
[20:55] <meena> falcojr: I've now reverted that silly mock patch, and the failures, (now) unsurprisingly still look the same.
[20:56] <meena> I'm… starting… to consider… a terrible approach
[20:59] <meena> https://gist.github.com/e05440564d52fa70f78fa48230085d44
[20:59] <meena> "fixes" two failing tests
[21:13] <falcojr> I think the idea behind the mock patch was a good one. If you have a common class you're going to be using in a bunch of tests but it has some code you don't want being executed in unit tests, then replace the problematic piece with something not problematic
[21:15] <jrm> meena: pong
[21:16] <meena> jrm: i think we should give net/cloud-init also an upgrade
[21:16] <Rick14> meena Thank you for your help!
[21:17] <jrm> meena: K.  Still reading the backlog.  Should I pull from the HEAD of upstream's main for the port upgrade?
[21:18] <meena> jrm: no, just use the latest tag, and we think about what fixes from net/cloud-init-devel we can push down to net/cloud-init
[21:18] <meena> but, basically, Rick14 installing cloud-init from source, rather than pkg prompted me to check what version we're on, and it's a bit behind
[21:21] <jrm> My last message was stupid me thinking you wrote net/cloud-init-devel, not cloud-init.
[21:22] <meena> falcojr:  btw, is there a way to only @mock.patch that only triggers on a specific subp.subp call? (this is well possible in Ruby…)
[21:33] <falcojr> like only from a particular call point? Not really
[21:35] <meena> falcojr: person in #python is recommending: https://bpa.st/YPLA
[21:36] <meena> but… i'm starting to wonder if we're not overriding @mock.patch
[21:37] <falcojr> that's one way to make it happen
[21:37] <meena> falcojr: btw, re https://docs.pytest.org/en/6.2.x/fixture.html#quick-example — in my code, this doesn't work: https://gist.github.com/fcefd4a0afee6e156fd7e3f691b0784c
[21:38] <meena> even tho, I already have this exact pattern in test_networking.py
[21:38] <falcojr> fixtures aren't called, they're passed into the test function
[21:39] <falcojr> oh wait, nm, that's what you're doing
[21:40] <falcojr> have you tried mocking cloudinit.distros.networking.subp.subp ?
[21:41] <falcojr> I read this a while ago and found it helpful btw, https://nedbatchelder.com/blog/201908/why_your_mock_doesnt_work.html
[21:42] <meena> falcojr: in networking.py, we're just importing from cloudinit import net, subp, util; so i assumed that's the one i have to mock.
[21:43] <meena> i wish there was a way to … initialize the BSD networking class only on (first) use
[21:46] <falcojr> but your test code is importing networking, so it should be patched there
[21:50] <meena> falcojr: either way, that's not waht's failing with this particular attempt…
[21:53] <meena> (also, in test_networking.py, we don't import networking)
[22:00] <meena> okay slowly starting to get a better grasp on this
[22:26] <meena> https://gist.github.com/ee97505d7b297237efbcfbe40563fd38 this works, but I really hope I'll stumble into a more generic solution
[22:26] <meena> tomorrow.