def setUp(self): """Set up the module.""" self.iscsi_module = ISCSIModule() self.iscsi_interface = ISCSIInterface(self.iscsi_module) self._portal = Portal() self._portal.ip_address = "10.43.136.67" self._portal.port = "3260" self._credentials = Credentials() self._credentials.username = "******" self._credentials.password = "******" self._credentials.reverse_username = "******" self._credentials.reverse_password = "******" self._node = Node() self._node.name = "iqn.2014-08.com.example:t1" self._node.address = "10.43.136.67" self._node.port = "3260" self._node.iface = "iface0" self._node.net_ifacename = "ens3" # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.iscsi_interface.PropertiesChanged.connect(self.callback)
def setUp(self): self.live_os_source_module = LiveOSSourceModule() self.live_os_source_interface = LiveOSSourceInterface( self.live_os_source_module) self.callback = PropertiesChangedCallback() self.live_os_source_interface.PropertiesChanged.connect(self.callback)
class LiveOSSourceInterfaceTestCase(unittest.TestCase): def setUp(self): self.module = LiveOSSourceModule() self.interface = LiveOSSourceInterface(self.module) self.callback = PropertiesChangedCallback() self.interface.PropertiesChanged.connect(self.callback) def type_test(self): """Test Live OS source has a correct type specified.""" self.assertEqual(SOURCE_TYPE_LIVE_OS_IMAGE, self.interface.Type) def image_path_empty_properties_test(self): """Test Live OS payload image path property when not set.""" self.assertEqual(self.interface.ImagePath, "") def image_path_properties_test(self): """Test Live OS payload image path property is correctly set.""" self.interface.SetImagePath("/my/supper/image/path") self.assertEqual(self.interface.ImagePath, "/my/supper/image/path") self.callback.assert_called_once_with( PAYLOAD_SOURCE_LIVE_OS.interface_name, {"ImagePath": "/my/supper/image/path"}, []) # TODO: Make detection method coverage better @patch("pyanaconda.modules.payloads.source.live_os.live_os.stat") @patch("pyanaconda.modules.payloads.source.live_os.live_os.os.stat") def detect_live_os_image_failed_block_device_test(self, os_stat_mock, stat_mock): """Test Live OS image detection failed block device check.""" # we have to patch this even thought that result is used in another mock # otherwise we will skip the whole sequence os_stat_mock.return_value = {stat_mock.ST_MODE: "whatever"} stat_mock.S_ISBLK = Mock() stat_mock.S_ISBLK.return_value = False self.assertEqual(self.interface.DetectLiveOSImage(), "") @patch("pyanaconda.modules.payloads.source.live_os.live_os.os.stat") def detect_live_os_image_failed_nothing_found_test(self, os_stat_mock): """Test Live OS image detection failed missing file.""" # we have to patch this even thought that result is used in another mock # otherwise we will skip the whole sequence os_stat_mock.side_effect = FileNotFoundError() self.assertEqual(self.interface.DetectLiveOSImage(), "") @patch("pyanaconda.modules.payloads.source.live_os.live_os.stat") @patch("pyanaconda.modules.payloads.source.live_os.live_os.os.stat") def detect_live_os_image_test(self, os_stat_mock, stat_mock): """Test Live OS image detection.""" # we have to patch this even thought that result is used in another mock # otherwise we will skip the whole sequence stat_mock.S_ISBLK = Mock(return_value=True) detected_image = self.interface.DetectLiveOSImage() stat_mock.S_ISBLK.assert_called_once() self.assertEqual(detected_image, "/dev/mapper/live-base")
def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.timezone_interface.PropertiesChanged.connect(self.callback)
def setUp(self): """Set up the network module.""" # Set up the network module. self.network_module = NetworkService() self.network_interface = NetworkInterface(self.network_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.network_interface.PropertiesChanged.connect(self.callback)
def setUp(self): """Set up the security module.""" # Set up the security module. self.security_module = SecurityService() self.security_interface = SecurityInterface(self.security_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.security_interface.PropertiesChanged.connect(self.callback)
def setUp(self): """Set up the user module.""" # Set up the users module. self.users_module = UsersService() self.users_interface = UsersInterface(self.users_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.users_interface.PropertiesChanged.connect(self.callback)
def setUp(self): """Set up the localization module.""" # Set up the localization module. self.localization_module = LocalizationService() self.localization_interface = LocalizationInterface(self.localization_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.localization_interface.PropertiesChanged.connect(self.callback)
def setUp(self): """Set up the subscription module.""" self.subscription_module = SubscriptionService() self.subscription_interface = SubscriptionInterface( self.subscription_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.subscription_interface.PropertiesChanged.connect(self.callback)
def setUp(self): self.live_os_module = LiveOSModule() self.live_os_interface = LiveOSInterface(self.live_os_module) self.shared_tests = PayloadSharedTest(self, payload=self.live_os_module, payload_intf=self.live_os_interface) self.callback = PropertiesChangedCallback() self.live_os_interface.PropertiesChanged.connect(self.callback)
def setUp(self): self.live_image_module = LiveImageModule() self.live_image_interface = LiveImageInterface(self.live_image_module) self.source_tests = SourceSharedTest( self, payload=self.live_image_module, payload_intf=self.live_image_interface) self.callback = PropertiesChangedCallback() self.live_image_interface.PropertiesChanged.connect(self.callback)
def setUp(self): self.cdrom_source_module = CdromSourceModule() self.cdrom_source_interface = CdromSourceInterface( self.cdrom_source_module) self.callback = PropertiesChangedCallback() self.cdrom_source_interface.PropertiesChanged.connect(self.callback)
def setUp(self): """Set up the module.""" self.firewall_module = FirewallModule() self.firewall_interface = FirewallInterface(self.firewall_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.firewall_interface.PropertiesChanged.connect(self.callback)
class PackagesInterfaceTestCase(unittest.TestCase): def setUp(self): self.packages_module = PackagesModule() self.packages_interface = PackagesInterface(self.packages_module) self.callback = PropertiesChangedCallback() self.packages_interface.PropertiesChanged.connect(self.callback) def core_group_enabled_properties_test(self): self.packages_interface.SetCoreGroupEnabled(True) self.assertEqual(self.packages_interface.CoreGroupEnabled, True) self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"CoreGroupEnabled": True}, []) def core_group_not_set_properties_test(self): self.assertEqual(self.packages_interface.CoreGroupEnabled, True) def default_environment_not_set_properties_test(self): self.assertEqual(self.packages_interface.DefaultEnvironment, False) def environment_properties_test(self): self.packages_interface.SetEnvironment("TestEnv") self.assertEqual(self.packages_interface.Environment, "TestEnv") self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"Environment": "TestEnv"}, []) def environment_not_set_properties_test(self): self.assertEqual(self.packages_interface.Environment, "") def groups_properties_test(self): self.packages_interface.SetGroups(["group1", "group2"]) self.assertEqual(self.packages_interface.Groups, ["group1", "group2"]) self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"Groups": ["group1", "group2"]}, []) def groups_not_set_properties_test(self): self.assertEqual(self.packages_interface.Groups, []) def packages_properties_test(self): self.packages_interface.SetPackages(["package1", "package2"]) self.assertEqual(self.packages_interface.Packages, ["package1", "package2"]) self.callback.assert_called_once_with( PAYLOAD_PACKAGES.interface_name, {"Packages": ["package1", "package2"]}, []) def packages_not_set_properties_test(self): self.assertEqual(self.packages_interface.Packages, []) def excluded_groups_properties_test(self): self.packages_interface.SetExcludedGroups(["group1", "group2"]) self.assertEqual(self.packages_interface.ExcludedGroups, ["group1", "group2"]) self.callback.assert_called_once_with( PAYLOAD_PACKAGES.interface_name, {"ExcludedGroups": ["group1", "group2"]}, []) def excluded_groups_not_set_properties_test(self): self.assertEqual(self.packages_interface.ExcludedGroups, []) def excluded_packages_properties_test(self): self.packages_interface.SetExcludedPackages(["package1", "package2"]) self.assertEqual(self.packages_interface.ExcludedPackages, ["package1", "package2"]) self.callback.assert_called_once_with( PAYLOAD_PACKAGES.interface_name, {"ExcludedPackages": ["package1", "package2"]}, []) def excluded_packages_not_set_properties_test(self): self.assertEqual(self.packages_interface.ExcludedPackages, []) def docs_excluded_properties_test(self): self.packages_interface.SetDocsExcluded(True) self.assertEqual(self.packages_interface.DocsExcluded, True) self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"DocsExcluded": True}, []) def docs_excluded_not_set_properties_test(self): self.assertEqual(self.packages_interface.DocsExcluded, False) def weakdeps_excluded_properties_test(self): self.packages_interface.SetWeakdepsExcluded(True) self.assertEqual(self.packages_interface.WeakdepsExcluded, True) self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"WeakdepsExcluded": True}, []) def weakdeps_excluded_not_set_properties_test(self): self.assertEqual(self.packages_interface.WeakdepsExcluded, False) def missing_ignored_properties_test(self): self.packages_interface.SetMissingIgnored(True) self.assertEqual(self.packages_interface.MissingIgnored, True) self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"MissingIgnored": True}, []) def missing_ignored_not_set_properties_test(self): self.assertEqual(self.packages_interface.MissingIgnored, False) def languages_properties_test(self): self.packages_interface.SetLanguages("en, es") self.assertEqual(self.packages_interface.Languages, "en, es") self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"Languages": "en, es"}, []) def languages_not_set_properties_test(self): self.assertEqual(self.packages_interface.Languages, LANGUAGES_DEFAULT) def languages_incorrect_value_properties_test(self): with self.assertRaises(InvalidValueError): self.packages_interface.SetLanguages("") def multilib_policy_properties_test(self): self.packages_interface.SetMultilibPolicy('all') self.assertEqual(self.packages_interface.MultilibPolicy, 'all') self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"MultilibPolicy": 'all'}, []) def multilib_policy_not_set_properties_test(self): self.assertEqual(self.packages_interface.MultilibPolicy, 'best') def timeout_properties_test(self): self.packages_interface.SetTimeout(60) self.assertEqual(self.packages_interface.Timeout, 60) self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"Timeout": 60}, []) def timeout_not_set_properties_test(self): self.assertEqual(self.packages_interface.Timeout, TIMEOUT_UNSET) def retries_properties_test(self): self.packages_interface.SetRetries(30) self.assertEqual(self.packages_interface.Retries, 30) self.callback.assert_called_once_with(PAYLOAD_PACKAGES.interface_name, {"Retries": 30}, []) def retries_not_set_properties_test(self): self.assertEqual(self.packages_interface.Retries, RETRIES_UNSET)
class ISCSIInterfaceTestCase(unittest.TestCase): """Test DBus interface of the iSCSI module.""" def setUp(self): """Set up the module.""" self.iscsi_module = ISCSIModule() self.iscsi_interface = ISCSIInterface(self.iscsi_module) self._portal = Portal() self._portal.ip_address = "10.43.136.67" self._portal.port = "3260" self._credentials = Credentials() self._credentials.username = "******" self._credentials.password = "******" self._credentials.reverse_username = "******" self._credentials.reverse_password = "******" self._node = Node() self._node.name = "iqn.2014-08.com.example:t1" self._node.address = "10.43.136.67" self._node.port = "3260" self._node.iface = "iface0" self._node.net_ifacename = "ens3" # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.iscsi_interface.PropertiesChanged.connect(self.callback) @patch("pyanaconda.modules.storage.iscsi.iscsi.iscsi", available=True) def is_supported_test(self, iscsi): self.assertEqual(self.iscsi_interface.IsSupported(), True) @patch('pyanaconda.modules.storage.iscsi.iscsi.iscsi') def initator_property_test(self, iscsi): """Test Initiator property.""" initiator_name = "iqn.1994-05.com.redhat:blabla" iscsi.initiator_set = False self.iscsi_interface.SetInitiator(initiator_name) iscsi.initiator = initiator_name self.assertEqual(self.iscsi_interface.Initiator, initiator_name) iscsi.initiator_set = True initiator_name2 = "iqn.1994-05.com.redhat:blablabla" self.iscsi_interface.SetInitiator(initiator_name2) self.callback.assert_called_once_with(ISCSI.interface_name, {'Initiator': initiator_name}, []) @patch('pyanaconda.modules.storage.iscsi.iscsi.iscsi') def can_set_initiator_test(self, iscsi): """Test CanSetInitiator method.""" self.assertIsInstance(self.iscsi_interface.CanSetInitiator(), bool) @patch('pyanaconda.modules.storage.iscsi.iscsi.iscsi') def get_interface_mode_test(self, iscsi): """Test GetInterfaceMode method.""" blivet_mode_values = ["none", "default", "bind"] for blivet_mode in blivet_mode_values + ["unexpected_value"]: iscsi.mode = blivet_mode _mode = IscsiInterfacesMode( self.iscsi_interface.GetInterfaceMode()) @patch('pyanaconda.modules.storage.iscsi.iscsi.iscsi') def is_node_from_ibft_test(self, iscsi): """Test IsNodeFromIbft method.""" iscsi.ibft_nodes = [] result = self.iscsi_interface.IsNodeFromIbft( Node.to_structure(self._node)) self.assertFalse(result) blivet_node = Mock() blivet_node.name = self._node.name blivet_node.address = self._node.address blivet_node.port = int(self._node.port) blivet_node.iface = self._node.iface iscsi.ibft_nodes = [blivet_node] result = self.iscsi_interface.IsNodeFromIbft( Node.to_structure(self._node)) self.assertTrue(result) @patch('pyanaconda.modules.storage.iscsi.iscsi.iscsi') def get_interface_test(self, iscsi): """Test GetInterface method.""" iscsi.ifaces = { "iface0": "ens3", "iface1": "ens7", } self.assertEqual(self.iscsi_interface.GetInterface("iface0"), "ens3") self.assertEqual(self.iscsi_interface.GetInterface("nonexisting"), "") @patch_dbus_publish_object def discover_with_task_test(self, publisher): """Test the discover task.""" interfaces_mode = "default" task_path = self.iscsi_interface.DiscoverWithTask( Portal.to_structure(self._portal), Credentials.to_structure(self._credentials), interfaces_mode) obj = check_task_creation(self, task_path, publisher, ISCSIDiscoverTask) self.assertIsInstance(obj, ISCSIDiscoverTaskInterface) self.assertEqual(obj.implementation._portal, self._portal) self.assertEqual(obj.implementation._credentials, self._credentials) self.assertEqual(obj.implementation._interfaces_mode, IscsiInterfacesMode.DEFAULT) @patch_dbus_publish_object def login_with_task_test(self, publisher): """Test the login task.""" task_path = self.iscsi_interface.LoginWithTask( Portal.to_structure(self._portal), Credentials.to_structure(self._credentials), Node.to_structure(self._node), ) obj = check_task_creation(self, task_path, publisher, ISCSILoginTask) self.assertEqual(obj.implementation._portal, self._portal) self.assertEqual(obj.implementation._credentials, self._credentials) self.assertEqual(obj.implementation._node, self._node) @patch('pyanaconda.modules.storage.iscsi.iscsi.iscsi') def write_configuration_test(self, iscsi): """Test WriteConfiguration.""" self.iscsi_interface.WriteConfiguration() iscsi.write.assert_called_once_with(conf.target.system_root, None) @patch('pyanaconda.modules.storage.iscsi.iscsi.iscsi') def get_dracut_arguments_test(self, iscsi): """Test the get_dracut_arguments function.""" blivet_node = Mock() blivet_node.name = self._node.name blivet_node.address = self._node.address blivet_node.port = int(self._node.port) blivet_node.iface = self._node.iface # The node is iBFT node iscsi.ibft_nodes = [blivet_node] self.assertEqual( self.iscsi_interface.GetDracutArguments( Node.to_structure(self._node)), ["rd.iscsi.firmware"]) # The node is not found iscsi.ibft_nodes = [] iscsi.get_node.return_value = None self.assertEqual( self.iscsi_interface.GetDracutArguments( Node.to_structure(self._node)), []) iscsi.ifaces = { "iface0": "ens3", "iface1": "ens7", } # The node is active iscsi.get_node.return_value = blivet_node blivet_node.username = "" blivet_node.r_username = "" blivet_node.password = "" blivet_node.r_password = "" iscsi.initiator = "iqn.1994-05.com.redhat:blablabla" self.assertEqual( self.iscsi_interface.GetDracutArguments( Node.to_structure(self._node)), [ "netroot=iscsi:@10.43.136.67::3260:iface0:ens3::iqn.2014-08.com.example:t1", "rd.iscsi.initiator=iqn.1994-05.com.redhat:blablabla" ]) # The node is active, with default interface iscsi.get_node.return_value = blivet_node blivet_node.iface = "default" iscsi.initiator = "iqn.1994-05.com.redhat:blablabla" self.assertEqual( self.iscsi_interface.GetDracutArguments( Node.to_structure(self._node)), [ "netroot=iscsi:@10.43.136.67::3260::iqn.2014-08.com.example:t1", "rd.iscsi.initiator=iqn.1994-05.com.redhat:blablabla" ]) # The node is active, with offload interface, and reverse chap iscsi.get_node.return_value = blivet_node blivet_node.username = "******" blivet_node.r_username = "******" blivet_node.password = "******" blivet_node.r_password = "******" blivet_node.iface = "qedi.a6:26:77:80:00:63" iscsi.initiator = "iqn.1994-05.com.redhat:blablabla" self.assertEqual( self.iscsi_interface.GetDracutArguments( Node.to_structure(self._node)), [ "netroot=iscsi:uname:passwd:r_uname:[email protected]::3260:qedi.a6:26:77:80:00:63:qedi.a6:26:77:80:00:63::iqn.2014-08.com.example:t1", "rd.iscsi.initiator=iqn.1994-05.com.redhat:blablabla" ])
def setUp(self): self.packages_module = PackagesModule() self.packages_interface = PackagesInterface(self.packages_module) self.callback = PropertiesChangedCallback() self.packages_interface.PropertiesChanged.connect(self.callback)
class PackagesInterfaceTestCase(unittest.TestCase): def setUp(self): self.packages_module = PackagesModule() self.packages_interface = PackagesInterface(self.packages_module) self.callback = PropertiesChangedCallback() self.packages_interface.PropertiesChanged.connect(self.callback) def _check_dbus_property(self, *args, **kwargs): check_dbus_property( self, PAYLOAD_PACKAGES, self.packages_interface, *args, **kwargs) def core_group_enabled_properties_test(self): self._check_dbus_property("CoreGroupEnabled", True) def core_group_not_set_properties_test(self): self.assertEqual(self.packages_interface.CoreGroupEnabled, True) def default_environment_not_set_properties_test(self): self.assertEqual(self.packages_interface.DefaultEnvironment, False) def environment_properties_test(self): self._check_dbus_property("Environment", "TestEnv") def environment_not_set_properties_test(self): self.assertEqual(self.packages_interface.Environment, "") def groups_properties_test(self): self._check_dbus_property("Groups", ["group1", "group2"]) def groups_not_set_properties_test(self): self.assertEqual(self.packages_interface.Groups, []) def packages_properties_test(self): self._check_dbus_property("Packages", ["package1", "package2"]) def packages_not_set_properties_test(self): self.assertEqual(self.packages_interface.Packages, []) def excluded_groups_properties_test(self): self._check_dbus_property("ExcludedGroups", ["group1", "group2"]) def excluded_groups_not_set_properties_test(self): self.assertEqual(self.packages_interface.ExcludedGroups, []) def excluded_packages_properties_test(self): self._check_dbus_property("ExcludedPackages", ["package1", "package2"]) def excluded_packages_not_set_properties_test(self): self.assertEqual(self.packages_interface.ExcludedPackages, []) def docs_excluded_properties_test(self): self._check_dbus_property("DocsExcluded", True) def docs_excluded_not_set_properties_test(self): self.assertEqual(self.packages_interface.DocsExcluded, False) def weakdeps_excluded_properties_test(self): self._check_dbus_property("WeakdepsExcluded", True) def weakdeps_excluded_not_set_properties_test(self): self.assertEqual(self.packages_interface.WeakdepsExcluded, False) def missing_ignored_properties_test(self): self._check_dbus_property("MissingIgnored", True) def missing_ignored_not_set_properties_test(self): self.assertEqual(self.packages_interface.MissingIgnored, False) def broken_ignored_properties_test(self): self._check_dbus_property("BrokenIgnored", True) def broken_ignored_not_set_properties_test(self): self.assertEqual(self.packages_interface.BrokenIgnored, False) @patch("pyanaconda.modules.payloads.packages.packages.conf") def broken_ignored_disabled_properties_test(self, conf): conf.payload = create_autospec(PayloadSection) conf.payload.enable_ignore_broken_packages = False with self.assertRaises(UnsupportedValueError): self.packages_interface.SetBrokenIgnored(True) self.assertEqual(self.packages_interface.BrokenIgnored, False) self.callback.assert_not_called() def languages_properties_test(self): self._check_dbus_property("Languages", "en, es") def languages_not_set_properties_test(self): self.assertEqual(self.packages_interface.Languages, LANGUAGES_DEFAULT) def languages_incorrect_value_properties_test(self): with self.assertRaises(InvalidValueError): self.packages_interface.SetLanguages("") self.callback.assert_not_called() def multilib_policy_properties_test(self): self._check_dbus_property("MultilibPolicy", 'all') def multilib_policy_not_set_properties_test(self): self.assertEqual(self.packages_interface.MultilibPolicy, 'best') def timeout_properties_test(self): self._check_dbus_property("Timeout", 60) def timeout_not_set_properties_test(self): self.assertEqual(self.packages_interface.Timeout, TIMEOUT_UNSET) def retries_properties_test(self): self._check_dbus_property("Retries", 30) def retries_not_set_properties_test(self): self.assertEqual(self.packages_interface.Retries, RETRIES_UNSET)
class ServicesInterfaceTestCase(unittest.TestCase): """Test DBus interface for the services module.""" def setUp(self): """Set up the services module.""" # Set up the services module. self.services_module = ServicesService() self.services_interface = ServicesInterface(self.services_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.services_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.services_interface.KickstartCommands, ["firstboot", "services", "skipx", "xconfig"]) self.assertEqual(self.services_interface.KickstartSections, []) self.assertEqual(self.services_interface.KickstartAddons, []) self.callback.assert_not_called() def enabled_services_property_test(self): """Test the enabled services property.""" self.services_interface.SetEnabledServices(["a", "b", "c"]) self.assertEqual(self.services_interface.EnabledServices, ["a", "b", "c"]) self.callback.assert_called_once_with( SERVICES.interface_name, {'EnabledServices': ["a", "b", "c"]}, []) def disabled_services_property_test(self): """Test the disabled services property.""" self.services_interface.SetDisabledServices(["a", "b", "c"]) self.assertEqual(self.services_interface.DisabledServices, ["a", "b", "c"]) self.callback.assert_called_once_with( SERVICES.interface_name, {'DisabledServices': ["a", "b", "c"]}, []) def default_target_property_default_graphical_test(self): """Test the default target property - default value.""" self.callback.assert_not_called() self.assertEqual(self.services_interface.DefaultTarget, "") def default_target_property_graphical_test(self): """Test the default target property - set graphical target.""" self.services_interface.SetDefaultTarget(GRAPHICAL_TARGET) self.assertEqual(self.services_interface.DefaultTarget, GRAPHICAL_TARGET) self.callback.assert_called_once_with( SERVICES.interface_name, {'DefaultTarget': GRAPHICAL_TARGET}, []) def default_target_property_text_test(self): """Test the default target property - set text target.""" self.services_interface.SetDefaultTarget(TEXT_ONLY_TARGET) self.assertEqual(self.services_interface.DefaultTarget, TEXT_ONLY_TARGET) self.callback.assert_called_once_with( SERVICES.interface_name, {'DefaultTarget': TEXT_ONLY_TARGET}, []) def default_desktop_property_test(self): """Test the default desktop property.""" self.services_interface.SetDefaultDesktop("KDE") self.assertEqual(self.services_interface.DefaultDesktop, "KDE") self.callback.assert_called_once_with(SERVICES.interface_name, {'DefaultDesktop': "KDE"}, []) def setup_on_boot_property_test(self): """Test the setup on boot property.""" self.services_interface.SetSetupOnBoot(SETUP_ON_BOOT_DISABLED) self.assertEqual(self.services_interface.SetupOnBoot, SETUP_ON_BOOT_DISABLED) self.callback.assert_called_once_with( SERVICES.interface_name, {'SetupOnBoot': SETUP_ON_BOOT_DISABLED}, []) def post_install_tools_disabled_test(self): """Test the post-install-tools-enabled property.""" # should not be marked as disabled by default self.assertEqual(self.services_interface.PostInstallToolsEnabled, True) # mark as disabled self.services_interface.SetPostInstallToolsEnabled(False) self.assertEqual(self.services_interface.PostInstallToolsEnabled, False) self.callback.assert_called_once_with( SERVICES.interface_name, {'PostInstallToolsEnabled': False}, []) # mark as not disabled again self.services_interface.SetPostInstallToolsEnabled(True) self.assertEqual(self.services_interface.PostInstallToolsEnabled, True) self.callback.assert_called_with(SERVICES.interface_name, {'PostInstallToolsEnabled': True}, []) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.services_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) self.assertEqual(self.services_interface.SetupOnBoot, SETUP_ON_BOOT_DEFAULT) self.assertEqual(self.services_interface.PostInstallToolsEnabled, True) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) self.assertEqual(self.services_interface.SetupOnBoot, SETUP_ON_BOOT_DEFAULT) self.assertEqual(self.services_interface.PostInstallToolsEnabled, True) def services_kickstart_test(self): """Test the services command.""" ks_in = """ services --disabled=a,b,c --enabled=d,e,f """ ks_out = """ # System services services --disabled="a,b,c" --enabled="d,e,f" """ self._test_kickstart(ks_in, ks_out) def skipx_kickstart_test(self): """Test the skipx command.""" ks_in = """ skipx """ ks_out = """ # Do not configure the X Window System skipx """ self._test_kickstart(ks_in, ks_out) def xconfig_kickstart_test(self): """Test the xconfig command.""" ks_in = """ xconfig --defaultdesktop GNOME --startxonboot """ ks_out = """ # X Window System configuration information xconfig --defaultdesktop=GNOME --startxonboot """ self._test_kickstart(ks_in, ks_out) def firstboot_disabled_kickstart_test(self): """Test the firstboot command - disabled.""" ks_in = """ firstboot --disable """ ks_out = """ firstboot --disable """ self._test_kickstart(ks_in, ks_out) self.assertEqual(self.services_interface.SetupOnBoot, SETUP_ON_BOOT_DISABLED) self.assertEqual(self.services_interface.PostInstallToolsEnabled, False) def firstboot_enabled_kickstart_test(self): """Test the firstboot command - enabled.""" ks_in = """ firstboot --enable """ ks_out = """ # Run the Setup Agent on first boot firstboot --enable """ self._test_kickstart(ks_in, ks_out) self.assertEqual(self.services_interface.SetupOnBoot, SETUP_ON_BOOT_ENABLED) self.assertEqual(self.services_interface.PostInstallToolsEnabled, True) def firstboot_reconfig_kickstart_test(self): """Test the firstboot command - reconfig.""" ks_in = """ firstboot --reconfig """ ks_out = """ # Run the Setup Agent on first boot firstboot --reconfig """ self._test_kickstart(ks_in, ks_out) self.assertEqual(self.services_interface.SetupOnBoot, SETUP_ON_BOOT_RECONFIG) self.assertEqual(self.services_interface.PostInstallToolsEnabled, True)
class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.timezone_interface.PropertiesChanged.connect(self.callback) def _check_dbus_property(self, *args, **kwargs): check_dbus_property( self, TIMEZONE, self.timezone_interface, *args, **kwargs ) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone", "timesource"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def timezone_property_test(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with( TIMEZONE.interface_name, {'Timezone': 'Europe/Prague'}, []) def utc_property_test(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'IsUTC': True}, []) def ntp_property_test(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'NTPEnabled': False}, []) def time_sources_property_test(self): """Test the TimeSources property.""" server = { "type": get_variant(Str, TIME_SOURCE_SERVER), "hostname": get_variant(Str, "ntp.cesnet.cz"), "options": get_variant(List[Str], ["iburst"]), } pool = { "type": get_variant(Str, TIME_SOURCE_POOL), "hostname": get_variant(Str, "0.fedora.pool.ntp.org"), "options": get_variant(List[Str], []), } self._check_dbus_property( "TimeSources", [server, pool] ) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.timezone_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ # System timezone timezone America/New_York """ self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_test(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart2_test(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ timesource --ntp-disable # System timezone timezone Europe/Prague --utc """ self._test_kickstart(ks_in, ks_out) def kickstart3_test(self): """Test the timezone command with ntp servers.""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart_timesource_ntp_disabled_test(self): """Test the timesource command with ntp disabled.""" ks_in = """ timesource --ntp-disable """ ks_out = """ timesource --ntp-disable """ self._test_kickstart(ks_in, ks_out) def kickstart_timesource_ntp_server_test(self): """Test the timesource command with ntp servers.""" ks_in = """ timesource --ntp-server ntp.cesnet.cz """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) def kickstart_timesource_ntp_pool_test(self): """Test the timesource command with ntp pools.""" ks_in = """ timesource --ntp-pool ntp.cesnet.cz """ ks_out = """ timesource --ntp-pool=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) def kickstart_timesource_nts_test(self): """Test the timesource command with the nts option.""" ks_in = """ timesource --ntp-pool ntp.cesnet.cz --nts """ ks_out = """ timesource --ntp-pool=ntp.cesnet.cz --nts """ self._test_kickstart(ks_in, ks_out) def kickstart_timesource_all_test(self): """Test the timesource commands.""" ks_in = """ timesource --ntp-server ntp.cesnet.cz timesource --ntp-pool 0.fedora.pool.ntp.org """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz timesource --ntp-pool=0.fedora.pool.ntp.org """ self._test_kickstart(ks_in, ks_out) def kickstart_timezone_timesource_test(self): """Test the combination of timezone and timesource commands.""" ks_in = """ timezone --ntpservers ntp.cesnet.cz,0.fedora.pool.ntp.org Europe/Prague timesource --ntp-server ntp.cesnet.cz --nts timesource --ntp-pool 0.fedora.pool.ntp.org """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz timesource --ntp-server=0.fedora.pool.ntp.org timesource --ntp-server=ntp.cesnet.cz --nts timesource --ntp-pool=0.fedora.pool.ntp.org # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test install tasks - module in default state.""" task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "America/New_York") self.assertEqual(obj.implementation._is_utc, False) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, True) self.assertEqual(obj.implementation._ntp_servers, []) @patch_dbus_publish_object def install_with_tasks_configured_test(self, publisher): """Test install tasks - module in configured state.""" self.timezone_interface.SetIsUTC(True) self.timezone_interface.SetTimezone("Asia/Tokyo") self.timezone_interface.SetNTPEnabled(False) # --nontp and --ntpservers are mutually exclusive in kicstart but # there is no such enforcement in the module so for testing this is ok server = TimeSourceData() server.type = TIME_SOURCE_SERVER server.hostname = "clock1.example.com" server.options = ["iburst"] pool = TimeSourceData() pool.type = TIME_SOURCE_POOL pool.hostname = "clock2.example.com" self.timezone_interface.SetTimeSources( TimeSourceData.to_structure_list([server, pool]) ) task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "Asia/Tokyo") self.assertEqual(obj.implementation._is_utc, True) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, False) self.assertEqual(len(obj.implementation._ntp_servers), 2) self.assertTrue(compare_data(obj.implementation._ntp_servers[0], server)) self.assertTrue(compare_data(obj.implementation._ntp_servers[1], pool)) @patch_dbus_publish_object def configure_ntp_service_enablement_default_test(self, publisher): """Test ntp service enablement with default module state.""" ntp_excluded = True task_path = self.timezone_interface.ConfigureNTPServiceEnablementWithTask(ntp_excluded) obj = check_task_creation(self, task_path, publisher, ConfigureNTPServiceEnablementTask) self.assertEqual(obj.implementation._ntp_enabled, True) self.assertEqual(obj.implementation._ntp_excluded, ntp_excluded) @patch_dbus_publish_object def configure_ntp_service_enablement_configured_test(self, publisher): """Test ntp service enablement with configured module state.""" ntp_excluded = False self.timezone_interface.SetNTPEnabled(False) task_path = self.timezone_interface.ConfigureNTPServiceEnablementWithTask(ntp_excluded) obj = check_task_creation(self, task_path, publisher, ConfigureNTPServiceEnablementTask) self.assertEqual(obj.implementation._ntp_enabled, False) self.assertEqual(obj.implementation._ntp_excluded, ntp_excluded) def deprecated_warnings_test(self): response = self.timezone_interface.ReadKickstart("timezone --isUtc Europe/Bratislava") report = KickstartReport.from_structure(response) warning = "The option --isUtc will be deprecated in future releases. " \ "Please modify your kickstart file to replace this option with " \ "its preferred alias --utc." self.assertEqual(len(report.warning_messages), 1) self.assertEqual(report.warning_messages[0].message, warning)
class LiveImageInterfaceTestCase(unittest.TestCase): def setUp(self): self.live_image_module = LiveImageModule() self.live_image_interface = LiveImageInterface(self.live_image_module) self.source_tests = SourceSharedTest( self, payload=self.live_image_module, payload_intf=self.live_image_interface) self.callback = PropertiesChangedCallback() self.live_image_interface.PropertiesChanged.connect(self.callback) # TODO: Add set_source and supported_sources like in Live OS payload when source is available def sources_empty_test(self): """Test sources Live Image API for emptiness.""" self.source_tests.check_empty_sources() def default_url_test(self): self.assertEqual(self.live_image_interface.Url, "") def url_properties_test(self): self.live_image_interface.SetUrl("http://OUCH!") self.assertEqual(self.live_image_interface.Url, "http://OUCH!") self.callback.assert_called_once_with( PAYLOAD_LIVE_IMAGE.interface_name, {"Url": "http://OUCH!"}, []) def default_proxy_test(self): self.assertEqual(self.live_image_interface.Proxy, "") def proxy_properties_test(self): self.live_image_interface.SetProxy("http://YAYKS!") self.assertEqual(self.live_image_interface.Proxy, "http://YAYKS!") self.callback.assert_called_once_with( PAYLOAD_LIVE_IMAGE.interface_name, {"Proxy": "http://YAYKS!"}, []) def default_checksum_test(self): self.assertEqual(self.live_image_interface.Checksum, "") def checksum_properties_test(self): self.live_image_interface.SetChecksum("ABC1234") self.assertEqual(self.live_image_interface.Checksum, "ABC1234") self.callback.assert_called_once_with( PAYLOAD_LIVE_IMAGE.interface_name, {"Checksum": "ABC1234"}, []) def default_verifyssl_test(self): self.assertTrue(self.live_image_interface.VerifySSL) def verifyssl_properties_test(self): self.live_image_interface.SetVerifySSL(True) self.assertEqual(self.live_image_interface.VerifySSL, True) self.callback.assert_called_once_with( PAYLOAD_LIVE_IMAGE.interface_name, {"VerifySSL": True}, []) def default_space_required_test(self): """Test Live Image RequiredSpace property. # TODO: Add a real test for required space property """ self.assertEqual(self.live_image_interface.RequiredSpace, 1024 * 1024 * 1024) @patch( "pyanaconda.modules.payloads.payload.live_image.live_image.get_kernel_version_list" ) def empty_kernel_version_list_test(self, get_kernel_version_list): """Test Live Image empty get kernel version list.""" self.assertEqual(self.live_image_interface.GetKernelVersionList(), []) get_kernel_version_list.return_value = [] kernel_list_callback = Mock() # pylint: disable=no-member self.live_image_interface.KernelVersionListChanged.connect( kernel_list_callback) self.live_image_interface.UpdateKernelVersionList() get_kernel_version_list.assert_called_once_with(INSTALL_TREE) self.assertEqual(self.live_image_interface.GetKernelVersionList(), []) kernel_list_callback.assert_called_once_with([]) @patch( "pyanaconda.modules.payloads.payload.live_image.live_image.get_kernel_version_list" ) def kernel_version_list_test(self, get_kernel_version_list): """Test Live Image get kernel version list.""" kernel_list = [ "kernel-abc", "magic-kernel.fc3000.x86_64", "sad-kernel" ] get_kernel_version_list.return_value = kernel_list kernel_list_callback = Mock() # pylint: disable=no-member self.live_image_interface.KernelVersionListChanged.connect( kernel_list_callback) self.live_image_interface.UpdateKernelVersionList() get_kernel_version_list.assert_called_once_with(INSTALL_TREE) self.assertListEqual(self.live_image_interface.GetKernelVersionList(), kernel_list) kernel_list_callback.assert_called_once_with(kernel_list) @patch_dbus_publish_object def check_installation_source_task_test(self, publisher): """Test Live Image is able to create a check installation source task.""" task_path = self.live_image_interface.SetupWithTask() check_task_creation(self, task_path, publisher, CheckInstallationSourceImageTask) @patch_dbus_publish_object def prepare_system_for_installation_task_test(self, publisher): """Test Live Image is able to create a prepare installation task.""" task_path = self.live_image_interface.PreInstallWithTasks() check_task_creation_list(self, task_path, publisher, [SetupInstallationSourceImageTask]) @patch( "pyanaconda.modules.payloads.payload.live_image.live_image.url_target_is_tarfile", lambda x: True) @patch_dbus_publish_object def install_with_task_from_tar_test(self, publisher): """Test Live Image install with tasks from tarfile.""" task_path = self.live_image_interface.InstallWithTasks() check_task_creation_list(self, task_path, publisher, [InstallFromTarTask]) @patch( "pyanaconda.modules.payloads.payload.live_image.live_image.url_target_is_tarfile", lambda x: False) @patch_dbus_publish_object def install_with_task_from_image_test(self, publisher): """Test Live Image install with tasks from image.""" task_path = self.live_image_interface.InstallWithTasks() check_task_creation_list(self, task_path, publisher, [InstallFromImageTask]) @patch_dbus_publish_object def post_install_with_tasks_test(self, publisher): """Test Live Image post installation configuration task.""" task_classes = [UpdateBLSConfigurationTask, CopyDriverDisksFilesTask] task_paths = self.live_image_interface.PostInstallWithTasks() # Check the number of installation tasks. task_number = len(task_classes) self.assertEqual(task_number, len(task_paths)) self.assertEqual(task_number, publisher.call_count) # Check the tasks. for i in range(task_number): object_path, obj = publisher.call_args_list[i][0] self.assertEqual(object_path, task_paths[i]) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, task_classes[i]) @patch_dbus_publish_object def teardown_with_task_test(self, publisher): """Test Live Image teardown task creation.""" task_path = self.live_image_interface.TeardownWithTask() check_task_creation(self, task_path, publisher, TeardownInstallationSourceImageTask)
class NetworkInterfaceTestCase(unittest.TestCase): """Test DBus interface for the Network module.""" def setUp(self): """Set up the network module.""" # Set up the network module. self.network_module = NetworkService() self.network_interface = NetworkInterface(self.network_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.network_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.network_interface.KickstartCommands, ["network", "firewall"]) self.assertEqual(self.network_interface.KickstartSections, []) self.assertEqual(self.network_interface.KickstartAddons, []) def _test_dbus_property(self, *args, **kwargs): check_dbus_property(self, NETWORK, self.network_interface, *args, **kwargs) @patch("pyanaconda.modules.common.base.base.setlocale") @patch("pyanaconda.modules.common.base.base.os") def set_locale_test(self, mocked_os, setlocale): """Test setting locale of the module.""" from locale import LC_ALL import pyanaconda.core.util locale = "en_US.UTF-8" mocked_os.environ = {} self.network_interface.SetLocale(locale) self.assertEqual(mocked_os.environ["LANG"], locale) setlocale.assert_called_once_with(LC_ALL, locale) self.assertEqual(pyanaconda.core.util._child_env['LANG'], locale) def hostname_property_test(self): """Test the hostname property.""" self._test_dbus_property( "Hostname", "dot.dot", ) def get_current_hostname_test(self): """Test getting current hostname does not fail.""" self.network_interface.GetCurrentHostname() def connected_test(self): """Test getting connectivity status does not fail.""" connected = self.network_interface.Connected self.assertIn(connected, (True, False)) def connecting_test(self): """Test checking connecting status does not fail.""" self.network_interface.IsConnecting() def mocked_client_connectivity_test(self): """Test connectivity properties with mocked NMClient.""" nm_client = MockedNMClient() nm_client._connect_state_changed(self.network_module._nm_state_changed) self.network_module.nm_client = nm_client nm_client._set_state(NM.State.CONNECTED_LOCAL) self.assertTrue(self.network_interface.Connected) nm_client._set_state(NM.State.DISCONNECTED) self.assertFalse(self.network_interface.Connected) self.callback.assert_called_with(NETWORK.interface_name, {'Connected': False}, []) self.assertFalse(self.network_interface.IsConnecting()) nm_client._set_state(NM.State.CONNECTED_SITE) self.assertTrue(self.network_interface.Connected) self.callback.assert_called_with(NETWORK.interface_name, {'Connected': True}, []) self.assertFalse(self.network_interface.IsConnecting()) nm_client._set_state(NM.State.CONNECTED_GLOBAL) self.assertTrue(self.network_interface.Connected) self.callback.assert_called_with(NETWORK.interface_name, {'Connected': True}, []) self.assertFalse(self.network_interface.IsConnecting()) nm_client._set_state(NM.State.CONNECTING) self.assertFalse(self.network_interface.Connected) self.callback.assert_called_with(NETWORK.interface_name, {'Connected': False}, []) self.assertTrue(self.network_interface.IsConnecting()) nm_client._set_state(NM.State.CONNECTED_LOCAL) self.assertTrue(self.network_interface.Connected) self.callback.assert_called_with(NETWORK.interface_name, {'Connected': True}, []) self.assertFalse(self.network_interface.IsConnecting()) def nm_availability_test(self): self.network_module.nm_client = None self.assertTrue(self.network_interface.Connected) self.assertFalse(self.network_interface.IsConnecting()) def create_device_configurations_test(self): """Test creating device configurations does not fail.""" self.network_interface.CreateDeviceConfigurations() def get_device_configurations_test(self): """Test GetDeviceConfigurations.""" self.assertListEqual(self.network_interface.GetDeviceConfigurations(), []) def network_device_configuration_changed_test(self): """Test NetworkDeviceConfigurationChanged.""" self.network_interface.NetworkDeviceConfigurationChanged() def get_dracut_arguments_test(self): """Test GetDracutArguments.""" self.assertListEqual( self.network_interface.GetDracutArguments("ens3", "10.10.10.10", "", False), []) def log_configuration_state_test(self): """Test LogConfigurationState.""" self.network_interface.LogConfigurationState("message") @patch_dbus_publish_object @patch('pyanaconda.modules.network.network.devices_ignore_ipv6', return_value=True) def install_network_with_task_test(self, devices_ignore_ipv6, publisher): """Test InstallNetworkWithTask.""" self.network_module._disable_ipv6 = True self.network_module.nm_client = Mock() self.__mock_nm_client_devices([ ("ens3", "33:33:33:33:33:33", "33:33:33:33:33:33", NM.DeviceType.ETHERNET), ("ens4", "44:44:44:44:44:44", "44:44:44:44:44:44", NM.DeviceType.ETHERNET), ("ens5", "55:55:55:55:55:55", "55:55:55:55:55:55", NM.DeviceType.ETHERNET) ]) task_path = self.network_interface.InstallNetworkWithTask(False) obj = check_task_creation(self, task_path, publisher, NetworkInstallationTask) self.assertEqual(obj.implementation._disable_ipv6, True) self.assertEqual(obj.implementation._overwrite, False) self.assertEqual(obj.implementation._network_ifaces, ["ens3", "ens4", "ens5"]) self.network_module.log_task_result = Mock() obj.implementation.succeeded_signal.emit() self.network_module.log_task_result.assert_called_once() @patch_dbus_publish_object def configure_hostname_with_task_test(self, publisher): """Test ConfigureHostnameWithTask.""" self.network_module._hostname = "my_hostname" task_path = self.network_interface.ConfigureHostnameWithTask(False) obj = check_task_creation(self, task_path, publisher, HostnameConfigurationTask) self.assertEqual(obj.implementation._overwrite, False) self.assertEqual(obj.implementation._hostname, "my_hostname") @patch_dbus_publish_object @patch('pyanaconda.modules.network.installation.update_connection_values') @patch('pyanaconda.modules.network.installation.find_ifcfg_uuid_of_device') def configure_activation_on_boot_with_task_test(self, find_ifcfg_uuid_of_device, update_connection_values, publisher): """Test ConfigureActivationOnBootWithTask.""" self.network_module.nm_client = Mock() self.network_module._should_apply_onboot_policy = Mock( return_value=True) self.network_module._has_any_onboot_yes_device = Mock( return_value=False) self.network_module._get_onboot_ifaces_by_policy = Mock( return_value=["ens4"]) task_path = self.network_interface.ConfigureActivationOnBootWithTask( ["ens3"], ) obj = check_task_creation(self, task_path, publisher, ConfigureActivationOnBootTask) self.assertEqual(set(obj.implementation._onboot_ifaces), set(["ens3", "ens4"])) self.network_module.log_task_result = Mock() obj.implementation.succeeded_signal.emit() self.network_module.log_task_result.assert_called_once() def _mock_supported_devices(self, devices_attributes): ret_val = [] for dev_name, dev_hwaddr, dev_type in devices_attributes: dev = Mock() dev.device_name = dev_name dev.device_hwaddress = dev_hwaddr dev.device_type = dev_type ret_val.append(dev) self.network_module.get_supported_devices = Mock(return_value=ret_val) @patch_dbus_publish_object def consolidate_initramfs_connections_with_task_test(self, publisher): """Test ConsolidateInitramfsConnectionsWithTask.""" task_path = self.network_interface.ConsolidateInitramfsConnectionsWithTask( ) obj = check_task_creation(self, task_path, publisher, ConsolidateInitramfsConnectionsTask) self.network_module.log_task_result = Mock() obj.implementation.succeeded_signal.emit() self.network_module.log_task_result.assert_called_once() @patch_dbus_publish_object def apply_kickstart_with_task_test(self, publisher): """Test ApplyKickstartWithTask.""" self._mock_supported_devices([("ens3", "", 0)]) task_path = self.network_interface.ApplyKickstartWithTask() obj = check_task_creation(self, task_path, publisher, ApplyKickstartTask) self.network_module.log_task_result = Mock() obj.implementation.succeeded_signal.emit() self.network_module.log_task_result.assert_called_once() @patch_dbus_publish_object def set_real_onboot_values_from_kickstart_with_task_test(self, publisher): """Test SetRealOnbootValuesFromKickstartWithTask.""" self._mock_supported_devices([("ens3", "", 0)]) task_path = self.network_interface.SetRealOnbootValuesFromKickstartWithTask( ) obj = check_task_creation(self, task_path, publisher, SetRealOnbootValuesFromKickstartTask) self.network_module.log_task_result = Mock() obj.implementation.succeeded_signal.emit() self.network_module.log_task_result.assert_called_once() @patch_dbus_publish_object def dump_missing_ifcfg_files_with_task_test(self, publisher): """Test DumpMissingIfcfgFilesWithTask.""" task_path = self.network_interface.DumpMissingIfcfgFilesWithTask() obj = check_task_creation(self, task_path, publisher, DumpMissingIfcfgFilesTask) self.network_module.log_task_result = Mock() obj.implementation.succeeded_signal.emit() self.network_module.log_task_result.assert_called_once() def __mock_nm_client_devices(self, device_specs): """Mock NM Client devices obtained by get_devices() method. :param device_specs: list of specifications of devices which are tuples (DEVICE_NAME, PERMANENT_HWADDRESS, HWADDRESS, DEVICE_TYPE) None value of PERMANENT_HWADDRESS means raising Attribute exception :type device_specs: list(tuple(str, str, str, int)) """ ret_val = [] for name, perm_hw, hw, dtype in device_specs: dev = Mock() dev.get_iface.return_value = name dev.get_device_type.return_value = dtype dev.get_hw_address.return_value = hw if perm_hw: dev.get_permanent_hw_address.return_value = perm_hw else: dev.get_permanent_hw_address = Mock(side_effect=AttributeError( 'mocking no permanent hw address')) ret_val.append(dev) self.network_module.nm_client.get_devices.return_value = ret_val def get_supported_devices_test(self): """Test GetSupportedDevices.""" # No NM available self.network_module.nm_client = None self.assertEqual(self.network_interface.GetSupportedDevices(), []) # Mocked NM self.network_module.nm_client = Mock() self.__mock_nm_client_devices([ ("ens3", "33:33:33:33:33:33", "33:33:33:33:33:33", NM.DeviceType.ETHERNET), ("ens4", "44:44:44:44:44:44", "44:44:44:44:44:44", NM.DeviceType.ETHERNET), # Permanent address is preferred ("ens5", "55:55:55:55:55:55", "FF:FF:FF:FF:FF:FF", NM.DeviceType.ETHERNET), # Virtual devices don't have permanent hw address ("team0", None, "33:33:33:33:33:33", NM.DeviceType.TEAM) ]) devs_infos = self.network_interface.GetSupportedDevices() self.assertDictEqual( devs_infos[0], { 'device-name': get_variant(Str, "ens3"), 'hw-address': get_variant(Str, "33:33:33:33:33:33"), 'device-type': get_variant(Int, NM.DeviceType.ETHERNET) }) self.assertDictEqual( devs_infos[1], { 'device-name': get_variant(Str, "ens4"), 'hw-address': get_variant(Str, "44:44:44:44:44:44"), 'device-type': get_variant(Int, NM.DeviceType.ETHERNET) }) self.assertDictEqual( devs_infos[2], { 'device-name': get_variant(Str, "ens5"), 'hw-address': get_variant(Str, "55:55:55:55:55:55"), 'device-type': get_variant(Int, NM.DeviceType.ETHERNET) }) self.assertDictEqual( devs_infos[3], { 'device-name': get_variant(Str, "team0"), 'hw-address': get_variant(Str, "33:33:33:33:33:33"), 'device-type': get_variant(Int, NM.DeviceType.TEAM) }) def _mock_nm_active_connections(self, connection_specs): active_connections = [] for activated, ifaces in connection_specs: con = Mock() if activated: con.get_state.return_value = NM.ActiveConnectionState.ACTIVATED devs = [] for iface in ifaces: dev = Mock() dev.get_ip_iface.return_value = iface dev.get_iface.return_value = iface devs.append(dev) con.get_devices.return_value = devs active_connections.append(con) self.network_module.nm_client.get_active_connections.return_value = active_connections def get_activated_interfaces_test(self): """Test GetActivatedInterfaces.""" # No NM available self.network_module.nm_client = None self.assertEqual(self.network_interface.GetActivatedInterfaces(), []) # Mocked NM self.network_module.nm_client = Mock() self._mock_nm_active_connections([ (True, ["ens3"]), # Slave of bond0 (True, ["ens5"]), # Slave of bond0 (True, ["ens7"]), (True, ["bond0"]), (False, ["ens11"]), # Not sure if/when this can happen, but we have been supporting it (True, ["devA", "devB"]), (True, []) ]) self.assertListEqual(self.network_interface.GetActivatedInterfaces(), ["ens3", "ens5", "ens7", "bond0", "devA", "devB"]) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.network_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = """ # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def network_kickstart_test(self): """Test the network command. In case of kickstart-only network configuration the original commands are preserved instead of generating the commands from ifcfg files which happens if there has been any non-kickstart (UI) configuration. """ ks_in = """ network --device ens7 --bootproto static --ip 192.168.124.200 --netmask 255.255.255.0 --gateway 192.168.124.255 --nameserver 10.34.39.2 --activate --onboot=no --hostname=dot.dot """ ks_out = """ # Network information network --bootproto=static --device=ens7 --gateway=192.168.124.255 --hostname=dot.dot --ip=192.168.124.200 --nameserver=10.34.39.2 --netmask=255.255.255.0 --onboot=off --activate """ self._test_kickstart(ks_in, ks_out) def kickstart_firewall_basic_test(self): """Test basic firewall command usage.""" ks_in = "firewall --enable --port=imap:tcp,1234:udp,47 --trust=eth0,eth1 --service=ptp,syslog,ssh --remove-service=tftp,ssh" ks_out = """ # Firewall configuration firewall --enabled --port=imap:tcp,1234:udp,47:tcp --trust=eth0,eth1 --service=ptp,syslog,ssh --remove-service=tftp,ssh # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def kickstart_firewall_disable_test(self): """Test firewall --disabled.""" ks_in = "firewall --disabled" ks_out = """ # Firewall configuration firewall --disabled # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def kickstart_firewall_disable_with_options_test(self): """Test firewall --disabled with options.""" # apparently Pykickstart dumps any additional options if --disabled is used ks_in = "firewall --disable --port=imap:tcp,1234:udp,47 --trust=eth0,eth1 --service=ptp,syslog,ssh --remove-service=tftp,ssh" ks_out = """ # Firewall configuration firewall --disabled # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def kickstart_firewall_use_system_defaults_test(self): """Test firewall --use-system-defaults.""" ks_in = "firewall --use-system-defaults" ks_out = """ # Firewall configuration firewall --use-system-defaults # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def kickstart_firewall_use_system_defaults_with_options_test(self): """Test firewall --use-system-defaults.""" # looks like --use-system-defaults also eats any additional options ks_in = "firewall --use-system-defaults --port=imap:tcp,1234:udp,47 --trust=eth0,eth1 --service=ptp,syslog,ssh --remove-service=tftp,ssh" ks_out = """ # Firewall configuration firewall --use-system-defaults # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def kickstart_firewall_service_options_test(self): """Test firewall with individual service options. The firewall command supports enabling some well known services, such as ssh or smtp, via dedicated options. The services should then end up in the --service list in the output. """ ks_in = "firewall --ftp --http --smtp --ssh" ks_out = """ # Firewall configuration firewall --enabled --service=ftp,http,smtp,ssh # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) def default_requirements_test(self): """Test that by default no packages are required by the network module.""" self.assertEqual(self.network_interface.CollectRequirements(), []) def kickstart_firewall_package_requirements_test(self): """Test that firewall command in kickstart results in request for firewalld package.""" ks_in = "firewall --ftp --http --smtp --ssh" ks_out = """ # Firewall configuration firewall --enabled --service=ftp,http,smtp,ssh # Network information network --hostname=localhost.localdomain """ self._test_kickstart(ks_in, ks_out) self.assertEqual(self.network_interface.CollectRequirements(), [{ "type": get_variant(Str, "package"), "name": get_variant(Str, "firewalld"), "reason": get_variant(Str, "Requested by the firewall kickstart command.") }]) def teamd_requirements_test(self): """Test that mocked team devices result in request for teamd package.""" # mock a team device self.network_module.nm_client = Mock() self.__mock_nm_client_devices([("team0", None, "33:33:33:33:33:33", NM.DeviceType.TEAM)]) # check that the teamd package is requested self.assertEqual(self.network_interface.CollectRequirements(), [{ "type": get_variant(Str, "package"), "name": get_variant(Str, "teamd"), "reason": get_variant(Str, "Necessary for network team device configuration.") }])
class SecurityInterfaceTestCase(unittest.TestCase): """Test DBus interface for the Security module.""" def setUp(self): """Set up the security module.""" # Set up the security module. self.security_module = SecurityService() self.security_interface = SecurityInterface(self.security_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.security_interface.PropertiesChanged.connect(self.callback) def _check_dbus_property(self, *args, **kwargs): check_dbus_property(self, SECURITY, self.security_interface, *args, **kwargs) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual( self.security_interface.KickstartCommands, ["auth", "authconfig", "authselect", "selinux", "realm"]) self.assertEqual(self.security_interface.KickstartSections, []) self.assertEqual(self.security_interface.KickstartAddons, []) self.callback.assert_not_called() def selinux_property_test(self): """Test the selinux property.""" self._check_dbus_property("SELinux", SELINUX_ENFORCING) def authselect_property_test(self): """Test the authselect property.""" self._check_dbus_property("Authselect", ["sssd", "with-mkhomedir"]) def authconfig_property_test(self): """Test the authconfig property.""" self._check_dbus_property("Authconfig", ["--passalgo=sha512", "--useshadow"]) def fingerprint_auth_enabled_test(self): """Test the fingerprint_auth_enabled property.""" self._check_dbus_property("FingerprintAuthEnabled", True) def realm_property_test(self): """Test the realm property.""" realm = { "name": get_variant(Str, "domain.example.com"), "discover-options": get_variant(List[Str], ["--client-software=sssd"]), "join-options": get_variant(List[Str], ["--one-time-password=password"]), "discovered": get_variant(Bool, True), "required-packages": get_variant(List[Str], []) } self._check_dbus_property("Realm", realm) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.security_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def selinux_kickstart_test(self): """Test the selinux command.""" ks_in = """ selinux --permissive """ ks_out = """ # SELinux configuration selinux --permissive """ self._test_kickstart(ks_in, ks_out) def auth_kickstart_test(self): """Test the auth command.""" ks_in = """ auth --passalgo=sha512 --useshadow """ ks_out = """ # System authorization information auth --passalgo=sha512 --useshadow """ self._test_kickstart(ks_in, ks_out) def authconfig_kickstart_test(self): """Test the authconfig command.""" ks_in = """ authconfig --passalgo=sha512 --useshadow """ ks_out = """ # System authorization information auth --passalgo=sha512 --useshadow """ self._test_kickstart(ks_in, ks_out) def authselect_kickstart_test(self): """Test the authselect command.""" ks_in = """ authselect select sssd with-mkhomedir """ ks_out = """ # System authorization information authselect select sssd with-mkhomedir """ self._test_kickstart(ks_in, ks_out) def realm_kickstart_test(self): """Test the realm command.""" ks_in = """ realm join --one-time-password=password --client-software=sssd domain.example.com """ ks_out = """ # Realm or domain membership realm join --one-time-password=password --client-software=sssd domain.example.com """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def realm_discover_default_test(self, publisher): """Test module in default state with realm discover task.""" realm_discover_task_path = self.security_interface.DiscoverRealmWithTask( ) obj = check_task_creation(self, realm_discover_task_path, publisher, RealmDiscoverTask) self.assertEqual(obj.implementation._realm_data.name, "") self.assertEqual(obj.implementation._realm_data.discover_options, []) @patch_dbus_publish_object def realm_discover_configured_test(self, publisher): """Test module in configured state with realm discover task.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] self.security_interface.SetRealm(RealmData.to_structure(realm)) realm_discover_task_path = self.security_interface.DiscoverRealmWithTask( ) obj = check_task_creation(self, realm_discover_task_path, publisher, RealmDiscoverTask) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.discover_options, ["--client-software=sssd"]) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test InstallWithTasks.""" task_classes = [ ConfigureSELinuxTask, ConfigureFingerprintAuthTask, ConfigureAuthselectTask, ConfigureAuthconfigTask, ] task_paths = self.security_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureSELinuxTask obj = task_objs[0] self.assertEqual(obj.implementation._selinux_mode, SELinuxMode.DEFAULT) # ConfigureFingerprintAuthTask obj = task_objs[1] self.assertEqual(obj.implementation._fingerprint_auth_enabled, False) # ConfigureAuthselectTask obj = task_objs[2] self.assertEqual(obj.implementation._authselect_options, []) # ConfigureAuthconfigTask obj = task_objs[3] self.assertEqual(obj.implementation._authconfig_options, []) @patch_dbus_publish_object def realm_join_default_test(self, publisher): """Test module in default state with realm join task.""" realm_join_task_path = self.security_interface.JoinRealmWithTask() obj = check_task_creation(self, realm_join_task_path, publisher, RealmJoinTask) self.assertEqual(obj.implementation._realm_data.discovered, False) self.assertEqual(obj.implementation._realm_data.name, "") self.assertEqual(obj.implementation._realm_data.join_options, []) @patch_dbus_publish_object def install_with_tasks_configured_test(self, publisher): """Test install tasks - module in configured state.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] realm.join_options = ["--one-time-password=password"] realm.discovered = True authselect = ['select', 'sssd'] authconfig = ['--passalgo=sha512', '--useshadow'] fingerprint = True self.security_interface.SetRealm(RealmData.to_structure(realm)) self.security_interface.SetSELinux(SELINUX_PERMISSIVE) self.security_interface.SetAuthselect(authselect) self.security_interface.SetAuthconfig(authconfig) self.security_interface.SetFingerprintAuthEnabled(fingerprint) task_classes = [ ConfigureSELinuxTask, ConfigureFingerprintAuthTask, ConfigureAuthselectTask, ConfigureAuthconfigTask, ] task_paths = self.security_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureSELinuxTask obj = task_objs[0] self.assertEqual(obj.implementation._selinux_mode, SELinuxMode.PERMISSIVE) # ConfigureFingerprintAuthTask obj = task_objs[1] self.assertEqual(obj.implementation._fingerprint_auth_enabled, fingerprint) # ConfigureAuthselectTask obj = task_objs[2] self.assertEqual(obj.implementation._authselect_options, authselect) # ConfigureAuthconfigTask obj = task_objs[3] self.assertEqual(obj.implementation._authconfig_options, authconfig) @patch_dbus_publish_object def realm_join_configured_test(self, publisher): """Test module in configured state with realm join task.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] realm.join_options = ["--one-time-password=password"] realm.discovered = True self.security_interface.SetRealm(RealmData.to_structure(realm)) realm_join_task_path = self.security_interface.JoinRealmWithTask() obj = check_task_creation(self, realm_join_task_path, publisher, RealmJoinTask) self.assertEqual(obj.implementation._realm_data.discovered, True) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.join_options, ["--one-time-password=password"]) @patch_dbus_publish_object def realm_data_propagation_test(self, publisher): """Test that realm data changes propagate to realm join task.""" # We connect to the realm_changed signal and update the realm data holder # in the realm join task when the signal is triggered. realm1 = RealmData() realm1.name = "domain.example.com" realm1.discover_options = ["--client-software=sssd"] realm1.discovered = False self.security_interface.SetRealm(RealmData.to_structure(realm1)) realm_join_task_path = self.security_interface.JoinRealmWithTask() # realm join - after task creation obj = check_task_creation(self, realm_join_task_path, publisher, RealmJoinTask) self.assertEqual(obj.implementation._realm_data.discovered, False) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.join_options, []) # change realm data and check the changes propagate to the realm join task realm2 = RealmData() realm2.name = "domain.example.com" realm2.discover_options = ["--client-software=sssd"] realm2.join_options = ["--one-time-password=password"] realm2.discovered = True self.security_interface.SetRealm(RealmData.to_structure(realm2)) # realm join - after realm data update self.assertEqual(obj.implementation._realm_data.discovered, True) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.join_options, ["--one-time-password=password"]) def collect_requirements_default_test(self): """Test requrements are empty by default.""" reqs = self.security_interface.CollectRequirements() self.assertListEqual(reqs, []) def realmd_requirements_test(self): """Test that package requirements in realm data propagate correctly.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] realm.join_options = ["--one-time-password=password"] realm.discovered = True realm.required_packages = ["realmd", "foo", "bar"] self.security_interface.SetRealm(RealmData.to_structure(realm)) # check that the teamd package is requested self.assertEqual( self.security_interface.CollectRequirements(), [{ "type": get_variant(Str, "package"), "name": get_variant(Str, "realmd"), "reason": get_variant(Str, "Needed to join a realm.") }, { "type": get_variant(Str, "package"), "name": get_variant(Str, "foo"), "reason": get_variant(Str, "Needed to join a realm.") }, { "type": get_variant(Str, "package"), "name": get_variant(Str, "bar"), "reason": get_variant(Str, "Needed to join a realm.") }]) def authselect_requirements_test(self): """Test that package requirements for authselect propagate correctly.""" self.security_interface.SetAuthconfig( ['--passalgo=sha512', '--useshadow']) requirements = Requirement.from_structure_list( self.security_interface.CollectRequirements()) self.assertEqual(len(requirements), 1) self.assertEqual(requirements[0].type, "package") self.assertEqual(requirements[0].name, "authselect-compat") self.security_interface.SetAuthconfig([]) self.security_interface.SetAuthselect(['select', 'sssd']) requirements = Requirement.from_structure_list( self.security_interface.CollectRequirements()) self.assertEqual(len(requirements), 1) self.assertEqual(requirements[0].type, "package") self.assertEqual(requirements[0].name, "authselect") self.security_interface.SetAuthconfig([]) self.security_interface.SetAuthselect([]) self.security_interface.SetFingerprintAuthEnabled(True) requirements = Requirement.from_structure_list( self.security_interface.CollectRequirements()) self.assertEqual(len(requirements), 1) self.assertEqual(requirements[0].type, "package") self.assertEqual(requirements[0].name, "authselect")
def setUp(self): self.module = NFSSourceModule() self.interface = NFSSourceInterface(self.module) self.callback = PropertiesChangedCallback() self.interface.PropertiesChanged.connect(self.callback)
class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.timezone_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def timezone_property_test(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with(TIMEZONE.interface_name, {'Timezone': 'Europe/Prague'}, []) def utc_property_test(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'IsUTC': True}, []) def ntp_property_test(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'NTPEnabled': False}, []) def ntp_servers_property_test(self): """Test the NTPServers property.""" self.timezone_interface.SetNTPServers(["ntp.cesnet.cz"]) self.assertEqual(self.timezone_interface.NTPServers, ["ntp.cesnet.cz"]) self.callback.assert_called_once_with( TIMEZONE.interface_name, {'NTPServers': ["ntp.cesnet.cz"]}, []) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.timezone_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ # System timezone timezone America/New_York """ self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_test(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart2_test(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --utc --nontp """ self._test_kickstart(ks_in, ks_out) def kickstart3_test(self): """Test the timezone command with ntp servers..""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --ntpservers=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test install tasks - module in default state.""" tasks = self.timezone_interface.InstallWithTasks() timezone_task_path = tasks[0] ntp_task_path = tasks[1] publisher.assert_called() # timezone configuration timezone_object_path = publisher.call_args_list[0][0][0] tz_obj = publisher.call_args_list[0][0][1] self.assertEqual(timezone_task_path, timezone_object_path) self.assertIsInstance(tz_obj, TaskInterface) self.assertIsInstance(tz_obj.implementation, ConfigureTimezoneTask) self.assertEqual(tz_obj.implementation._timezone, "America/New_York") self.assertEqual(tz_obj.implementation._is_utc, False) # NTP configuration ntp_object_path = publisher.call_args_list[1][0][0] ntp_obj = publisher.call_args_list[1][0][1] self.assertEqual(ntp_task_path, ntp_object_path) self.assertIsInstance(ntp_obj, TaskInterface) self.assertIsInstance(ntp_obj.implementation, ConfigureNTPTask) self.assertEqual(ntp_obj.implementation._ntp_enabled, True) @patch_dbus_publish_object def install_with_tasks_configured_test(self, publisher): """Test install tasks - module in configured state.""" self.timezone_interface.SetNTPEnabled(False) self.timezone_interface.SetIsUTC(True) self.timezone_interface.SetTimezone("Asia/Tokyo") tasks = self.timezone_interface.InstallWithTasks() timezone_task_path = tasks[0] ntp_task_path = tasks[1] publisher.assert_called() # timezone configuration timezone_object_path = publisher.call_args_list[0][0][0] tz_obj = publisher.call_args_list[0][0][1] self.assertEqual(timezone_task_path, timezone_object_path) self.assertIsInstance(tz_obj, TaskInterface) self.assertIsInstance(tz_obj.implementation, ConfigureTimezoneTask) self.assertEqual(tz_obj.implementation._timezone, "Asia/Tokyo") self.assertEqual(tz_obj.implementation._is_utc, True) # NTP configuration ntp_object_path = publisher.call_args_list[1][0][0] ntp_obj = publisher.call_args_list[1][0][1] self.assertEqual(ntp_task_path, ntp_object_path) self.assertIsInstance(ntp_obj, TaskInterface) self.assertIsInstance(ntp_obj.implementation, ConfigureNTPTask) self.assertEqual(ntp_obj.implementation._ntp_enabled, False)
class SecurityInterfaceTestCase(unittest.TestCase): """Test DBus interface for the Security module.""" def setUp(self): """Set up the security module.""" # Set up the security module. self.security_module = SecurityService() self.security_interface = SecurityInterface(self.security_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.security_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.security_interface.KickstartCommands, ["auth", "authconfig", "authselect", "selinux", "realm"]) self.assertEqual(self.security_interface.KickstartSections, []) self.assertEqual(self.security_interface.KickstartAddons, []) self.callback.assert_not_called() def selinux_property_test(self): """Test the selinux property.""" self.security_interface.SetSELinux(SELINUX_ENFORCING) self.assertEqual(self.security_interface.SELinux, SELINUX_ENFORCING) self.callback.assert_called_once_with(SECURITY.interface_name, {'SELinux': SELINUX_ENFORCING}, []) def authselect_property_test(self): """Test the authselect property.""" self.security_interface.SetAuthselect(["sssd", "with-mkhomedir"]) self.assertEqual(self.security_interface.Authselect, ["sssd", "with-mkhomedir"]) self.callback.assert_called_once_with(SECURITY.interface_name, {'Authselect': ["sssd", "with-mkhomedir"]}, []) def authconfig_property_test(self): """Test the authconfig property.""" self.security_interface.SetAuthconfig(["--passalgo=sha512", "--useshadow"]) self.assertEqual(self.security_interface.Authconfig, ["--passalgo=sha512", "--useshadow"]) self.callback.assert_called_once_with(SECURITY.interface_name, {'Authconfig': ["--passalgo=sha512", "--useshadow"]}, []) def realm_property_test(self): """Test the realm property.""" realm_in = { "name": "domain.example.com", "discover-options": ["--client-software=sssd"], "join-options": ["--one-time-password=password"], "discovered": True } realm_out = { "name": get_variant(Str, "domain.example.com"), "discover-options": get_variant(List[Str], ["--client-software=sssd"]), "join-options": get_variant(List[Str], ["--one-time-password=password"]), "discovered": get_variant(Bool, True), "required-packages": get_variant(List[Str], []) } self.security_interface.SetRealm(realm_in) self.assertEqual(realm_out, self.security_interface.Realm) self.callback.assert_called_once_with(SECURITY.interface_name, { 'Realm': get_native(realm_out) }, []) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.security_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def selinux_kickstart_test(self): """Test the selinux command.""" ks_in = """ selinux --permissive """ ks_out = """ # SELinux configuration selinux --permissive """ self._test_kickstart(ks_in, ks_out) def auth_kickstart_test(self): """Test the auth command.""" ks_in = """ auth --passalgo=sha512 --useshadow """ ks_out = """ # System authorization information auth --passalgo=sha512 --useshadow """ self._test_kickstart(ks_in, ks_out) def authconfig_kickstart_test(self): """Test the authconfig command.""" ks_in = """ authconfig --passalgo=sha512 --useshadow """ ks_out = """ # System authorization information auth --passalgo=sha512 --useshadow """ self._test_kickstart(ks_in, ks_out) def authselect_kickstart_test(self): """Test the authselect command.""" ks_in = """ authselect select sssd with-mkhomedir """ ks_out = """ # System authorization information authselect select sssd with-mkhomedir """ self._test_kickstart(ks_in, ks_out) def realm_kickstart_test(self): """Test the realm command.""" ks_in = """ realm join --one-time-password=password --client-software=sssd domain.example.com """ ks_out = """ # Realm or domain membership realm join --one-time-password=password --client-software=sssd domain.example.com """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def realm_discover_default_test(self, publisher): """Test module in default state with realm discover task.""" realm_discover_task_path = self.security_interface.DiscoverRealmWithTask() publisher.assert_called() # realm discover obj = check_task_creation(self, realm_discover_task_path, publisher, RealmDiscoverTask) self.assertEqual(obj.implementation._realm_data.name, "") self.assertEqual(obj.implementation._realm_data.discover_options, []) @patch_dbus_publish_object def realm_discover_configured_test(self, publisher): """Test module in configured state with realm discover task.""" realm_in = { "name": "domain.example.com", "discover-options": ["--client-software=sssd"], } self.security_interface.SetRealm(realm_in) realm_discover_task_path = self.security_interface.DiscoverRealmWithTask() publisher.assert_called() # realm discover obj = check_task_creation(self, realm_discover_task_path, publisher, RealmDiscoverTask) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.discover_options, ["--client-software=sssd"]) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test install tasks - module in default state.""" tasks = self.security_interface.InstallWithTasks() selinux_task_path = tasks[0] publisher.assert_called() # SELinux configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] self.assertEqual(selinux_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureSELinuxTask) self.assertEqual(obj.implementation._selinux_mode, SELinuxMode.DEFAULT) @patch_dbus_publish_object def realm_join_default_test(self, publisher): """Test module in default state with realm join task.""" realm_join_task_path = self.security_interface.JoinRealmWithTask() publisher.assert_called() # realm join obj = check_task_creation(self, realm_join_task_path, publisher, RealmJoinTask) self.assertEqual(obj.implementation._realm_data.discovered, False) self.assertEqual(obj.implementation._realm_data.name, "") self.assertEqual(obj.implementation._realm_data.join_options, []) @patch_dbus_publish_object def install_with_tasks_configured_test(self, publisher): """Test install tasks - module in configured state.""" realm_in = { "name": "domain.example.com", "discover-options": ["--client-software=sssd"], "join-options": ["--one-time-password=password"], "discovered": True } self.security_interface.SetRealm(realm_in) self.security_interface.SetSELinux(SELINUX_PERMISSIVE) tasks = self.security_interface.InstallWithTasks() selinux_task_path = tasks[0] publisher.assert_called() # SELinux configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] self.assertEqual(selinux_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureSELinuxTask) self.assertEqual(obj.implementation._selinux_mode, SELinuxMode.PERMISSIVE) @patch_dbus_publish_object def realm_join_configured_test(self, publisher): """Test module in configured state with realm join task.""" realm_in = { "name": "domain.example.com", "discover-options": ["--client-software=sssd"], "join-options": ["--one-time-password=password"], "discovered": True } self.security_interface.SetRealm(realm_in) realm_join_task_path = self.security_interface.JoinRealmWithTask() publisher.assert_called() # realm join obj = check_task_creation(self, realm_join_task_path, publisher, RealmJoinTask) self.assertEqual(obj.implementation._realm_data.discovered, True) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.join_options, ["--one-time-password=password"]) @patch_dbus_publish_object def realm_data_propagation_test(self, publisher): """Test that realm data changes propagate to realm join task.""" # We connect to the realm_changed signal and update the realm data holder # in the realm join task when the signal is triggered. realm_in_1 = { "name": "domain.example.com", "discover-options": ["--client-software=sssd"], "discovered": False } self.security_interface.SetRealm(realm_in_1) realm_join_task_path = self.security_interface.JoinRealmWithTask() publisher.assert_called() # realm join - after task creation obj = check_task_creation(self, realm_join_task_path, publisher, RealmJoinTask) self.assertEqual(obj.implementation._realm_data.discovered, False) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.join_options, []) # change realm data and check the changes propagate to the realm join task realm_in_2 = { "name": "domain.example.com", "discover-options": ["--client-software=sssd"], "join-options": ["--one-time-password=password"], "discovered": True } self.security_interface.SetRealm(realm_in_2) # realm join - after realm data update self.assertEqual(obj.implementation._realm_data.discovered, True) self.assertEqual(obj.implementation._realm_data.name, "domain.example.com") self.assertEqual(obj.implementation._realm_data.join_options, ["--one-time-password=password"]) def collect_requirements_default_test(self): """Test requrements are empty by default.""" reqs = self.security_interface.CollectRequirements() self.assertListEqual(reqs, []) def realmd_requirements_test(self): """Test that package requirements in realm data propagate correctly.""" realm_in = { "name": "domain.example.com", "discover-options": ["--client-software=sssd"], "join-options": ["--one-time-password=password"], "discovered": True, "required-packages" : ["realmd", "foo", "bar"] } self.security_interface.SetRealm(realm_in) # check that the teamd package is requested self.assertEqual(self.security_interface.CollectRequirements(), [ { "type": get_variant(Str, "package"), "name": get_variant(Str, "realmd"), "reason": get_variant(Str, "Needed to join a realm.") }, { "type": get_variant(Str, "package"), "name": get_variant(Str, "foo"), "reason": get_variant(Str, "Needed to join a realm.") }, { "type": get_variant(Str, "package"), "name": get_variant(Str, "bar"), "reason": get_variant(Str, "Needed to join a realm.") } ])
class LocalizationInterfaceTestCase(unittest.TestCase): """Test DBus interface for the localization module.""" def setUp(self): """Set up the localization module.""" # Set up the localization module. self.localization_module = LocalizationService() self.localization_interface = LocalizationInterface( self.localization_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.localization_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.localization_interface.KickstartCommands, ["keyboard", "lang"]) self.assertEqual(self.localization_interface.KickstartSections, []) self.assertEqual(self.localization_interface.KickstartAddons, []) self.callback.assert_not_called() def language_property_test(self): """Test the Language property.""" self.localization_interface.SetLanguage("cs_CZ.UTF-8") self.assertEqual(self.localization_interface.Language, "cs_CZ.UTF-8") self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'Language': 'cs_CZ.UTF-8'}, []) def language_support_property_test(self): """Test the LanguageSupport property.""" self.localization_interface.SetLanguageSupport(["fr_FR"]) self.assertEqual(self.localization_interface.LanguageSupport, ["fr_FR"]) self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageSupport': ["fr_FR"]}, []) def vc_keymap_property_test(self): """Test the VirtualConsoleKeymap property.""" self.localization_interface.SetVirtualConsoleKeymap("cz") self.assertEqual(self.localization_interface.VirtualConsoleKeymap, "cz") self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'VirtualConsoleKeymap': 'cz'}, []) def x_layouts_property_test(self): """Test the XLayouts property.""" self.localization_interface.SetXLayouts(["en", "cz(querty)"]) self.assertEqual(self.localization_interface.XLayouts, ["en", "cz(querty)"]) self.callback.assert_called_once_with( LOCALIZATION.interface_name, {'XLayouts': ["en", "cz(querty)"]}, []) def switch_options_property_test(self): """Test the LayoutSwitchOptions property.""" self.localization_interface.SetLayoutSwitchOptions( ["grp:alt_shift_toggle"]) self.assertEqual(self.localization_interface.LayoutSwitchOptions, ["grp:alt_shift_toggle"]) self.callback.assert_called_once_with( LOCALIZATION.interface_name, {'LayoutSwitchOptions': ["grp:alt_shift_toggle"]}, []) def keyboard_seen_test(self): """Test the KeyboardKickstarted property.""" self.assertEqual(self.localization_interface.KeyboardKickstarted, False) ks_in = """ lang cs_CZ.UTF-8 """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.KeyboardKickstarted, False) ks_in = """ lang cs_CZ.UTF-8 keyboard cz """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.KeyboardKickstarted, True) def language_seen_test(self): """Test the LanguageKickstarted property.""" self.assertEqual(self.localization_interface.LanguageKickstarted, False) ks_in = """ keyboard cz """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.LanguageKickstarted, False) ks_in = """ keyboard cz lang cs_CZ.UTF-8 """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.LanguageKickstarted, True) def set_language_kickstarted_test(self): """Test SetLanguageKickstarted.""" self.localization_interface.SetLanguageKickstarted(True) self.assertEqual(self.localization_interface.LanguageKickstarted, True) self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageKickstarted': True}, []) def set_keyboard_kickstarted_test(self): """Test SetLanguageKickstarted.""" self.localization_interface.SetKeyboardKickstarted(True) self.assertEqual(self.localization_interface.KeyboardKickstarted, True) self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'KeyboardKickstarted': True}, []) @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap") def set_keyboard_test(self, mocked_load_keymap): """Test SetKeyboard.""" # Makes sure VirtualConsoleKeymap setting will be used no matter the # conf.system.can_activate_keyboard value is. mocked_load_keymap.return_value = True self.localization_interface.SetKeyboard("us") self.assertEqual(self.localization_interface.VirtualConsoleKeymap, "us") @patch_dbus_publish_object def install_with_task_test(self, publisher): """Test InstallWithTask.""" self.localization_interface.SetLanguage("cs_CZ.UTF-8") self.localization_interface.SetVirtualConsoleKeymap('us') self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)']) self.localization_interface.SetLayoutSwitchOptions( ["grp:alt_shift_toggle"]) tasks = self.localization_interface.InstallWithTasks() language_installation_task_path = tasks[0] keyboard_installation_task_path = tasks[1] publisher.assert_called() object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] self.assertEqual(language_installation_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, LanguageInstallationTask) self.assertEqual(obj.implementation._lang, "cs_CZ.UTF-8") object_path = publisher.call_args_list[1][0][0] obj = publisher.call_args_list[1][0][1] self.assertEqual(keyboard_installation_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, KeyboardInstallationTask) self.assertEqual(obj.implementation._x_layouts, ['cz', 'cz (qwerty)']) self.assertEqual(obj.implementation._vc_keymap, 'us') self.assertEqual(obj.implementation._switch_options, ["grp:alt_shift_toggle"]) @patch_dbus_publish_object def populate_missing_keyboard_configuration_with_task_test( self, publisher): """Test PopulateMissingKeyboardConfigurationWithTask.""" self.localization_interface.SetVirtualConsoleKeymap('us') self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)']) task_path = self.localization_interface.PopulateMissingKeyboardConfigurationWithTask( ) obj = check_task_creation(self, task_path, publisher, GetMissingKeyboardConfigurationTask) self.assertEqual(obj.implementation._vc_keymap, 'us') self.assertEqual(obj.implementation._x_layouts, ['cz', 'cz (qwerty)']) @patch_dbus_publish_object def apply_keyboard_with_task_test(self, publisher): """Test ApplyKeyboardWithTask.""" self.localization_interface.SetVirtualConsoleKeymap('us') self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)']) self.localization_interface.SetLayoutSwitchOptions( ["grp:alt_shift_toggle"]) task_path = self.localization_interface.ApplyKeyboardWithTask() obj = check_task_creation(self, task_path, publisher, ApplyKeyboardTask) self.assertEqual(obj.implementation._vc_keymap, 'us') self.assertEqual(obj.implementation._x_layouts, ['cz', 'cz (qwerty)']) self.assertEqual(obj.implementation._switch_options, ["grp:alt_shift_toggle"]) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.localization_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def lang_kickstart_test(self): """Test the lang command.""" ks_in = """ lang cs_CZ.UTF-8 """ ks_out = """ # System language lang cs_CZ.UTF-8 """ self._test_kickstart(ks_in, ks_out) def lang_kickstart2_test(self): """Test the lang command with added language support..""" ks_in = """ lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8 """ ks_out = """ # System language lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8 """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart1_test(self): """Test the keyboard command.""" ks_in = """ keyboard --vckeymap=us --xlayouts='us','cz (qwerty)' """ ks_out = """ # Keyboard layouts keyboard --vckeymap=us --xlayouts='us','cz (qwerty)' """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart2_test(self): """Test the keyboard command.""" ks_in = """ keyboard us """ ks_out = """ # Keyboard layouts keyboard --vckeymap=us """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart_ignore_generic_keyboard_test(self): """Test that keyboard argument is ignored if there is specific option.""" ks_in = """ keyboard --vckeymap cz us """ ks_out = """ # Keyboard layouts keyboard --vckeymap=cz """ self._test_kickstart(ks_in, ks_out) @patch("pyanaconda.modules.localization.runtime.conf") @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap") def keyboard_kickstart_keyboard_assign_test(self, mocked_load_keymap, mocked_conf): """Test the keyboard command assignment to proper setting (running a task with try_to_load_keymap).""" mocked_conf.system.can_activate_keyboard = True mocked_load_keymap.return_value = True ks_in = """ keyboard us """ ks_out = """ # Keyboard layouts keyboard --vckeymap=us """ self._test_kickstart(ks_in, ks_out) mocked_load_keymap.return_value = False ks_in = """ keyboard us """ ks_out = """ # Keyboard layouts keyboard --xlayouts='us' """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart3_test(self): """Test the keyboard command.""" ks_in = """ keyboard --xlayouts=cz,'cz (qwerty)' --switch=grp:alt_shift_toggle """ ks_out = """ # Keyboard layouts keyboard --xlayouts='cz','cz (qwerty)' --switch='grp:alt_shift_toggle' """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart4_test(self): """Test the keyboard command.""" ks_in = """ keyboard --xlayouts='cz (qwerty)','en' en """ ks_out = """ # Keyboard layouts keyboard --xlayouts='cz (qwerty)','en' """ self._test_kickstart(ks_in, ks_out)
class LiveOSInterfaceTestCase(unittest.TestCase): def setUp(self): self.live_os_module = LiveOSModule() self.live_os_interface = LiveOSInterface(self.live_os_module) self.shared_tests = PayloadSharedTest( self, payload=self.live_os_module, payload_intf=self.live_os_interface) self.callback = PropertiesChangedCallback() self.live_os_interface.PropertiesChanged.connect(self.callback) def _prepare_source(self): return self.shared_tests.prepare_source(SourceType.LIVE_OS_IMAGE) def _prepare_and_use_source(self): source = self._prepare_source() self.live_os_module.set_sources([source]) return source def type_test(self): self.shared_tests.check_type(PayloadType.LIVE_OS) def supported_sources_test(self): """Test LiveOS supported sources API.""" self.assertEqual([SOURCE_TYPE_LIVE_OS_IMAGE], self.live_os_interface.SupportedSourceTypes) @patch_dbus_publish_object def set_source_test(self, publisher): """Test if set source API of LiveOS payload.""" sources = [self._prepare_source()] self.shared_tests.set_and_check_sources(sources) @patch_dbus_publish_object def set_multiple_sources_fail_test(self, publisher): """Test LiveOS payload can't set multiple sources.""" paths = [self._prepare_source(), self._prepare_source()] self.shared_tests.set_and_check_sources( paths, exception=IncompatibleSourceError) @patch_dbus_publish_object def set_when_initialized_source_fail_test(self, publisher): """Test LiveOS payload can't set new sources if the old ones are initialized.""" source1 = self._prepare_source() source2 = self._prepare_source() self.shared_tests.set_and_check_sources([source1]) # can't switch source if attached source is ready source1.get_state.return_value = SourceState.READY self.shared_tests.set_sources([source2], SourceSetupError) self.shared_tests.check_sources([source1]) source1.get_state.return_value = SourceState.UNREADY self.shared_tests.set_and_check_sources([source1]) @patch("pyanaconda.modules.payloads.payload.live_os.live_os.get_dir_size") @patch_dbus_publish_object def required_space_properties_test(self, publisher, get_dir_size_mock): """Test Live OS RequiredSpace property.""" self.assertEqual(self.live_os_interface.RequiredSpace, 0) get_dir_size_mock.return_value = 2 self._prepare_and_use_source() task = self.live_os_module.set_up_sources_with_task() task.succeeded_signal.emit() self.assertEqual(self.live_os_interface.RequiredSpace, 2048) object_path, _ = publisher.call_args[0] self.callback.assert_called_once_with(PAYLOAD.interface_name, { "RequiredSpace": 2048, "Sources": [object_path] }, []) self.callback.reset_mock() task = self.live_os_module.tear_down_sources_with_task() task.stopped_signal.emit() self.assertEqual(self.live_os_interface.RequiredSpace, 0) self.callback.assert_called_once_with(PAYLOAD.interface_name, {"RequiredSpace": 0}, []) @patch( "pyanaconda.modules.payloads.payload.live_os.live_os.get_kernel_version_list" ) def empty_kernel_version_list_test(self, get_kernel_version_list): """Test Live OS empty get kernel version list.""" self.assertEqual(self.live_os_interface.GetKernelVersionList(), []) get_kernel_version_list.return_value = [] kernel_list_callback = Mock() # pylint: disable=no-member self.live_os_interface.KernelVersionListChanged.connect( kernel_list_callback) self.live_os_interface.UpdateKernelVersionList() get_kernel_version_list.assert_called_once_with(INSTALL_TREE) self.assertEqual(self.live_os_interface.GetKernelVersionList(), []) kernel_list_callback.assert_called_once_with([]) @patch( "pyanaconda.modules.payloads.payload.live_os.live_os.get_kernel_version_list" ) def kernel_version_list_test(self, get_kernel_version_list): """Test Live OS get kernel version list.""" kernel_list = [ "kernel-abc", "magic-kernel.fc3000.x86_64", "sad-kernel" ] get_kernel_version_list.return_value = kernel_list kernel_list_callback = Mock() # pylint: disable=no-member self.live_os_interface.KernelVersionListChanged.connect( kernel_list_callback) self.live_os_interface.UpdateKernelVersionList() get_kernel_version_list.assert_called_once_with(INSTALL_TREE) self.assertListEqual(self.live_os_interface.GetKernelVersionList(), kernel_list) kernel_list_callback.assert_called_once_with(kernel_list) @patch_dbus_publish_object def set_up_installation_sources_task_test(self, publisher): """Test Live OS is able to create a set up installation sources task.""" self._prepare_and_use_source() task_path = self.live_os_interface.SetUpSourcesWithTask() check_task_creation(self, task_path, publisher, SetUpSourcesTask) @patch_dbus_publish_object def prepare_system_for_installation_task_test(self, publisher): """Test Live OS is able to create a prepare installation task.""" self._prepare_and_use_source() task_path = self.live_os_interface.PreInstallWithTasks() check_task_creation_list(self, task_path, publisher, [PrepareSystemForInstallationTask]) @patch_dbus_publish_object def prepare_system_for_installation_task_no_source_test(self, publisher): """Test Live OS prepare installation task with no source fail.""" with self.assertRaises(SourceSetupError): self.live_os_interface.PreInstallWithTasks() @patch_dbus_publish_object def tear_down_installation_source_task_test(self, publisher): """Test Live OS is able to create a tear down installation sources task.""" self._prepare_and_use_source() task_path = self.live_os_interface.TearDownSourcesWithTask() check_task_creation(self, task_path, publisher, TearDownSourcesTask) @patch_dbus_publish_object def install_with_task_test(self, publisher): """Test Live OS install with tasks.""" self._prepare_and_use_source() task_path = self.live_os_interface.InstallWithTasks() check_task_creation_list(self, task_path, publisher, [InstallFromImageTask]) @patch_dbus_publish_object def install_with_task_no_source_test(self, publisher): """Test Live OS install with tasks with no source fail.""" with self.assertRaises(SourceSetupError): self.live_os_interface.InstallWithTasks() @patch_dbus_publish_object def post_install_with_tasks_test(self, publisher): """Test Live OS post installation configuration task.""" task_classes = [UpdateBLSConfigurationTask, CopyDriverDisksFilesTask] task_paths = self.live_os_interface.PostInstallWithTasks() # Check the number of installation tasks. task_number = len(task_classes) self.assertEqual(task_number, len(task_paths)) self.assertEqual(task_number, publisher.call_count) # Check the tasks. for i in range(task_number): object_path, obj = publisher.call_args_list[i][0] self.assertEqual(object_path, task_paths[i]) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, task_classes[i])
class UsersInterfaceTestCase(unittest.TestCase): """Test DBus interface for the users module.""" def setUp(self): """Set up the user module.""" # Set up the users module. self.users_module = UsersService() self.users_interface = UsersInterface(self.users_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.users_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.users_interface.KickstartCommands, ["rootpw", "user", "group", "sshkey"]) self.assertEqual(self.users_interface.KickstartSections, []) self.assertEqual(self.users_interface.KickstartAddons, []) self.callback.assert_not_called() def _check_dbus_property(self, *args, **kwargs): check_dbus_property(self, USERS, self.users_interface, *args, **kwargs) def default_property_values_test(self): """Test the default user module values are as expected.""" self.assertEqual(self.users_interface.Users, []) self.assertEqual(self.users_interface.Groups, []) self.assertEqual(self.users_interface.SshKeys, []) self.assertEqual(self.users_interface.RootPassword, "") self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.IsRootPasswordCrypted, False) self.assertEqual(self.users_interface.RootPasswordSSHLoginAllowed, False) self.assertEqual(self.users_interface.CanChangeRootPassword, True) def users_property_test(self): """Test the Users property.""" user_1 = { "name": get_variant(Str, "user1"), "uid-mode": get_variant(Str, ID_MODE_USE_VALUE), "uid": get_variant(UInt32, 123), "groups": get_variant(List[Str], ["foo", "bar"]), "gid-mode": get_variant(Str, ID_MODE_USE_VALUE), "gid": get_variant(UInt32, 321), "homedir": get_variant(Str, "user1_home"), "password": get_variant(Str, "swordfish"), "is-crypted": get_variant(Bool, False), "lock": get_variant(Bool, False), "shell": get_variant(Str, "zsh"), "gecos": get_variant(Str, "some stuff"), } user_2 = { "name": get_variant(Str, "user2"), "uid-mode": get_variant(Str, ID_MODE_USE_DEFAULT), "uid": get_variant(UInt32, 456), "groups": get_variant(List[Str], ["baz", "bar"]), "gid-mode": get_variant(Str, ID_MODE_USE_DEFAULT), "gid": get_variant(UInt32, 654), "homedir": get_variant(Str, "user2_home"), "password": get_variant(Str, "laksdjaskldjhasjhd"), "is-crypted": get_variant(Bool, True), "lock": get_variant(Bool, False), "shell": get_variant(Str, "csh"), "gecos": get_variant(Str, "some other stuff"), } self._check_dbus_property("Users", [user_1, user_2]) def groups_property_test(self): """Test the Groups property.""" group_1 = { "name": get_variant(Str, "group1"), "gid-mode": get_variant(Str, ID_MODE_USE_VALUE), "gid": get_variant(UInt32, 321), } group_2 = { "name": get_variant(Str, "group2"), "gid-mode": get_variant(Str, ID_MODE_USE_DEFAULT), "gid": get_variant(UInt32, 654), } self._check_dbus_property("Groups", [group_1, group_2]) def ssh_keys_property_test(self): """Test the SshKeys property.""" key_1 = { "key": get_variant(Str, "aaa"), "username": get_variant(Str, "user1"), } key_2 = { "key": get_variant(Str, "bbb"), "username": get_variant(Str, "user2"), } self._check_dbus_property("SshKeys", [key_1, key_2]) def set_crypted_roopw_test(self): """Test if setting crypted root password works correctly.""" self.users_interface.SetCryptedRootPassword("abcef") self.assertEqual(self.users_interface.RootPassword, "abcef") self.assertEqual(self.users_interface.IsRootPasswordCrypted, True) self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) def set_crypted_roopw_and_unlock_test(self): """Test if setting crypted root password & unlocking it from kickstart works correctly.""" self.users_interface.SetCryptedRootPassword("abcef") self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.CanChangeRootPassword, True) self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) # this should not be a valid admin user for interactive install self.assertFalse(self.users_interface.CheckAdminUserExists()) # root password is locked by default and remains locked even after a password is set # and needs to be unlocked via another DBus API call self.users_interface.SetRootAccountLocked(False) self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, False) self.callback.assert_called_with(USERS.interface_name, {'IsRootAccountLocked': False}, []) def lock_root_account_test(self): """Test if root account can be locked via DBus correctly.""" self.users_interface.SetRootAccountLocked(True) self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.callback.assert_called_once_with(USERS.interface_name, {'IsRootAccountLocked': True}, []) def clear_rootpw_test(self): """Test clearing of the root password.""" # set the password to something self.users_interface.SetCryptedRootPassword("abcef") self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) # clear it self.users_interface.ClearRootPassword() # check if it looks cleared self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.callback.assert_called_with(USERS.interface_name, { 'IsRootPasswordSet': False, 'IsRootAccountLocked': True }, []) def clear_unlocked_rootpw_test(self): """Test clearing of unlocked root password.""" # set the password to something self.users_interface.SetCryptedRootPassword("abcef") self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) self.users_interface.SetRootAccountLocked(False) self.callback.assert_called_with(USERS.interface_name, {'IsRootAccountLocked': False}, []) self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, False) # clear it self.users_interface.ClearRootPassword() # check if it looks cleared self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.callback.assert_called_with(USERS.interface_name, { 'IsRootPasswordSet': False, 'IsRootAccountLocked': True }, []) def allow_root_password_ssh_login_test(self): """Test if root password SSH login can be allowed.""" self.users_interface.SetRootPasswordSSHLoginAllowed(True) self.assertEqual(self.users_interface.RootPasswordSSHLoginAllowed, True) self.callback.assert_called_once_with( USERS.interface_name, {'RootPasswordSSHLoginAllowed': True}, []) self.callback.reset_mock() self.users_interface.SetRootPasswordSSHLoginAllowed(False) self.assertEqual(self.users_interface.RootPasswordSSHLoginAllowed, False) self.callback.assert_called_once_with( USERS.interface_name, {'RootPasswordSSHLoginAllowed': False}, []) def admin_user_detection_1_test(self): """Test that admin user detection works correctly - 3 admins.""" # 2 admin users, unlocked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = False self.users_interface.SetUsers( UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(False) self.assertTrue(self.users_interface.CheckAdminUserExists()) def admin_user_detection_2_test(self): """Test that admin user detection works correctly - 0 admins (case 1).""" # 2 locked admin users, locked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = True user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = True self.users_interface.SetUsers( UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(True) self.assertFalse(self.users_interface.CheckAdminUserExists()) def admin_user_detection_3_test(self): """Test that admin user detection works correctly - 1 admin (case 2).""" # 2 locked admin users, unlocked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = True user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = True self.users_interface.SetUsers( UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(False) self.assertTrue(self.users_interface.CheckAdminUserExists()) def admin_user_detection_4_test(self): """Test that admin user detection works correctly - 1 admin (case 3).""" # 1 locked admin user, 1 unlocked admin user, locked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = True self.users_interface.SetUsers( UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(True) self.assertTrue(self.users_interface.CheckAdminUserExists()) def admin_user_detection_5_test(self): """Test that admin user detection works correctly - 1 admin (case 4).""" # 1 user, 1 unlocked admin user, locked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = False self.users_interface.SetUsers( UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(True) self.assertTrue(self.users_interface.CheckAdminUserExists()) def admin_user_detection_6_test(self): """Test that admin user detection works correctly - 1 admin (case 5).""" # 2 users, unlocked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar"] user2.lock = False self.users_interface.SetUsers( UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(False) self.assertTrue(self.users_interface.CheckAdminUserExists()) def _test_kickstart(self, ks_in, ks_out, ks_tmp=None): check_kickstart_interface(self, self.users_interface, ks_in, ks_out, ks_tmp=ks_tmp) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) # root password should be empty and locked by default, but mutable self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.CanChangeRootPassword, True) # this should not be considered a valid admin user for interactive install self.assertFalse(self.users_interface.CheckAdminUserExists()) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = """ #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and mutable self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.CanChangeRootPassword, True) # not a valid admin user from kickstart PoV self.assertFalse(self.users_interface.CheckAdminUserExists()) def kickstart_set_rootpw_test(self): """Test the setting root password via kickstart.""" ks_in = """ rootpw abcdef """ ks_out = """ # Root password rootpw --plaintext abcdef """ self._test_kickstart(ks_in, ks_out) # if rootpw shows up in the kickstart is should be reported as immutable self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, False) self.assertEqual(self.users_interface.CanChangeRootPassword, False) # but this should still be a valid admin user from kickstart PoV self.assertTrue(self.users_interface.CheckAdminUserExists()) def kickstart_set_plain_rootpw_test(self): """Test the setting plaintext root password via kickstart.""" ks_in = """ rootpw --plaintext abcdef """ ks_out = """ # Root password rootpw --plaintext abcdef """ self._test_kickstart(ks_in, ks_out) def kickstart_set_crypted_rootpw_test(self): """Test the setting crypted root password via kickstart.""" ks_in = """ rootpw --iscrypted abcdef """ ks_out = """ # Root password rootpw --iscrypted abcdef """ self._test_kickstart(ks_in, ks_out) self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, False) def kickstart_lock_root_account_test(self): """Test locking the root account via kickstart.""" ks_in = """ rootpw --lock """ ks_out = """ #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and immutable self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.CanChangeRootPassword, False) # but this should still be a valid admin user from kickstart PoV self.assertTrue(self.users_interface.CheckAdminUserExists()) def kickstart_lock_root_account_with_password_test(self): """Test locking the root account with a password via kickstart.""" ks_in = """ rootpw abcdef --lock """ ks_out = """ # Root password rootpw --lock --plaintext abcdef """ self._test_kickstart(ks_in, ks_out) # password should be marked as set, locked and immutable self.assertEqual(self.users_interface.IsRootPasswordSet, True) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.CanChangeRootPassword, False) # but this should still be a valid admin user from kickstart PoV self.assertTrue(self.users_interface.CheckAdminUserExists()) def kickstart_user_test(self): """Test kickstart user input and output.""" ks_in = """ user --name=user1 --password=abcedf """ ks_out = """ #Root password rootpw --lock user --name=user1 --password=abcedf """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and mutable self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.CanChangeRootPassword, True) # no a valid admin user exists from kickstart PoV self.assertFalse(self.users_interface.CheckAdminUserExists()) def kickstart_user_admin_test(self): """Test kickstart admin user input and output.""" ks_in = """ user --groups=wheel --name=user1 --password=abcedf """ ks_out = """ #Root password rootpw --lock user --groups=wheel --name=user1 --password=abcedf """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and mutable self.assertEqual(self.users_interface.IsRootPasswordSet, False) self.assertEqual(self.users_interface.IsRootAccountLocked, True) self.assertEqual(self.users_interface.CanChangeRootPassword, True) # provides a valid admin user exists from kickstart PoV self.assertTrue(self.users_interface.CheckAdminUserExists()) def kickstart_users_test(self): """Test kickstart users input and output.""" ks_in = """ user --name=user1 --homedir=user1_home --password=foo --shell=ksh --uid=123 --gecos=baz --gid=345 --groups=a,b,c,d --plaintext user --name=user2 --homedir=user2_home --password=asasas --shell=csh --uid=321 --gecos=bar --gid=543 --groups=wheel,mockuser --iscrypted user --name=user3 --lock """ ks_out = """ #Root password rootpw --lock user --groups=a,b,c,d --homedir=user1_home --name=user1 --password=foo --shell=ksh --uid=123 --gecos="baz" --gid=345 user --groups=wheel,mockuser --homedir=user2_home --name=user2 --password=asasas --iscrypted --shell=csh --uid=321 --gecos="bar" --gid=543 user --name=user3 --lock """ self._test_kickstart(ks_in, ks_out) def kickstart_groups_test(self): """Test kickstart groups input and output.""" ks_in = """ group --name=group1 --gid=321 group --name=group2 --gid=654 group --name=group3 """ ks_out = """ group --name=group1 --gid=321 group --name=group2 --gid=654 group --name=group3 #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) def kickstart_ssh_keys_test(self): """Test kickstart ssh keys input and output.""" ks_in = """ sshkey --username=user1 "aaa" sshkey --username=user2 "bbb" sshkey --username=user3 "ccc" """ ks_out = """ #Root password rootpw --lock sshkey --username=user1 "aaa" sshkey --username=user2 "bbb" sshkey --username=user3 "ccc" """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def install_with_tasks_test(self, publisher): """Test InstallWithTasks.""" task_classes = [ CreateGroupsTask, CreateUsersTask, SetRootPasswordTask, SetSshKeysTask, ConfigureRootPasswordSSHLoginTask ] task_paths = self.users_interface.InstallWithTasks() check_task_creation_list(self, task_paths, publisher, task_classes) @patch_dbus_publish_object def configure_groups_with_task_test(self, publisher): """Test ConfigureGroupsWithTask.""" task_path = self.users_interface.ConfigureGroupsWithTask() check_task_creation(self, task_path, publisher, CreateGroupsTask) @patch_dbus_publish_object def configure_users_with_task_test(self, publisher): """Test ConfigureUsersWithTask.""" task_path = self.users_interface.ConfigureUsersWithTask() check_task_creation(self, task_path, publisher, CreateUsersTask) @patch_dbus_publish_object def set_root_password_with_task_test(self, publisher): """Test SetRootPasswordWithTask.""" task_path = self.users_interface.SetRootPasswordWithTask() check_task_creation(self, task_path, publisher, SetRootPasswordTask)
class LocalizationInterfaceTestCase(unittest.TestCase): """Test DBus interface for the localization module.""" def setUp(self): """Set up the localization module.""" # Set up the localization module. self.localization_module = LocalizationService() self.localization_interface = LocalizationInterface( self.localization_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.localization_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.localization_interface.KickstartCommands, ["keyboard", "lang"]) self.assertEqual(self.localization_interface.KickstartSections, []) self.assertEqual(self.localization_interface.KickstartAddons, []) self.callback.assert_not_called() def language_property_test(self): """Test the Language property.""" self.localization_interface.SetLanguage("cs_CZ.UTF-8") self.assertEqual(self.localization_interface.Language, "cs_CZ.UTF-8") self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'Language': 'cs_CZ.UTF-8'}, []) def language_support_property_test(self): """Test the LanguageSupport property.""" self.localization_interface.SetLanguageSupport(["fr_FR"]) self.assertEqual(self.localization_interface.LanguageSupport, ["fr_FR"]) self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageSupport': ["fr_FR"]}, []) def keyboard_property_test(self): """Test the Keyboard property.""" self.localization_interface.SetKeyboard("cz") self.assertEqual(self.localization_interface.Keyboard, "cz") self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'Keyboard': 'cz'}, []) def vc_keymap_property_test(self): """Test the VirtualConsoleKeymap property.""" self.localization_interface.SetVirtualConsoleKeymap("cz") self.assertEqual(self.localization_interface.VirtualConsoleKeymap, "cz") self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'VirtualConsoleKeymap': 'cz'}, []) def x_layouts_property_test(self): """Test the XLayouts property.""" self.localization_interface.SetXLayouts(["en", "cz(querty)"]) self.assertEqual(self.localization_interface.XLayouts, ["en", "cz(querty)"]) self.callback.assert_called_once_with( LOCALIZATION.interface_name, {'XLayouts': ["en", "cz(querty)"]}, []) def switch_options_property_test(self): """Test the LayoutSwitchOptions property.""" self.localization_interface.SetLayoutSwitchOptions( ["grp:alt_shift_toggle"]) self.assertEqual(self.localization_interface.LayoutSwitchOptions, ["grp:alt_shift_toggle"]) self.callback.assert_called_once_with( LOCALIZATION.interface_name, {'LayoutSwitchOptions': ["grp:alt_shift_toggle"]}, []) def keyboard_seen_test(self): """Test the KeyboardKickstarted property.""" self.assertEqual(self.localization_interface.KeyboardKickstarted, False) ks_in = """ lang cs_CZ.UTF-8 """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.KeyboardKickstarted, False) ks_in = """ lang cs_CZ.UTF-8 keyboard cz """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.KeyboardKickstarted, True) def language_seen_test(self): """Test the LanguageKickstarted property.""" self.assertEqual(self.localization_interface.LanguageKickstarted, False) ks_in = """ keyboard cz """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.LanguageKickstarted, False) ks_in = """ keyboard cz lang cs_CZ.UTF-8 """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) self.assertEqual(self.localization_interface.LanguageKickstarted, True) def set_language_kickstarted_test(self): """Test SetLanguageKickstart.""" self.localization_interface.SetLanguageKickstarted(True) self.assertEqual(self.localization_interface.LanguageKickstarted, True) self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageKickstarted': True}, []) @patch_dbus_publish_object def install_language_with_task_test(self, publisher): """Test InstallLanguageWithTask.""" self.localization_interface.SetLanguage("cs_CZ.UTF-8") task_path = self.localization_interface.InstallWithTasks()[0] obj = check_task_creation(self, task_path, publisher, LanguageInstallationTask) self.assertEqual(obj.implementation._lang, "cs_CZ.UTF-8") def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.localization_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def lang_kickstart_test(self): """Test the lang command.""" ks_in = """ lang cs_CZ.UTF-8 """ ks_out = """ # System language lang cs_CZ.UTF-8 """ self._test_kickstart(ks_in, ks_out) def lang_kickstart2_test(self): """Test the lang command with added language support..""" ks_in = """ lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8 """ ks_out = """ # System language lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8 """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart1_test(self): """Test the keyboard command.""" ks_in = """ keyboard --vckeymap=us --xlayouts='us','cz (qwerty)' """ ks_out = """ # Keyboard layouts keyboard --vckeymap=us --xlayouts='us','cz (qwerty)' """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart2_test(self): """Test the keyboard command.""" ks_in = """ keyboard us """ ks_out = """ # Keyboard layouts keyboard 'us' """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart3_test(self): """Test the keyboard command.""" ks_in = """ keyboard --xlayouts=cz,'cz (qwerty)' --switch=grp:alt_shift_toggle """ ks_out = """ # Keyboard layouts keyboard --xlayouts='cz','cz (qwerty)' --switch='grp:alt_shift_toggle' """ self._test_kickstart(ks_in, ks_out) def keyboard_kickstart4_test(self): """Test the keyboard command.""" ks_in = """ keyboard --xlayouts='cz (qwerty)','en' en """ ks_out = """ # Keyboard layouts # old format: keyboard en # new format: keyboard --xlayouts='cz (qwerty)','en' """ self._test_kickstart(ks_in, ks_out)
class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.timezone_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def timezone_property_test(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with(TIMEZONE.interface_name, {'Timezone': 'Europe/Prague'}, []) def utc_property_test(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'IsUTC': True}, []) def ntp_property_test(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'NTPEnabled': False}, []) def ntp_servers_property_test(self): """Test the NTPServers property.""" self.timezone_interface.SetNTPServers(["ntp.cesnet.cz"]) self.assertEqual(self.timezone_interface.NTPServers, ["ntp.cesnet.cz"]) self.callback.assert_called_once_with( TIMEZONE.interface_name, {'NTPServers': ["ntp.cesnet.cz"]}, []) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.timezone_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ # System timezone timezone America/New_York """ self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_test(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart2_test(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --utc --nontp """ self._test_kickstart(ks_in, ks_out) def kickstart3_test(self): """Test the timezone command with ntp servers..""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --ntpservers=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test install tasks - module in default state.""" task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "America/New_York") self.assertEqual(obj.implementation._is_utc, False) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, True) self.assertEqual(obj.implementation._ntp_servers, []) @patch_dbus_publish_object def install_with_tasks_configured_test(self, publisher): """Test install tasks - module in configured state.""" self.timezone_interface.SetIsUTC(True) self.timezone_interface.SetTimezone("Asia/Tokyo") self.timezone_interface.SetNTPEnabled(False) # --nontp and --ntpservers are mutually exclusive in kicstart but # there is no such enforcement in the module so for testing this is ok self.timezone_interface.SetNTPServers([ "clock1.example.com", "clock2.example.com", ]) task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "Asia/Tokyo") self.assertEqual(obj.implementation._is_utc, True) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, False) self.assertEqual(obj.implementation._ntp_servers, [ "clock1.example.com", "clock2.example.com", ]) @patch_dbus_publish_object def configure_ntp_service_enablement_default_test(self, publisher): """Test ntp service enablement with default module state.""" ntp_excluded = True task_path = self.timezone_interface.ConfigureNTPServiceEnablementWithTask( ntp_excluded) obj = check_task_creation(self, task_path, publisher, ConfigureNTPServiceEnablementTask) self.assertEqual(obj.implementation._ntp_enabled, True) self.assertEqual(obj.implementation._ntp_excluded, ntp_excluded) @patch_dbus_publish_object def configure_ntp_service_enablement_configured_test(self, publisher): """Test ntp service enablement with configured module state.""" ntp_excluded = False self.timezone_interface.SetNTPEnabled(False) task_path = self.timezone_interface.ConfigureNTPServiceEnablementWithTask( ntp_excluded) obj = check_task_creation(self, task_path, publisher, ConfigureNTPServiceEnablementTask) self.assertEqual(obj.implementation._ntp_enabled, False) self.assertEqual(obj.implementation._ntp_excluded, ntp_excluded) def deprecated_warnings_test(self): response = self.timezone_interface.ReadKickstart( "timezone --isUtc Europe/Bratislava") report = KickstartReport.from_structure(response) warning = "The option --isUtc will be deprecated in future releases. " \ "Please modify your kickstart file to replace this option with " \ "its preferred alias --utc." self.assertEqual(len(report.warning_messages), 1) self.assertEqual(report.warning_messages[0].message, warning)