GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 6843145a authored by juga  's avatar juga
Browse files

fix: v3bwfile: Add tor_version KeyValue

- Create new KeyValues constants for the new v1.5.0 KeyValues
- Instanciate State in Header.from_results so that there is no need
  to create new methods for all the header KeyValues that are read
  from the state file
- Add tor_version to the kwargs to initialize the Header
- Write tor_version in the state file when the scanner is started

Closes: #30196.
parent ed24b53d
......@@ -679,9 +679,14 @@ def run_speedtest(args, conf):
# When there will be a refactor where conf is global, this can be removed
# from here.
state = State(conf.getpath('paths', 'state_fname'))
# XXX: tech-debt: create new function to obtain the controller and to
# write the state, so that a unit test to check the state tor version can
# be created
# Store tor version whenever the scanner starts.
state['tor_version'] = str(controller.get_version())
# Call only once to initialize http_headers
settings.init_http_headers(conf.get('scanner', 'nickname'), state['uuid'],
str(controller.get_version()))
state['tor_version'])
# To do not have to pass args and conf to RelayList, pass an extra
# argument with the data_period
measurements_period = conf.getint('general', 'data_period')
......
......@@ -121,12 +121,21 @@ HEADER_KEYS_V1_4 = [
'time_to_report_half_network',
] + HEADER_RECENT_MEASUREMENTS_EXCLUDED_KEYS
# KeyValues added in the Bandwidth File v1.5.0
# XXX: Change SPEC_VERSION when all the v1.5.0 keys are added, before a new
# sbws release.
# Tor version will be obtained from the state file, so it won't be pass as an
# argument, but will be self-initialized.
HEADER_KEYS_V1_5_TO_INIT = ['tor_version']
HEADER_KEYS_V1_5 = HEADER_KEYS_V1_5_TO_INIT
# KeyValues that are initialized from arguments, not self-initialized.
HEADER_INIT_KEYS = (
HEADER_KEYS_V1_1_TO_INIT
+ HEADER_KEYS_V1_3
+ HEADER_KEYS_V1_2
+ HEADER_KEYS_V1_4
+ HEADER_KEYS_V1_5_TO_INIT
)
HEADER_INT_KEYS = HEADER_KEYS_V1_2 + HEADER_KEYS_V1_4
......@@ -137,6 +146,7 @@ HEADER_UNORDERED_KEYS = (
+ HEADER_KEYS_V1_3
+ HEADER_KEYS_V1_2
+ HEADER_KEYS_V1_4
+ HEADER_KEYS_V1_5
)
# List of all the KeyValues currently being used to generate the file
HEADER_ALL_KEYS = HEADER_KEYS_V1_1_ORDERED + HEADER_UNORDERED_KEYS
......@@ -331,6 +341,15 @@ class V3BWHeader(object):
generator_started = cls.generator_started_from_file(state_fpath)
recent_consensus_count = cls.consensus_count_from_file(state_fpath)
timestamp = str(latest_bandwidth)
# XXX: tech-debt: obtain the other values from the state file using
# this state variable.
# Store the state as an attribute of the object?
state = State(state_fpath)
tor_version = state.get('tor_version', None)
if tor_version:
kwargs['tor_version'] = tor_version
kwargs['latest_bandwidth'] = unixts_to_isodt_str(latest_bandwidth)
kwargs['earliest_bandwidth'] = unixts_to_isodt_str(earliest_bandwidth)
if generator_started is not None:
......
......@@ -50,10 +50,14 @@ earliest_bandwidth_l = KEYVALUE_SEP_V1.join(['earliest_bandwidth',
generator_started = '2018-04-16T14:09:05'
generator_started_l = KEYVALUE_SEP_V1.join(['generator_started',
generator_started])
tor_version = '0.4.2.5'
tor_version_l = KEYVALUE_SEP_V1.join(['tor_version', tor_version])
header_extra_ls = [timestamp_l, version_l,
earliest_bandwidth_l, file_created_l, generator_started_l,
latest_bandwidth_l,
software_l, software_version_l, TERMINATOR]
software_l, software_version_l, tor_version_l,
TERMINATOR]
header_extra_str = LINE_SEP.join(header_extra_ls) + LINE_SEP
# Line produced without any scaling.
......@@ -90,7 +94,8 @@ def test_v3bwheader_extra_str():
header = V3BWHeader(timestamp_l,
file_created=file_created,
generator_started=generator_started,
earliest_bandwidth=earliest_bandwidth)
earliest_bandwidth=earliest_bandwidth,
tor_version=tor_version)
assert header_extra_str == str(header)
......@@ -98,7 +103,8 @@ def test_v3bwheader_from_lines():
header_obj = V3BWHeader(timestamp_l,
file_created=file_created,
generator_started=generator_started,
earliest_bandwidth=earliest_bandwidth)
earliest_bandwidth=earliest_bandwidth,
tor_version=tor_version)
header, _ = V3BWHeader.from_lines_v1(header_extra_ls)
assert str(header_obj) == str(header)
......@@ -107,7 +113,8 @@ def test_v3bwheader_from_text():
header_obj = V3BWHeader(timestamp_l,
file_created=file_created,
generator_started=generator_started,
earliest_bandwidth=earliest_bandwidth)
earliest_bandwidth=earliest_bandwidth,
tor_version=tor_version)
header, _ = V3BWHeader.from_text_v1(header_extra_str)
assert str(header_obj) == str(header)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment