def test_single_source_corrupt(tmpdir): with pytest.raises(CalledProcessError): package("resources-nonbootstrapable/single_source_corrupt", "single_source", tmpdir) # Check the corrupt file got moved to the right place expect_fs(str(tmpdir.join("single_source/cache")), ["foo.corrupt"])
def test_single_source_corrupt(tmpdir): copyfile("resources-nonbootstrapable/buildinfo.json", str(tmpdir.join('buildinfo.json'))) with pytest.raises(CalledProcessError): package("resources-nonbootstrapable/single_source_corrupt", "single_source", tmpdir) # Check the corrupt file got moved to the right place expect_fs(str(tmpdir.join("cache/packages/single_source/single_source")), ["foo.corrupt"])
def test_recovery_archive(tmpdir): # Recover from the "archive" state correctly. shutil.copytree("resources/install_recovery_archive", str(tmpdir.join("install")), symlinks=True) install = Install(str(tmpdir.join("install")), "resources/systemd", True, False, True) action, _ = install.recover_swap_active() assert action # TODO(cmaloney): expect_fs expect_fs( str(tmpdir.join("install")), { ".gitignore": None, "active": ["mesos"], "active.buildinfo.full.json": None, "active.old": ["mesos"], "bin": ["mesos", "mesos-dir"], "dcos.target.wants": [".gitignore"], "environment": None, "environment.export": None, "environment.old": None, "etc": [".gitignore"], "include": [".gitignore"], "lib": ["libmesos.so"] })
def test_single_source_with_extra(tmpdir): package("resources/single_source_extra", "single_source_extra", tmpdir) # remove the built package tarball because that has a variable filename cache_dir = tmpdir.join("cache/packages/single_source_extra/") packages = [str(x) for x in cache_dir.visit(fil="single_source_extra*.tar.xz")] assert len(packages) == 1, "should have built exactly one package: {}".format(packages) os.remove(packages[0]) expect_fs(str(cache_dir), { "latest": None, "single_source_extra": ["foo"]})
def test_add(tmpdir): assert run([ "pkgpanda", "add", resources_test_dir('remote_repo/packages/mesos/mesos--0.22.0.tar.xz'), "--repository={0}".format(tmpdir), ]) == "" # Ensure that the package at least somewhat extracted correctly. expect_fs("{0}".format(tmpdir), { "mesos--0.22.0": ["lib", "bin_master", "bin_slave", "pkginfo.json", "bin"] })
def test_add(tmpdir): assert run([ "pkgpanda", "add", "{0}/../tests/resources/remote_repo/packages/mesos/mesos--0.22.0.tar.xz".format(os.getcwd()), "--repository={0}".format(tmpdir), ]) == "" # Ensure that the package at least somewhat extracted correctly. expect_fs( "{0}".format(tmpdir), { "mesos--0.22.0": ["lib", "bin_master", "bin_slave", "pkginfo.json", "bin"] })
def test_fetch(tmpdir): # NOTE: tmpdir is explicitly empty because we want to be sure a fetch. # succeeds when there isn't anything yet. # Start a simpleHTTPServer to serve the packages # fetch a couple packages assert run([ "pkgpanda", "fetch", "mesos--0.22.0", "--repository={0}".format(tmpdir), "--repository-url=file://{}/".format(resources_test_dir('remote_repo')) ]) == fetch_output # Ensure that the package at least somewhat extracted correctly. expect_fs("{0}".format(tmpdir), { "mesos--0.22.0": ["lib", "bin_master", "bin_slave", "pkginfo.json", "bin"] })
def test_fetch(tmpdir): # NOTE: tmpdir is explicitly empty because we want to be sure a fetch. # succeeds when there isn't anything yet. # Start a simpleHTTPServer to serve the packages # fetch a couple packages assert run([ "pkgpanda", "fetch", "mesos--0.22.0", "--repository={0}".format(tmpdir), "--repository-url=file://{0}/../tests/resources/remote_repo/".format(os.getcwd()) ]) == fetch_output # Ensure that the package at least somewhat extracted correctly. expect_fs( "{0}".format(tmpdir), { "mesos--0.22.0": ["lib", "bin_master", "bin_slave", "pkginfo.json", "bin"] })
def test_recovery_move_new(tmpdir): # From the "move_new" state correctly. shutil.copytree("resources/install_recovery_move", str(tmpdir.join("install")), symlinks=True) install = Install(str(tmpdir.join("install")), "resources/systemd", True, False, True) action, _ = install.recover_swap_active() assert action # TODO(cmaloney): expect_fs expect_fs( str(tmpdir.join("install")), { ".gitignore": None, "active": ["mesos"], "active.buildinfo.full.json": None, "bin": ["mesos", "mesos-dir"], "dcos.target.wants": [".gitignore"], "environment": None, "environment.export": None, "etc": [".gitignore"], "include": [".gitignore"], "lib": ["libmesos.so"] })
def test_single_source_with_extra(tmpdir): package("resources/single_source_extra", "single_source_extra", tmpdir) expect_fs(str(tmpdir.join("single_source_extra/cache")), ["latest", "foo"])
def test_setup(tmpdir): repo_path = tmp_repository(tmpdir) tmpdir.join("root", "bootstrap").write("", ensure=True) check_call([ "pkgpanda", "setup", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=../resources/etc-active", "--no-systemd" ]) expect_fs("{0}".format(tmpdir), ["repository", "root"]) # TODO(cmaloney): Validate things got placed correctly. expect_fs( "{0}/root".format(tmpdir), { "active": ["env", "mesos", "mesos-config"], "active.buildinfo.full.json": None, "bin": ["mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib": ["libmesos.so"], "etc": ["dcos-service-configuration.json", "foobar", "some.json"], "include": [], "dcos.target.wants": ["dcos-mesos-master.service"], "dcos.target": None, "environment": None, "environment.export": None, "dcos-mesos-master.service": None # rooted_systemd }) expected_dcos_service_configuration = { "sysctl": { "dcos-mesos-master": { "kernel.watchdog_thresh": "11", "net.netfilter.nf_conntrack_udp_timeout": "30" }, "dcos-mesos-slave": { "kperf.debug_level": "1" } } } assert expected_dcos_service_configuration == load_json( "{tmpdir}/root/etc/dcos-service-configuration.json".format( tmpdir=tmpdir)) # Introspection should work right active = set( check_output([ "pkgpanda", "active", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=../resources/etc-active" ]).decode("utf-8").split()) assert active == { "env--setup", "mesos--0.22.0", "mesos-config--ffddcfb53168d42f92e4771c6f8a8a9a818fd6b8" } tmpdir.join("root", "bootstrap").write("", ensure=True) # If we setup the same directory again we should get .old files. check_call([ "pkgpanda", "setup", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=../resources/etc-active", "--no-systemd" ]) # TODO(cmaloney): Validate things got placed correctly. expect_fs( "{0}/root".format(tmpdir), { "active": ["env", "mesos", "mesos-config"], "active.buildinfo.full.json.old": None, "active.buildinfo.full.json": None, "bin": ["mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib": ["libmesos.so"], "etc": ["dcos-service-configuration.json", "foobar", "some.json"], "include": [], "dcos.target": None, "dcos.target.wants": ["dcos-mesos-master.service"], "environment": None, "environment.export": None, "active.old": ["env", "mesos", "mesos-config"], "bin.old": ["mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib.old": ["libmesos.so"], "etc.old": ["dcos-service-configuration.json", "foobar", "some.json"], "include.old": [], "dcos.target.wants.old": ["dcos-mesos-master.service"], "environment.old": None, "environment.export.old": None, "dcos-mesos-master.service": None # rooted systemd }) # Should only pickup the packages once / one active set. active = set( check_output([ "pkgpanda", "active", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=../resources/etc-active" ]).decode('utf-8').split()) assert active == { "env--setup", "mesos--0.22.0", "mesos-config--ffddcfb53168d42f92e4771c6f8a8a9a818fd6b8" } # Touch some .new files so we can be sure that deactivate cleans those up as well. tmpdir.mkdir("root/bin.new") tmpdir.mkdir("root/lib.new") tmpdir.mkdir("root/etc.new") tmpdir.mkdir("root/foo.new") tmpdir.mkdir("root/baz") tmpdir.mkdir("root/foobar.old") tmpdir.mkdir("root/packages") # Uninstall / deactivate everything, check_call([ "pkgpanda", "uninstall", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=../resources/etc-active", "--no-systemd" ]) expect_fs("{0}".format(tmpdir), {"repository": None})
def test_setup(tmpdir): repo_path = tmp_repository(tmpdir) tmpdir.join("root", "bootstrap").write("", ensure=True) check_call(["pkgpanda", "setup", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir={}".format(resources_test_dir("etc-active")), "--no-systemd" ]) expect_fs("{0}".format(tmpdir), ["repository", "root"]) # TODO(cmaloney): Validate things got placed correctly. expect_fs( "{0}/root".format(tmpdir), { "active": ["dcos-provider-abcdef-test", "mesos", "mesos-config"], "active.buildinfo.full.json": None, "bin": [ "mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib": ["libmesos.so"], "etc": ["dcos-service-configuration.json", "foobar", "some.json"], "include": [], "dcos.target.wants": ["dcos-mesos-master.service"], "dcos.target": None, "environment": None, "environment.export": None, "dcos-mesos-master.service": None # rooted_systemd }) expected_dcos_service_configuration = { "sysctl": { "dcos-mesos-master": { "kernel.watchdog_thresh": "11", "net.netfilter.nf_conntrack_udp_timeout": "30" }, "dcos-mesos-slave": { "kperf.debug_level": "1" } } } assert expected_dcos_service_configuration == load_json( "{tmpdir}/root/etc/dcos-service-configuration.json".format(tmpdir=tmpdir)) assert load_json('{0}/root/etc/some.json'.format(tmpdir)) == { 'cluster-specific-stuff': 'magic', 'foo': 'bar', 'baz': 'qux', } # Introspection should work right active = set(check_output([ "pkgpanda", "active", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir={}".format(resources_test_dir("etc-active"))]).decode().split()) assert active == { "dcos-provider-abcdef-test--setup", "mesos--0.22.0", "mesos-config--ffddcfb53168d42f92e4771c6f8a8a9a818fd6b8", } tmpdir.join("root", "bootstrap").write("", ensure=True) # If we setup the same directory again we should get .old files. check_call(["pkgpanda", "setup", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir={}".format(resources_test_dir("etc-active")), "--no-systemd" ]) # TODO(cmaloney): Validate things got placed correctly. expect_fs( "{0}/root".format(tmpdir), { "active": ["dcos-provider-abcdef-test", "mesos", "mesos-config"], "active.buildinfo.full.json.old": None, "active.buildinfo.full.json": None, "bin": [ "mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib": ["libmesos.so"], "etc": ["dcos-service-configuration.json", "foobar", "some.json"], "include": [], "dcos.target": None, "dcos.target.wants": ["dcos-mesos-master.service"], "environment": None, "environment.export": None, "active.old": ["dcos-provider-abcdef-test", "mesos", "mesos-config"], "bin.old": [ "mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib.old": ["libmesos.so"], "etc.old": ["dcos-service-configuration.json", "foobar", "some.json"], "include.old": [], "dcos.target.wants.old": ["dcos-mesos-master.service"], "environment.old": None, "environment.export.old": None, "dcos-mesos-master.service": None # rooted systemd }) # Should only pickup the packages once / one active set. active = set(check_output([ "pkgpanda", "active", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir={}".format(resources_test_dir("etc-active"))]).decode().split()) assert active == { "dcos-provider-abcdef-test--setup", "mesos--0.22.0", "mesos-config--ffddcfb53168d42f92e4771c6f8a8a9a818fd6b8", } # Touch some .new files so we can be sure that deactivate cleans those up as well. tmpdir.mkdir("root/bin.new") tmpdir.mkdir("root/lib.new") tmpdir.mkdir("root/etc.new") tmpdir.mkdir("root/foo.new") tmpdir.mkdir("root/baz") tmpdir.mkdir("root/foobar.old") tmpdir.mkdir("root/packages") # Uninstall / deactivate everything, check_call(["pkgpanda", "uninstall", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir={}".format(resources_test_dir("etc-active")), "--no-systemd" ]) expect_fs("{0}".format(tmpdir), {"repository": None})
def test_setup(tmpdir): repo_path = tmp_repository(tmpdir) tmpdir.join("root", "bootstrap").write("", ensure=True) check_call(["pkgpanda", "setup", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=resources/etc-active", "--no-systemd" ]) # TODO(cmaloney): Validate things got placed correctly. expect_fs( "{0}/root".format(tmpdir), { "active": ["env", "mesos", "mesos-config"], "active.buildinfo.full.json": None, "bin": [ "mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib": ["libmesos.so"], "etc": ["foobar", "some.json"], "include": [], "dcos.target.wants": [], "dcos.target": None, "environment": None, "environment.export": None }) # Introspection should work right active = set(check_output([ "pkgpanda", "active", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=resources/etc-active" ]).decode("utf-8").split()) assert active == {"env--setup", "mesos--0.22.0", "mesos-config--ffddcfb53168d42f92e4771c6f8a8a9a818fd6b8"} tmpdir.join("root", "bootstrap").write("", ensure=True) # If we setup the same directory again we should get .old files. check_call(["pkgpanda", "setup", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=resources/etc-active", "--no-systemd" ]) # TODO(cmaloney): Validate things got placed correctly. expect_fs( "{0}/root".format(tmpdir), { "active": ["env", "mesos", "mesos-config"], "active.buildinfo.full.json.old": None, "active.buildinfo.full.json": None, "bin": [ "mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib": ["libmesos.so"], "etc": ["foobar", "some.json"], "include": [], "dcos.target": None, "dcos.target.wants": [], "environment": None, "environment.export": None, "active.old": ["env", "mesos", "mesos-config"], "bin.old": [ "mesos", "mesos-dir", "mesos-master", "mesos-slave"], "lib.old": ["libmesos.so"], "etc.old": ["foobar", "some.json"], "include.old": [], "dcos.target.wants.old": [], "environment.old": None, "environment.export.old": None }) # Should only pickup the packages once / one active set. active = set(check_output([ "pkgpanda", "active", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=resources/etc-active" ]).decode('utf-8').split()) assert active == {"env--setup", "mesos--0.22.0", "mesos-config--ffddcfb53168d42f92e4771c6f8a8a9a818fd6b8"} # Touch some .new files so we can be sure that deactivate cleans those up as well. tmpdir.mkdir("root/bin.new") tmpdir.mkdir("root/lib.new") tmpdir.mkdir("root/etc.new") tmpdir.mkdir("root/foo.new") tmpdir.mkdir("root/baz") tmpdir.mkdir("root/foobar.old") tmpdir.mkdir("root/packages") # Uninstall / deactivate everything, check_call(["pkgpanda", "uninstall", "--root={0}/root".format(tmpdir), "--rooted-systemd", "--repository={}".format(repo_path), "--config-dir=resources/etc-active", "--no-systemd" ]) expect_fs("{0}".format(tmpdir), {"repository": None})