def apply_simple_structure_test(self): data = self.SimpleData() self.assertEqual(data.x, 0) structure = {'x': 10} apply_structure(structure, data) self.assertEqual(data.x, 10)
def get_from_invalid_data_test(self): data = self.InvalidData() self.assertEqual(data.x, 0) with self.assertRaises(DBusStructureError) as cm: apply_structure({'y': 10}, self.InvalidData()) self.assertEqual(str(cm.exception), """Fields are not defined at '__dbus_fields__'.""")
def SetRealm(self, realm: Structure): """Specify of the enrollment in a realm. The DBus structure is defined by RealmData. :param realm: a dictionary with a specification """ realm_data = self.implementation.create_realm() apply_structure(realm, realm_data) self.implementation.set_realm(realm_data)
def execute(self): if not self.discovered: return security_proxy = SECURITY.get_proxy() realm = apply_structure(security_proxy.Realm, RealmData()) for arg in realm.join_options: if arg.startswith("--no-password") or arg.startswith( "--one-time-password"): pw_args = [] break else: # no explicit password arg using implicit --no-password pw_args = ["--no-password"] argv = ["join", "--install", util.getSysroot(), "--verbose"] + pw_args + realm.join_options rc = -1 try: rc = util.execWithRedirect("realm", argv) except OSError: pass if rc == 0: realm_log.info("Joined realm %s", realm.name)
def setup(self): security_proxy = SECURITY.get_proxy() realm = apply_structure(security_proxy.Realm, RealmData()) if not realm.name: return try: argv = ["discover", "--verbose" ] + realm.discover_options + [realm.name] output = util.execWithCapture("realm", argv, filter_stderr=True) except OSError: # TODO: A lousy way of propagating what will usually be # 'no such realm' # The error message is logged by util return # Now parse the output for the required software. First line is the # realm name, and following lines are information as "name: value" self.packages = ["realmd"] self.discovered = "" lines = output.split("\n") if not lines: return self.discovered = lines.pop(0).strip() realm_log.info("Realm discovered: %s", self.discovered) for line in lines: parts = line.split(":", 1) if len(parts) == 2 and parts[0].strip() == "required-package": self.packages.append(parts[1].strip()) realm_log.info("Realm %s needs packages %s", self.discovered, ", ".join(self.packages))
def _update_editable_configurations(self): device_configurations = self._network_module.proxy.GetDeviceConfigurations( ) self.editable_configurations = [ apply_structure(dc, NetworkDeviceConfiguration()) for dc in device_configurations if dc['device-type'] in self.configurable_device_types ]
def get_interface_hw_address(iface): """Get hardware address of network interface.""" network_proxy = NETWORK.get_proxy() device_infos = [apply_structure(device, NetworkDeviceInfo()) for device in network_proxy.GetSupportedDevices()] for info in device_infos: if info.device_name == iface: return info.hw_address return ""
def get_supported_devices(): """Get existing network devices supported by the installer. :return: basic information about the devices :rtype: list(NetworkDeviceInfo) """ network_proxy = NETWORK.get_proxy() return [ apply_structure(device, NetworkDeviceInfo()) for device in network_proxy.GetSupportedDevices() ]
def refresh(self): self._nicCombo.remove_all() network_proxy = NETWORK.get_proxy() ethernet_devices = [apply_structure(device, NetworkDeviceInfo()) for device in network_proxy.GetSupportedDevices() if device['device-type'] == NM.DeviceType.ETHERNET] for dev_info in ethernet_devices: self._nicCombo.append_text("%s - %s" % (dev_info.device_name, dev_info.hw_address)) self._nicCombo.set_active(0)
def apply_complicated_structure_test(self): data = apply_structure( { 'dictionary': {1: "1", 2: "2"}, 'bool-list': [True, False, False], 'very-long-property-name': "My String Value" }, self.ComplicatedData() ) self.assertEqual(data.dictionary, {1: "1", 2: "2"}) self.assertEqual(data.bool_list, [True, False, False]) self.assertEqual(data.very_long_property_name, "My String Value")
def apply_complicated_structure_test(self): data = apply_structure( { 'dictionary': { 1: "1", 2: "2" }, 'bool-list': [True, False, False], 'very-long-property-name': "My String Value" }, self.ComplicatedData()) self.assertEqual(data.dictionary, {1: "1", 2: "2"}) self.assertEqual(data.bool_list, [True, False, False]) self.assertEqual(data.very_long_property_name, "My String Value")
def apply_simple_invalid_structure_test(self): with self.assertRaises(DBusStructureError) as cm: apply_structure({'y': 10}, self.SimpleData()) self.assertEqual(str(cm.exception), "Field 'y' doesn't exist.")
def skip_members_test(self): structure = get_structure(self.SkipData()) self.assertEqual(structure, {'x': get_variant(Int, 0)}) data = apply_structure({'x': 10}, self.SkipData()) self.assertEqual(data.x, 10)