a Ag)@sddlZddlZddlZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z da dadadadadadadaddZddZd$dd Zifd d Zd d ZddZgdifddZgdifddZddZddZddZddZ ddZ!ddZ"d d!Z#d%d"d#Z$dS)&NFcCs tjjdddtgdddjdkS)NpodmanZimageexistsFT)check no_podmanr)testenvcmdrun image_name returncoder r S/home/osmocom-build/jenkins/workspace/ttcn3-hss-test-ogs/_testenv/testenv/podman.py image_existssr cCstjjddtddgdddd}t|jddd d d}tj |d }t d |t j d rvt ddSt jtjd}t |j}tj|}t dt|d d||kS)Nrhistoryz--formatjsonT)capture_outputrtextrcreated.z%Y-%m-%dT%H:%M:%SzImage creation date: Z!TESTENV_NO_IMAGE_UP_TO_DATE_CHECKz'Assuming the podman image is up-to-datezpodman/DockerfilezDockerfile last modified: )rrrr rloadsstdoutsplitdatetimestrptimeloggingdebugosenvirongetpathjoindata_dirstatst_mtimeutcfromtimestampstr)rrZ dockerfilemtimer r r image_up_to_dates"      r'Tc Cs||r8tr8tr8tdttjjr4tdndStdttj j ddddt dtt j tjd gd d dS) NzPodman image is up-to-date: z&Building anyway since --force was usedzBuilding podman image: Zbuildahbuildz --build-argzDISTRO=-trT)r)r r'rrr rargsforceinforrdistrorrr r!)Zcheck_existingr r r image_build9s$   r.cCs:g}tj|dD]\}}|d|d|g7}q|S)NT-e=)rr generate_envitems)envretkeyvalr r r generate_env_podmanQsr7cCs2ttjdtjatdatddddadS)Nr-z-osmo-ttcn3-testenv:-_)getattrrr*distro_defaultr-r replacer r r r init_image_name_distroZs r>cCstjtjjddatjtjjddatjtddtjtddtjtjj ddt t slt dt stjddkrtd td ntd td tttjjrdadS) Nrz var-cache-aptz var-lib-aptTexist_okzDMissing podman image, run 'testenv.py init podman' first to build itZTESTENV_REBUILD_OUTDATED_IMAGE1zQThe podman image is outdated, rebuilding it... (TESTENV_REBUILD_OUTDATED_IMAGE=1)Fz[The podman image might be outdated, consider running 'testenv.py init podman' to rebuild itz@Set TESTENV_REBUILD_OUTDATED_IMAGE=1 to rebuild it automatically)rrr rr*cacheapt_dir_var_cacheapt_dir_var_libmakedirsccacher>r NoTraceExceptionr'rrrwarningr.ratexitregisterstopshellrun_shell_on_stopr r r r initcs&     rNcOststd|t|}|t|7}|dg7}|r@|d|g7}t|trTdd|g}tjjddg|tg|g|Rdd i|S) NzTAttempting to execute a command in podman, but the container isn't running anymore: r)-wsh-crexecrT) container_name RuntimeErrorlistr7 isinstancer%rrr)r podman_optscwdr3r*kwargsr r r exec_cmds$     rZcCsdt|t|}|r |d|g7}t|tr4dd|g}ddg|tg|}td|t|S)NrOrPrQrrR+ ) rUr7rVr%rSrr subprocessPopen)rrWrXr3r r r exec_cmd_backgrounds   r^cCsXz@tdtjddtddgtjd}|jrtdWdSqWnt yRYn0dS)NrrRtouchz /tmp/watchdog)stderrz0feed_watchdog_loop: podman container has stopped) timesleepr\rrSDEVNULLr rrKeyboardInterrupt)pr r r feed_watchdog_loops    rgcCs0tdD]}tdtrdSqtddS)Ndg?zPodman failed to start)rangerbrc is_runningrT)ir r r wait_until_starteds   rlcCsbtjtjjd}tj|ddtd|t j |tj dt tjtd}|dS)NrTr?r[)r3)target)rrr rtestdirtestdir_topdirrErrr\r]rr1rlmultiprocessingProcessrgstart)rlog_dirfeed_watchdog_processr r r start_in_backgrounds rucCstjj}tj}tjjdtatj tj d}ddddtddd d |d td d |ddddt ddt dddddddg}tjjr|ddg7}n|d|d|g7}tjjrtjdstj dr|ddg7}tj tjrttj}|d|d|dg7}|d|d|dtjjdtjjdtjjdtjjdtjdtjttj tj dg 7}t|td d!gtj t d"}tj |stgd#dS)$Nr9zpodman/seccomp.jsonrrz--rmz--namez --log-driverz json-filez --log-optzpath=z/podman/z.logz--security-opt=seccomp=z--cap-add=NET_ADMINz--cap-add=NET_RAWz--device=/dev/net/tunz--volumez:/var/cache/aptz :/var/lib/aptz--sysctlz"net.ipv4.conf.all.send_redirects=0z&net.ipv4.conf.default.send_redirects=0r/zPODMAN=1zTESTENV_BINARY_REPO=1r8ZTESTENV_NO_KVMz/dev/kvmz/dev/kvm:/dev/kvmz:rozscripts/testenv-podman-main.shrmz /etc/apt/apt.conf.d/docker-cleanz pkgcache.binzapt-get-qupdate)rrnroosmo_devget_osmo_dev_dirprefix restart_countrSrrr r!rCrDr* binary_repokernelrrrislinkcustom_kernel_pathreadlinkrBrFsrc_dirr rurZ)ro osmo_dev_dirZseccomprdestZpkgcacher r r rrsx        rrcCs |dkr dStd|ddS)Nzdebian:bookwormZ Debian_12zCan't translate distro z to repo_dir!)rT)r-r r r distro_to_repo_dirsrcCspd}|d7}|tjjdd7}|d7}|tt7}|d7}d}tdd d t|d |gtgd dS) Nzdeb [signed-by=/obs.key]z( https://downloads.osmocom.org/packages/r8z://z/ ./z$/etc/apt/sources.list.d/osmocom.listrPrQzecho z > rw) rr*r~r=rr-rZshlexquote)configrr r r enable_binary_repo$s  rcCs:tdur dSdddddtg}tj|dddjs6dSdS) NFrpsrxz--filterzname=T)rr)rSr\rr)rr r r rj2s rjcCsts dStj|sDtrDtdtdgdgtjjdddda|rLdnd}td|t rxt t da tj j d d tgd dd da|rtd 7atdS)Nz=Running interactive shell before stopping container (--shell)bashz-iF)rXstdinrz (restart)zStopping podman containerrkillT)rrr)rjrcoredump get_backtracerMrr,rZrnrt terminatewaitrrrSr}rr)ZrestartZ restart_msgr r r rK=s$   rK)T)F)%rIrrrrprrr\ testenv.cmdrtestenv.testdirtestenv.coredumprbr r-rSrCrDrtrMr}r r'r.r7r>rNrZr^rgrlrurrrrrjrKr r r r sF   # M