/srv/irclogs.ubuntu.com/2020/08/26/#smooth-operator.txt

stubreactive encoded data to json by default, and gave you access to the raw data if you needed. operator reverted to the basic Juju behaviour of only allowing strings.03:15
stub(which I think originates from insisting that all interaction comes through a CLI, rather than say feeding JSON or YAML to a tool, because we were still trying to write charms using bash)03:16
axinohello07:52
axinoshould I be able to easily unittest leader-get calls with the current version of the ops framework ?07:53
axinoI can see relation-get/relation-set and is-leader, but not leader-get07:54
bthomas𝓖𝓸𝓸𝓭 π“œπ“Έπ“»π“·π“²π“·π“°07:55
Chipacagood morning peeps!09:50
bthomasMorning Chipaca : FYI I was wrong k8s is working correctly. I made the mistake of using pod name "prometheus-0" instead of "prometheus/0". I used the former because that is what one sees when one does get pods.09:52
Chipacabthomas: fresh eyes \o/09:55
bthomasYep. Mornings are best for both coding and math.09:58
bthomasAlso now that I can probe the code using pdb. I realize that the prometheus application containers are stuck in ContainerNotReady status which is set by Kubernetes. My current best guess is that this is because they are failing the kubernetes liveness and readyness probes. I have not yet figured out how to confirm this since the application pod is not yet accessible. I am thinking of just deleting the probes and see what happens.10:00
Chipacamore good news: https://arstechnica.com/science/2020/08/black-paint-on-wind-turbines-helps-prevent-bird-massacres/10:01
bthomasindeed10:01
bthomasnext they need to figure out how to prevent them from being fried by flying into the part of solar beams in solar power plants10:02
Chipacabthomas: or team up with kfc10:25
axinohello again10:25
bthomasrol10:26
Chipacaaxino: πŸ‘‹10:26
axinoI'm trying to mock self.model.unit.is_leader() calls, but not succeeding so far. Would anyone have tips ? I don't want to use harness.set_leader() because it triggers a bunch of other code10:26
axinowhich is completely unrelated to the function I want to test10:27
Chipacaaxino: what code does it trigger?10:27
Chipacaaxino: are you trying to test what happens when something becomes the leader in the middle of something?10:28
axinoChipaca: nope10:28
Chipacaaxino: or are you trying to test what happens when something is the leader already10:28
axino^ this10:28
Chipacaaxino: then harness.set_leader before harness.begin should not trigger anything10:29
axinoI see10:29
axinohmm10:29
axinoexcept we initialize the harness in setUp() currently10:30
Chipacaaxino: including harness.begin?10:30
Chipacahmm10:30
axinoindeed10:30
axinois there an harness.stop equivalent ? :)10:31
axinoI see we call harness.cleanup() in tearDown()10:31
Chipacaaxino: you could harness.disable_hooks()10:32
Chipacaaxino: that'll stop leader_elected from being emitted10:32
axinook10:34
axinoChipaca: that works indeed !10:35
axinothank you10:35
axinoChipaca: for context this is to test _on_database_relation_joined() as coded in https://github.com/canonical/ops-lib-pgsql10:36
axinoI'm still curious, for my personal knowledge, how I would mock self.model.unit.is_leader() calls btw :)10:38
bthomasInformation returned by kubernetes says that the juju-pod-init container has "incomplete status" and the prometheus and prometheus-nginx containers have "unready status". This is after disabling any liveness and readyness probes in the pod spec. All these containers are in the application pod of the charm.10:42
Chipacabthomas: if you take a step back, can you get k8s to do the thing you want it to do without juju?10:47
Chipacabthomas: juju's job is to automate things, but you need to be able to do those things to automate them :)10:48
moon127Chipaca: I've pushed the changes we discussed on the call, https://code.launchpad.net/~moon127/charm-k8s-unifi-poller/+git/charm-k8s-unifi-poller/+merge/389643 is ready to be re-reviewed.10:48
Chipacamoon127: πŸ‘10:49
bthomasChipaca: I think I shall try and learn how to deploy prometheus using just k8s. As I understand this is what you seem to be suggesting. Which sounds like a good idea to me. Thanks.10:51
Chipacaaxino: what's your github @?10:52
mthaddonChipaca: https://github.com/axinojolais10:53
Chipacamthaddon: thanks10:54
Chipacaaxino: https://github.com/canonical/operator/pull/393 :-)10:54
mupPR #393: adds Harness.hooks_disabled, a context manager <Created by chipaca> <https://github.com/canonical/operator/pull/393>10:54
mupPR operator#393 opened: adds Harness.hooks_disabled, a context manager <Created by chipaca> <https://github.com/canonical/operator/pull/393>10:54
Chipacad'oh and the docstring is wrong10:55
* Chipaca fixes10:55
Chipacafacubatista, jam, this is the current state of the fixes for the tests on windows, so you get an idea of the scope of it: https://github.com/canonical/operator/compare/master...chipaca:more-win-fixes10:57
facubatistaΒ‘Muy buenos dΓ­as a todos!10:57
Chipacathere's one more thing to do, that i need to dig into, and then i need to clean it up and make it more reasonable and split it into digestible changes10:57
Chipacabut those changes can result in passing unit tests on windows10:58
Chipaca(granted as i say there is 1 more thing to do, and that one is skipped currently)10:58
Chipacabut that's what i got to last night (or was it this morning) (it was a long hack sesh)10:58
Chipacafacubatista: buen dΓ­a cabeza10:59
* Chipaca speaking all proper-like today10:59
* Chipaca needs more coffee10:59
Chipacawrt windows again, i say "can result" because it makes some assumptions about windows11:00
Chipacalike, you have python and git-for-windows (inlcuding git-bash) installed11:00
Chipacaand it assumes things about how juju calls charms on windows, that need verifying11:00
Chipacabut seem sensible to me :)11:00
Chipacaanyway. coffee! and then to meet with mthaddon11:00
* Chipaca looks at the time11:01
Chipacaor maybe the other way around11:01
facubatistaChipaca, one thing I would love to NOT see in the code are "if is_window" structures, we should hide compatibility code in a layer... for tests we'll sure have different ones in several cases, probably we could handle that with decorators, or something11:16
Chipacafacubatista: yeah i'm hoping to refactor the is_windows checks into a couple of higher level functions11:17
Chipacafacubatista: e.g. i can hide most of it by just wrapping subprocess.run11:17
facubatistawonderful11:17
facubatistaChipaca, remember your https://github.com/canonical/charmcraft/pull/11611:18
Chipacafacubatista: and the _exe_path wrapper already there11:18
mupPR charmcraft#116: include install info in README <Created by chipaca> <https://github.com/canonical/charmcraft/pull/116>11:18
facubatistaChipaca, and please give a review in https://github.com/canonical/charmcraft/pull/13711:18
mupPR charmcraft#137: Fixed global options behaviour <Created by facundobatista> <https://github.com/canonical/charmcraft/pull/137>11:18
* Chipaca gets out his red byro11:18
axinoChipaca: thanks that looks useful12:03
Chipacacrodriguez_: WRT #1892255, do you still need a workaround for older jujus, or are you happy to work with 2.8.2?13:10
jammorning all13:31
Chipacajam: πŸ‘‹β—13:32
Chipacajam: welcome to the other side :-D13:33
crodriguez_morning!13:33
jamChipaca: indeed13:33
crodriguez_let me check which bug that is13:33
jamChipaca: 2.8.2 isn't officially out yet, AIUI13:33
Chipacajam: correct, it's in candidate13:33
facubatistahola jam, welcome back!13:35
jamhi facubatista13:35
crodriguez_oh the one with the env vars. Yeah, I'm using this in a new charm, so I could work with 2.8.2.13:36
drewn3ssstub: Thank you for your response.  As I started thinking about it, I also came to the conclusion that ultimately it's calling the relation-set tool which will require strings.13:52
jamChipaca: this is the code that Juju uses for charm hook extensions: https://github.com/juju/juju/blob/develop/worker/uniter/runner/args.go14:00
jamit supports .ps1, .cmd, .bat and .exe14:00
bthomasChipaca: I have a prometheus deployment running on microk8s accessible from localhost:808014:53
bthomasNow still need to figure outh getting this working with juju14:54
bthomasand charms14:54
facubatistamthaddon, Chipaca, gunicorn meeting?15:03
Chipacafacubatista: 1'15:03
Chipacajam: would it be reasonable to add .py with a special handler for it similar to .ps1 ?15:04
mthaddonfacubatista: will be there in a few mins, just finishing up another call - axino are you on that one already?15:04
axinomthaddon: I am15:04
Chipaca*twice* :-p15:04
mthaddonack, feel free to just go ahead without me15:04
jamChipaca: .py sounds reasonable, but why wouldn't we do dispatch.ps1 /dispatch.bat that can figure the rest out. Its already a dispatch.sh15:15
jamfor Linux15:15
jam(my concern is around things like "python isn't default installed on Windows, so you still have to get it there"15:16
Chipacajam: i guess charmcraft can drop a .bat in there just fine15:30
* facubatista -> live15:40
facubatistaerr, lunch :p15:40
mthaddonwhat am I missing here? https://pastebin.ubuntu.com/p/PNvtcKSnST/ I don't understand why I can import GunicornK8sCharm from "charm" but when I try to mock it I get an import failure :/16:09
narindergupta@here I am looking for running a command line tool in k8s container deployed through framework. I can confirm that I have python in the image but not python3 do we have any examples where I can run the command through python in actions?16:13
bthomasnarindergupta: you can use kubectl exec to run a command in any accessible container. So in principle you can use python subprocess to excecute such a command and collect its output. This may not be the only way to do or the best way to do, just what comes to my mind immediately.16:17
narinderguptabthomas, you mean use Kubectl using python? That won't be as efficient to use as charm action I guess?16:18
bthomasnarindergupta: I was not thinking of charm action. It was if you just wanted to run a command in a container.16:20
narinderguptabthomas, but I thinking of creating actions for operations in case of Cassandra and run nodetool command to maintain and operate the cluster so that's what look for operations through action.16:22
bthomasnarindergupta: why are "os" or "subprocess" modules not suffecient for your purpose ?16:26
facubatistamthaddon, can you show the import failure you're getting? thanks16:28
drewn3ssnarindergupta: would agree, subprocess.check_call or subprocess.check_output to nodetool within your on_action method should be pretty straight forward.16:39
narinderguptadrewn3ss, bthomas yeah that's what I am trying but wanted to make sure there is no wrapper in framework16:40
drewn3ssno, best you might find is charmhelpers.core.host16:40
drewn3sser, charmhelpers.cli16:41
drewn3ssnarindergupta: https://charm-helpers.readthedocs.io/en/latest/api/charmhelpers.cli.html#charmhelpers.cli.CommandLine.run16:44
drewn3ssyou could then add charmhelpers to your requires and import and use that, if it suits your needs.  however, charmhelpers is heavy for subprocess only ;-)16:44
drewn3ss*requirements.txt16:44
narinderguptadrewn3ss, this is operator framework so I doubt this will work though17:35
drewn3ssyou can certainly use charmhelpers in operator charms.17:41
drewn3ssbut simpler is better17:42
Chipacamthaddon: 'mock' is weird, you need to have the referred object in scope exactly as you pass it in17:51
Chipacamthaddon: that first stringy argument is the 'target' of patch(), and the docs say:17:51
Chipacatarget should be a string in the form 'package.module.ClassName'. The target is imported and the specified object replaced with the new object, so the target must be importable from the environment you are calling patch() from. The target is imported when the decorated function is executed, not at decoration time.17:51
Chipacamthaddon: so AIUI (without running the code, and i'm not super experienced with mock so i wouldn't be surprised if i got it a bit wrong), it won't work if you have something else called 'charm' in scope at patching time17:53
Chipacatomorrow i could actually try the code17:54
Chipacatoday it's already beer o'clock here so no code is happening17:54
Chipaca(it's 0% beer but rules are rules)17:54
crodriguezChipaca : RE https://bugs.launchpad.net/juju/+bug/1892255 , 2.8.2 does not contain a fix that works for me, I still see the same issue18:38
facubatistaoh, no chipaca18:44
mupIssue operator#394 opened: Create basic documentation <Created by facundobatista> <https://github.com/canonical/operator/issues/394>18:45
narinderguptaIt seems operator framework is looking for python3. Can we use just python with operator framework rather than python3?19:48
narinderguptaWhile running the action19:48
drewn3sswhy are you looking to run python external to the charm?  are you trying to call "python nodetool"?19:52
narinderguptaI am using juju run juju run-action cassandra/0 status --wait which internally call os.popen("nodetool status")19:54
narinderguptaGive me error /usr/bin/env: β€˜python3’: No such file or directory19:55
narinderguptaI think juju internally runs the action using python call19:55
narinderguptaWhich is python3 in this case so unless containers have python3 I can not run any command. I can confirm my container has python19:56
drewn3ssis nodetool the one stating #!/usr/bin/env python3?19:59
narinderguptadrewn3ss, no nodetool works fine using kubectl exec20:00
drewn3ssnarindergupta: can you share your code where the actions are configured?20:00
narinderguptadrewn3ss, ok let me check in my code in github20:00
narinderguptaHere it is https://paste.ubuntu.com/p/kJhtbVjBKj/20:01
narinderguptaIt is charm.yaml20:01
narinderguptaThis is action https://paste.ubuntu.com/p/ttPYqVKSCD/20:01
narinderguptamicrok8s.kubectl exec -n cassandramodel -it cassandra-0 -- nodetool status20:02
narinderguptaDatacenter: datacenter120:02
narindergupta=======================20:02
narinderguptaStatus=Up/Down20:02
narindergupta|/ State=Normal/Leaving/Joining/Moving20:02
narindergupta--  Address     Load        Tokens  Owns (effective)  Host ID                               Rack20:02
narinderguptaUN  10.1.17.50  554.96 KiB  256     ?                 29057614-e28a-4331-a236-efff00a01312  rack120:02
narinderguptaUN  10.1.17.49  394.43 KiB  256     ?                 6b16060c-5240-4419-a069-e2203276400a  rack120:02
narinderguptaUN  10.1.17.48  417.78 KiB  256     ?                 76fdf154-7c06-4169-a01a-fbf22a42c9e6  rack120:02
narinderguptaWithout juju20:03
drewn3ssare you making symlinks directly to charm.py?20:03
drewn3ssor are you running through the dispatch script20:03
drewn3ssbecause your code shouldn't need #!/usr/bin/env python3 at the top whatsoever20:03
drewn3ssyou just need to implement a CharmBase object in your module that reacts to on.status_action, and the dispatch should take care of executing python for you.20:04
narinderguptaNo I am using charmcraft build and run charm from there20:04
drewn3ssif you make symlinks like the old charms, you're working around the framework's dispatcher20:04
narinderguptadrewn3ss, this must be from charmcraft build20:04
drewn3ssoh, nvm, I do have the shebang on my charm.py too.20:05
drewn3ssand the dispatcher does use that shebang20:05
drewn3ssmy bad20:05
drewn3ssso, do your other hooks work?20:05
narinderguptadrewn3ss, yes like update status20:06
narinderguptaBecause those hooks might be running on operator20:06
narinderguptaconfig_change works20:06
drewn3ssso, gonna need to see a find -ls of your build dir20:07
narinderguptaFind what?20:07
drewn3ss"find ./build -ls" after you charmcraft build20:07
narinderguptaOh ok20:08
narinderguptahttps://pastebin.ubuntu.com/p/j6vxmwJ4W3/20:09
drewn3ssrunning a recent juju model, I assume?20:10
drewn3ss2.7.7 or later?20:10
narindergupta2.8.120:10
drewn3ssI'll note that the 2.7.6 and earlier jujus won't work for actions without the links to dispatch.20:10
narinderguptaubuntu@OrangeBox24:~/narinder/charm-k8s-cassandra$ juju controllers20:10
narinderguptaUse --refresh option with this command to see the latest information.20:10
narinderguptaController        Model           User   Access     Cloud/Region        Models  Nodes    HA  Version20:10
narinderguptafoundations-maas  default         admin  superuser  maas_cloud               1      1  none  2.8.120:10
narinderguptak8s-cloud*        cassandramodel  admin  superuser  microk8s/localhost       2      1     -  2.8.120:10
drewn3sswild.20:10
narinderguptaack20:11
drewn3ssso, operator isn't doing anything fancy in the way of finding python for you, so there must be something different about the env/path when doing run-action vs juju run (some hook)20:12
drewn3sswondering if this is a juju bug in general, or you need to apt-install python3 in your container.20:13
drewn3ssneither of which seems right.20:13
narinderguptadrewn3ss, I am using Datastax Cassandra container directly from there.20:14
drewn3ssnarindergupta: if you fake in a symlink from actions/status to ../dispatch, I wonder if it resolves.20:16
narinderguptaIn build20:16
drewn3ssprobably going to have to unzip the .charm file20:17
drewn3ssand add it in there20:17
drewn3ssand deploy the unpacked directory20:17
drewn3ssjust to test the theory20:17
narinderguptadrewn3ss, I never unzip it...20:17
drewn3sswell, you certainly can if you want to see under the covers.  it's not quite exactly the same as what's in the build dir.20:18
drewn3ssbut .charm is just a classic charm dir in zip format20:18
* drewn3ss wonders if this would be helpful:https://github.com/canonical/operator/issues/29220:23
drewn3sslooks like the framework has access to run requests against the k8s api where you could trigger a kubectl exec-like job20:23
drewn3ssbut I don't think that's the problem you're having20:24
narinderguptadrewn3ss, reading20:24
drewn3ssalso, os.popen is deprecated and subprocess.check_output should be used.20:25
drewn3ssit may be that os.popen could be trying to re-fork your current python environment and failing.20:25
narinderguptadrewn3ss, ok I can try that but by reading above issue I do not think so that will solve my problem though20:27
drewn3ssyeah, wish I knew more about how the framework around k8s charms worked.20:27
drewn3ssgood luck20:27
narinderguptadrewn3ss, thanks man no worries you did try...20:30
narinderguptadrewn3ss, fyi same error20:43
Chipacamthaddon: so, that thing kept on kicking around my brain and bothering me20:52
Chipacamthaddon: here's what you want to do:20:52
Chipaca    @unittest.mock.patch.object(Unit, 'is_leader')20:52
Chipacawhere Unit is ops.model.Unit20:52
Chipacathat's all. Good night.20:53

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