async def test_version_argument(modules_repo): make_module_simple(modules_repo, "mod-version", [], "1.2") module_path = os.path.join(modules_repo, "mod-version") mod = module.ModuleV1(None, module_path) assert mod.version == version.Version("1.2") args = [ sys.executable, "-m", "inmanta.app", "module", "commit", "-m", "msg", "-v", "1.3.1", "-r" ] process = await asyncio.subprocess.create_subprocess_exec( *args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=module_path) try: await asyncio.wait_for(process.communicate(), timeout=30) except asyncio.TimeoutError as e: process.kill() await process.communicate() raise e # Make sure exitcode is zero assert process.returncode == 0 # Verify changes assert mod._get_metadata_from_disk().version == "1.3.1"
def modules_repo(git_modules_dir) -> str: """ +--------+-------------+----------+ | Name | Requires | Versions | +--------+-------------+----------+ | std | | 0.0.1 | +--------+-------------+----------+ | | | 3.2 | +--------+-------------+----------+ | mod1 | mod3 ~= 0.1 | 0.0.1 | +--------+-------------+----------+ | | mod3 ~= 0.1 | 3.2 | +--------+-------------+----------+ | mod2 | | 0.0.1 | +--------+-------------+----------+ | | | 2016.1 | +--------+-------------+----------+ | mod3 | | 0.0.1 | +--------+-------------+----------+ | | | 0.1 | +--------+-------------+----------+ | badmod | mod2 < 2016 | 0.0.1 | +--------+-------------+----------+ | | | 0.1 | +--------+-------------+----------+ | mod5 | | 0.0.1 | +--------+-------------+----------+ | | | 0.1 | +--------+-------------+----------+ | mod6 | | 0.0.1 | +--------+-------------+----------+ | | | 3.2 | +--------+-------------+----------+ | mod7 | | 0.0.1 | +--------+-------------+----------+ | | | 3.2 | +--------+-------------+----------+ | | | 3.2.1 | +--------+-------------+----------+ | | | 3.2.2 | +--------+-------------+----------+ | | | 4.0 | +--------+-------------+----------+ | | | 4.2 | +--------+-------------+----------+ | | | 4.3 | +--------+-------------+----------+ | mod8 | | 0.0.1 | +--------+-------------+----------+ | | | 3.2 | +--------+-------------+----------+ | | | 3.3.dev | +--------+-------------+----------+""" tempdir = git_modules_dir reporoot = os.path.join(tempdir, "repos") os.makedirs(reporoot) make_module_simple(reporoot, "std") make_module_simple(reporoot, "mod1", depends=[("mod3", "~=0.1")]) make_module_simple(reporoot, "mod2", version="2016.1") mod3 = make_module_simple(reporoot, "mod3", version="0.1") add_file(mod3, "badsignal", "present", "third commit") mod4 = make_module_simple(reporoot, "badmod", [("mod2", "<2016")]) add_file(mod4, "badsignal", "present", "third commit") mod5 = make_module_simple(reporoot, "mod5", version="0.1") add_file(mod5, "badsignal", "present", "third commit") mod6 = make_module_simple(reporoot, "mod6") add_file(mod6, "badsignal", "present", "third commit") mod7 = make_module_simple(reporoot, "mod7") add_file(mod7, "nsignal", "present", "third commit", version="3.2.1") add_file(mod7, "signal", "present", "fourth commit", version="3.2.2") add_file_and_compiler_constraint(mod7, "badsignal", "present", "fifth commit", version="4.0", compiler_version="1000000.4") add_file(mod7, "badsignal", "present", "sixth commit", version="4.1") add_file_and_compiler_constraint(mod7, "badsignal", "present", "fifth commit", version="4.2", compiler_version="1000000.5") add_file(mod7, "badsignal", "present", "sixth commit", version="4.3") mod8 = make_module_simple(reporoot, "mod8", []) add_file(mod8, "devsignal", "present", "third commit", version="3.3.dev2") add_file(mod8, "mastersignal", "present", "last commit") mod11 = make_module_simple(reporoot, "mod11") add_file(mod11, "file", "test", "release version 3.2.1", version="3.2.1") add_file(mod11, "file", "test", "release version 4.0.0", version="4.0.0") add_file(mod11, "file", "test", "release version 4.1.0", version="4.1.0") add_file(mod11, "file", "test", "release version 4.1.2", version="4.1.2") add_file(mod11, "file", "test", "release version 4.2.0", version="4.2.0") proj = makemodule(reporoot, "testproject", [("mod1", None), ("mod2", ">2016"), ("mod5", None)], True, ["mod1", "mod2", "mod6", "mod7"]) # results in loading of 1,2,3,6 commitmodule(proj, "first commit") badproject = makemodule(reporoot, "badproject", [("mod15", None)], True) commitmodule(badproject, "first commit") baddep = makemodule(reporoot, "baddep", [("badmod", None), ("mod2", ">2016")], True) commitmodule(baddep, "first commit") devproject = makeproject(reporoot, "devproject", imports=["mod8"], install_mode=InstallMode.prerelease) commitmodule(devproject, "first commit") masterproject = makeproject(reporoot, "masterproject", imports=["mod8"], install_mode=InstallMode.master) commitmodule(masterproject, "first commit") masterproject_multi_mod = makeproject(reporoot, "masterproject_multi_mod", imports=["mod2", "mod8"], install_mode=InstallMode.master) commitmodule(masterproject_multi_mod, "first commit") nover = makemodule(reporoot, "nover", []) commitmodule(nover, "first commit") add_file(nover, "signal", "present", "second commit") noverproject = makeproject(reporoot, "noverproject", imports=["nover"]) commitmodule(noverproject, "first commit") """ for freeze, test from C A-> B,C,D C-> E,F,E::a C::a -> I E::a -> J E-> H D-> F,G """ make_module_simple_deps(reporoot, "A", ["B", "C", "D"], project=True) make_module_simple_deps(reporoot, "B") c = make_module_simple_deps(reporoot, "C", ["E", "F", "E::a"], version="3.0") add_file(c, "model/a.cf", "import modI", "add mod C::a", "3.2") make_module_simple_deps(reporoot, "D", ["F", "G"]) e = make_module_simple_deps(reporoot, "E", ["H"], version="3.0") add_file(e, "model/a.cf", "import modJ", "add mod E::a", "3.2") make_module_simple_deps(reporoot, "F") make_module_simple_deps(reporoot, "G") make_module_simple_deps(reporoot, "H") make_module_simple_deps(reporoot, "I") make_module_simple_deps(reporoot, "J") return reporoot
def module_without_tags(modules_repo): mod_no_tag = make_module_simple(modules_repo, "mod-no-tag") yield mod_no_tag shutil.rmtree(mod_no_tag)
def test_module_corruption(modules_dir, modules_repo): mod9 = make_module_simple(modules_repo, "mod9", [("mod10", None)]) add_file(mod9, "signal", "present", "third commit", version="3.3") add_file(mod9, "model/b.cf", "import mod9", "fourth commit", version="4.0") mod10 = make_module_simple(modules_repo, "mod10", []) add_file(mod10, "signal", "present", "a commit", version="3.3") # syntax error add_file(mod10, "model/_init.cf", "SomeInvalidThings", "a commit", version="3.5") # fix it add_file(mod10, "model/_init.cf", "", "a commit", version="3.6") add_file(mod10, "secondsignal", "import mod9", "b commit", version="4.0") add_file(mod10, "badsignal", "import mod9", "c commit", version="5.0") p9 = makeproject(modules_repo, "proj9", [("mod9", "==3.3"), ("mod10", "==3.3")], ["mod9"]) commitmodule(p9, "first commit") # setup project proj = install_project(modules_dir, "proj9") app(["modules", "install"]) print(os.listdir(proj)) # unfreeze deps to allow update projectyml = os.path.join(proj, "project.yml") assert os.path.exists(projectyml) with open(projectyml, "r", encoding="utf-8") as fh: pyml = yaml.load(fh) pyml["requires"] = ["mod10 == 3.5"] with open(projectyml, "w", encoding="utf-8") as fh: yaml.dump(pyml, fh) # clear cache Project._project = None # attempt to update, mod10 is wrong, but only after the update app(["modules", "update"]) with pytest.raises(ParserException): # clear cache Project._project = None # attempt to update, mod10 is wrong, can not be fixed app(["modules", "update"]) # unfreeze deps to allow update pyml["requires"] = ["mod10 == 4.0"] with open(projectyml, "w", encoding="utf-8") as fh: yaml.dump(pyml, fh) # overwrite main to import unknown sub module main = os.path.join(proj, "main.cf") assert os.path.exists(main) with open(main, "w", encoding="utf-8") as fh: fh.write("import mod9::b") # clear cache Project._project = None # attempt to update app(["modules", "update"]) # Additional output Project._project = None app(["modules", "list"]) # Verify m9dir = os.path.join(proj, "libs", "mod9") assert os.path.exists(os.path.join(m9dir, "model", "b.cf")) m10dir = os.path.join(proj, "libs", "mod10") assert os.path.exists(os.path.join(m10dir, "secondsignal")) # should not be lastest version assert not os.path.exists(os.path.join(m10dir, "badsignal"))