Skip to content

Commit d6653b0

Browse files
authored
Merge branch 'master' into pants-pack-globs
2 parents 85a8219 + 6adb0f5 commit d6653b0

File tree

20 files changed

+949
-1
lines changed

20 files changed

+949
-1
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ jobs:
3939
python-version-short: '3.8'
4040
python-version: '3.8.10'
4141

42+
services:
43+
mongo:
44+
image: mongo:4.4
45+
ports:
46+
- 27017:27017
47+
4248
env:
4349
COLUMNS: '120'
4450

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Added
1414
working on StackStorm, improve our security posture, and improve CI reliability thanks in part
1515
to pants' use of PEX lockfiles. This is not a user-facing addition.
1616
#5778 #5789 #5817 #5795 #5830 #5833 #5834 #5841 #5840 #5838 #5842 #5837 #5849 #5850
17-
#5846 #5853 #5848 #5847 #5858 #5857 #5860 #5868 #5871 #5874
17+
#5846 #5853 #5848 #5847 #5858 #5857 #5860 #5868 #5871 #5874 #5864
1818
Contributed by @cognifloyd
1919

2020
* Added a joint index to solve the problem of slow mongo queries for scheduled executions. #5805

pants-plugins/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ The plugins here add custom goals or other logic into pants.
88

99
To see available goals, do "./pants help goals" and "./pants help $goal".
1010

11+
These plugins might be useful outside of the StackStorm project:
12+
- `uses_services`
13+
1114
These StackStorm-specific plugins might be useful in other StackStorm-related repos.
1215
- `pack_metadata`
1316

@@ -66,3 +69,13 @@ the `fmt` goal (eg `./pants fmt contrib/schemas::`), the schemas will
6669
be regenerated if any of the files used to generate them have changed.
6770
Also, running the `lint` goal will fail if the schemas need to be
6871
regenerated.
72+
73+
### `uses_seevices` plugin
74+
75+
This plugin validates that services are running if required. For example, some tests
76+
need mongo, so this plugin can ensure mongo is running. If it is not running, then
77+
an error with instructions on how to run it are given to the user.
78+
79+
`uses_services` has some StackStorm-specific assumptions in it, but it might be
80+
generalizable. There are several other StackStorm-specific plugins, but some of
81+
them are only useful in the st2 repo.

pants-plugins/uses_services/BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
python_sources(
2+
sources=["*.py", "!*_test.py", "!data_fixtures.py"],
3+
)
4+
5+
python_test_utils(
6+
name="test_utils",
7+
sources=["data_fixtures.py"],
8+
)
9+
10+
python_tests(
11+
name="tests",
12+
# Do not enable `uses` for these tests.
13+
# These tests still need the running services, but if the plugin
14+
# is somehow broken, then any failures would prevent these tests
15+
# from running to tell us what is wrong.
16+
# overrides={
17+
# "mongo_rules_test.py": {"uses": ["mongo"]},
18+
# },
19+
)

pants-plugins/uses_services/__init__.py

Whitespace-only changes.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Copyright 2023 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from __future__ import annotations
15+
16+
from .platform_rules import Platform
17+
18+
19+
def platform(
20+
arch="",
21+
os="",
22+
distro="",
23+
distro_name="",
24+
distro_codename="",
25+
distro_like="",
26+
distro_major_version="",
27+
distro_version="",
28+
mac_release="",
29+
win_release="",
30+
) -> Platform:
31+
"""Create a Platform with all values defaulted to the empty string."""
32+
return Platform(
33+
arch=arch,
34+
os=os,
35+
distro=distro,
36+
distro_name=distro_name,
37+
distro_codename=distro_codename,
38+
distro_like=distro_like,
39+
distro_major_version=distro_major_version,
40+
distro_version=distro_version,
41+
mac_release=mac_release,
42+
win_release=win_release,
43+
)
44+
45+
46+
platform_samples = (
47+
platform(), # empty
48+
# EL distros ##################
49+
platform(
50+
arch="x86_64",
51+
os="Linux",
52+
distro="centos",
53+
distro_name="Centos Linux",
54+
distro_codename="Core",
55+
distro_like="rhel fedora",
56+
distro_major_version="7",
57+
distro_version="7",
58+
),
59+
platform(
60+
arch="x86_64",
61+
os="Linux",
62+
distro="rocky",
63+
distro_name="Rocky Linux",
64+
distro_codename="Green Obsidian",
65+
distro_like="rhel centos fedora",
66+
distro_major_version="8",
67+
distro_version="8.7",
68+
),
69+
# debian distros ##############
70+
platform(
71+
arch="x86_64",
72+
os="Linux",
73+
distro="ubuntu",
74+
distro_name="Ubuntu",
75+
distro_codename="xenial",
76+
distro_like="debian",
77+
distro_major_version="16",
78+
distro_version="16.04",
79+
),
80+
platform(
81+
arch="x86_64",
82+
os="Linux",
83+
distro="ubuntu",
84+
distro_name="Ubuntu",
85+
distro_codename="bionic",
86+
distro_like="debian",
87+
distro_major_version="18",
88+
distro_version="18.04",
89+
),
90+
platform(
91+
arch="x86_64",
92+
os="Linux",
93+
distro="ubuntu",
94+
distro_name="Ubuntu",
95+
distro_codename="focal",
96+
distro_like="debian",
97+
distro_major_version="20",
98+
distro_version="20.04",
99+
),
100+
# other Linux distros #########
101+
platform(
102+
arch="x86_64",
103+
os="Linux",
104+
distro="gentoo",
105+
distro_name="Gentoo",
106+
distro_codename="n/a",
107+
distro_major_version="2",
108+
distro_version="2.7",
109+
),
110+
platform(
111+
arch="aarch64",
112+
os="Linux",
113+
# no distro in termux on android
114+
),
115+
# platform(
116+
# arch="x86_64",
117+
# os="Linux",
118+
# distro="",
119+
# distro_name="",
120+
# distro_codename="",
121+
# distro_like="",
122+
# distro_major_version="",
123+
# distro_version="",
124+
# ),
125+
# Mac OS X ####################
126+
platform(
127+
arch="x86_64",
128+
os="Darwin",
129+
distro="darwin",
130+
distro_name="Darwin",
131+
distro_major_version="19",
132+
distro_version="19.6.0",
133+
mac_release="10.15.7",
134+
),
135+
platform(
136+
arch="x86_64",
137+
os="Darwin",
138+
distro="darwin",
139+
distro_name="Darwin",
140+
distro_major_version="21",
141+
distro_version="21.6.0",
142+
mac_release="12.6.2",
143+
),
144+
)
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Copyright 2023 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from __future__ import annotations
15+
16+
from dataclasses import dataclass
17+
from textwrap import dedent
18+
19+
from uses_services.platform_rules import Platform
20+
21+
22+
@dataclass(frozen=True)
23+
class ServiceSpecificMessages:
24+
service: str
25+
26+
service_start_cmd_el_7: str
27+
service_start_cmd_el: str
28+
not_installed_clause_el: str
29+
install_instructions_el: str
30+
31+
service_start_cmd_deb: str
32+
not_installed_clause_deb: str
33+
install_instructions_deb: str
34+
35+
service_start_cmd_generic: str
36+
37+
38+
class ServiceMissingError(Exception):
39+
"""Error raised when a test uses a service but that service is missing."""
40+
41+
def __init__(
42+
self, service: str, platform: Platform, instructions: str = "", msg=None
43+
):
44+
if msg is None:
45+
msg = f"The {service} service does not seem to be running or is not accessible!"
46+
if instructions:
47+
msg += f"\n{instructions}"
48+
super().__init__(msg)
49+
self.service = service
50+
self.platform = platform
51+
self.instructions = instructions
52+
53+
@classmethod
54+
def generate(
55+
cls, platform: Platform, messages: ServiceSpecificMessages
56+
) -> ServiceMissingError:
57+
service = messages.service
58+
59+
supported = False
60+
if platform.distro in ["centos", "rhel"] or "rhel" in platform.distro_like:
61+
supported = True
62+
if platform.distro_major_version == "7":
63+
service_start_cmd = messages.service_start_cmd_el_7
64+
else:
65+
service_start_cmd = messages.service_start_cmd_el
66+
not_installed_clause = messages.not_installed_clause_el
67+
install_instructions = messages.install_instructions_el
68+
69+
elif (
70+
platform.distro in ["ubuntu", "debian"] or "debian" in platform.distro_like
71+
):
72+
supported = True
73+
service_start_cmd = messages.service_start_cmd_deb
74+
not_installed_clause = messages.not_installed_clause_deb
75+
install_instructions = messages.install_instructions_deb
76+
77+
if supported:
78+
instructions = dedent(
79+
f"""\
80+
If {service} is installed, but not running try:
81+
82+
{service_start_cmd}
83+
84+
If {service} is not installed, {not_installed_clause}:
85+
86+
"""
87+
).format(
88+
service=service,
89+
service_start_cmd=service_start_cmd,
90+
not_installed_clause=not_installed_clause,
91+
)
92+
instructions += install_instructions
93+
elif platform.os == "Linux":
94+
instructions = dedent(
95+
f"""\
96+
You are on Linux using {platform.distro_name}, which is not
97+
one of our generally supported distributions. We recommend
98+
you use vagrant for local development with something like:
99+
100+
vagrant init stackstorm/st2
101+
vagrant up
102+
vagrant ssh
103+
104+
Please see: https://docs.stackstorm.com/install/vagrant.html
105+
106+
For anyone who wants to attempt local development without vagrant,
107+
you are pretty much on your own. At a minimum you need to install
108+
and start {service} with something like:
109+
110+
{messages.service_start_cmd_generic}
111+
112+
We would be interested to hear about alternative distros people
113+
are using for development. If you are able, please let us know
114+
on slack which distro you are using:
115+
116+
Arch: {platform.arch}
117+
Distro: {platform.distro}
118+
Distro Name: {platform.distro_name}
119+
Distro Codename: {platform.distro_codename}
120+
Distro Family: {platform.distro_like}
121+
Distro Major Version: {platform.distro_major_version}
122+
Distro Version: {platform.distro_version}
123+
124+
Thanks and Good Luck!
125+
"""
126+
)
127+
elif platform.os == "Darwin": # MacOS
128+
instructions = dedent(
129+
f"""\
130+
You are on Mac OS. Generally we recommend using vagrant for local
131+
development on Mac OS with something like:
132+
133+
vagrant init stackstorm/st2
134+
vagrant up
135+
vagrant ssh
136+
137+
Please see: https://docs.stackstorm.com/install/vagrant.html
138+
139+
For anyone who wants to attempt local development without vagrant,
140+
you may run into some speed bumps. Other StackStorm developers have
141+
been known to use Mac OS for development, so feel free to ask for
142+
help in slack. At a minimum you need to install and start {service}.
143+
"""
144+
)
145+
else:
146+
instructions = dedent(
147+
f"""\
148+
You are not on Linux. In this case we recommend using vagrant
149+
for local development with something like:
150+
151+
vagrant init stackstorm/st2
152+
vagrant up
153+
vagrant ssh
154+
155+
Please see: https://docs.stackstorm.com/install/vagrant.html
156+
157+
For anyone who wants to attempt local development without vagrant,
158+
you are pretty much on your own. At a minimum you need to install
159+
and start {service}. Good luck!
160+
"""
161+
)
162+
163+
return cls(
164+
service=service,
165+
platform=platform,
166+
instructions=instructions,
167+
)

0 commit comments

Comments
 (0)