def test_container_basic(self): im = NspawnImage(repository=image_name, pull_policy=ImagePullPolicy.IF_NOT_PRESENT, location=url) cont = im.run_via_binary() logger.debug(im.get_metadata()) logger.debug(cont.get_metadata()) assert cont.is_running() assert cont.selfcheck() cont.stop() assert not cont.selfcheck() cont.start() assert cont.selfcheck() cont.stop() assert not cont.selfcheck()
def test_volumes(self): im = NspawnImage(repository=image_name, pull_policy=ImagePullPolicy.IF_NOT_PRESENT, location=url) dirname = mkdtemp() filename = "somefile" host_fn = os.path.join(dirname, filename) run_cmd(["touch", host_fn]) cont = im.run_via_binary(volumes=["{}:/opt".format(dirname)]) cont.execute(["ls", os.path.join("/opt", filename)]) assert os.path.exists(host_fn) cont.execute(["rm", "-f", os.path.join("/opt", filename)]) assert not os.path.exists(host_fn) os.rmdir(dirname)
def test_container_exit_states(self): im = NspawnImage(repository=image_name, pull_policy=ImagePullPolicy.IF_NOT_PRESENT, location=url) cont = im.run_via_binary() try: cont.execute(["exit", "1"]) except subprocess.CalledProcessError: pass else: raise BaseException("It has to fail") cont.execute(["exit", "0"]) cont.execute(["touch", "/aa"]) cont.execute(["ls", "/aa"]) assert 2 == cont.execute(["ls", "/aabb"], ignore_status=True) out = cont.execute(["ls", "/"], return_output=True) assert "sbin" in out out = cont.execute(["ls", "/"], return_full_dict=True) logger.debug(out) cont.stop()