def inventory_connect(time_out=10.0, time_interval=0.2): """ Mount all unmounted devices and wait for the (asynchronous) connection to occur. Parameters: time_out -- Number of seconds to elapse before time out. time_interval -- Initial time interval between checks. Raise: Exception if any connections are not verified during the time allocated. """ unmounted_device_names = set(inventory_unmounted()) if unmounted_device_names: for device_name in unmounted_device_names: mount_from_settings(device_name) time_accum = 0.0 num_checks = 0 while time_accum < time_out: unconnected_device_names = unmounted_device_names - set(inventory_connected()) num_checks += 1 if not unconnected_device_names: print('%s network device connection(s) verified after %s check(s) and %s seconds.' % (len(unmounted_device_names), num_checks, time_accum)) return else: # Don't hammer the Controller or it will crash. # This not a denial-of-service (DOS) attack ;-) # Print a message explaining the pause, otherwise user might terminate. expanding_interval = time_interval * num_checks time_accum += expanding_interval print('sleep(%s) seconds pending connection to %s network device(s).' % (expanding_interval, len(unconnected_device_names))) time.sleep(expanding_interval) unconnected_device_names = unmounted_device_names - set(inventory_connected()) if unconnected_device_names: raise Exception('Expected connection after %s check(s) and %s seconds to network device(s): ' % (num_checks, time_accum) + ', '.join(unconnected_device_names))
def setUp(self): unmounted_list = inventory_unmounted() for device_name in unmounted_list: device_config = self.network_device_config[device_name] print('setup: device_mount(' + device_name, *device_config.values(), sep=', ', end=')\n') device_mount( device_name, device_config['address'], device_config['port'], device_config['username'], device_config['password']) if unmounted_list: print('Sleep to allow Controller to update...') time.sleep(2) self.assertTrue(inventory_mounted(), 'Not mounted: ' + str(inventory_unmounted()))
def main(): print(plain(doc(device_mount))) for device_name in inventory_unmounted(): demonstrate(device_name) return os.EX_OK print('All configured devices are mounted. Demonstration cancelled.') return os.EX_TEMPFAIL
def main(): print(plain(doc(device_mount))) for device_name in inventory_unmounted(): demonstrate(device_name) return os.EX_OK print('All configured devices are mounted. Demonstration cancelled.') return os.EX_TEMPFAIL
def setUp(self): unmounted_list = inventory_unmounted() for device_name in unmounted_list: device_config = self.network_device_config[device_name] print('setup: device_mount(' + device_name, *device_config.values(), sep=', ', end=')\n') device_mount(device_name, device_config['address'], device_config['port'], device_config['username'], device_config['password']) if unmounted_list: print('Sleep to allow Controller to update...') time.sleep(2) self.assertTrue(inventory_mounted(), 'Not mounted: ' + str(inventory_unmounted()))
def setUp(self): """ Mount every device that is unmounted. """ unmounted_list = inventory_unmounted() if unmounted_list: for device_name in unmounted_list: mount_from_settings(device_name) self.assertTrue(mounted(device_name), 'Expected mounted: ' + device_name)
def setUp(self): """ Mount every device that is unmounted. """ unmounted_list = inventory_unmounted() if unmounted_list: for device_name in unmounted_list: mount_from_settings(device_name) self.assertTrue(mounted(device_name), 'Expected mounted: ' + device_name)
def main(): """Demonstrate on the unmounted devices, stopping when a connection to any device is established.""" unmounted_list = inventory_unmounted() if not unmounted_list: print('All configured devices are mounted. Demonstration cancelled.') else: for device_name in unmounted_list: if demonstrate(device_name): return os.EX_OK return os.EX_TEMPFAIL
def main(): """Demonstrate on the unmounted devices, stopping when a connection to any device is established.""" unmounted_list = inventory_unmounted() if not unmounted_list: print('All configured devices are mounted. Demonstration cancelled.') else: for device_name in unmounted_list: if demonstrate(device_name): return EX_OK return EX_TEMPFAIL
def test_device_mount(self): device_names = inventory_unmounted() self.assertTrue(device_names, "One or more devices must be configured.") for device_name in device_names: expected = mount_from_settings(device_name) self.assertTrue(mounted(device_name), "Expected mounted: " + device_name) actual = device_control(device_name) self.assertEqual(device_name, actual.device_name) self.assertEqual(expected.device_name, actual.device_name) self.assertEqual(expected.address, actual.address) self.assertEqual(expected.port, actual.port) self.assertEqual(expected.username, actual.username) self.assertEqual(expected.password, actual.password)
def test_device_mount(self): device_names = inventory_unmounted() self.assertTrue(device_names, 'One or more devices must be configured.') for device_name in device_names: expected = mount_from_settings(device_name) self.assertTrue(mounted(device_name), 'Expected mounted: ' + device_name) actual = device_control(device_name) self.assertEqual(device_name, actual.device_name) self.assertEqual(expected.device_name, actual.device_name) self.assertEqual(expected.address, actual.address) self.assertEqual(expected.port, actual.port) self.assertEqual(expected.username, actual.username) self.assertEqual(expected.password, actual.password)
def main(): print(plain(doc(device_mount))) unmounted_list = inventory_unmounted() if not unmounted_list: print('There are no (configured) devices unmounted.') else: configured = settings.config['network_device'] for device_name in unmounted_list: device_config = configured[device_name] print('device_mount(' + device_name, *device_config.values(), sep=', ', end=')\n') device_mount( device_name, device_config['address'], device_config['port'], device_config['username'], device_config['password'])
def main(): inventory_set = set(inventory()) inventory_connected_set = set(inventory_connected()) inventory_not_connected_set = set(inventory_not_connected()) inventory_mounted_set = set(inventory_mounted()) inventory_unmounted_set = set(inventory_unmounted()) empty_set = set() print("The set of 'connected' devices is a subset of the inventory:", inventory_connected_set <= inventory_set) assert inventory_connected_set <= inventory_set print( "The set of 'not connected' devices is also a subset of the inventory:", inventory_not_connected_set <= inventory_set) assert inventory_not_connected_set <= inventory_set print( "There are no network devices in both the 'connected' set and the 'not connected' set:", inventory_not_connected_set & inventory_connected_set == empty_set) assert inventory_not_connected_set & inventory_connected_set == empty_set print( "Every network device in the inventory is in either the 'connected' set or the 'not connected' set:", inventory_connected_set | inventory_not_connected_set == inventory_set) assert inventory_connected_set | inventory_not_connected_set == inventory_set print() print("The set of 'mounted' devices is a subset of the inventory:", inventory_mounted_set <= inventory_set) assert inventory_mounted_set <= inventory_set print( "The set of 'unmounted' devices has no intersection with the inventory:", inventory_unmounted_set & inventory_set == empty_set) assert inventory_unmounted_set & inventory_set == empty_set, 'Expect no intersection, got %s' % ( inventory_unmounted_set & inventory_set) print( "There are no network devices in both the 'mounted' set and the 'unmounted' set:", inventory_unmounted_set & inventory_mounted_set == empty_set) assert inventory_unmounted_set & inventory_mounted_set == empty_set
def test_mount_device(self): self.assertTrue(self.network_device_config, 'One or more devices must be configured.') unmounted_list = inventory_unmounted() self.assertTrue(unmounted_list, 'One or more devices must be unmounted.') for device_name in unmounted_list: device_config = self.network_device_config[device_name] print('test: device_mount(' + device_name, *device_config.values(), sep=', ', end=')\n') device_mount( device_name, device_config['address'], device_config['port'], device_config['username'], device_config['password']) print('Sleep to allow Controller to update...') time.sleep(2) for device_name in unmounted_list: self.assertTrue(mounted(device_name), 'Not mounted: ' + device_name)
def inventory_connect(time_out=10.0, time_interval=0.2): """ Mount all unmounted devices and wait for the (asynchronous) connection to occur. Parameters: time_out -- Number of seconds to elapse before time out. time_interval -- Initial time interval between checks. Raise: Exception if any connections are not verified during the time allocated. """ unmounted_device_names = set(inventory_unmounted()) if unmounted_device_names: for device_name in unmounted_device_names: mount_from_settings(device_name) time_accum = 0.0 num_checks = 0 while time_accum < time_out: unconnected_device_names = unmounted_device_names - set( inventory_connected()) num_checks += 1 if not unconnected_device_names: print( '%s network device connection(s) verified after %s check(s) and %s seconds.' % (len(unmounted_device_names), num_checks, time_accum)) return else: # Don't hammer the Controller or it will crash. # This not a denial-of-service (DOS) attack ;-) # Print a message explaining the pause, otherwise user might terminate. expanding_interval = time_interval * num_checks time_accum += expanding_interval print( 'sleep(%s) seconds pending connection to %s network device(s).' % (expanding_interval, len(unconnected_device_names))) time.sleep(expanding_interval) unconnected_device_names = unmounted_device_names - set( inventory_connected()) if unconnected_device_names: raise Exception( 'Expected connection after %s check(s) and %s seconds to network device(s): ' % (num_checks, time_accum) + ', '.join(unconnected_device_names))
def test_mount_device(self): self.assertTrue(self.network_device_config, 'One or more devices must be configured.') unmounted_list = inventory_unmounted() self.assertTrue(unmounted_list, 'One or more devices must be unmounted.') for device_name in unmounted_list: device_config = self.network_device_config[device_name] print('test: device_mount(' + device_name, *device_config.values(), sep=', ', end=')\n') device_mount(device_name, device_config['address'], device_config['port'], device_config['username'], device_config['password']) print('Sleep to allow Controller to update...') time.sleep(2) for device_name in unmounted_list: self.assertTrue(mounted(device_name), 'Not mounted: ' + device_name)
def main(): inventory_set = set(inventory()) inventory_connected_set = set(inventory_connected()) inventory_not_connected_set = set(inventory_not_connected()) inventory_mounted_set = set(inventory_mounted()) inventory_unmounted_set = set(inventory_unmounted()) empty_set = set() print("The set of 'connected' devices is a subset of the inventory:", inventory_connected_set <= inventory_set) assert inventory_connected_set <= inventory_set print("The set of 'not connected' devices is also a subset of the inventory:", inventory_not_connected_set <= inventory_set) assert inventory_not_connected_set <= inventory_set print("There are no network devices in both the 'connected' set and the 'not connected' set:", inventory_not_connected_set & inventory_connected_set == empty_set) assert inventory_not_connected_set & inventory_connected_set == empty_set print("Every network device in the inventory is in either the 'connected' set or the 'not connected' set:", inventory_connected_set | inventory_not_connected_set == inventory_set) assert inventory_connected_set | inventory_not_connected_set == inventory_set print() print("The set of 'mounted' devices is a subset of the inventory:", inventory_mounted_set <= inventory_set) assert inventory_mounted_set <= inventory_set print("The set of 'unmounted' devices has no intersection with the inventory:", inventory_unmounted_set & inventory_set == empty_set) assert inventory_unmounted_set & inventory_set == empty_set, 'Expect no intersection, got %s' % (inventory_unmounted_set & inventory_set) print("There are no network devices in both the 'mounted' set and the 'unmounted' set:", inventory_unmounted_set & inventory_mounted_set == empty_set) assert inventory_unmounted_set & inventory_mounted_set == empty_set
def main(): print(plain(doc(inventory_unmounted))) print(inventory_unmounted())
def main(): print(plain(doc(inventory_unmounted))) print(inventory_unmounted())