def test_docker_run_dvol_multiple_containers_shows_up_in_list_output(self): container1 = "fancy" container2 = "fancier" def cleanup(): run(["docker", "rm", "-f", container1]) run(["docker", "rm", "-f", container2]) run([DVOL, "rm", "-f", "memorydiskserver"]) try: cleanup() except: pass run([ "docker", "run", "--name", container1, "-d", "-v", "memorydiskserver:/data", "--volume-driver", "dvol", "clusterhq/memorydiskserver" ]) run([ "docker", "run", "--name", container2, "-d", "-v", "memorydiskserver:/data", "--volume-driver", "dvol", "clusterhq/memorydiskserver" ]) def dvol_list_includes_container_names(): result = run([DVOL, "list"]) # Either way round is OK if (("/" + container1 + ",/" + container2 not in result) and ("/" + container2 + ",/" + container1 not in result)): raise Exception( "containers never showed up in result %s" % (result,) ) try_until(dvol_list_includes_container_names) cleanup()
def test_docker_run_dvol_container_show_up_in_list_output(self): container = "fancy" def cleanup(): cmds = [ ["docker", "rm", "-f", container], ["docker", "volume", "rm", "memorydiskserver"], [DVOL, "rm", "-f", "memorydiskserver"], ] for cmd in cmds: try: run(cmd) except: pass cleanup() self.addCleanup(cleanup) run([ "docker", "run", "--name", container, "-d", "-v", "memorydiskserver:/data", "--volume-driver", "dvol", "clusterhq/memorydiskserver" ]) def dvol_list_includes_container_name(): result = dvol(["list"]) if "/" + container not in result: raise Exception("container never showed up in result %s" % (result, )) try_until(dvol_list_includes_container_name)
def test_dvol_volumes_listed_in_docker(self): """ Volumes created with dvol an be listed in `docker volume ls`. """ def cleanup(): try: run(["docker", "volume", "rm", "docker-volume-list-test"]) except: pass try: run([DVOL, "rm", "-f", "docker-volume-list-test"]) except: pass cleanup() self.addCleanup(cleanup) run([DVOL, "init", "docker-volume-list-test"]) docker_output = run(["docker", "volume", "ls"]) for line in docker_output.split("\n"): if line.startswith("dvol") and "docker-volume-list-test" in line: return self.fail("Volume 'docker-volume-list-test' not found in Docker " "output:\n\n" + docker_output)
def test_docker_run_dvol_container_show_up_in_list_output(self): container = "fancy" def cleanup(): cmds = [ ["docker", "rm", "-f", container], ["docker", "volume", "rm", "memorydiskserver"], [DVOL, "rm", "-f", "memorydiskserver"], ] for cmd in cmds: try: run(cmd) except: pass cleanup() self.addCleanup(cleanup) run([ "docker", "run", "--name", container, "-d", "-v", "memorydiskserver:/data", "--volume-driver", "dvol", "clusterhq/memorydiskserver" ]) def dvol_list_includes_container_name(): result = dvol(["list"]) if "/" + container not in result: raise Exception("container never showed up in result %s" % (result,)) try_until(dvol_list_includes_container_name)
def test_implicit_creation(self): """ ``docker run`` with the dvol volume driver creates a master branch. """ volume_name = 'docker-volume-implicit-creation-test' volume_directory = "/data" docker_volume_arg = '%s:/%s' % (volume_name, volume_directory) # XXX: This is a) duplicated, b) dangerous, as the bare `except` masks # real errors. def cleanup(): try: run(["docker", "volume", "rm", volume_name]) except: pass try: dvol(["rm", "-f", volume_name]) except: pass cleanup() self.addCleanup(cleanup) run([ 'docker', 'run', '--rm', '-v', docker_volume_arg, '--volume-driver=dvol', 'busybox', 'sh', '-c', 'echo word > /%s/file' % (volume_directory, ) ]) branch_output = dvol(["branch"]) self.assertIn('* master', branch_output)
def test_unique_volumes(self): """ Two separate volumes do not share the same filesystem namespace. """ alpha = "test-unique-volume-alpha" beta = "test-unique-volume-beta" def cleanup(): for volume in [alpha, beta]: try: run(["docker", "rm", "-fv", volume]) except: pass try: run(["docker", "volume", "rm", volume]) except: pass try: dvol(["rm", "-f", volume]) except: pass cleanup() self.addCleanup(cleanup) for volume in [alpha, beta]: run(["docker", "run", "-v", "%s:/data" % (volume,), "--volume-driver", "dvol", "--name", volume, "ubuntu", "bash", "-c", "echo -n %s > /data/data" % (volume,)]) run(["docker", "rm", volume]) # using volume as the container name data = dict() for volume in [alpha, beta]: result = run(["docker", "run", "-v", "%s:/data" % (volume,), "--volume-driver", "dvol", "--name", volume, "ubuntu", "cat", "/data/data"]) data[volume] = result # These could be moved into the loop above, but leave them here so it # is clearer which is failing. self.assertEqual(data[alpha], alpha) self.assertEqual(data[beta], beta)
def test_implicit_creation(self): """ ``docker run`` with the dvol volume driver creates a master branch. """ volume_name = 'docker-volume-implicit-creation-test' volume_directory = "/data" docker_volume_arg = '%s:/%s' % (volume_name, volume_directory) # XXX: This is a) duplicated, b) dangerous, as the bare `except` masks # real errors. def cleanup(): try: run(["docker", "volume", "rm", volume_name]) except: pass try: dvol(["rm", "-f", volume_name]) except: pass cleanup() self.addCleanup(cleanup) run(['docker', 'run', '--rm', '-v', docker_volume_arg, '--volume-driver=dvol', 'busybox', 'sh', '-c', 'echo word > /%s/file' % (volume_directory,)]) branch_output = dvol(["branch"]) self.assertIn('* master', branch_output)
def cleanup(): for volume in [alpha, beta]: try: run(["docker", "rm", "-fv", volume]) except: pass try: run(["docker", "volume", "rm", volume]) except: pass try: dvol(["rm", "-f", volume]) except: pass
def cleanup(): try: run(["docker", "volume", "rm", volume_name]) except: pass try: dvol(["rm", "-f", volume_name]) except: pass
def cleanup(): try: run(["docker", "volume", "rm", "docker-volume-list-test"]) except: pass try: dvol(["rm", "-f", "docker-volume-list-test"]) except: pass
def start_memorydiskserver(self): """ Standard start for memorydiskserver. """ run([ "docker", "run", "--name", "memorydiskserver", "-d", "-v", "memorydiskserver:/data", "--volume-driver", "dvol", "-p", "8080:80", "clusterhq/memorydiskserver", ])
def cleanup(): try: run(["docker", "volume", "rm", "docker-volume-list-test"]) except: pass try: run([DVOL, "rm", "-f", "docker-volume-list-test"]) except: pass
def cleanup(): cmds = [ ["docker", "rm", "-f", container], ["docker", "volume", "rm", "memorydiskserver"], [DVOL, "rm", "-f", "memorydiskserver"], ] for cmd in cmds: try: run(cmd) except: pass
def cleanup(): try: run(["docker", "rm", "-f", "memorydiskserver"]) except: pass try: run(["docker", "volume", "rm", "memorydiskserver"]) except: pass try: dvol(["rm", "-f", "memorydiskserver"]) except: pass
def test_docker_run_test_container(self): def cleanup(): run(["docker", "rm", "-f", "memorydiskserver"]) try: cleanup() except: pass run([ "docker", "run", "--name", "memorydiskserver", "-d", "-p", "8080:80", "clusterhq/memorydiskserver" ]) wait_for_server = try_until( lambda: get("http://" + docker_host() + ":8080/get") ) self.assertEqual(wait_for_server.content, "Value: ")
def test_dvol_volumes_listed_in_docker(self): """ Volumes created with dvol an be listed in `docker volume ls`. """ def cleanup(): try: run(["docker", "volume", "rm", "docker-volume-list-test"]) except: pass try: dvol(["rm", "-f", "docker-volume-list-test"]) except: pass cleanup() self.addCleanup(cleanup) dvol(["init", "docker-volume-list-test"]) docker_output = run(["docker", "volume", "ls"]) for line in docker_output.split("\n"): if line.startswith("dvol") and "docker-volume-list-test" in line: return self.fail("Volume 'docker-volume-list-test' not found in Docker " "output:\n\n" + docker_output)
def test_docker_run_test_container(self): def cleanup(): run(["docker", "rm", "-f", "memorydiskserver"]) try: cleanup() except: pass run([ "docker", "run", "--name", "memorydiskserver", "-d", "-p", "8080:80", "clusterhq/memorydiskserver" ]) wait_for_server = try_until( lambda: get("http://" + docker_host() + ":8080/get")) self.assertEqual(wait_for_server.content, "Value: ")
def test_unique_volumes(self): """ Two separate volumes do not share the same filesystem namespace. """ alpha = "test-unique-volume-alpha" beta = "test-unique-volume-beta" def cleanup(): for volume in [alpha, beta]: try: run(["docker", "rm", "-fv", volume]) except: pass try: run(["docker", "volume", "rm", volume]) except: pass try: dvol(["rm", "-f", volume]) except: pass cleanup() self.addCleanup(cleanup) for volume in [alpha, beta]: run([ "docker", "run", "-v", "%s:/data" % (volume, ), "--volume-driver", "dvol", "--name", volume, "ubuntu", "bash", "-c", "echo -n %s > /data/data" % (volume, ) ]) run(["docker", "rm", volume]) # using volume as the container name data = dict() for volume in [alpha, beta]: result = run([ "docker", "run", "-v", "%s:/data" % (volume, ), "--volume-driver", "dvol", "--name", volume, "ubuntu", "cat", "/data/data" ]) data[volume] = result # These could be moved into the loop above, but leave them here so it # is clearer which is failing. self.assertEqual(data[alpha], alpha) self.assertEqual(data[beta], beta)
def dvol_list_includes_container_names(): result = run([DVOL, "list"]) # Either way round is OK if (("/" + container1 + ",/" + container2 not in result) and ("/" + container2 + ",/" + container1 not in result)): raise Exception( "containers never showed up in result %s" % (result,) )
def test_docker_volumes_removed(self): """ When a dvol volume is removed, you can implicitly create a new volume using `docker run` and it succeeds. """ def cleanup(): try: run(["docker", "rm", "-fv", "volumeremove"]) except: pass try: run(["docker", "rm", "-fv", "volumeremoveerror"]) except: pass try: run(["docker", "volume", "rm", "volumeremove"]) pass except: pass try: dvol(["rm", "-f", "volumeremove"]) pass except: pass cleanup() self.addCleanup(cleanup) # Start a new container run([ "docker", "run", "--name", "volumeremove", "-v", "volumeremove:/data", "--volume-driver", "dvol", "-d", "busybox", "true" ]) # Remove the volume dvol(["rm", "-f", "volumeremove"]) # Start a new container on the same volume and there are no errors run([ "docker", "run", "--name", "volumeremoveerror", "-v", "volumeremove:/data", "--volume-driver", "dvol", "-d", "busybox", "true" ])
def test_docker_run_dvol_multiple_containers_shows_up_in_list_output(self): container1 = "fancy" container2 = "fancier" def cleanup(): cmds = [ ["docker", "rm", "-f", container1], ["docker", "rm", "-f", container2], ["docker", "volume", "rm", "memorydiskserver"], [DVOL, "rm", "-f", "memorydiskserver"], ] for cmd in cmds: try: run(cmd) except: pass cleanup() self.addCleanup(cleanup) run([ "docker", "run", "--name", container1, "-d", "-v", "memorydiskserver:/data", "--volume-driver", "dvol", "clusterhq/memorydiskserver" ]) run([ "docker", "run", "--name", container2, "-d", "-v", "memorydiskserver:/data", "--volume-driver", "dvol", "clusterhq/memorydiskserver" ]) def dvol_list_includes_container_names(): result = dvol(["list"]) # Either way round is OK if (("/" + container1 + ",/" + container2 not in result) and ("/" + container2 + ",/" + container1 not in result)): raise Exception("containers never showed up in result %s" % (result, )) try_until(dvol_list_includes_container_names)
def test_docker_volumes_removed(self): """ When a dvol volume is removed, you can implicitly create a new volume using `docker run` and it succeeds. """ def cleanup(): try: run(["docker", "rm", "-fv", "volumeremove"]) except: pass try: run(["docker", "rm", "-fv", "volumeremoveerror"]) except: pass try: run(["docker", "volume", "rm", "volumeremove"]) pass except: pass try: dvol(["rm", "-f", "volumeremove"]) pass except: pass cleanup() self.addCleanup(cleanup) # Start a new container run(["docker", "run", "--name", "volumeremove", "-v", "volumeremove:/data", "--volume-driver", "dvol", "-d", "busybox", "true"]) # Remove the volume dvol(["rm", "-f", "volumeremove"]) # Start a new container on the same volume and there are no errors run(["docker", "run", "--name", "volumeremoveerror", "-v", "volumeremove:/data", "--volume-driver", "dvol", "-d", "busybox", "true"])
def cleanup(): try: run(["docker", "rm", "-fv", "volumeremove"]) except: pass try: run(["docker", "rm", "-fv", "volumeremoveerror"]) except: pass try: run(["docker", "volume", "rm", "volumeremove"]) pass except: pass try: dvol(["rm", "-f", "volumeremove"]) pass except: pass
def cleanup(): run(["docker", "rm", "-f", "memorydiskserver"])
def dvol(args): return run([DVOL] + args)
def dvol_list_includes_memorydiskserver(): result = run([DVOL, "list"]) if "memorydiskserver" not in result: raise Exception("volume never showed up in result %s" % (result,))
def dvol_list_includes_container_name(): result = run([DVOL, "list"]) if "/" + container not in result: raise Exception("container never showed up in result %s" % (result,))
def test_switch_branches_restarts_containers(self): """ Docker containers are restarted when switching branches. """ self.cleanup_memorydiskserver() self.start_memorydiskserver() # We have to do an initial state commit before we can switch branches run([DVOL, "commit", "-m", "Initial"]) run([DVOL, "checkout", "-b", "alpha"]) self.try_set_memorydiskserver_value("alpha") run([DVOL, "commit", "-m", "alpha"]) run([DVOL, "checkout", "-b", "beta"]) self.try_set_memorydiskserver_value("beta") run([DVOL, "commit", "-m", "beta"]) current_value = self.try_get_memorydiskserver_value() self.assertEqual(current_value, "Value: beta") run([DVOL, "checkout", "alpha"]) current_value = self.try_get_memorydiskserver_value() self.assertEqual(current_value, "Value: alpha")
def cleanup(): run(["docker", "rm", "-f", container]) run([DVOL, "rm", "-f", "memorydiskserver"])