pytest-pve-cloud 3.2.0__tar.gz → 3.2.1__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 (20) hide show
  1. {pytest_pve_cloud-3.2.0/src/pytest_pve_cloud.egg-info → pytest_pve_cloud-3.2.1}/PKG-INFO +2 -2
  2. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/requirements.txt +1 -1
  3. pytest_pve_cloud-3.2.1/src/pve_cloud_test/_version.py +1 -0
  4. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pve_cloud_test/cloud_fixtures.py +67 -0
  5. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pve_cloud_test/options.py +16 -4
  6. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pve_cloud_test/terraform.py +59 -0
  7. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1/src/pytest_pve_cloud.egg-info}/PKG-INFO +2 -2
  8. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pytest_pve_cloud.egg-info/requires.txt +1 -1
  9. pytest_pve_cloud-3.2.0/src/pve_cloud_test/_version.py +0 -1
  10. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/LICENSE.md +0 -0
  11. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/README.md +0 -0
  12. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/pyproject.toml +0 -0
  13. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/setup.cfg +0 -0
  14. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pve_cloud_test/k8s_fixtures.py +0 -0
  15. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pve_cloud_test/tdd_watchdog.py +0 -0
  16. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pve_cloud_test/test_env_schema.yaml +0 -0
  17. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pytest_pve_cloud.egg-info/SOURCES.txt +0 -0
  18. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pytest_pve_cloud.egg-info/dependency_links.txt +0 -0
  19. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pytest_pve_cloud.egg-info/entry_points.txt +0 -0
  20. {pytest_pve_cloud-3.2.0 → pytest_pve_cloud-3.2.1}/src/pytest_pve_cloud.egg-info/top_level.txt +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-pve-cloud
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Author-email: Tobias Huebner <tobias.huebner@vmzberlin.com>
5
5
  License-Expression: GPL-3.0-or-later
6
6
  License-File: LICENSE.md
7
- Requires-Dist: py-pve-cloud<3.3.0,>=3.2.0
7
+ Requires-Dist: py-pve-cloud<3.3.0,>=3.2.1
8
8
  Requires-Dist: kubernetes==34.1.0
9
9
  Requires-Dist: pytest==8.4.2
10
10
  Requires-Dist: ansible-runner==2.4.2
@@ -1,4 +1,4 @@
1
- py-pve-cloud>=3.2.0,<3.3.0
1
+ py-pve-cloud>=3.2.1,<3.3.0
2
2
  kubernetes==34.1.0
3
3
  pytest==8.4.2
4
4
  ansible-runner==2.4.2
@@ -0,0 +1 @@
1
+ __version__ = "3.2.1"
@@ -3,7 +3,9 @@ import inspect
3
3
  import logging
4
4
  import os
5
5
  import re
6
+ from contextlib import contextmanager
6
7
 
8
+ import ansible_runner
7
9
  import jsonschema
8
10
  import paramiko
9
11
  import pytest
@@ -78,6 +80,13 @@ def cloud_fixture(*tags):
78
80
  yield
79
81
  return
80
82
 
83
+ if request.config.getoption("--fixture-tags") and request.config.getoption(
84
+ "--skip-fixture-tags"
85
+ ):
86
+ raise RuntimeError(
87
+ "Cannot both specify skip fixture tags and include fixture tags!"
88
+ )
89
+
81
90
  # filter out fixtures that are not specifically targeted
82
91
  allowed_tags_opt = request.config.getoption("--fixture-tags")
83
92
  if allowed_tags_opt:
@@ -89,6 +98,16 @@ def cloud_fixture(*tags):
89
98
  yield
90
99
  return
91
100
 
101
+ skip_tags_opt = request.config.getoption("--skip-fixture-tags")
102
+ if skip_tags_opt:
103
+ skip_tags = skip_tags_opt.split(",")
104
+ if any(tag in skip_tags for tag in func._tags):
105
+ logger.info(f"Skipping fixture {func.__name__} due to tags")
106
+
107
+ # mimic fixture returns and pass blanks
108
+ yield
109
+ return
110
+
92
111
  # when fixtures are executed we give the option to skip the cleanup part
93
112
  skip_cleanup = request.config.getoption("--skip-cleanup")
94
113
 
@@ -118,6 +137,54 @@ def cloud_fixture(*tags):
118
137
  return decorator
119
138
 
120
139
 
140
+ @contextmanager
141
+ def run_playbook(
142
+ request, inventory_file, *create_playbooks, destroy_playbook=None, extra_vars=None
143
+ ):
144
+ cmd_line = None
145
+
146
+ if request.config.getoption("--runner-tags") and request.config.getoption(
147
+ "--skip-runner-tags"
148
+ ):
149
+ raise RuntimeError("Cannot specify both include and exclude runner tags!")
150
+
151
+ if request.config.getoption("--runner-tags"):
152
+ cmd_line = f"--tags {request.config.getoption('--runner-tags')}"
153
+
154
+ if request.config.getoption("--skip-runner-tags"):
155
+ cmd_line = f"--skip-tags {request.config.getoption('--skip-runner-tags')}"
156
+
157
+ try:
158
+ for create_playbook in create_playbooks:
159
+ logger.info(f"Running create playbook {create_playbook}")
160
+ create_run = ansible_runner.run(
161
+ project_dir=os.getcwd(),
162
+ playbook=create_playbook,
163
+ inventory=inventory_file,
164
+ verbosity=request.config.getoption("--ansible-verbosity"),
165
+ cmdline=cmd_line,
166
+ extravars=extra_vars,
167
+ )
168
+
169
+ assert create_run.rc == 0, f"Create playbook run failed {create_playbook}"
170
+
171
+ yield
172
+
173
+ finally:
174
+ if not request.config.getoption("--skip-cleanup") and destroy_playbook:
175
+ logger.info(f"Running destroy playbook {destroy_playbook}")
176
+ destroy_run = ansible_runner.run(
177
+ project_dir=os.getcwd(),
178
+ playbook=destroy_playbook,
179
+ inventory=inventory_file,
180
+ verbosity=request.config.getoption("--ansible-verbosity"),
181
+ cmdline=cmd_line,
182
+ extravars=extra_vars,
183
+ )
184
+
185
+ assert destroy_run.rc == 0, f"Create playbook run failed {destroy_playbook}"
186
+
187
+
121
188
  # load the test environment yaml from parameters
122
189
  @pytest.fixture(scope="session")
123
190
  def get_test_env(request):
@@ -23,9 +23,21 @@ def pytest_addoption(parser):
23
23
  help="Runs only fixtures with the specified tags (comma seperated list). Works for fixtures annotated with special cloud_fixture from cloud_fixtures.py",
24
24
  )
25
25
  parser.addoption(
26
- "--skip-kubespray",
27
- action="store_true",
28
- default=False,
29
- help="Skips the kubespray playbook part when syncing test kubespray clusters. This saves a lot of time in total.",
26
+ "--skip-fixture-tags",
27
+ type=str,
28
+ default=None,
29
+ help="Runs only fixtures with the specified tags (comma seperated list). Works for fixtures annotated with special cloud_fixture from cloud_fixtures.py",
30
+ )
31
+ parser.addoption(
32
+ "--runner-tags",
33
+ type=str,
34
+ default=None,
35
+ help="Runs only fixtures with the specified tags (comma seperated list). Works for fixtures annotated with special cloud_fixture from cloud_fixtures.py",
36
+ )
37
+ parser.addoption(
38
+ "--skip-runner-tags",
39
+ type=str,
40
+ default=None,
41
+ help="Runs only fixtures with the specified tags (comma seperated list). Works for fixtures annotated with special cloud_fixture from cloud_fixtures.py",
30
42
  )
31
43
  parser.addoption("--ansible-verbosity", type=int, choices=[1, 2, 3], default=0)
@@ -5,13 +5,19 @@ import os
5
5
  import shutil
6
6
  import subprocess
7
7
  from contextlib import contextmanager
8
+ from pathlib import Path
8
9
 
9
10
  import netifaces
10
11
  import paramiko
11
12
  import yaml
12
13
  from jinja2 import Environment, FileSystemLoader
13
14
  from pve_cloud.lib.inventory import get_pve_inventory
15
+ from pve_cloud.orm.alchemy import AcmeX509, ProxmoxCloudSecrets
14
16
  from pytest_httpserver import HTTPServer
17
+ from sqlalchemy import create_engine, delete, select
18
+ from sqlalchemy.orm import Session
19
+
20
+ from pve_cloud_test.cloud_fixtures import *
15
21
 
16
22
  logger = logging.getLogger(__name__)
17
23
 
@@ -78,6 +84,59 @@ def get_tf_env_vars(
78
84
  # write testing kubespray inv and set the path (for provider init)
79
85
  tf_env_vars["TF_VAR_e2e_kubespray_inv"] = get_kubespray_inv
80
86
 
87
+ # if the harbor_copy_mirror_host is defined in the kubernetes section, we set is as an env variable
88
+ # to use in the pxc_helm_mirror terraform resource
89
+ if "harbor_copy_mirror_host" in get_test_env["kubernetes"]:
90
+ tf_env_vars["E2E_HARBOR_MIRROR_HOST"] = get_test_env["kubernetes"][
91
+ "harbor_copy_mirror_host"
92
+ ]
93
+
94
+ # look for mirror vm presence and rsync terraform provider cache
95
+ engine = create_engine(pg_conn_str_orm)
96
+
97
+ with Session(engine) as session:
98
+ stmt = select(ProxmoxCloudSecrets).where(
99
+ ProxmoxCloudSecrets.cloud_domain
100
+ == get_test_env["cloud_inventory"]["pve_cloud_domain"],
101
+ ProxmoxCloudSecrets.secret_name == "cloud-mirror-vm",
102
+ )
103
+ cloud_mirror_vm = session.scalars(stmt).first()
104
+
105
+ logger.info(
106
+ f"found cloud mirror vm {cloud_mirror_vm.secret_data['mirror_vm_addr']}"
107
+ )
108
+ if cloud_mirror_vm:
109
+ # create local cache idr
110
+ local_cache_dir = f"{os.getenv('HOME')}/.terraform.d/plugin-cache/"
111
+
112
+ if Path(local_cache_dir).exists():
113
+ # rsync local to upstream
114
+ upsync_cmd = [
115
+ "rsync",
116
+ "-avz",
117
+ local_cache_dir,
118
+ f"admin@{cloud_mirror_vm.secret_data['mirror_vm_addr']}:/home/admin/.cache/terraform-plugins/",
119
+ ]
120
+ logger.info(upsync_cmd)
121
+ subprocess.run(upsync_cmd, check=True, text=True)
122
+
123
+ Path(local_cache_dir).mkdir(parents=True, exist_ok=True)
124
+
125
+ # rsync download
126
+ subprocess.run(
127
+ [
128
+ "rsync",
129
+ "-avz",
130
+ f"admin@{cloud_mirror_vm.secret_data['mirror_vm_addr']}:/home/admin/.cache/terraform-plugins/",
131
+ local_cache_dir,
132
+ ],
133
+ check=True,
134
+ text=True,
135
+ )
136
+
137
+ # set the cache dir for terraform subprocess launches
138
+ tf_env_vars["TF_PLUGIN_CACHE_DIR"] = local_cache_dir
139
+
81
140
  return tf_env_vars
82
141
 
83
142
 
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-pve-cloud
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Author-email: Tobias Huebner <tobias.huebner@vmzberlin.com>
5
5
  License-Expression: GPL-3.0-or-later
6
6
  License-File: LICENSE.md
7
- Requires-Dist: py-pve-cloud<3.3.0,>=3.2.0
7
+ Requires-Dist: py-pve-cloud<3.3.0,>=3.2.1
8
8
  Requires-Dist: kubernetes==34.1.0
9
9
  Requires-Dist: pytest==8.4.2
10
10
  Requires-Dist: ansible-runner==2.4.2
@@ -1,4 +1,4 @@
1
- py-pve-cloud<3.3.0,>=3.2.0
1
+ py-pve-cloud<3.3.0,>=3.2.1
2
2
  kubernetes==34.1.0
3
3
  pytest==8.4.2
4
4
  ansible-runner==2.4.2
@@ -1 +0,0 @@
1
- __version__ = "3.2.0"