Added SDXC, MS, MSP and XD memory card tests
--memorycard added for all mediacard jobs
heuristics: add is_memory_card()

Copy the is_memory_card() from scripts/removable_storage_watcher
into the heuristics package.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
heuristics: reuse patterns from udevadm parser

The is_memory_card() function originally used a number of regular
expressions copied from the udisks1 implementation of
removable_storage_watcher script. The udevadm parser already
has similar logic so to improve consistency and code reuse
import the patterns from checkbox.parsers.udevadm

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: kill local copy of is_memory_card()

Use replace local copy with import from checkbox.heuristics.udisks2

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: minor PEP8 improvement

Comparison to false should be done with "if not xxx" or "if x is False",
not with "if x == False".

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: move is_udisks2_supported to checkbox.dbus.udisks

This function is also needed by the removable_storage_test script
so it should be in the checkbox.dbus.udisks module

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
merge is_media_card branch:

* scripts: minor PEP8 improvement
* scripts: kill local copy of is_memory_card()
* heuristics: reuse patterns from udevadm parser
* heuristics: add is_memory_card()
merge code-reuse brancH:

* scripts: move is_udisks2_supported to checkbox.dbus.udisks
scripts: md5_hash_file convert to function

In scripts/removable_storage_tests md5_hash_file is a method
on the DiskTest class. Because does not access any object or class
bits it can be converted to a function and shared between udisks1
and udisks2 implementations

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: remove DiskTest.compare_hash

In scripts/removable_storage_test the DiskTest.compare_hash method
is really a very strange == operator (using an odd spelling
of != and returning the opposite value). The only call site uses
'if not compare_hash()'. Replace it with a single usage of
the != operator for simplicity.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: sort imports in removable_storage_tests

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: fix possible resource leak in removable_storage_test

Both DiskTest.{read,write}_file() methods used incorrect resource
finalization that allowed for an open file to slip on IOError or
when .flush() / os.fsync() throw

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: use logging.{warning,error} instead of print to stderr

This patch replaces a number of calls to print() with either
logging.error() or logging.warning(). This makes the code somewhat
less unreadable and more configurable IMHO

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: discard dummy loop variables

In scripts/removable_storage_test a few loops over dicts use .items()
with a dummy value that is never used. Replace all of them with the
implicit loop over .keys()

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: correct error conditions in md5_hash_file()

md5_hash_file() may misbehave if .read() raises an exception.
In such case the hash of a part of the file would be reported
without a hint of trouble.

In addition, if initial open() fails the result is confusingly, 1.

In both cases, on any error the function returns None and logs
the details of the problem that had occurred. Error handling is
also shorter than before.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: do not specify tempfile.mkdtemp(dir=...)

Explicitly specifying that argument here is wrong as it will get
the correct (environment dependent) value automatically and breaks
customization users may have.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: rename confusing 'file' to 'temp_dir'

While using 'file' as a name for a file might be a stretch (hides builtin
name bound to different object) it certainly makes no sense when it
is used to represent a temporary _directory_

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: don't use threading to mount/umount filesystems

scripts/removable_storage_test uses threads to mount and unmount
filesystems on demand. Nothing in the history of the project warrants
this added complexity and indeterminism. Replace threads with direct,
blocking calls.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
scripts: provide exception details on errors

In several cases an exception is simply logged with a constant message
without any hints as to what may have gone wrong. In those cases,
basic add exception data to the error message.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>