Skip to content

Commit 7d28d9a

Browse files
committed
Port to Python 3
1 parent 6cf5144 commit 7d28d9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1355
-3290
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ sudo apt install python3-amqp python3-cassandra apport-retrace ubuntu-dbgsym-key
88
```
99

1010

11+
## Running the tests locally
12+
13+
Start by having a local Cassandra:
14+
```
15+
docker run --name cassandra --network host --rm -d docker.io/cassandra
16+
```
17+
Then run the tests with `pytest`:
18+
```
19+
cd src
20+
pytest -o log_cli=1 -vv --log-level=INFO tests/
21+
```
22+
1123
## Documentation
1224

1325
Here is some archive documentation for you. New and up-to-date one hasn't

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
name = "error-tracker"
33
requires-python = ">=3.8"
44
dynamic = ["version"]
5-
dependencies = [
6-
"jubilant>=1.3.0",
7-
"pytest>=8.3.5",
8-
]
95

106

117
[tool.setuptools.dynamic]
@@ -19,3 +15,6 @@ extend-exclude = ["__pycache__", "*.egg_info"]
1915
[tool.ruff.lint]
2016
select = ["E", "F", "W", "Q", "I"]
2117
ignore = ["E501"]
18+
19+
[tool.pytest]
20+
pythonpath = ["./src", "./local_config"]

src/Makefile

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/daisy/__init__.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from functools import reduce
2-
3-
# !/usr/bin/python
1+
# !/usr/bin/python3
42
# -*- coding: utf-8 -*-
53
#
64
# Copyright © 2011-2013 Canonical Ltd.
@@ -18,6 +16,8 @@
1816
# You should have received a copy of the GNU Affero Public License
1917
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2018

19+
from functools import reduce
20+
2121
config = None
2222
try:
2323
import local_config as config
@@ -41,13 +41,10 @@ def validate_and_set_configuration():
4141
raise ImportError(msg)
4242
if not core_storage:
4343
swift = getattr(config, "swift_bucket", "")
44-
ec2 = getattr(config, "ec2_bucket", "")
4544
local = getattr(config, "san_path", "")
46-
if ec2 and swift:
47-
raise ImportError("ec2_bucket and swift_bucket cannot both be set.")
4845

4946
# Match the old behaviour. Put everything on swift, if available.
50-
# Failing that, fall back to EC2, then local.
47+
# Failing that, then local.
5148
if swift:
5249
# If there is no swift configuration set in local_config or the
5350
# default config check swift_config as that's what the charms
@@ -85,27 +82,6 @@ def validate_and_set_configuration():
8582
"os_region_name": os_region_name,
8683
},
8784
}
88-
elif ec2:
89-
host = getattr(config, "ec2_host", "")
90-
aws_access_key = getattr(config, "aws_access_key", "")
91-
aws_secret_key = getattr(config, "aws_secret_key", "")
92-
if not (host and aws_access_key and aws_secret_key):
93-
msg = (
94-
"EC2 provider set but host, bucket, aws_access_key, or"
95-
" aws_secret_key not set."
96-
)
97-
raise ImportError(msg)
98-
config.storage_write_weights = {"s3": 1.0}
99-
config.core_storage = {
100-
"default": "s3",
101-
"s3": {
102-
"type": "s3",
103-
"host": host,
104-
"bucket": ec2,
105-
"aws_access_key": aws_access_key,
106-
"aws_secret_key": aws_secret_key,
107-
},
108-
}
10985
elif local:
11086
config.storage_write_weights = {"local": 1.0}
11187
config.core_storage = {
@@ -118,7 +94,7 @@ def validate_and_set_configuration():
11894
if not getattr(config, "storage_write_weights", ""):
11995
d = config.core_storage.get("default", "")
12096
if not d:
121-
msg = "No storage_write_weights set, but no default set in core" " storage"
97+
msg = "No storage_write_weights set, but no default set in core storage"
12298
raise ImportError(msg)
12399
config.storage_write_weights = {d: 1.0}
124100

@@ -137,8 +113,6 @@ def validate_and_set_configuration():
137113
"os_tenant_name",
138114
"os_region_name",
139115
]
140-
elif t == "s3":
141-
keys = ["host", "bucket", "aws_access_key", "aws_secret_key"]
142116
elif t == "local":
143117
keys = ["path"]
144118
missing = set(keys) - set(v.keys())
@@ -150,6 +124,8 @@ def validate_and_set_configuration():
150124
msg = "storage_write_weights values do not add up to 1.0."
151125
raise ImportError(msg)
152126

127+
print("Configuration validated")
128+
153129

154130
def gen_write_weight_ranges(d):
155131
total = 0
@@ -160,9 +136,9 @@ def gen_write_weight_ranges(d):
160136
return r
161137

162138

163-
validate_and_set_configuration()
139+
# validate_and_set_configuration()
164140

165-
config.write_weight_ranges = None
166-
if getattr(config, "storage_write_weights", ""):
167-
ranges = gen_write_weight_ranges(config.storage_write_weights)
168-
config.write_weight_ranges = ranges
141+
# config.write_weight_ranges = None
142+
# if getattr(config, "storage_write_weights", ""):
143+
# ranges = gen_write_weight_ranges(config.storage_write_weights)
144+
# config.write_weight_ranges = ranges

src/daisy/app.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from flask import Flask, request
2+
3+
from daisy.submit import submit
4+
from daisy.submit_core import submit_core
5+
6+
app = Flask(__name__)
7+
8+
9+
@app.route("/<system_token>", methods=["POST"])
10+
def handle_submit(system_token):
11+
return submit(request, system_token)
12+
13+
14+
@app.route("/<oopsid>/submit-core/<architecture>/<system_token>", methods=["POST"])
15+
def handle_submit_core(oopsid, architecture, system_token):
16+
return submit_core(request, oopsid, architecture, system_token)
17+
18+
19+
def __main__():
20+
app.run(host="0.0.0.0", debug=True)
21+
22+
23+
if __name__ == "__main__":
24+
__main__()

src/daisy/cassandra_schema.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/daisy/configuration.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@
9797
}
9898
}
9999

100-
# S3 configuration (deprecated). Only set these if you're using S3 for storing
101-
# the core files.
102-
aws_access_key = ""
103-
aws_secret_key = ""
104-
ec2_host = ""
105-
106-
# The bucket to place core files in when using S3 (deprecated).
107-
ec2_bucket = ""
108-
109100
# Swift configuration (deprecated). Only set these if you're using Swift for
110101
# storing the core files.
111102
os_auth_url = ""
@@ -137,11 +128,6 @@
137128
# 'os_password': 'secret',
138129
# 'os_tenant_name': 'ostack_project',
139130
# 'os_region_name': 'region01'}
140-
# 's3-east-1': {'type': 's3',
141-
# 'bucket': 'cores',
142-
# 'host': 's3.amazonaws.com',
143-
# 'aws_secret_key': 'secret',
144-
# 'aws_access_key': 'access-key'}
145131
# }
146132

147133
core_storage = {}
@@ -194,21 +180,29 @@
194180
# Hooks for relations in charms to contribute their configuration settings.
195181
try:
196182
from db_settings import * # noqa: F403
183+
184+
print("Loaded local db settings")
197185
except ImportError:
198186
pass
199187

200188
try:
201189
from amqp_settings import * # noqa: F403
190+
191+
print("Loaded local amqp settings")
202192
except ImportError:
203193
pass
204194

205195
try:
206196
from postgres_settings import * # noqa: F403
197+
198+
print("Loaded local postgres settings")
207199
except ImportError:
208200
pass
209201

210202
try:
211203
from local_settings import * # noqa: F403
204+
205+
print("Loaded local settings")
212206
except ImportError:
213207
pass
214208

src/daisy/metrics.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
from cassandra import ConsistencyLevel
2-
from cassandra.auth import PlainTextAuthProvider
3-
from cassandra.cluster import Cluster
4-
5-
from daisy import config
6-
71
METRICS = None
82

93

@@ -34,16 +28,6 @@ def get_metrics(namespace="daisy"):
3428
return METRICS
3529

3630

37-
def cassandra_session():
38-
auth_provider = PlainTextAuthProvider(
39-
username=config.cassandra_username, password=config.cassandra_password
40-
)
41-
cluster = Cluster(config.cassandra_hosts, auth_provider=auth_provider)
42-
cassandra_session = cluster.connect(config.cassandra_keyspace)
43-
cassandra_session.default_consistency_level = ConsistencyLevel.LOCAL_ONE
44-
return cassandra_session
45-
46-
4731
def record_revno(namespace="daisy"):
4832
import socket
4933

0 commit comments

Comments
 (0)