koan 3.2.2__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. {koan-3.2.2 → koan-3.3.0}/.github/workflows/testing.yml +7 -2
  2. {koan-3.2.2 → koan-3.3.0}/PKG-INFO +1 -2
  3. koan-3.3.0/koan/_version.py +5 -0
  4. {koan-3.2.2 → koan-3.3.0}/koan/app.py +1 -1
  5. koan-3.3.0/koan/virt/openvz.py +605 -0
  6. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/PKG-INFO +1 -2
  7. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/SOURCES.txt +10 -2
  8. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/requires.txt +0 -1
  9. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/scm_file_list.json +10 -2
  10. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/scm_version.json +2 -2
  11. {koan-3.2.2 → koan-3.3.0}/koan.spec +0 -4
  12. {koan-3.2.2 → koan-3.3.0}/setup.cfg +0 -1
  13. koan-3.3.0/tests/test_app.py +1748 -0
  14. koan-3.3.0/tests/test_cexceptions.py +51 -0
  15. koan-3.3.0/tests/test_cli.py +257 -0
  16. koan-3.3.0/tests/test_configurator.py +444 -0
  17. koan-3.3.0/tests/test_register.py +240 -0
  18. koan-3.3.0/tests/test_utils.py +869 -0
  19. koan-3.3.0/tests/test_virt_image.py +47 -0
  20. koan-3.3.0/tests/test_virt_openvz.py +599 -0
  21. koan-3.3.0/tests/test_virt_qemu.py +143 -0
  22. koan-3.3.0/tests/test_virt_vmw.py +207 -0
  23. koan-3.3.0/tests/test_virt_xen.py +47 -0
  24. koan-3.2.2/tests/virtinstall.py → koan-3.3.0/tests/test_virtinstall.py +68 -34
  25. koan-3.2.2/bin/ovz-install +0 -192
  26. koan-3.2.2/koan/_version.py +0 -5
  27. koan-3.2.2/koan/virt/openvz.py +0 -140
  28. koan-3.2.2/tests/test_app.py +0 -26
  29. koan-3.2.2/tests/test_utils.py +0 -95
  30. {koan-3.2.2 → koan-3.3.0}/.dockerignore +0 -0
  31. {koan-3.2.2 → koan-3.3.0}/.github/FUNDING.yml +0 -0
  32. {koan-3.2.2 → koan-3.3.0}/.github/ISSUE_TEMPLATE/01_bug_report.md +0 -0
  33. {koan-3.2.2 → koan-3.3.0}/.github/ISSUE_TEMPLATE/02_feature_request.md +0 -0
  34. {koan-3.2.2 → koan-3.3.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  35. {koan-3.2.2 → koan-3.3.0}/.github/dependabot.yml +0 -0
  36. {koan-3.2.2 → koan-3.3.0}/.github/pull_request_template.md +0 -0
  37. {koan-3.2.2 → koan-3.3.0}/.github/workflows/codeql-analysis.yml +0 -0
  38. {koan-3.2.2 → koan-3.3.0}/.github/workflows/lint.yml +0 -0
  39. {koan-3.2.2 → koan-3.3.0}/.github/workflows/packaging.yml +0 -0
  40. {koan-3.2.2 → koan-3.3.0}/.github/workflows/pypi.yml +0 -0
  41. {koan-3.2.2 → koan-3.3.0}/.github/workflows/release.yml +0 -0
  42. {koan-3.2.2 → koan-3.3.0}/.gitignore +0 -0
  43. {koan-3.2.2 → koan-3.3.0}/.pre-commit-config.yaml +0 -0
  44. {koan-3.2.2 → koan-3.3.0}/.readthedocs.yml +0 -0
  45. {koan-3.2.2 → koan-3.3.0}/.releaserc.json +0 -0
  46. {koan-3.2.2 → koan-3.3.0}/AGENTS.md +0 -0
  47. {koan-3.2.2 → koan-3.3.0}/AUTHORS.in +0 -0
  48. {koan-3.2.2 → koan-3.3.0}/CLAUDE.md +0 -0
  49. {koan-3.2.2 → koan-3.3.0}/CONTRIBUTING.md +0 -0
  50. {koan-3.2.2 → koan-3.3.0}/COPYING +0 -0
  51. {koan-3.2.2 → koan-3.3.0}/MANIFEST.in +0 -0
  52. {koan-3.2.2 → koan-3.3.0}/Makefile +0 -0
  53. {koan-3.2.2 → koan-3.3.0}/README.md +0 -0
  54. {koan-3.2.2 → koan-3.3.0}/commitlint.config.js +0 -0
  55. {koan-3.2.2 → koan-3.3.0}/debian/changelog +0 -0
  56. {koan-3.2.2 → koan-3.3.0}/debian/compat +0 -0
  57. {koan-3.2.2 → koan-3.3.0}/debian/control +0 -0
  58. {koan-3.2.2 → koan-3.3.0}/debian/copyright +0 -0
  59. {koan-3.2.2 → koan-3.3.0}/debian/koan.docs +0 -0
  60. {koan-3.2.2 → koan-3.3.0}/debian/rules +0 -0
  61. {koan-3.2.2 → koan-3.3.0}/debian/source/format +0 -0
  62. {koan-3.2.2 → koan-3.3.0}/docker/debs/build-and-install-debs.sh +0 -0
  63. {koan-3.2.2 → koan-3.3.0}/docker/debs/debian/Debian13.dockerfile +0 -0
  64. {koan-3.2.2 → koan-3.3.0}/docker/debs/install-debs.sh +0 -0
  65. {koan-3.2.2 → koan-3.3.0}/docker/rpms/Fedora/Fedora.dockerfile +0 -0
  66. {koan-3.2.2 → koan-3.3.0}/docker/rpms/RockyLinux10/RockyLinux10.dockerfile +0 -0
  67. {koan-3.2.2 → koan-3.3.0}/docker/rpms/build-and-install-rpms.sh +0 -0
  68. {koan-3.2.2 → koan-3.3.0}/docker/rpms/install-rpms.sh +0 -0
  69. {koan-3.2.2 → koan-3.3.0}/docker/rpms/openSUSE_Leap/openSUSE_Leap.dockerfile +0 -0
  70. {koan-3.2.2 → koan-3.3.0}/docker/rpms/openSUSE_Tumbleweed/openSUSE_TW.dockerfile +0 -0
  71. {koan-3.2.2 → koan-3.3.0}/docs/Makefile +0 -0
  72. {koan-3.2.2 → koan-3.3.0}/docs/cobbler-register.rst +0 -0
  73. {koan-3.2.2 → koan-3.3.0}/docs/conf.py +0 -0
  74. {koan-3.2.2 → koan-3.3.0}/docs/index.rst +0 -0
  75. {koan-3.2.2 → koan-3.3.0}/docs/installing-virtual-guests.rst +0 -0
  76. {koan-3.2.2 → koan-3.3.0}/docs/koan-on-openvz.rst +0 -0
  77. {koan-3.2.2 → koan-3.3.0}/docs/koan-with-isos.rst +0 -0
  78. {koan-3.2.2 → koan-3.3.0}/docs/koan.rst +0 -0
  79. {koan-3.2.2 → koan-3.3.0}/docs/reinstallation.rst +0 -0
  80. {koan-3.2.2 → koan-3.3.0}/docs/release-notes.rst +0 -0
  81. {koan-3.2.2 → koan-3.3.0}/docs/virtual-networking-setup.rst +0 -0
  82. {koan-3.2.2 → koan-3.3.0}/docs/vmware.rst +0 -0
  83. {koan-3.2.2 → koan-3.3.0}/koan/__init__.py +0 -0
  84. {koan-3.2.2 → koan-3.3.0}/koan/cexceptions.py +0 -0
  85. {koan-3.2.2 → koan-3.3.0}/koan/cli.py +0 -0
  86. {koan-3.2.2 → koan-3.3.0}/koan/configurator.py +0 -0
  87. {koan-3.2.2 → koan-3.3.0}/koan/register.py +0 -0
  88. {koan-3.2.2 → koan-3.3.0}/koan/utils.py +0 -0
  89. {koan-3.2.2 → koan-3.3.0}/koan/virt/__init__.py +0 -0
  90. {koan-3.2.2 → koan-3.3.0}/koan/virt/image.py +0 -0
  91. {koan-3.2.2 → koan-3.3.0}/koan/virt/qemu.py +0 -0
  92. {koan-3.2.2 → koan-3.3.0}/koan/virt/vmw.py +0 -0
  93. {koan-3.2.2 → koan-3.3.0}/koan/virt/xen.py +0 -0
  94. {koan-3.2.2 → koan-3.3.0}/koan/virtinstall.py +0 -0
  95. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/dependency_links.txt +0 -0
  96. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/entry_points.txt +0 -0
  97. {koan-3.2.2 → koan-3.3.0}/koan.egg-info/top_level.txt +0 -0
  98. {koan-3.2.2 → koan-3.3.0}/package-lock.json +0 -0
  99. {koan-3.2.2 → koan-3.3.0}/package.json +0 -0
  100. {koan-3.2.2 → koan-3.3.0}/pyproject.toml +0 -0
  101. {koan-3.2.2 → koan-3.3.0}/setup.py +0 -0
  102. {koan-3.2.2 → koan-3.3.0}/tests/__init__.py +0 -0
  103. {koan-3.2.2 → koan-3.3.0}/tests/conftest.py +0 -0
@@ -16,7 +16,7 @@ jobs:
16
16
  # git must be present before checkout, or the container image has none and actions/checkout silently falls back to
17
17
  # downloading a tarball via the GitHub REST API, which has no .git dir for setuptools_scm to read.
18
18
  - name: Install package deps
19
- run: zypper -n in --no-recommends git tar python3 python3-devel python3-wheel python3-pip python3-libvirt-python gcc make
19
+ run: zypper -n in --no-recommends git tar curl python3 python3-devel python3-wheel python3-pip python3-libvirt-python gcc make virt-install
20
20
  - name: Checkout repository
21
21
  # setuptools_scm needs full history (incl. tags) to derive the version
22
22
  # https://github.com/actions/checkout
@@ -26,4 +26,9 @@ jobs:
26
26
  - name: Install dependencies
27
27
  run: pip3 install --break-system-packages .[lint,test]
28
28
  - name: Run tests
29
- run: pytest --cov=./koan
29
+ run: pytest --cov=./koan --cov-report=term-missing --cov-report=xml:coverage.xml
30
+ - name: Upload coverage to Codacy
31
+ uses: codacy/codacy-coverage-reporter-action@89d6c85cfafaec52c72b6c5e8b2878d33104c699 # v1.3.0
32
+ with:
33
+ project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
34
+ coverage-reports: coverage.xml
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koan
3
- Version: 3.2.2
3
+ Version: 3.3.0
4
4
  Summary: Kickstart over a Network Client for Cobbler
5
5
  Home-page: https://www.github.com/cobbler/koan
6
6
  Author: Team Cobbler
@@ -19,7 +19,6 @@ Requires-Dist: black; extra == "lint"
19
19
  Requires-Dist: isort; extra == "lint"
20
20
  Provides-Extra: test
21
21
  Requires-Dist: pytest; extra == "test"
22
- Requires-Dist: nose; extra == "test"
23
22
  Requires-Dist: pytest-cov; extra == "test"
24
23
  Requires-Dist: pytest-mock; extra == "test"
25
24
  Provides-Extra: docs
@@ -0,0 +1,5 @@
1
+ # Auto-generated by setuptools_scm — do not edit
2
+ __version__ = "3.3.0"
3
+ __gitstamp__ = "g606484c3774dba749523dcf555778f1347393241"
4
+ __gitdate__ = "2026-07-21"
5
+ __builddate__ = "2026-12-01 09:38:47.292556+00:00"
@@ -650,7 +650,7 @@ class Koan:
650
650
  )
651
651
  if not os.path.exists(os.path.dirname(save_as)):
652
652
  os.makedirs(os.path.dirname(save_as))
653
- cmd = ["/usr/bin/curl", url, "--output ", save_as]
653
+ cmd = ["/usr/bin/curl", url, "--output", save_as]
654
654
  utils.subprocess_call(cmd)
655
655
 
656
656
  return True
@@ -0,0 +1,605 @@
1
+ """
2
+ OpenVZ container-type virtualization installation functions.
3
+ """
4
+
5
+ # SPDX-License-Identifier: GPL-2.0-or-later
6
+ # SPDX-FileCopyrightText: Copyright 2012 Artem Kanarev <kanarev AT tncc.ru>, Sergey Podushkin <psv AT tncc.ru>
7
+
8
+ import glob
9
+ import os
10
+ import re
11
+ import shutil
12
+
13
+ from koan import utils
14
+ from koan.cexceptions import OVZCreateException
15
+
16
+
17
+ def _extract_rootpw(kickstart_text):
18
+ """
19
+ Extract the root password hash/value from a "rootpw ..." kickstart line.
20
+ """
21
+ for line in kickstart_text.splitlines():
22
+ if line.startswith("rootpw"):
23
+ fields = line.split()
24
+ if len(fields) > 1:
25
+ return fields[-1]
26
+ return None
27
+
28
+
29
+ def _extract_post_install_interpreter(kickstart_text):
30
+ """
31
+ Extract the interpreter from "%post --interpreter <shell>", defaulting to /bin/sh.
32
+ """
33
+ for line in kickstart_text.splitlines():
34
+ if line.startswith("%post"):
35
+ match = re.search(r"--interpreter\s+(\S+)", line)
36
+ if match:
37
+ return match.group(1)
38
+ break
39
+ return "/bin/sh"
40
+
41
+
42
+ def _extract_post_install_script(kickstart_text):
43
+ """
44
+ Return everything after the first "%post" line, as the post-install script body.
45
+ """
46
+ lines = kickstart_text.splitlines()
47
+ for index, line in enumerate(lines):
48
+ if "%post" in line:
49
+ return "\n".join(lines[index + 1 :])
50
+ return ""
51
+
52
+
53
+ def _extract_services(kickstart_text):
54
+ """
55
+ Extract enabled/disabled service lists from a "services --enabled=... --disabled=..." line.
56
+ """
57
+ enabled = []
58
+ disabled = []
59
+ for line in kickstart_text.splitlines():
60
+ if not line.startswith("services"):
61
+ continue
62
+ enabled_match = re.search(r"--enabled[= ](\S+)", line)
63
+ if enabled_match:
64
+ enabled = enabled_match.group(1).split(",")
65
+ disabled_match = re.search(r"--disabled[= ](\S+)", line)
66
+ if disabled_match:
67
+ disabled = disabled_match.group(1).split(",")
68
+ break
69
+ return enabled, disabled
70
+
71
+
72
+ def _extract_base_repo_url(kickstart_text):
73
+ """
74
+ Extract the base install tree URL from a "url --url=..." line.
75
+ """
76
+ for line in kickstart_text.splitlines():
77
+ if line.startswith("url"):
78
+ match = re.search(r"--url[= ](\S+)", line)
79
+ if match:
80
+ return match.group(1)
81
+ return None
82
+
83
+
84
+ def _extract_ignoremissing(kickstart_text):
85
+ return "--ignoremissing" in kickstart_text
86
+
87
+
88
+ def _extract_nobase(kickstart_text):
89
+ return "--nobase" in kickstart_text
90
+
91
+
92
+ def _extract_repos(kickstart_text):
93
+ """
94
+ Extract additional yum repos from "repo --name=... --baseurl=..." lines.
95
+
96
+ Returns a list of (tag, name_directive, rest_directive) tuples, where
97
+ name_directive/rest_directive are the raw "key=value" tokens intended to be
98
+ written verbatim into a yum repo config file.
99
+ """
100
+ repos = []
101
+ for line in kickstart_text.splitlines():
102
+ tokens = line.split()
103
+ if not tokens or tokens[0] != "repo":
104
+ continue
105
+ directive_tokens = [token.replace("--", "") for token in tokens[1:]]
106
+ if not directive_tokens:
107
+ continue
108
+ name_directive = directive_tokens[0]
109
+ rest_directive = " ".join(directive_tokens[1:])
110
+ tag = name_directive.split("=", 1)[-1]
111
+ repos.append((tag, name_directive, rest_directive))
112
+ return repos
113
+
114
+
115
+ def _extract_packages(kickstart_text):
116
+ """
117
+ Extract package/group install-or-remove entries from the "%packages" section.
118
+
119
+ Returns a list of (action, is_group, name) tuples where action is
120
+ "install" or "remove".
121
+ """
122
+ lines = kickstart_text.splitlines()
123
+ start_index = None
124
+ for index, line in enumerate(lines):
125
+ if line.strip().startswith("%packages"):
126
+ start_index = index + 1
127
+ break
128
+ if start_index is None:
129
+ return []
130
+
131
+ end_index = len(lines)
132
+ for index in range(start_index, len(lines)):
133
+ if lines[index].strip().startswith("%post"):
134
+ end_index = index
135
+ break
136
+
137
+ packages = []
138
+ for line in lines[start_index:end_index]:
139
+ stripped = line.strip()
140
+ if not stripped or stripped.startswith("#") or stripped.startswith("%"):
141
+ continue
142
+ action = "install"
143
+ if stripped.startswith("-"):
144
+ action = "remove"
145
+ stripped = stripped[1:]
146
+ is_group = False
147
+ if stripped.startswith("@"):
148
+ is_group = True
149
+ stripped = stripped[1:]
150
+ packages.append((action, is_group, stripped))
151
+ return packages
152
+
153
+
154
+ # packages we don't need to install (but included in installed groups)
155
+ _EXCLUDED_PACKAGES = "selinux-policy-targeted kernel* *firmware* b43*"
156
+
157
+ # packages we want installed, besides of those listed in the kickstart
158
+ _EXTRA_PACKAGES = "vim-minimal ssh-clients openssh-server logrotate"
159
+
160
+
161
+ def _build_yum_config(base_repo_url, ignore_missing, repos):
162
+ """
163
+ Build the contents of a temporary yum config restricted to the base install
164
+ tree repo plus any additional repos declared in the kickstart file.
165
+ """
166
+ lines = [
167
+ "[main]",
168
+ r"cachedir=/var/cache/yum/$basearch/$releasever",
169
+ "keepcache=0",
170
+ "debuglevel=2",
171
+ "logfile=/var/log/yum.log",
172
+ "exactarch=1",
173
+ "obsoletes=1",
174
+ "gpgcheck=0",
175
+ "plugins=1",
176
+ "distroverpkg=centos-release",
177
+ "reposdir=/dev/null",
178
+ "groupremove_leaf_only=1",
179
+ "group_package_types=mandatory",
180
+ "tsflags=nodocs",
181
+ ]
182
+ if ignore_missing:
183
+ lines.append("skip_broken=1")
184
+
185
+ lines.extend(
186
+ [
187
+ "",
188
+ "[base-os]",
189
+ "name=base-os",
190
+ "baseurl=%s" % base_repo_url,
191
+ "enabled=1",
192
+ "priority=1",
193
+ "gpgcheck=0",
194
+ ]
195
+ )
196
+
197
+ for tag, name_directive, rest_directive in repos:
198
+ lines.extend(
199
+ [
200
+ "",
201
+ "[%s]" % tag,
202
+ name_directive,
203
+ rest_directive,
204
+ "enabled=1",
205
+ "priority=99",
206
+ "gpgcheck=0",
207
+ ]
208
+ )
209
+
210
+ return "\n".join(lines) + "\n"
211
+
212
+
213
+ def _build_yum_script(packages, nobase):
214
+ """
215
+ Build a "yum shell" script installing/removing the given packages/groups.
216
+ """
217
+ lines = [
218
+ "config assumeyes True",
219
+ "config gpgcheck False",
220
+ "install %s" % _EXTRA_PACKAGES,
221
+ 'config exclude "%s"' % _EXCLUDED_PACKAGES,
222
+ ]
223
+ for action, is_group, name in packages:
224
+ prefix = ("group" if is_group else "") + action
225
+ lines.append('%s "%s"' % (prefix, name))
226
+ if nobase:
227
+ lines.append("groupremove base")
228
+ lines.append("run")
229
+ return "\n".join(lines) + "\n"
230
+
231
+
232
+ def _run_yum_install(rootdir, yum_config_path, yum_script_path):
233
+ """
234
+ Install the container's package set via "yum shell", then remove the
235
+ kernel-related packages that don't belong inside an OpenVZ container.
236
+ """
237
+ print("Start installing packages")
238
+ utils.subprocess_call(
239
+ [
240
+ "yum",
241
+ "shell",
242
+ "--quiet",
243
+ "--config=%s" % yum_config_path,
244
+ "--installroot=%s" % rootdir,
245
+ yum_script_path,
246
+ ],
247
+ ignore_rc=True,
248
+ )
249
+ utils.subprocess_call(
250
+ [
251
+ "yum",
252
+ "remove",
253
+ "kernel",
254
+ "kernel-firmware",
255
+ "dracut",
256
+ "dracut-kernel",
257
+ "dracut-network",
258
+ "fcoe-utils",
259
+ "libdrm",
260
+ "lldpad",
261
+ "plymouth",
262
+ "-y",
263
+ "--quiet",
264
+ "--config=%s" % yum_config_path,
265
+ "--installroot=%s" % rootdir,
266
+ ],
267
+ ignore_rc=True,
268
+ )
269
+ print("Packages installed")
270
+
271
+
272
+ def _move_script_into_chroot(rootdir, script_path, content):
273
+ """
274
+ Write `content` to `script_path` and move it under `rootdir`, so it's
275
+ reachable at the same path once chrooted into `rootdir`.
276
+ """
277
+ with open(script_path, "w") as fh:
278
+ fh.write(content)
279
+ shutil.move(script_path, os.path.join(rootdir, script_path.lstrip("/")))
280
+
281
+
282
+ def _apply_services_script(rootdir, sysname, enabled, disabled):
283
+ """
284
+ Generate a chkconfig on/off script from the kickstart's services directive
285
+ and run it inside the container via chroot.
286
+ """
287
+ print("Disabling and enabling services as needed")
288
+ script_path = "/tmp/%s-services.sh" % sysname
289
+ lines = ["chkconfig --level 345 %s off" % service for service in disabled]
290
+ lines += ["chkconfig --level 345 %s on" % service for service in enabled]
291
+ content = "\n".join(lines) + ("\n" if lines else "")
292
+ _move_script_into_chroot(rootdir, script_path, content)
293
+ utils.subprocess_call(["chroot", rootdir, "/bin/bash", script_path], ignore_rc=True)
294
+
295
+
296
+ def _apply_post_install_script(rootdir, sysname, interpreter, script_body):
297
+ """
298
+ Write out the kickstart's %post script and run it inside the container
299
+ via chroot, using the interpreter declared in the kickstart file.
300
+ """
301
+ print("Perform post-installation actions")
302
+ script_path = "/tmp/%s-post-install" % sysname
303
+ _move_script_into_chroot(rootdir, script_path, script_body)
304
+ utils.subprocess_call(["chroot", rootdir, interpreter, script_path], ignore_rc=True)
305
+
306
+
307
+ _STALE_UPSTART_CONFIGS = [
308
+ "etc/init/control-alt-delete.conf",
309
+ "etc/init/plymouth-shutdown.conf",
310
+ "etc/init/prefdm.conf",
311
+ "etc/init/quit-plymouth.conf",
312
+ "etc/init/rcS-sulogin.conf",
313
+ "etc/init/serial.conf",
314
+ "etc/init/start-ttys.conf",
315
+ "etc/init/tty.conf",
316
+ ]
317
+
318
+ # BSD-style pty/tty device names, e.g. ptya0, ptyp0, ttya0, ttyp0, ...
319
+ _PTY_DEVICE_NAMES = [
320
+ "%sty%s%s" % (first, second, suffix)
321
+ for first in "pt"
322
+ for second in "ap"
323
+ for suffix in "0123456789abcdef"
324
+ ]
325
+
326
+ _STATIC_DEVICE_NAMES = [
327
+ "console",
328
+ "core",
329
+ "full",
330
+ "kmem",
331
+ "kmsg",
332
+ "mem",
333
+ "null",
334
+ "port",
335
+ "ptmx",
336
+ "random",
337
+ "urandom",
338
+ "zero",
339
+ "ram0",
340
+ ]
341
+
342
+ _STDIO_SYMLINKS = [
343
+ ("fd", "/proc/self/fd"),
344
+ ("stderr", "/proc/self/fd/2"),
345
+ ("stdin", "/proc/self/fd/0"),
346
+ ("stdout", "/proc/self/fd/1"),
347
+ ]
348
+
349
+
350
+ def _comment_out_console_lines(path):
351
+ if not os.path.exists(path):
352
+ return
353
+ with open(path) as fh:
354
+ content = fh.read()
355
+ content = re.sub(r"^console", "#console", content, flags=re.MULTILINE)
356
+ with open(path, "w") as fh:
357
+ fh.write(content)
358
+
359
+
360
+ def _disable_gssapi_authentication(path):
361
+ if not os.path.exists(path):
362
+ return
363
+ with open(path) as fh:
364
+ content = fh.read()
365
+ content = content.replace("GSSAPIAuthentication yes", "GSSAPIAuthentication no")
366
+ with open(path, "w") as fh:
367
+ fh.write(content)
368
+
369
+
370
+ def _set_root_password_hash(path, rootpw):
371
+ if not rootpw or not os.path.exists(path):
372
+ return
373
+ with open(path) as fh:
374
+ content = fh.read()
375
+ content = re.sub(r"root:.:", "root:%s:" % rootpw, content, count=1)
376
+ with open(path, "w") as fh:
377
+ fh.write(content)
378
+
379
+
380
+ def _replace_symlink(link_path, target):
381
+ if os.path.lexists(link_path):
382
+ os.remove(link_path)
383
+ os.symlink(target, link_path)
384
+
385
+
386
+ def _recreate_device_nodes(device_dir):
387
+ utils.subprocess_call(
388
+ ["/sbin/MAKEDEV", "-d", device_dir, "-x"]
389
+ + _PTY_DEVICE_NAMES
390
+ + _STATIC_DEVICE_NAMES,
391
+ ignore_rc=True,
392
+ )
393
+ for name, target in _STDIO_SYMLINKS:
394
+ _replace_symlink(os.path.join(device_dir, name), target)
395
+
396
+
397
+ def _tune_container_tree(rootdir, rootpw):
398
+ """
399
+ Adjust a freshly-installed root filesystem to be suitable for running as
400
+ an OpenVZ container (as opposed to a standalone/physical install).
401
+ """
402
+ print("Make the tree container-ready")
403
+
404
+ for relative_path in _STALE_UPSTART_CONFIGS:
405
+ path = os.path.join(rootdir, relative_path)
406
+ if os.path.exists(path):
407
+ os.remove(path)
408
+
409
+ _comment_out_console_lines(os.path.join(rootdir, "etc/init/rc.conf"))
410
+ _comment_out_console_lines(os.path.join(rootdir, "etc/init/rcS.conf"))
411
+
412
+ _disable_gssapi_authentication(os.path.join(rootdir, "etc/ssh/sshd_config"))
413
+
414
+ selinux_dir = os.path.join(rootdir, "etc/selinux")
415
+ os.makedirs(selinux_dir, exist_ok=True)
416
+ with open(os.path.join(selinux_dir, "config"), "w") as fh:
417
+ fh.write("SELINUX=disabled\n")
418
+
419
+ _set_root_password_hash(os.path.join(rootdir, "etc/shadow"), rootpw)
420
+
421
+ _replace_symlink(os.path.join(rootdir, "etc/mtab"), "/proc/mounts")
422
+
423
+ with open(os.path.join(rootdir, "etc/fstab"), "w") as fh:
424
+ fh.write("none /dev/pts devpts rw,gid=5,mode=620 0 0\n")
425
+
426
+ dev_null_path = os.path.join(rootdir, "dev/null")
427
+ if os.path.exists(dev_null_path):
428
+ os.remove(dev_null_path)
429
+
430
+ _recreate_device_nodes(os.path.join(rootdir, "dev"))
431
+ _recreate_device_nodes(os.path.join(rootdir, "etc/udev/devices"))
432
+
433
+ os.chmod(os.path.join(rootdir, "tmp"), 0o1777)
434
+ os.chmod(os.path.join(rootdir, "var/tmp"), 0o1777)
435
+
436
+
437
+ def _install_container_tree(sysname, kickstart_url, rootdir):
438
+ """
439
+ Populate an OpenVZ container's root filesystem from a kickstart file:
440
+ install packages via yum, enable/disable services, run the post-install
441
+ script, and tune the resulting tree to run as a container.
442
+ """
443
+ kickstart_text = utils.urlread(kickstart_url)
444
+ if isinstance(kickstart_text, bytes):
445
+ kickstart_text = kickstart_text.decode()
446
+
447
+ rootpw = _extract_rootpw(kickstart_text)
448
+ interpreter = _extract_post_install_interpreter(kickstart_text)
449
+ post_install_script = _extract_post_install_script(kickstart_text)
450
+ enabled, disabled = _extract_services(kickstart_text)
451
+ base_repo_url = _extract_base_repo_url(kickstart_text)
452
+ ignore_missing = _extract_ignoremissing(kickstart_text)
453
+ repos = _extract_repos(kickstart_text)
454
+ nobase = _extract_nobase(kickstart_text)
455
+ packages = _extract_packages(kickstart_text)
456
+
457
+ yum_config_path = "/tmp/%s-yum.cfg" % sysname
458
+ yum_script_path = "/tmp/%s-yum.yum" % sysname
459
+ with open(yum_config_path, "w") as fh:
460
+ fh.write(_build_yum_config(base_repo_url, ignore_missing, repos))
461
+ with open(yum_script_path, "w") as fh:
462
+ fh.write(_build_yum_script(packages, nobase))
463
+
464
+ _run_yum_install(rootdir, yum_config_path, yum_script_path)
465
+
466
+ for repo_file in glob.glob(os.path.join(rootdir, "etc/yum.repos.d/*.repo")):
467
+ os.remove(repo_file)
468
+
469
+ _apply_services_script(rootdir, sysname, enabled, disabled)
470
+ _apply_post_install_script(rootdir, sysname, interpreter, post_install_script)
471
+ _tune_container_tree(rootdir, rootpw)
472
+
473
+ print("All done")
474
+
475
+
476
+ def start_install(*args, **kwargs):
477
+ # check for Openvz tools presence
478
+ # can be this apps installed in some other place?
479
+ vzcfgvalidate = "/usr/sbin/vzcfgvalidate"
480
+ vzctl = "/usr/sbin/vzctl"
481
+ if not os.path.exists(vzcfgvalidate) or not os.path.exists(vzctl):
482
+ raise OVZCreateException(
483
+ "Cannot find %s and/or %s! Are OpenVZ tools installed?"
484
+ % (vzcfgvalidate, vzctl)
485
+ )
486
+
487
+ # params, that can be defined/redefined through autoinstall_meta
488
+ keys_for_meta = [
489
+ "KMEMSIZE", # "14372700:14790164",
490
+ "LOCKEDPAGES", # "2048:2048",
491
+ "PRIVVMPAGES", # "65536:69632",
492
+ "SHMPAGES", # "21504:21504",
493
+ "NUMPROC", # "240:240",
494
+ "VMGUARPAGES", # "33792:unlimited",
495
+ "OOMGUARPAGES", # "26112:unlimited",
496
+ "NUMTCPSOCK", # "360:360",
497
+ "NUMFLOCK", # "188:206",
498
+ "NUMPTY", # "16:16",
499
+ "NUMSIGINFO", # "256:256",
500
+ "TCPSNDBUF", # "1720320:2703360",
501
+ "TCPRCVBUF", # "1720320:2703360",
502
+ "OTHERSOCKBUF", # "1126080:2097152",
503
+ "DGRAMRCVBUF", # "262144:262144",
504
+ "NUMOTHERSOCK", # "120",
505
+ "DCACHESIZE", # "3409920:3624960",
506
+ "NUMFILE", # "9312:9312",
507
+ "AVNUMPROC", # "180:180",
508
+ "NUMIPTENT", # "128:128",
509
+ "DISKINODES", # "200000:220000",
510
+ "QUOTATIME", # "0",
511
+ "VE_ROOT", # "/vz/root/$VEID",
512
+ "VE_PRIVATE", # "/vz/private/$VEID",
513
+ "SWAPPAGES", # "0:1G",
514
+ "ONBOOT", # "yes"
515
+ ]
516
+
517
+ sysname = kwargs["name"]
518
+ autoinst = kwargs["profile_data"]["autoinst"]
519
+ # we use it for --ostemplate parameter
520
+ template = kwargs["profile_data"]["breed"]
521
+ hostname = kwargs["profile_data"]["hostname"]
522
+ ipadd = kwargs["profile_data"]["ip_address_eth0"]
523
+ nameserver = kwargs["profile_data"]["name_servers"][0]
524
+ diskspace = kwargs["profile_data"]["virt_file_size"]
525
+ physpages = kwargs["profile_data"]["virt_ram"]
526
+ cpus = kwargs["profile_data"]["virt_cpus"]
527
+ onboot = kwargs["profile_data"]["virt_auto_boot"]
528
+
529
+ # we get [0,1] ot [False,True] and have to map it to [no,yes]
530
+ onboot = "yes" if onboot == "1" or onboot else "no"
531
+ CTID = None
532
+ vz_meta = {}
533
+
534
+ # get all vz_ parameters from autoinstall_meta
535
+ for key, value in kwargs["profile_data"]["autoinstall_meta"]:
536
+ if key.startswith("vz_"):
537
+ vz_meta[key.replace("vz_", "").upper()] = value
538
+
539
+ if "CTID" in vz_meta and vz_meta["CTID"]:
540
+ try:
541
+ CTID = int(vz_meta["CTID"])
542
+ del vz_meta["CTID"]
543
+ except ValueError:
544
+ print("Invalid CTID in autoinstall_meta. Exiting...")
545
+ return 1
546
+ else:
547
+ raise OVZCreateException(
548
+ 'Mandatory "vz_ctid" parameter not found in autoinstall_meta!'
549
+ )
550
+
551
+ confiname = "/etc/vz/conf/%d.conf" % CTID
552
+
553
+ # this is the minimal config. we can define additional parameters or
554
+ # override some of them in autoinstall_meta
555
+ min_config = {
556
+ "PHYSPAGES": "0:%sM" % physpages,
557
+ "SWAPPAGES": "0:1G",
558
+ "DISKSPACE": "%sG:%sG" % (diskspace, diskspace),
559
+ "DISKINODES": "200000:220000",
560
+ "QUOTATIME": "0",
561
+ "CPUUNITS": "1000",
562
+ "CPUS": cpus,
563
+ "VE_ROOT": "/vz/root/$VEID",
564
+ "VE_PRIVATE": "/vz/private/$VEID",
565
+ "OSTEMPLATE": template,
566
+ "NAME": sysname,
567
+ "HOSTNAME": hostname,
568
+ "IP_ADDRESS": ipadd,
569
+ "NAMESERVER": nameserver,
570
+ }
571
+
572
+ # merge with override
573
+ full_config = dict(
574
+ [
575
+ (k, vz_meta[k] if k in vz_meta and k in keys_for_meta else min_config[k])
576
+ for k in set(min_config.keys()) | set(vz_meta.keys())
577
+ ]
578
+ )
579
+
580
+ # write config file for container
581
+ f = open(confiname, "w+")
582
+ for key, val in full_config.items():
583
+ f.write('%s="%s"\n' % (key, val))
584
+ f.close()
585
+
586
+ # validate the config file. confiname/CTID are derived from the
587
+ # already-validated integer CTID, not attacker-controlled input, so
588
+ # os.system() here and for the vzctl start below is safe.
589
+ cmd = "%s %s" % (vzcfgvalidate, confiname)
590
+ if not os.system(cmd.strip()):
591
+ # now install the container tree
592
+ try:
593
+ _install_container_tree(
594
+ sysname,
595
+ autoinst,
596
+ full_config["VE_PRIVATE"].replace("$VEID", "%d" % CTID),
597
+ )
598
+ except Exception:
599
+ raise OVZCreateException("Container creation %s failed" % CTID)
600
+ # if everything fine, start the container
601
+ cmd = "%s start %s" % (vzctl, CTID)
602
+ if os.system(cmd.strip()):
603
+ raise OVZCreateException("Start container %s failed" % CTID)
604
+ else:
605
+ raise OVZCreateException("Container %s config file is not valid" % CTID)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koan
3
- Version: 3.2.2
3
+ Version: 3.3.0
4
4
  Summary: Kickstart over a Network Client for Cobbler
5
5
  Home-page: https://www.github.com/cobbler/koan
6
6
  Author: Team Cobbler
@@ -19,7 +19,6 @@ Requires-Dist: black; extra == "lint"
19
19
  Requires-Dist: isort; extra == "lint"
20
20
  Provides-Extra: test
21
21
  Requires-Dist: pytest; extra == "test"
22
- Requires-Dist: nose; extra == "test"
23
22
  Requires-Dist: pytest-cov; extra == "test"
24
23
  Requires-Dist: pytest-mock; extra == "test"
25
24
  Provides-Extra: docs
@@ -30,7 +30,6 @@ setup.py
30
30
  .github/workflows/pypi.yml
31
31
  .github/workflows/release.yml
32
32
  .github/workflows/testing.yml
33
- bin/ovz-install
34
33
  debian/changelog
35
34
  debian/compat
36
35
  debian/control
@@ -85,5 +84,14 @@ koan/virt/xen.py
85
84
  tests/__init__.py
86
85
  tests/conftest.py
87
86
  tests/test_app.py
87
+ tests/test_cexceptions.py
88
+ tests/test_cli.py
89
+ tests/test_configurator.py
90
+ tests/test_register.py
88
91
  tests/test_utils.py
89
- tests/virtinstall.py
92
+ tests/test_virt_image.py
93
+ tests/test_virt_openvz.py
94
+ tests/test_virt_qemu.py
95
+ tests/test_virt_vmw.py
96
+ tests/test_virt_xen.py
97
+ tests/test_virtinstall.py