/srv/irclogs.ubuntu.com/2022/10/26/#cloud-init.txt

meenafalcojr: https://github.com/canonical/cloud-init/pull/1779#issuecomment-1292195028 I'm not seing travis tests running the unit tests15:07
-ubottu:#cloud-init- Pull 1779 in canonical/cloud-init "Net: add BSD ifconfig(8) parser" [Open]15:07
minimalfolcojr, 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:16
minimalthis 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:17
minimalI don't believe udevadm_settle is called at all for BSD systems (though not sure about cc_disk_setup.py)15:18
falcojrmeena: You don't get something like this? https://i.imgur.com/E9avfYC.png15:18
minimalfalcojr: ^^^15:19
falcojrminimal: I think that'd be reasonable, though you might want an alternative15:19
falcojris there anything similar that alpine uses?15:20
minimalfalcojr: Alpine has mdev and mdevd as alternatives to udev but they don' have the equivalent of a settle command15:20
minimalactually 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:21
minimalfalcojr: many months ago growpart (in cloud-utils) was modified to also only run "udevadm settle" if udevadm was present15:27
rharperminimal: 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:11
minimalrharper: I'd guess if udevadm is missing when it shouldn't be then you've got (other) bigger problems ;-)16:20
rharperpossibly16:20
minimalI can wrap it with a condition for Alpine, just wasn't sure if udevadm_settle was ever called for BSDs16:21
meenaminimal: not yet. I have a plan, and going thru all modules is part of that16:22
rharperI'm not saying you have to do it that way, was just a thought.16:22
minimalas I mentione earlier from a quick look at cc_disk_setup I see nothing to prevent it being called for BSDs16:22
meenafalcojr: I couldn't see any tests that… aren't lint tests there16:22
minimalyet cc_disk_setup is enabled for all distros (i.e. including [Free/Open/Net]BSD16:23
minimalthat seems to be the obly module using udevadm_settle that doesn't seem to check for non-Linux OSes16:25
falcojrmeena: 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:05
meenafalcojr: oh. that's another 9 checks that i haven't noticed so far17:11
meenabut any way, this build is is failing for everyone, not just me17:11
meenaright?17:12
falcojryes, https://app.travis-ci.com/github/canonical/cloud-init/jobs/58666136417:12
meenaminimal: I'm not sure disk_setup can work on BSD, I'll need to properly read thru17:14
meenait's not enabled in the config anyway17:14
minimalmeena: I was referring to the "distros": [ALL_DISTROS] in its code17:18
minimalyeah I wasn't sure if the various utils it uses (sfdisk, sgdisk, etc) were present in BSDs17:18
meenanot without additional installation.17:22
meenait would be better to use base system utilities to… you know… manipulate disks and partitions17:23
minimalmeena: so I guess that line should be changed (as it is used to populate the "Supported distros:" entry in the online docs for modules17:24
meenacan you open a bug?17:24
meenaI would actually like to support disk_setup for at least FreeBSD17:25
meenafalcojr: any idea how to get these tests fixed?17:27
minimalmeena: 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 distros17:28
falcojrmeena: looks like they're all subp mocking related17:29
meenaminimal: there's also no distros=Linux, which is true… sometimes… 17:29
falcojrexcept maybe17:29
falcojr> ifs_txt, _ = subp.subp(["ifconfig", "-a"])17:29
falcojrE ValueError: not enough values to unpack (expected 2, got 0)17:29
meenafalcojr: that's the whole point of the mock i committed17:29
falcojrmeena: I'm seeing a common traceback in a lot of tests17:36
falcojrhttps://paste.ubuntu.com/p/4DMwHcj6vx/plain/17:36
falcojrthey're not BSD-related tests, yet it's trying to return a BSD distro17:36
falcojrthat shouldn't be happening, so might be worth checking if you accidentally changed something to make that happen17:37
falcojrcls = distros.fetch(distro) if distro else MockDistro17:37
falcojryet somehow BSD is coming back there for a number of tests?17:37
meenafalcojr: I've fixed at least two functions that now can run on BSDs, and a third one that can run on FreeBSD17:38
meena18:37 <@falcojr> cls = distros.fetch(distro) if distro else MockDistro ⬅️ which commit is that? and which function is it?17:39
falcojrlook at the traceback...though...now that I look a little closer those tests do all seems to specifically requesting a BSD distro17:39
meenahttps://github.com/canonical/cloud-init/pull/1779/commits/bd5c1de7f1829e1e7407e606b1ef6c2fbbfd739e here's the commit that tries to fix this, and seems to have no effect17:42
-ubottu:#cloud-init- Pull 1779 in canonical/cloud-init "Net: add BSD ifconfig(8) parser" [Open]17:42
falcojrthe mock will be popped as soon as the context manager exits17:42
falcojrso you're right...it has no effect17:42
falcojractually, not 100% sure on that...but it's worth double checking17:43
meenaoh17:44
meenai figured from… this https://github.com/canonical/cloud-init/blob/main/tests/unittests/distros/test_networking.py#L20 i figured it should just work17:46
meenabut I reckon i should be using yield then, and return17:47
falcojryeah, this is a fixture, so the entire test is going to run within that context manager17:47
meenawell, if i knew how use fixtures17:48
falcojrpytest docs are pretty good17:49
falcojrI'd start with the example and then move up/down from there https://docs.pytest.org/en/6.2.x/fixture.html#quick-example17:49
falcojrit's the standard way to do setup/teardown in pytest, so worth understanding17:50
Rick14Hello19:07
Rick14I 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 changes19:09
meenaRick14: hi! I'm the main developer for the FreeBSD bits19:19
meenawhat cloud are you running on, and what does your user-data look like, exactly?19:20
Rick14Hi Mina! Im running on a private openstack19:26
Rick14#cloud-config19:26
Rick14users:19:26
Rick14  - name: user19:26
Rick14    ssh-authorized-keys:19:26
Rick14      - KEY19:26
Rick14    gecos: user19:26
Rick14    groups: [adm, wheel]19:26
Rick14    sudo: ["ALL=(ALL) NOPASSWD:ALL"]19:26
Rick14    shell: /bin/csh19:26
Rick14    passwd: "$6$ hash"19:26
Rick14    lock_passwd: false19:26
Rick14ssh_pwauth: yes19:26
Rick14timezone: US/Eastern19:26
Rick14I can see in the logs that cloud init is doing something. Just not making any chnages19:26
meenaRick14: you… could've used a pastebin for that…19:26
Rick14Sorry19:27
meenaanyway, do you have /usr/local/etc/cloud/cloud.cfg.d/99_freebsd.cfg enabled? or even customized?19:27
falcojrIRC 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 here19:28
Rick14Sorry about that and noted. Never used IRC before today.19:30
Rick14And There is a 99_freebsd.cfg in that path. But its just the default19:31
meenaokay, so, let's start fresh: cloud-init clean -slr (cleans logs, seed, and reboot)19:33
Rick14Ok Done19:35
Rick14Cloud init just ran and injected the user19:38
meenaRick14: so… it thought before that it had already ran?19:38
Rick14The user that I was injecting didnt exist till after I ran the command you sent19:39
meenaRick14: 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:41
meenahttps://cloudinit.readthedocs.io/en/latest/topics/modules.html#users-and-groups Module frequency: once-per-instance19:43
meenaRick14: so, maybe the way the image was created, cloud-init clean wasn't called.19:44
Rick14I see ok19:45
Rick14So 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 new19:46
skull-skrimpdo everything you need before booting the guest19:47
skull-skrimpthat is to say, if you're using packer you should have a "provision" stage19:48
skull-skrimpwhen the guest boots it'll run cloud-init as you'd expect19:48
Rick14ok Noted19:48
skull-skrimphttps://developer.hashicorp.com/packer/tutorials/docker-get-started/docker-get-started-provision what are you using to build the images?19:49
Rick14So 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 again19:53
meenaRick14: was it uninstalled in a conflict? pkg logs to /var/log/messages19:59
Rick14Based on what logs are from the previous image, it was uninstalled but nothing much more I could see. So im just trying to reinstall it20:02
Rick14if I hit a conflict I will mention it here20:03
meenaRick14: which FreeBSD version is this? and which cloud-init version is it? Are you using quarterly or latest?20:05
Rick14This is freebsd 13.1 and Release 22.3.420:07
meenaRick14: I'm not seeing 22.3.4 anywhere here: https://www.freshports.org/net/cloud-init/20:18
Rick14I installed from https://github.com/canonical/cloud-init/releases/tag/22.3.420:19
meenaRick14: whyyyyyyyyy20:19
* meena should submit a port upgrade…20:21
meenaRick14: this is my port: https://www.freshports.org/net/cloud-init-devel/20:21
Rick14So I should install from freshports?20:21
meenaRick14: 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:22
Rick14Ok noted.20:23
meenaRick14: you can join #freebsd for help on FreeBSD. You can join #bsdports on EFNet to talk with porters.20:24
Rick14Ok Cool Ill save those for later if I come into port issues20:24
* meena should update net/cloud-init… not just net/cloud-init-devel…20:24
meenajrm: ping20:25
Rick14So 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:25
meenaRick14: you should check the config files, and you need to enable it via service cloudinit enable / sysrc cloudinit_enable=YES20:27
meenathe net/cloud-init port doesn't enable logging, some people like it that way…20:28
Rick14Ok. Im installing it fresh now20:33
meenaRick14: there's a bunch of fixes in net/cloud-init-devel, like we can configure ntp now, but, they're not released yet.20:34
* 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:37
meenafalcojr: I've now reverted that silly mock patch, and the failures, (now) unsurprisingly still look the same.20:55
meenaI'm… starting… to consider… a terrible approach20:56
meenahttps://gist.github.com/e05440564d52fa70f78fa48230085d4420:59
meena"fixes" two failing tests20:59
falcojrI 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 problematic21:13
jrmmeena: pong21:15
meenajrm: i think we should give net/cloud-init also an upgrade21:16
Rick14meena Thank you for your help!21:16
jrmmeena: K.  Still reading the backlog.  Should I pull from the HEAD of upstream's main for the port upgrade?21:17
meenajrm: no, just use the latest tag, and we think about what fixes from net/cloud-init-devel we can push down to net/cloud-init21:18
meenabut, basically, Rick14 installing cloud-init from source, rather than pkg prompted me to check what version we're on, and it's a bit behind21:18
jrmMy last message was stupid me thinking you wrote net/cloud-init-devel, not cloud-init.21:21
meenafalcojr:  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:22
falcojrlike only from a particular call point? Not really21:33
meenafalcojr: person in #python is recommending: https://bpa.st/YPLA21:35
meenabut… i'm starting to wonder if we're not overriding @mock.patch21:36
falcojrthat's one way to make it happen21:37
meenafalcojr: 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/fcefd4a0afee6e156fd7e3f691b0784c21:37
meenaeven tho, I already have this exact pattern in test_networking.py21:38
falcojrfixtures aren't called, they're passed into the test function21:38
falcojroh wait, nm, that's what you're doing21:39
falcojrhave you tried mocking cloudinit.distros.networking.subp.subp ?21:40
falcojrI read this a while ago and found it helpful btw, https://nedbatchelder.com/blog/201908/why_your_mock_doesnt_work.html21:41
meenafalcojr: 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:42
meenai wish there was a way to … initialize the BSD networking class only on (first) use21:43
falcojrbut your test code is importing networking, so it should be patched there21:46
meenafalcojr: either way, that's not waht's failing with this particular attempt…21:50
meena(also, in test_networking.py, we don't import networking)21:53
meenaokay slowly starting to get a better grasp on this22:00
meenahttps://gist.github.com/ee97505d7b297237efbcfbe40563fd38 this works, but I really hope I'll stumble into a more generic solution22:26
meenatomorrow.22:26

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!