-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathverify.py
More file actions
90 lines (72 loc) · 3.05 KB
/
verify.py
File metadata and controls
90 lines (72 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
"""Verify the backend lab environment.
Verify that the `env_lab.py` and `env_user.py` Python environment files exist
and that they import successfully, and then verify that the backend lab
environments are accessible and responding to API calls.
Copyright (c) 2018 Cisco and/or its affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from importlib.util import module_from_spec, spec_from_file_location
from glob import glob
import os
import sys
# Get the absolute path for the directory where this file is located "here"
here = os.path.abspath(os.path.dirname(__file__))
# Get the absolute path for the project / repository root
project_root = os.path.abspath(os.path.join(here, ".."))
# Extend the system path to include the project root
if project_root not in sys.path:
sys.path.insert(0, project_root)
# Verify env_lab.py
try:
print("==> Importing env_lab")
import env_lab # noqa
except Exception as e:
print("FAILED: Error importing env_lab.py; error details:\n{}\n".format(e))
sys.exit(1)
# Verify env_user.py
try:
print("==> Importing env_user")
import env_user # noqa
except ModuleNotFoundError:
print(
"\nFAILED: Error importing env_user.py; file not found. Did you "
"create one? Copy and edit env_lab.template in the repository root.\n"
)
sys.exit(1)
except Exception as e:
print(
"\nFAILED: Error importing `env_user.py`. Error Details:\n"
"{}\n".format(e)
)
sys.exit(1)
# Verify backend lab environments
backend = os.path.abspath(os.path.join(here, "backend"))
verified = []
for python_file in glob(os.path.join(backend, "*.py")):
name = os.path.splitext(os.path.basename(python_file))[0]
spec = spec_from_file_location(name, python_file)
module = module_from_spec(spec)
spec.loader.exec_module(module)
verified.append(module.verify())
if all(verified):
print("\nAll lab backend systems are responding. You're good to go!")
else:
print(
"\nSome of the backend systems didn't respond or reported errors; "
"please check the above output for details."
)