Skip to content

Commit

Permalink
Plugins should never fail the tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
Shay Arbov committed Jan 7, 2018
1 parent 77e525d commit b86a172
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 39 deletions.
11 changes: 9 additions & 2 deletions docker_test_tools/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ def setup(self):
self.run_containers()

for plugin in self.plugins:
plugin.start()
try:
plugin.start()
except:
logging.warning("Failed starting Plugin %s, skipping", plugin)

except:
log.exception("Setup failure, tearing down the test environment")
self.teardown()
Expand All @@ -102,7 +106,10 @@ def teardown(self):
log.debug("Tearing down the environment")
try:
for plugin in self.plugins:
plugin.stop()
try:
plugin.stop()
except:
logging.warning("Failed stopping Plugin %s, skipping", plugin)
finally:
self.cleanup()

Expand Down
77 changes: 40 additions & 37 deletions docker_test_tools/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def _split_logs(self, stat_file_path):
with io.open(stat_file_path, 'r', encoding=self.encoding) as combined_stats_file:
for raw_line in combined_stats_file.readlines():

# Cleanup escape characters prefix
raw_line = raw_line.lstrip(self.SAMPLE_PREFIX)

if raw_line.startswith(COMMON_STATS_PREFIX):
value = {"test": raw_line.lstrip(COMMON_STATS_PREFIX).strip()}
common_stats.append(value)
Expand Down Expand Up @@ -139,43 +142,43 @@ def parse_line(self, line):
- Extract the line data from the raw string.
- Add the data to the stats summary info.
"""
# Cleanup escape characters prefix
line = line.lstrip(self.SAMPLE_PREFIX)

# Split the stat data to it's raw components
components = json.loads(line)

# Handle bad stats metrics
for key, val in components.items():
if '--' in val:
components[key] = 0

# Skip bad stats metrics
if len(components) != 5:
return

name = components['name']

if not isinstance(components['cpu'], int):
# Get the used CPU percentage as a floating number
components['cpu'] = float(components['cpu'][:-1])

# Get the used stats numbers as used bytes number
components['ram'] = self.get_bytes(components['ram'])
components['net'] = self.get_bytes(components['net'])
components['block'] = self.get_bytes(components['block'])

if name not in self.summary_data:
self.summary_data[name] = ContainerStats(name=name)

self.summary_data[name].update(
cpu_used=components['cpu'],
ram_used=components['ram'],
net_io_used=components['net'],
block_io_used=components['block']
)

return components
try:
# Split the stat data to it's raw components
components = json.loads(line)

# Handle bad stats metrics
for key, val in components.items():
if '--' in val:
components[key] = 0

# Skip bad stats metrics
if len(components) != 5:
return

name = components['name']

if not isinstance(components['cpu'], int):
# Get the used CPU percentage as a floating number
components['cpu'] = float(components['cpu'][:-1])

# Get the used stats numbers as used bytes number
components['ram'] = self.get_bytes(components['ram'])
components['net'] = self.get_bytes(components['net'])
components['block'] = self.get_bytes(components['block'])

if name not in self.summary_data:
self.summary_data[name] = ContainerStats(name=name)

self.summary_data[name].update(
cpu_used=components['cpu'],
ram_used=components['ram'],
net_io_used=components['net'],
block_io_used=components['block']
)

return components
except:
logging.debug("Failed parsing line: %r", line)

@staticmethod
def get_bytes(raw_value):
Expand Down

0 comments on commit b86a172

Please sign in to comment.