def read_password(path, default=None): """ Return ProtectedPassword wrapping value of a sysfs attribute, or defualt if default is specified and the attribute does not exists. Raises: EnviromentError if reading the attribute fails, or default was not specified and the attribute does not exist. """ value = read(path, default) return password.ProtectedPassword(value)
def __init__(self, vminfo, vmid, irs): self._vminfo = vminfo self._vmid = vmid self._irs = irs self._prepared_volumes = [] self._passwd_file = os.path.join(_V2V_DIR, "%s.tmp" % vmid) self._password = password.ProtectedPassword('') self._base_command = [_VIRT_V2V.cmd, '-v', '-x'] self._query_v2v_caps() if 'qcow2_compat' in vminfo: qcow2_compat = vminfo['qcow2_compat'] if qcow2_compat not in _QCOW2_COMPAT_SUPPORTED: logging.error('Invalid QCOW2 compat version %r' % qcow2_compat) raise ValueError('Invalid QCOW2 compat version %r' % qcow2_compat) if 'vdsm-compat-option' in self._v2v_caps: self._base_command.extend(['--vdsm-compat', qcow2_compat]) elif qcow2_compat != '0.10': # Note: qcow2 is only a suggestion from the engine # if virt-v2v doesn't support it we fall back to default logging.info( 'virt-v2v not supporting qcow2 compat version: ' '%r', qcow2_compat)
'displayPort': -1, 'displaySecurePort': -1, 'display': 'qxl', 'displayIp': '127.0.0.1', 'vmType': 'kvm', 'memSize': 1024 } _TICKET_PARAMS = { 'userName': '******', 'userId': 'fdfc627c-d875-11e0-90f0-83df133b58cc' } _GRAPHICS_DEVICE_PARAMS = { 'deviceType': hwclass.GRAPHICS, 'password': password.ProtectedPassword('12345678'), 'ttl': 0, 'existingConnAction': 'disconnect', 'params': _TICKET_PARAMS } @expandPermutations class TestVmOperations(TestCaseBase): # just numbers, no particular meaning UPDATE_OFFSETS = [-3200, 3502, -2700, 3601] BASE_OFFSET = 42 GRAPHIC_DEVICES = [{ 'type': 'graphics', 'device': 'spice',
def test_read_password_missing_default(self): self.assertEqual(sysfs.read_password("/no/such/path", ""), password.ProtectedPassword(""))
def test_read_password_strip(self): with temporaryPath(data=b" password\n ") as path: self.assertEqual(sysfs.read_password(path), password.ProtectedPassword("password"))