def test_get_source(self, proxy_getter, get_object_path): """Test the get_source function.""" payload_proxy = PAYLOADS.get_proxy("/my/payload") source_proxy_1 = PAYLOADS.get_proxy("/my/source/1") payload_proxy.Sources = [ "/my/source/1", "/my/source/2", "/my/source/3" ] self.assertEqual(get_source(payload_proxy), source_proxy_1) payload_proxy.Sources = ["/my/source/1"] self.assertEqual(get_source(payload_proxy), source_proxy_1) payload_proxy.Sources = [] self.assertRaises(ValueError, get_source, payload_proxy) payloads_proxy = PAYLOADS.get_proxy() payloads_proxy.CreateSource.return_value = "/my/source/4" source_proxy_4 = PAYLOADS.get_proxy("/my/source/4") get_object_path.return_value = "/my/source/4" payload_proxy.Sources = [] self.assertEqual(get_source(payload_proxy, SOURCE_TYPE_CDROM), source_proxy_4) payloads_proxy.CreateSource.assert_called_once_with(SOURCE_TYPE_CDROM) payload_proxy.SetSources.assert_called_once_with(["/my/source/4"])
def test_get_source(self, proxy_getter, get_object_path): """Test the get_source function.""" payload_proxy = PAYLOADS.get_proxy("/my/payload") source_proxy_1 = PAYLOADS.get_proxy("/my/source/1") payload_proxy.Sources = [ "/my/source/1", "/my/source/2", "/my/source/3" ] assert get_source(payload_proxy) == source_proxy_1 payload_proxy.Sources = ["/my/source/1"] assert get_source(payload_proxy) == source_proxy_1 payloads_proxy = PAYLOADS.get_proxy() payloads_proxy.CreateSource.return_value = "/my/source/4" source_proxy_4 = PAYLOADS.get_proxy("/my/source/4") get_object_path.return_value = "/my/source/4" payload_proxy.Sources = [] payload_proxy.DefaultSourceType = SOURCE_TYPE_CDROM assert get_source(payload_proxy) == source_proxy_4 payloads_proxy.CreateSource.assert_called_once_with(SOURCE_TYPE_CDROM) assert payload_proxy.Sources == ["/my/source/4"]
def set_source_test(self, proxy_getter, get_object_path): """Test the set_source function.""" payload_proxy = PAYLOADS.get_proxy("/my/payload") source_proxy = PAYLOADS.get_proxy("/my/source") get_object_path.return_value = "/my/source" set_source(payload_proxy, source_proxy) payload_proxy.SetSources.assert_called_once_with(["/my/source"])
def test_set_source(self, proxy_getter, get_object_path): """Test the set_source function.""" payload_proxy = PAYLOADS.get_proxy("/my/payload") source_proxy = PAYLOADS.get_proxy("/my/source") get_object_path.return_value = "/my/source" set_source(payload_proxy, source_proxy) assert payload_proxy.Sources == ["/my/source"]
def create_source(source_type): """Create a source. :param source_type: a source type :return: a DBus proxy of a source """ payloads_proxy = PAYLOADS.get_proxy() object_path = payloads_proxy.CreateSource(source_type) return PAYLOADS.get_proxy(object_path)
def _get_dbus_payload_type(): payloads_proxy = PAYLOADS.get_proxy() object_path = payloads_proxy.ActivePayload if not object_path: return None object_proxy = PAYLOADS.get_proxy(object_path) return object_proxy.Type
def create_source_test(self, proxy_getter): """Test the create_source function.""" payloads_proxy = PAYLOADS.get_proxy() payloads_proxy.CreateSource.return_value = "/my/source" source_proxy = PAYLOADS.get_proxy("/my/source") source_proxy.Type = SOURCE_TYPE_CDROM self.assertEqual(create_source(SOURCE_TYPE_CDROM), source_proxy) payloads_proxy.CreateSource.assert_called_once_with(SOURCE_TYPE_CDROM)
def tear_down_sources_test(self, proxy_getter): payload_proxy = PAYLOADS.get_proxy("/my/payload") payload_proxy.TearDownSourcesWithTask.return_value = "/my/task" task_proxy = PAYLOADS.get_proxy("/my/task") task_proxy.IsRunning = False tear_down_sources(payload_proxy) payload_proxy.TearDownSourcesWithTask.assert_called_once_with() task_proxy.Start.assert_called_once_with() task_proxy.Finish.assert_called_once_with()
def create_payload_test(self, proxy_getter): """Test the create_payload function.""" payloads_proxy = PAYLOADS.get_proxy() payloads_proxy.CreatePayload.return_value = "/my/path" payload_proxy = PAYLOADS.get_proxy("/my/path") payload_proxy.Type = PAYLOAD_TYPE_LIVE_OS self.assertEqual(create_payload(PAYLOAD_TYPE_LIVE_OS), payload_proxy) payloads_proxy.CreatePayload.assert_called_once_with(PAYLOAD_TYPE_LIVE_OS) payloads_proxy.ActivatePayload.assert_called_once_with("/my/path")
def _check_create_proxy(self, source_type, test_value): payloads_proxy = PAYLOADS.get_proxy() payloads_proxy.CreateSource.return_value = "my/source/1" source = SourceFactory.parse_repo_cmdline_string(test_value) source_proxy = source.create_proxy() payloads_proxy.CreateSource.assert_called_once_with(source_type) self.assertEqual(source_proxy, PAYLOADS.get_proxy("my/source/1")) return source_proxy
def get_payload_proxy(): """Get the DBus proxy of the active payload. :return: a DBus proxy """ payloads_proxy = PAYLOADS.get_proxy() object_path = payloads_proxy.ActivePayload if not object_path: raise ValueError("Active payload is not set.") return PAYLOADS.get_proxy(object_path)
def _get_live_os_image(): """Detect live os image on the system. FIXME: This is a temporary workaround. :return: a path to the image """ payloads_proxy = PAYLOADS.get_proxy() source_path = payloads_proxy.CreateSource(SOURCE_TYPE_LIVE_OS_IMAGE) source_proxy = PAYLOADS.get_proxy(source_path) return source_proxy.DetectLiveOSImage()
def create_payload(payload_type=PAYLOAD_TYPE_DNF, activate=True): """Create a payload module. :param payload_type: a payload type :param activate: True to activate the payload, otherwise False :return: a proxy of a payload module """ payloads_proxy = PAYLOADS.get_proxy() object_path = payloads_proxy.CreatePayload(payload_type) if activate: payloads_proxy.ActivatePayload(object_path) return PAYLOADS.get_proxy(object_path)
def test_revert_package_rules(proxy_getter, rule_data, ksdata_mock, storage_mock): rule_data.new_rule("package --add=firewalld --remove=telnet --add=iptables --add=vim") packages_data = PackagesSelectionData() packages_data.packages = ["vim"] dnf_payload_mock = PAYLOADS.get_proxy("/fake/payload/1") dnf_payload_mock.PackagesSelection = PackagesSelectionData.to_structure(packages_data) # run twice --> nothing should be different in the second run messages = rule_data.eval_rules(ksdata_mock, storage_mock) messages = rule_data.eval_rules(ksdata_mock, storage_mock) # one info message for each added/removed package assert len(messages) == 3 rule_data.revert_changes(ksdata_mock, storage_mock) # (only) added and excluded packages should have been removed from the # list assert dnf_payload_mock.PackagesSelection == \ PackagesSelectionData.to_structure(packages_data) # now do the same again # messages = rule_data.eval_rules(ksdata_mock, storage_mock) # one info message for each added/removed package assert len(messages) == 3 rule_data.revert_changes(ksdata_mock, storage_mock) # (only) added and excluded packages should have been removed from the # list assert dnf_payload_mock.PackagesSelection == \ PackagesSelectionData.to_structure(packages_data)
def test_evaluation_package_rules(proxy_getter, rule_data, ksdata_mock, storage_mock): rule_data.new_rule("package --add=firewalld --remove=telnet --add=vim") packages_data = PackagesSelectionData() packages_data.packages = ["vim"] dnf_payload_mock = PAYLOADS.get_proxy("/fake/payload/1") dnf_payload_mock.PackagesSelection = PackagesSelectionData.to_structure(packages_data) messages = rule_data.eval_rules(ksdata_mock, storage_mock) # one info message for each (really) added/removed package assert len(messages) == 2 assert all(message.type == common.MESSAGE_TYPE_INFO for message in messages) # all packages should appear in the messages not_seen = _quoted_keywords_not_seen_in_messages( {"firewalld", "telnet"}, messages, ) assert not not_seen packages_data = PackagesSelectionData() packages_data.packages = ["vim", "firewalld"] packages_data.excluded_packages = ["telnet"] assert dnf_payload_mock.PackagesSelection == \ PackagesSelectionData.to_structure(packages_data)
def __init__(self): """Initialize the payload.""" # A DBus proxy of the Payloads service. self._service_proxy = PAYLOADS.get_proxy() # A DBus proxy of the active payload. self._payload_proxy = None
def get_source(payload_proxy): """Get a source of the given payload. If the payload has one or more sources, return the first one. If the payload has no sources and the default source type is specified, create a default source. If the payload has no sources and the default source type is not specified, raise an exception. :param payload_proxy: a DBus proxy of a payload :return: a DBus proxy of a source :raise: ValueError if there is no source to return """ sources = payload_proxy.Sources if sources: # Return the first source in the list. We don't # really support multiple sources at this moment. return PAYLOADS.get_proxy(sources[0]) # Or create a new source of the specified type # and attach it to the given payload. source = create_source(payload_proxy.DefaultSourceType) set_source(payload_proxy, source) return source
def tear_down_sources(payload_proxy): """Tear down the sources of the given payload. :param payload_proxy: a DBus proxy of a payload """ task_path = payload_proxy.TearDownSourcesWithTask() task_proxy = PAYLOADS.get_proxy(task_path) sync_run_task(task_proxy)
def set_up_sources(payload_proxy): """Set up the sources of the given payload. :param payload_proxy: a DBus proxy of a payload """ task_path = payload_proxy.SetUpSourcesWithTask() task_proxy = PAYLOADS.get_proxy(task_path) sync_run_task(task_proxy)
def set_from_opts(self, opts): """Detect the Live OS image.""" # Create the image source. source_proxy = self.get_source_proxy() # Detect the image path. task_path = source_proxy.DetectImageWithTask() task_proxy = PAYLOADS.get_proxy(task_path) sync_run_task(task_proxy)
def _run_tasks(self, task_paths, progress_cb=None): """Run the given remote tasks of the Payload module.""" for task_path in task_paths: task_proxy = PAYLOADS.get_proxy(task_path) if progress_cb: task_proxy.ProgressChanged.connect(progress_cb) sync_run_task(task_proxy)
def get_payload_test(self, proxy_getter): """Test the get_payload function.""" payloads_proxy = PAYLOADS.get_proxy() payloads_proxy.ActivePayload = "/my/path1" payloads_proxy.CreatePayload.return_value = "/my/path2" payload_proxy_1 = PAYLOADS.get_proxy("/my/path1") payload_proxy_1.Type = PAYLOAD_TYPE_LIVE_OS payload_proxy_2 = PAYLOADS.get_proxy("/my/path2") payload_proxy_2.Type = PAYLOAD_TYPE_DNF # Get the active payload. self.assertEqual(get_payload(PAYLOAD_TYPE_LIVE_OS), payload_proxy_1) self.assertEqual(get_payload(PAYLOAD_TYPE_LIVE_OS), payload_proxy_1) payloads_proxy.ActivatePayload.assert_not_called() # Or create a new one. self.assertEqual(get_payload(PAYLOAD_TYPE_DNF), payload_proxy_2) payloads_proxy.ActivatePayload.assert_called_once_with("/my/path2")
def set_dbus_defaults(): boss = BOSS.get_proxy() boss.GetModules.return_value = [ KDUMP.service_name ] kdump = KDUMP.get_proxy() kdump.KdumpEnabled = True user_interface = BOSS.get_proxy(USER_INTERFACE) user_interface.PasswordPolicies = {} network = NETWORK.get_proxy() network.Connected.return_value = True firewall = NETWORK.get_proxy(FIREWALL) firewall.EnabledServices = [] firewall.DisabledServices = [] firewall.EnabledPorts = [] firewall.Trusts = [] device_tree = STORAGE.get_proxy(DEVICE_TREE) device_tree.GetDeviceMountOptions.return_value = "defaults" device_tree.GetMountPoints.return_value = {} bootloader = STORAGE.get_proxy(BOOTLOADER) bootloader.IsPasswordSet = False users = USERS.get_proxy() users.IsRootPasswordSet = True users.IsRootPasswordCrypted = False users.RootPassword = "******" payloads = PAYLOADS.get_proxy() payloads.ActivePayload = "/fake/payload/1" dnf_payload = PAYLOADS.get_proxy("/fake/payload/1") dnf_payload.Type = PAYLOAD_TYPE_DNF packages_data = PackagesSelectionData() dnf_payload.PackagesSelection = PackagesSelectionData.to_structure(packages_data)
def __init__(self, data): """Initialize Payload class :param data: This param is a kickstart.AnacondaKSHandler class. """ self.data = data # A DBus proxy of the Payloads service. self._service_proxy = PAYLOADS.get_proxy() # A DBus proxy of the active payload. self._payload_proxy = None
def get_payload(payload_type=PAYLOAD_TYPE_DNF): """Get a payload of the specified type. If there is no active payload of the specified type, we will create and activate a new payload. :return: a proxy of a payload module """ payloads_proxy = PAYLOADS.get_proxy() object_path = payloads_proxy.ActivePayload # Choose the active payload. if object_path: object_proxy = PAYLOADS.get_proxy(object_path) # Check the type of the active payload. if object_proxy.Type == payload_type: return object_proxy # Or create a new payload. return create_payload(payload_type)
def test_evaluation_package_rules_report_only(proxy_getter, rule_data, ksdata_mock, storage_mock): rule_data.new_rule("package --add=firewalld --remove=telnet --add=iptables") messages = rule_data.eval_rules(ksdata_mock, storage_mock, report_only=True) # one info message for each added/removed package assert len(messages) == 3 assert all(message.type == common.MESSAGE_TYPE_INFO for message in messages) not_seen = _quoted_keywords_not_seen_in_messages( {"firewalld", "telnet", "iptables"}, messages, ) assert not not_seen # report_only --> no packages should be added or excluded dnf_payload_mock = PAYLOADS.get_proxy("/fake/payload/1") packages_data = PackagesSelectionData() assert dnf_payload_mock.PackagesSelection == \ PackagesSelectionData.to_structure(packages_data)
def _create_payload_proxy(self): """Create a DBus proxy of the active payload.""" object_path = self.service_proxy.ActivePayload return PAYLOADS.get_proxy(object_path)