Пример #1
0
 def test_mounts(self):
     im = NspawnImage(repository=image_name,
                      pull_policy=ImagePullPolicy.IF_NOT_PRESENT,
                      location=url)
     with im.mount() as fs:
         logger.debug(fs.mount_point)
         assert fs.directory_is_present("/lost+found")
Пример #2
0
 def test_image(self):
     im1 = NspawnImage(repository=image_name, pull_policy=ImagePullPolicy.IF_NOT_PRESENT,
                       location=url)
     logger.debug("%s", im1)
     logger.debug("%s", im1.get_metadata())
     logger.debug("%s", im1.get_id())
     logger.debug("%s", im1.get_full_name())
Пример #3
0
    def test_image_run_foreground(self):
        im = NspawnImage(repository=image_name, pull_policy=ImagePullPolicy.IF_NOT_PRESENT,
                         location=url)
        cmd = im.run_foreground(["ls", "/"]).communicate()
        out = cmd
        assert not out[0]

        out = im.run_foreground(["ls", "/"], stdout=subprocess.PIPE).communicate()
        stdout = out[0].decode("utf-8")
        assert "sbin" in stdout
Пример #4
0
 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)
Пример #5
0
 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()
Пример #6
0
 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()
Пример #7
0
    def test_image_bootstrapping(self):
        with NspawnBackend() as backend:
            backend.cleanup_containers()
            backend.cleanup_images()

        im = NspawnImage.bootstrap(repositories=bootstrap_repos,
                                   name="bootstrapped",
                                   additional_packages=["fedora-release"])
        logger.debug(im.get_metadata())
        out = im.run_foreground(["ls", "/"],
                                stdout=subprocess.PIPE).communicate()
        assert "sbin" in out[0]
        out = im.run_foreground(["ls", "/etc"],
                                stdout=subprocess.PIPE).communicate()
        logger.info(out)
        assert "os-release" in out[0]
        out = im.run_foreground(["cat", "/etc/os-release"],
                                stdout=subprocess.PIPE).communicate()
        logger.info(out)
        assert "VERSION_ID=27" in out[0]
        im.rmi()