diff options
| author | Sylvain Pineau <sylvain.pineau@canonical.com> | 2017-07-03 10:10:16 +0200 |
|---|---|---|
| committer | Sylvain Pineau <sylvain.pineau@canonical.com> | 2017-07-03 10:10:16 +0200 |
| commit | 9d59f8582348f7a95205b6ca50587d45ba869857 (patch) | |
| tree | 6431667f4214d36e0deabbf99fe61eb5a528848a /bin | |
| parent | 18f79d91e4376193287b980c60452b9a6696d221 (diff) | |
Update scripts in bin dir with fixes from the snappy provider
The fork versions got some fixes/enhancements that were never merged back.
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/gateway_ping_test | 2 | ||||
| -rwxr-xr-x | bin/network_device_info | 13 | ||||
| -rwxr-xr-x | bin/removable_storage_test | 117 | ||||
| -rwxr-xr-x | bin/removable_storage_watcher | 15 | ||||
| -rwxr-xr-x | bin/storage_test | 10 |
5 files changed, 139 insertions, 18 deletions
diff --git a/bin/gateway_ping_test b/bin/gateway_ping_test index 22aec6a..3e58c21 100755 --- a/bin/gateway_ping_test +++ b/bin/gateway_ping_test @@ -278,7 +278,7 @@ def main(args): ).format(ping_summary['pct_loss'], args.threshold)) return 0 else: - print(_("Internet connection fully established")) + print(_("Connection to test host fully established")) return 0 diff --git a/bin/network_device_info b/bin/network_device_info index 19e5b68..9aa4f90 100755 --- a/bin/network_device_info +++ b/bin/network_device_info @@ -126,12 +126,9 @@ class NetworkingDevice(): try: stream = check_output(cmd, stderr=STDOUT, universal_newlines=True) except CalledProcessError as err: - print("Error running %s:" % ' '.join(cmd), file=sys.stderr) - print(err.output, file=sys.stderr) return None if not stream: - print("Error: modinfo returned nothing", file=sys.stderr) return None else: parser = ModinfoParser(stream) @@ -193,7 +190,11 @@ def match_counts(nm_devices, udev_devices, devtype): """ # now check that the count (by type) matches nm_type_devices = [dev for dev in nm_devices if dev.gettype() in devtype] - udevtype = 'WIRELESS' if devtype == 'WiFi' else 'NETWORK' + udevtype = 'NETWORK' + if devtype == 'WiFi': + udevtype = 'WIRELESS' + elif devtype == 'Modem': + udevtype = 'WWAN' udev_type_devices = [ udev for udev in udev_devices @@ -262,7 +263,9 @@ def main(args): if not match_counts(nm_devices, udev_devices, "WiFi"): return 1 - elif not match_counts(nm_devices, udev_devices, ("Ethernet", "Modem")): + elif not match_counts(nm_devices, udev_devices, "Ethernet"): + return 1 + elif not match_counts(nm_devices, udev_devices, "Modem"): return 1 else: return 0 diff --git a/bin/removable_storage_test b/bin/removable_storage_test index 3502455..ddd4e1b 100755 --- a/bin/removable_storage_test +++ b/bin/removable_storage_test @@ -177,11 +177,120 @@ class DiskTest(): Indirectly sets: self.rem_disks{,_nm,_memory_cards,_memory_cards_nm,_speed} """ - bus, loop = connect_to_system_bus() - if is_udisks2_supported(bus): - self._probe_disks_udisks2(bus) + if "SNAP" in os.environ: + self._probe_disks_udisks2_cli() else: - self._probe_disks_udisks1(bus) + bus, loop = connect_to_system_bus() + if is_udisks2_supported(bus): + self._probe_disks_udisks2(bus) + else: + self._probe_disks_udisks1(bus) + + def _probe_disks_udisks2_cli(self): + # First we will build up a db of udisks info by scraping the output + # of the dump command + # TODO: remove the snap prefix when the alias becomes available + proc = subprocess.Popen(['udisks2.udisksctl', 'dump'], + stdout=subprocess.PIPE) + udisks_devices = {} + current_bd = None + current_interface = None + while True: + line = proc.stdout.readline().decode(sys.stdout.encoding) + if line == '': + break + if line == '\n': + current_bd = None + current_interface = None + if line.startswith('/org/freedesktop/UDisks2/'): + path = line.strip() + current_bd = os.path.basename(path).rstrip(':') + udisks_devices[current_bd] = {} + continue + if current_bd is None: + continue + if line.startswith(' org.freedesktop'): + current_interface = line.strip().rstrip(':') + udisks_devices[current_bd][current_interface] = {} + continue + if current_interface is None: + continue + entry = ''.join(c for c in line if c not in '\n\t\' ') + wanted_keys = ('Device:', 'Drive:', 'MountPoints:', 'Vendor:', + 'ConnectionBus:', 'Model:', 'Media:',) + for key in wanted_keys: + if entry.startswith(key): + udisks_devices[current_bd][current_interface][key] = ( + entry[len(key):]) + + # Now use the populated udisks structure to fill out the API used by + # other _probe disks functions + for device, interfaces in udisks_devices.items(): + # iterate over udisks objects that have both filesystem and + # block device interfaces + if (UDISKS2_FILESYSTEM_INTERFACE in interfaces and + UDISKS2_BLOCK_INTERFACE in interfaces): + # To be an IO candidate there must be a drive object + drive = interfaces[UDISKS2_BLOCK_INTERFACE].get('Drive:') + if drive is None or drive is '/': + continue + drive_object = udisks_devices[os.path.basename(drive)] + + # Get the connection bus property from the drive interface of + # the drive object. This is required to filter out the devices + # we don't want to look at now. + connection_bus = ( + drive_object[UDISKS2_DRIVE_INTERFACE]['ConnectionBus:']) + desired_connection_buses = set([ + map_udisks1_connection_bus(device) + for device in self.device]) + # Skip devices that are attached to undesired connection buses + if connection_bus not in desired_connection_buses: + continue + + dev_file = ( + interfaces[UDISKS2_BLOCK_INTERFACE].get('Device:')) + + parent = self._find_parent(dev_file.replace('/dev/', '')) + if (parent and + find_pkname_is_root_mountpoint(parent, self.lsblk)): + continue + + # XXX: we actually only scrape the first one currently + mount_point = ( + interfaces[UDISKS2_FILESYSTEM_INTERFACE].get( + 'MountPoints:')) + if mount_point == '': + mount_point = None + + # We need to skip-non memory cards if we look for memory cards + # and vice-versa so let's inspect the drive and use heuristics + # to detect memory cards (a memory card reader actually) now. + if self.memorycard != is_memory_card( + drive_object[UDISKS2_DRIVE_INTERFACE]['Vendor:'], + drive_object[UDISKS2_DRIVE_INTERFACE]['Model:'], + drive_object[UDISKS2_DRIVE_INTERFACE]['Media:']): + continue + + if mount_point is None: + self.rem_disks_memory_cards_nm[dev_file] = None + self.rem_disks_nm[dev_file] = None + else: + self.rem_disks_memory_cards[dev_file] = mount_point + self.rem_disks[dev_file] = mount_point + + # Get the speed of the interconnect that is associated with the + # block device we're looking at. This is purely informational + # but it is a part of the required API + udev_devices = get_udev_block_devices(GUdev.Client()) + for udev_device in udev_devices: + if udev_device.get_device_file() == dev_file: + interconnect_speed = get_interconnect_speed(udev_device) + if interconnect_speed: + self.rem_disks_speed[dev_file] = ( + interconnect_speed * 10 ** 6) + else: + self.rem_disks_speed[dev_file] = None def _probe_disks_udisks2(self, bus): """ diff --git a/bin/removable_storage_watcher b/bin/removable_storage_watcher index 794bb1b..88cae9b 100755 --- a/bin/removable_storage_watcher +++ b/bin/removable_storage_watcher @@ -411,7 +411,7 @@ class UDisks2StorageDeviceListener: UDISKS2_DRIVE_PROPERTY_CONNECTION_BUS = "ConnectionBus" def __init__(self, system_bus, loop, action, devices, minimum_speed, - memorycard): + memorycard, unmounted = False): # Store the desired minimum speed of the device in Mbit/s. The argument # is passed as the number of bits per second so let's fix that. self._desired_minimum_speed = minimum_speed / 10 ** 6 @@ -421,6 +421,9 @@ class UDisks2StorageDeviceListener: map_udisks1_connection_bus(device) for device in devices]) # Check if we are explicitly looking for memory cards self._desired_memory_card = memorycard + # Store information whether we also want detected, but unmounted + # devices too + self._allow_unmounted = unmounted # Store the desired "delta" direction depending on # whether we test for insertion or removal if action == "insert": @@ -561,7 +564,10 @@ class UDisks2StorageDeviceListener: # Skip objects we already ignored and complained about before if object_path in self._ignored_objects: continue - needs = set(('block-fs', 'partition', 'non-empty', 'mounted')) + needs = set(('block-fs', 'partition', 'non-empty')) + if not self._allow_unmounted: + needs.add('mounted') + # As a special exception when the ConnectionBus is allowed to be # empty, as is the case with eSATA devices, do not require the # filesystem to be mounted as gvfs may choose not to mount it @@ -851,6 +857,8 @@ def main(): dest='logging_level', help="Enable verbose output") parser.add_argument('--debug', action='store_const', const=logging.DEBUG, dest='logging_level', help="Enable debugging") + parser.add_argument('--unmounted', action='store_true', + help="Don't require drive being automounted") parser.set_defaults(logging_level=logging.WARNING) args = parser.parse_args() @@ -873,7 +881,8 @@ def main(): logging.debug("Using UDisks2 interface") listener = UDisks2StorageDeviceListener( system_bus, loop, - args.action, args.device, args.minimum_speed, args.memorycard) + args.action, args.device, args.minimum_speed, args.memorycard, + args.unmounted) else: # Construct the listener with all of the arguments provided on the # command line and the explicit system_bus, loop objects. diff --git a/bin/storage_test b/bin/storage_test index 5f7516b..da4b717 100755 --- a/bin/storage_test +++ b/bin/storage_test @@ -116,7 +116,7 @@ fi echo "Set disk to $disk" scripted_mount=0 -if [ -b $disk ] +if [ -b "$disk" ] then echo "$disk is a block device" @@ -133,7 +133,7 @@ then # Regex changed to better handle when $disk appears more than once # in parted output (such as in warning messages or not caught in the # check above) - size=`parted -l -s |grep "Disk.*${disk}" |awk '{print $3}'` + size=`parted -l -s 2>&1 | grep "Disk .*${disk}:" | awk '{print $3}'` if [ -n "$size" ] then @@ -163,15 +163,15 @@ then fi - if [ $size_range == "KB" ] + if [ "$size_range" == "KB" ] then echo "$disk size reported in KB, seems to be too small for testing." exit 1 - elif [ $size_range == "MB" ] + elif [ "$size_range" == "MB" ] then size_int=${size::${#size}-2} - if [ $size_int -gt 10 ] + if [ "$size_int" -gt 10 ] then run_bonnie $disk if [[ $scripted_mount == 1 ]] |
