From 20570add1c2aa6efe3ce175723255db691f99c21 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Thu, 9 Nov 2023 09:38:43 -0800 Subject: [PATCH 01/37] migrating mac module integration tests to pytest. --- .../integration/modules/test_mac_assistive.py | 89 ----- .../integration/modules/test_mac_brew_pkg.py | 188 ---------- tests/integration/modules/test_mac_desktop.py | 58 --- tests/integration/modules/test_mac_group.py | 177 --------- .../integration/modules/test_mac_keychain.py | 106 ------ .../integration/modules/test_mac_portspkg.py | 104 ------ tests/integration/modules/test_mac_power.py | 345 ------------------ tests/integration/modules/test_mac_service.py | 233 ------------ tests/integration/modules/test_mac_shadow.py | 226 ------------ .../modules/test_mac_softwareupdate.py | 170 --------- tests/integration/modules/test_mac_sysctl.py | 174 --------- tests/integration/modules/test_mac_system.py | 263 ------------- .../integration/modules/test_mac_timezone.py | 206 ----------- tests/integration/modules/test_mac_user.py | 235 ------------ tests/integration/modules/test_mac_xattr.py | 193 ---------- .../integration/modules/test_mac_assistive.py | 86 +++++ .../integration/modules/test_mac_brew_pkg.py | 188 ++++++++++ .../integration/modules/test_mac_desktop.py | 57 +++ .../integration/modules/test_mac_group.py | 194 ++++++++++ .../integration/modules/test_mac_keychain.py | 108 ++++++ .../integration/modules/test_mac_portspkg.py | 95 +++++ .../integration/modules/test_mac_power.py | 123 +++++++ .../test_mac_power_restart_power_failure.py | 38 ++ .../test_mac_power_sleep_on_power_button.py | 38 ++ .../modules/test_mac_power_wake_on_modem.py | 36 ++ .../modules/test_mac_power_wake_on_net.py | 38 ++ .../integration/modules/test_mac_service.py | 218 +++++++++++ .../integration/modules/test_mac_shadow.py | 226 ++++++++++++ .../modules/test_mac_softwareupdate.py | 144 ++++++++ .../integration/modules/test_mac_sysctl.py | 182 +++++++++ .../integration/modules/test_mac_system.py | 211 +++++++++++ .../integration/modules/test_mac_timezone.py | 202 ++++++++++ .../integration/modules/test_mac_user.py | 234 ++++++++++++ .../integration/modules/test_mac_xattr.py | 166 +++++++++ 34 files changed, 2584 insertions(+), 2767 deletions(-) delete mode 100644 tests/integration/modules/test_mac_assistive.py delete mode 100644 tests/integration/modules/test_mac_brew_pkg.py delete mode 100644 tests/integration/modules/test_mac_desktop.py delete mode 100644 tests/integration/modules/test_mac_group.py delete mode 100644 tests/integration/modules/test_mac_keychain.py delete mode 100644 tests/integration/modules/test_mac_portspkg.py delete mode 100644 tests/integration/modules/test_mac_power.py delete mode 100644 tests/integration/modules/test_mac_service.py delete mode 100644 tests/integration/modules/test_mac_shadow.py delete mode 100644 tests/integration/modules/test_mac_softwareupdate.py delete mode 100644 tests/integration/modules/test_mac_sysctl.py delete mode 100644 tests/integration/modules/test_mac_system.py delete mode 100644 tests/integration/modules/test_mac_timezone.py delete mode 100644 tests/integration/modules/test_mac_user.py delete mode 100644 tests/integration/modules/test_mac_xattr.py create mode 100644 tests/pytests/integration/modules/test_mac_assistive.py create mode 100644 tests/pytests/integration/modules/test_mac_brew_pkg.py create mode 100644 tests/pytests/integration/modules/test_mac_desktop.py create mode 100644 tests/pytests/integration/modules/test_mac_group.py create mode 100644 tests/pytests/integration/modules/test_mac_keychain.py create mode 100644 tests/pytests/integration/modules/test_mac_portspkg.py create mode 100644 tests/pytests/integration/modules/test_mac_power.py create mode 100644 tests/pytests/integration/modules/test_mac_power_restart_power_failure.py create mode 100644 tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py create mode 100644 tests/pytests/integration/modules/test_mac_power_wake_on_modem.py create mode 100644 tests/pytests/integration/modules/test_mac_power_wake_on_net.py create mode 100644 tests/pytests/integration/modules/test_mac_service.py create mode 100644 tests/pytests/integration/modules/test_mac_shadow.py create mode 100644 tests/pytests/integration/modules/test_mac_softwareupdate.py create mode 100644 tests/pytests/integration/modules/test_mac_sysctl.py create mode 100644 tests/pytests/integration/modules/test_mac_system.py create mode 100644 tests/pytests/integration/modules/test_mac_timezone.py create mode 100644 tests/pytests/integration/modules/test_mac_user.py create mode 100644 tests/pytests/integration/modules/test_mac_xattr.py diff --git a/tests/integration/modules/test_mac_assistive.py b/tests/integration/modules/test_mac_assistive.py deleted file mode 100644 index 5c435def9807..000000000000 --- a/tests/integration/modules/test_mac_assistive.py +++ /dev/null @@ -1,89 +0,0 @@ -""" - :codeauthor: Nicole Thomas -""" - -import pytest - -from tests.support.case import ModuleCase - -OSA_SCRIPT = "/usr/bin/osascript" - - -@pytest.mark.destructive_test -@pytest.mark.skip_if_not_root -@pytest.mark.skip_initial_gh_actions_failure -@pytest.mark.skip_unless_on_darwin -class MacAssistiveTest(ModuleCase): - """ - Integration tests for the mac_assistive module. - """ - - def setUp(self): - """ - Sets up test requirements - """ - # Let's install a bundle to use in tests - self.run_function("assistive.install", [OSA_SCRIPT, True]) - - def tearDown(self): - """ - Clean up after tests - """ - # Delete any bundles that were installed - osa_script = self.run_function("assistive.installed", [OSA_SCRIPT]) - if osa_script: - self.run_function("assistive.remove", [OSA_SCRIPT]) - - smile_bundle = "com.smileonmymac.textexpander" - smile_bundle_present = self.run_function("assistive.installed", [smile_bundle]) - if smile_bundle_present: - self.run_function("assistive.remove", [smile_bundle]) - - @pytest.mark.slow_test - def test_install_and_remove(self): - """ - Tests installing and removing a bundled ID or command to use assistive access. - """ - new_bundle = "com.smileonmymac.textexpander" - self.assertTrue(self.run_function("assistive.install", [new_bundle])) - self.assertTrue(self.run_function("assistive.remove", [new_bundle])) - - @pytest.mark.slow_test - def test_installed(self): - """ - Tests the True and False return of assistive.installed. - """ - # OSA script should have been installed in setUp function - self.assertTrue(self.run_function("assistive.installed", [OSA_SCRIPT])) - # Clean up install - self.run_function("assistive.remove", [OSA_SCRIPT]) - # Installed should now return False - self.assertFalse(self.run_function("assistive.installed", [OSA_SCRIPT])) - - @pytest.mark.slow_test - def test_enable(self): - """ - Tests setting the enabled status of a bundled ID or command. - """ - # OSA script should have been installed and enabled in setUp function - # Now let's disable it, which should return True. - self.assertTrue(self.run_function("assistive.enable", [OSA_SCRIPT, False])) - # Double check the script was disabled, as intended. - self.assertFalse(self.run_function("assistive.enabled", [OSA_SCRIPT])) - # Now re-enable - self.assertTrue(self.run_function("assistive.enable", [OSA_SCRIPT])) - # Double check the script was enabled, as intended. - self.assertTrue(self.run_function("assistive.enabled", [OSA_SCRIPT])) - - @pytest.mark.slow_test - def test_enabled(self): - """ - Tests if a bundled ID or command is listed in assistive access returns True. - """ - # OSA script should have been installed in setUp function, which sets - # enabled to True by default. - self.assertTrue(self.run_function("assistive.enabled", [OSA_SCRIPT])) - # Disable OSA Script - self.run_function("assistive.enable", [OSA_SCRIPT, False]) - # Assert against new disabled status - self.assertFalse(self.run_function("assistive.enabled", [OSA_SCRIPT])) diff --git a/tests/integration/modules/test_mac_brew_pkg.py b/tests/integration/modules/test_mac_brew_pkg.py deleted file mode 100644 index 59d2dcde1dee..000000000000 --- a/tests/integration/modules/test_mac_brew_pkg.py +++ /dev/null @@ -1,188 +0,0 @@ -""" - :codeauthor: Nicole Thomas -""" - -import pytest - -from salt.exceptions import CommandExecutionError -from tests.support.case import ModuleCase - -# Brew doesn't support local package installation - So, let's -# Grab some small packages available online for brew -ADD_PKG = "algol68g" -DEL_PKG = "acme" - - -@pytest.mark.skip_if_not_root -@pytest.mark.destructive_test -@pytest.mark.skip_if_binaries_missing("brew") -@pytest.mark.skip_unless_on_darwin -class BrewModuleTest(ModuleCase): - """ - Integration tests for the brew module - """ - - @pytest.mark.slow_test - def test_brew_install(self): - """ - Tests the installation of packages - """ - try: - self.run_function("pkg.install", [ADD_PKG]) - pkg_list = self.run_function("pkg.list_pkgs") - try: - self.assertIn(ADD_PKG, pkg_list) - except AssertionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - except CommandExecutionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - - @pytest.mark.slow_test - def test_remove(self): - """ - Tests the removal of packages - """ - try: - # Install a package to delete - If unsuccessful, skip the test - self.run_function("pkg.install", [DEL_PKG]) - pkg_list = self.run_function("pkg.list_pkgs") - if DEL_PKG not in pkg_list: - self.run_function("pkg.install", [DEL_PKG]) - self.skipTest("Failed to install a package to delete") - - # Now remove the installed package - self.run_function("pkg.remove", [DEL_PKG]) - del_list = self.run_function("pkg.list_pkgs") - self.assertNotIn(DEL_PKG, del_list) - except CommandExecutionError: - self.run_function("pkg.remove", [DEL_PKG]) - raise - - @pytest.mark.slow_test - def test_version(self): - """ - Test pkg.version for mac. Installs a package and then checks we can get - a version for the installed package. - """ - try: - self.run_function("pkg.install", [ADD_PKG]) - pkg_list = self.run_function("pkg.list_pkgs") - version = self.run_function("pkg.version", [ADD_PKG]) - try: - self.assertTrue( - version, - msg="version: {} is empty, or other issue is present".format( - version - ), - ) - self.assertIn( - ADD_PKG, - pkg_list, - msg="package: {} is not in the list of installed packages: {}".format( - ADD_PKG, pkg_list - ), - ) - # make sure the version is accurate and is listed in the pkg_list - self.assertIn( - version, - str(pkg_list[ADD_PKG]), - msg="The {} version: {} is not listed in the pkg_list: {}".format( - ADD_PKG, version, pkg_list[ADD_PKG] - ), - ) - except AssertionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - except CommandExecutionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - - @pytest.mark.slow_test - def test_latest_version(self): - """ - Test pkg.latest_version: - - get the latest version available - - install the package - - get the latest version available - - check that the latest version is empty after installing it - """ - try: - self.run_function("pkg.remove", [ADD_PKG]) - uninstalled_latest = self.run_function("pkg.latest_version", [ADD_PKG]) - - self.run_function("pkg.install", [ADD_PKG]) - installed_latest = self.run_function("pkg.latest_version", [ADD_PKG]) - version = self.run_function("pkg.version", [ADD_PKG]) - try: - self.assertTrue(isinstance(uninstalled_latest, str)) - self.assertEqual(installed_latest, version) - except AssertionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - except CommandExecutionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - - @pytest.mark.slow_test - def test_refresh_db(self): - """ - Integration test to ensure pkg.refresh_db works with brew - """ - refresh_brew = self.run_function("pkg.refresh_db") - self.assertTrue(refresh_brew) - - @pytest.mark.slow_test - def test_list_upgrades(self): - """ - Test pkg.list_upgrades: data is in the form {'name1': 'version1', - 'name2': 'version2', ... } - """ - try: - upgrades = self.run_function("pkg.list_upgrades") - try: - self.assertTrue(isinstance(upgrades, dict)) - if upgrades: - for name in upgrades: - self.assertTrue(isinstance(name, str)) - self.assertTrue(isinstance(upgrades[name], str)) - except AssertionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - except CommandExecutionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - - @pytest.mark.slow_test - def test_info_installed(self): - """ - Test pkg.info_installed: info returned has certain fields used by - mac_brew.latest_version - """ - try: - self.run_function("pkg.install", [ADD_PKG]) - info = self.run_function("pkg.info_installed", [ADD_PKG]) - try: - self.assertTrue(ADD_PKG in info) - self.assertTrue("versions" in info[ADD_PKG]) - self.assertTrue("revision" in info[ADD_PKG]) - self.assertTrue("stable" in info[ADD_PKG]["versions"]) - except AssertionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - except CommandExecutionError: - self.run_function("pkg.remove", [ADD_PKG]) - raise - - def tearDown(self): - """ - Clean up after tests - """ - pkg_list = self.run_function("pkg.list_pkgs") - - # Remove any installed packages - if ADD_PKG in pkg_list: - self.run_function("pkg.remove", [ADD_PKG]) - if DEL_PKG in pkg_list: - self.run_function("pkg.remove", [DEL_PKG]) diff --git a/tests/integration/modules/test_mac_desktop.py b/tests/integration/modules/test_mac_desktop.py deleted file mode 100644 index 73f12c18e539..000000000000 --- a/tests/integration/modules/test_mac_desktop.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -Integration tests for the mac_desktop execution module. -""" - -import pytest - -from tests.support.case import ModuleCase - - -@pytest.mark.destructive_test -@pytest.mark.skip_if_not_root -@pytest.mark.skip_unless_on_darwin -class MacDesktopTestCase(ModuleCase): - """ - Integration tests for the mac_desktop module. - """ - - def test_get_output_volume(self): - """ - Tests the return of get_output_volume. - """ - ret = self.run_function("desktop.get_output_volume") - self.assertIsNotNone(ret) - - @pytest.mark.slow_test - def test_set_output_volume(self): - """ - Tests the return of set_output_volume. - """ - current_vol = self.run_function("desktop.get_output_volume") - to_set = 10 - if current_vol == str(to_set): - to_set += 2 - new_vol = self.run_function("desktop.set_output_volume", [str(to_set)]) - check_vol = self.run_function("desktop.get_output_volume") - self.assertEqual(new_vol, check_vol) - - # Set volume back to what it was before - self.run_function("desktop.set_output_volume", [current_vol]) - - def test_screensaver(self): - """ - Tests the return of the screensaver function. - """ - self.assertTrue(self.run_function("desktop.screensaver")) - - def test_lock(self): - """ - Tests the return of the lock function. - """ - self.assertTrue(self.run_function("desktop.lock")) - - @pytest.mark.slow_test - def test_say(self): - """ - Tests the return of the say function. - """ - self.assertTrue(self.run_function("desktop.say", ["hello", "world"])) diff --git a/tests/integration/modules/test_mac_group.py b/tests/integration/modules/test_mac_group.py deleted file mode 100644 index 46be79667f85..000000000000 --- a/tests/integration/modules/test_mac_group.py +++ /dev/null @@ -1,177 +0,0 @@ -""" - :codeauthor: Nicole Thomas -""" - -import pytest -from saltfactories.utils import random_string - -from salt.exceptions import CommandExecutionError -from tests.support.case import ModuleCase - -# Create group name strings for tests -ADD_GROUP = random_string("RS-", lowercase=False) -DEL_GROUP = random_string("RS-", lowercase=False) -CHANGE_GROUP = random_string("RS-", lowercase=False) -ADD_USER = random_string("RS-", lowercase=False) -REP_USER_GROUP = random_string("RS-", lowercase=False) - - -@pytest.mark.skip_if_not_root -@pytest.mark.destructive_test -@pytest.mark.skip_unless_on_darwin -class MacGroupModuleTest(ModuleCase): - """ - Integration tests for the mac_group module - """ - - def setUp(self): - """ - Sets up test requirements - """ - os_grain = self.run_function("grains.item", ["kernel"]) - if os_grain["kernel"] not in "Darwin": - self.skipTest("Test not applicable to '{kernel}' kernel".format(**os_grain)) - - @pytest.mark.slow_test - def test_mac_group_add(self): - """ - Tests the add group function - """ - try: - self.run_function("group.add", [ADD_GROUP, 3456]) - group_info = self.run_function("group.info", [ADD_GROUP]) - self.assertEqual(group_info["name"], ADD_GROUP) - except CommandExecutionError: - self.run_function("group.delete", [ADD_GROUP]) - raise - - @pytest.mark.slow_test - def test_mac_group_delete(self): - """ - Tests the delete group function - """ - # Create a group to delete - If unsuccessful, skip the test - if self.run_function("group.add", [DEL_GROUP, 4567]) is not True: - self.run_function("group.delete", [DEL_GROUP]) - self.skipTest("Failed to create a group to delete") - - # Now try to delete the added group - ret = self.run_function("group.delete", [DEL_GROUP]) - self.assertTrue(ret) - - @pytest.mark.slow_test - def test_mac_group_chgid(self): - """ - Tests changing the group id - """ - # Create a group to delete - If unsuccessful, skip the test - if self.run_function("group.add", [CHANGE_GROUP, 5678]) is not True: - self.run_function("group.delete", [CHANGE_GROUP]) - self.skipTest("Failed to create a group to manipulate") - - try: - self.run_function("group.chgid", [CHANGE_GROUP, 6789]) - group_info = self.run_function("group.info", [CHANGE_GROUP]) - self.assertEqual(group_info["gid"], 6789) - except AssertionError: - self.run_function("group.delete", [CHANGE_GROUP]) - raise - - @pytest.mark.slow_test - def test_mac_adduser(self): - """ - Tests adding user to the group - """ - # Create a group to use for test - If unsuccessful, skip the test - if self.run_function("group.add", [ADD_GROUP, 5678]) is not True: - self.run_function("group.delete", [ADD_GROUP]) - self.skipTest("Failed to create a group to manipulate") - - try: - self.run_function("group.adduser", [ADD_GROUP, ADD_USER]) - group_info = self.run_function("group.info", [ADD_GROUP]) - self.assertEqual(ADD_USER, "".join(group_info["members"])) - except AssertionError: - self.run_function("group.delete", [ADD_GROUP]) - raise - - @pytest.mark.slow_test - def test_mac_deluser(self): - """ - Test deleting user from a group - """ - # Create a group to use for test - If unsuccessful, skip the test - if ( - self.run_function("group.add", [ADD_GROUP, 5678]) - and self.run_function("group.adduser", [ADD_GROUP, ADD_USER]) is not True - ): - self.run_function("group.delete", [ADD_GROUP]) - self.skipTest("Failed to create a group to manipulate") - - delusr = self.run_function("group.deluser", [ADD_GROUP, ADD_USER]) - self.assertTrue(delusr) - - group_info = self.run_function("group.info", [ADD_GROUP]) - self.assertNotIn(ADD_USER, "".join(group_info["members"])) - - @pytest.mark.slow_test - def test_mac_members(self): - """ - Test replacing members of a group - """ - if ( - self.run_function("group.add", [ADD_GROUP, 5678]) - and self.run_function("group.adduser", [ADD_GROUP, ADD_USER]) is not True - ): - self.run_function("group.delete", [ADD_GROUP]) - self.skipTest( - "Failed to create the {} group or add user {} to group " - "to manipulate".format(ADD_GROUP, ADD_USER) - ) - - rep_group_mem = self.run_function("group.members", [ADD_GROUP, REP_USER_GROUP]) - self.assertTrue(rep_group_mem) - - # ensure new user is added to group and previous user is removed - group_info = self.run_function("group.info", [ADD_GROUP]) - self.assertIn(REP_USER_GROUP, str(group_info["members"])) - self.assertNotIn(ADD_USER, str(group_info["members"])) - - @pytest.mark.slow_test - def test_mac_getent(self): - """ - Test returning info on all groups - """ - if ( - self.run_function("group.add", [ADD_GROUP, 5678]) - and self.run_function("group.adduser", [ADD_GROUP, ADD_USER]) is not True - ): - self.run_function("group.delete", [ADD_GROUP]) - self.skipTest( - "Failed to create the {} group or add user {} to group " - "to manipulate".format(ADD_GROUP, ADD_USER) - ) - - getinfo = self.run_function("group.getent") - self.assertTrue(getinfo) - self.assertIn(ADD_GROUP, str(getinfo)) - self.assertIn(ADD_USER, str(getinfo)) - - def tearDown(self): - """ - Clean up after tests - """ - # Delete ADD_GROUP - add_info = self.run_function("group.info", [ADD_GROUP]) - if add_info: - self.run_function("group.delete", [ADD_GROUP]) - - # Delete DEL_GROUP if something failed - del_info = self.run_function("group.info", [DEL_GROUP]) - if del_info: - self.run_function("group.delete", [DEL_GROUP]) - - # Delete CHANGE_GROUP - change_info = self.run_function("group.info", [CHANGE_GROUP]) - if change_info: - self.run_function("group.delete", [CHANGE_GROUP]) diff --git a/tests/integration/modules/test_mac_keychain.py b/tests/integration/modules/test_mac_keychain.py deleted file mode 100644 index afd195524f36..000000000000 --- a/tests/integration/modules/test_mac_keychain.py +++ /dev/null @@ -1,106 +0,0 @@ -""" -Validate the mac-keychain module -""" - -import os - -import pytest - -from salt.exceptions import CommandExecutionError -from tests.support.case import ModuleCase -from tests.support.runtests import RUNTIME_VARS - - -@pytest.mark.destructive_test -@pytest.mark.skip_if_not_root -@pytest.mark.skip_unless_on_darwin -class MacKeychainModuleTest(ModuleCase): - """ - Integration tests for the mac_keychain module - """ - - @classmethod - def setUpClass(cls): - cls.cert = os.path.join( - RUNTIME_VARS.FILES, "file", "base", "certs", "salttest.p12" - ) - cls.cert_alias = "Salt Test" - cls.passwd = "salttest" - - def tearDown(self): - """ - Clean up after tests - """ - # Remove the salttest cert, if left over. - certs_list = self.run_function("keychain.list_certs") - if self.cert_alias in certs_list: - self.run_function("keychain.uninstall", [self.cert_alias]) - - @pytest.mark.slow_test - def test_mac_keychain_install(self): - """ - Tests that attempts to install a certificate - """ - install_cert = self.run_function("keychain.install", [self.cert, self.passwd]) - self.assertTrue(install_cert) - - # check to ensure the cert was installed - certs_list = self.run_function("keychain.list_certs") - self.assertIn(self.cert_alias, certs_list) - - @pytest.mark.slow_test - def test_mac_keychain_uninstall(self): - """ - Tests that attempts to uninstall a certificate - """ - self.run_function("keychain.install", [self.cert, self.passwd]) - certs_list = self.run_function("keychain.list_certs") - - if self.cert_alias not in certs_list: - self.run_function("keychain.uninstall", [self.cert_alias]) - self.skipTest("Failed to install keychain") - - # uninstall cert - self.run_function("keychain.uninstall", [self.cert_alias]) - certs_list = self.run_function("keychain.list_certs") - - # check to ensure the cert was uninstalled - try: - self.assertNotIn(self.cert_alias, str(certs_list)) - except CommandExecutionError: - self.run_function("keychain.uninstall", [self.cert_alias]) - - @pytest.mark.slow_test - def test_mac_keychain_get_friendly_name(self): - """ - Test that attempts to get friendly name of a cert - """ - self.run_function("keychain.install", [self.cert, self.passwd]) - certs_list = self.run_function("keychain.list_certs") - if self.cert_alias not in certs_list: - self.run_function("keychain.uninstall", [self.cert_alias]) - self.skipTest("Failed to install keychain") - - get_name = self.run_function( - "keychain.get_friendly_name", [self.cert, self.passwd] - ) - self.assertEqual(get_name, self.cert_alias) - - @pytest.mark.slow_test - def test_mac_keychain_get_default_keychain(self): - """ - Test that attempts to get the default keychain - """ - salt_get_keychain = self.run_function("keychain.get_default_keychain") - sys_get_keychain = self.run_function( - "cmd.run", ["security default-keychain -d user"] - ) - self.assertEqual(salt_get_keychain, sys_get_keychain) - - def test_mac_keychain_list_certs(self): - """ - Test that attempts to list certs - """ - cert_default = "com.apple.systemdefault" - certs = self.run_function("keychain.list_certs") - self.assertIn(cert_default, certs) diff --git a/tests/integration/modules/test_mac_portspkg.py b/tests/integration/modules/test_mac_portspkg.py deleted file mode 100644 index 35ebe3735b6e..000000000000 --- a/tests/integration/modules/test_mac_portspkg.py +++ /dev/null @@ -1,104 +0,0 @@ -""" -integration tests for mac_ports -""" - -import pytest - -from tests.support.case import ModuleCase - - -@pytest.mark.skip_if_not_root -@pytest.mark.skip_if_binaries_missing("port") -@pytest.mark.skip_unless_on_darwin -class MacPortsModuleTest(ModuleCase): - """ - Validate the mac_ports module - """ - - AGREE_INSTALLED = False - - def setUp(self): - """ - Get current settings - """ - self.AGREE_INSTALLED = "agree" in self.run_function("pkg.list_pkgs") - self.run_function("pkg.refresh_db") - - def tearDown(self): - """ - Reset to original settings - """ - if not self.AGREE_INSTALLED: - self.run_function("pkg.remove", ["agree"]) - - @pytest.mark.destructive_test - def test_list_pkgs(self): - """ - Test pkg.list_pkgs - """ - self.run_function("pkg.install", ["agree"]) - self.assertIsInstance(self.run_function("pkg.list_pkgs"), dict) - self.assertIn("agree", self.run_function("pkg.list_pkgs")) - - @pytest.mark.destructive_test - def test_latest_version(self): - """ - Test pkg.latest_version - """ - self.run_function("pkg.install", ["agree"]) - result = self.run_function("pkg.latest_version", ["agree"], refresh=False) - self.assertIsInstance(result, dict) - self.assertIn("agree", result) - - @pytest.mark.destructive_test - def test_remove(self): - """ - Test pkg.remove - """ - self.run_function("pkg.install", ["agree"]) - removed = self.run_function("pkg.remove", ["agree"]) - self.assertIsInstance(removed, dict) - self.assertIn("agree", removed) - - @pytest.mark.destructive_test - def test_install(self): - """ - Test pkg.install - """ - self.run_function("pkg.remove", ["agree"]) - installed = self.run_function("pkg.install", ["agree"]) - self.assertIsInstance(installed, dict) - self.assertIn("agree", installed) - - def test_list_upgrades(self): - """ - Test pkg.list_upgrades - """ - self.assertIsInstance( - self.run_function("pkg.list_upgrades", refresh=False), dict - ) - - @pytest.mark.destructive_test - def test_upgrade_available(self): - """ - Test pkg.upgrade_available - """ - self.run_function("pkg.install", ["agree"]) - self.assertFalse( - self.run_function("pkg.upgrade_available", ["agree"], refresh=False) - ) - - def test_refresh_db(self): - """ - Test pkg.refresh_db - """ - self.assertTrue(self.run_function("pkg.refresh_db")) - - @pytest.mark.destructive_test - def test_upgrade(self): - """ - Test pkg.upgrade - """ - results = self.run_function("pkg.upgrade", refresh=False) - self.assertIsInstance(results, dict) - self.assertTrue(results["result"]) diff --git a/tests/integration/modules/test_mac_power.py b/tests/integration/modules/test_mac_power.py deleted file mode 100644 index aa0de2667077..000000000000 --- a/tests/integration/modules/test_mac_power.py +++ /dev/null @@ -1,345 +0,0 @@ -""" -integration tests for mac_power -""" - -import pytest - -from tests.support.case import ModuleCase - - -@pytest.mark.flaky(max_runs=10) -@pytest.mark.skip_unless_on_darwin -@pytest.mark.skip_if_binaries_missing("systemsetup") -@pytest.mark.skip_if_not_root -@pytest.mark.slow_test -class MacPowerModuleTest(ModuleCase): - """ - Validate the mac_power module - """ - - def setUp(self): - """ - Get current settings - """ - # Get current settings - self.COMPUTER_SLEEP = self.run_function("power.get_computer_sleep") - self.DISPLAY_SLEEP = self.run_function("power.get_display_sleep") - self.HARD_DISK_SLEEP = self.run_function("power.get_harddisk_sleep") - - def tearDown(self): - """ - Reset to original settings - """ - self.run_function("power.set_computer_sleep", [self.COMPUTER_SLEEP]) - self.run_function("power.set_display_sleep", [self.DISPLAY_SLEEP]) - self.run_function("power.set_harddisk_sleep", [self.HARD_DISK_SLEEP]) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_computer_sleep(self): - """ - Test power.get_computer_sleep - Test power.set_computer_sleep - """ - - # Normal Functionality - self.assertTrue(self.run_function("power.set_computer_sleep", [90])) - self.assertEqual( - self.run_function("power.get_computer_sleep"), "after 90 minutes" - ) - self.assertTrue(self.run_function("power.set_computer_sleep", ["Off"])) - self.assertEqual(self.run_function("power.get_computer_sleep"), "Never") - - # Test invalid input - self.assertIn( - "Invalid String Value for Minutes", - self.run_function("power.set_computer_sleep", ["spongebob"]), - ) - self.assertIn( - "Invalid Integer Value for Minutes", - self.run_function("power.set_computer_sleep", [0]), - ) - self.assertIn( - "Invalid Integer Value for Minutes", - self.run_function("power.set_computer_sleep", [181]), - ) - self.assertIn( - "Invalid Boolean Value for Minutes", - self.run_function("power.set_computer_sleep", [True]), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_display_sleep(self): - """ - Test power.get_display_sleep - Test power.set_display_sleep - """ - - # Normal Functionality - self.assertTrue(self.run_function("power.set_display_sleep", [90])) - self.assertEqual( - self.run_function("power.get_display_sleep"), "after 90 minutes" - ) - self.assertTrue(self.run_function("power.set_display_sleep", ["Off"])) - self.assertEqual(self.run_function("power.get_display_sleep"), "Never") - - # Test invalid input - self.assertIn( - "Invalid String Value for Minutes", - self.run_function("power.set_display_sleep", ["spongebob"]), - ) - self.assertIn( - "Invalid Integer Value for Minutes", - self.run_function("power.set_display_sleep", [0]), - ) - self.assertIn( - "Invalid Integer Value for Minutes", - self.run_function("power.set_display_sleep", [181]), - ) - self.assertIn( - "Invalid Boolean Value for Minutes", - self.run_function("power.set_display_sleep", [True]), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_harddisk_sleep(self): - """ - Test power.get_harddisk_sleep - Test power.set_harddisk_sleep - """ - - # Normal Functionality - self.assertTrue(self.run_function("power.set_harddisk_sleep", [90])) - self.assertEqual( - self.run_function("power.get_harddisk_sleep"), "after 90 minutes" - ) - self.assertTrue(self.run_function("power.set_harddisk_sleep", ["Off"])) - self.assertEqual(self.run_function("power.get_harddisk_sleep"), "Never") - - # Test invalid input - self.assertIn( - "Invalid String Value for Minutes", - self.run_function("power.set_harddisk_sleep", ["spongebob"]), - ) - self.assertIn( - "Invalid Integer Value for Minutes", - self.run_function("power.set_harddisk_sleep", [0]), - ) - self.assertIn( - "Invalid Integer Value for Minutes", - self.run_function("power.set_harddisk_sleep", [181]), - ) - self.assertIn( - "Invalid Boolean Value for Minutes", - self.run_function("power.set_harddisk_sleep", [True]), - ) - - @pytest.mark.slow_test - def test_restart_freeze(self): - """ - Test power.get_restart_freeze - Test power.set_restart_freeze - """ - # Normal Functionality - self.assertTrue(self.run_function("power.set_restart_freeze", ["on"])) - self.assertTrue(self.run_function("power.get_restart_freeze")) - # This will return False because mac fails to actually make the change - self.assertFalse(self.run_function("power.set_restart_freeze", ["off"])) - # Even setting to off returns true, it actually is never set - # This is an apple bug - self.assertTrue(self.run_function("power.get_restart_freeze")) - - -@pytest.mark.flaky(max_runs=10) -@pytest.mark.skip_unless_on_darwin -@pytest.mark.skip_if_binaries_missing("systemsetup") -@pytest.mark.skip_if_not_root -class MacPowerModuleTestSleepOnPowerButton(ModuleCase): - """ - Test power.get_sleep_on_power_button - Test power.set_sleep_on_power_button - """ - - SLEEP_ON_BUTTON = None - - def setUp(self): - """ - Check if function is available - Get existing value - """ - # Is the function available - ret = self.run_function("power.get_sleep_on_power_button") - if isinstance(ret, bool): - self.SLEEP_ON_BUTTON = self.run_function("power.get_sleep_on_power_button") - - def tearDown(self): - """ - Reset to original value - """ - if self.SLEEP_ON_BUTTON is not None: - self.run_function("power.set_sleep_on_power_button", [self.SLEEP_ON_BUTTON]) - - @pytest.mark.slow_test - def test_sleep_on_power_button(self): - """ - Test power.get_sleep_on_power_button - Test power.set_sleep_on_power_button - """ - # If available on this system, test it - if self.SLEEP_ON_BUTTON is None: - # Check for not available - ret = self.run_function("power.get_sleep_on_power_button") - self.assertIn("Error", ret) - else: - self.assertTrue( - self.run_function("power.set_sleep_on_power_button", ["on"]) - ) - self.assertTrue(self.run_function("power.get_sleep_on_power_button")) - self.assertTrue( - self.run_function("power.set_sleep_on_power_button", ["off"]) - ) - self.assertFalse(self.run_function("power.get_sleep_on_power_button")) - - -@pytest.mark.flaky(max_runs=10) -@pytest.mark.skip_unless_on_darwin -@pytest.mark.skip_if_binaries_missing("systemsetup") -@pytest.mark.skip_if_not_root -class MacPowerModuleTestRestartPowerFailure(ModuleCase): - """ - Test power.get_restart_power_failure - Test power.set_restart_power_failure - """ - - RESTART_POWER = None - - def setUp(self): - """ - Check if function is available - Get existing value - """ - # Is the function available - ret = self.run_function("power.get_restart_power_failure") - if isinstance(ret, bool): - self.RESTART_POWER = ret - - def tearDown(self): - """ - Reset to original value - """ - if self.RESTART_POWER is not None: - self.run_function("power.set_sleep_on_power_button", [self.RESTART_POWER]) - - def test_restart_power_failure(self): - """ - Test power.get_restart_power_failure - Test power.set_restart_power_failure - """ - # If available on this system, test it - if self.RESTART_POWER is None: - # Check for not available - ret = self.run_function("power.get_restart_power_failure") - self.assertIn("Error", ret) - else: - self.assertTrue( - self.run_function("power.set_restart_power_failure", ["on"]) - ) - self.assertTrue(self.run_function("power.get_restart_power_failure")) - self.assertTrue( - self.run_function("power.set_restart_power_failure", ["off"]) - ) - self.assertFalse(self.run_function("power.get_restart_power_failure")) - - -@pytest.mark.flaky(max_runs=10) -@pytest.mark.skip_unless_on_darwin -@pytest.mark.skip_if_binaries_missing("systemsetup") -@pytest.mark.skip_if_not_root -class MacPowerModuleTestWakeOnNet(ModuleCase): - """ - Test power.get_wake_on_network - Test power.set_wake_on_network - """ - - WAKE_ON_NET = None - - def setUp(self): - """ - Check if function is available - Get existing value - """ - # Is the function available - ret = self.run_function("power.get_wake_on_network") - if isinstance(ret, bool): - self.WAKE_ON_NET = ret - - def tearDown(self): - """ - Reset to original value - """ - if self.WAKE_ON_NET is not None: - self.run_function("power.set_wake_on_network", [self.WAKE_ON_NET]) - - def test_wake_on_network(self): - """ - Test power.get_wake_on_network - Test power.set_wake_on_network - """ - # If available on this system, test it - if self.WAKE_ON_NET is None: - # Check for not available - ret = self.run_function("power.get_wake_on_network") - self.assertIn("Error", ret) - else: - self.assertTrue(self.run_function("power.set_wake_on_network", ["on"])) - self.assertTrue(self.run_function("power.get_wake_on_network")) - self.assertTrue(self.run_function("power.set_wake_on_network", ["off"])) - self.assertFalse(self.run_function("power.get_wake_on_network")) - - -@pytest.mark.flaky(max_runs=10) -@pytest.mark.skip_unless_on_darwin -@pytest.mark.skip_if_binaries_missing("systemsetup") -@pytest.mark.skip_if_not_root -class MacPowerModuleTestWakeOnModem(ModuleCase): - """ - Test power.get_wake_on_modem - Test power.set_wake_on_modem - """ - - WAKE_ON_MODEM = None - - def setUp(self): - """ - Check if function is available - Get existing value - """ - # Is the function available - ret = self.run_function("power.get_wake_on_modem") - if isinstance(ret, bool): - self.WAKE_ON_MODEM = ret - - def tearDown(self): - """ - Reset to original value - """ - if self.WAKE_ON_MODEM is not None: - self.run_function("power.set_wake_on_modem", [self.WAKE_ON_MODEM]) - - def test_wake_on_modem(self): - """ - Test power.get_wake_on_modem - Test power.set_wake_on_modem - """ - # If available on this system, test it - if self.WAKE_ON_MODEM is None: - # Check for not available - ret = self.run_function("power.get_wake_on_modem") - self.assertIn("Error", ret) - else: - self.assertTrue(self.run_function("power.set_wake_on_modem", ["on"])) - self.assertTrue(self.run_function("power.get_wake_on_modem")) - self.assertTrue(self.run_function("power.set_wake_on_modem", ["off"])) - self.assertFalse(self.run_function("power.get_wake_on_modem")) diff --git a/tests/integration/modules/test_mac_service.py b/tests/integration/modules/test_mac_service.py deleted file mode 100644 index d4022cab535e..000000000000 --- a/tests/integration/modules/test_mac_service.py +++ /dev/null @@ -1,233 +0,0 @@ -""" -integration tests for mac_service -""" - -import plistlib - -import pytest - -import salt.utils.files -from tests.support.case import ModuleCase - - -@pytest.mark.skip_if_not_root -@pytest.mark.skip_if_binaries_missing("launchctl", "plutil") -@pytest.mark.skip_unless_on_darwin -class MacServiceModuleTest(ModuleCase): - """ - Validate the mac_service module - """ - - SERVICE_NAME = "com.salt.integration.test" - SERVICE_PATH = "/Library/LaunchDaemons/com.salt.integration.test.plist" - - def setUp(self): - """ - setup our test launch service. - """ - service_data = { - "KeepAlive": True, - "Label": self.SERVICE_NAME, - "ProgramArguments": ["/bin/sleep", "1000"], - "RunAtLoad": True, - } - with salt.utils.files.fopen(self.SERVICE_PATH, "wb") as fp: - plistlib.dump(service_data, fp) - self.run_function("service.enable", [self.SERVICE_NAME]) - self.run_function("service.start", [self.SERVICE_NAME]) - - def tearDown(self): - """ - stop and remove our test service. - """ - self.run_function("service.stop", [self.SERVICE_NAME]) - salt.utils.files.safe_rm(self.SERVICE_PATH) - - @pytest.mark.slow_test - def test_show(self): - """ - Test service.show - """ - # Existing Service - service_info = self.run_function("service.show", [self.SERVICE_NAME]) - self.assertIsInstance(service_info, dict) - self.assertEqual(service_info["plist"]["Label"], self.SERVICE_NAME) - - # Missing Service - self.assertIn( - "Service not found", self.run_function("service.show", ["spongebob"]) - ) - - @pytest.mark.slow_test - def test_launchctl(self): - """ - Test service.launchctl - """ - # Expected Functionality - self.assertTrue( - self.run_function("service.launchctl", ["error", "bootstrap", 64]) - ) - self.assertEqual( - self.run_function( - "service.launchctl", ["error", "bootstrap", 64], return_stdout=True - ), - "64: unknown error code", - ) - - # Raise an error - self.assertIn( - "Failed to error service", - self.run_function("service.launchctl", ["error", "bootstrap"]), - ) - - @pytest.mark.slow_test - def test_list(self): - """ - Test service.list - """ - # Expected Functionality - self.assertIn("PID", self.run_function("service.list")) - self.assertIn("{", self.run_function("service.list", [self.SERVICE_NAME])) - - # Service not found - self.assertIn( - "Service not found", self.run_function("service.list", ["spongebob"]) - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_enable(self): - """ - Test service.enable - """ - self.assertTrue(self.run_function("service.enable", [self.SERVICE_NAME])) - - self.assertIn( - "Service not found", self.run_function("service.enable", ["spongebob"]) - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_disable(self): - """ - Test service.disable - """ - self.assertTrue(self.run_function("service.disable", [self.SERVICE_NAME])) - - self.assertIn( - "Service not found", self.run_function("service.disable", ["spongebob"]) - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_start(self): - """ - Test service.start - Test service.stop - Test service.status - """ - self.assertTrue(self.run_function("service.start", [self.SERVICE_NAME])) - - self.assertIn( - "Service not found", self.run_function("service.start", ["spongebob"]) - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_stop(self): - """ - Test service.stop - """ - self.assertTrue(self.run_function("service.stop", [self.SERVICE_NAME])) - - self.assertIn( - "Service not found", self.run_function("service.stop", ["spongebob"]) - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_status(self): - """ - Test service.status - """ - # A running service - self.assertTrue(self.run_function("service.start", [self.SERVICE_NAME])) - self.assertTrue(self.run_function("service.status", [self.SERVICE_NAME])) - - # A stopped service - self.assertTrue(self.run_function("service.stop", [self.SERVICE_NAME])) - self.assertFalse(self.run_function("service.status", [self.SERVICE_NAME])) - - # Service not found - self.assertFalse(self.run_function("service.status", ["spongebob"])) - - @pytest.mark.slow_test - def test_available(self): - """ - Test service.available - """ - self.assertTrue(self.run_function("service.available", [self.SERVICE_NAME])) - self.assertFalse(self.run_function("service.available", ["spongebob"])) - - @pytest.mark.slow_test - def test_missing(self): - """ - Test service.missing - """ - self.assertFalse(self.run_function("service.missing", [self.SERVICE_NAME])) - self.assertTrue(self.run_function("service.missing", ["spongebob"])) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_enabled(self): - """ - Test service.enabled - """ - self.assertTrue(self.run_function("service.enabled", [self.SERVICE_NAME])) - self.assertTrue(self.run_function("service.start", [self.SERVICE_NAME])) - - self.assertTrue(self.run_function("service.enabled", [self.SERVICE_NAME])) - self.assertTrue(self.run_function("service.stop", [self.SERVICE_NAME])) - - self.assertTrue(self.run_function("service.enabled", ["spongebob"])) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_disabled(self): - """ - Test service.disabled - """ - self.assertTrue(self.run_function("service.start", [self.SERVICE_NAME])) - self.assertFalse(self.run_function("service.disabled", [self.SERVICE_NAME])) - - self.assertTrue(self.run_function("service.disable", [self.SERVICE_NAME])) - self.assertTrue(self.run_function("service.disabled", [self.SERVICE_NAME])) - self.assertTrue(self.run_function("service.enable", [self.SERVICE_NAME])) - self.assertIn( - "Service not found", self.run_function("service.stop", ["spongebob"]) - ) - - @pytest.mark.slow_test - def test_get_all(self): - """ - Test service.get_all - """ - services = self.run_function("service.get_all") - self.assertIsInstance(services, list) - self.assertIn(self.SERVICE_NAME, services) - - @pytest.mark.slow_test - def test_get_enabled(self): - """ - Test service.get_enabled - """ - services = self.run_function("service.get_enabled") - self.assertIsInstance(services, list) - self.assertIn(self.SERVICE_NAME, services) - - @pytest.mark.slow_test - def test_service_laoded(self): - """ - Test service.get_enabled - """ - self.assertTrue(self.run_function("service.loaded", [self.SERVICE_NAME])) diff --git a/tests/integration/modules/test_mac_shadow.py b/tests/integration/modules/test_mac_shadow.py deleted file mode 100644 index bb859ffbf099..000000000000 --- a/tests/integration/modules/test_mac_shadow.py +++ /dev/null @@ -1,226 +0,0 @@ -""" -integration tests for mac_shadow -""" - -import datetime - -import pytest -from saltfactories.utils import random_string - -from tests.support.case import ModuleCase - -TEST_USER = random_string("RS-", lowercase=False) -NO_USER = random_string("RS-", lowercase=False) - - -@pytest.mark.skip_if_binaries_missing("dscl", "pwpolicy") -@pytest.mark.skip_if_not_root -@pytest.mark.skip_unless_on_darwin -class MacShadowModuleTest(ModuleCase): - """ - Validate the mac_shadow module - """ - - def setUp(self): - """ - Get current settings - """ - self.run_function("user.add", [TEST_USER]) - - def tearDown(self): - """ - Reset to original settings - """ - self.run_function("user.delete", [TEST_USER]) - - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_info(self): - """ - Test shadow.info - """ - # Correct Functionality - ret = self.run_function("shadow.info", [TEST_USER]) - self.assertEqual(ret["name"], TEST_USER) - - # User does not exist - ret = self.run_function("shadow.info", [NO_USER]) - self.assertEqual(ret["name"], "") - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_account_created(self): - """ - Test shadow.get_account_created - """ - # Correct Functionality - text_date = self.run_function("shadow.get_account_created", [TEST_USER]) - self.assertNotEqual(text_date, "Invalid Timestamp") - obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") - self.assertIsInstance(obj_date, datetime.date) - - # User does not exist - self.assertEqual( - self.run_function("shadow.get_account_created", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_get_last_change(self): - """ - Test shadow.get_last_change - """ - # Correct Functionality - text_date = self.run_function("shadow.get_last_change", [TEST_USER]) - self.assertNotEqual(text_date, "Invalid Timestamp") - obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") - self.assertIsInstance(obj_date, datetime.date) - - # User does not exist - self.assertEqual( - self.run_function("shadow.get_last_change", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_get_login_failed_last(self): - """ - Test shadow.get_login_failed_last - """ - # Correct Functionality - text_date = self.run_function("shadow.get_login_failed_last", [TEST_USER]) - self.assertNotEqual(text_date, "Invalid Timestamp") - obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") - self.assertIsInstance(obj_date, datetime.date) - - # User does not exist - self.assertEqual( - self.run_function("shadow.get_login_failed_last", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_get_login_failed_count(self): - """ - Test shadow.get_login_failed_count - """ - # Correct Functionality - self.assertEqual( - self.run_function("shadow.get_login_failed_count", [TEST_USER]), "0" - ) - - # User does not exist - self.assertEqual( - self.run_function("shadow.get_login_failed_count", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_set_maxdays(self): - """ - Test shadow.get_maxdays - Test shadow.set_maxdays - """ - # Correct Functionality - self.assertTrue(self.run_function("shadow.set_maxdays", [TEST_USER, 20])) - self.assertEqual(self.run_function("shadow.get_maxdays", [TEST_USER]), 20) - - # User does not exist - self.assertEqual( - self.run_function("shadow.set_maxdays", [NO_USER, 7]), - "ERROR: User not found: {}".format(NO_USER), - ) - self.assertEqual( - self.run_function("shadow.get_maxdays", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_set_change(self): - """ - Test shadow.get_change - Test shadow.set_change - """ - # Correct Functionality - self.assertTrue( - self.run_function("shadow.set_change", [TEST_USER, "02/11/2011"]) - ) - self.assertEqual( - self.run_function("shadow.get_change", [TEST_USER]), "02/11/2011" - ) - - # User does not exist - self.assertEqual( - self.run_function("shadow.set_change", [NO_USER, "02/11/2012"]), - "ERROR: User not found: {}".format(NO_USER), - ) - self.assertEqual( - self.run_function("shadow.get_change", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_set_expire(self): - """ - Test shadow.get_expire - Test shadow.set_expire - """ - # Correct Functionality - self.assertTrue( - self.run_function("shadow.set_expire", [TEST_USER, "02/11/2011"]) - ) - self.assertEqual( - self.run_function("shadow.get_expire", [TEST_USER]), "02/11/2011" - ) - - # User does not exist - self.assertEqual( - self.run_function("shadow.set_expire", [NO_USER, "02/11/2012"]), - "ERROR: User not found: {}".format(NO_USER), - ) - self.assertEqual( - self.run_function("shadow.get_expire", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_del_password(self): - """ - Test shadow.del_password - """ - # Correct Functionality - self.assertTrue(self.run_function("shadow.del_password", [TEST_USER])) - self.assertEqual(self.run_function("shadow.info", [TEST_USER])["passwd"], "*") - - # User does not exist - self.assertEqual( - self.run_function("shadow.del_password", [NO_USER]), - "ERROR: User not found: {}".format(NO_USER), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_set_password(self): - """ - Test shadow.set_password - """ - # Correct Functionality - self.assertTrue( - self.run_function("shadow.set_password", [TEST_USER, "Pa$$W0rd"]) - ) - - # User does not exist - self.assertEqual( - self.run_function("shadow.set_password", [NO_USER, "P@SSw0rd"]), - "ERROR: User not found: {}".format(NO_USER), - ) diff --git a/tests/integration/modules/test_mac_softwareupdate.py b/tests/integration/modules/test_mac_softwareupdate.py deleted file mode 100644 index a8094969c358..000000000000 --- a/tests/integration/modules/test_mac_softwareupdate.py +++ /dev/null @@ -1,170 +0,0 @@ -""" -integration tests for mac_softwareupdate -""" - -import pytest - -from tests.support.case import ModuleCase - - -@pytest.mark.skip_if_not_root -@pytest.mark.skip_if_binaries_missing("softwareupdate") -@pytest.mark.skip_unless_on_darwin -class MacSoftwareUpdateModuleTest(ModuleCase): - """ - Validate the mac_softwareupdate module - """ - - IGNORED_LIST = [] - SCHEDULE = False - CATALOG = "" - - def setUp(self): - """ - Get current settings - """ - self.IGNORED_LIST = self.run_function("softwareupdate.list_ignored") - self.SCHEDULE = self.run_function("softwareupdate.schedule") - self.CATALOG = self.run_function("softwareupdate.get_catalog") - - super().setUp() - - def tearDown(self): - """ - Reset to original settings - """ - if self.IGNORED_LIST: - for item in self.IGNORED_LIST: - self.run_function("softwareupdate.ignore", [item]) - else: - self.run_function("softwareupdate.reset_ignored") - - self.run_function("softwareupdate.schedule", [self.SCHEDULE]) - - if self.CATALOG == "Default": - self.run_function("softwareupdate.reset_catalog") - else: - self.run_function("softwareupdate.set_catalog", [self.CATALOG]) - - super().tearDown() - - @pytest.mark.slow_test - def test_list_available(self): - """ - Test softwareupdate.list_available - """ - # Can't predict what will be returned, so can only test that the return - # is the correct type, dict - self.assertIsInstance(self.run_function("softwareupdate.list_available"), dict) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_ignore(self): - """ - Test softwareupdate.ignore - Test softwareupdate.list_ignored - Test softwareupdate.reset_ignored - """ - # Test reset_ignored - self.assertTrue(self.run_function("softwareupdate.reset_ignored")) - self.assertEqual(self.run_function("softwareupdate.list_ignored"), []) - - # Test ignore - self.assertTrue(self.run_function("softwareupdate.ignore", ["spongebob"])) - self.assertTrue(self.run_function("softwareupdate.ignore", ["squidward"])) - - # Test list_ignored and verify ignore - self.assertIn("spongebob", self.run_function("softwareupdate.list_ignored")) - self.assertIn("squidward", self.run_function("softwareupdate.list_ignored")) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_schedule(self): - """ - Test softwareupdate.schedule_enable - Test softwareupdate.schedule_enabled - """ - # Test enable - self.assertTrue(self.run_function("softwareupdate.schedule_enable", [True])) - self.assertTrue(self.run_function("softwareupdate.schedule_enabled")) - - # Test disable in case it was already enabled - self.assertTrue(self.run_function("softwareupdate.schedule_enable", [False])) - self.assertFalse(self.run_function("softwareupdate.schedule_enabled")) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_update(self): - """ - Test softwareupdate.update_all - Test softwareupdate.update - Test softwareupdate.update_available - - Need to know the names of updates that are available to properly test - the update functions... - """ - # There's no way to know what the dictionary will contain, so all we can - # check is that the return is a dictionary - self.assertIsInstance(self.run_function("softwareupdate.update_all"), dict) - - # Test update_available - self.assertFalse( - self.run_function("softwareupdate.update_available", ["spongebob"]) - ) - - # Test update not available - self.assertIn( - "Update not available", - self.run_function("softwareupdate.update", ["spongebob"]), - ) - - @pytest.mark.slow_test - def test_list_downloads(self): - """ - Test softwareupdate.list_downloads - """ - self.assertIsInstance(self.run_function("softwareupdate.list_downloads"), list) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_download(self): - """ - Test softwareupdate.download - - Need to know the names of updates that are available to properly test - the download function - """ - # Test update not available - self.assertIn( - "Update not available", - self.run_function("softwareupdate.download", ["spongebob"]), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_download_all(self): - """ - Test softwareupdate.download_all - """ - self.assertIsInstance(self.run_function("softwareupdate.download_all"), list) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_get_set_reset_catalog(self): - """ - Test softwareupdate.download_all - """ - # Reset the catalog - self.assertTrue(self.run_function("softwareupdate.reset_catalog")) - self.assertEqual(self.run_function("softwareupdate.get_catalog"), "Default") - - # Test setting and getting the catalog - self.assertTrue(self.run_function("softwareupdate.set_catalog", ["spongebob"])) - self.assertEqual(self.run_function("softwareupdate.get_catalog"), "spongebob") - - # Test reset the catalog - self.assertTrue(self.run_function("softwareupdate.reset_catalog")) - self.assertEqual(self.run_function("softwareupdate.get_catalog"), "Default") diff --git a/tests/integration/modules/test_mac_sysctl.py b/tests/integration/modules/test_mac_sysctl.py deleted file mode 100644 index 6d7b1c945d6c..000000000000 --- a/tests/integration/modules/test_mac_sysctl.py +++ /dev/null @@ -1,174 +0,0 @@ -""" - :codeauthor: Nicole Thomas -""" - -import os -import random - -import pytest - -import salt.utils.files -from salt.exceptions import CommandExecutionError -from tests.support.case import ModuleCase - -# Module Variables -ASSIGN_CMD = "net.inet.icmp.icmplim" -CONFIG = "/etc/sysctl.conf" - - -@pytest.mark.destructive_test -@pytest.mark.skip_if_not_root -@pytest.mark.skip_unless_on_darwin -class DarwinSysctlModuleTest(ModuleCase): - """ - Integration tests for the darwin_sysctl module - """ - - def setUp(self): - """ - Sets up the test requirements - """ - super().setUp() - # Data needed for cleanup - self.has_conf = False - self.val = self.run_function("sysctl.get", [ASSIGN_CMD]) - - # If sysctl file is present, make a copy - # Remove original file so we can replace it with test files - if os.path.isfile(CONFIG): - self.has_conf = True - try: - self.conf = self.__copy_sysctl() - except CommandExecutionError: - msg = "Could not copy file: {0}" - raise CommandExecutionError(msg.format(CONFIG)) - os.remove(CONFIG) - - @pytest.mark.slow_test - def test_assign(self): - """ - Tests assigning a single sysctl parameter - """ - try: - rand = random.randint(0, 500) - while rand == self.val: - rand = random.randint(0, 500) - self.run_function("sysctl.assign", [ASSIGN_CMD, rand]) - info = int(self.run_function("sysctl.get", [ASSIGN_CMD])) - try: - self.assertEqual(rand, info) - except AssertionError: - self.run_function("sysctl.assign", [ASSIGN_CMD, self.val]) - raise - except CommandExecutionError: - self.run_function("sysctl.assign", [ASSIGN_CMD, self.val]) - raise - - @pytest.mark.slow_test - def test_persist_new_file(self): - """ - Tests assigning a sysctl value to a system without a sysctl.conf file - """ - # Always start with a clean/known sysctl.conf state - if os.path.isfile(CONFIG): - os.remove(CONFIG) - try: - self.run_function("sysctl.persist", [ASSIGN_CMD, 10]) - line = "{}={}".format(ASSIGN_CMD, 10) - found = self.__check_string(CONFIG, line) - self.assertTrue(found) - except CommandExecutionError: - os.remove(CONFIG) - raise - - @pytest.mark.slow_test - def test_persist_already_set(self): - """ - Tests assigning a sysctl value that is already set in sysctl.conf file - """ - # Always start with a clean/known sysctl.conf state - if os.path.isfile(CONFIG): - os.remove(CONFIG) - try: - self.run_function("sysctl.persist", [ASSIGN_CMD, 50]) - ret = self.run_function("sysctl.persist", [ASSIGN_CMD, 50]) - self.assertEqual(ret, "Already set") - except CommandExecutionError: - os.remove(CONFIG) - raise - - @pytest.mark.slow_test - def test_persist_apply_change(self): - """ - Tests assigning a sysctl value and applying the change to system - """ - # Always start with a clean/known sysctl.conf state - if os.path.isfile(CONFIG): - os.remove(CONFIG) - try: - rand = random.randint(0, 500) - while rand == self.val: - rand = random.randint(0, 500) - self.run_function("sysctl.persist", [ASSIGN_CMD, rand], apply_change=True) - info = int(self.run_function("sysctl.get", [ASSIGN_CMD])) - self.assertEqual(info, rand) - except CommandExecutionError: - os.remove(CONFIG) - raise - - def __copy_sysctl(self): - """ - Copies an existing sysconf file and returns temp file path. Copied - file will be restored in tearDown - """ - # Create new temporary file path and open needed files - temp_path = salt.utils.files.mkstemp() - with salt.utils.files.fopen(CONFIG, "r") as org_conf: - with salt.utils.files.fopen(temp_path, "w") as temp_sysconf: - # write sysctl lines to temp file - for line in org_conf: - temp_sysconf.write(line) - return temp_path - - def __restore_sysctl(self): - """ - Restores the original sysctl.conf file from temporary copy - """ - # If sysctl testing file exists, delete it - if os.path.isfile(CONFIG): - os.remove(CONFIG) - - # write temp lines to sysctl file to restore - with salt.utils.files.fopen(self.conf, "r") as temp_sysctl: - with salt.utils.files.fopen(CONFIG, "w") as sysctl: - for line in temp_sysctl: - sysctl.write(line) - - # delete temporary file - os.remove(self.conf) - - def __check_string(self, conf_file, to_find): - """ - Returns True if given line is present in file - """ - with salt.utils.files.fopen(conf_file, "r") as f_in: - for line in f_in: - if to_find in salt.utils.stringutils.to_unicode(line): - return True - return False - - def tearDown(self): - """ - Clean up after tests - """ - ret = self.run_function("sysctl.get", [ASSIGN_CMD]) - if ret != self.val: - self.run_function("sysctl.assign", [ASSIGN_CMD, self.val]) - - if self.has_conf is True: - # restore original sysctl file - self.__restore_sysctl() - - if self.has_conf is False and os.path.isfile(CONFIG): - # remove sysctl.conf created by tests - os.remove(CONFIG) diff --git a/tests/integration/modules/test_mac_system.py b/tests/integration/modules/test_mac_system.py deleted file mode 100644 index bf590f82c784..000000000000 --- a/tests/integration/modules/test_mac_system.py +++ /dev/null @@ -1,263 +0,0 @@ -""" -integration tests for mac_system -""" - -import logging - -import pytest -from saltfactories.utils import random_string - -from tests.support.case import ModuleCase - -log = logging.getLogger(__name__) - - -SET_COMPUTER_NAME = random_string("RS-", lowercase=False) -SET_SUBNET_NAME = random_string("RS-", lowercase=False) - - -@pytest.mark.flaky(max_runs=10) -@pytest.mark.skip_unless_on_darwin -@pytest.mark.usefixtures("salt_sub_minion") -@pytest.mark.skip_if_not_root -@pytest.mark.skip_if_binaries_missing("systemsetup") -@pytest.mark.slow_test -class MacSystemModuleTest(ModuleCase): - """ - Validate the mac_system module - """ - - ATRUN_ENABLED = False - REMOTE_LOGIN_ENABLED = False - REMOTE_EVENTS_ENABLED = False - SUBNET_NAME = "" - KEYBOARD_DISABLED = False - - def setUp(self): - """ - Get current settings - """ - self.ATRUN_ENABLED = self.run_function("service.enabled", ["com.apple.atrun"]) - self.REMOTE_LOGIN_ENABLED = self.run_function("system.get_remote_login") - self.REMOTE_EVENTS_ENABLED = self.run_function("system.get_remote_events") - self.SUBNET_NAME = self.run_function("system.get_subnet_name") - self.KEYBOARD_DISABLED = self.run_function( - "system.get_disable_keyboard_on_lock" - ) - - def tearDown(self): - """ - Reset to original settings - """ - if not self.ATRUN_ENABLED: - atrun = "/System/Library/LaunchDaemons/com.apple.atrun.plist" - self.run_function("service.stop", [atrun]) - - self.run_function("system.set_remote_login", [self.REMOTE_LOGIN_ENABLED]) - self.run_function("system.set_remote_events", [self.REMOTE_EVENTS_ENABLED]) - self.run_function("system.set_subnet_name", [self.SUBNET_NAME]) - self.run_function( - "system.set_disable_keyboard_on_lock", [self.KEYBOARD_DISABLED] - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_set_remote_login(self): - """ - Test system.get_remote_login - Test system.set_remote_login - """ - # Normal Functionality - self.assertTrue(self.run_function("system.set_remote_login", [True])) - self.assertTrue(self.run_function("system.get_remote_login")) - self.assertTrue(self.run_function("system.set_remote_login", [False])) - self.assertFalse(self.run_function("system.get_remote_login")) - - # Test valid input - self.assertTrue(self.run_function("system.set_remote_login", [True])) - self.assertTrue(self.run_function("system.set_remote_login", [False])) - self.assertTrue(self.run_function("system.set_remote_login", ["yes"])) - self.assertTrue(self.run_function("system.set_remote_login", ["no"])) - self.assertTrue(self.run_function("system.set_remote_login", ["On"])) - self.assertTrue(self.run_function("system.set_remote_login", ["Off"])) - self.assertTrue(self.run_function("system.set_remote_login", [1])) - self.assertTrue(self.run_function("system.set_remote_login", [0])) - - # Test invalid input - self.assertIn( - "Invalid String Value for Enabled", - self.run_function("system.set_remote_login", ["spongebob"]), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_set_remote_events(self): - """ - Test system.get_remote_events - Test system.set_remote_events - """ - # Normal Functionality - self.assertTrue(self.run_function("system.set_remote_events", [True])) - self.assertTrue(self.run_function("system.get_remote_events")) - self.assertTrue(self.run_function("system.set_remote_events", [False])) - self.assertFalse(self.run_function("system.get_remote_events")) - - # Test valid input - self.assertTrue(self.run_function("system.set_remote_events", [True])) - self.assertTrue(self.run_function("system.set_remote_events", [False])) - self.assertTrue(self.run_function("system.set_remote_events", ["yes"])) - self.assertTrue(self.run_function("system.set_remote_events", ["no"])) - self.assertTrue(self.run_function("system.set_remote_events", ["On"])) - self.assertTrue(self.run_function("system.set_remote_events", ["Off"])) - self.assertTrue(self.run_function("system.set_remote_events", [1])) - self.assertTrue(self.run_function("system.set_remote_events", [0])) - - # Test invalid input - self.assertIn( - "Invalid String Value for Enabled", - self.run_function("system.set_remote_events", ["spongebob"]), - ) - - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_set_subnet_name(self): - """ - Test system.get_subnet_name - Test system.set_subnet_name - """ - self.assertTrue(self.run_function("system.set_subnet_name", [SET_SUBNET_NAME])) - self.assertEqual(self.run_function("system.get_subnet_name"), SET_SUBNET_NAME) - - @pytest.mark.slow_test - @pytest.mark.skip_initial_gh_actions_failure - def test_get_list_startup_disk(self): - """ - Test system.get_startup_disk - Test system.list_startup_disks - Don't know how to test system.set_startup_disk as there's usually only - one startup disk available on a system - """ - # Test list and get - ret = self.run_function("system.list_startup_disks") - self.assertIsInstance(ret, list) - self.assertIn(self.run_function("system.get_startup_disk"), ret) - - # Test passing set a bad disk - self.assertIn( - "Invalid value passed for path.", - self.run_function("system.set_startup_disk", ["spongebob"]), - ) - - @pytest.mark.skip(reason="Skip this test until mac fixes it.") - def test_get_set_restart_delay(self): - """ - Test system.get_restart_delay - Test system.set_restart_delay - system.set_restart_delay does not work due to an apple bug, see docs - may need to disable this test as we can't control the delay value - """ - # Normal Functionality - self.assertTrue(self.run_function("system.set_restart_delay", [90])) - self.assertEqual(self.run_function("system.get_restart_delay"), "90 seconds") - - # Pass set bad value for seconds - self.assertIn( - "Invalid value passed for seconds.", - self.run_function("system.set_restart_delay", [70]), - ) - - @pytest.mark.slow_test - def test_get_set_disable_keyboard_on_lock(self): - """ - Test system.get_disable_keyboard_on_lock - Test system.set_disable_keyboard_on_lock - """ - # Normal Functionality - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", [True]) - ) - self.assertTrue(self.run_function("system.get_disable_keyboard_on_lock")) - - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", [False]) - ) - self.assertFalse(self.run_function("system.get_disable_keyboard_on_lock")) - - # Test valid input - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", [True]) - ) - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", [False]) - ) - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", ["yes"]) - ) - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", ["no"]) - ) - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", ["On"]) - ) - self.assertTrue( - self.run_function("system.set_disable_keyboard_on_lock", ["Off"]) - ) - self.assertTrue(self.run_function("system.set_disable_keyboard_on_lock", [1])) - self.assertTrue(self.run_function("system.set_disable_keyboard_on_lock", [0])) - - # Test invalid input - self.assertIn( - "Invalid String Value for Enabled", - self.run_function("system.set_disable_keyboard_on_lock", ["spongebob"]), - ) - - @pytest.mark.skip(reason="Skip this test until mac fixes it.") - def test_get_set_boot_arch(self): - """ - Test system.get_boot_arch - Test system.set_boot_arch - system.set_boot_arch does not work due to an apple bug, see docs - may need to disable this test as we can't set the boot architecture - """ - # Normal Functionality - self.assertTrue(self.run_function("system.set_boot_arch", ["i386"])) - self.assertEqual(self.run_function("system.get_boot_arch"), "i386") - self.assertTrue(self.run_function("system.set_boot_arch", ["default"])) - self.assertEqual(self.run_function("system.get_boot_arch"), "default") - - # Test invalid input - self.assertIn( - "Invalid value passed for arch", - self.run_function("system.set_boot_arch", ["spongebob"]), - ) - - -@pytest.mark.skip_unless_on_darwin -@pytest.mark.skip_if_not_root -class MacSystemComputerNameTest(ModuleCase): - def setUp(self): - self.COMPUTER_NAME = self.run_function("system.get_computer_name") - self.wait_for_all_jobs() - - def tearDown(self): - self.run_function("system.set_computer_name", [self.COMPUTER_NAME]) - self.wait_for_all_jobs() - - # A similar test used to be skipped on py3 due to 'hanging', if we see - # something similar again we may want to skip this gain until we - # investigate - # @pytest.mark.skipif(salt.utils.platform.is_darwin() and six.PY3, reason='This test hangs on OS X on Py3. Skipping until #53566 is merged.') - @pytest.mark.destructive_test - @pytest.mark.slow_test - def test_get_set_computer_name(self): - """ - Test system.get_computer_name - Test system.set_computer_name - """ - log.debug("Set name is %s", SET_COMPUTER_NAME) - self.assertTrue( - self.run_function("system.set_computer_name", [SET_COMPUTER_NAME]) - ) - self.assertEqual( - self.run_function("system.get_computer_name"), SET_COMPUTER_NAME - ) diff --git a/tests/integration/modules/test_mac_timezone.py b/tests/integration/modules/test_mac_timezone.py deleted file mode 100644 index c424710a410e..000000000000 --- a/tests/integration/modules/test_mac_timezone.py +++ /dev/null @@ -1,206 +0,0 @@ -""" -Integration tests for mac_timezone - -If using parallels, make sure Time sync is turned off. Otherwise, parallels will -keep changing your date/time settings while the tests are running. To turn off -Time sync do the following: - - Go to actions -> configure - - Select options at the top and 'More Options' on the left - - Set time to 'Do not sync' -""" - -import datetime - -import pytest - -from tests.support.case import ModuleCase - - -@pytest.mark.flaky(max_runs=4) -@pytest.mark.skip_unless_on_darwin -@pytest.mark.skip_if_binaries_missing("systemsetup") -@pytest.mark.skip_if_not_root -@pytest.mark.slow_test -class MacTimezoneModuleTest(ModuleCase): - """ - Validate the mac_timezone module - """ - - USE_NETWORK_TIME = False - TIME_SERVER = "time.apple.com" - TIME_ZONE = "" - CURRENT_DATE = "" - CURRENT_TIME = "" - - def setUp(self): - """ - Get current settings - """ - self.USE_NETWORK_TIME = self.run_function("timezone.get_using_network_time") - self.TIME_SERVER = self.run_function("timezone.get_time_server") - self.TIME_ZONE = self.run_function("timezone.get_zone") - self.CURRENT_DATE = self.run_function("timezone.get_date") - self.CURRENT_TIME = self.run_function("timezone.get_time") - - self.run_function("timezone.set_using_network_time", [False]) - self.run_function("timezone.set_zone", ["America/Denver"]) - - def tearDown(self): - """ - Reset to original settings - """ - self.run_function("timezone.set_time_server", [self.TIME_SERVER]) - self.run_function("timezone.set_using_network_time", [self.USE_NETWORK_TIME]) - self.run_function("timezone.set_zone", [self.TIME_ZONE]) - if not self.USE_NETWORK_TIME: - self.run_function("timezone.set_date", [self.CURRENT_DATE]) - self.run_function("timezone.set_time", [self.CURRENT_TIME]) - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_get_set_date(self): - """ - Test timezone.get_date - Test timezone.set_date - """ - # Correct Functionality - self.assertTrue(self.run_function("timezone.set_date", ["2/20/2011"])) - self.assertEqual(self.run_function("timezone.get_date"), "2/20/2011") - - # Test bad date format - self.assertEqual( - self.run_function("timezone.set_date", ["13/12/2014"]), - "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014", - ) - - @pytest.mark.slow_test - def test_get_time(self): - """ - Test timezone.get_time - """ - text_time = self.run_function("timezone.get_time") - self.assertNotEqual(text_time, "Invalid Timestamp") - obj_date = datetime.datetime.strptime(text_time, "%H:%M:%S") - self.assertIsInstance(obj_date, datetime.date) - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_set_time(self): - """ - Test timezone.set_time - """ - # Correct Functionality - self.assertTrue(self.run_function("timezone.set_time", ["3:14"])) - - # Test bad time format - self.assertEqual( - self.run_function("timezone.set_time", ["3:71"]), - "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71", - ) - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_get_set_zone(self): - """ - Test timezone.get_zone - Test timezone.set_zone - """ - # Correct Functionality - self.assertTrue(self.run_function("timezone.set_zone", ["Pacific/Wake"])) - self.assertEqual(self.run_function("timezone.get_zone"), "Pacific/Wake") - - # Test bad time zone - self.assertEqual( - self.run_function("timezone.set_zone", ["spongebob"]), - "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob", - ) - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_get_offset(self): - """ - Test timezone.get_offset - """ - self.assertTrue(self.run_function("timezone.set_zone", ["Pacific/Wake"])) - self.assertIsInstance(self.run_function("timezone.get_offset"), (str,)) - self.assertEqual(self.run_function("timezone.get_offset"), "+1200") - - self.assertTrue(self.run_function("timezone.set_zone", ["America/Los_Angeles"])) - self.assertIsInstance(self.run_function("timezone.get_offset"), (str,)) - self.assertEqual(self.run_function("timezone.get_offset"), "-0700") - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_get_set_zonecode(self): - """ - Test timezone.get_zonecode - Test timezone.set_zonecode - """ - self.assertTrue(self.run_function("timezone.set_zone", ["America/Los_Angeles"])) - self.assertIsInstance(self.run_function("timezone.get_zonecode"), (str,)) - self.assertEqual(self.run_function("timezone.get_zonecode"), "PDT") - - self.assertTrue(self.run_function("timezone.set_zone", ["Pacific/Wake"])) - self.assertIsInstance(self.run_function("timezone.get_zonecode"), (str,)) - self.assertEqual(self.run_function("timezone.get_zonecode"), "WAKT") - - @pytest.mark.slow_test - def test_list_zones(self): - """ - Test timezone.list_zones - """ - zones = self.run_function("timezone.list_zones") - self.assertIsInstance(self.run_function("timezone.list_zones"), list) - self.assertIn("America/Denver", self.run_function("timezone.list_zones")) - self.assertIn("America/Los_Angeles", self.run_function("timezone.list_zones")) - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_zone_compare(self): - """ - Test timezone.zone_compare - """ - self.assertTrue(self.run_function("timezone.set_zone", ["America/Denver"])) - self.assertTrue(self.run_function("timezone.zone_compare", ["America/Denver"])) - self.assertFalse(self.run_function("timezone.zone_compare", ["Pacific/Wake"])) - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_get_set_using_network_time(self): - """ - Test timezone.get_using_network_time - Test timezone.set_using_network_time - """ - self.assertTrue(self.run_function("timezone.set_using_network_time", [True])) - self.assertTrue(self.run_function("timezone.get_using_network_time")) - - self.assertTrue(self.run_function("timezone.set_using_network_time", [False])) - self.assertFalse(self.run_function("timezone.get_using_network_time")) - - @pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", - ) - @pytest.mark.destructive_test - def test_get_set_time_server(self): - """ - Test timezone.get_time_server - Test timezone.set_time_server - """ - self.assertTrue( - self.run_function("timezone.set_time_server", ["spongebob.com"]) - ) - self.assertEqual(self.run_function("timezone.get_time_server"), "spongebob.com") diff --git a/tests/integration/modules/test_mac_user.py b/tests/integration/modules/test_mac_user.py deleted file mode 100644 index 144267d72f6b..000000000000 --- a/tests/integration/modules/test_mac_user.py +++ /dev/null @@ -1,235 +0,0 @@ -""" - :codeauthor: Nicole Thomas -""" - -import os - -import pytest -from saltfactories.utils import random_string - -import salt.utils.files -from salt.exceptions import CommandExecutionError -from tests.support.case import ModuleCase - -# Create user strings for tests -ADD_USER = random_string("RS-", lowercase=False) -DEL_USER = random_string("RS-", lowercase=False) -PRIMARY_GROUP_USER = random_string("RS-", lowercase=False) -CHANGE_USER = random_string("RS-", lowercase=False) - - -@pytest.mark.skip_if_not_root -@pytest.mark.destructive_test -@pytest.mark.skip_unless_on_darwin -class MacUserModuleTest(ModuleCase): - """ - Integration tests for the mac_user module - """ - - def setUp(self): - """ - Sets up test requirements - """ - super().setUp() - os_grain = self.run_function("grains.item", ["kernel"]) - if os_grain["kernel"] not in "Darwin": - self.skipTest("Test not applicable to '{kernel}' kernel".format(**os_grain)) - - @pytest.mark.slow_test - def test_mac_user_add(self): - """ - Tests the add function - """ - try: - self.run_function("user.add", [ADD_USER]) - user_info = self.run_function("user.info", [ADD_USER]) - self.assertEqual(ADD_USER, user_info["name"]) - except CommandExecutionError: - self.run_function("user.delete", [ADD_USER]) - raise - - @pytest.mark.slow_test - def test_mac_user_delete(self): - """ - Tests the delete function - """ - - # Create a user to delete - If unsuccessful, skip the test - if self.run_function("user.add", [DEL_USER]) is not True: - self.run_function("user.delete", [DEL_USER]) - self.skipTest("Failed to create a user to delete") - - # Now try to delete the added user - ret = self.run_function("user.delete", [DEL_USER]) - self.assertTrue(ret) - - @pytest.mark.slow_test - def test_mac_user_primary_group(self): - """ - Tests the primary_group function - """ - - # Create a user to test primary group function - if self.run_function("user.add", [PRIMARY_GROUP_USER]) is not True: - self.run_function("user.delete", [PRIMARY_GROUP_USER]) - self.skipTest("Failed to create a user") - - try: - # Test mac_user.primary_group - primary_group = self.run_function( - "user.primary_group", [PRIMARY_GROUP_USER] - ) - uid_info = self.run_function("user.info", [PRIMARY_GROUP_USER]) - self.assertIn(primary_group, uid_info["groups"]) - - except AssertionError: - self.run_function("user.delete", [PRIMARY_GROUP_USER]) - raise - - @pytest.mark.slow_test - def test_mac_user_changes(self): - """ - Tests mac_user functions that change user properties - """ - # Create a user to manipulate - if unsuccessful, skip the test - if self.run_function("user.add", [CHANGE_USER]) is not True: - self.run_function("user.delete", [CHANGE_USER]) - self.skipTest("Failed to create a user") - - try: - # Test mac_user.chuid - self.run_function("user.chuid", [CHANGE_USER, 4376]) - uid_info = self.run_function("user.info", [CHANGE_USER]) - self.assertEqual(uid_info["uid"], 4376) - - # Test mac_user.chgid - self.run_function("user.chgid", [CHANGE_USER, 4376]) - gid_info = self.run_function("user.info", [CHANGE_USER]) - self.assertEqual(gid_info["gid"], 4376) - - # Test mac.user.chshell - self.run_function("user.chshell", [CHANGE_USER, "/bin/zsh"]) - shell_info = self.run_function("user.info", [CHANGE_USER]) - self.assertEqual(shell_info["shell"], "/bin/zsh") - - # Test mac_user.chhome - self.run_function("user.chhome", [CHANGE_USER, "/Users/foo"]) - home_info = self.run_function("user.info", [CHANGE_USER]) - self.assertEqual(home_info["home"], "/Users/foo") - - # Test mac_user.chfullname - self.run_function("user.chfullname", [CHANGE_USER, "Foo Bar"]) - fullname_info = self.run_function("user.info", [CHANGE_USER]) - self.assertEqual(fullname_info["fullname"], "Foo Bar") - - # Test mac_user.chgroups - pre_info = self.run_function("user.info", [CHANGE_USER])["groups"] - expected = pre_info + ["wheel"] - self.run_function("user.chgroups", [CHANGE_USER, "wheel"]) - groups_info = self.run_function("user.info", [CHANGE_USER]) - self.assertEqual(groups_info["groups"], expected) - - except AssertionError: - self.run_function("user.delete", [CHANGE_USER]) - raise - - @pytest.mark.slow_test - def test_mac_user_enable_auto_login(self): - """ - Tests mac_user functions that enable auto login - """ - # Make sure auto login is disabled before we start - if self.run_function("user.get_auto_login"): - self.skipTest("Auto login already enabled") - - try: - # Does enable return True - self.assertTrue( - self.run_function( - "user.enable_auto_login", ["Spongebob", "Squarepants"] - ) - ) - - # Did it set the user entry in the plist file - self.assertEqual(self.run_function("user.get_auto_login"), "Spongebob") - - # Did it generate the `/etc/kcpassword` file - self.assertTrue(os.path.exists("/etc/kcpassword")) - - # Are the contents of the file correct - test_data = bytes.fromhex("2e f8 27 42 a0 d9 ad 8b cd cd 6c 7d") - with salt.utils.files.fopen("/etc/kcpassword", "rb") as f: - file_data = f.read() - self.assertEqual(test_data, file_data) - - # Does disable return True - self.assertTrue(self.run_function("user.disable_auto_login")) - - # Does it remove the user entry in the plist file - self.assertFalse(self.run_function("user.get_auto_login")) - - # Is the `/etc/kcpassword` file removed - self.assertFalse(os.path.exists("/etc/kcpassword")) - - finally: - # Make sure auto_login is disabled - self.assertTrue(self.run_function("user.disable_auto_login")) - - # Make sure autologin is disabled - if self.run_function("user.get_auto_login"): - raise Exception("Failed to disable auto login") - - @pytest.mark.slow_test - def test_mac_user_disable_auto_login(self): - """ - Tests mac_user functions that disable auto login - """ - # Make sure auto login is enabled before we start - # Is there an existing setting - if self.run_function("user.get_auto_login"): - self.skipTest("Auto login already enabled") - - try: - # Enable auto login for the test - self.run_function("user.enable_auto_login", ["Spongebob", "Squarepants"]) - - # Make sure auto login got set up - if not self.run_function("user.get_auto_login") == "Spongebob": - raise Exception("Failed to enable auto login") - - # Does disable return True - self.assertTrue(self.run_function("user.disable_auto_login")) - - # Does it remove the user entry in the plist file - self.assertFalse(self.run_function("user.get_auto_login")) - - # Is the `/etc/kcpassword` file removed - self.assertFalse(os.path.exists("/etc/kcpassword")) - - finally: - # Make sure auto login is disabled - self.assertTrue(self.run_function("user.disable_auto_login")) - - # Make sure auto login is disabled - if self.run_function("user.get_auto_login"): - raise Exception("Failed to disable auto login") - - def tearDown(self): - """ - Clean up after tests - """ - - # Delete ADD_USER - add_info = self.run_function("user.info", [ADD_USER]) - if add_info: - self.run_function("user.delete", [ADD_USER]) - - # Delete DEL_USER if something failed - del_info = self.run_function("user.info", [DEL_USER]) - if del_info: - self.run_function("user.delete", [DEL_USER]) - - # Delete CHANGE_USER - change_info = self.run_function("user.info", [CHANGE_USER]) - if change_info: - self.run_function("user.delete", [CHANGE_USER]) diff --git a/tests/integration/modules/test_mac_xattr.py b/tests/integration/modules/test_mac_xattr.py deleted file mode 100644 index bcc39339b069..000000000000 --- a/tests/integration/modules/test_mac_xattr.py +++ /dev/null @@ -1,193 +0,0 @@ -""" -integration tests for mac_xattr -""" - -import os - -import pytest - -from tests.support.case import ModuleCase -from tests.support.runtests import RUNTIME_VARS - - -@pytest.mark.skip_if_binaries_missing("xattr") -@pytest.mark.skip_unless_on_darwin -class MacXattrModuleTest(ModuleCase): - """ - Validate the mac_xattr module - """ - - @classmethod - def setUpClass(cls): - cls.test_file = os.path.join(RUNTIME_VARS.TMP, "xattr_test_file.txt") - cls.no_file = os.path.join(RUNTIME_VARS.TMP, "xattr_no_file.txt") - - def setUp(self): - """ - Create test file for testing extended attributes - """ - self.run_function("file.touch", [self.test_file]) - - def tearDown(self): - """ - Clean up test file - """ - if os.path.exists(self.test_file): - os.remove(self.test_file) - - @pytest.mark.slow_test - def test_list_no_xattr(self): - """ - Make sure there are no attributes - """ - # Clear existing attributes - self.assertTrue(self.run_function("xattr.clear", [self.test_file])) - - # Test no attributes - self.assertEqual(self.run_function("xattr.list", [self.test_file]), {}) - - # Test file not found - self.assertEqual( - self.run_function("xattr.list", [self.no_file]), - "ERROR: File not found: {}".format(self.no_file), - ) - - @pytest.mark.slow_test - def test_write(self): - """ - Write an attribute - """ - # Clear existing attributes - self.assertTrue(self.run_function("xattr.clear", [self.test_file])) - - # Write some attributes - self.assertTrue( - self.run_function( - "xattr.write", [self.test_file, "spongebob", "squarepants"] - ) - ) - self.assertTrue( - self.run_function("xattr.write", [self.test_file, "squidward", "plankton"]) - ) - self.assertTrue( - self.run_function("xattr.write", [self.test_file, "crabby", "patty"]) - ) - - # Test that they were actually added - self.assertEqual( - self.run_function("xattr.list", [self.test_file]), - {"spongebob": "squarepants", "squidward": "plankton", "crabby": "patty"}, - ) - - # Test file not found - self.assertEqual( - self.run_function("xattr.write", [self.no_file, "patrick", "jellyfish"]), - "ERROR: File not found: {}".format(self.no_file), - ) - - @pytest.mark.slow_test - def test_read(self): - """ - Test xattr.read - """ - # Clear existing attributes - self.assertTrue(self.run_function("xattr.clear", [self.test_file])) - - # Write an attribute - self.assertTrue( - self.run_function( - "xattr.write", [self.test_file, "spongebob", "squarepants"] - ) - ) - - # Read the attribute - self.assertEqual( - self.run_function("xattr.read", [self.test_file, "spongebob"]), - "squarepants", - ) - - # Test file not found - self.assertEqual( - self.run_function("xattr.read", [self.no_file, "spongebob"]), - "ERROR: File not found: {}".format(self.no_file), - ) - - # Test attribute not found - self.assertEqual( - self.run_function("xattr.read", [self.test_file, "patrick"]), - "ERROR: Attribute not found: patrick", - ) - - @pytest.mark.slow_test - def test_delete(self): - """ - Test xattr.delete - """ - # Clear existing attributes - self.assertTrue(self.run_function("xattr.clear", [self.test_file])) - - # Write some attributes - self.assertTrue( - self.run_function( - "xattr.write", [self.test_file, "spongebob", "squarepants"] - ) - ) - self.assertTrue( - self.run_function("xattr.write", [self.test_file, "squidward", "plankton"]) - ) - self.assertTrue( - self.run_function("xattr.write", [self.test_file, "crabby", "patty"]) - ) - - # Delete an attribute - self.assertTrue( - self.run_function("xattr.delete", [self.test_file, "squidward"]) - ) - - # Make sure it was actually deleted - self.assertEqual( - self.run_function("xattr.list", [self.test_file]), - {"spongebob": "squarepants", "crabby": "patty"}, - ) - - # Test file not found - self.assertEqual( - self.run_function("xattr.delete", [self.no_file, "spongebob"]), - "ERROR: File not found: {}".format(self.no_file), - ) - - # Test attribute not found - self.assertEqual( - self.run_function("xattr.delete", [self.test_file, "patrick"]), - "ERROR: Attribute not found: patrick", - ) - - @pytest.mark.slow_test - def test_clear(self): - """ - Test xattr.clear - """ - # Clear existing attributes - self.assertTrue(self.run_function("xattr.clear", [self.test_file])) - - # Write some attributes - self.assertTrue( - self.run_function( - "xattr.write", [self.test_file, "spongebob", "squarepants"] - ) - ) - self.assertTrue( - self.run_function("xattr.write", [self.test_file, "squidward", "plankton"]) - ) - self.assertTrue( - self.run_function("xattr.write", [self.test_file, "crabby", "patty"]) - ) - - # Test Clear - self.assertTrue(self.run_function("xattr.clear", [self.test_file])) - - # Test file not found - self.assertEqual( - self.run_function("xattr.clear", [self.no_file]), - "ERROR: File not found: {}".format(self.no_file), - ) diff --git a/tests/pytests/integration/modules/test_mac_assistive.py b/tests/pytests/integration/modules/test_mac_assistive.py new file mode 100644 index 000000000000..527a804f76fb --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_assistive.py @@ -0,0 +1,86 @@ +""" + :codeauthor: Nicole Thomas +""" + +import pytest + +pytestmark = [ + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_initial_gh_actions_failure, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def osa_script(): + yield "/usr/bin/osascript" + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli, osa_script, setup_teardown_vars): + salt_call_cli.run("assistive.install", osa_script, True) + try: + yield + finally: + osa_script_ret = salt_call_cli.run("assistive.installed", osa_script) + if osa_script_ret: + salt_call_cli.run("assistive.remove", osa_script) + + smile_bundle = "com.smileonmymac.textexpander" + smile_bundle_present = salt_call_cli.run("assistive.installed", smile_bundle) + if smile_bundle_present: + salt_call_cli.run("assistive.remove", smile_bundle) + + +@pytest.mark.slow_test +def test_install_and_remove(salt_call_cli, osa_script, setup_teardown_vars): + """ + Tests installing and removing a bundled ID or command to use assistive access. + """ + new_bundle = "com.smileonmymac.textexpander" + assert salt_call_cli.run("assistive.install", new_bundle) + assert salt_call_cli.run("assistive.remove", new_bundle) + + +@pytest.mark.slow_test +def test_installed(salt_call_cli, osa_script, setup_teardown_vars): + """ + Tests the True and False return of assistive.installed. + """ + # OSA script should have been installed in setUp function + assert salt_call_cli.run("assistive.installed", osa_script) + # Clean up install + salt_call_cli.run("assistive.remove", osa_script) + # Installed should now return False + assert not salt_call_cli.run("assistive.installed", osa_script) + + +@pytest.mark.slow_test +def test_enable(salt_call_cli, osa_script, setup_teardown_vars): + """ + Tests setting the enabled status of a bundled ID or command. + """ + # OSA script should have been installed and enabled in setUp function + # Now let's disable it, which should return True. + assert salt_call_cli.run("assistive.enable", osa_script, False) + # Double check the script was disabled, as intended. + assert not salt_call_cli.run("assistive.enabled", osa_script) + # Now re-enable + assert salt_call_cli.run("assistive.enable", osa_script) + # Double check the script was enabled, as intended. + assert salt_call_cli.run("assistive.enabled", osa_script) + + +@pytest.mark.slow_test +def test_enabled(salt_call_cli, osa_script, setup_teardown_vars): + """ + Tests if a bundled ID or command is listed in assistive access returns True. + """ + # OSA script should have been installed in setUp function, which sets + # enabled to True by default. + assert salt_call_cli.run("assistive.enabled", osa_script) + # Disable OSA Script + salt_call_cli.run("assistive.enable", osa_script, False) + # Assert against new disabled status + assert not salt_call_cli.run("assistive.enabled", osa_script) diff --git a/tests/pytests/integration/modules/test_mac_brew_pkg.py b/tests/pytests/integration/modules/test_mac_brew_pkg.py new file mode 100644 index 000000000000..d298116cc676 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_brew_pkg.py @@ -0,0 +1,188 @@ +""" + :codeauthor: Nicole Thomas +""" + +import pytest + +from salt.exceptions import CommandExecutionError + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.skip_if_binaries_missing("brew"), +] + +# Brew doesn't support local package installation - So, let's +# Grab some small packages available online for brew + + +@pytest.fixture(scope="function") +def add_pkg(): + yield "algol68g" + + +@pytest.fixture(scope="function") +def del_pkg(): + yield "acme" + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli, add_pkg, del_pkg): + try: + yield + finally: + pkg_list = salt_call_cli.run("pkg.list_pkgs") + + # Remove any installed packages + if add_pkg in pkg_list: + salt_call_cli.run("pkg.remove", add_pkg) + if del_pkg in pkg_list: + salt_call_cli.run("pkg.remove", del_pkg) + + +def test_brew_install(salt_call_cli, add_pkg, setup_teardown_vars): + """ + Tests the installation of packages + """ + try: + salt_call_cli.run("pkg.install", add_pkg) + pkg_list = salt_call_cli.run("pkg.list_pkgs") + try: + assert add_pkg in pkg_list + except AssertionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + except CommandExecutionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + + +def test_remove(salt_call_cli, del_pkg, setup_teardown_vars): + """ + Tests the removal of packages + """ + try: + # Install a package to delete - If unsuccessful, skip the test + salt_call_cli.run("pkg.install", del_pkg) + pkg_list = salt_call_cli.run("pkg.list_pkgs") + if del_pkg not in pkg_list: + salt_call_cli.run("pkg.install", del_pkg) + pytest.skip("Failed to install a package to delete") + + # Now remove the installed package + salt_call_cli.run("pkg.remove", del_pkg) + del_list = salt_call_cli.run("pkg.list_pkgs") + assert del_pkg not in del_list + except CommandExecutionError: + salt_call_cli.run("pkg.remove", del_pkg) + raise + + +def test_version(salt_call_cli, add_pkg, setup_teardown_vars): + """ + Test pkg.version for mac. Installs a package and then checks we can get + a version for the installed package. + """ + try: + salt_call_cli.run("pkg.install", add_pkg) + pkg_list = salt_call_cli.run("pkg.list_pkgs") + version = salt_call_cli.run("pkg.version", add_pkg) + try: + assert version, "version: {} is empty, or other issue is present".format( + version + ) + assert ( + add_pkg in pkg_list + ), "package: {} is not in the list of installed packages: {}".format( + add_pkg, pkg_list + ) + # make sure the version is accurate and is listed in the pkg_list + assert version in str( + pkg_list[add_pkg] + ), "The {} version: {} is not listed in the pkg_list: {}".format( + add_pkg, version, pkg_list[add_pkg] + ) + except AssertionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + except CommandExecutionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + + +def test_latest_version(salt_call_cli, add_pkg, setup_teardown_vars): + """ + Test pkg.latest_version: + - get the latest version available + - install the package + - get the latest version available + - check that the latest version is empty after installing it + """ + try: + salt_call_cli.run("pkg.remove", add_pkg) + uninstalled_latest = salt_call_cli.run("pkg.latest_version", add_pkg) + + salt_call_cli.run("pkg.install", add_pkg) + installed_latest = salt_call_cli.run("pkg.latest_version", add_pkg) + version = salt_call_cli.run("pkg.version", add_pkg) + try: + assert isinstance(uninstalled_latest, str) + assert installed_latest == version + except AssertionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + except CommandExecutionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + + +def test_refresh_db(salt_call_cli, setup_teardown_vars): + """ + Integration test to ensure pkg.refresh_db works with brew + """ + refresh_brew = salt_call_cli.run("pkg.refresh_db") + assert refresh_brew + + +def test_list_upgrades(salt_call_cli, add_pkg, setup_teardown_vars): + """ + Test pkg.list_upgrades: data is in the form {'name1': 'version1', + 'name2': 'version2', ... } + """ + try: + upgrades = salt_call_cli.run("pkg.list_upgrades") + try: + assert isinstance(upgrades, dict) + if upgrades: + for name in upgrades: + assert isinstance(name, str) + assert isinstance(upgrades[name], str) + except AssertionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + except CommandExecutionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + + +def test_info_installed(salt_call_cli, add_pkg, setup_teardown_vars): + """ + Test pkg.info_installed: info returned has certain fields used by + mac_brew.latest_version + """ + try: + salt_call_cli.run("pkg.install", add_pkg) + info = salt_call_cli.run("pkg.info_installed", add_pkg) + try: + assert add_pkg in info + assert "versions" in info[add_pkg] + assert "revision" in info[add_pkg] + assert "stable" in info[add_pkg]["versions"] + except AssertionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise + except CommandExecutionError: + salt_call_cli.run("pkg.remove", add_pkg) + raise diff --git a/tests/pytests/integration/modules/test_mac_desktop.py b/tests/pytests/integration/modules/test_mac_desktop.py new file mode 100644 index 000000000000..6a3ce1e60084 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_desktop.py @@ -0,0 +1,57 @@ +""" +Integration tests for the mac_desktop execution module. +""" + +import pytest + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +def test_get_output_volume(salt_call_cli): + """ + Tests the return of get_output_volume. + """ + ret = salt_call_cli.run("desktop.get_output_volume") + assert ret is not None + + +def test_set_output_volume(salt_call_cli): + """ + Tests the return of set_output_volume. + """ + current_vol = salt_call_cli.run("desktop.get_output_volume") + to_set = 10 + if current_vol == str(to_set): + to_set += 2 + new_vol = salt_call_cli.run("desktop.set_output_volume", str(to_set)) + check_vol = salt_call_cli.run("desktop.get_output_volume") + assert new_vol == check_vol + + # Set volume back to what it was before + salt_call_cli.run("desktop.set_output_volume", [current_vol]) + + +def test_screensaver(salt_call_cli): + """ + Tests the return of the screensaver function. + """ + assert salt_call_cli.run("desktop.screensaver") + + +def test_lock(salt_call_cli): + """ + Tests the return of the lock function. + """ + assert salt_call_cli.run("desktop.lock") + + +def test_say(salt_call_cli): + """ + Tests the return of the say function. + """ + assert salt_call_cli.run("desktop.say", "hello", "world") diff --git a/tests/pytests/integration/modules/test_mac_group.py b/tests/pytests/integration/modules/test_mac_group.py new file mode 100644 index 000000000000..71822580def0 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_group.py @@ -0,0 +1,194 @@ +""" + :codeauthor: Nicole Thomas +""" + +import pytest +from saltfactories.utils import random_string + +from salt.exceptions import CommandExecutionError + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +# Create group name strings for tests +@pytest.fixture(scope="module") +def add_group(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def del_group(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def change_group(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def add_user(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def rep_user_group(): + yield random_string("RS-", lowercase=False) + + +pytest.fixture(scope="function") + + +def setup_teardown_vars(salt_call_cli, add_group, change_group, del_group): + try: + os_grain = salt_call_cli.run("grains.item", "kernel") + if os_grain["kernel"] not in "Darwin": + pytest.skip("Test not applicable to '{kernel}' kernel".format(**os_grain)) + yield + finally: + # Delete ADD_GROUP + add_info = salt_call_cli.run("group.info", add_group) + if add_info: + salt_call_cli.run("group.delete", add_group) + + # Delete DEL_GROUP if something failed + del_info = salt_call_cli.run("group.info", del_group) + if del_info: + salt_call_cli.run("group.delete", del_group) + + # Delete CHANGE_GROUP + change_info = salt_call_cli.run("group.info", change_group) + if change_info: + salt_call_cli.run("group.delete", change_group) + + +def test_mac_group_add(salt_call_cli, add_group, setup_teardown_vars): + """ + Tests the add group function + """ + try: + salt_call_cli.run("group.add", add_group, 3456) + group_info = salt_call_cli.run("group.info", add_group) + assert group_info["name"] == add_group + except CommandExecutionError: + salt_call_cli.run("group.delete", add_group) + raise + + +def test_mac_group_delete(salt_call_cli, del_group, setup_teardown_vars): + """ + Tests the delete group function + """ + # Create a group to delete - If unsuccessful, skip the test + if salt_call_cli.run("group.add", del_group, 4567) is not True: + salt_call_cli.run("group.delete", del_group) + pytest.skip("Failed to create a group to delete") + + # Now try to delete the added group + ret = salt_call_cli.run("group.delete", del_group) + assert ret + + +def test_mac_group_chgid(salt_call_cli, change_group, setup_teardown_vars): + """ + Tests changing the group id + """ + # Create a group to delete - If unsuccessful, skip the test + if salt_call_cli.run("group.add", change_group, 5678) is not True: + salt_call_cli.run("group.delete", change_group) + pytest.skip("Failed to create a group to manipulate") + + try: + salt_call_cli.run("group.chgid", change_group, 6789) + group_info = salt_call_cli.run("group.info", change_group) + assert group_info["gid"] == 6789 + except AssertionError: + salt_call_cli.run("group.delete", change_group) + raise + + +def test_mac_adduser(salt_call_cli, add_group, add_user, setup_teardown_vars): + """ + Tests adding user to the group + """ + # Create a group to use for test - If unsuccessful, skip the test + if salt_call_cli.run("group.add", add_group, 5678) is not True: + salt_call_cli.run("group.delete", add_group) + pytest.skip("Failed to create a group to manipulate") + + try: + salt_call_cli.run("group.adduser", add_group, add_user) + group_info = salt_call_cli.run("group.info", add_group) + assert add_user == "".join(group_info["members"]) + except AssertionError: + salt_call_cli.run("group.delete", add_group) + raise + + +def test_mac_deluser(salt_call_cli, add_group, add_user, setup_teardown_vars): + """ + Test deleting user from a group + """ + # Create a group to use for test - If unsuccessful, skip the test + if ( + salt_call_cli.run("group.add", add_group, 5678) + and salt_call_cli.run("group.adduser", add_group, add_user) is not True + ): + salt_call_cli.run("group.delete", add_group) + pytest.skip("Failed to create a group to manipulate") + + delusr = salt_call_cli.run("group.deluser", add_group, add_user) + assert delusr + + group_info = salt_call_cli.run("group.info", add_group) + assert add_user not in "".join(group_info["members"]) + + +def test_mac_members( + salt_call_cli, add_group, add_user, rep_user_group, setup_teardown_vars +): + """ + Test replacing members of a group + """ + if ( + salt_call_cli.run("group.add", add_group, 5678) + and salt_call_cli.run("group.adduser", add_group, add_user) is not True + ): + salt_call_cli.run("group.delete", add_group) + pytest.skip( + "Failed to create the {} group or add user {} to group " + "to manipulate".format(add_group, add_user) + ) + + rep_group_mem = salt_call_cli.run("group.members", add_group, rep_user_group) + assert rep_group_mem + + # ensure new user is added to group and previous user is removed + group_info = salt_call_cli.run("group.info", [add_group]) + assert rep_user_group in str(group_info["members"]) + assert add_user not in str(group_info["members"]) + + +def test_mac_getent(salt_call_cli, add_group, add_user, setup_teardown_vars): + """ + Test returning info on all groups + """ + if ( + salt_call_cli.run("group.add", add_group, 5678) + and salt_call_cli.run("group.adduser", add_group, add_user) is not True + ): + salt_call_cli.run("group.delete", add_group) + pytest.skip( + "Failed to create the {} group or add user {} to group " + "to manipulate".format(add_group, add_user) + ) + + getinfo = salt_call_cli.run("group.getent") + assert getinfo + assert add_group in str(getinfo) + assert add_user in str(getinfo) diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py new file mode 100644 index 000000000000..c66f9efc028d --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -0,0 +1,108 @@ +""" +Validate the mac-keychain module +""" + +import pytest + +from salt.exceptions import CommandExecutionError + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli, base_env_state_tree_root_dir): + cert = str(base_env_state_tree_root_dir / "certs" / "salttest.p12") + cert_alias = "Salt Test" + passwd = "salttest" + + try: + yield cert, cert_alias, passwd + finally: + certs_list = salt_call_cli.run("keychain.list_certs") + if cert_alias in certs_list: + salt_call_cli.run("keychain.uninstall", cert_alias) + + +def test_mac_keychain_install(setup_teardown_vars, salt_call_cli): + """ + Tests that attempts to install a certificate + """ + + cert = setup_teardown_vars[0] + cert_alias = setup_teardown_vars[1] + passwd = setup_teardown_vars[2] + + install_cert = salt_call_cli.run("keychain.install", cert, passwd) + assert install_cert + + # check to ensure the cert was installed + certs_list = salt_call_cli.run("keychain.list_certs") + assert cert_alias in certs_list + + +def test_mac_keychain_uninstall(setup_teardown_vars, salt_call_cli): + """ + Tests that attempts to uninstall a certificate + """ + + cert = setup_teardown_vars[0] + cert_alias = setup_teardown_vars[1] + passwd = setup_teardown_vars[2] + + salt_call_cli.run("keychain.install", cert, passwd) + certs_list = salt_call_cli.run("keychain.list_certs") + + if cert_alias not in certs_list: + salt_call_cli.run("keychain.uninstall", cert_alias) + pytest.skip("Failed to install keychain") + + # uninstall cert + salt_call_cli.run("keychain.uninstall", cert_alias) + certs_list = salt_call_cli.run("keychain.list_certs") + + # check to ensure the cert was uninstalled + try: + assert cert_alias not in str(certs_list) + except CommandExecutionError: + salt_call_cli.run("keychain.uninstall", cert_alias) + + +def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli): + """ + Test that attempts to get friendly name of a cert + """ + cert = setup_teardown_vars[0] + cert_alias = setup_teardown_vars[1] + passwd = setup_teardown_vars[2] + + salt_call_cli.run("keychain.install", cert, passwd) + certs_list = salt_call_cli.run("keychain.list_certs") + if cert_alias not in certs_list: + salt_call_cli.run("keychain.uninstall", cert_alias) + pytest.skip("Failed to install keychain") + + get_name = salt_call_cli.run("keychain.get_friendly_name", cert, passwd) + assert get_name == cert_alias + + +def test_mac_keychain_get_default_keychain(salt_call_cli): + """ + Test that attempts to get the default keychain + """ + salt_get_keychain = salt_call_cli.run("keychain.get_default_keychain") + sys_get_keychain = salt_call_cli.run("cmd.run", "security default-keychain -d user") + assert salt_get_keychain == sys_get_keychain + + +def test_mac_keychain_list_certs(salt_call_cli): + """ + Test that attempts to list certs + """ + cert_default = "com.apple.systemdefault" + certs = salt_call_cli.run("keychain.list_certs") + assert cert_default in certs diff --git a/tests/pytests/integration/modules/test_mac_portspkg.py b/tests/pytests/integration/modules/test_mac_portspkg.py new file mode 100644 index 000000000000..16d5ae92560c --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_portspkg.py @@ -0,0 +1,95 @@ +""" +integration tests for mac_ports +""" + +import pytest + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + AGREE_INSTALLED = False + try: + AGREE_INSTALLED = "agree" in salt_call_cli.run("pkg.list_pkgs") + salt_call_cli.run("pkg.refresh_db") + yield + finally: + if AGREE_INSTALLED: + salt_call_cli.run("pkg.remove", "agree") + + +def test_list_pkgs(salt_call_cli, setup_teardown_vars): + """ + Test pkg.list_pkgs + """ + salt_call_cli.run("pkg.install", "agree") + assert isinstance(salt_call_cli.run("pkg.list_pkgs"), dict) + assert "agree" in salt_call_cli.run("pkg.list_pkgs") + + +def test_latest_version(salt_call_cli, setup_teardown_vars): + """ + Test pkg.latest_version + """ + salt_call_cli.run("pkg.install", "agree") + result = salt_call_cli.run("pkg.latest_version", "agree", refresh=False) + assert isinstance(result, dict) + assert "agree" in result + + +def test_remove(salt_call_cli, setup_teardown_vars): + """ + Test pkg.remove + """ + salt_call_cli.run("pkg.install", "agree") + removed = salt_call_cli.run("pkg.remove", "agree") + assert isinstance(removed, dict) + assert "agree" in removed + + +@pytest.mark.destructive_test +def test_install(salt_call_cli, setup_teardown_vars): + """ + Test pkg.install + """ + salt_call_cli.run("pkg.remove", "agree") + installed = salt_call_cli.run("pkg.install", "agree") + assert isinstance(installed, dict) + assert "agree" in installed + + +def test_list_upgrades(salt_call_cli, setup_teardown_vars): + """ + Test pkg.list_upgrades + """ + assert isinstance(salt_call_cli.run("pkg.list_upgrades", refresh=False), dict) + + +def test_upgrade_available(salt_call_cli, setup_teardown_vars): + """ + Test pkg.upgrade_available + """ + salt_call_cli.run("pkg.install", "agree") + assert not salt_call_cli.run("pkg.upgrade_available", "agree", refresh=False) + + +def test_refresh_db(salt_call_cli, setup_teardown_vars): + """ + Test pkg.refresh_db + """ + assert salt_call_cli.run("pkg.refresh_db") + + +def test_upgrade(salt_call_cli, setup_teardown_vars): + """ + Test pkg.upgrade + """ + results = salt_call_cli.run("pkg.upgrade", refresh=False) + assert isinstance(results, dict) + assert results["result"] diff --git a/tests/pytests/integration/modules/test_mac_power.py b/tests/pytests/integration/modules/test_mac_power.py new file mode 100644 index 000000000000..ba52b8b32b11 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_power.py @@ -0,0 +1,123 @@ +""" +integration tests for mac_power +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + COMPUTER_SLEEP = salt_call_cli.run("power.get_computer_sleep") + DISPLAY_SLEEP = salt_call_cli.run("power.get_display_sleep") + HARD_DISK_SLEEP = salt_call_cli.run("power.get_harddisk_sleep") + try: + yield + finally: + salt_call_cli.run("power.set_computer_sleep", COMPUTER_SLEEP) + salt_call_cli.run("power.set_display_sleep", DISPLAY_SLEEP) + salt_call_cli.run("power.set_harddisk_sleep", HARD_DISK_SLEEP) + + +def test_computer_sleep(salt_call_cli, setup_teardown_vars): + """ + Test power.get_computer_sleep + Test power.set_computer_sleep + """ + + # Normal Functionality + assert salt_call_cli.run("power.set_computer_sleep", 90) + assert salt_call_cli.run("power.get_computer_sleep") == "after 90 minutes" + assert salt_call_cli.run("power.set_computer_sleep", "Off") + assert salt_call_cli.run("power.get_computer_sleep") == "Never" + + # Test invalid input + assert "Invalid String Value for Minutes" in salt_call_cli.run( + "power.set_computer_sleep", "spongebob" + ) + assert "Invalid Integer Value for Minutes" in salt_call_cli.run( + "power.set_computer_sleep", 0 + ) + assert "Invalid Integer Value for Minutes" in salt_call_cli.run( + "power.set_computer_sleep", 181 + ) + assert "Invalid Boolean Value for Minutes" in salt_call_cli.run( + "power.set_computer_sleep", True + ) + + +def test_display_sleep(salt_call_cli, setup_teardown_vars): + """ + Test power.get_display_sleep + Test power.set_display_sleep + """ + + # Normal Functionality + assert salt_call_cli.run("power.set_display_sleep", 90) + assert salt_call_cli.run("power.get_display_sleep") == "after 90 minutes" + assert salt_call_cli.run("power.set_display_sleep", "Off") + assert salt_call_cli.run("power.get_display_sleep") == "Never" + + # Test invalid input + assert "Invalid String Value for Minutes" in salt_call_cli.run( + "power.set_display_sleep", "spongebob" + ) + assert "Invalid Integer Value for Minutes" in salt_call_cli.run( + "power.set_display_sleep", 0 + ) + assert "Invalid Integer Value for Minutes" in salt_call_cli.run( + "power.set_display_sleep", 181 + ) + assert "Invalid Boolean Value for Minutes" in salt_call_cli.run( + "power.set_display_sleep", True + ) + + +def test_harddisk_sleep(salt_call_cli, setup_teardown_vars): + """ + Test power.get_harddisk_sleep + Test power.set_harddisk_sleep + """ + + # Normal Functionality + assert salt_call_cli.run("power.set_harddisk_sleep", 90) + assert salt_call_cli.run("power.get_harddisk_sleep") == "after 90 minutes" + assert salt_call_cli.run("power.set_harddisk_sleep", "Off") + assert salt_call_cli.run("power.get_harddisk_sleep") == "Never" + + # Test invalid input + assert "Invalid String Value for Minutes" in salt_call_cli.run( + "power.set_harddisk_sleep", "spongebob" + ) + assert "Invalid Integer Value for Minutes" in salt_call_cli.run( + "power.set_harddisk_sleep", 0 + ) + assert "Invalid Integer Value for Minutes" in salt_call_cli.run( + "power.set_harddisk_sleep", 181 + ) + assert "Invalid Boolean Value for Minutes" in salt_call_cli.run( + "power.set_harddisk_sleep", True + ) + + +def test_restart_freeze(salt_call_cli, setup_teardown_vars): + """ + Test power.get_restart_freeze + Test power.set_restart_freeze + """ + # Normal Functionality + assert salt_call_cli.run("power.set_restart_freeze", "on") + assert salt_call_cli.run("power.get_restart_freeze") + # This will return False because mac fails to actually make the change + assert not salt_call_cli.run("power.set_restart_freeze", "off") + # Even setting to off returns true, it actually is never set + # This is an apple bug + assert salt_call_cli.run("power.get_restart_freeze") diff --git a/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py b/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py new file mode 100644 index 000000000000..2438e06ebdf9 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py @@ -0,0 +1,38 @@ +""" +integration tests for mac_power +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +def test_restart_power_failure(salt_call_cli): + """ + Test power.get_restart_power_failure + Test power.set_restart_power_failure + """ + RESTART_POWER = None + + ret = salt_call_cli.run("power.get_restart_power_failure") + if isinstance(ret, bool): + RESTART_POWER = ret + + # If available on this system, test it + if RESTART_POWER is None: + # Check for not available + ret = salt_call_cli.run("power.get_restart_power_failure") + assert "Error" in ret + else: + assert salt_call_cli.run("power.set_restart_power_failure", "on") + assert salt_call_cli.run("power.get_restart_power_failure") + assert salt_call_cli.run("power.set_restart_power_failure", "off") + assert not salt_call_cli.run("power.get_restart_power_failure") + + salt_call_cli.run("power.set_sleep_on_power_button", RESTART_POWER) diff --git a/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py b/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py new file mode 100644 index 000000000000..82fad62bdc30 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py @@ -0,0 +1,38 @@ +""" +integration tests for mac_power sleep_on_power_button +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +def test_sleep_on_power_button(salt_call_cli): + """ + Test power.get_sleep_on_power_button + Test power.set_sleep_on_power_button + """ + SLEEP_ON_BUTTON = None + + ret = salt_call_cli.run("power.get_sleep_on_power_button") + if isinstance(ret, bool): + SLEEP_ON_BUTTON = salt_call_cli.run("power.get_sleep_on_power_button") + + # If available on this system, test it + if SLEEP_ON_BUTTON is None: + # Check for not available + ret = salt_call_cli.run("power.get_sleep_on_power_button") + assert "Error" in ret + else: + assert salt_call_cli.run("power.set_sleep_on_power_button", "on") + assert salt_call_cli.run("power.get_sleep_on_power_button") + assert salt_call_cli.run("power.set_sleep_on_power_button", "off") + assert not salt_call_cli.run("power.get_sleep_on_power_button") + + salt_call_cli.run("power.set_sleep_on_power_button", SLEEP_ON_BUTTON) diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py b/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py new file mode 100644 index 000000000000..90e7903e4d0b --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py @@ -0,0 +1,36 @@ +""" +integration tests for mac_power wake_on_modem +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.skip_if_binaries_missing("systemsetup"), +] + + +def test_wake_on_modem(salt_call_cli): + """ + Test power.get_wake_on_modem + Test power.set_wake_on_modem + """ + WAKE_ON_MODEM = None + ret = salt_call_cli.run("power.get_wake_on_modem") + if isinstance(ret, bool): + WAKE_ON_MODEM = ret + + if WAKE_ON_MODEM is None: + # Check for not available + ret = salt_call_cli.run("power.get_wake_on_modem") + assert "Error" in ret + else: + assert salt_call_cli.run("power.set_wake_on_modem", "on") + assert salt_call_cli.run("power.get_wake_on_modem") + assert salt_call_cli.run("power.set_wake_on_modem", "off") + assert not salt_call_cli.run("power.get_wake_on_modem") + + salt_call_cli.run("power.set_wake_on_modem", WAKE_ON_MODEM) diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_net.py b/tests/pytests/integration/modules/test_mac_power_wake_on_net.py new file mode 100644 index 000000000000..3a816a7e2d78 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_power_wake_on_net.py @@ -0,0 +1,38 @@ +""" +integration tests for mac_power wake_on_network +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +def test_wake_on_network(salt_call_cli): + """ + Test power.get_wake_on_network + Test power.set_wake_on_network + """ + + WAKE_ON_NET = None + ret = salt_call_cli.run("power.get_wake_on_network") + if isinstance(ret, bool): + WAKE_ON_NET = ret + + # If available on this system, test it + if WAKE_ON_NET is None: + # Check for not available + ret = salt_call_cli.run("power.get_wake_on_network") + assert "Error" in ret + else: + assert salt_call_cli.run("power.set_wake_on_network", "on") + assert salt_call_cli.run("power.get_wake_on_network") + assert salt_call_cli.run("power.set_wake_on_network", "off") + assert not salt_call_cli.run("power.get_wake_on_network") + + salt_call_cli.run("power.set_wake_on_network", WAKE_ON_NET) diff --git a/tests/pytests/integration/modules/test_mac_service.py b/tests/pytests/integration/modules/test_mac_service.py new file mode 100644 index 000000000000..18ce16c21e68 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_service.py @@ -0,0 +1,218 @@ +""" +integration tests for mac_service +""" + +import plistlib + +import pytest + +import salt.utils.files + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.skip_if_binaries_missing("launchctl", "plutil"), + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + + SERVICE_NAME = "com.salt.integration.test" + SERVICE_PATH = "/Library/LaunchDaemons/com.salt.integration.test.plist" + + service_data = { + "KeepAlive": True, + "Label": SERVICE_NAME, + "ProgramArguments": ["/bin/sleep", "1000"], + "RunAtLoad": True, + } + with salt.utils.files.fopen(SERVICE_PATH, "wb") as fp: + plistlib.dump(service_data, fp) + salt_call_cli.run("service.enable", SERVICE_NAME) + salt_call_cli.run("service.start", SERVICE_NAME) + + try: + yield SERVICE_NAME + finally: + salt_call_cli.run("service.stop", SERVICE_NAME) + salt.utils.files.safe_rm(SERVICE_PATH) + + +def test_show(salt_call_cli, setup_teardown_vars): + """ + Test service.show + """ + SERVICE_NAME = setup_teardown_vars[0] + # Existing Service + service_info = salt_call_cli.run("service.show", [SERVICE_NAME]) + assert isinstance(service_info, dict) + assert service_info["plist"]["Label"] == SERVICE_NAME + + # Missing Service + assert "Service not found" in salt_call_cli.run("service.show", "spongebob") + + +def test_launchctl(salt_call_cli): + """ + Test service.launchctl + """ + # Expected Functionality + assert salt_call_cli.run("service.launchctl", "error", "bootstrap", 64) + assert ( + salt_call_cli.run( + "service.launchctl", ["error", "bootstrap", 64], return_stdout=True + ) + == "64: unknown error code" + ) + + # Raise an error + assert "Failed to error service" in salt_call_cli.run( + "service.launchctl", "error", "bootstrap" + ) + + +def test_list(salt_call_cli, setup_teardown_vars): + """ + Test service.list + """ + SERVICE_NAME = setup_teardown_vars[0] + # Expected Functionality + assert "PID" in salt_call_cli.run("service.list") + assert "{" in salt_call_cli.run("service.list", SERVICE_NAME) + + # Service not found + assert "Service not found" in salt_call_cli.run("service.list", "spongebob") + + +def test_enable(salt_call_cli, setup_teardown_vars): + """ + Test service.enable + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.enable", SERVICE_NAME) + + assert "Service not found" in salt_call_cli.run("service.enable", "spongebob") + + +def test_disable(salt_call_cli, setup_teardown_vars): + """ + Test service.disable + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.disable", SERVICE_NAME) + + assert "Service not found" in salt_call_cli.run("service.disable", "spongebob") + + +def test_start(salt_call_cli, setup_teardown_vars): + """ + Test service.start + Test service.stop + Test service.status + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.start", SERVICE_NAME) + + assert "Service not found" in salt_call_cli.run("service.start", "spongebob") + + +def test_stop(salt_call_cli, setup_teardown_vars): + """ + Test service.stop + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.stop", SERVICE_NAME) + + assert "Service not found" in salt_call_cli.run("service.stop", ["spongebob"]) + + +def test_status(salt_call_cli, setup_teardown_vars): + """ + Test service.status + """ + SERVICE_NAME = setup_teardown_vars[0] + # A running service + assert salt_call_cli.run("service.start", SERVICE_NAME) + assert salt_call_cli.run("service.status", SERVICE_NAME) + + # A stopped service + assert salt_call_cli.run("service.stop", SERVICE_NAME) + assert not salt_call_cli.run("service.status", SERVICE_NAME) + + # Service not found + assert not salt_call_cli.run("service.status", "spongebob") + + +def test_available(salt_call_cli, setup_teardown_vars): + """ + Test service.available + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.available", SERVICE_NAME) + assert not salt_call_cli.run("service.available", "spongebob") + + +def test_missing(salt_call_cli, setup_teardown_vars): + """ + Test service.missing + """ + SERVICE_NAME = setup_teardown_vars[0] + assert not salt_call_cli.run("service.missing", SERVICE_NAME) + assert salt_call_cli.run("service.missing", "spongebob") + + +def test_enabled(salt_call_cli, setup_teardown_vars): + """ + Test service.enabled + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.enabled", SERVICE_NAME) + assert salt_call_cli.run("service.start", SERVICE_NAME) + + assert salt_call_cli.run("service.enabled", SERVICE_NAME) + assert salt_call_cli.run("service.stop", SERVICE_NAME) + + assert salt_call_cli.run("service.enabled", "spongebob") + + +def test_disabled(salt_call_cli, setup_teardown_vars): + """ + Test service.disabled + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.start", SERVICE_NAME) + assert not salt_call_cli.run("service.disabled", SERVICE_NAME) + + assert salt_call_cli.run("service.disable", SERVICE_NAME) + assert salt_call_cli.run("service.disabled", SERVICE_NAME) + assert salt_call_cli.run("service.enable", SERVICE_NAME) + assert "Service not found" in salt_call_cli.run("service.stop", "spongebob") + + +def test_get_all(salt_call_cli, setup_teardown_vars): + """ + Test service.get_all + """ + SERVICE_NAME = setup_teardown_vars[0] + services = salt_call_cli.run("service.get_all") + assert isinstance(services, list) + assert SERVICE_NAME in services + + +def test_get_enabled(salt_call_cli, setup_teardown_vars): + """ + Test service.get_enabled + """ + SERVICE_NAME = setup_teardown_vars[0] + services = salt_call_cli.run("service.get_enabled") + assert isinstance(services, list) + assert SERVICE_NAME in services + + +def test_service_laoded(salt_call_cli, setup_teardown_vars): + """ + Test service.get_enabled + """ + SERVICE_NAME = setup_teardown_vars[0] + assert salt_call_cli.run("service.loaded", SERVICE_NAME) diff --git a/tests/pytests/integration/modules/test_mac_shadow.py b/tests/pytests/integration/modules/test_mac_shadow.py new file mode 100644 index 000000000000..c1d03465b3e0 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_shadow.py @@ -0,0 +1,226 @@ +""" +integration tests for mac_shadow +""" + +import datetime + +import pytest +from saltfactories.utils import random_string + +pytestmark = [ + pytest.mark.skip_if_binaries_missing("dscl", "pwpolicy"), + pytest.mark.skip_initial_gh_actions_failure, + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + TEST_USER = random_string("RS-", lowercase=False) + NO_USER = random_string("RS-", lowercase=False) + + salt_call_cli.run("user.add", TEST_USER) + + try: + yield TEST_USER, NO_USER + finally: + salt_call_cli.run("user.delete", TEST_USER) + + +def test_info(salt_call_cli, setup_teardown_vars): + """ + Test shadow.info + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + ret = salt_call_cli.run("shadow.info", TEST_USER) + assert ret["name"] == TEST_USER + + # User does not exist + ret = salt_call_cli.run("shadow.info", NO_USER) + assert ret["name"] == "" + + +def test_get_account_created(salt_call_cli, setup_teardown_vars): + """ + Test shadow.get_account_created + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + text_date = salt_call_cli.run("shadow.get_account_created", TEST_USER) + assert text_date != "Invalid Timestamp" + obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") + assert isinstance(obj_date, datetime.date) + + # User does not exist + assert ( + salt_call_cli.run("shadow.get_account_created", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_get_last_change(salt_call_cli, setup_teardown_vars): + """ + Test shadow.get_last_change + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + text_date = salt_call_cli.run("shadow.get_last_change", TEST_USER) + assert text_date != "Invalid Timestamp" + obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") + assert isinstance(obj_date, datetime.date) + + # User does not exist + assert ( + salt_call_cli.run("shadow.get_last_change", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_get_login_failed_last(salt_call_cli, setup_teardown_vars): + """ + Test shadow.get_login_failed_last + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + text_date = salt_call_cli.run("shadow.get_login_failed_last", TEST_USER) + assert text_date != "Invalid Timestamp" + obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") + assert isinstance(obj_date, datetime.date) + + # User does not exist + assert ( + salt_call_cli.run("shadow.get_login_failed_last", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_get_login_failed_count(salt_call_cli, setup_teardown_vars): + """ + Test shadow.get_login_failed_count + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + assert salt_call_cli.run("shadow.get_login_failed_count", TEST_USER) == "0" + + # User does not exist + assert ( + salt_call_cli.run("shadow.get_login_failed_count", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_get_set_maxdays(salt_call_cli, setup_teardown_vars): + """ + Test shadow.get_maxdays + Test shadow.set_maxdays + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + assert salt_call_cli.run("shadow.set_maxdays", TEST_USER, 20) + assert salt_call_cli.run("shadow.get_maxdays", TEST_USER) == 20 + + # User does not exist + assert ( + salt_call_cli.run("shadow.set_maxdays", NO_USER, 7) + == f"ERROR: User not found: {NO_USER}" + ) + assert ( + salt_call_cli.run("shadow.get_maxdays", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_get_set_change(salt_call_cli, setup_teardown_vars): + """ + Test shadow.get_change + Test shadow.set_change + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + assert salt_call_cli.run("shadow.set_change", TEST_USER, "02/11/2011") + assert salt_call_cli.run("shadow.get_change", TEST_USER) == "02/11/2011" + + # User does not exist + assert ( + salt_call_cli.run("shadow.set_change", NO_USER, "02/11/2012") + == f"ERROR: User not found: {NO_USER}" + ) + assert ( + salt_call_cli.run("shadow.get_change", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_get_set_expire(salt_call_cli, setup_teardown_vars): + """ + Test shadow.get_expire + Test shadow.set_expire + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + assert salt_call_cli.run("shadow.set_expire", TEST_USER, "02/11/2011") + assert salt_call_cli.run("shadow.get_expire", TEST_USER) == "02/11/2011" + + # User does not exist + assert ( + salt_call_cli.run("shadow.set_expire", NO_USER, "02/11/2012") + == f"ERROR: User not found: {NO_USER}" + ) + assert ( + salt_call_cli.run("shadow.get_expire", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_del_password(salt_call_cli, setup_teardown_vars): + """ + Test shadow.del_password + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + assert salt_call_cli.run("shadow.del_password", TEST_USER) + assert salt_call_cli.run("shadow.info", TEST_USER)["passwd"] == "*" + + # User does not exist + assert ( + salt_call_cli.run("shadow.del_password", NO_USER) + == f"ERROR: User not found: {NO_USER}" + ) + + +def test_set_password(salt_call_cli, setup_teardown_vars): + """ + Test shadow.set_password + """ + TEST_USER = setup_teardown_vars[0] + NO_USER = setup_teardown_vars[1] + + # Correct Functionality + assert salt_call_cli.run("shadow.set_password", TEST_USER, "Pa$$W0rd") + + # User does not exist + assert ( + salt_call_cli.run("shadow.set_password", NO_USER, "P@SSw0rd") + == f"ERROR: User not found: {NO_USER}" + ) diff --git a/tests/pytests/integration/modules/test_mac_softwareupdate.py b/tests/pytests/integration/modules/test_mac_softwareupdate.py new file mode 100644 index 000000000000..19502c348891 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_softwareupdate.py @@ -0,0 +1,144 @@ +""" +integration tests for mac_softwareupdate +""" + +import pytest + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.skip_if_binaries_missing("softwareupdate"), + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.skip_initial_gh_actions_failure, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + IGNORED_LIST = salt_call_cli.run("softwareupdate.list_ignored") + SCHEDULE = salt_call_cli.run("softwareupdate.schedule") + CATALOG = salt_call_cli.run("softwareupdate.get_catalog") + + try: + yield IGNORED_LIST, SCHEDULE, CATALOG + finally: + if IGNORED_LIST: + for item in IGNORED_LIST: + salt_call_cli.run_function("softwareupdate.ignore", item) + else: + salt_call_cli.run_function("softwareupdate.reset_ignored") + + salt_call_cli.run_function("softwareupdate.schedule", SCHEDULE) + + if CATALOG == "Default": + salt_call_cli.run_function("softwareupdate.reset_catalog") + else: + salt_call_cli.run_function("softwareupdate.set_catalog", CATALOG) + + +def test_list_available(salt_call_cli, setup_teardown_vars): + """ + Test softwareupdate.list_available + """ + # Can't predict what will be returned, so can only test that the return + # is the correct type, dict + assert isinstance(salt_call_cli.run("softwareupdate.list_available"), dict) + + +def test_ignore(salt_call_cli, setup_teardown_vars): + """ + Test softwareupdate.ignore + Test softwareupdate.list_ignored + Test softwareupdate.reset_ignored + """ + # Test reset_ignored + assert salt_call_cli.run("softwareupdate.reset_ignored") + assert salt_call_cli.run("softwareupdate.list_ignored") == [] + + # Test ignore + assert salt_call_cli.run("softwareupdate.ignore", "spongebob") + assert salt_call_cli.run("softwareupdate.ignore", "squidward") + + # Test list_ignored and verify ignore + assert "spongebob" in salt_call_cli.run("softwareupdate.list_ignored") + assert "squidward" in salt_call_cli.run("softwareupdate.list_ignored") + + +def test_schedule(salt_call_cli): + """ + Test softwareupdate.schedule_enable + Test softwareupdate.schedule_enabled + """ + # Test enable + assert salt_call_cli.run("softwareupdate.schedule_enable", True) + assert salt_call_cli.run("softwareupdate.schedule_enabled") + + # Test disable in case it was already enabled + assert salt_call_cli.run("softwareupdate.schedule_enable", False) + assert not salt_call_cli.run("softwareupdate.schedule_enabled") + + +def test_update(salt_call_cli, setup_teardown_vars): + """ + Test softwareupdate.update_all + Test softwareupdate.update + Test softwareupdate.update_available + + Need to know the names of updates that are available to properly test + the update functions... + """ + # There's no way to know what the dictionary will contain, so all we can + # check is that the return is a dictionary + assert isinstance(salt_call_cli.run("softwareupdate.update_all"), dict) + + # Test update_available + assert not salt_call_cli.run("softwareupdate.update_available", "spongebob") + + # Test update not available + assert "Update not available" in salt_call_cli.run( + "softwareupdate.update", "spongebob" + ) + + +def test_list_downloads(salt_call_cli, setup_teardown_vars): + """ + Test softwareupdate.list_downloads + """ + assert isinstance(salt_call_cli.run("softwareupdate.list_downloads"), list) + + +def test_download(salt_call_cli, setup_teardown_vars): + """ + Test softwareupdate.download + + Need to know the names of updates that are available to properly test + the download function + """ + # Test update not available + assert "Update not available" in salt_call_cli.run( + "softwareupdate.download", ["spongebob"] + ) + + +def test_download_all(salt_call_cli, setup_teardown_vars): + """ + Test softwareupdate.download_all + """ + assert isinstance(salt_call_cli.run("softwareupdate.download_all"), list) + + +def test_get_set_reset_catalog(salt_call_cli, setup_teardown_vars): + """ + Test softwareupdate.download_all + """ + # Reset the catalog + assert salt_call_cli.run("softwareupdate.reset_catalog") + assert salt_call_cli.run("softwareupdate.get_catalog") == "Default" + + # Test setting and getting the catalog + assert salt_call_cli.run("softwareupdate.set_catalog", "spongebob") + assert salt_call_cli.run("softwareupdate.get_catalog") == "spongebob" + + # Test reset the catalog + assert salt_call_cli.run("softwareupdate.reset_catalog") + assert salt_call_cli.run("softwareupdate.get_catalog") == "Default" diff --git a/tests/pytests/integration/modules/test_mac_sysctl.py b/tests/pytests/integration/modules/test_mac_sysctl.py new file mode 100644 index 000000000000..52933b2169c4 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_sysctl.py @@ -0,0 +1,182 @@ +""" + :codeauthor: Nicole Thomas +""" + +import os +import random + +import pytest + +import salt.utils.files +from salt.exceptions import CommandExecutionError + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def assign_cmd(): + return "net.inet.icmp.icmplim" + + +@pytest.fixture(scope="function") +def config_file(): + return "/etc/sysctl.conf" + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli, assign_cmd, config_file): + has_conf = False + val = salt_call_cli.run("sysctl.get", assign_cmd, config_file) + + # If sysctl file is present, make a copy + # Remove original file so we can replace it with test files + if os.path.isfile(config_file): + has_conf = True + try: + temp_sysctl_config = __copy_sysctl(config_file) + except CommandExecutionError: + msg = "Could not copy file: {0}" + raise CommandExecutionError(msg.format(config_file)) + os.remove(config_file) + + try: + yield val + finally: + ret = salt_call_cli.run("sysctl.get", assign_cmd) + if ret != val: + salt_call_cli.run("sysctl.assign", assign_cmd, val) + + if has_conf is True: + # restore original sysctl file + __restore_sysctl(config_file, temp_sysctl_config) + + if has_conf is False and os.path.isfile(config_file): + # remove sysctl.conf created by tests + os.remove(temp_sysctl_config) + + +def test_assign(salt_call_cli, assign_cmd, setup_teardown_vars): + """ + Tests assigning a single sysctl parameter + """ + val = setup_teardown_vars[0] + + try: + rand = random.randint(0, 500) + while rand == val: + rand = random.randint(0, 500) + salt_call_cli.run("sysctl.assign", assign_cmd, rand) + info = int(salt_call_cli.run("sysctl.get", assign_cmd)) + try: + assert rand == info + except AssertionError: + salt_call_cli.run("sysctl.assign", assign_cmd, val) + raise + except CommandExecutionError: + salt_call_cli.run("sysctl.assign", assign_cmd, val) + raise + + +def test_persist_new_file(salt_call_cli, assign_cmd, config_file): + """ + Tests assigning a sysctl value to a system without a sysctl.conf file + """ + # Always start with a clean/known sysctl.conf state + if os.path.isfile(config_file): + os.remove(config_file) + try: + salt_call_cli.run("sysctl.persist", assign_cmd, 10) + line = f"{assign_cmd}={10}" + found = __check_string(config_file, line) + assert found + except CommandExecutionError: + os.remove(config_file) + raise + + +def test_persist_already_set(salt_call_cli, config_file, setup_teardown_vars): + """ + Tests assigning a sysctl value that is already set in sysctl.conf file + """ + # Always start with a clean/known sysctl.conf state + if os.path.isfile(config_file): + os.remove(config_file) + try: + salt_call_cli.run("sysctl.persist", assign_cmd, 50) + ret = salt_call_cli.run("sysctl.persist", assign_cmd, 50) + assert ret == "Already set" + except CommandExecutionError: + os.remove(config_file) + raise + + +def test_persist_apply_change( + salt_call_cli, assign_cmd, config_file, setup_teardown_vars +): + """ + Tests assigning a sysctl value and applying the change to system + """ + val = setup_teardown_vars[0] + + # Always start with a clean/known sysctl.conf state + if os.path.isfile(config_file): + os.remove(config_file) + try: + rand = random.randint(0, 500) + while rand == val: + rand = random.randint(0, 500) + salt_call_cli.run("sysctl.persist", assign_cmd, rand, apply_change=True) + info = int(salt_call_cli.run("sysctl.get", assign_cmd)) + assert info == rand + except CommandExecutionError: + os.remove(config_file) + raise + + +def __copy_sysctl(CONFIG): + """ + Copies an existing sysconf file and returns temp file path. Copied + file will be restored in tearDown + """ + # Create new temporary file path and open needed files + temp_path = salt.utils.files.mkstemp() + with salt.utils.files.fopen(CONFIG, "r") as org_conf: + with salt.utils.files.fopen(temp_path, "w") as temp_sysconf: + # write sysctl lines to temp file + for line in org_conf: + temp_sysconf.write(line) + return temp_path + + +def __restore_sysctl(sysctl_config, temp_sysctl_config): + """ + Restores the original sysctl.conf file from temporary copy + """ + # If sysctl testing file exists, delete it + if os.path.isfile(sysctl_config): + os.remove(sysctl_config) + + # write temp lines to sysctl file to restore + with salt.utils.files.fopen(temp_sysctl_config, "r") as temp_sysctl: + with salt.utils.files.fopen(sysctl_config, "w") as sysctl: + for line in temp_sysctl: + sysctl.write(line) + + # delete temporary file + os.remove(temp_sysctl_config) + + +def __check_string(conf_file, to_find): + """ + Returns True if given line is present in file + """ + with salt.utils.files.fopen(conf_file, "r") as f_in: + for line in f_in: + if to_find in salt.utils.stringutils.to_unicode(line): + return True + return False diff --git a/tests/pytests/integration/modules/test_mac_system.py b/tests/pytests/integration/modules/test_mac_system.py new file mode 100644 index 000000000000..ddadd9ad9c77 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_system.py @@ -0,0 +1,211 @@ +""" +integration tests for mac_system +""" + +import logging + +import pytest +from saltfactories.utils import random_string + +log = logging.getLogger(__name__) + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.usefixtures("salt_sub_minion"), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.skip_initial_gh_actions_failure, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + ATRUN_ENABLED = salt_call_cli.run("service.enabled", "com.apple.atrun") + REMOTE_LOGIN_ENABLED = salt_call_cli.run("system.get_remote_login") + REMOTE_EVENTS_ENABLED = salt_call_cli.run("system.get_remote_events") + SUBNET_NAME = salt_call_cli.run("system.get_subnet_name") + KEYBOARD_DISABLED = salt_call_cli.run("system.get_disable_keyboard_on_lock") + + try: + yield + finally: + if not ATRUN_ENABLED: + atrun = "/System/Library/LaunchDaemons/com.apple.atrun.plist" + salt_call_cli.run("service.stop", atrun) + + salt_call_cli.run("system.set_remote_login", REMOTE_LOGIN_ENABLED) + salt_call_cli.run("system.set_remote_events", REMOTE_EVENTS_ENABLED) + salt_call_cli.run("system.set_subnet_name", SUBNET_NAME) + salt_call_cli.run("system.set_disable_keyboard_on_lock", KEYBOARD_DISABLED) + + +def test_get_set_remote_login(salt_call_cli): + """ + Test system.get_remote_login + Test system.set_remote_login + """ + # Normal Functionality + assert salt_call_cli.run("system.set_remote_login", True) + assert salt_call_cli.run("system.get_remote_login") + assert salt_call_cli.run("system.set_remote_login", False) + assert not salt_call_cli.run("system.get_remote_login") + + # Test valid input + assert salt_call_cli.run("system.set_remote_login", True) + assert salt_call_cli.run("system.set_remote_login", False) + assert salt_call_cli.run("system.set_remote_login", "yes") + assert salt_call_cli.run("system.set_remote_login", "no") + assert salt_call_cli.run("system.set_remote_login", "On") + assert salt_call_cli.run("system.set_remote_login", "Off") + assert salt_call_cli.run("system.set_remote_login", 1) + assert salt_call_cli.run("system.set_remote_login", 0) + + # Test invalid input + assert "Invalid String Value for Enabled" in salt_call_cli.run( + "system.set_remote_login", "spongebob" + ) + + +def test_get_set_remote_events(salt_call_cli): + """ + Test system.get_remote_events + Test system.set_remote_events + """ + # Normal Functionality + assert salt_call_cli.run("system.set_remote_events", True) + assert salt_call_cli.run("system.get_remote_events") + assert salt_call_cli.run("system.set_remote_events", False) + assert not salt_call_cli.run("system.get_remote_events") + + # Test valid input + assert salt_call_cli.run("system.set_remote_events", True) + assert salt_call_cli.run("system.set_remote_events", False) + assert salt_call_cli.run("system.set_remote_events", "yes") + assert salt_call_cli.run("system.set_remote_events", "no") + assert salt_call_cli.run("system.set_remote_events", "On") + assert salt_call_cli.run("system.set_remote_events", "Off") + assert salt_call_cli.run("system.set_remote_events", 1) + assert salt_call_cli.run("system.set_remote_events", 0) + + # Test invalid input + assert "Invalid String Value for Enabled" in salt_call_cli.run( + "system.set_remote_events", "spongebob" + ) + + +def test_get_set_subnet_name(salt_call_cli): + """ + Test system.get_subnet_name + Test system.set_subnet_name + """ + SET_SUBNET_NAME = random_string("RS-", lowercase=False) + + assert salt_call_cli.run("system.set_subnet_name", SET_SUBNET_NAME) + assert salt_call_cli.run("system.get_subnet_name") == SET_SUBNET_NAME + + +def test_get_list_startup_disk(salt_call_cli): + """ + Test system.get_startup_disk + Test system.list_startup_disks + Don't know how to test system.set_startup_disk as there's usually only + one startup disk available on a system + """ + # Test list and get + ret = salt_call_cli.run("system.list_startup_disks") + assert isinstance(ret, list) + assert salt_call_cli.run("system.get_startup_disk") in ret + + # Test passing set a bad disk + assert "Invalid value passed for path." in salt_call_cli.run( + "system.set_startup_disk", "spongebob" + ) + + +@pytest.mark.skip(reason="Skip this test until mac fixes it.") +def test_get_set_restart_delay(salt_call_cli): + """ + Test system.get_restart_delay + Test system.set_restart_delay + system.set_restart_delay does not work due to an apple bug, see docs + may need to disable this test as we can't control the delay value + """ + # Normal Functionality + assert salt_call_cli.run("system.set_restart_delay", 90) + assert salt_call_cli.run("system.get_restart_delay") == "90 seconds" + + # Pass set bad value for seconds + assert "Invalid value passed for seconds." in salt_call_cli.run( + "system.set_restart_delay", 70 + ) + + +def test_get_set_disable_keyboard_on_lock(salt_call_cli): + """ + Test system.get_disable_keyboard_on_lock + Test system.set_disable_keyboard_on_lock + """ + # Normal Functionality + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", True) + assert salt_call_cli.run("system.get_disable_keyboard_on_lock") + + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", False) + assert not salt_call_cli.run("system.get_disable_keyboard_on_lock") + + # Test valid input + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", True) + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", False) + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "yes") + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "no") + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "On") + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "Off") + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", 1) + assert salt_call_cli.run("system.set_disable_keyboard_on_lock", 0) + + # Test invalid input + assert "Invalid String Value for Enabled" in salt_call_cli.run( + "system.set_disable_keyboard_on_lock", "spongebob" + ) + + +@pytest.mark.skip(reason="Skip this test until mac fixes it.") +def test_get_set_boot_arch(salt_call_cli): + """ + Test system.get_boot_arch + Test system.set_boot_arch + system.set_boot_arch does not work due to an apple bug, see docs + may need to disable this test as we can't set the boot architecture + """ + # Normal Functionality + assert salt_call_cli.run("system.set_boot_arch", "i386") + assert salt_call_cli.run("system.get_boot_arch") == "i386" + assert salt_call_cli.run("system.set_boot_arch", "default") + assert salt_call_cli.run("system.get_boot_arch") == "default" + + # Test invalid input + assert "Invalid value passed for arch" in salt_call_cli.run( + "system.set_boot_arch", "spongebob" + ) + + +# A similar test used to be skipped on py3 due to 'hanging', if we see +# something similar again we may want to skip this gain until we +# investigate +# @pytest.mark.skipif(salt.utils.platform.is_darwin() and six.PY3, reason='This test hangs on OS X on Py3. Skipping until #53566 is merged.') +@pytest.mark.destructive_test +def test_get_set_computer_name(salt_call_cli): + """ + Test system.get_computer_name + Test system.set_computer_name + """ + SET_COMPUTER_NAME = random_string("RS-", lowercase=False) + + COMPUTER_NAME = salt_call_cli.run("system.get_computer_name") + + log.debug("Set name is %s", SET_COMPUTER_NAME) + assert salt_call_cli.run("system.set_computer_name", [SET_COMPUTER_NAME]) + assert salt_call_cli.run("system.get_computer_name") == SET_COMPUTER_NAME + + salt_call_cli.run("system.set_computer_name", COMPUTER_NAME) diff --git a/tests/pytests/integration/modules/test_mac_timezone.py b/tests/pytests/integration/modules/test_mac_timezone.py new file mode 100644 index 000000000000..1b7382ab088c --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_timezone.py @@ -0,0 +1,202 @@ +""" +Integration tests for mac_timezone + +If using parallels, make sure Time sync is turned off. Otherwise, parallels will +keep changing your date/time settings while the tests are running. To turn off +Time sync do the following: + - Go to actions -> configure + - Select options at the top and 'More Options' on the left + - Set time to 'Do not sync' +""" + +import datetime + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=4), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + USE_NETWORK_TIME = salt_call_cli.run("timezone.get_using_network_time") + TIME_SERVER = salt_call_cli.run("timezone.get_time_server") + TIME_ZONE = salt_call_cli.run("timezone.get_zone") + CURRENT_DATE = salt_call_cli.run("timezone.get_date") + CURRENT_TIME = salt_call_cli.run("timezone.get_time") + + salt_call_cli.run("timezone.set_using_network_time", False) + salt_call_cli.run("timezone.set_zone", "America/Denver") + + try: + yield + finally: + salt_call_cli.run("timezone.set_time_server", TIME_SERVER) + salt_call_cli.run("timezone.set_using_network_time", USE_NETWORK_TIME) + salt_call_cli.run("timezone.set_zone", TIME_ZONE) + if not USE_NETWORK_TIME: + salt_call_cli.run("timezone.set_date", CURRENT_DATE) + salt_call_cli.run("timezone.set_time", CURRENT_TIME) + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_date(salt_call_cli): + """ + Test timezone.get_date + Test timezone.set_date + """ + # Correct Functionality + assert salt_call_cli.run("timezone.set_date", "2/20/2011") + assert salt_call_cli.run("timezone.get_date") == "2/20/2011" + + # Test bad date format + assert ( + salt_call_cli.run("timezone.set_date", "13/12/2014") + == "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014" + ) + + +@pytest.mark.slow_test +def test_get_time(salt_call_cli): + """ + Test timezone.get_time + """ + text_time = salt_call_cli.run("timezone.get_time") + assert text_time != "Invalid Timestamp" + obj_date = datetime.datetime.strptime(text_time, "%H:%M:%S") + assert isinstance(obj_date, datetime.date) + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_set_time(salt_call_cli): + """ + Test timezone.set_time + """ + # Correct Functionality + assert salt_call_cli.run("timezone.set_time", "3:14") + + # Test bad time format + assert ( + salt_call_cli.run("timezone.set_time", "3:71") + == "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" + ) + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_zone(salt_call_cli): + """ + Test timezone.get_zone + Test timezone.set_zone + """ + # Correct Functionality + assert salt_call_cli.run("timezone.set_zone", "Pacific/Wake") + assert salt_call_cli.run("timezone.get_zone") == "Pacific/Wake" + + # Test bad time zone + assert ( + salt_call_cli.run("timezone.set_zone", "spongebob") + == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" + ) + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_offset(salt_call_cli): + """ + Test timezone.get_offset + """ + assert salt_call_cli.run("timezone.set_zone", "Pacific/Wake") + assert isinstance(salt_call_cli.run("timezone.get_offset"), (str,)) + assert salt_call_cli.run("timezone.get_offset") == "+1200" + + assert salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") + assert isinstance(salt_call_cli.run("timezone.get_offset"), (str,)) + assert salt_call_cli.run("timezone.get_offset") == "-0700" + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_zonecode(salt_call_cli): + """ + Test timezone.get_zonecode + Test timezone.set_zonecode + """ + assert salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") + assert isinstance(salt_call_cli.run("timezone.get_zonecode"), (str,)) + assert salt_call_cli.run("timezone.get_zonecode") == "PDT" + + assert salt_call_cli.run("timezone.set_zone", "Pacific/Wake") + assert isinstance(salt_call_cli.run("timezone.get_zonecode"), (str,)) + assert salt_call_cli.run("timezone.get_zonecode") == "WAKT" + + +@pytest.mark.slow_test +def test_list_zones(salt_call_cli): + """ + Test timezone.list_zones + """ + zones = salt_call_cli.run("timezone.list_zones") + assert isinstance(zones, list) + assert "America/Denver" in zones + assert "America/Los_Angeles" in zones + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_zone_compare(salt_call_cli): + """ + Test timezone.zone_compare + """ + assert salt_call_cli.run("timezone.set_zone", "America/Denver") + assert salt_call_cli.run("timezone.zone_compare", "America/Denver") + assert not salt_call_cli.run("timezone.zone_compare", "Pacific/Wake") + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_using_network_time(salt_call_cli): + """ + Test timezone.get_using_network_time + Test timezone.set_using_network_time + """ + assert salt_call_cli.run("timezone.set_using_network_time", True) + assert salt_call_cli.run("timezone.get_using_network_time") + + assert salt_call_cli.run("timezone.set_using_network_time", False) + assert not salt_call_cli.run("timezone.get_using_network_time") + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_time_server(salt_call_cli): + """ + Test timezone.get_time_server + Test timezone.set_time_server + """ + assert salt_call_cli.run("timezone.set_time_server", "spongebob.com") + assert salt_call_cli.run("timezone.get_time_server") == "spongebob.com" diff --git a/tests/pytests/integration/modules/test_mac_user.py b/tests/pytests/integration/modules/test_mac_user.py new file mode 100644 index 000000000000..b6ec05ecc602 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_user.py @@ -0,0 +1,234 @@ +""" + :codeauthor: Nicole Thomas +""" + +import os + +import pytest +from saltfactories.utils import random_string + +import salt.utils.files +from salt.exceptions import CommandExecutionError + +# Create user strings for tests + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli): + os_grain = salt_call_cli.run("grains.item", ["kernel"]) + if os_grain["kernel"] not in "Darwin": + pytest.skip("Test not applicable to '{kernel}' kernel".format(**os_grain)) + + ADD_USER = random_string("RS-", lowercase=False) + DEL_USER = random_string("RS-", lowercase=False) + PRIMARY_GROUP_USER = random_string("RS-", lowercase=False) + CHANGE_USER = random_string("RS-", lowercase=False) + + try: + yield ADD_USER, DEL_USER, PRIMARY_GROUP_USER, CHANGE_USER + finally: + # Delete ADD_USER + add_info = salt_call_cli.run("user.info", ADD_USER) + if add_info: + salt_call_cli.run("user.delete", ADD_USER) + + # Delete DEL_USER if something failed + del_info = salt_call_cli.run("user.info", DEL_USER) + if del_info: + salt_call_cli.run("user.delete", DEL_USER) + + # Delete CHANGE_USER + change_info = salt_call_cli.run("user.info", CHANGE_USER) + if change_info: + salt_call_cli.run("user.delete", CHANGE_USER) + + +def test_mac_user_add(salt_call_cli, setup_teardown_vars): + """ + Tests the add function + """ + ADD_USER = setup_teardown_vars[0] + + try: + salt_call_cli.run("user.add", ADD_USER) + user_info = salt_call_cli.run("user.info", ADD_USER) + assert ADD_USER == user_info["name"] + except CommandExecutionError: + salt_call_cli.run("user.delete", ADD_USER) + raise + + +@pytest.mark.slow_test +def test_mac_user_delete(salt_call_cli, setup_teardown_vars): + """ + Tests the delete function + """ + DEL_USER = setup_teardown_vars[1] + + # Create a user to delete - If unsuccessful, skip the test + if salt_call_cli.run("user.add", DEL_USER) is not True: + salt_call_cli.run("user.delete", DEL_USER) + pytest.skip("Failed to create a user to delete") + + # Now try to delete the added user + ret = salt_call_cli.run("user.delete", DEL_USER) + assert ret + + +@pytest.mark.slow_test +def test_mac_user_primary_group(salt_call_cli, setup_teardown_vars): + """ + Tests the primary_group function + """ + PRIMARY_GROUP_USER = setup_teardown_vars[2] + + # Create a user to test primary group function + if salt_call_cli.run("user.add", PRIMARY_GROUP_USER) is not True: + salt_call_cli.run("user.delete", PRIMARY_GROUP_USER) + pytest.skip("Failed to create a user") + + try: + # Test mac_user.primary_group + primary_group = salt_call_cli.run("user.primary_group", PRIMARY_GROUP_USER) + uid_info = salt_call_cli.run("user.info", PRIMARY_GROUP_USER) + assert primary_group in uid_info["groups"] + + except AssertionError: + salt_call_cli.run("user.delete", PRIMARY_GROUP_USER) + raise + + +@pytest.mark.slow_test +def test_mac_user_changes(salt_call_cli, setup_teardown_vars): + """ + Tests mac_user functions that change user properties + """ + CHANGE_USER = setup_teardown_vars[3] + + # Create a user to manipulate - if unsuccessful, skip the test + if salt_call_cli.run("user.add", CHANGE_USER) is not True: + salt_call_cli.run("user.delete", CHANGE_USER) + pytest.skip("Failed to create a user") + + try: + # Test mac_user.chuid + salt_call_cli.run("user.chuid", CHANGE_USER, 4376) + uid_info = salt_call_cli.run("user.info", CHANGE_USER) + assert uid_info["uid"] == 4376 + + # Test mac_user.chgid + salt_call_cli.run("user.chgid", CHANGE_USER, 4376) + gid_info = salt_call_cli.run("user.info", CHANGE_USER) + assert gid_info["gid"] == 4376 + + # Test mac.user.chshell + salt_call_cli.run("user.chshell", CHANGE_USER, "/bin/zsh") + shell_info = salt_call_cli.run("user.info", CHANGE_USER) + assert shell_info["shell"] == "/bin/zsh" + + # Test mac_user.chhome + salt_call_cli.run("user.chhome", CHANGE_USER, "/Users/foo") + home_info = salt_call_cli.run("user.info", CHANGE_USER) + assert home_info["home"] == "/Users/foo" + + # Test mac_user.chfullname + salt_call_cli.run("user.chfullname", CHANGE_USER, "Foo Bar") + fullname_info = salt_call_cli.run("user.info", CHANGE_USER) + assert fullname_info["fullname"] == "Foo Bar" + + # Test mac_user.chgroups + pre_info = salt_call_cli.run("user.info", CHANGE_USER)["groups"] + expected = pre_info + ["wheel"] + salt_call_cli.run("user.chgroups", CHANGE_USER, "wheel") + groups_info = salt_call_cli.run("user.info", CHANGE_USER) + assert groups_info["groups"] == expected + + except AssertionError: + salt_call_cli.run("user.delete", CHANGE_USER) + raise + + +@pytest.mark.slow_test +def test_mac_user_enable_auto_login(salt_call_cli): + """ + Tests mac_user functions that enable auto login + """ + # Make sure auto login is disabled before we start + if salt_call_cli.run("user.get_auto_login"): + pytest.skip("Auto login already enabled") + + try: + # Does enable return True + assert salt_call_cli.run("user.enable_auto_login", ["Spongebob", "Squarepants"]) + + # Did it set the user entry in the plist file + assert salt_call_cli.run("user.get_auto_login") == "Spongebob" + + # Did it generate the `/etc/kcpassword` file + assert os.path.exists("/etc/kcpassword") + + # Are the contents of the file correct + test_data = bytes.fromhex("2e f8 27 42 a0 d9 ad 8b cd cd 6c 7d") + with salt.utils.files.fopen("/etc/kcpassword", "rb") as f: + file_data = f.read() + assert test_data == file_data + + # Does disable return True + assert salt_call_cli.run("user.disable_auto_login") + + # Does it remove the user entry in the plist file + assert not salt_call_cli.run("user.get_auto_login") + + # Is the `/etc/kcpassword` file removed + assert not os.path.exists("/etc/kcpassword") + + finally: + # Make sure auto_login is disabled + assert salt_call_cli.run("user.disable_auto_login") + + # Make sure autologin is disabled + if salt_call_cli.run("user.get_auto_login"): + raise Exception("Failed to disable auto login") + + +@pytest.mark.slow_test +def test_mac_user_disable_auto_login(salt_call_cli): + """ + Tests mac_user functions that disable auto login + """ + # Make sure auto login is enabled before we start + # Is there an existing setting + if salt_call_cli.run("user.get_auto_login"): + pytest.skip("Auto login already enabled") + + try: + # Enable auto login for the test + salt_call_cli.run("user.enable_auto_login", ["Spongebob", "Squarepants"]) + + # Make sure auto login got set up + if not salt_call_cli.run("user.get_auto_login") == "Spongebob": + raise Exception("Failed to enable auto login") + + # Does disable return True + assert salt_call_cli.run("user.disable_auto_login") + + # Does it remove the user entry in the plist file + assert not salt_call_cli.run("user.get_auto_login") + + # Is the `/etc/kcpassword` file removed + assert not os.path.exists("/etc/kcpassword") + + finally: + # Make sure auto login is disabled + assert salt_call_cli.run("user.disable_auto_login") + + # Make sure auto login is disabled + if salt_call_cli.run("user.get_auto_login"): + raise Exception("Failed to disable auto login") diff --git a/tests/pytests/integration/modules/test_mac_xattr.py b/tests/pytests/integration/modules/test_mac_xattr.py new file mode 100644 index 000000000000..7c36df639321 --- /dev/null +++ b/tests/pytests/integration/modules/test_mac_xattr.py @@ -0,0 +1,166 @@ +""" +integration tests for mac_xattr +""" + +import os + +import pytest + +pytestmark = [ + pytest.mark.skip_if_binaries_missing("xattr"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli, tmp_path): + test_file = tmp_path / "xattr_test_file.txt" + no_file = tmp_path / "xattr_no_file.txt" + + salt_call_cli.run("file.touch", test_file) + + try: + yield test_file, no_file + finally: + if os.path.exists(test_file): + os.remove(test_file) + + +def test_list_no_xattr(salt_call_cli, setup_teardown_vars): + """ + Make sure there are no attributes + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + assert salt_call_cli.run("xattr.clear", test_file) + + # Test no attributes + assert salt_call_cli.run("xattr.list", test_file) == {} + + # Test file not found + assert ( + salt_call_cli.run("xattr.list", no_file) == f"ERROR: File not found: {no_file}" + ) + + +def test_write(salt_call_cli, setup_teardown_vars): + """ + Write an attribute + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + assert salt_call_cli.run("xattr.clear", test_file) + + # Write some attributes + assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + assert salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") + assert salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + + # Test that they were actually added + assert salt_call_cli.run("xattr.list", test_file) == { + "spongebob": "squarepants", + "squidward": "plankton", + "crabby": "patty", + } + + # Test file not found + assert ( + salt_call_cli.run("xattr.write", no_file, "patrick", "jellyfish") + == f"ERROR: File not found: {no_file}" + ) + + +def test_read(salt_call_cli, setup_teardown_vars): + """ + Test xattr.read + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + assert salt_call_cli.run("xattr.clear", test_file) + + # Write an attribute + assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + + # Read the attribute + assert salt_call_cli.run("xattr.read", test_file, "spongebob") == "squarepants" + + # Test file not found + assert ( + salt_call_cli.run("xattr.read", no_file, "spongebob") + == f"ERROR: File not found: {no_file}" + ) + + # Test attribute not found + assert ( + salt_call_cli.run("xattr.read", test_file, "patrick") + == "ERROR: Attribute not found: patrick" + ) + + +def test_delete(salt_call_cli, setup_teardown_vars): + """ + Test xattr.delete + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + assert salt_call_cli.run("xattr.clear", test_file) + + # Write some attributes + assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + assert salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") + assert salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + + # Delete an attribute + assert salt_call_cli.run("xattr.delete", test_file, "squidward") + + # Make sure it was actually deleted + assert salt_call_cli.run("xattr.list", test_file) == { + "spongebob": "squarepants", + "crabby": "patty", + } + + # Test file not found + assert ( + salt_call_cli.run("xattr.delete", no_file, "spongebob") + == f"ERROR: File not found: {no_file}" + ) + + # Test attribute not found + assert ( + salt_call_cli.run("xattr.delete", test_file, "patrick") + == "ERROR: Attribute not found: patrick" + ) + + +def test_clear(salt_call_cli, setup_teardown_vars): + """ + Test xattr.clear + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + assert salt_call_cli.run("xattr.clear", test_file) + + # Write some attributes + assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + assert salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") + assert salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + + # Test Clear + assert salt_call_cli.run("xattr.clear", test_file) + + # Test file not found + assert ( + salt_call_cli.run("xattr.clear", no_file) == f"ERROR: File not found: {no_file}" + ) From 705cdb0353671f16943fb04e29fdd660cda76a57 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Thu, 9 Nov 2023 15:56:52 -0800 Subject: [PATCH 02/37] Fixing test_mac_brew_pkg failures. --- .../integration/modules/test_mac_brew_pkg.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/pytests/integration/modules/test_mac_brew_pkg.py b/tests/pytests/integration/modules/test_mac_brew_pkg.py index d298116cc676..6aa4ae150be5 100644 --- a/tests/pytests/integration/modules/test_mac_brew_pkg.py +++ b/tests/pytests/integration/modules/test_mac_brew_pkg.py @@ -33,7 +33,8 @@ def setup_teardown_vars(salt_call_cli, add_pkg, del_pkg): try: yield finally: - pkg_list = salt_call_cli.run("pkg.list_pkgs") + ret = salt_call_cli.run("pkg.list_pkgs") + pkg_list = ret.data # Remove any installed packages if add_pkg in pkg_list: @@ -48,7 +49,8 @@ def test_brew_install(salt_call_cli, add_pkg, setup_teardown_vars): """ try: salt_call_cli.run("pkg.install", add_pkg) - pkg_list = salt_call_cli.run("pkg.list_pkgs") + ret = salt_call_cli.run("pkg.list_pkgs") + pkg_list = ret.data try: assert add_pkg in pkg_list except AssertionError: @@ -66,14 +68,16 @@ def test_remove(salt_call_cli, del_pkg, setup_teardown_vars): try: # Install a package to delete - If unsuccessful, skip the test salt_call_cli.run("pkg.install", del_pkg) - pkg_list = salt_call_cli.run("pkg.list_pkgs") + ret = salt_call_cli.run("pkg.list_pkgs") + pkg_list = ret.data if del_pkg not in pkg_list: salt_call_cli.run("pkg.install", del_pkg) pytest.skip("Failed to install a package to delete") # Now remove the installed package salt_call_cli.run("pkg.remove", del_pkg) - del_list = salt_call_cli.run("pkg.list_pkgs") + ret = salt_call_cli.run("pkg.list_pkgs") + del_list = ret.data assert del_pkg not in del_list except CommandExecutionError: salt_call_cli.run("pkg.remove", del_pkg) @@ -87,8 +91,10 @@ def test_version(salt_call_cli, add_pkg, setup_teardown_vars): """ try: salt_call_cli.run("pkg.install", add_pkg) - pkg_list = salt_call_cli.run("pkg.list_pkgs") - version = salt_call_cli.run("pkg.version", add_pkg) + ret = salt_call_cli.run("pkg.list_pkgs") + pkg_list = ret.data + ret = salt_call_cli.run("pkg.version", add_pkg) + version = ret.data try: assert version, "version: {} is empty, or other issue is present".format( version @@ -152,7 +158,8 @@ def test_list_upgrades(salt_call_cli, add_pkg, setup_teardown_vars): 'name2': 'version2', ... } """ try: - upgrades = salt_call_cli.run("pkg.list_upgrades") + ret = salt_call_cli.run("pkg.list_upgrades") + upgrades = ret.data try: assert isinstance(upgrades, dict) if upgrades: @@ -174,7 +181,8 @@ def test_info_installed(salt_call_cli, add_pkg, setup_teardown_vars): """ try: salt_call_cli.run("pkg.install", add_pkg) - info = salt_call_cli.run("pkg.info_installed", add_pkg) + ret = salt_call_cli.run("pkg.info_installed", add_pkg) + info = ret.data try: assert add_pkg in info assert "versions" in info[add_pkg] From 97ee142bbe0e3c0b28f32bf68c9619b8bcc6df4a Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Thu, 9 Nov 2023 16:31:39 -0800 Subject: [PATCH 03/37] fixing test_mac_assistive.py --- .../integration/modules/test_mac_assistive.py | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/pytests/integration/modules/test_mac_assistive.py b/tests/pytests/integration/modules/test_mac_assistive.py index 527a804f76fb..e7d044c659df 100644 --- a/tests/pytests/integration/modules/test_mac_assistive.py +++ b/tests/pytests/integration/modules/test_mac_assistive.py @@ -18,17 +18,19 @@ def osa_script(): @pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli, osa_script, setup_teardown_vars): +def setup_teardown_vars(salt_call_cli, osa_script): salt_call_cli.run("assistive.install", osa_script, True) try: yield finally: - osa_script_ret = salt_call_cli.run("assistive.installed", osa_script) + ret = salt_call_cli.run("assistive.installed", osa_script) + osa_script_ret = ret.data if osa_script_ret: salt_call_cli.run("assistive.remove", osa_script) smile_bundle = "com.smileonmymac.textexpander" - smile_bundle_present = salt_call_cli.run("assistive.installed", smile_bundle) + ret = salt_call_cli.run("assistive.installed", smile_bundle) + smile_bundle_present = ret.data if smile_bundle_present: salt_call_cli.run("assistive.remove", smile_bundle) @@ -49,11 +51,13 @@ def test_installed(salt_call_cli, osa_script, setup_teardown_vars): Tests the True and False return of assistive.installed. """ # OSA script should have been installed in setUp function - assert salt_call_cli.run("assistive.installed", osa_script) + ret = salt_call_cli.run("assistive.installed", osa_script) + assert ret.data # Clean up install salt_call_cli.run("assistive.remove", osa_script) # Installed should now return False - assert not salt_call_cli.run("assistive.installed", osa_script) + ret = salt_call_cli.run("assistive.installed", osa_script) + assert not ret.data @pytest.mark.slow_test @@ -63,13 +67,17 @@ def test_enable(salt_call_cli, osa_script, setup_teardown_vars): """ # OSA script should have been installed and enabled in setUp function # Now let's disable it, which should return True. - assert salt_call_cli.run("assistive.enable", osa_script, False) + ret = salt_call_cli.run("assistive.enable", osa_script, False) + assert ret.data # Double check the script was disabled, as intended. - assert not salt_call_cli.run("assistive.enabled", osa_script) + ret = salt_call_cli.run("assistive.enabled", osa_script) + assert not ret.data # Now re-enable - assert salt_call_cli.run("assistive.enable", osa_script) + ret = salt_call_cli.run("assistive.enable", osa_script) + assert ret.data # Double check the script was enabled, as intended. - assert salt_call_cli.run("assistive.enabled", osa_script) + ret = salt_call_cli.run("assistive.enabled", osa_script) + assert ret.data @pytest.mark.slow_test @@ -79,8 +87,10 @@ def test_enabled(salt_call_cli, osa_script, setup_teardown_vars): """ # OSA script should have been installed in setUp function, which sets # enabled to True by default. - assert salt_call_cli.run("assistive.enabled", osa_script) + ret = salt_call_cli.run("assistive.enabled", osa_script) + assert ret.data # Disable OSA Script salt_call_cli.run("assistive.enable", osa_script, False) # Assert against new disabled status - assert not salt_call_cli.run("assistive.enabled", osa_script) + ret = salt_call_cli.run("assistive.enabled", osa_script) + assert not ret.data From 071074b35f6daf36f0f1ea1a33899eb5117b53de Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Thu, 9 Nov 2023 16:37:39 -0800 Subject: [PATCH 04/37] fixing test_mac_desktop.py --- .../integration/modules/test_mac_desktop.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/pytests/integration/modules/test_mac_desktop.py b/tests/pytests/integration/modules/test_mac_desktop.py index 6a3ce1e60084..71686c189a64 100644 --- a/tests/pytests/integration/modules/test_mac_desktop.py +++ b/tests/pytests/integration/modules/test_mac_desktop.py @@ -17,41 +17,47 @@ def test_get_output_volume(salt_call_cli): Tests the return of get_output_volume. """ ret = salt_call_cli.run("desktop.get_output_volume") - assert ret is not None + assert ret.data is not None def test_set_output_volume(salt_call_cli): """ Tests the return of set_output_volume. """ - current_vol = salt_call_cli.run("desktop.get_output_volume") + ret = salt_call_cli.run("desktop.get_output_volume") + current_vol = ret.data to_set = 10 if current_vol == str(to_set): to_set += 2 - new_vol = salt_call_cli.run("desktop.set_output_volume", str(to_set)) - check_vol = salt_call_cli.run("desktop.get_output_volume") + ret = salt_call_cli.run("desktop.set_output_volume", str(to_set)) + new_vol = ret.data + ret = salt_call_cli.run("desktop.get_output_volume") + check_vol = ret.data assert new_vol == check_vol # Set volume back to what it was before - salt_call_cli.run("desktop.set_output_volume", [current_vol]) + salt_call_cli.run("desktop.set_output_volume", current_vol) def test_screensaver(salt_call_cli): """ Tests the return of the screensaver function. """ - assert salt_call_cli.run("desktop.screensaver") + ret = salt_call_cli.run("desktop.screensaver") + assert ret.data def test_lock(salt_call_cli): """ Tests the return of the lock function. """ - assert salt_call_cli.run("desktop.lock") + ret = salt_call_cli.run("desktop.lock") + assert ret.data def test_say(salt_call_cli): """ Tests the return of the say function. """ - assert salt_call_cli.run("desktop.say", "hello", "world") + ret = salt_call_cli.run("desktop.say", "hello", "world") + assert ret.data From 5853b87aabaeeeb979de5128533300e9368b2330 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 13 Nov 2023 12:32:54 -0800 Subject: [PATCH 05/37] fixing references to what is returned from salt_call_cli. --- .../integration/modules/test_mac_assistive.py | 6 +- .../integration/modules/test_mac_brew_pkg.py | 6 +- .../integration/modules/test_mac_group.py | 70 +++--- .../integration/modules/test_mac_keychain.py | 27 ++- .../integration/modules/test_mac_portspkg.py | 32 ++- .../integration/modules/test_mac_power.py | 129 ++++++---- .../test_mac_power_restart_power_failure.py | 19 +- .../test_mac_power_sleep_on_power_button.py | 21 +- .../modules/test_mac_power_wake_on_modem.py | 21 +- .../modules/test_mac_power_wake_on_net.py | 21 +- .../integration/modules/test_mac_service.py | 138 +++++++---- .../integration/modules/test_mac_shadow.py | 6 +- .../modules/test_mac_softwareupdate.py | 92 ++++--- .../integration/modules/test_mac_sysctl.py | 13 +- .../integration/modules/test_mac_system.py | 229 ++++++++++++------ .../integration/modules/test_mac_timezone.py | 91 ++++--- .../integration/modules/test_mac_user.py | 83 ++++--- .../integration/modules/test_mac_xattr.py | 102 ++++---- 18 files changed, 709 insertions(+), 397 deletions(-) diff --git a/tests/pytests/integration/modules/test_mac_assistive.py b/tests/pytests/integration/modules/test_mac_assistive.py index e7d044c659df..0fa404029bf1 100644 --- a/tests/pytests/integration/modules/test_mac_assistive.py +++ b/tests/pytests/integration/modules/test_mac_assistive.py @@ -41,8 +41,10 @@ def test_install_and_remove(salt_call_cli, osa_script, setup_teardown_vars): Tests installing and removing a bundled ID or command to use assistive access. """ new_bundle = "com.smileonmymac.textexpander" - assert salt_call_cli.run("assistive.install", new_bundle) - assert salt_call_cli.run("assistive.remove", new_bundle) + ret = salt_call_cli.run("assistive.install", new_bundle) + assert ret.data + ret = salt_call_cli.run("assistive.remove", new_bundle) + assert ret.data @pytest.mark.slow_test diff --git a/tests/pytests/integration/modules/test_mac_brew_pkg.py b/tests/pytests/integration/modules/test_mac_brew_pkg.py index 6aa4ae150be5..d4424fef0eed 100644 --- a/tests/pytests/integration/modules/test_mac_brew_pkg.py +++ b/tests/pytests/integration/modules/test_mac_brew_pkg.py @@ -134,8 +134,8 @@ def test_latest_version(salt_call_cli, add_pkg, setup_teardown_vars): installed_latest = salt_call_cli.run("pkg.latest_version", add_pkg) version = salt_call_cli.run("pkg.version", add_pkg) try: - assert isinstance(uninstalled_latest, str) - assert installed_latest == version + assert isinstance(uninstalled_latest.data, str) + assert installed_latest.data == version.data except AssertionError: salt_call_cli.run("pkg.remove", add_pkg) raise @@ -149,7 +149,7 @@ def test_refresh_db(salt_call_cli, setup_teardown_vars): Integration test to ensure pkg.refresh_db works with brew """ refresh_brew = salt_call_cli.run("pkg.refresh_db") - assert refresh_brew + assert refresh_brew.data def test_list_upgrades(salt_call_cli, add_pkg, setup_teardown_vars): diff --git a/tests/pytests/integration/modules/test_mac_group.py b/tests/pytests/integration/modules/test_mac_group.py index 71822580def0..9be30e023c41 100644 --- a/tests/pytests/integration/modules/test_mac_group.py +++ b/tests/pytests/integration/modules/test_mac_group.py @@ -46,23 +46,27 @@ def rep_user_group(): def setup_teardown_vars(salt_call_cli, add_group, change_group, del_group): try: - os_grain = salt_call_cli.run("grains.item", "kernel") + ret = salt_call_cli.run("grains.item", "kernel") + os_grain = ret.data if os_grain["kernel"] not in "Darwin": pytest.skip("Test not applicable to '{kernel}' kernel".format(**os_grain)) yield finally: # Delete ADD_GROUP - add_info = salt_call_cli.run("group.info", add_group) + ret = salt_call_cli.run("group.info", add_group) + add_info = ret.data if add_info: salt_call_cli.run("group.delete", add_group) # Delete DEL_GROUP if something failed - del_info = salt_call_cli.run("group.info", del_group) + ret = salt_call_cli.run("group.info", del_group) + del_info = ret.data if del_info: salt_call_cli.run("group.delete", del_group) # Delete CHANGE_GROUP - change_info = salt_call_cli.run("group.info", change_group) + ret = salt_call_cli.run("group.info", change_group) + change_info = ret.data if change_info: salt_call_cli.run("group.delete", change_group) @@ -73,7 +77,8 @@ def test_mac_group_add(salt_call_cli, add_group, setup_teardown_vars): """ try: salt_call_cli.run("group.add", add_group, 3456) - group_info = salt_call_cli.run("group.info", add_group) + ret = salt_call_cli.run("group.info", add_group) + group_info = ret.data assert group_info["name"] == add_group except CommandExecutionError: salt_call_cli.run("group.delete", add_group) @@ -85,7 +90,8 @@ def test_mac_group_delete(salt_call_cli, del_group, setup_teardown_vars): Tests the delete group function """ # Create a group to delete - If unsuccessful, skip the test - if salt_call_cli.run("group.add", del_group, 4567) is not True: + group_add_ret = salt_call_cli.run("group.add", del_group, 4567) + if group_add_ret.data is not True: salt_call_cli.run("group.delete", del_group) pytest.skip("Failed to create a group to delete") @@ -99,13 +105,15 @@ def test_mac_group_chgid(salt_call_cli, change_group, setup_teardown_vars): Tests changing the group id """ # Create a group to delete - If unsuccessful, skip the test - if salt_call_cli.run("group.add", change_group, 5678) is not True: + ret = salt_call_cli.run("group.add", change_group, 5678) + if ret.data is not True: salt_call_cli.run("group.delete", change_group) pytest.skip("Failed to create a group to manipulate") try: salt_call_cli.run("group.chgid", change_group, 6789) - group_info = salt_call_cli.run("group.info", change_group) + ret = salt_call_cli.run("group.info", change_group) + group_info = ret.data assert group_info["gid"] == 6789 except AssertionError: salt_call_cli.run("group.delete", change_group) @@ -117,13 +125,15 @@ def test_mac_adduser(salt_call_cli, add_group, add_user, setup_teardown_vars): Tests adding user to the group """ # Create a group to use for test - If unsuccessful, skip the test - if salt_call_cli.run("group.add", add_group, 5678) is not True: + ret = salt_call_cli.run("group.add", add_group, 5678) + if ret.data is not True: salt_call_cli.run("group.delete", add_group) pytest.skip("Failed to create a group to manipulate") try: salt_call_cli.run("group.adduser", add_group, add_user) - group_info = salt_call_cli.run("group.info", add_group) + ret = salt_call_cli.run("group.info", add_group) + group_info = ret.data assert add_user == "".join(group_info["members"]) except AssertionError: salt_call_cli.run("group.delete", add_group) @@ -135,18 +145,18 @@ def test_mac_deluser(salt_call_cli, add_group, add_user, setup_teardown_vars): Test deleting user from a group """ # Create a group to use for test - If unsuccessful, skip the test - if ( - salt_call_cli.run("group.add", add_group, 5678) - and salt_call_cli.run("group.adduser", add_group, add_user) is not True - ): + group_add_ret = salt_call_cli.run("group.add", add_group, 5678) + user_add_ret = salt_call_cli.run("group.adduser", add_group, add_user) + + if group_add_ret.data and user_add_ret is not True: salt_call_cli.run("group.delete", add_group) pytest.skip("Failed to create a group to manipulate") delusr = salt_call_cli.run("group.deluser", add_group, add_user) - assert delusr + assert delusr.data group_info = salt_call_cli.run("group.info", add_group) - assert add_user not in "".join(group_info["members"]) + assert add_user.data not in "".join(group_info["members"]) def test_mac_members( @@ -155,10 +165,10 @@ def test_mac_members( """ Test replacing members of a group """ - if ( - salt_call_cli.run("group.add", add_group, 5678) - and salt_call_cli.run("group.adduser", add_group, add_user) is not True - ): + group_add_ret = salt_call_cli.run("group.add", add_group, 5678) + user_add_ret = salt_call_cli.run("group.adduser", add_group, add_user) + + if group_add_ret.data and user_add_ret is not True: salt_call_cli.run("group.delete", add_group) pytest.skip( "Failed to create the {} group or add user {} to group " @@ -166,22 +176,22 @@ def test_mac_members( ) rep_group_mem = salt_call_cli.run("group.members", add_group, rep_user_group) - assert rep_group_mem + assert rep_group_mem.data # ensure new user is added to group and previous user is removed group_info = salt_call_cli.run("group.info", [add_group]) - assert rep_user_group in str(group_info["members"]) - assert add_user not in str(group_info["members"]) + assert rep_user_group.data in str(group_info.data["members"]) + assert add_user not in str(group_info.data["members"]) def test_mac_getent(salt_call_cli, add_group, add_user, setup_teardown_vars): """ Test returning info on all groups """ - if ( - salt_call_cli.run("group.add", add_group, 5678) - and salt_call_cli.run("group.adduser", add_group, add_user) is not True - ): + group_add_ret = salt_call_cli.run("group.add", add_group, 5678) + user_add_ret = salt_call_cli.run("group.adduser", add_group, add_user) + + if group_add_ret.data and user_add_ret is not True: salt_call_cli.run("group.delete", add_group) pytest.skip( "Failed to create the {} group or add user {} to group " @@ -189,6 +199,6 @@ def test_mac_getent(salt_call_cli, add_group, add_user, setup_teardown_vars): ) getinfo = salt_call_cli.run("group.getent") - assert getinfo - assert add_group in str(getinfo) - assert add_user in str(getinfo) + assert getinfo.data + assert add_group in str(getinfo.data) + assert add_user in str(getinfo.data) diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py index c66f9efc028d..278a66919a9b 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -23,7 +23,8 @@ def setup_teardown_vars(salt_call_cli, base_env_state_tree_root_dir): try: yield cert, cert_alias, passwd finally: - certs_list = salt_call_cli.run("keychain.list_certs") + ret = salt_call_cli.run("keychain.list_certs") + certs_list = ret.data if cert_alias in certs_list: salt_call_cli.run("keychain.uninstall", cert_alias) @@ -37,11 +38,13 @@ def test_mac_keychain_install(setup_teardown_vars, salt_call_cli): cert_alias = setup_teardown_vars[1] passwd = setup_teardown_vars[2] - install_cert = salt_call_cli.run("keychain.install", cert, passwd) + ret = salt_call_cli.run("keychain.install", cert, passwd) + install_cert = ret.data assert install_cert # check to ensure the cert was installed - certs_list = salt_call_cli.run("keychain.list_certs") + ret = salt_call_cli.run("keychain.list_certs") + certs_list = ret.data assert cert_alias in certs_list @@ -55,7 +58,8 @@ def test_mac_keychain_uninstall(setup_teardown_vars, salt_call_cli): passwd = setup_teardown_vars[2] salt_call_cli.run("keychain.install", cert, passwd) - certs_list = salt_call_cli.run("keychain.list_certs") + ret = salt_call_cli.run("keychain.list_certs") + certs_list = ret.data if cert_alias not in certs_list: salt_call_cli.run("keychain.uninstall", cert_alias) @@ -63,7 +67,8 @@ def test_mac_keychain_uninstall(setup_teardown_vars, salt_call_cli): # uninstall cert salt_call_cli.run("keychain.uninstall", cert_alias) - certs_list = salt_call_cli.run("keychain.list_certs") + ret = salt_call_cli.run("keychain.list_certs") + certs_list = ret.data # check to ensure the cert was uninstalled try: @@ -86,7 +91,8 @@ def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli): salt_call_cli.run("keychain.uninstall", cert_alias) pytest.skip("Failed to install keychain") - get_name = salt_call_cli.run("keychain.get_friendly_name", cert, passwd) + ret = salt_call_cli.run("keychain.get_friendly_name", cert, passwd) + get_name = ret.data assert get_name == cert_alias @@ -94,8 +100,10 @@ def test_mac_keychain_get_default_keychain(salt_call_cli): """ Test that attempts to get the default keychain """ - salt_get_keychain = salt_call_cli.run("keychain.get_default_keychain") - sys_get_keychain = salt_call_cli.run("cmd.run", "security default-keychain -d user") + ret = salt_call_cli.run("keychain.get_default_keychain") + salt_get_keychain = ret.data + ret = salt_call_cli.run("cmd.run", "security default-keychain -d user") + sys_get_keychain = ret.data assert salt_get_keychain == sys_get_keychain @@ -104,5 +112,6 @@ def test_mac_keychain_list_certs(salt_call_cli): Test that attempts to list certs """ cert_default = "com.apple.systemdefault" - certs = salt_call_cli.run("keychain.list_certs") + ret = salt_call_cli.run("keychain.list_certs") + certs = ret.data assert cert_default in certs diff --git a/tests/pytests/integration/modules/test_mac_portspkg.py b/tests/pytests/integration/modules/test_mac_portspkg.py index 16d5ae92560c..3ab4e245c2bb 100644 --- a/tests/pytests/integration/modules/test_mac_portspkg.py +++ b/tests/pytests/integration/modules/test_mac_portspkg.py @@ -29,8 +29,9 @@ def test_list_pkgs(salt_call_cli, setup_teardown_vars): Test pkg.list_pkgs """ salt_call_cli.run("pkg.install", "agree") - assert isinstance(salt_call_cli.run("pkg.list_pkgs"), dict) - assert "agree" in salt_call_cli.run("pkg.list_pkgs") + pkg_list_ret = salt_call_cli.run("pkg.list_pkgs") + assert isinstance(pkg_list_ret.data, dict) + assert "agree" in pkg_list_ret.data def test_latest_version(salt_call_cli, setup_teardown_vars): @@ -39,8 +40,8 @@ def test_latest_version(salt_call_cli, setup_teardown_vars): """ salt_call_cli.run("pkg.install", "agree") result = salt_call_cli.run("pkg.latest_version", "agree", refresh=False) - assert isinstance(result, dict) - assert "agree" in result + assert isinstance(result.data, dict) + assert "agree" in result.data def test_remove(salt_call_cli, setup_teardown_vars): @@ -49,8 +50,8 @@ def test_remove(salt_call_cli, setup_teardown_vars): """ salt_call_cli.run("pkg.install", "agree") removed = salt_call_cli.run("pkg.remove", "agree") - assert isinstance(removed, dict) - assert "agree" in removed + assert isinstance(removed.data, dict) + assert "agree" in removed.data @pytest.mark.destructive_test @@ -60,15 +61,16 @@ def test_install(salt_call_cli, setup_teardown_vars): """ salt_call_cli.run("pkg.remove", "agree") installed = salt_call_cli.run("pkg.install", "agree") - assert isinstance(installed, dict) - assert "agree" in installed + assert isinstance(installed.data, dict) + assert "agree" in installed.data def test_list_upgrades(salt_call_cli, setup_teardown_vars): """ Test pkg.list_upgrades """ - assert isinstance(salt_call_cli.run("pkg.list_upgrades", refresh=False), dict) + upgrade = salt_call_cli.run("pkg.list_upgrades", refresh=False) + assert isinstance(upgrade.data, dict) def test_upgrade_available(salt_call_cli, setup_teardown_vars): @@ -76,14 +78,18 @@ def test_upgrade_available(salt_call_cli, setup_teardown_vars): Test pkg.upgrade_available """ salt_call_cli.run("pkg.install", "agree") - assert not salt_call_cli.run("pkg.upgrade_available", "agree", refresh=False) + upgrade_available = salt_call_cli.run( + "pkg.upgrade_available", "agree", refresh=False + ) + assert not upgrade_available.data def test_refresh_db(salt_call_cli, setup_teardown_vars): """ Test pkg.refresh_db """ - assert salt_call_cli.run("pkg.refresh_db") + refresh = salt_call_cli.run("pkg.refresh_db") + assert refresh.data def test_upgrade(salt_call_cli, setup_teardown_vars): @@ -91,5 +97,5 @@ def test_upgrade(salt_call_cli, setup_teardown_vars): Test pkg.upgrade """ results = salt_call_cli.run("pkg.upgrade", refresh=False) - assert isinstance(results, dict) - assert results["result"] + assert isinstance(results.data, dict) + assert results.data["result"] diff --git a/tests/pytests/integration/modules/test_mac_power.py b/tests/pytests/integration/modules/test_mac_power.py index ba52b8b32b11..e19b914e70ec 100644 --- a/tests/pytests/integration/modules/test_mac_power.py +++ b/tests/pytests/integration/modules/test_mac_power.py @@ -34,24 +34,30 @@ def test_computer_sleep(salt_call_cli, setup_teardown_vars): """ # Normal Functionality - assert salt_call_cli.run("power.set_computer_sleep", 90) - assert salt_call_cli.run("power.get_computer_sleep") == "after 90 minutes" - assert salt_call_cli.run("power.set_computer_sleep", "Off") - assert salt_call_cli.run("power.get_computer_sleep") == "Never" + ret = salt_call_cli.run("power.set_computer_sleep", 90) + assert ret.data + + ret = salt_call_cli.run("power.get_computer_sleep") + assert ret.data == "after 90 minutes" + + ret = salt_call_cli.run("power.set_computer_sleep", "Off") + assert ret.data + + ret = salt_call_cli.run("power.get_computer_sleep") + assert ret.data == "Never" # Test invalid input - assert "Invalid String Value for Minutes" in salt_call_cli.run( - "power.set_computer_sleep", "spongebob" - ) - assert "Invalid Integer Value for Minutes" in salt_call_cli.run( - "power.set_computer_sleep", 0 - ) - assert "Invalid Integer Value for Minutes" in salt_call_cli.run( - "power.set_computer_sleep", 181 - ) - assert "Invalid Boolean Value for Minutes" in salt_call_cli.run( - "power.set_computer_sleep", True - ) + ret = salt_call_cli.run("power.set_computer_sleep", "spongebob") + assert "Invalid String Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_computer_sleep", 0) + assert "Invalid Integer Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_computer_sleep", 181) + assert "Invalid Integer Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_computer_sleep", True) + assert "Invalid Boolean Value for Minutes" in ret.data def test_display_sleep(salt_call_cli, setup_teardown_vars): @@ -61,24 +67,30 @@ def test_display_sleep(salt_call_cli, setup_teardown_vars): """ # Normal Functionality - assert salt_call_cli.run("power.set_display_sleep", 90) - assert salt_call_cli.run("power.get_display_sleep") == "after 90 minutes" - assert salt_call_cli.run("power.set_display_sleep", "Off") - assert salt_call_cli.run("power.get_display_sleep") == "Never" + ret = salt_call_cli.run("power.set_display_sleep", 90) + assert ret.data + + ret = salt_call_cli.run("power.get_display_sleep") + assert ret.data == "after 90 minutes" + + ret = salt_call_cli.run("power.set_display_sleep", "Off") + assert ret.data + + ret = salt_call_cli.run("power.get_display_sleep") + assert ret.data == "Never" # Test invalid input - assert "Invalid String Value for Minutes" in salt_call_cli.run( - "power.set_display_sleep", "spongebob" - ) - assert "Invalid Integer Value for Minutes" in salt_call_cli.run( - "power.set_display_sleep", 0 - ) - assert "Invalid Integer Value for Minutes" in salt_call_cli.run( - "power.set_display_sleep", 181 - ) - assert "Invalid Boolean Value for Minutes" in salt_call_cli.run( - "power.set_display_sleep", True - ) + ret = salt_call_cli.run("power.set_display_sleep", "spongebob") + assert "Invalid String Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_display_sleep", 0) + assert "Invalid Integer Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_display_sleep", 181) + assert "Invalid Integer Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_display_sleep", True) + assert "Invalid Boolean Value for Minutes" in ret.data def test_harddisk_sleep(salt_call_cli, setup_teardown_vars): @@ -88,24 +100,30 @@ def test_harddisk_sleep(salt_call_cli, setup_teardown_vars): """ # Normal Functionality - assert salt_call_cli.run("power.set_harddisk_sleep", 90) - assert salt_call_cli.run("power.get_harddisk_sleep") == "after 90 minutes" - assert salt_call_cli.run("power.set_harddisk_sleep", "Off") - assert salt_call_cli.run("power.get_harddisk_sleep") == "Never" + ret = salt_call_cli.run("power.set_harddisk_sleep", 90) + assert ret.data + + ret = salt_call_cli.run("power.get_harddisk_sleep") + assert ret.data == "after 90 minutes" + + ret = salt_call_cli.run("power.set_harddisk_sleep", "Off") + assert ret.data + + ret = salt_call_cli.run("power.get_harddisk_sleep") + assert ret.data == "Never" # Test invalid input - assert "Invalid String Value for Minutes" in salt_call_cli.run( - "power.set_harddisk_sleep", "spongebob" - ) - assert "Invalid Integer Value for Minutes" in salt_call_cli.run( - "power.set_harddisk_sleep", 0 - ) - assert "Invalid Integer Value for Minutes" in salt_call_cli.run( - "power.set_harddisk_sleep", 181 - ) - assert "Invalid Boolean Value for Minutes" in salt_call_cli.run( - "power.set_harddisk_sleep", True - ) + ret = salt_call_cli.run("power.set_harddisk_sleep", "spongebob") + assert "Invalid String Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_harddisk_sleep", 0) + assert "Invalid Integer Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_harddisk_sleep", 181) + assert "Invalid Integer Value for Minutes" in ret.data + + ret = salt_call_cli.run("power.set_harddisk_sleep", True) + assert "Invalid Boolean Value for Minutes" in ret.data def test_restart_freeze(salt_call_cli, setup_teardown_vars): @@ -114,10 +132,17 @@ def test_restart_freeze(salt_call_cli, setup_teardown_vars): Test power.set_restart_freeze """ # Normal Functionality - assert salt_call_cli.run("power.set_restart_freeze", "on") - assert salt_call_cli.run("power.get_restart_freeze") + ret = salt_call_cli.run("power.set_restart_freeze", "on") + assert ret.data + + ret = salt_call_cli.run("power.get_restart_freeze") + assert ret.data + # This will return False because mac fails to actually make the change - assert not salt_call_cli.run("power.set_restart_freeze", "off") + ret = salt_call_cli.run("power.set_restart_freeze", "off") + assert not ret.data + # Even setting to off returns true, it actually is never set # This is an apple bug - assert salt_call_cli.run("power.get_restart_freeze") + ret = salt_call_cli.run("power.get_restart_freeze") + assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py b/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py index 2438e06ebdf9..c2d0277fa8ec 100644 --- a/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py +++ b/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py @@ -22,17 +22,24 @@ def test_restart_power_failure(salt_call_cli): ret = salt_call_cli.run("power.get_restart_power_failure") if isinstance(ret, bool): - RESTART_POWER = ret + RESTART_POWER = ret.data # If available on this system, test it if RESTART_POWER is None: # Check for not available ret = salt_call_cli.run("power.get_restart_power_failure") - assert "Error" in ret + assert "Error" in ret.data else: - assert salt_call_cli.run("power.set_restart_power_failure", "on") - assert salt_call_cli.run("power.get_restart_power_failure") - assert salt_call_cli.run("power.set_restart_power_failure", "off") - assert not salt_call_cli.run("power.get_restart_power_failure") + ret = salt_call_cli.run("power.set_restart_power_failure", "on") + assert ret.data + + ret = salt_call_cli.run("power.get_restart_power_failure") + assert ret.data + + ret = salt_call_cli.run("power.set_restart_power_failure", "off") + assert ret.data + + ret = salt_call_cli.run("power.get_restart_power_failure") + assert not ret.data salt_call_cli.run("power.set_sleep_on_power_button", RESTART_POWER) diff --git a/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py b/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py index 82fad62bdc30..543dd5e3539c 100644 --- a/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py +++ b/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py @@ -21,18 +21,25 @@ def test_sleep_on_power_button(salt_call_cli): SLEEP_ON_BUTTON = None ret = salt_call_cli.run("power.get_sleep_on_power_button") - if isinstance(ret, bool): + if isinstance(ret.data, bool): SLEEP_ON_BUTTON = salt_call_cli.run("power.get_sleep_on_power_button") # If available on this system, test it - if SLEEP_ON_BUTTON is None: + if SLEEP_ON_BUTTON.data is None: # Check for not available ret = salt_call_cli.run("power.get_sleep_on_power_button") - assert "Error" in ret + assert "Error" in ret.data else: - assert salt_call_cli.run("power.set_sleep_on_power_button", "on") - assert salt_call_cli.run("power.get_sleep_on_power_button") - assert salt_call_cli.run("power.set_sleep_on_power_button", "off") - assert not salt_call_cli.run("power.get_sleep_on_power_button") + ret = salt_call_cli.run("power.set_sleep_on_power_button", "on") + assert ret.data + + ret = salt_call_cli.run("power.get_sleep_on_power_button") + assert ret.data + + ret = salt_call_cli.run("power.set_sleep_on_power_button", "off") + assert ret.data + + ret = salt_call_cli.run("power.get_sleep_on_power_button") + assert not ret.data salt_call_cli.run("power.set_sleep_on_power_button", SLEEP_ON_BUTTON) diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py b/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py index 90e7903e4d0b..137d74c202ce 100644 --- a/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py +++ b/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py @@ -20,17 +20,24 @@ def test_wake_on_modem(salt_call_cli): """ WAKE_ON_MODEM = None ret = salt_call_cli.run("power.get_wake_on_modem") - if isinstance(ret, bool): - WAKE_ON_MODEM = ret + if isinstance(ret.data, bool): + WAKE_ON_MODEM = ret.data if WAKE_ON_MODEM is None: # Check for not available ret = salt_call_cli.run("power.get_wake_on_modem") - assert "Error" in ret + assert "Error" in ret.data else: - assert salt_call_cli.run("power.set_wake_on_modem", "on") - assert salt_call_cli.run("power.get_wake_on_modem") - assert salt_call_cli.run("power.set_wake_on_modem", "off") - assert not salt_call_cli.run("power.get_wake_on_modem") + ret = salt_call_cli.run("power.set_wake_on_modem", "on") + assert ret.data + + ret = salt_call_cli.run("power.get_wake_on_modem") + assert ret.data + + ret = salt_call_cli.run("power.set_wake_on_modem", "off") + assert ret.data + + ret = salt_call_cli.run("power.get_wake_on_modem") + assert not ret.data salt_call_cli.run("power.set_wake_on_modem", WAKE_ON_MODEM) diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_net.py b/tests/pytests/integration/modules/test_mac_power_wake_on_net.py index 3a816a7e2d78..741e6119a96b 100644 --- a/tests/pytests/integration/modules/test_mac_power_wake_on_net.py +++ b/tests/pytests/integration/modules/test_mac_power_wake_on_net.py @@ -21,18 +21,25 @@ def test_wake_on_network(salt_call_cli): WAKE_ON_NET = None ret = salt_call_cli.run("power.get_wake_on_network") - if isinstance(ret, bool): - WAKE_ON_NET = ret + if isinstance(ret.data, bool): + WAKE_ON_NET = ret.data # If available on this system, test it if WAKE_ON_NET is None: # Check for not available ret = salt_call_cli.run("power.get_wake_on_network") - assert "Error" in ret + assert "Error" in ret.data else: - assert salt_call_cli.run("power.set_wake_on_network", "on") - assert salt_call_cli.run("power.get_wake_on_network") - assert salt_call_cli.run("power.set_wake_on_network", "off") - assert not salt_call_cli.run("power.get_wake_on_network") + ret = salt_call_cli.run("power.set_wake_on_network", "on") + assert ret.data + + ret = salt_call_cli.run("power.get_wake_on_network") + assert ret.data + + ret = salt_call_cli.run("power.set_wake_on_network", "off") + assert ret.data + + ret = salt_call_cli.run("power.get_wake_on_network") + assert not ret.data salt_call_cli.run("power.set_wake_on_network", WAKE_ON_NET) diff --git a/tests/pytests/integration/modules/test_mac_service.py b/tests/pytests/integration/modules/test_mac_service.py index 18ce16c21e68..165f44fc5ad1 100644 --- a/tests/pytests/integration/modules/test_mac_service.py +++ b/tests/pytests/integration/modules/test_mac_service.py @@ -45,12 +45,13 @@ def test_show(salt_call_cli, setup_teardown_vars): """ SERVICE_NAME = setup_teardown_vars[0] # Existing Service - service_info = salt_call_cli.run("service.show", [SERVICE_NAME]) - assert isinstance(service_info, dict) - assert service_info["plist"]["Label"] == SERVICE_NAME + service_info = salt_call_cli.run("service.show", SERVICE_NAME) + assert isinstance(service_info.data, dict) + assert service_info.data["plist"]["Label"] == SERVICE_NAME # Missing Service - assert "Service not found" in salt_call_cli.run("service.show", "spongebob") + ret = salt_call_cli.run("service.show", "spongebob") + assert "Service not found" in ret.data def test_launchctl(salt_call_cli): @@ -58,18 +59,17 @@ def test_launchctl(salt_call_cli): Test service.launchctl """ # Expected Functionality - assert salt_call_cli.run("service.launchctl", "error", "bootstrap", 64) - assert ( - salt_call_cli.run( - "service.launchctl", ["error", "bootstrap", 64], return_stdout=True - ) - == "64: unknown error code" + ret = salt_call_cli.run("service.launchctl", "error", "bootstrap", 64) + assert ret.data + + ret = salt_call_cli.run( + "service.launchctl", ["error", "bootstrap", 64], return_stdout=True ) + assert ret.data == "64: unknown error code" # Raise an error - assert "Failed to error service" in salt_call_cli.run( - "service.launchctl", "error", "bootstrap" - ) + ret = salt_call_cli.run("service.launchctl", "error", "bootstrap") + assert "Failed to error service" in ret.data def test_list(salt_call_cli, setup_teardown_vars): @@ -78,11 +78,14 @@ def test_list(salt_call_cli, setup_teardown_vars): """ SERVICE_NAME = setup_teardown_vars[0] # Expected Functionality - assert "PID" in salt_call_cli.run("service.list") - assert "{" in salt_call_cli.run("service.list", SERVICE_NAME) + ret = salt_call_cli.run("service.list") + assert "PID" in ret.data + ret = salt_call_cli.run("service.list", SERVICE_NAME) + assert "{" in ret.data # Service not found - assert "Service not found" in salt_call_cli.run("service.list", "spongebob") + ret = salt_call_cli.run("service.list", "spongebob") + assert "Service not found" in ret.data def test_enable(salt_call_cli, setup_teardown_vars): @@ -90,9 +93,11 @@ def test_enable(salt_call_cli, setup_teardown_vars): Test service.enable """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.enable", SERVICE_NAME) + ret = salt_call_cli.run("service.enable", SERVICE_NAME) + assert ret.data - assert "Service not found" in salt_call_cli.run("service.enable", "spongebob") + ret = salt_call_cli.run("service.enable", "spongebob") + assert "Service not found" in ret.data def test_disable(salt_call_cli, setup_teardown_vars): @@ -100,9 +105,11 @@ def test_disable(salt_call_cli, setup_teardown_vars): Test service.disable """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.disable", SERVICE_NAME) + ret = salt_call_cli.run("service.disable", SERVICE_NAME) + assert ret.data - assert "Service not found" in salt_call_cli.run("service.disable", "spongebob") + ret = salt_call_cli.run("service.disable", "spongebob") + assert "Service not found" in ret.data def test_start(salt_call_cli, setup_teardown_vars): @@ -112,9 +119,11 @@ def test_start(salt_call_cli, setup_teardown_vars): Test service.status """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.start", SERVICE_NAME) + ret = salt_call_cli.run("service.start", SERVICE_NAME) + assert ret.data - assert "Service not found" in salt_call_cli.run("service.start", "spongebob") + ret = salt_call_cli.run("service.start", "spongebob") + assert "Service not found" in ret.data def test_stop(salt_call_cli, setup_teardown_vars): @@ -122,9 +131,11 @@ def test_stop(salt_call_cli, setup_teardown_vars): Test service.stop """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.stop", SERVICE_NAME) + ret = salt_call_cli.run("service.stop", SERVICE_NAME) + assert ret.data - assert "Service not found" in salt_call_cli.run("service.stop", ["spongebob"]) + ret = salt_call_cli.run("service.stop", ["spongebob"]) + assert "Service not found" in ret.data def test_status(salt_call_cli, setup_teardown_vars): @@ -133,15 +144,20 @@ def test_status(salt_call_cli, setup_teardown_vars): """ SERVICE_NAME = setup_teardown_vars[0] # A running service - assert salt_call_cli.run("service.start", SERVICE_NAME) - assert salt_call_cli.run("service.status", SERVICE_NAME) + ret = salt_call_cli.run("service.start", SERVICE_NAME) + assert ret.data + ret = salt_call_cli.run("service.status", SERVICE_NAME) + assert ret.data # A stopped service - assert salt_call_cli.run("service.stop", SERVICE_NAME) - assert not salt_call_cli.run("service.status", SERVICE_NAME) + ret = salt_call_cli.run("service.stop", SERVICE_NAME) + assert ret.data + ret = salt_call_cli.run("service.status", SERVICE_NAME) + assert not ret.data # Service not found - assert not salt_call_cli.run("service.status", "spongebob") + ret = salt_call_cli.run("service.status", "spongebob") + assert not ret.data def test_available(salt_call_cli, setup_teardown_vars): @@ -149,8 +165,11 @@ def test_available(salt_call_cli, setup_teardown_vars): Test service.available """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.available", SERVICE_NAME) - assert not salt_call_cli.run("service.available", "spongebob") + ret = salt_call_cli.run("service.available", SERVICE_NAME) + assert ret.data + + ret = salt_call_cli.run("service.available", "spongebob") + assert not ret.data def test_missing(salt_call_cli, setup_teardown_vars): @@ -158,8 +177,11 @@ def test_missing(salt_call_cli, setup_teardown_vars): Test service.missing """ SERVICE_NAME = setup_teardown_vars[0] - assert not salt_call_cli.run("service.missing", SERVICE_NAME) - assert salt_call_cli.run("service.missing", "spongebob") + ret = salt_call_cli.run("service.missing", SERVICE_NAME) + assert not ret.data + + ret = salt_call_cli.run("service.missing", "spongebob") + assert ret.data def test_enabled(salt_call_cli, setup_teardown_vars): @@ -167,13 +189,20 @@ def test_enabled(salt_call_cli, setup_teardown_vars): Test service.enabled """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.enabled", SERVICE_NAME) - assert salt_call_cli.run("service.start", SERVICE_NAME) + ret = salt_call_cli.run("service.enabled", SERVICE_NAME) + assert ret.data + + ret = salt_call_cli.run("service.start", SERVICE_NAME) + assert ret.data - assert salt_call_cli.run("service.enabled", SERVICE_NAME) - assert salt_call_cli.run("service.stop", SERVICE_NAME) + ret = salt_call_cli.run("service.enabled", SERVICE_NAME) + assert ret.data - assert salt_call_cli.run("service.enabled", "spongebob") + ret = salt_call_cli.run("service.stop", SERVICE_NAME) + assert ret.data + + ret = salt_call_cli.run("service.enabled", "spongebob") + assert ret.data def test_disabled(salt_call_cli, setup_teardown_vars): @@ -181,13 +210,23 @@ def test_disabled(salt_call_cli, setup_teardown_vars): Test service.disabled """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.start", SERVICE_NAME) - assert not salt_call_cli.run("service.disabled", SERVICE_NAME) + ret = salt_call_cli.run("service.start", SERVICE_NAME) + assert ret.data + + ret = salt_call_cli.run("service.disabled", SERVICE_NAME) + assert not ret.data + + ret = salt_call_cli.run("service.disable", SERVICE_NAME) + assert ret.data + + ret = salt_call_cli.run("service.disabled", SERVICE_NAME) + assert ret.data + + ret = salt_call_cli.run("service.enable", SERVICE_NAME) + assert ret.data - assert salt_call_cli.run("service.disable", SERVICE_NAME) - assert salt_call_cli.run("service.disabled", SERVICE_NAME) - assert salt_call_cli.run("service.enable", SERVICE_NAME) - assert "Service not found" in salt_call_cli.run("service.stop", "spongebob") + ret = salt_call_cli.run("service.stop", "spongebob") + assert "Service not found" in ret.data def test_get_all(salt_call_cli, setup_teardown_vars): @@ -196,8 +235,8 @@ def test_get_all(salt_call_cli, setup_teardown_vars): """ SERVICE_NAME = setup_teardown_vars[0] services = salt_call_cli.run("service.get_all") - assert isinstance(services, list) - assert SERVICE_NAME in services + assert isinstance(services.data, list) + assert SERVICE_NAME in services.data def test_get_enabled(salt_call_cli, setup_teardown_vars): @@ -206,8 +245,8 @@ def test_get_enabled(salt_call_cli, setup_teardown_vars): """ SERVICE_NAME = setup_teardown_vars[0] services = salt_call_cli.run("service.get_enabled") - assert isinstance(services, list) - assert SERVICE_NAME in services + assert isinstance(services.data, list) + assert SERVICE_NAME in services.data def test_service_laoded(salt_call_cli, setup_teardown_vars): @@ -215,4 +254,5 @@ def test_service_laoded(salt_call_cli, setup_teardown_vars): Test service.get_enabled """ SERVICE_NAME = setup_teardown_vars[0] - assert salt_call_cli.run("service.loaded", SERVICE_NAME) + ret = salt_call_cli.run("service.loaded", SERVICE_NAME) + assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_shadow.py b/tests/pytests/integration/modules/test_mac_shadow.py index c1d03465b3e0..5d5c5dc5b21d 100644 --- a/tests/pytests/integration/modules/test_mac_shadow.py +++ b/tests/pytests/integration/modules/test_mac_shadow.py @@ -38,11 +38,11 @@ def test_info(salt_call_cli, setup_teardown_vars): # Correct Functionality ret = salt_call_cli.run("shadow.info", TEST_USER) - assert ret["name"] == TEST_USER + assert ret.data["name"] == TEST_USER # User does not exist ret = salt_call_cli.run("shadow.info", NO_USER) - assert ret["name"] == "" + assert ret.data["name"] == "" def test_get_account_created(salt_call_cli, setup_teardown_vars): @@ -54,7 +54,7 @@ def test_get_account_created(salt_call_cli, setup_teardown_vars): # Correct Functionality text_date = salt_call_cli.run("shadow.get_account_created", TEST_USER) - assert text_date != "Invalid Timestamp" + assert text_date.data != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) diff --git a/tests/pytests/integration/modules/test_mac_softwareupdate.py b/tests/pytests/integration/modules/test_mac_softwareupdate.py index 19502c348891..4198a2be96b0 100644 --- a/tests/pytests/integration/modules/test_mac_softwareupdate.py +++ b/tests/pytests/integration/modules/test_mac_softwareupdate.py @@ -15,9 +15,14 @@ @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli): - IGNORED_LIST = salt_call_cli.run("softwareupdate.list_ignored") - SCHEDULE = salt_call_cli.run("softwareupdate.schedule") - CATALOG = salt_call_cli.run("softwareupdate.get_catalog") + ret = salt_call_cli.run("softwareupdate.list_ignored") + IGNORED_LIST = ret.data + + ret = salt_call_cli.run("softwareupdate.schedule") + SCHEDULE = ret.data + + ret = salt_call_cli.run("softwareupdate.get_catalog") + CATALOG = ret.data try: yield IGNORED_LIST, SCHEDULE, CATALOG @@ -42,7 +47,8 @@ def test_list_available(salt_call_cli, setup_teardown_vars): """ # Can't predict what will be returned, so can only test that the return # is the correct type, dict - assert isinstance(salt_call_cli.run("softwareupdate.list_available"), dict) + ret = salt_call_cli.run("softwareupdate.list_available") + assert isinstance(ret.data, dict) def test_ignore(salt_call_cli, setup_teardown_vars): @@ -52,16 +58,25 @@ def test_ignore(salt_call_cli, setup_teardown_vars): Test softwareupdate.reset_ignored """ # Test reset_ignored - assert salt_call_cli.run("softwareupdate.reset_ignored") - assert salt_call_cli.run("softwareupdate.list_ignored") == [] + ret = salt_call_cli.run("softwareupdate.reset_ignored") + assert ret.data + + ret = salt_call_cli.run("softwareupdate.list_ignored") == [] + assert ret.data # Test ignore - assert salt_call_cli.run("softwareupdate.ignore", "spongebob") - assert salt_call_cli.run("softwareupdate.ignore", "squidward") + ret = salt_call_cli.run("softwareupdate.ignore", "spongebob") + assert ret.data + + ret = salt_call_cli.run("softwareupdate.ignore", "squidward") + assert ret.data # Test list_ignored and verify ignore - assert "spongebob" in salt_call_cli.run("softwareupdate.list_ignored") - assert "squidward" in salt_call_cli.run("softwareupdate.list_ignored") + ret = salt_call_cli.run("softwareupdate.list_ignored") + assert "spongebob" in ret.data + + ret = salt_call_cli.run("softwareupdate.list_ignored") + assert "squidward" in ret.data def test_schedule(salt_call_cli): @@ -70,12 +85,18 @@ def test_schedule(salt_call_cli): Test softwareupdate.schedule_enabled """ # Test enable - assert salt_call_cli.run("softwareupdate.schedule_enable", True) - assert salt_call_cli.run("softwareupdate.schedule_enabled") + ret = salt_call_cli.run("softwareupdate.schedule_enable", True) + assert ret.data + + ret = salt_call_cli.run("softwareupdate.schedule_enabled") + assert ret.data # Test disable in case it was already enabled - assert salt_call_cli.run("softwareupdate.schedule_enable", False) - assert not salt_call_cli.run("softwareupdate.schedule_enabled") + ret = salt_call_cli.run("softwareupdate.schedule_enable", False) + assert ret.data + + ret = salt_call_cli.run("softwareupdate.schedule_enabled") + assert not ret.data def test_update(salt_call_cli, setup_teardown_vars): @@ -89,22 +110,24 @@ def test_update(salt_call_cli, setup_teardown_vars): """ # There's no way to know what the dictionary will contain, so all we can # check is that the return is a dictionary - assert isinstance(salt_call_cli.run("softwareupdate.update_all"), dict) + ret = salt_call_cli.run("softwareupdate.update_all") + assert isinstance(ret, dict) # Test update_available - assert not salt_call_cli.run("softwareupdate.update_available", "spongebob") + ret = salt_call_cli.run("softwareupdate.update_available", "spongebob") + assert not ret.data # Test update not available - assert "Update not available" in salt_call_cli.run( - "softwareupdate.update", "spongebob" - ) + ret = salt_call_cli.run("softwareupdate.update", "spongebob") + assert "Update not available" in ret.data def test_list_downloads(salt_call_cli, setup_teardown_vars): """ Test softwareupdate.list_downloads """ - assert isinstance(salt_call_cli.run("softwareupdate.list_downloads"), list) + ret = salt_call_cli.run("softwareupdate.list_downloads") + assert isinstance(ret.data, list) def test_download(salt_call_cli, setup_teardown_vars): @@ -115,16 +138,16 @@ def test_download(salt_call_cli, setup_teardown_vars): the download function """ # Test update not available - assert "Update not available" in salt_call_cli.run( - "softwareupdate.download", ["spongebob"] - ) + ret = salt_call_cli.run("softwareupdate.download", ["spongebob"]) + assert "Update not available" in ret.data def test_download_all(salt_call_cli, setup_teardown_vars): """ Test softwareupdate.download_all """ - assert isinstance(salt_call_cli.run("softwareupdate.download_all"), list) + ret = salt_call_cli.run("softwareupdate.download_all") + assert isinstance(ret.data, list) def test_get_set_reset_catalog(salt_call_cli, setup_teardown_vars): @@ -132,13 +155,22 @@ def test_get_set_reset_catalog(salt_call_cli, setup_teardown_vars): Test softwareupdate.download_all """ # Reset the catalog - assert salt_call_cli.run("softwareupdate.reset_catalog") - assert salt_call_cli.run("softwareupdate.get_catalog") == "Default" + ret = salt_call_cli.run("softwareupdate.reset_catalog") + assert ret.data + + ret = salt_call_cli.run("softwareupdate.get_catalog") + assert ret.data == "Default" # Test setting and getting the catalog - assert salt_call_cli.run("softwareupdate.set_catalog", "spongebob") - assert salt_call_cli.run("softwareupdate.get_catalog") == "spongebob" + ret = salt_call_cli.run("softwareupdate.set_catalog", "spongebob") + assert ret.data + + ret = salt_call_cli.run("softwareupdate.get_catalog") == "spongebob" + assert ret.data # Test reset the catalog - assert salt_call_cli.run("softwareupdate.reset_catalog") - assert salt_call_cli.run("softwareupdate.get_catalog") == "Default" + ret = salt_call_cli.run("softwareupdate.reset_catalog") + assert ret.data + + assert salt_call_cli.run("softwareupdate.get_catalog") + assert ret.data == "Default" diff --git a/tests/pytests/integration/modules/test_mac_sysctl.py b/tests/pytests/integration/modules/test_mac_sysctl.py index 52933b2169c4..4f7363d6e2fb 100644 --- a/tests/pytests/integration/modules/test_mac_sysctl.py +++ b/tests/pytests/integration/modules/test_mac_sysctl.py @@ -31,7 +31,8 @@ def config_file(): @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli, assign_cmd, config_file): has_conf = False - val = salt_call_cli.run("sysctl.get", assign_cmd, config_file) + ret = salt_call_cli.run("sysctl.get", assign_cmd, config_file) + val = ret.data # If sysctl file is present, make a copy # Remove original file so we can replace it with test files @@ -48,7 +49,7 @@ def setup_teardown_vars(salt_call_cli, assign_cmd, config_file): yield val finally: ret = salt_call_cli.run("sysctl.get", assign_cmd) - if ret != val: + if ret.data != val: salt_call_cli.run("sysctl.assign", assign_cmd, val) if has_conf is True: @@ -71,7 +72,8 @@ def test_assign(salt_call_cli, assign_cmd, setup_teardown_vars): while rand == val: rand = random.randint(0, 500) salt_call_cli.run("sysctl.assign", assign_cmd, rand) - info = int(salt_call_cli.run("sysctl.get", assign_cmd)) + ret = int(salt_call_cli.run("sysctl.get", assign_cmd)) + info = int(ret.data) try: assert rand == info except AssertionError: @@ -109,7 +111,7 @@ def test_persist_already_set(salt_call_cli, config_file, setup_teardown_vars): try: salt_call_cli.run("sysctl.persist", assign_cmd, 50) ret = salt_call_cli.run("sysctl.persist", assign_cmd, 50) - assert ret == "Already set" + assert ret.data == "Already set" except CommandExecutionError: os.remove(config_file) raise @@ -131,7 +133,8 @@ def test_persist_apply_change( while rand == val: rand = random.randint(0, 500) salt_call_cli.run("sysctl.persist", assign_cmd, rand, apply_change=True) - info = int(salt_call_cli.run("sysctl.get", assign_cmd)) + ret = salt_call_cli.run("sysctl.get", assign_cmd) + info = int(ret.data) assert info == rand except CommandExecutionError: os.remove(config_file) diff --git a/tests/pytests/integration/modules/test_mac_system.py b/tests/pytests/integration/modules/test_mac_system.py index ddadd9ad9c77..4ccb43e1e35e 100644 --- a/tests/pytests/integration/modules/test_mac_system.py +++ b/tests/pytests/integration/modules/test_mac_system.py @@ -22,11 +22,20 @@ @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli): - ATRUN_ENABLED = salt_call_cli.run("service.enabled", "com.apple.atrun") - REMOTE_LOGIN_ENABLED = salt_call_cli.run("system.get_remote_login") - REMOTE_EVENTS_ENABLED = salt_call_cli.run("system.get_remote_events") - SUBNET_NAME = salt_call_cli.run("system.get_subnet_name") - KEYBOARD_DISABLED = salt_call_cli.run("system.get_disable_keyboard_on_lock") + ret = salt_call_cli.run("service.enabled", "com.apple.atrun") + ATRUN_ENABLED = ret.data + + ret = salt_call_cli.run("system.get_remote_login") + REMOTE_LOGIN_ENABLED = ret.data + + ret = salt_call_cli.run("system.get_remote_events") + REMOTE_EVENTS_ENABLED = ret.data + + ret = salt_call_cli.run("system.get_subnet_name") + SUBNET_NAME = ret.data + + ret = salt_call_cli.run("system.get_disable_keyboard_on_lock") + KEYBOARD_DISABLED = ret.data try: yield @@ -47,25 +56,46 @@ def test_get_set_remote_login(salt_call_cli): Test system.set_remote_login """ # Normal Functionality - assert salt_call_cli.run("system.set_remote_login", True) - assert salt_call_cli.run("system.get_remote_login") - assert salt_call_cli.run("system.set_remote_login", False) - assert not salt_call_cli.run("system.get_remote_login") + ret = salt_call_cli.run("system.set_remote_login", True) + assert ret.data + + ret = salt_call_cli.run("system.get_remote_login") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", False) + assert ret.data + + ret = salt_call_cli.run("system.get_remote_login") + assert not ret.data # Test valid input - assert salt_call_cli.run("system.set_remote_login", True) - assert salt_call_cli.run("system.set_remote_login", False) - assert salt_call_cli.run("system.set_remote_login", "yes") - assert salt_call_cli.run("system.set_remote_login", "no") - assert salt_call_cli.run("system.set_remote_login", "On") - assert salt_call_cli.run("system.set_remote_login", "Off") - assert salt_call_cli.run("system.set_remote_login", 1) - assert salt_call_cli.run("system.set_remote_login", 0) + ret = salt_call_cli.run("system.set_remote_login", True) + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", False) + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", "yes") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", "no") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", "On") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", "Off") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", 1) + assert ret.data + + ret = salt_call_cli.run("system.set_remote_login", 0) + assert ret.data # Test invalid input - assert "Invalid String Value for Enabled" in salt_call_cli.run( - "system.set_remote_login", "spongebob" - ) + ret = salt_call_cli.run("system.set_remote_login", "spongebob") + assert "Invalid String Value for Enabled" in ret.data def test_get_set_remote_events(salt_call_cli): @@ -74,25 +104,46 @@ def test_get_set_remote_events(salt_call_cli): Test system.set_remote_events """ # Normal Functionality - assert salt_call_cli.run("system.set_remote_events", True) - assert salt_call_cli.run("system.get_remote_events") - assert salt_call_cli.run("system.set_remote_events", False) - assert not salt_call_cli.run("system.get_remote_events") + ret = salt_call_cli.run("system.set_remote_events", True) + assert ret.data + + ret = salt_call_cli.run("system.get_remote_events") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", False) + assert ret.data + + ret = not salt_call_cli.run("system.get_remote_events") + assert not ret.data # Test valid input - assert salt_call_cli.run("system.set_remote_events", True) - assert salt_call_cli.run("system.set_remote_events", False) - assert salt_call_cli.run("system.set_remote_events", "yes") - assert salt_call_cli.run("system.set_remote_events", "no") - assert salt_call_cli.run("system.set_remote_events", "On") - assert salt_call_cli.run("system.set_remote_events", "Off") - assert salt_call_cli.run("system.set_remote_events", 1) - assert salt_call_cli.run("system.set_remote_events", 0) + ret = salt_call_cli.run("system.set_remote_events", True) + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", False) + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", "yes") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", "no") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", "On") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", "Off") + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", 1) + assert ret.data + + ret = salt_call_cli.run("system.set_remote_events", 0) + assert ret.data # Test invalid input - assert "Invalid String Value for Enabled" in salt_call_cli.run( - "system.set_remote_events", "spongebob" - ) + ret = salt_call_cli.run("system.set_remote_events", "spongebob") + assert "Invalid String Value for Enabled" in ret.data def test_get_set_subnet_name(salt_call_cli): @@ -102,8 +153,11 @@ def test_get_set_subnet_name(salt_call_cli): """ SET_SUBNET_NAME = random_string("RS-", lowercase=False) - assert salt_call_cli.run("system.set_subnet_name", SET_SUBNET_NAME) - assert salt_call_cli.run("system.get_subnet_name") == SET_SUBNET_NAME + ret = salt_call_cli.run("system.set_subnet_name", SET_SUBNET_NAME) + assert ret.data + + ret = salt_call_cli.run("system.get_subnet_name") + assert ret.data == SET_SUBNET_NAME def test_get_list_startup_disk(salt_call_cli): @@ -115,13 +169,14 @@ def test_get_list_startup_disk(salt_call_cli): """ # Test list and get ret = salt_call_cli.run("system.list_startup_disks") - assert isinstance(ret, list) - assert salt_call_cli.run("system.get_startup_disk") in ret + assert isinstance(ret.data, list) + + startup_disk = salt_call_cli.run("system.get_startup_disk") + assert startup_disk in ret # Test passing set a bad disk - assert "Invalid value passed for path." in salt_call_cli.run( - "system.set_startup_disk", "spongebob" - ) + ret = salt_call_cli.run("system.set_startup_disk", "spongebob") + assert "Invalid value passed for path." in ret.data @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -133,13 +188,15 @@ def test_get_set_restart_delay(salt_call_cli): may need to disable this test as we can't control the delay value """ # Normal Functionality - assert salt_call_cli.run("system.set_restart_delay", 90) - assert salt_call_cli.run("system.get_restart_delay") == "90 seconds" + ret = salt_call_cli.run("system.set_restart_delay", 90) + assert ret.data + + ret = salt_call_cli.run("system.get_restart_delay") + assert ret.data == "90 seconds" # Pass set bad value for seconds - assert "Invalid value passed for seconds." in salt_call_cli.run( - "system.set_restart_delay", 70 - ) + ret = salt_call_cli.run("system.set_restart_delay", 70) + assert "Invalid value passed for seconds." in ret.data def test_get_set_disable_keyboard_on_lock(salt_call_cli): @@ -148,26 +205,46 @@ def test_get_set_disable_keyboard_on_lock(salt_call_cli): Test system.set_disable_keyboard_on_lock """ # Normal Functionality - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", True) - assert salt_call_cli.run("system.get_disable_keyboard_on_lock") + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", True) + assert ret.data + + ret = salt_call_cli.run("system.get_disable_keyboard_on_lock") + assert ret.data - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", False) - assert not salt_call_cli.run("system.get_disable_keyboard_on_lock") + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", False) + assert ret.data + + ret = not salt_call_cli.run("system.get_disable_keyboard_on_lock") + assert not ret.data # Test valid input - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", True) - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", False) - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "yes") - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "no") - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "On") - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", "Off") - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", 1) - assert salt_call_cli.run("system.set_disable_keyboard_on_lock", 0) + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", True) + assert ret.data + + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", False) + assert ret.data + + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "yes") + assert ret.data + + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "no") + assert ret.data + + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "On") + assert ret.data + + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "Off") + assert ret.data + + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", 1) + assert ret.data + + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", 0) + assert ret.data # Test invalid input - assert "Invalid String Value for Enabled" in salt_call_cli.run( - "system.set_disable_keyboard_on_lock", "spongebob" - ) + ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "spongebob") + assert "Invalid String Value for Enabled" in ret.data @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -179,15 +256,21 @@ def test_get_set_boot_arch(salt_call_cli): may need to disable this test as we can't set the boot architecture """ # Normal Functionality - assert salt_call_cli.run("system.set_boot_arch", "i386") - assert salt_call_cli.run("system.get_boot_arch") == "i386" - assert salt_call_cli.run("system.set_boot_arch", "default") - assert salt_call_cli.run("system.get_boot_arch") == "default" + ret = salt_call_cli.run("system.set_boot_arch", "i386") + assert ret.data + + ret = salt_call_cli.run("system.get_boot_arch") == "i386" + assert ret.data + + ret = salt_call_cli.run("system.set_boot_arch", "default") + assert ret.data + + ret = salt_call_cli.run("system.get_boot_arch") == "default" + assert ret.data # Test invalid input - assert "Invalid value passed for arch" in salt_call_cli.run( - "system.set_boot_arch", "spongebob" - ) + ret = salt_call_cli.run("system.set_boot_arch", "spongebob") + assert "Invalid value passed for arch" in ret.data # A similar test used to be skipped on py3 due to 'hanging', if we see @@ -202,10 +285,14 @@ def test_get_set_computer_name(salt_call_cli): """ SET_COMPUTER_NAME = random_string("RS-", lowercase=False) - COMPUTER_NAME = salt_call_cli.run("system.get_computer_name") + ret = salt_call_cli.run("system.get_computer_name") + COMPUTER_NAME = ret.data log.debug("Set name is %s", SET_COMPUTER_NAME) assert salt_call_cli.run("system.set_computer_name", [SET_COMPUTER_NAME]) - assert salt_call_cli.run("system.get_computer_name") == SET_COMPUTER_NAME + assert ret.data + + ret = salt_call_cli.run("system.get_computer_name") + assert ret.data == SET_COMPUTER_NAME salt_call_cli.run("system.set_computer_name", COMPUTER_NAME) diff --git a/tests/pytests/integration/modules/test_mac_timezone.py b/tests/pytests/integration/modules/test_mac_timezone.py index 1b7382ab088c..c97bb7e3052e 100644 --- a/tests/pytests/integration/modules/test_mac_timezone.py +++ b/tests/pytests/integration/modules/test_mac_timezone.py @@ -55,12 +55,15 @@ def test_get_set_date(salt_call_cli): Test timezone.set_date """ # Correct Functionality - assert salt_call_cli.run("timezone.set_date", "2/20/2011") - assert salt_call_cli.run("timezone.get_date") == "2/20/2011" + ret = salt_call_cli.run("timezone.set_date", "2/20/2011") + assert ret.data + ret = salt_call_cli.run("timezone.get_date") + assert ret.data == "2/20/2011" # Test bad date format + ret = salt_call_cli.run("timezone.set_date", "13/12/2014") assert ( - salt_call_cli.run("timezone.set_date", "13/12/2014") + ret.data == "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014" ) @@ -71,7 +74,7 @@ def test_get_time(salt_call_cli): Test timezone.get_time """ text_time = salt_call_cli.run("timezone.get_time") - assert text_time != "Invalid Timestamp" + assert text_time.data != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_time, "%H:%M:%S") assert isinstance(obj_date, datetime.date) @@ -85,11 +88,13 @@ def test_set_time(salt_call_cli): Test timezone.set_time """ # Correct Functionality - assert salt_call_cli.run("timezone.set_time", "3:14") + ret = salt_call_cli.run("timezone.set_time", "3:14") + assert ret.data # Test bad time format + ret = salt_call_cli.run("timezone.set_time", "3:71") assert ( - salt_call_cli.run("timezone.set_time", "3:71") + ret.data == "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" ) @@ -104,13 +109,14 @@ def test_get_set_zone(salt_call_cli): Test timezone.set_zone """ # Correct Functionality - assert salt_call_cli.run("timezone.set_zone", "Pacific/Wake") - assert salt_call_cli.run("timezone.get_zone") == "Pacific/Wake" + ret = salt_call_cli.run("timezone.set_zone", "Pacific/Wake") + assert ret.data + assert ret.data == "Pacific/Wake" # Test bad time zone + ret = salt_call_cli.run("timezone.set_zone", "spongebob") assert ( - salt_call_cli.run("timezone.set_zone", "spongebob") - == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" + ret.data == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" ) @@ -122,13 +128,16 @@ def test_get_offset(salt_call_cli): """ Test timezone.get_offset """ - assert salt_call_cli.run("timezone.set_zone", "Pacific/Wake") - assert isinstance(salt_call_cli.run("timezone.get_offset"), (str,)) - assert salt_call_cli.run("timezone.get_offset") == "+1200" + ret = salt_call_cli.run("timezone.set_zone", "Pacific/Wake") + assert ret.data + ret = salt_call_cli.run("timezone.get_offset") + assert isinstance(ret.data, str) + assert ret.data == "+1200" - assert salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") - assert isinstance(salt_call_cli.run("timezone.get_offset"), (str,)) - assert salt_call_cli.run("timezone.get_offset") == "-0700" + ret = salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") + assert ret.data + assert isinstance(ret.data, str) + assert ret.data == "-0700" @pytest.mark.skip( @@ -140,13 +149,15 @@ def test_get_set_zonecode(salt_call_cli): Test timezone.get_zonecode Test timezone.set_zonecode """ - assert salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") - assert isinstance(salt_call_cli.run("timezone.get_zonecode"), (str,)) - assert salt_call_cli.run("timezone.get_zonecode") == "PDT" + ret = salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") + assert ret.data + assert isinstance(ret.data, str) + assert ret.data == "PDT" - assert salt_call_cli.run("timezone.set_zone", "Pacific/Wake") - assert isinstance(salt_call_cli.run("timezone.get_zonecode"), (str,)) - assert salt_call_cli.run("timezone.get_zonecode") == "WAKT" + ret = salt_call_cli.run("timezone.set_zone", "Pacific/Wake") + assert ret.data + assert isinstance(ret.data, str) + assert ret.data == "WAKT" @pytest.mark.slow_test @@ -155,9 +166,9 @@ def test_list_zones(salt_call_cli): Test timezone.list_zones """ zones = salt_call_cli.run("timezone.list_zones") - assert isinstance(zones, list) - assert "America/Denver" in zones - assert "America/Los_Angeles" in zones + assert isinstance(zones.data, list) + assert "America/Denver" in zones.data + assert "America/Los_Angeles" in zones.data @pytest.mark.skip( @@ -168,9 +179,12 @@ def test_zone_compare(salt_call_cli): """ Test timezone.zone_compare """ - assert salt_call_cli.run("timezone.set_zone", "America/Denver") - assert salt_call_cli.run("timezone.zone_compare", "America/Denver") - assert not salt_call_cli.run("timezone.zone_compare", "Pacific/Wake") + ret = salt_call_cli.run("timezone.set_zone", "America/Denver") + assert ret.data + ret = salt_call_cli.run("timezone.zone_compare", "America/Denver") + assert ret.data + ret = salt_call_cli.run("timezone.zone_compare", "Pacific/Wake") + assert not ret.data @pytest.mark.skip( @@ -182,11 +196,17 @@ def test_get_set_using_network_time(salt_call_cli): Test timezone.get_using_network_time Test timezone.set_using_network_time """ - assert salt_call_cli.run("timezone.set_using_network_time", True) - assert salt_call_cli.run("timezone.get_using_network_time") + ret = salt_call_cli.run("timezone.set_using_network_time", True) + assert ret.data - assert salt_call_cli.run("timezone.set_using_network_time", False) - assert not salt_call_cli.run("timezone.get_using_network_time") + ret = salt_call_cli.run("timezone.get_using_network_time") + assert ret.data + + ret = salt_call_cli.run("timezone.set_using_network_time", False) + assert ret.data + + ret = salt_call_cli.run("timezone.get_using_network_time") + assert not ret.data @pytest.mark.skip( @@ -198,5 +218,8 @@ def test_get_set_time_server(salt_call_cli): Test timezone.get_time_server Test timezone.set_time_server """ - assert salt_call_cli.run("timezone.set_time_server", "spongebob.com") - assert salt_call_cli.run("timezone.get_time_server") == "spongebob.com" + ret = salt_call_cli.run("timezone.set_time_server", "spongebob.com") + assert ret.data + + ret = salt_call_cli.run("timezone.get_time_server") == "spongebob.com" + assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_user.py b/tests/pytests/integration/modules/test_mac_user.py index b6ec05ecc602..fc6e92680bf2 100644 --- a/tests/pytests/integration/modules/test_mac_user.py +++ b/tests/pytests/integration/modules/test_mac_user.py @@ -22,7 +22,8 @@ @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli): - os_grain = salt_call_cli.run("grains.item", ["kernel"]) + ret = salt_call_cli.run("grains.item", "kernel") + os_grain = ret.data if os_grain["kernel"] not in "Darwin": pytest.skip("Test not applicable to '{kernel}' kernel".format(**os_grain)) @@ -35,17 +36,20 @@ def setup_teardown_vars(salt_call_cli): yield ADD_USER, DEL_USER, PRIMARY_GROUP_USER, CHANGE_USER finally: # Delete ADD_USER - add_info = salt_call_cli.run("user.info", ADD_USER) + ret = salt_call_cli.run("user.info", ADD_USER) + add_info = ret.data if add_info: salt_call_cli.run("user.delete", ADD_USER) # Delete DEL_USER if something failed - del_info = salt_call_cli.run("user.info", DEL_USER) + ret = salt_call_cli.run("user.info", DEL_USER) + del_info = ret.data if del_info: salt_call_cli.run("user.delete", DEL_USER) # Delete CHANGE_USER - change_info = salt_call_cli.run("user.info", CHANGE_USER) + ret = salt_call_cli.run("user.info", CHANGE_USER) + change_info = ret.data if change_info: salt_call_cli.run("user.delete", CHANGE_USER) @@ -58,7 +62,8 @@ def test_mac_user_add(salt_call_cli, setup_teardown_vars): try: salt_call_cli.run("user.add", ADD_USER) - user_info = salt_call_cli.run("user.info", ADD_USER) + ret = salt_call_cli.run("user.info", ADD_USER) + user_info = ret.data assert ADD_USER == user_info["name"] except CommandExecutionError: salt_call_cli.run("user.delete", ADD_USER) @@ -73,13 +78,14 @@ def test_mac_user_delete(salt_call_cli, setup_teardown_vars): DEL_USER = setup_teardown_vars[1] # Create a user to delete - If unsuccessful, skip the test - if salt_call_cli.run("user.add", DEL_USER) is not True: + ret = salt_call_cli.run("user.add", DEL_USER) + if ret.data is not True: salt_call_cli.run("user.delete", DEL_USER) pytest.skip("Failed to create a user to delete") # Now try to delete the added user ret = salt_call_cli.run("user.delete", DEL_USER) - assert ret + assert ret.data @pytest.mark.slow_test @@ -90,14 +96,17 @@ def test_mac_user_primary_group(salt_call_cli, setup_teardown_vars): PRIMARY_GROUP_USER = setup_teardown_vars[2] # Create a user to test primary group function - if salt_call_cli.run("user.add", PRIMARY_GROUP_USER) is not True: + ret = salt_call_cli.run("user.add", PRIMARY_GROUP_USER) + if ret.data is not True: salt_call_cli.run("user.delete", PRIMARY_GROUP_USER) pytest.skip("Failed to create a user") try: # Test mac_user.primary_group - primary_group = salt_call_cli.run("user.primary_group", PRIMARY_GROUP_USER) - uid_info = salt_call_cli.run("user.info", PRIMARY_GROUP_USER) + ret = salt_call_cli.run("user.primary_group", PRIMARY_GROUP_USER) + primary_group = ret.data + ret = salt_call_cli.run("user.info", PRIMARY_GROUP_USER) + uid_info = ret.data assert primary_group in uid_info["groups"] except AssertionError: @@ -113,19 +122,22 @@ def test_mac_user_changes(salt_call_cli, setup_teardown_vars): CHANGE_USER = setup_teardown_vars[3] # Create a user to manipulate - if unsuccessful, skip the test - if salt_call_cli.run("user.add", CHANGE_USER) is not True: + ret = salt_call_cli.run("user.add", CHANGE_USER) + if ret.data is not True: salt_call_cli.run("user.delete", CHANGE_USER) pytest.skip("Failed to create a user") try: # Test mac_user.chuid salt_call_cli.run("user.chuid", CHANGE_USER, 4376) - uid_info = salt_call_cli.run("user.info", CHANGE_USER) + ret = salt_call_cli.run("user.info", CHANGE_USER) + uid_info = ret.data assert uid_info["uid"] == 4376 # Test mac_user.chgid salt_call_cli.run("user.chgid", CHANGE_USER, 4376) - gid_info = salt_call_cli.run("user.info", CHANGE_USER) + ret = salt_call_cli.run("user.info", CHANGE_USER) + gid_info = ret.data assert gid_info["gid"] == 4376 # Test mac.user.chshell @@ -135,19 +147,23 @@ def test_mac_user_changes(salt_call_cli, setup_teardown_vars): # Test mac_user.chhome salt_call_cli.run("user.chhome", CHANGE_USER, "/Users/foo") - home_info = salt_call_cli.run("user.info", CHANGE_USER) + ret = salt_call_cli.run("user.info", CHANGE_USER) + home_info = ret.data assert home_info["home"] == "/Users/foo" # Test mac_user.chfullname salt_call_cli.run("user.chfullname", CHANGE_USER, "Foo Bar") - fullname_info = salt_call_cli.run("user.info", CHANGE_USER) + ret = salt_call_cli.run("user.info", CHANGE_USER) + fullname_info = ret.data assert fullname_info["fullname"] == "Foo Bar" # Test mac_user.chgroups - pre_info = salt_call_cli.run("user.info", CHANGE_USER)["groups"] + ret = salt_call_cli.run("user.info", CHANGE_USER)["groups"] + pre_info = ret.data expected = pre_info + ["wheel"] salt_call_cli.run("user.chgroups", CHANGE_USER, "wheel") - groups_info = salt_call_cli.run("user.info", CHANGE_USER) + ret = salt_call_cli.run("user.info", CHANGE_USER) + groups_info = ret.data assert groups_info["groups"] == expected except AssertionError: @@ -166,10 +182,12 @@ def test_mac_user_enable_auto_login(salt_call_cli): try: # Does enable return True - assert salt_call_cli.run("user.enable_auto_login", ["Spongebob", "Squarepants"]) + ret = salt_call_cli.run("user.enable_auto_login", ["Spongebob", "Squarepants"]) + assert ret.data # Did it set the user entry in the plist file - assert salt_call_cli.run("user.get_auto_login") == "Spongebob" + ret = salt_call_cli.run("user.get_auto_login") + assert ret.data == "Spongebob" # Did it generate the `/etc/kcpassword` file assert os.path.exists("/etc/kcpassword") @@ -181,20 +199,24 @@ def test_mac_user_enable_auto_login(salt_call_cli): assert test_data == file_data # Does disable return True - assert salt_call_cli.run("user.disable_auto_login") + ret = salt_call_cli.run("user.disable_auto_login") + assert ret.data # Does it remove the user entry in the plist file - assert not salt_call_cli.run("user.get_auto_login") + ret = salt_call_cli.run("user.get_auto_login") + assert not ret # Is the `/etc/kcpassword` file removed assert not os.path.exists("/etc/kcpassword") finally: # Make sure auto_login is disabled - assert salt_call_cli.run("user.disable_auto_login") + ret = salt_call_cli.run("user.disable_auto_login") + assert ret.data # Make sure autologin is disabled - if salt_call_cli.run("user.get_auto_login"): + ret = salt_call_cli.run("user.get_auto_login") + if ret.data: raise Exception("Failed to disable auto login") @@ -213,22 +235,27 @@ def test_mac_user_disable_auto_login(salt_call_cli): salt_call_cli.run("user.enable_auto_login", ["Spongebob", "Squarepants"]) # Make sure auto login got set up - if not salt_call_cli.run("user.get_auto_login") == "Spongebob": + ret = salt_call_cli.run("user.get_auto_login") + if not ret.data == "Spongebob": raise Exception("Failed to enable auto login") # Does disable return True - assert salt_call_cli.run("user.disable_auto_login") + ret = salt_call_cli.run("user.disable_auto_login") + assert ret.data # Does it remove the user entry in the plist file - assert not salt_call_cli.run("user.get_auto_login") + ret = salt_call_cli.run("user.get_auto_login") + assert not ret.data # Is the `/etc/kcpassword` file removed assert not os.path.exists("/etc/kcpassword") finally: # Make sure auto login is disabled - assert salt_call_cli.run("user.disable_auto_login") + ret = salt_call_cli.run("user.disable_auto_login") + assert ret.data # Make sure auto login is disabled - if salt_call_cli.run("user.get_auto_login"): + ret = salt_call_cli.run("user.get_auto_login") + if ret.data: raise Exception("Failed to disable auto login") diff --git a/tests/pytests/integration/modules/test_mac_xattr.py b/tests/pytests/integration/modules/test_mac_xattr.py index 7c36df639321..24f9e02e2fca 100644 --- a/tests/pytests/integration/modules/test_mac_xattr.py +++ b/tests/pytests/integration/modules/test_mac_xattr.py @@ -36,15 +36,16 @@ def test_list_no_xattr(salt_call_cli, setup_teardown_vars): no_file = setup_teardown_vars[1] # Clear existing attributes - assert salt_call_cli.run("xattr.clear", test_file) + ret = salt_call_cli.run("xattr.clear", test_file) + assert ret.data # Test no attributes - assert salt_call_cli.run("xattr.list", test_file) == {} + ret = salt_call_cli.run("xattr.list", test_file) + assert ret.data == {} # Test file not found - assert ( - salt_call_cli.run("xattr.list", no_file) == f"ERROR: File not found: {no_file}" - ) + ret = salt_call_cli.run("xattr.list", no_file) + assert ret.data == f"ERROR: File not found: {no_file}" def test_write(salt_call_cli, setup_teardown_vars): @@ -55,25 +56,30 @@ def test_write(salt_call_cli, setup_teardown_vars): no_file = setup_teardown_vars[1] # Clear existing attributes - assert salt_call_cli.run("xattr.clear", test_file) + ret = salt_call_cli.run("xattr.clear", test_file) + assert ret.data # Write some attributes - assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") - assert salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") - assert salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + assert ret.data + + ret = salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") + assert ret.data + + ret = salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + assert ret.data # Test that they were actually added - assert salt_call_cli.run("xattr.list", test_file) == { + ret = salt_call_cli.run("xattr.list", test_file) + assert ret.data == { "spongebob": "squarepants", "squidward": "plankton", "crabby": "patty", } # Test file not found - assert ( - salt_call_cli.run("xattr.write", no_file, "patrick", "jellyfish") - == f"ERROR: File not found: {no_file}" - ) + ret = salt_call_cli.run("xattr.write", no_file, "patrick", "jellyfish") + assert ret.data == f"ERROR: File not found: {no_file}" def test_read(salt_call_cli, setup_teardown_vars): @@ -84,25 +90,24 @@ def test_read(salt_call_cli, setup_teardown_vars): no_file = setup_teardown_vars[1] # Clear existing attributes - assert salt_call_cli.run("xattr.clear", test_file) + ret = salt_call_cli.run("xattr.clear", test_file) + assert ret.data # Write an attribute - assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + assert ret.data # Read the attribute - assert salt_call_cli.run("xattr.read", test_file, "spongebob") == "squarepants" + ret = salt_call_cli.run("xattr.read", test_file, "spongebob") + assert ret.data == "squarepants" # Test file not found - assert ( - salt_call_cli.run("xattr.read", no_file, "spongebob") - == f"ERROR: File not found: {no_file}" - ) + ret = salt_call_cli.run("xattr.read", no_file, "spongebob") + assert ret.data == f"ERROR: File not found: {no_file}" # Test attribute not found - assert ( - salt_call_cli.run("xattr.read", test_file, "patrick") - == "ERROR: Attribute not found: patrick" - ) + ret = salt_call_cli.run("xattr.read", test_file, "patrick") + assert ret.data == "ERROR: Attribute not found: patrick" def test_delete(salt_call_cli, setup_teardown_vars): @@ -113,33 +118,40 @@ def test_delete(salt_call_cli, setup_teardown_vars): no_file = setup_teardown_vars[1] # Clear existing attributes - assert salt_call_cli.run("xattr.clear", test_file) + ret = salt_call_cli.run("xattr.clear", test_file) + assert ret.data # Write some attributes - assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") - assert salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") - assert salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + assert ret.data + + ret = salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") + assert ret.data + + ret = salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + assert ret.data # Delete an attribute - assert salt_call_cli.run("xattr.delete", test_file, "squidward") + ret = salt_call_cli.run("xattr.delete", test_file, "squidward") + assert ret.data # Make sure it was actually deleted - assert salt_call_cli.run("xattr.list", test_file) == { + ret = salt_call_cli.run("xattr.list", test_file) + assert ret.data == { "spongebob": "squarepants", "crabby": "patty", } # Test file not found + ret = salt_call_cli.run("xattr.delete", no_file, "spongebob") assert ( salt_call_cli.run("xattr.delete", no_file, "spongebob") == f"ERROR: File not found: {no_file}" ) # Test attribute not found - assert ( - salt_call_cli.run("xattr.delete", test_file, "patrick") - == "ERROR: Attribute not found: patrick" - ) + ret = salt_call_cli.run("xattr.delete", test_file, "patrick") + assert ret.data == "ERROR: Attribute not found: patrick" def test_clear(salt_call_cli, setup_teardown_vars): @@ -150,17 +162,25 @@ def test_clear(salt_call_cli, setup_teardown_vars): no_file = setup_teardown_vars[1] # Clear existing attributes - assert salt_call_cli.run("xattr.clear", test_file) + ret = salt_call_cli.run("xattr.clear", test_file) + assert ret.data # Write some attributes - assert salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") - assert salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") - assert salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") + assert ret.data + + ret = salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") + assert ret.data + + ret = salt_call_cli.run("xattr.write", test_file, "crabby", "patty") + assert ret.data # Test Clear - assert salt_call_cli.run("xattr.clear", test_file) + ret = salt_call_cli.run("xattr.clear", test_file) + assert ret.data # Test file not found - assert ( + ret = ( salt_call_cli.run("xattr.clear", no_file) == f"ERROR: File not found: {no_file}" ) + assert ret.data == f"ERROR: File not found: {no_file}" From 1f3ac8dd1088ce6fdc26b848d91cc274a1485a0f Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 13 Nov 2023 12:37:16 -0800 Subject: [PATCH 06/37] change sysctl setting we use to account for Mac OS X 13. --- tests/pytests/integration/modules/test_mac_sysctl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytests/integration/modules/test_mac_sysctl.py b/tests/pytests/integration/modules/test_mac_sysctl.py index 4f7363d6e2fb..b1f1ce7ce1f1 100644 --- a/tests/pytests/integration/modules/test_mac_sysctl.py +++ b/tests/pytests/integration/modules/test_mac_sysctl.py @@ -20,7 +20,7 @@ @pytest.fixture(scope="function") def assign_cmd(): - return "net.inet.icmp.icmplim" + return "net.inet.icmp.timestamp" @pytest.fixture(scope="function") From d980f0f0a8eda1d57a37b715c218bad767b328a4 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 13 Nov 2023 15:29:42 -0800 Subject: [PATCH 07/37] A couple more fixes to the salt_call_cli results. --- .../integration/modules/test_mac_group.py | 4 +--- .../integration/modules/test_mac_portspkg.py | 3 ++- .../integration/modules/test_mac_power.py | 24 +++++++++---------- .../integration/modules/test_mac_system.py | 12 +++++----- .../integration/modules/test_mac_timezone.py | 6 ++--- .../integration/modules/test_mac_xattr.py | 4 +--- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/tests/pytests/integration/modules/test_mac_group.py b/tests/pytests/integration/modules/test_mac_group.py index 9be30e023c41..a64d7ae08f2d 100644 --- a/tests/pytests/integration/modules/test_mac_group.py +++ b/tests/pytests/integration/modules/test_mac_group.py @@ -41,9 +41,7 @@ def rep_user_group(): yield random_string("RS-", lowercase=False) -pytest.fixture(scope="function") - - +@pytest.fixture(scope="module") def setup_teardown_vars(salt_call_cli, add_group, change_group, del_group): try: ret = salt_call_cli.run("grains.item", "kernel") diff --git a/tests/pytests/integration/modules/test_mac_portspkg.py b/tests/pytests/integration/modules/test_mac_portspkg.py index 3ab4e245c2bb..edf8d4e7a5a7 100644 --- a/tests/pytests/integration/modules/test_mac_portspkg.py +++ b/tests/pytests/integration/modules/test_mac_portspkg.py @@ -16,7 +16,8 @@ def setup_teardown_vars(salt_call_cli): AGREE_INSTALLED = False try: - AGREE_INSTALLED = "agree" in salt_call_cli.run("pkg.list_pkgs") + ret = salt_call_cli.run("pkg.list_pkgs") + AGREE_INSTALLED = "agree" in ret.data salt_call_cli.run("pkg.refresh_db") yield finally: diff --git a/tests/pytests/integration/modules/test_mac_power.py b/tests/pytests/integration/modules/test_mac_power.py index e19b914e70ec..69be4568bdff 100644 --- a/tests/pytests/integration/modules/test_mac_power.py +++ b/tests/pytests/integration/modules/test_mac_power.py @@ -48,16 +48,16 @@ def test_computer_sleep(salt_call_cli, setup_teardown_vars): # Test invalid input ret = salt_call_cli.run("power.set_computer_sleep", "spongebob") - assert "Invalid String Value for Minutes" in ret.data + assert "Invalid String Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_computer_sleep", 0) - assert "Invalid Integer Value for Minutes" in ret.data + assert "Invalid Integer Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_computer_sleep", 181) - assert "Invalid Integer Value for Minutes" in ret.data + assert "Invalid Integer Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_computer_sleep", True) - assert "Invalid Boolean Value for Minutes" in ret.data + assert "Invalid Boolean Value for Minutes" in ret.stderr def test_display_sleep(salt_call_cli, setup_teardown_vars): @@ -81,16 +81,16 @@ def test_display_sleep(salt_call_cli, setup_teardown_vars): # Test invalid input ret = salt_call_cli.run("power.set_display_sleep", "spongebob") - assert "Invalid String Value for Minutes" in ret.data + assert "Invalid String Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_display_sleep", 0) - assert "Invalid Integer Value for Minutes" in ret.data + assert "Invalid Integer Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_display_sleep", 181) - assert "Invalid Integer Value for Minutes" in ret.data + assert "Invalid Integer Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_display_sleep", True) - assert "Invalid Boolean Value for Minutes" in ret.data + assert "Invalid Boolean Value for Minutes" in ret.stderr def test_harddisk_sleep(salt_call_cli, setup_teardown_vars): @@ -114,16 +114,16 @@ def test_harddisk_sleep(salt_call_cli, setup_teardown_vars): # Test invalid input ret = salt_call_cli.run("power.set_harddisk_sleep", "spongebob") - assert "Invalid String Value for Minutes" in ret.data + assert "Invalid String Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_harddisk_sleep", 0) - assert "Invalid Integer Value for Minutes" in ret.data + assert "Invalid Integer Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_harddisk_sleep", 181) - assert "Invalid Integer Value for Minutes" in ret.data + assert "Invalid Integer Value for Minutes" in ret.stderr ret = salt_call_cli.run("power.set_harddisk_sleep", True) - assert "Invalid Boolean Value for Minutes" in ret.data + assert "Invalid Boolean Value for Minutes" in ret.stderr def test_restart_freeze(salt_call_cli, setup_teardown_vars): diff --git a/tests/pytests/integration/modules/test_mac_system.py b/tests/pytests/integration/modules/test_mac_system.py index 4ccb43e1e35e..0ee2f8751c98 100644 --- a/tests/pytests/integration/modules/test_mac_system.py +++ b/tests/pytests/integration/modules/test_mac_system.py @@ -95,7 +95,7 @@ def test_get_set_remote_login(salt_call_cli): # Test invalid input ret = salt_call_cli.run("system.set_remote_login", "spongebob") - assert "Invalid String Value for Enabled" in ret.data + assert "Invalid String Value for Enabled" in ret.stderr def test_get_set_remote_events(salt_call_cli): @@ -143,7 +143,7 @@ def test_get_set_remote_events(salt_call_cli): # Test invalid input ret = salt_call_cli.run("system.set_remote_events", "spongebob") - assert "Invalid String Value for Enabled" in ret.data + assert "Invalid String Value for Enabled" in ret.stderr def test_get_set_subnet_name(salt_call_cli): @@ -176,7 +176,7 @@ def test_get_list_startup_disk(salt_call_cli): # Test passing set a bad disk ret = salt_call_cli.run("system.set_startup_disk", "spongebob") - assert "Invalid value passed for path." in ret.data + assert "Invalid value passed for path." in ret.stderr @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -196,7 +196,7 @@ def test_get_set_restart_delay(salt_call_cli): # Pass set bad value for seconds ret = salt_call_cli.run("system.set_restart_delay", 70) - assert "Invalid value passed for seconds." in ret.data + assert "Invalid value passed for seconds." in ret.stderr def test_get_set_disable_keyboard_on_lock(salt_call_cli): @@ -244,7 +244,7 @@ def test_get_set_disable_keyboard_on_lock(salt_call_cli): # Test invalid input ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "spongebob") - assert "Invalid String Value for Enabled" in ret.data + assert "Invalid String Value for Enabled" in ret.stderr @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -270,7 +270,7 @@ def test_get_set_boot_arch(salt_call_cli): # Test invalid input ret = salt_call_cli.run("system.set_boot_arch", "spongebob") - assert "Invalid value passed for arch" in ret.data + assert "Invalid value passed for arch" in ret.stderr # A similar test used to be skipped on py3 due to 'hanging', if we see diff --git a/tests/pytests/integration/modules/test_mac_timezone.py b/tests/pytests/integration/modules/test_mac_timezone.py index c97bb7e3052e..afffe751ce81 100644 --- a/tests/pytests/integration/modules/test_mac_timezone.py +++ b/tests/pytests/integration/modules/test_mac_timezone.py @@ -63,7 +63,7 @@ def test_get_set_date(salt_call_cli): # Test bad date format ret = salt_call_cli.run("timezone.set_date", "13/12/2014") assert ( - ret.data + ret.stderr == "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014" ) @@ -94,7 +94,7 @@ def test_set_time(salt_call_cli): # Test bad time format ret = salt_call_cli.run("timezone.set_time", "3:71") assert ( - ret.data + ret.stderr == "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" ) @@ -116,7 +116,7 @@ def test_get_set_zone(salt_call_cli): # Test bad time zone ret = salt_call_cli.run("timezone.set_zone", "spongebob") assert ( - ret.data == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" + ret.stderr == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" ) diff --git a/tests/pytests/integration/modules/test_mac_xattr.py b/tests/pytests/integration/modules/test_mac_xattr.py index 24f9e02e2fca..a2a6dcfbe2b0 100644 --- a/tests/pytests/integration/modules/test_mac_xattr.py +++ b/tests/pytests/integration/modules/test_mac_xattr.py @@ -180,7 +180,5 @@ def test_clear(salt_call_cli, setup_teardown_vars): assert ret.data # Test file not found - ret = ( - salt_call_cli.run("xattr.clear", no_file) == f"ERROR: File not found: {no_file}" - ) + ret = salt_call_cli.run("xattr.clear", no_file) assert ret.data == f"ERROR: File not found: {no_file}" From 6f76cf94b8a09c593a2df97061b8903a55c1b76b Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 13 Nov 2023 20:47:25 -0800 Subject: [PATCH 08/37] more changes to mac tests. --- .../integration/modules/test_mac_brew_pkg.py | 6 ++-- .../integration/modules/test_mac_service.py | 28 +++++++++---------- .../integration/modules/test_mac_timezone.py | 2 +- .../integration/modules/test_mac_user.py | 3 +- .../integration/modules/test_mac_xattr.py | 17 +++++------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/pytests/integration/modules/test_mac_brew_pkg.py b/tests/pytests/integration/modules/test_mac_brew_pkg.py index d4424fef0eed..c3acae12c73f 100644 --- a/tests/pytests/integration/modules/test_mac_brew_pkg.py +++ b/tests/pytests/integration/modules/test_mac_brew_pkg.py @@ -128,10 +128,12 @@ def test_latest_version(salt_call_cli, add_pkg, setup_teardown_vars): """ try: salt_call_cli.run("pkg.remove", add_pkg) - uninstalled_latest = salt_call_cli.run("pkg.latest_version", add_pkg) + ret = salt_call_cli.run("pkg.latest_version", add_pkg) + uninstalled_latest = ret.data salt_call_cli.run("pkg.install", add_pkg) - installed_latest = salt_call_cli.run("pkg.latest_version", add_pkg) + ret = salt_call_cli.run("pkg.latest_version", add_pkg) + installed_latest = ret.data version = salt_call_cli.run("pkg.version", add_pkg) try: assert isinstance(uninstalled_latest.data, str) diff --git a/tests/pytests/integration/modules/test_mac_service.py b/tests/pytests/integration/modules/test_mac_service.py index 165f44fc5ad1..370a75307473 100644 --- a/tests/pytests/integration/modules/test_mac_service.py +++ b/tests/pytests/integration/modules/test_mac_service.py @@ -43,7 +43,7 @@ def test_show(salt_call_cli, setup_teardown_vars): """ Test service.show """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars # Existing Service service_info = salt_call_cli.run("service.show", SERVICE_NAME) assert isinstance(service_info.data, dict) @@ -76,7 +76,7 @@ def test_list(salt_call_cli, setup_teardown_vars): """ Test service.list """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars # Expected Functionality ret = salt_call_cli.run("service.list") assert "PID" in ret.data @@ -92,7 +92,7 @@ def test_enable(salt_call_cli, setup_teardown_vars): """ Test service.enable """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.enable", SERVICE_NAME) assert ret.data @@ -104,7 +104,7 @@ def test_disable(salt_call_cli, setup_teardown_vars): """ Test service.disable """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.disable", SERVICE_NAME) assert ret.data @@ -118,7 +118,7 @@ def test_start(salt_call_cli, setup_teardown_vars): Test service.stop Test service.status """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.start", SERVICE_NAME) assert ret.data @@ -130,7 +130,7 @@ def test_stop(salt_call_cli, setup_teardown_vars): """ Test service.stop """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.stop", SERVICE_NAME) assert ret.data @@ -142,7 +142,7 @@ def test_status(salt_call_cli, setup_teardown_vars): """ Test service.status """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars # A running service ret = salt_call_cli.run("service.start", SERVICE_NAME) assert ret.data @@ -164,7 +164,7 @@ def test_available(salt_call_cli, setup_teardown_vars): """ Test service.available """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.available", SERVICE_NAME) assert ret.data @@ -176,7 +176,7 @@ def test_missing(salt_call_cli, setup_teardown_vars): """ Test service.missing """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.missing", SERVICE_NAME) assert not ret.data @@ -188,7 +188,7 @@ def test_enabled(salt_call_cli, setup_teardown_vars): """ Test service.enabled """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.enabled", SERVICE_NAME) assert ret.data @@ -209,7 +209,7 @@ def test_disabled(salt_call_cli, setup_teardown_vars): """ Test service.disabled """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.start", SERVICE_NAME) assert ret.data @@ -233,7 +233,7 @@ def test_get_all(salt_call_cli, setup_teardown_vars): """ Test service.get_all """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars services = salt_call_cli.run("service.get_all") assert isinstance(services.data, list) assert SERVICE_NAME in services.data @@ -243,7 +243,7 @@ def test_get_enabled(salt_call_cli, setup_teardown_vars): """ Test service.get_enabled """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars services = salt_call_cli.run("service.get_enabled") assert isinstance(services.data, list) assert SERVICE_NAME in services.data @@ -253,6 +253,6 @@ def test_service_laoded(salt_call_cli, setup_teardown_vars): """ Test service.get_enabled """ - SERVICE_NAME = setup_teardown_vars[0] + SERVICE_NAME = setup_teardown_vars ret = salt_call_cli.run("service.loaded", SERVICE_NAME) assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_timezone.py b/tests/pytests/integration/modules/test_mac_timezone.py index afffe751ce81..23f83bc4a00c 100644 --- a/tests/pytests/integration/modules/test_mac_timezone.py +++ b/tests/pytests/integration/modules/test_mac_timezone.py @@ -75,7 +75,7 @@ def test_get_time(salt_call_cli): """ text_time = salt_call_cli.run("timezone.get_time") assert text_time.data != "Invalid Timestamp" - obj_date = datetime.datetime.strptime(text_time, "%H:%M:%S") + obj_date = datetime.datetime.strptime(text_time.data, "%H:%M:%S") assert isinstance(obj_date, datetime.date) diff --git a/tests/pytests/integration/modules/test_mac_user.py b/tests/pytests/integration/modules/test_mac_user.py index fc6e92680bf2..5216a460a6c7 100644 --- a/tests/pytests/integration/modules/test_mac_user.py +++ b/tests/pytests/integration/modules/test_mac_user.py @@ -142,7 +142,8 @@ def test_mac_user_changes(salt_call_cli, setup_teardown_vars): # Test mac.user.chshell salt_call_cli.run("user.chshell", CHANGE_USER, "/bin/zsh") - shell_info = salt_call_cli.run("user.info", CHANGE_USER) + ret = salt_call_cli.run("user.info", CHANGE_USER) + shell_info = ret.data assert shell_info["shell"] == "/bin/zsh" # Test mac_user.chhome diff --git a/tests/pytests/integration/modules/test_mac_xattr.py b/tests/pytests/integration/modules/test_mac_xattr.py index a2a6dcfbe2b0..1f3d5b21774c 100644 --- a/tests/pytests/integration/modules/test_mac_xattr.py +++ b/tests/pytests/integration/modules/test_mac_xattr.py @@ -45,7 +45,7 @@ def test_list_no_xattr(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.list", no_file) - assert ret.data == f"ERROR: File not found: {no_file}" + assert ret.stderr == f"ERROR: File not found: {no_file}" def test_write(salt_call_cli, setup_teardown_vars): @@ -79,7 +79,7 @@ def test_write(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.write", no_file, "patrick", "jellyfish") - assert ret.data == f"ERROR: File not found: {no_file}" + assert ret.stderr == f"ERROR: File not found: {no_file}" def test_read(salt_call_cli, setup_teardown_vars): @@ -103,11 +103,11 @@ def test_read(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.read", no_file, "spongebob") - assert ret.data == f"ERROR: File not found: {no_file}" + assert ret.stderr == f"ERROR: File not found: {no_file}" # Test attribute not found ret = salt_call_cli.run("xattr.read", test_file, "patrick") - assert ret.data == "ERROR: Attribute not found: patrick" + assert ret.stderr == "ERROR: Attribute not found: patrick" def test_delete(salt_call_cli, setup_teardown_vars): @@ -144,14 +144,11 @@ def test_delete(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.delete", no_file, "spongebob") - assert ( - salt_call_cli.run("xattr.delete", no_file, "spongebob") - == f"ERROR: File not found: {no_file}" - ) + assert ret.stderr == f"ERROR: File not found: {no_file}" # Test attribute not found ret = salt_call_cli.run("xattr.delete", test_file, "patrick") - assert ret.data == "ERROR: Attribute not found: patrick" + assert ret.stderr == "ERROR: Attribute not found: patrick" def test_clear(salt_call_cli, setup_teardown_vars): @@ -181,4 +178,4 @@ def test_clear(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.clear", no_file) - assert ret.data == f"ERROR: File not found: {no_file}" + assert ret.stderr == f"ERROR: File not found: {no_file}" From a24cc91c0af37fa1dec9a0a00191baffe6e02adb Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 15 Nov 2023 10:33:56 -0800 Subject: [PATCH 09/37] Adding more fixes for failing mac tests. --- salt/modules/mac_keychain.py | 15 ++++-- salt/modules/mac_power.py | 24 +++++---- .../integration/modules/test_mac_brew_pkg.py | 4 +- .../integration/modules/test_mac_desktop.py | 4 ++ .../integration/modules/test_mac_keychain.py | 11 +++-- .../integration/modules/test_mac_portspkg.py | 1 + .../test_mac_power_restart_power_failure.py | 6 +-- .../test_mac_power_sleep_on_power_button.py | 7 ++- .../modules/test_mac_power_wake_on_modem.py | 2 +- .../modules/test_mac_power_wake_on_net.py | 2 +- .../integration/modules/test_mac_service.py | 49 ++++++++----------- .../integration/modules/test_mac_xattr.py | 18 +++---- 12 files changed, 78 insertions(+), 65 deletions(-) diff --git a/salt/modules/mac_keychain.py b/salt/modules/mac_keychain.py index 7fdc162b9aa2..294d8f1c2e6a 100644 --- a/salt/modules/mac_keychain.py +++ b/salt/modules/mac_keychain.py @@ -129,7 +129,7 @@ def list_certs(keychain="/Library/Keychains/System.keychain"): return out.replace('"', "").split("\n") -def get_friendly_name(cert, password): +def get_friendly_name(cert, password, legacy=False): """ Get the friendly name of the given certificate @@ -143,15 +143,24 @@ def get_friendly_name(cert, password): Note: The password given here will show up as plaintext in the returned job info. + legacy + Assume legacy format for certificate. + CLI Example: .. code-block:: bash salt '*' keychain.get_friendly_name /tmp/test.p12 test123 """ + legacy_arg = "" + if legacy: + legacy_arg = "-legacy" + cmd = ( - "openssl pkcs12 -in {} -passin pass:{} -info -nodes -nokeys 2> /dev/null | " - "grep friendlyName:".format(shlex.quote(cert), shlex.quote(password)) + "openssl pkcs12 {} -in {} -passin pass:{} -info -nodes -nokeys 2> /dev/null | " + "grep friendlyName:".format( + legacy_arg, shlex.quote(cert), shlex.quote(password) + ) ) out = __salt__["cmd.run"](cmd, python_shell=True) return out.replace("friendlyName: ", "").strip() diff --git a/salt/modules/mac_power.py b/salt/modules/mac_power.py index 01fc561e834b..efdca6528465 100644 --- a/salt/modules/mac_power.py +++ b/salt/modules/mac_power.py @@ -68,7 +68,7 @@ def _validate_sleep(minutes): ) raise SaltInvocationError(msg) else: - msg = "Unknown Variable Type Passed for Minutes.\nPassed: {}".format(minutes) + msg = f"Unknown Variable Type Passed for Minutes.\nPassed: {minutes}" raise SaltInvocationError(msg) @@ -115,7 +115,7 @@ def set_sleep(minutes): salt '*' power.set_sleep never """ value = _validate_sleep(minutes) - cmd = "systemsetup -setsleep {}".format(value) + cmd = f"systemsetup -setsleep {value}" salt.utils.mac_utils.execute_return_success(cmd) state = [] @@ -165,7 +165,7 @@ def set_computer_sleep(minutes): salt '*' power.set_computer_sleep off """ value = _validate_sleep(minutes) - cmd = "systemsetup -setcomputersleep {}".format(value) + cmd = f"systemsetup -setcomputersleep {value}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated( @@ -210,7 +210,7 @@ def set_display_sleep(minutes): salt '*' power.set_display_sleep off """ value = _validate_sleep(minutes) - cmd = "systemsetup -setdisplaysleep {}".format(value) + cmd = f"systemsetup -setdisplaysleep {value}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated( @@ -255,7 +255,7 @@ def set_harddisk_sleep(minutes): salt '*' power.set_harddisk_sleep off """ value = _validate_sleep(minutes) - cmd = "systemsetup -setharddisksleep {}".format(value) + cmd = f"systemsetup -setharddisksleep {value}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated( @@ -303,12 +303,13 @@ def set_wake_on_modem(enabled): salt '*' power.set_wake_on_modem True """ state = salt.utils.mac_utils.validate_enabled(enabled) - cmd = "systemsetup -setwakeonmodem {}".format(state) + cmd = f"systemsetup -setwakeonmodem {state}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated( state, get_wake_on_modem, + True, ) @@ -353,12 +354,13 @@ def set_wake_on_network(enabled): salt '*' power.set_wake_on_network True """ state = salt.utils.mac_utils.validate_enabled(enabled) - cmd = "systemsetup -setwakeonnetworkaccess {}".format(state) + cmd = f"systemsetup -setwakeonnetworkaccess {state}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated( state, get_wake_on_network, + True, ) @@ -403,12 +405,13 @@ def set_restart_power_failure(enabled): salt '*' power.set_restart_power_failure True """ state = salt.utils.mac_utils.validate_enabled(enabled) - cmd = "systemsetup -setrestartpowerfailure {}".format(state) + cmd = f"systemsetup -setrestartpowerfailure {state}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated( state, get_restart_power_failure, + True, ) @@ -453,7 +456,7 @@ def set_restart_freeze(enabled): salt '*' power.set_restart_freeze True """ state = salt.utils.mac_utils.validate_enabled(enabled) - cmd = "systemsetup -setrestartfreeze {}".format(state) + cmd = f"systemsetup -setrestartfreeze {state}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated(state, get_restart_freeze, True) @@ -502,10 +505,11 @@ def set_sleep_on_power_button(enabled): salt '*' power.set_sleep_on_power_button True """ state = salt.utils.mac_utils.validate_enabled(enabled) - cmd = "systemsetup -setallowpowerbuttontosleepcomputer {}".format(state) + cmd = f"systemsetup -setallowpowerbuttontosleepcomputer {state}" salt.utils.mac_utils.execute_return_success(cmd) return salt.utils.mac_utils.confirm_updated( state, get_sleep_on_power_button, + True, ) diff --git a/tests/pytests/integration/modules/test_mac_brew_pkg.py b/tests/pytests/integration/modules/test_mac_brew_pkg.py index c3acae12c73f..52304ab1a851 100644 --- a/tests/pytests/integration/modules/test_mac_brew_pkg.py +++ b/tests/pytests/integration/modules/test_mac_brew_pkg.py @@ -136,8 +136,8 @@ def test_latest_version(salt_call_cli, add_pkg, setup_teardown_vars): installed_latest = ret.data version = salt_call_cli.run("pkg.version", add_pkg) try: - assert isinstance(uninstalled_latest.data, str) - assert installed_latest.data == version.data + assert isinstance(uninstalled_latest, str) + assert installed_latest == version.data except AssertionError: salt_call_cli.run("pkg.remove", add_pkg) raise diff --git a/tests/pytests/integration/modules/test_mac_desktop.py b/tests/pytests/integration/modules/test_mac_desktop.py index 71686c189a64..d918b7c74172 100644 --- a/tests/pytests/integration/modules/test_mac_desktop.py +++ b/tests/pytests/integration/modules/test_mac_desktop.py @@ -44,6 +44,8 @@ def test_screensaver(salt_call_cli): Tests the return of the screensaver function. """ ret = salt_call_cli.run("desktop.screensaver") + if "does not exist" in ret.stderr: + pytest.skip("Skipping. Screensaver unavailable.") assert ret.data @@ -52,6 +54,8 @@ def test_lock(salt_call_cli): Tests the return of the lock function. """ ret = salt_call_cli.run("desktop.lock") + if "Unable to run" in ret.stderr: + pytest.skip("Skipping. Unable to lock screen.") assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py index 278a66919a9b..24eed4740da9 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -2,9 +2,12 @@ Validate the mac-keychain module """ +import os + import pytest from salt.exceptions import CommandExecutionError +from tests.support.runtests import RUNTIME_VARS pytestmark = [ pytest.mark.slow_test, @@ -16,7 +19,7 @@ @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli, base_env_state_tree_root_dir): - cert = str(base_env_state_tree_root_dir / "certs" / "salttest.p12") + cert = os.path.join(RUNTIME_VARS.FILES, "file", "base", "certs", "salttest.p12") cert_alias = "Salt Test" passwd = "salttest" @@ -41,6 +44,7 @@ def test_mac_keychain_install(setup_teardown_vars, salt_call_cli): ret = salt_call_cli.run("keychain.install", cert, passwd) install_cert = ret.data assert install_cert + assert install_cert == "1 identity imported." # check to ensure the cert was installed ret = salt_call_cli.run("keychain.list_certs") @@ -86,12 +90,13 @@ def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli): passwd = setup_teardown_vars[2] salt_call_cli.run("keychain.install", cert, passwd) - certs_list = salt_call_cli.run("keychain.list_certs") + ret = salt_call_cli.run("keychain.list_certs") + certs_list = ret.data if cert_alias not in certs_list: salt_call_cli.run("keychain.uninstall", cert_alias) pytest.skip("Failed to install keychain") - ret = salt_call_cli.run("keychain.get_friendly_name", cert, passwd) + ret = salt_call_cli.run("keychain.get_friendly_name", cert, passwd, legacy=True) get_name = ret.data assert get_name == cert_alias diff --git a/tests/pytests/integration/modules/test_mac_portspkg.py b/tests/pytests/integration/modules/test_mac_portspkg.py index edf8d4e7a5a7..6fc65aad125c 100644 --- a/tests/pytests/integration/modules/test_mac_portspkg.py +++ b/tests/pytests/integration/modules/test_mac_portspkg.py @@ -9,6 +9,7 @@ pytest.mark.destructive_test, pytest.mark.skip_if_not_root, pytest.mark.skip_unless_on_darwin, + pytest.mark.skip_if_binaries_missing("port"), ] diff --git a/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py b/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py index c2d0277fa8ec..aec2d90fd142 100644 --- a/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py +++ b/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py @@ -21,7 +21,7 @@ def test_restart_power_failure(salt_call_cli): RESTART_POWER = None ret = salt_call_cli.run("power.get_restart_power_failure") - if isinstance(ret, bool): + if isinstance(ret.data, bool): RESTART_POWER = ret.data # If available on this system, test it @@ -30,13 +30,13 @@ def test_restart_power_failure(salt_call_cli): ret = salt_call_cli.run("power.get_restart_power_failure") assert "Error" in ret.data else: - ret = salt_call_cli.run("power.set_restart_power_failure", "on") + ret = salt_call_cli.run("power.set_restart_power_failure", "On") assert ret.data ret = salt_call_cli.run("power.get_restart_power_failure") assert ret.data - ret = salt_call_cli.run("power.set_restart_power_failure", "off") + ret = salt_call_cli.run("power.set_restart_power_failure", "Off") assert ret.data ret = salt_call_cli.run("power.get_restart_power_failure") diff --git a/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py b/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py index 543dd5e3539c..1e6f71b3babb 100644 --- a/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py +++ b/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py @@ -22,13 +22,12 @@ def test_sleep_on_power_button(salt_call_cli): ret = salt_call_cli.run("power.get_sleep_on_power_button") if isinstance(ret.data, bool): - SLEEP_ON_BUTTON = salt_call_cli.run("power.get_sleep_on_power_button") + SLEEP_ON_BUTTON = ret.data # If available on this system, test it - if SLEEP_ON_BUTTON.data is None: + if SLEEP_ON_BUTTON is None: # Check for not available - ret = salt_call_cli.run("power.get_sleep_on_power_button") - assert "Error" in ret.data + assert "Error" in ret.stderr else: ret = salt_call_cli.run("power.set_sleep_on_power_button", "on") assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py b/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py index 137d74c202ce..1fbb273eb8fc 100644 --- a/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py +++ b/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py @@ -26,7 +26,7 @@ def test_wake_on_modem(salt_call_cli): if WAKE_ON_MODEM is None: # Check for not available ret = salt_call_cli.run("power.get_wake_on_modem") - assert "Error" in ret.data + assert "Error" in ret.stderr else: ret = salt_call_cli.run("power.set_wake_on_modem", "on") assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_net.py b/tests/pytests/integration/modules/test_mac_power_wake_on_net.py index 741e6119a96b..15b26672c3c7 100644 --- a/tests/pytests/integration/modules/test_mac_power_wake_on_net.py +++ b/tests/pytests/integration/modules/test_mac_power_wake_on_net.py @@ -28,7 +28,7 @@ def test_wake_on_network(salt_call_cli): if WAKE_ON_NET is None: # Check for not available ret = salt_call_cli.run("power.get_wake_on_network") - assert "Error" in ret.data + assert "Error" in ret.stderr else: ret = salt_call_cli.run("power.set_wake_on_network", "on") assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_service.py b/tests/pytests/integration/modules/test_mac_service.py index 370a75307473..d57d89dc985e 100644 --- a/tests/pytests/integration/modules/test_mac_service.py +++ b/tests/pytests/integration/modules/test_mac_service.py @@ -29,8 +29,8 @@ def setup_teardown_vars(salt_call_cli): } with salt.utils.files.fopen(SERVICE_PATH, "wb") as fp: plistlib.dump(service_data, fp) - salt_call_cli.run("service.enable", SERVICE_NAME) - salt_call_cli.run("service.start", SERVICE_NAME) + ret = salt_call_cli.run("service.enable", SERVICE_NAME) + ret = salt_call_cli.run("service.start", SERVICE_NAME) try: yield SERVICE_NAME @@ -51,7 +51,7 @@ def test_show(salt_call_cli, setup_teardown_vars): # Missing Service ret = salt_call_cli.run("service.show", "spongebob") - assert "Service not found" in ret.data + assert "Service not found" in ret.stderr def test_launchctl(salt_call_cli): @@ -63,13 +63,13 @@ def test_launchctl(salt_call_cli): assert ret.data ret = salt_call_cli.run( - "service.launchctl", ["error", "bootstrap", 64], return_stdout=True + "service.launchctl", "error", "bootstrap", 64, return_stdout=True ) assert ret.data == "64: unknown error code" # Raise an error ret = salt_call_cli.run("service.launchctl", "error", "bootstrap") - assert "Failed to error service" in ret.data + assert "Failed to error service" in ret.stderr def test_list(salt_call_cli, setup_teardown_vars): @@ -85,7 +85,7 @@ def test_list(salt_call_cli, setup_teardown_vars): # Service not found ret = salt_call_cli.run("service.list", "spongebob") - assert "Service not found" in ret.data + assert "Service not found" in ret.stderr def test_enable(salt_call_cli, setup_teardown_vars): @@ -97,7 +97,7 @@ def test_enable(salt_call_cli, setup_teardown_vars): assert ret.data ret = salt_call_cli.run("service.enable", "spongebob") - assert "Service not found" in ret.data + assert "Service not found" in ret.stderr def test_disable(salt_call_cli, setup_teardown_vars): @@ -109,7 +109,7 @@ def test_disable(salt_call_cli, setup_teardown_vars): assert ret.data ret = salt_call_cli.run("service.disable", "spongebob") - assert "Service not found" in ret.data + assert "Service not found" in ret.stderr def test_start(salt_call_cli, setup_teardown_vars): @@ -119,11 +119,12 @@ def test_start(salt_call_cli, setup_teardown_vars): Test service.status """ SERVICE_NAME = setup_teardown_vars + salt_call_cli.run("service.stop", SERVICE_NAME) ret = salt_call_cli.run("service.start", SERVICE_NAME) assert ret.data ret = salt_call_cli.run("service.start", "spongebob") - assert "Service not found" in ret.data + assert "Service not found" in ret.stderr def test_stop(salt_call_cli, setup_teardown_vars): @@ -134,8 +135,8 @@ def test_stop(salt_call_cli, setup_teardown_vars): ret = salt_call_cli.run("service.stop", SERVICE_NAME) assert ret.data - ret = salt_call_cli.run("service.stop", ["spongebob"]) - assert "Service not found" in ret.data + ret = salt_call_cli.run("service.stop", "spongebob") + assert "Service not found" in ret.stderr def test_status(salt_call_cli, setup_teardown_vars): @@ -144,14 +145,12 @@ def test_status(salt_call_cli, setup_teardown_vars): """ SERVICE_NAME = setup_teardown_vars # A running service - ret = salt_call_cli.run("service.start", SERVICE_NAME) - assert ret.data + salt_call_cli.run("service.start", SERVICE_NAME) ret = salt_call_cli.run("service.status", SERVICE_NAME) assert ret.data # A stopped service - ret = salt_call_cli.run("service.stop", SERVICE_NAME) - assert ret.data + salt_call_cli.run("service.stop", SERVICE_NAME) ret = salt_call_cli.run("service.status", SERVICE_NAME) assert not ret.data @@ -189,20 +188,12 @@ def test_enabled(salt_call_cli, setup_teardown_vars): Test service.enabled """ SERVICE_NAME = setup_teardown_vars + salt_call_cli.run("service.disabled", SERVICE_NAME) ret = salt_call_cli.run("service.enabled", SERVICE_NAME) assert ret.data - ret = salt_call_cli.run("service.start", SERVICE_NAME) - assert ret.data - - ret = salt_call_cli.run("service.enabled", SERVICE_NAME) - assert ret.data - - ret = salt_call_cli.run("service.stop", SERVICE_NAME) - assert ret.data - ret = salt_call_cli.run("service.enabled", "spongebob") - assert ret.data + assert "Service not found: spongebob" in ret.stderr def test_disabled(salt_call_cli, setup_teardown_vars): @@ -210,8 +201,8 @@ def test_disabled(salt_call_cli, setup_teardown_vars): Test service.disabled """ SERVICE_NAME = setup_teardown_vars - ret = salt_call_cli.run("service.start", SERVICE_NAME) - assert ret.data + salt_call_cli.run("service.enabled", SERVICE_NAME) + salt_call_cli.run("service.start", SERVICE_NAME) ret = salt_call_cli.run("service.disabled", SERVICE_NAME) assert not ret.data @@ -225,8 +216,8 @@ def test_disabled(salt_call_cli, setup_teardown_vars): ret = salt_call_cli.run("service.enable", SERVICE_NAME) assert ret.data - ret = salt_call_cli.run("service.stop", "spongebob") - assert "Service not found" in ret.data + ret = salt_call_cli.run("service.disable", "spongebob") + assert "Service not found: spongebob" in ret.stderr def test_get_all(salt_call_cli, setup_teardown_vars): diff --git a/tests/pytests/integration/modules/test_mac_xattr.py b/tests/pytests/integration/modules/test_mac_xattr.py index 1f3d5b21774c..5ac390f46589 100644 --- a/tests/pytests/integration/modules/test_mac_xattr.py +++ b/tests/pytests/integration/modules/test_mac_xattr.py @@ -16,8 +16,8 @@ @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli, tmp_path): - test_file = tmp_path / "xattr_test_file.txt" - no_file = tmp_path / "xattr_no_file.txt" + test_file = str(tmp_path / "xattr_test_file.txt") + no_file = str(tmp_path / "xattr_no_file.txt") salt_call_cli.run("file.touch", test_file) @@ -45,7 +45,7 @@ def test_list_no_xattr(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.list", no_file) - assert ret.stderr == f"ERROR: File not found: {no_file}" + assert f"File not found: {no_file}" in ret.stderr def test_write(salt_call_cli, setup_teardown_vars): @@ -79,7 +79,7 @@ def test_write(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.write", no_file, "patrick", "jellyfish") - assert ret.stderr == f"ERROR: File not found: {no_file}" + assert f"File not found: {no_file}" in ret.stderr def test_read(salt_call_cli, setup_teardown_vars): @@ -103,11 +103,11 @@ def test_read(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.read", no_file, "spongebob") - assert ret.stderr == f"ERROR: File not found: {no_file}" + assert f"File not found: {no_file}" in ret.stderr # Test attribute not found ret = salt_call_cli.run("xattr.read", test_file, "patrick") - assert ret.stderr == "ERROR: Attribute not found: patrick" + assert "Attribute not found: patrick" in ret.stderr def test_delete(salt_call_cli, setup_teardown_vars): @@ -144,11 +144,11 @@ def test_delete(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.delete", no_file, "spongebob") - assert ret.stderr == f"ERROR: File not found: {no_file}" + assert f"File not found: {no_file}" in ret.stderr # Test attribute not found ret = salt_call_cli.run("xattr.delete", test_file, "patrick") - assert ret.stderr == "ERROR: Attribute not found: patrick" + assert "Attribute not found: patrick" in ret.stderr def test_clear(salt_call_cli, setup_teardown_vars): @@ -178,4 +178,4 @@ def test_clear(salt_call_cli, setup_teardown_vars): # Test file not found ret = salt_call_cli.run("xattr.clear", no_file) - assert ret.stderr == f"ERROR: File not found: {no_file}" + assert f"File not found: {no_file}" in ret.stderr From 5bf6dc5a65f7b467147f2bc6c2de190c1e1b05d0 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 15 Nov 2023 11:26:05 -0800 Subject: [PATCH 10/37] Update test_mac_keychain.py::test_get_friendly_name to reflect changes. --- tests/pytests/unit/modules/test_mac_keychain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytests/unit/modules/test_mac_keychain.py b/tests/pytests/unit/modules/test_mac_keychain.py index eb411e69b57b..0d5dd47afbe8 100644 --- a/tests/pytests/unit/modules/test_mac_keychain.py +++ b/tests/pytests/unit/modules/test_mac_keychain.py @@ -81,7 +81,7 @@ def test_get_friendly_name(): with patch.dict(keychain.__salt__, {"cmd.run": mock}): out = keychain.get_friendly_name("/path/to/cert.p12", "passw0rd") mock.assert_called_once_with( - "openssl pkcs12 -in /path/to/cert.p12 -passin pass:passw0rd -info " + "openssl pkcs12 -legacy -in /path/to/cert.p12 -passin pass:passw0rd -info " "-nodes -nokeys 2> /dev/null | grep friendlyName:", python_shell=True, ) From 47fa609ef33a3b788d245d5419a856d950574ccb Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 15 Nov 2023 14:20:56 -0800 Subject: [PATCH 11/37] fixing test_mac_user_changes and test_mac_keychain_get_friendly_name --- salt/modules/mac_keychain.py | 2 +- tests/pytests/integration/modules/test_mac_user.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/modules/mac_keychain.py b/salt/modules/mac_keychain.py index 294d8f1c2e6a..1ba50261c59e 100644 --- a/salt/modules/mac_keychain.py +++ b/salt/modules/mac_keychain.py @@ -122,7 +122,7 @@ def list_certs(keychain="/Library/Keychains/System.keychain"): salt '*' keychain.list_certs """ cmd = ( - 'security find-certificate -a {} | grep -o "alis".*\\" | ' + 'security find-certificate -a {} | grep -o "alis.*" | ' "grep -o '\\\"[-A-Za-z0-9.:() ]*\\\"'".format(shlex.quote(keychain)) ) out = __salt__["cmd.run"](cmd, python_shell=True) diff --git a/tests/pytests/integration/modules/test_mac_user.py b/tests/pytests/integration/modules/test_mac_user.py index 5216a460a6c7..9add44141be8 100644 --- a/tests/pytests/integration/modules/test_mac_user.py +++ b/tests/pytests/integration/modules/test_mac_user.py @@ -159,8 +159,8 @@ def test_mac_user_changes(salt_call_cli, setup_teardown_vars): assert fullname_info["fullname"] == "Foo Bar" # Test mac_user.chgroups - ret = salt_call_cli.run("user.info", CHANGE_USER)["groups"] - pre_info = ret.data + ret = salt_call_cli.run("user.info", CHANGE_USER) + pre_info = ret.data["groups"] expected = pre_info + ["wheel"] salt_call_cli.run("user.chgroups", CHANGE_USER, "wheel") ret = salt_call_cli.run("user.info", CHANGE_USER) From 1b68610da894f5c79de2d67927a3d748117e3136 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 15 Nov 2023 17:03:57 -0800 Subject: [PATCH 12/37] fixing failing unit tests. --- tests/pytests/unit/modules/test_mac_keychain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pytests/unit/modules/test_mac_keychain.py b/tests/pytests/unit/modules/test_mac_keychain.py index 0d5dd47afbe8..cf06c9889430 100644 --- a/tests/pytests/unit/modules/test_mac_keychain.py +++ b/tests/pytests/unit/modules/test_mac_keychain.py @@ -65,7 +65,7 @@ def test_list_certs(): out = keychain.list_certs("/path/to/cert.p12") mock.assert_called_once_with( "security find-certificate -a /path/to/cert.p12 | " - 'grep -o "alis".*\\" | grep -o \'\\"[-A-Za-z0-9.:() ]*\\"\'', + 'grep -o "alis.*" | grep -o \'\\"[-A-Za-z0-9.:() ]*\\"\'', python_shell=True, ) @@ -79,7 +79,7 @@ def test_get_friendly_name(): expected = "ID Installer Salt" mock = MagicMock(return_value="friendlyName: ID Installer Salt") with patch.dict(keychain.__salt__, {"cmd.run": mock}): - out = keychain.get_friendly_name("/path/to/cert.p12", "passw0rd") + out = keychain.get_friendly_name("/path/to/cert.p12", "passw0rd", legacy=True) mock.assert_called_once_with( "openssl pkcs12 -legacy -in /path/to/cert.p12 -passin pass:passw0rd -info " "-nodes -nokeys 2> /dev/null | grep friendlyName:", From eff3e3dfa51dce02da226c72c7cacaf417b33d8e Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Thu, 16 Nov 2023 17:30:34 -0800 Subject: [PATCH 13/37] move test_mac_brew_pkg.py integration tests to functional. --- .../modules/test_mac_brew_pkg.py | 104 +++++++++--------- 1 file changed, 50 insertions(+), 54 deletions(-) rename tests/pytests/{integration => functional}/modules/test_mac_brew_pkg.py (57%) diff --git a/tests/pytests/integration/modules/test_mac_brew_pkg.py b/tests/pytests/functional/modules/test_mac_brew_pkg.py similarity index 57% rename from tests/pytests/integration/modules/test_mac_brew_pkg.py rename to tests/pytests/functional/modules/test_mac_brew_pkg.py index 52304ab1a851..f1e6d75fbaf1 100644 --- a/tests/pytests/integration/modules/test_mac_brew_pkg.py +++ b/tests/pytests/functional/modules/test_mac_brew_pkg.py @@ -1,5 +1,6 @@ """ :codeauthor: Nicole Thomas + :codeauthor: Gareth J. Greenaway """ import pytest @@ -18,6 +19,11 @@ # Grab some small packages available online for brew +@pytest.fixture(scope="module") +def pkg(modules): + return modules.pkg + + @pytest.fixture(scope="function") def add_pkg(): yield "algol68g" @@ -29,72 +35,66 @@ def del_pkg(): @pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli, add_pkg, del_pkg): +def setup_teardown_vars(pkg, add_pkg, del_pkg): try: yield finally: - ret = salt_call_cli.run("pkg.list_pkgs") - pkg_list = ret.data + pkg_list = pkg.list_pkgs() # Remove any installed packages if add_pkg in pkg_list: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) if del_pkg in pkg_list: - salt_call_cli.run("pkg.remove", del_pkg) + pkg.remove(del_pkg) -def test_brew_install(salt_call_cli, add_pkg, setup_teardown_vars): +def test_brew_install(pkg, add_pkg, setup_teardown_vars): """ Tests the installation of packages """ try: - salt_call_cli.run("pkg.install", add_pkg) - ret = salt_call_cli.run("pkg.list_pkgs") - pkg_list = ret.data + pkg.install(add_pkg) + pkg_list = pkg.list_pkgs() try: assert add_pkg in pkg_list except AssertionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise except CommandExecutionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise -def test_remove(salt_call_cli, del_pkg, setup_teardown_vars): +def test_remove(pkg, del_pkg, setup_teardown_vars): """ Tests the removal of packages """ try: # Install a package to delete - If unsuccessful, skip the test - salt_call_cli.run("pkg.install", del_pkg) - ret = salt_call_cli.run("pkg.list_pkgs") - pkg_list = ret.data + pkg.install(del_pkg) + pkg_list = pkg.list_pkgs() if del_pkg not in pkg_list: - salt_call_cli.run("pkg.install", del_pkg) + pkg.install(del_pkg) pytest.skip("Failed to install a package to delete") # Now remove the installed package - salt_call_cli.run("pkg.remove", del_pkg) - ret = salt_call_cli.run("pkg.list_pkgs") - del_list = ret.data + pkg.remove(del_pkg) + del_list = pkg.list_pkgs() assert del_pkg not in del_list except CommandExecutionError: - salt_call_cli.run("pkg.remove", del_pkg) + pkg.remove(del_pkg) raise -def test_version(salt_call_cli, add_pkg, setup_teardown_vars): +def test_version(pkg, add_pkg, setup_teardown_vars): """ Test pkg.version for mac. Installs a package and then checks we can get a version for the installed package. """ try: - salt_call_cli.run("pkg.install", add_pkg) - ret = salt_call_cli.run("pkg.list_pkgs") - pkg_list = ret.data - ret = salt_call_cli.run("pkg.version", add_pkg) - version = ret.data + pkg.install(add_pkg) + pkg_list = pkg.list_pkgs() + version = pkg.version(add_pkg) try: assert version, "version: {} is empty, or other issue is present".format( version @@ -111,14 +111,14 @@ def test_version(salt_call_cli, add_pkg, setup_teardown_vars): add_pkg, version, pkg_list[add_pkg] ) except AssertionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise except CommandExecutionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise -def test_latest_version(salt_call_cli, add_pkg, setup_teardown_vars): +def test_latest_version(pkg, add_pkg, setup_teardown_vars): """ Test pkg.latest_version: - get the latest version available @@ -127,41 +127,38 @@ def test_latest_version(salt_call_cli, add_pkg, setup_teardown_vars): - check that the latest version is empty after installing it """ try: - salt_call_cli.run("pkg.remove", add_pkg) - ret = salt_call_cli.run("pkg.latest_version", add_pkg) - uninstalled_latest = ret.data - - salt_call_cli.run("pkg.install", add_pkg) - ret = salt_call_cli.run("pkg.latest_version", add_pkg) - installed_latest = ret.data - version = salt_call_cli.run("pkg.version", add_pkg) + pkg.remove(add_pkg) + uninstalled_latest = pkg.latest_version(add_pkg) + + pkg.install(add_pkg) + installed_latest = pkg.latest_version(add_pkg) + version = pkg.version(add_pkg) try: assert isinstance(uninstalled_latest, str) - assert installed_latest == version.data + assert installed_latest == version except AssertionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise except CommandExecutionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise -def test_refresh_db(salt_call_cli, setup_teardown_vars): +def test_refresh_db(pkg, setup_teardown_vars): """ Integration test to ensure pkg.refresh_db works with brew """ - refresh_brew = salt_call_cli.run("pkg.refresh_db") - assert refresh_brew.data + refresh_brew = pkg.refresh_db() + assert refresh_brew -def test_list_upgrades(salt_call_cli, add_pkg, setup_teardown_vars): +def test_list_upgrades(pkg, add_pkg, setup_teardown_vars): """ Test pkg.list_upgrades: data is in the form {'name1': 'version1', 'name2': 'version2', ... } """ try: - ret = salt_call_cli.run("pkg.list_upgrades") - upgrades = ret.data + upgrades = pkg.list_upgrades() try: assert isinstance(upgrades, dict) if upgrades: @@ -169,30 +166,29 @@ def test_list_upgrades(salt_call_cli, add_pkg, setup_teardown_vars): assert isinstance(name, str) assert isinstance(upgrades[name], str) except AssertionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise except CommandExecutionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise -def test_info_installed(salt_call_cli, add_pkg, setup_teardown_vars): +def test_info_installed(pkg, add_pkg, setup_teardown_vars): """ Test pkg.info_installed: info returned has certain fields used by mac_brew.latest_version """ try: - salt_call_cli.run("pkg.install", add_pkg) - ret = salt_call_cli.run("pkg.info_installed", add_pkg) - info = ret.data + pkg.install(add_pkg) + info = pkg.info_installed(add_pkg) try: assert add_pkg in info assert "versions" in info[add_pkg] assert "revision" in info[add_pkg] assert "stable" in info[add_pkg]["versions"] except AssertionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise except CommandExecutionError: - salt_call_cli.run("pkg.remove", add_pkg) + pkg.remove(add_pkg) raise From 817ae824caf34760c3fa8801cf6e54d75bcaf382 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 17 Nov 2023 09:12:49 -0800 Subject: [PATCH 14/37] Add an assert to make sure the cert_alias is in the list of certs. --- salt/modules/mac_keychain.py | 2 ++ tests/pytests/integration/modules/test_mac_keychain.py | 1 + 2 files changed, 3 insertions(+) diff --git a/salt/modules/mac_keychain.py b/salt/modules/mac_keychain.py index 1ba50261c59e..13e82d615e80 100644 --- a/salt/modules/mac_keychain.py +++ b/salt/modules/mac_keychain.py @@ -151,6 +151,8 @@ def get_friendly_name(cert, password, legacy=False): .. code-block:: bash salt '*' keychain.get_friendly_name /tmp/test.p12 test123 + + salt '*' keychain.get_friendly_name /tmp/test.p12 test123 legacy=True """ legacy_arg = "" if legacy: diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py index 24eed4740da9..b999702c9597 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -92,6 +92,7 @@ def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli): salt_call_cli.run("keychain.install", cert, passwd) ret = salt_call_cli.run("keychain.list_certs") certs_list = ret.data + assert cert_alias in certs_list if cert_alias not in certs_list: salt_call_cli.run("keychain.uninstall", cert_alias) pytest.skip("Failed to install keychain") From 412370f773001696cffbc30410e67cbb08e6201c Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 17 Nov 2023 10:36:20 -0800 Subject: [PATCH 15/37] allow SSH before slow tests start --- .github/workflows/test-action-macos.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-action-macos.yml b/.github/workflows/test-action-macos.yml index 6eb610302c0a..eab50b7c34f6 100644 --- a/.github/workflows/test-action-macos.yml +++ b/.github/workflows/test-action-macos.yml @@ -202,6 +202,11 @@ jobs: -k "mac or darwin" --suppress-no-test-exit-code \ --from-filenames=testrun-changed-files.txt + - name: ssh into vm + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: true + - name: Run Slow/Changed Tests id: run-slow-changed-tests if: ${{ fromJSON(inputs.testrun)['type'] != 'full' && fromJSON(inputs.testrun)['selected_tests']['slow'] == false }} From 82c9d4ca32bf0ac3f5c36a4bfabafd0f563814b7 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 17 Nov 2023 14:55:41 -0800 Subject: [PATCH 16/37] Only use legacy=True if openssl version is greater than or equal to 3.0.0. --- .github/workflows/test-action-macos.yml | 5 ----- .../integration/modules/test_mac_keychain.py | 14 ++++++++++++-- tests/pytests/unit/modules/test_mac_keychain.py | 9 +++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-action-macos.yml b/.github/workflows/test-action-macos.yml index eab50b7c34f6..6eb610302c0a 100644 --- a/.github/workflows/test-action-macos.yml +++ b/.github/workflows/test-action-macos.yml @@ -202,11 +202,6 @@ jobs: -k "mac or darwin" --suppress-no-test-exit-code \ --from-filenames=testrun-changed-files.txt - - name: ssh into vm - uses: mxschmitt/action-tmate@v3 - with: - limit-access-to-actor: true - - name: Run Slow/Changed Tests id: run-slow-changed-tests if: ${{ fromJSON(inputs.testrun)['type'] != 'full' && fromJSON(inputs.testrun)['selected_tests']['slow'] == false }} diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py index b999702c9597..4b231c30227d 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -6,6 +6,7 @@ import pytest +import salt.utils.versions from salt.exceptions import CommandExecutionError from tests.support.runtests import RUNTIME_VARS @@ -81,7 +82,7 @@ def test_mac_keychain_uninstall(setup_teardown_vars, salt_call_cli): salt_call_cli.run("keychain.uninstall", cert_alias) -def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli): +def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli, shell): """ Test that attempts to get friendly name of a cert """ @@ -97,7 +98,16 @@ def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli): salt_call_cli.run("keychain.uninstall", cert_alias) pytest.skip("Failed to install keychain") - ret = salt_call_cli.run("keychain.get_friendly_name", cert, passwd, legacy=True) + openssl_version = shell.run("openssl", "version") + + # openssl versions under 3.0.0 do not include legacy flag + if salt.utils.versions.compare(ver1=openssl_version, oper="<", ver2="3.0.0"): + ret = salt_call_cli.run( + "keychain.get_friendly_name", cert, passwd, legacy=False + ) + else: + ret = salt_call_cli.run("keychain.get_friendly_name", cert, passwd, legacy=True) + get_name = ret.data assert get_name == cert_alias diff --git a/tests/pytests/unit/modules/test_mac_keychain.py b/tests/pytests/unit/modules/test_mac_keychain.py index cf06c9889430..75a8cb2110e5 100644 --- a/tests/pytests/unit/modules/test_mac_keychain.py +++ b/tests/pytests/unit/modules/test_mac_keychain.py @@ -88,6 +88,15 @@ def test_get_friendly_name(): assert out == expected + out = keychain.get_friendly_name("/path/to/cert.p12", "passw0rd", legacy=False) + mock.assert_called_once_with( + "openssl pkcs12 -in /path/to/cert.p12 -passin pass:passw0rd -info " + "-nodes -nokeys 2> /dev/null | grep friendlyName:", + python_shell=True, + ) + + assert out == expected + def test_get_default_keychain(): """ From 39d6e5fad9d57862915947a0647f42541c35c906 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 17 Nov 2023 16:56:48 -0800 Subject: [PATCH 17/37] Update test_mac_keychain.py Need to mock cmd again for the second call. --- tests/pytests/unit/modules/test_mac_keychain.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pytests/unit/modules/test_mac_keychain.py b/tests/pytests/unit/modules/test_mac_keychain.py index 75a8cb2110e5..ed00a645219e 100644 --- a/tests/pytests/unit/modules/test_mac_keychain.py +++ b/tests/pytests/unit/modules/test_mac_keychain.py @@ -88,6 +88,7 @@ def test_get_friendly_name(): assert out == expected + with patch.dict(keychain.__salt__, {"cmd.run": mock}): out = keychain.get_friendly_name("/path/to/cert.p12", "passw0rd", legacy=False) mock.assert_called_once_with( "openssl pkcs12 -in /path/to/cert.p12 -passin pass:passw0rd -info " From 1dd2269f1c3a51bb432731c42768c290d2d17eb2 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 17 Nov 2023 17:43:57 -0800 Subject: [PATCH 18/37] Update mac_keychain.py Update openssl_cmd is legacy is True. --- salt/modules/mac_keychain.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/salt/modules/mac_keychain.py b/salt/modules/mac_keychain.py index 13e82d615e80..978d214ebf26 100644 --- a/salt/modules/mac_keychain.py +++ b/salt/modules/mac_keychain.py @@ -154,14 +154,14 @@ def get_friendly_name(cert, password, legacy=False): salt '*' keychain.get_friendly_name /tmp/test.p12 test123 legacy=True """ - legacy_arg = "" + openssl_cmd = "openssl pkcs12" if legacy: - legacy_arg = "-legacy" + openssl_cmd = f"{openssl_cmd} -legacy" cmd = ( - "openssl pkcs12 {} -in {} -passin pass:{} -info -nodes -nokeys 2> /dev/null | " + "{} -in {} -passin pass:{} -info -nodes -nokeys 2> /dev/null | " "grep friendlyName:".format( - legacy_arg, shlex.quote(cert), shlex.quote(password) + openssl_cmd, shlex.quote(cert), shlex.quote(password) ) ) out = __salt__["cmd.run"](cmd, python_shell=True) From 118a0aaebc665b10aac0712aea051ff4f26da990 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 17 Nov 2023 21:41:43 -0800 Subject: [PATCH 19/37] Update test_mac_keychain.py Need to recreate the mock to ensure the number of calls is correct. --- tests/pytests/unit/modules/test_mac_keychain.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pytests/unit/modules/test_mac_keychain.py b/tests/pytests/unit/modules/test_mac_keychain.py index ed00a645219e..bbf9d20aaf41 100644 --- a/tests/pytests/unit/modules/test_mac_keychain.py +++ b/tests/pytests/unit/modules/test_mac_keychain.py @@ -88,6 +88,7 @@ def test_get_friendly_name(): assert out == expected + mock = MagicMock(return_value="friendlyName: ID Installer Salt") with patch.dict(keychain.__salt__, {"cmd.run": mock}): out = keychain.get_friendly_name("/path/to/cert.p12", "passw0rd", legacy=False) mock.assert_called_once_with( From 95ec32c4e84c9eec8513682dfe0809154226d463 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Sat, 18 Nov 2023 07:46:49 -0800 Subject: [PATCH 20/37] add in SSH debugging again. --- .github/workflows/test-action-macos.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-action-macos.yml b/.github/workflows/test-action-macos.yml index 6eb610302c0a..eab50b7c34f6 100644 --- a/.github/workflows/test-action-macos.yml +++ b/.github/workflows/test-action-macos.yml @@ -202,6 +202,11 @@ jobs: -k "mac or darwin" --suppress-no-test-exit-code \ --from-filenames=testrun-changed-files.txt + - name: ssh into vm + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: true + - name: Run Slow/Changed Tests id: run-slow-changed-tests if: ${{ fromJSON(inputs.testrun)['type'] != 'full' && fromJSON(inputs.testrun)['selected_tests']['slow'] == false }} From f9af1d420598da5a5beafbc6dcb435d2d4dcbf46 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Sat, 18 Nov 2023 07:53:02 -0800 Subject: [PATCH 21/37] fixing the logic to retreive version for openssl. remove ssh debug. --- .github/workflows/test-action-macos.yml | 5 ----- tests/pytests/integration/modules/test_mac_keychain.py | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-action-macos.yml b/.github/workflows/test-action-macos.yml index eab50b7c34f6..6eb610302c0a 100644 --- a/.github/workflows/test-action-macos.yml +++ b/.github/workflows/test-action-macos.yml @@ -202,11 +202,6 @@ jobs: -k "mac or darwin" --suppress-no-test-exit-code \ --from-filenames=testrun-changed-files.txt - - name: ssh into vm - uses: mxschmitt/action-tmate@v3 - with: - limit-access-to-actor: true - - name: Run Slow/Changed Tests id: run-slow-changed-tests if: ${{ fromJSON(inputs.testrun)['type'] != 'full' && fromJSON(inputs.testrun)['selected_tests']['slow'] == false }} diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py index 4b231c30227d..fa042f89f6eb 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -98,7 +98,8 @@ def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli, shel salt_call_cli.run("keychain.uninstall", cert_alias) pytest.skip("Failed to install keychain") - openssl_version = shell.run("openssl", "version") + ret = shell.run("openssl", "version") + openssl_version = ret.stdout.split()[1] # openssl versions under 3.0.0 do not include legacy flag if salt.utils.versions.compare(ver1=openssl_version, oper="<", ver2="3.0.0"): From a08d7151ab3432eb88a8cab851d593e28e3a34c2 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Sun, 19 Nov 2023 11:55:57 -0800 Subject: [PATCH 22/37] adding a couple of checks to ensure the test runs as expected and if skipped otherwise. --- tests/pytests/integration/modules/test_mac_keychain.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py index fa042f89f6eb..79d304ddd1de 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -82,6 +82,7 @@ def test_mac_keychain_uninstall(setup_teardown_vars, salt_call_cli): salt_call_cli.run("keychain.uninstall", cert_alias) +@pytest.mark.skip_if_binaries_missing("openssl") def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli, shell): """ Test that attempts to get friendly name of a cert @@ -93,12 +94,12 @@ def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli, shel salt_call_cli.run("keychain.install", cert, passwd) ret = salt_call_cli.run("keychain.list_certs") certs_list = ret.data - assert cert_alias in certs_list if cert_alias not in certs_list: salt_call_cli.run("keychain.uninstall", cert_alias) pytest.skip("Failed to install keychain") ret = shell.run("openssl", "version") + assert ret.stdout openssl_version = ret.stdout.split()[1] # openssl versions under 3.0.0 do not include legacy flag From 70dfb5c132747678406094cf0363b5eb78ab02e7 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 20 Nov 2023 09:46:47 -0800 Subject: [PATCH 23/37] suggested changes --- .../functional/modules/test_mac_brew_pkg.py | 164 +++++++----------- .../integration/modules/test_mac_assistive.py | 12 +- .../integration/modules/test_mac_desktop.py | 27 +-- .../integration/modules/test_mac_group.py | 58 +++---- .../integration/modules/test_mac_keychain.py | 14 +- .../integration/modules/test_mac_portspkg.py | 20 +-- .../integration/modules/test_mac_power.py | 24 +-- .../integration/modules/test_mac_service.py | 116 ++++++------- .../integration/modules/test_mac_shadow.py | 146 ++++++---------- .../modules/test_mac_softwareupdate.py | 18 +- .../integration/modules/test_mac_system.py | 4 +- .../integration/modules/test_mac_timezone.py | 4 +- .../integration/modules/test_mac_user.py | 118 +++++-------- .../integration/modules/test_mac_xattr.py | 12 +- 14 files changed, 299 insertions(+), 438 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_brew_pkg.py b/tests/pytests/functional/modules/test_mac_brew_pkg.py index f1e6d75fbaf1..47895f0476cc 100644 --- a/tests/pytests/functional/modules/test_mac_brew_pkg.py +++ b/tests/pytests/functional/modules/test_mac_brew_pkg.py @@ -5,8 +5,6 @@ import pytest -from salt.exceptions import CommandExecutionError - pytestmark = [ pytest.mark.slow_test, pytest.mark.destructive_test, @@ -34,8 +32,8 @@ def del_pkg(): yield "acme" -@pytest.fixture(scope="function") -def setup_teardown_vars(pkg, add_pkg, del_pkg): +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(pkg, add_pkg, del_pkg): try: yield finally: @@ -48,77 +46,55 @@ def setup_teardown_vars(pkg, add_pkg, del_pkg): pkg.remove(del_pkg) -def test_brew_install(pkg, add_pkg, setup_teardown_vars): +def test_brew_install(pkg, add_pkg): """ Tests the installation of packages """ - try: - pkg.install(add_pkg) - pkg_list = pkg.list_pkgs() - try: - assert add_pkg in pkg_list - except AssertionError: - pkg.remove(add_pkg) - raise - except CommandExecutionError: - pkg.remove(add_pkg) - raise + pkg.install(add_pkg) + pkg_list = pkg.list_pkgs() + assert add_pkg in pkg_list -def test_remove(pkg, del_pkg, setup_teardown_vars): +def test_remove(pkg, del_pkg): """ Tests the removal of packages """ - try: - # Install a package to delete - If unsuccessful, skip the test + # Install a package to delete - If unsuccessful, skip the test + pkg.install(del_pkg) + pkg_list = pkg.list_pkgs() + if del_pkg not in pkg_list: pkg.install(del_pkg) - pkg_list = pkg.list_pkgs() - if del_pkg not in pkg_list: - pkg.install(del_pkg) - pytest.skip("Failed to install a package to delete") + pytest.skip("Failed to install a package to delete") - # Now remove the installed package - pkg.remove(del_pkg) - del_list = pkg.list_pkgs() - assert del_pkg not in del_list - except CommandExecutionError: - pkg.remove(del_pkg) - raise + # Now remove the installed package + pkg.remove(del_pkg) + del_list = pkg.list_pkgs() + assert del_pkg not in del_list -def test_version(pkg, add_pkg, setup_teardown_vars): +def test_version(pkg, add_pkg): """ Test pkg.version for mac. Installs a package and then checks we can get a version for the installed package. """ - try: - pkg.install(add_pkg) - pkg_list = pkg.list_pkgs() - version = pkg.version(add_pkg) - try: - assert version, "version: {} is empty, or other issue is present".format( - version - ) - assert ( - add_pkg in pkg_list - ), "package: {} is not in the list of installed packages: {}".format( - add_pkg, pkg_list - ) - # make sure the version is accurate and is listed in the pkg_list - assert version in str( - pkg_list[add_pkg] - ), "The {} version: {} is not listed in the pkg_list: {}".format( - add_pkg, version, pkg_list[add_pkg] - ) - except AssertionError: - pkg.remove(add_pkg) - raise - except CommandExecutionError: - pkg.remove(add_pkg) - raise - - -def test_latest_version(pkg, add_pkg, setup_teardown_vars): + pkg.install(add_pkg) + pkg_list = pkg.list_pkgs() + version = pkg.version(add_pkg) + assert version, f"version: {version} is empty, or other issue is present" + assert ( + add_pkg in pkg_list + ), "package: {} is not in the list of installed packages: {}".format( + add_pkg, pkg_list + ) + # make sure the version is accurate and is listed in the pkg_list + assert version in str( + pkg_list[add_pkg] + ), "The {} version: {} is not listed in the pkg_list: {}".format( + add_pkg, version, pkg_list[add_pkg] + ) + + +def test_latest_version(pkg, add_pkg): """ Test pkg.latest_version: - get the latest version available @@ -126,25 +102,17 @@ def test_latest_version(pkg, add_pkg, setup_teardown_vars): - get the latest version available - check that the latest version is empty after installing it """ - try: - pkg.remove(add_pkg) - uninstalled_latest = pkg.latest_version(add_pkg) - - pkg.install(add_pkg) - installed_latest = pkg.latest_version(add_pkg) - version = pkg.version(add_pkg) - try: - assert isinstance(uninstalled_latest, str) - assert installed_latest == version - except AssertionError: - pkg.remove(add_pkg) - raise - except CommandExecutionError: - pkg.remove(add_pkg) - raise + pkg.remove(add_pkg) + uninstalled_latest = pkg.latest_version(add_pkg) + + pkg.install(add_pkg) + installed_latest = pkg.latest_version(add_pkg) + version = pkg.version(add_pkg) + assert isinstance(uninstalled_latest, str) + assert installed_latest == version -def test_refresh_db(pkg, setup_teardown_vars): +def test_refresh_db(pkg): """ Integration test to ensure pkg.refresh_db works with brew """ @@ -152,43 +120,27 @@ def test_refresh_db(pkg, setup_teardown_vars): assert refresh_brew -def test_list_upgrades(pkg, add_pkg, setup_teardown_vars): +def test_list_upgrades(pkg, add_pkg): """ Test pkg.list_upgrades: data is in the form {'name1': 'version1', 'name2': 'version2', ... } """ - try: - upgrades = pkg.list_upgrades() - try: - assert isinstance(upgrades, dict) - if upgrades: - for name in upgrades: - assert isinstance(name, str) - assert isinstance(upgrades[name], str) - except AssertionError: - pkg.remove(add_pkg) - raise - except CommandExecutionError: - pkg.remove(add_pkg) - raise + upgrades = pkg.list_upgrades() + assert isinstance(upgrades, dict) + if upgrades: + for name in upgrades: + assert isinstance(name, str) + assert isinstance(upgrades[name], str) -def test_info_installed(pkg, add_pkg, setup_teardown_vars): +def test_info_installed(pkg, add_pkg): """ Test pkg.info_installed: info returned has certain fields used by mac_brew.latest_version """ - try: - pkg.install(add_pkg) - info = pkg.info_installed(add_pkg) - try: - assert add_pkg in info - assert "versions" in info[add_pkg] - assert "revision" in info[add_pkg] - assert "stable" in info[add_pkg]["versions"] - except AssertionError: - pkg.remove(add_pkg) - raise - except CommandExecutionError: - pkg.remove(add_pkg) - raise + pkg.install(add_pkg) + info = pkg.info_installed(add_pkg) + assert add_pkg in info + assert "versions" in info[add_pkg] + assert "revision" in info[add_pkg] + assert "stable" in info[add_pkg]["versions"] diff --git a/tests/pytests/integration/modules/test_mac_assistive.py b/tests/pytests/integration/modules/test_mac_assistive.py index 0fa404029bf1..fbcb01b17a1b 100644 --- a/tests/pytests/integration/modules/test_mac_assistive.py +++ b/tests/pytests/integration/modules/test_mac_assistive.py @@ -17,8 +17,8 @@ def osa_script(): yield "/usr/bin/osascript" -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli, osa_script): +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(salt_call_cli, osa_script): salt_call_cli.run("assistive.install", osa_script, True) try: yield @@ -36,7 +36,7 @@ def setup_teardown_vars(salt_call_cli, osa_script): @pytest.mark.slow_test -def test_install_and_remove(salt_call_cli, osa_script, setup_teardown_vars): +def test_install_and_remove(salt_call_cli, osa_script): """ Tests installing and removing a bundled ID or command to use assistive access. """ @@ -48,7 +48,7 @@ def test_install_and_remove(salt_call_cli, osa_script, setup_teardown_vars): @pytest.mark.slow_test -def test_installed(salt_call_cli, osa_script, setup_teardown_vars): +def test_installed(salt_call_cli, osa_script): """ Tests the True and False return of assistive.installed. """ @@ -63,7 +63,7 @@ def test_installed(salt_call_cli, osa_script, setup_teardown_vars): @pytest.mark.slow_test -def test_enable(salt_call_cli, osa_script, setup_teardown_vars): +def test_enable(salt_call_cli, osa_script): """ Tests setting the enabled status of a bundled ID or command. """ @@ -83,7 +83,7 @@ def test_enable(salt_call_cli, osa_script, setup_teardown_vars): @pytest.mark.slow_test -def test_enabled(salt_call_cli, osa_script, setup_teardown_vars): +def test_enabled(salt_call_cli, osa_script): """ Tests if a bundled ID or command is listed in assistive access returns True. """ diff --git a/tests/pytests/integration/modules/test_mac_desktop.py b/tests/pytests/integration/modules/test_mac_desktop.py index d918b7c74172..e420f50fb15c 100644 --- a/tests/pytests/integration/modules/test_mac_desktop.py +++ b/tests/pytests/integration/modules/test_mac_desktop.py @@ -24,19 +24,20 @@ def test_set_output_volume(salt_call_cli): """ Tests the return of set_output_volume. """ - ret = salt_call_cli.run("desktop.get_output_volume") - current_vol = ret.data - to_set = 10 - if current_vol == str(to_set): - to_set += 2 - ret = salt_call_cli.run("desktop.set_output_volume", str(to_set)) - new_vol = ret.data - ret = salt_call_cli.run("desktop.get_output_volume") - check_vol = ret.data - assert new_vol == check_vol - - # Set volume back to what it was before - salt_call_cli.run("desktop.set_output_volume", current_vol) + try: + ret = salt_call_cli.run("desktop.get_output_volume") + current_vol = ret.data + to_set = 10 + if current_vol == str(to_set): + to_set += 2 + ret = salt_call_cli.run("desktop.set_output_volume", str(to_set)) + new_vol = ret.data + ret = salt_call_cli.run("desktop.get_output_volume") + check_vol = ret.data + assert new_vol == check_vol + finally: + # Set volume back to what it was before + salt_call_cli.run("desktop.set_output_volume", current_vol) def test_screensaver(salt_call_cli): diff --git a/tests/pytests/integration/modules/test_mac_group.py b/tests/pytests/integration/modules/test_mac_group.py index a64d7ae08f2d..02c6ad8be417 100644 --- a/tests/pytests/integration/modules/test_mac_group.py +++ b/tests/pytests/integration/modules/test_mac_group.py @@ -5,8 +5,6 @@ import pytest from saltfactories.utils import random_string -from salt.exceptions import CommandExecutionError - pytestmark = [ pytest.mark.slow_test, pytest.mark.destructive_test, @@ -41,8 +39,8 @@ def rep_user_group(): yield random_string("RS-", lowercase=False) -@pytest.fixture(scope="module") -def setup_teardown_vars(salt_call_cli, add_group, change_group, del_group): +@pytest.fixture(scope="module", autouse=True) +def _setup_teardown_vars(salt_call_cli, add_group, change_group, del_group): try: ret = salt_call_cli.run("grains.item", "kernel") os_grain = ret.data @@ -69,21 +67,17 @@ def setup_teardown_vars(salt_call_cli, add_group, change_group, del_group): salt_call_cli.run("group.delete", change_group) -def test_mac_group_add(salt_call_cli, add_group, setup_teardown_vars): +def test_mac_group_add(salt_call_cli, add_group): """ Tests the add group function """ - try: - salt_call_cli.run("group.add", add_group, 3456) - ret = salt_call_cli.run("group.info", add_group) - group_info = ret.data - assert group_info["name"] == add_group - except CommandExecutionError: - salt_call_cli.run("group.delete", add_group) - raise + salt_call_cli.run("group.add", add_group, 3456) + ret = salt_call_cli.run("group.info", add_group) + group_info = ret.data + assert group_info["name"] == add_group -def test_mac_group_delete(salt_call_cli, del_group, setup_teardown_vars): +def test_mac_group_delete(salt_call_cli, del_group): """ Tests the delete group function """ @@ -98,7 +92,7 @@ def test_mac_group_delete(salt_call_cli, del_group, setup_teardown_vars): assert ret -def test_mac_group_chgid(salt_call_cli, change_group, setup_teardown_vars): +def test_mac_group_chgid(salt_call_cli, change_group): """ Tests changing the group id """ @@ -108,17 +102,13 @@ def test_mac_group_chgid(salt_call_cli, change_group, setup_teardown_vars): salt_call_cli.run("group.delete", change_group) pytest.skip("Failed to create a group to manipulate") - try: - salt_call_cli.run("group.chgid", change_group, 6789) - ret = salt_call_cli.run("group.info", change_group) - group_info = ret.data - assert group_info["gid"] == 6789 - except AssertionError: - salt_call_cli.run("group.delete", change_group) - raise + salt_call_cli.run("group.chgid", change_group, 6789) + ret = salt_call_cli.run("group.info", change_group) + group_info = ret.data + assert group_info["gid"] == 6789 -def test_mac_adduser(salt_call_cli, add_group, add_user, setup_teardown_vars): +def test_mac_adduser(salt_call_cli, add_group, add_user): """ Tests adding user to the group """ @@ -128,17 +118,13 @@ def test_mac_adduser(salt_call_cli, add_group, add_user, setup_teardown_vars): salt_call_cli.run("group.delete", add_group) pytest.skip("Failed to create a group to manipulate") - try: - salt_call_cli.run("group.adduser", add_group, add_user) - ret = salt_call_cli.run("group.info", add_group) - group_info = ret.data - assert add_user == "".join(group_info["members"]) - except AssertionError: - salt_call_cli.run("group.delete", add_group) - raise + salt_call_cli.run("group.adduser", add_group, add_user) + ret = salt_call_cli.run("group.info", add_group) + group_info = ret.data + assert add_user == "".join(group_info["members"]) -def test_mac_deluser(salt_call_cli, add_group, add_user, setup_teardown_vars): +def test_mac_deluser(salt_call_cli, add_group, add_user): """ Test deleting user from a group """ @@ -157,9 +143,7 @@ def test_mac_deluser(salt_call_cli, add_group, add_user, setup_teardown_vars): assert add_user.data not in "".join(group_info["members"]) -def test_mac_members( - salt_call_cli, add_group, add_user, rep_user_group, setup_teardown_vars -): +def test_mac_members(salt_call_cli, add_group, add_user, rep_user_group): """ Test replacing members of a group """ @@ -182,7 +166,7 @@ def test_mac_members( assert add_user not in str(group_info.data["members"]) -def test_mac_getent(salt_call_cli, add_group, add_user, setup_teardown_vars): +def test_mac_getent(salt_call_cli, add_group, add_user): """ Test returning info on all groups """ diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/integration/modules/test_mac_keychain.py index 79d304ddd1de..a19c843bb6fb 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/integration/modules/test_mac_keychain.py @@ -7,7 +7,6 @@ import pytest import salt.utils.versions -from salt.exceptions import CommandExecutionError from tests.support.runtests import RUNTIME_VARS pytestmark = [ @@ -18,7 +17,7 @@ ] -@pytest.fixture(scope="function") +@pytest.fixture(scope="function", autouse=True) def setup_teardown_vars(salt_call_cli, base_env_state_tree_root_dir): cert = os.path.join(RUNTIME_VARS.FILES, "file", "base", "certs", "salttest.p12") cert_alias = "Salt Test" @@ -33,7 +32,7 @@ def setup_teardown_vars(salt_call_cli, base_env_state_tree_root_dir): salt_call_cli.run("keychain.uninstall", cert_alias) -def test_mac_keychain_install(setup_teardown_vars, salt_call_cli): +def test_mac_keychain_install(salt_call_cli): """ Tests that attempts to install a certificate """ @@ -53,7 +52,7 @@ def test_mac_keychain_install(setup_teardown_vars, salt_call_cli): assert cert_alias in certs_list -def test_mac_keychain_uninstall(setup_teardown_vars, salt_call_cli): +def test_mac_keychain_uninstall(salt_call_cli): """ Tests that attempts to uninstall a certificate """ @@ -76,14 +75,11 @@ def test_mac_keychain_uninstall(setup_teardown_vars, salt_call_cli): certs_list = ret.data # check to ensure the cert was uninstalled - try: - assert cert_alias not in str(certs_list) - except CommandExecutionError: - salt_call_cli.run("keychain.uninstall", cert_alias) + assert cert_alias not in str(certs_list) @pytest.mark.skip_if_binaries_missing("openssl") -def test_mac_keychain_get_friendly_name(setup_teardown_vars, salt_call_cli, shell): +def test_mac_keychain_get_friendly_name(salt_call_cli, shell): """ Test that attempts to get friendly name of a cert """ diff --git a/tests/pytests/integration/modules/test_mac_portspkg.py b/tests/pytests/integration/modules/test_mac_portspkg.py index 6fc65aad125c..feb82862c4bc 100644 --- a/tests/pytests/integration/modules/test_mac_portspkg.py +++ b/tests/pytests/integration/modules/test_mac_portspkg.py @@ -13,8 +13,8 @@ ] -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(salt_call_cli): AGREE_INSTALLED = False try: ret = salt_call_cli.run("pkg.list_pkgs") @@ -26,7 +26,7 @@ def setup_teardown_vars(salt_call_cli): salt_call_cli.run("pkg.remove", "agree") -def test_list_pkgs(salt_call_cli, setup_teardown_vars): +def test_list_pkgs(salt_call_cli): """ Test pkg.list_pkgs """ @@ -36,7 +36,7 @@ def test_list_pkgs(salt_call_cli, setup_teardown_vars): assert "agree" in pkg_list_ret.data -def test_latest_version(salt_call_cli, setup_teardown_vars): +def test_latest_version(salt_call_cli): """ Test pkg.latest_version """ @@ -46,7 +46,7 @@ def test_latest_version(salt_call_cli, setup_teardown_vars): assert "agree" in result.data -def test_remove(salt_call_cli, setup_teardown_vars): +def test_remove(salt_call_cli): """ Test pkg.remove """ @@ -57,7 +57,7 @@ def test_remove(salt_call_cli, setup_teardown_vars): @pytest.mark.destructive_test -def test_install(salt_call_cli, setup_teardown_vars): +def test_install(salt_call_cli): """ Test pkg.install """ @@ -67,7 +67,7 @@ def test_install(salt_call_cli, setup_teardown_vars): assert "agree" in installed.data -def test_list_upgrades(salt_call_cli, setup_teardown_vars): +def test_list_upgrades(salt_call_cli): """ Test pkg.list_upgrades """ @@ -75,7 +75,7 @@ def test_list_upgrades(salt_call_cli, setup_teardown_vars): assert isinstance(upgrade.data, dict) -def test_upgrade_available(salt_call_cli, setup_teardown_vars): +def test_upgrade_available(salt_call_cli): """ Test pkg.upgrade_available """ @@ -86,7 +86,7 @@ def test_upgrade_available(salt_call_cli, setup_teardown_vars): assert not upgrade_available.data -def test_refresh_db(salt_call_cli, setup_teardown_vars): +def test_refresh_db(salt_call_cli): """ Test pkg.refresh_db """ @@ -94,7 +94,7 @@ def test_refresh_db(salt_call_cli, setup_teardown_vars): assert refresh.data -def test_upgrade(salt_call_cli, setup_teardown_vars): +def test_upgrade(salt_call_cli): """ Test pkg.upgrade """ diff --git a/tests/pytests/integration/modules/test_mac_power.py b/tests/pytests/integration/modules/test_mac_power.py index 69be4568bdff..4c6149d105c5 100644 --- a/tests/pytests/integration/modules/test_mac_power.py +++ b/tests/pytests/integration/modules/test_mac_power.py @@ -14,20 +14,20 @@ ] -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): - COMPUTER_SLEEP = salt_call_cli.run("power.get_computer_sleep") - DISPLAY_SLEEP = salt_call_cli.run("power.get_display_sleep") - HARD_DISK_SLEEP = salt_call_cli.run("power.get_harddisk_sleep") +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(salt_call_cli): + computer_sleep = salt_call_cli.run("power.get_computer_sleep") + display_sleep = salt_call_cli.run("power.get_display_sleep") + hard_disk_sleep = salt_call_cli.run("power.get_harddisk_sleep") try: yield finally: - salt_call_cli.run("power.set_computer_sleep", COMPUTER_SLEEP) - salt_call_cli.run("power.set_display_sleep", DISPLAY_SLEEP) - salt_call_cli.run("power.set_harddisk_sleep", HARD_DISK_SLEEP) + salt_call_cli.run("power.set_computer_sleep", computer_sleep) + salt_call_cli.run("power.set_display_sleep", display_sleep) + salt_call_cli.run("power.set_harddisk_sleep", hard_disk_sleep) -def test_computer_sleep(salt_call_cli, setup_teardown_vars): +def test_computer_sleep(salt_call_cli): """ Test power.get_computer_sleep Test power.set_computer_sleep @@ -60,7 +60,7 @@ def test_computer_sleep(salt_call_cli, setup_teardown_vars): assert "Invalid Boolean Value for Minutes" in ret.stderr -def test_display_sleep(salt_call_cli, setup_teardown_vars): +def test_display_sleep(salt_call_cli): """ Test power.get_display_sleep Test power.set_display_sleep @@ -93,7 +93,7 @@ def test_display_sleep(salt_call_cli, setup_teardown_vars): assert "Invalid Boolean Value for Minutes" in ret.stderr -def test_harddisk_sleep(salt_call_cli, setup_teardown_vars): +def test_harddisk_sleep(salt_call_cli): """ Test power.get_harddisk_sleep Test power.set_harddisk_sleep @@ -126,7 +126,7 @@ def test_harddisk_sleep(salt_call_cli, setup_teardown_vars): assert "Invalid Boolean Value for Minutes" in ret.stderr -def test_restart_freeze(salt_call_cli, setup_teardown_vars): +def test_restart_freeze(salt_call_cli): """ Test power.get_restart_freeze Test power.set_restart_freeze diff --git a/tests/pytests/integration/modules/test_mac_service.py b/tests/pytests/integration/modules/test_mac_service.py index d57d89dc985e..13e45d5cef1c 100644 --- a/tests/pytests/integration/modules/test_mac_service.py +++ b/tests/pytests/integration/modules/test_mac_service.py @@ -15,46 +15,45 @@ ] -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): +@pytest.fixture(scope="function", autouse=True) +def service_name(salt_call_cli, service_name): - SERVICE_NAME = "com.salt.integration.test" - SERVICE_PATH = "/Library/LaunchDaemons/com.salt.integration.test.plist" + service_name = "com.salt.integration.test" + service_path = "/Library/LaunchDaemons/com.salt.integration.test.plist" service_data = { "KeepAlive": True, - "Label": SERVICE_NAME, + "Label": service_name, "ProgramArguments": ["/bin/sleep", "1000"], "RunAtLoad": True, } - with salt.utils.files.fopen(SERVICE_PATH, "wb") as fp: + with salt.utils.files.fopen(service_path, "wb") as fp: plistlib.dump(service_data, fp) - ret = salt_call_cli.run("service.enable", SERVICE_NAME) - ret = salt_call_cli.run("service.start", SERVICE_NAME) + salt_call_cli.run("service.enable", service_name) + salt_call_cli.run("service.start", service_name) try: - yield SERVICE_NAME + yield service_name finally: - salt_call_cli.run("service.stop", SERVICE_NAME) - salt.utils.files.safe_rm(SERVICE_PATH) + salt_call_cli.run("service.stop", service_name) + salt.utils.files.safe_rm(service_path) -def test_show(salt_call_cli, setup_teardown_vars): +def test_show(salt_call_cli, service_name): """ Test service.show """ - SERVICE_NAME = setup_teardown_vars # Existing Service - service_info = salt_call_cli.run("service.show", SERVICE_NAME) + service_info = salt_call_cli.run("service.show", service_name) assert isinstance(service_info.data, dict) - assert service_info.data["plist"]["Label"] == SERVICE_NAME + assert service_info.data["plist"]["Label"] == service_name # Missing Service ret = salt_call_cli.run("service.show", "spongebob") assert "Service not found" in ret.stderr -def test_launchctl(salt_call_cli): +def test_launchctl(salt_call_cli, service_name): """ Test service.launchctl """ @@ -72,15 +71,14 @@ def test_launchctl(salt_call_cli): assert "Failed to error service" in ret.stderr -def test_list(salt_call_cli, setup_teardown_vars): +def test_list(salt_call_cli, service_name): """ Test service.list """ - SERVICE_NAME = setup_teardown_vars # Expected Functionality ret = salt_call_cli.run("service.list") assert "PID" in ret.data - ret = salt_call_cli.run("service.list", SERVICE_NAME) + ret = salt_call_cli.run("service.list", service_name) assert "{" in ret.data # Service not found @@ -88,70 +86,65 @@ def test_list(salt_call_cli, setup_teardown_vars): assert "Service not found" in ret.stderr -def test_enable(salt_call_cli, setup_teardown_vars): +def test_enable(salt_call_cli, service_name): """ Test service.enable """ - SERVICE_NAME = setup_teardown_vars - ret = salt_call_cli.run("service.enable", SERVICE_NAME) + ret = salt_call_cli.run("service.enable", service_name) assert ret.data ret = salt_call_cli.run("service.enable", "spongebob") assert "Service not found" in ret.stderr -def test_disable(salt_call_cli, setup_teardown_vars): +def test_disable(salt_call_cli, service_name): """ Test service.disable """ - SERVICE_NAME = setup_teardown_vars - ret = salt_call_cli.run("service.disable", SERVICE_NAME) + ret = salt_call_cli.run("service.disable", service_name) assert ret.data ret = salt_call_cli.run("service.disable", "spongebob") assert "Service not found" in ret.stderr -def test_start(salt_call_cli, setup_teardown_vars): +def test_start(salt_call_cli, service_name): """ Test service.start Test service.stop Test service.status """ - SERVICE_NAME = setup_teardown_vars - salt_call_cli.run("service.stop", SERVICE_NAME) - ret = salt_call_cli.run("service.start", SERVICE_NAME) + salt_call_cli.run("service.stop", service_name) + ret = salt_call_cli.run("service.start", service_name) assert ret.data ret = salt_call_cli.run("service.start", "spongebob") assert "Service not found" in ret.stderr -def test_stop(salt_call_cli, setup_teardown_vars): +def test_stop(salt_call_cli, service_name): """ Test service.stop """ - SERVICE_NAME = setup_teardown_vars - ret = salt_call_cli.run("service.stop", SERVICE_NAME) + ret = salt_call_cli.run("service.stop", service_name) assert ret.data ret = salt_call_cli.run("service.stop", "spongebob") assert "Service not found" in ret.stderr -def test_status(salt_call_cli, setup_teardown_vars): +def test_status(salt_call_cli, service_name): """ Test service.status """ - SERVICE_NAME = setup_teardown_vars # A running service - salt_call_cli.run("service.start", SERVICE_NAME) - ret = salt_call_cli.run("service.status", SERVICE_NAME) + salt_call_cli.run("service.start", service_name) + ret = salt_call_cli.run("service.status", service_name) assert ret.data # A stopped service - salt_call_cli.run("service.stop", SERVICE_NAME) - ret = salt_call_cli.run("service.status", SERVICE_NAME) + salt_call_cli.run("service.stop", service_name) + ret = salt_call_cli.run("service.status", service_name) assert not ret.data # Service not found @@ -159,91 +152,84 @@ def test_status(salt_call_cli, setup_teardown_vars): assert not ret.data -def test_available(salt_call_cli, setup_teardown_vars): +def test_available(salt_call_cli, service_name): """ Test service.available """ - SERVICE_NAME = setup_teardown_vars - ret = salt_call_cli.run("service.available", SERVICE_NAME) + ret = salt_call_cli.run("service.available", service_name) assert ret.data ret = salt_call_cli.run("service.available", "spongebob") assert not ret.data -def test_missing(salt_call_cli, setup_teardown_vars): +def test_missing(salt_call_cli, service_name): """ Test service.missing """ - SERVICE_NAME = setup_teardown_vars - ret = salt_call_cli.run("service.missing", SERVICE_NAME) + ret = salt_call_cli.run("service.missing", service_name) assert not ret.data ret = salt_call_cli.run("service.missing", "spongebob") assert ret.data -def test_enabled(salt_call_cli, setup_teardown_vars): +def test_enabled(salt_call_cli, service_name): """ Test service.enabled """ - SERVICE_NAME = setup_teardown_vars - salt_call_cli.run("service.disabled", SERVICE_NAME) - ret = salt_call_cli.run("service.enabled", SERVICE_NAME) + salt_call_cli.run("service.disabled", service_name) + ret = salt_call_cli.run("service.enabled", service_name) assert ret.data ret = salt_call_cli.run("service.enabled", "spongebob") assert "Service not found: spongebob" in ret.stderr -def test_disabled(salt_call_cli, setup_teardown_vars): +def test_disabled(salt_call_cli, service_name): """ Test service.disabled """ - SERVICE_NAME = setup_teardown_vars - salt_call_cli.run("service.enabled", SERVICE_NAME) - salt_call_cli.run("service.start", SERVICE_NAME) + salt_call_cli.run("service.enabled", service_name) + salt_call_cli.run("service.start", service_name) - ret = salt_call_cli.run("service.disabled", SERVICE_NAME) + ret = salt_call_cli.run("service.disabled", service_name) assert not ret.data - ret = salt_call_cli.run("service.disable", SERVICE_NAME) + ret = salt_call_cli.run("service.disable", service_name) assert ret.data - ret = salt_call_cli.run("service.disabled", SERVICE_NAME) + ret = salt_call_cli.run("service.disabled", service_name) assert ret.data - ret = salt_call_cli.run("service.enable", SERVICE_NAME) + ret = salt_call_cli.run("service.enable", service_name) assert ret.data ret = salt_call_cli.run("service.disable", "spongebob") assert "Service not found: spongebob" in ret.stderr -def test_get_all(salt_call_cli, setup_teardown_vars): +def test_get_all(salt_call_cli, service_name): """ Test service.get_all """ - SERVICE_NAME = setup_teardown_vars services = salt_call_cli.run("service.get_all") assert isinstance(services.data, list) - assert SERVICE_NAME in services.data + assert service_name in services.data -def test_get_enabled(salt_call_cli, setup_teardown_vars): +def test_get_enabled(salt_call_cli, service_name): """ Test service.get_enabled """ - SERVICE_NAME = setup_teardown_vars services = salt_call_cli.run("service.get_enabled") assert isinstance(services.data, list) - assert SERVICE_NAME in services.data + assert service_name in services.data -def test_service_laoded(salt_call_cli, setup_teardown_vars): +def test_service_laoded(salt_call_cli, service_name): """ Test service.get_enabled """ - SERVICE_NAME = setup_teardown_vars - ret = salt_call_cli.run("service.loaded", SERVICE_NAME) + ret = salt_call_cli.run("service.loaded", service_name) assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_shadow.py b/tests/pytests/integration/modules/test_mac_shadow.py index 5d5c5dc5b21d..80ffe35d8e5d 100644 --- a/tests/pytests/integration/modules/test_mac_shadow.py +++ b/tests/pytests/integration/modules/test_mac_shadow.py @@ -3,6 +3,7 @@ """ import datetime +import types import pytest from saltfactories.utils import random_string @@ -17,210 +18,175 @@ @pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): - TEST_USER = random_string("RS-", lowercase=False) - NO_USER = random_string("RS-", lowercase=False) +def accounts(): + with pytest.helpers.create_account(create_group=True) as _account: + yield types.SimpleNamespace( + created=_account.username, not_created=random_string("RS-", lowercase=False) + ) - salt_call_cli.run("user.add", TEST_USER) - try: - yield TEST_USER, NO_USER - finally: - salt_call_cli.run("user.delete", TEST_USER) - - -def test_info(salt_call_cli, setup_teardown_vars): +def test_info(salt_call_cli, accounts): """ Test shadow.info """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - ret = salt_call_cli.run("shadow.info", TEST_USER) - assert ret.data["name"] == TEST_USER + ret = salt_call_cli.run("shadow.info", accounts.created) + assert ret.data["name"] == accounts.created # User does not exist - ret = salt_call_cli.run("shadow.info", NO_USER) + ret = salt_call_cli.run("shadow.info", accounts.not_created) assert ret.data["name"] == "" -def test_get_account_created(salt_call_cli, setup_teardown_vars): +def test_get_account_created(salt_call_cli, accounts): """ Test shadow.get_account_created """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - text_date = salt_call_cli.run("shadow.get_account_created", TEST_USER) + text_date = salt_call_cli.run("shadow.get_account_created", accounts.created) assert text_date.data != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) # User does not exist assert ( - salt_call_cli.run("shadow.get_account_created", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.get_account_created", accounts.not_created) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_last_change(salt_call_cli, setup_teardown_vars): +def test_get_last_change(salt_call_cli, accounts): """ Test shadow.get_last_change """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - text_date = salt_call_cli.run("shadow.get_last_change", TEST_USER) + text_date = salt_call_cli.run("shadow.get_last_change", accounts.created) assert text_date != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) # User does not exist assert ( - salt_call_cli.run("shadow.get_last_change", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.get_last_change", accounts.not_created) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_login_failed_last(salt_call_cli, setup_teardown_vars): +def test_get_login_failed_last(salt_call_cli, accounts): """ Test shadow.get_login_failed_last """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - text_date = salt_call_cli.run("shadow.get_login_failed_last", TEST_USER) + text_date = salt_call_cli.run("shadow.get_login_failed_last", accounts.created) assert text_date != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) # User does not exist assert ( - salt_call_cli.run("shadow.get_login_failed_last", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.get_login_failed_last", accounts) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_login_failed_count(salt_call_cli, setup_teardown_vars): +def test_get_login_failed_count(salt_call_cli, accounts): """ Test shadow.get_login_failed_count """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - assert salt_call_cli.run("shadow.get_login_failed_count", TEST_USER) == "0" + assert salt_call_cli.run("shadow.get_login_failed_count", accounts.created) == "0" # User does not exist assert ( - salt_call_cli.run("shadow.get_login_failed_count", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.get_login_failed_count", accounts.not_created) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_set_maxdays(salt_call_cli, setup_teardown_vars): +def test_get_set_maxdays(salt_call_cli, accounts): """ Test shadow.get_maxdays Test shadow.set_maxdays """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - assert salt_call_cli.run("shadow.set_maxdays", TEST_USER, 20) - assert salt_call_cli.run("shadow.get_maxdays", TEST_USER) == 20 + assert salt_call_cli.run("shadow.set_maxdays", accounts.created, 20) + assert salt_call_cli.run("shadow.get_maxdays", accounts.created) == 20 # User does not exist assert ( - salt_call_cli.run("shadow.set_maxdays", NO_USER, 7) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.set_maxdays", accounts.not_created, 7) + == f"ERROR: User not found: {accounts.not_created}" ) assert ( - salt_call_cli.run("shadow.get_maxdays", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.get_maxdays", accounts.not_created) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_set_change(salt_call_cli, setup_teardown_vars): +def test_get_set_change(salt_call_cli, accounts): """ Test shadow.get_change Test shadow.set_change """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - assert salt_call_cli.run("shadow.set_change", TEST_USER, "02/11/2011") - assert salt_call_cli.run("shadow.get_change", TEST_USER) == "02/11/2011" + assert salt_call_cli.run("shadow.set_change", accounts.created, "02/11/2011") + assert salt_call_cli.run("shadow.get_change", accounts.created) == "02/11/2011" # User does not exist assert ( - salt_call_cli.run("shadow.set_change", NO_USER, "02/11/2012") - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.set_change", accounts.not_created, "02/11/2012") + == f"ERROR: User not found: {accounts.not_created}" ) assert ( - salt_call_cli.run("shadow.get_change", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.get_change", accounts.not_created) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_set_expire(salt_call_cli, setup_teardown_vars): +def test_get_set_expire(salt_call_cli, accounts): """ Test shadow.get_expire Test shadow.set_expire """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - assert salt_call_cli.run("shadow.set_expire", TEST_USER, "02/11/2011") - assert salt_call_cli.run("shadow.get_expire", TEST_USER) == "02/11/2011" + assert salt_call_cli.run("shadow.set_expire", accounts.created, "02/11/2011") + assert salt_call_cli.run("shadow.get_expire", accounts.created) == "02/11/2011" # User does not exist assert ( - salt_call_cli.run("shadow.set_expire", NO_USER, "02/11/2012") - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.set_expire", accounts.not_created, "02/11/2012") + == f"ERROR: User not found: {accounts.not_created}" ) assert ( - salt_call_cli.run("shadow.get_expire", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.get_expire", accounts.not_created) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_del_password(salt_call_cli, setup_teardown_vars): +def test_del_password(salt_call_cli, accounts): """ Test shadow.del_password """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - assert salt_call_cli.run("shadow.del_password", TEST_USER) - assert salt_call_cli.run("shadow.info", TEST_USER)["passwd"] == "*" + assert salt_call_cli.run("shadow.del_password", accounts.created) + assert salt_call_cli.run("shadow.info", accounts.created)["passwd"] == "*" # User does not exist assert ( - salt_call_cli.run("shadow.del_password", NO_USER) - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.del_password", accounts.not_created) + == f"ERROR: User not found: {accounts.not_created}" ) -def test_set_password(salt_call_cli, setup_teardown_vars): +def test_set_password(salt_call_cli, accounts): """ Test shadow.set_password """ - TEST_USER = setup_teardown_vars[0] - NO_USER = setup_teardown_vars[1] - # Correct Functionality - assert salt_call_cli.run("shadow.set_password", TEST_USER, "Pa$$W0rd") + assert salt_call_cli.run("shadow.set_password", accounts.created, "Pa$$W0rd") # User does not exist assert ( - salt_call_cli.run("shadow.set_password", NO_USER, "P@SSw0rd") - == f"ERROR: User not found: {NO_USER}" + salt_call_cli.run("shadow.set_password", accounts.not_created, "P@SSw0rd") + == f"ERROR: User not found: {accounts.not_created}" ) diff --git a/tests/pytests/integration/modules/test_mac_softwareupdate.py b/tests/pytests/integration/modules/test_mac_softwareupdate.py index 4198a2be96b0..b70297e9c03f 100644 --- a/tests/pytests/integration/modules/test_mac_softwareupdate.py +++ b/tests/pytests/integration/modules/test_mac_softwareupdate.py @@ -13,8 +13,8 @@ ] -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(salt_call_cli): ret = salt_call_cli.run("softwareupdate.list_ignored") IGNORED_LIST = ret.data @@ -41,7 +41,7 @@ def setup_teardown_vars(salt_call_cli): salt_call_cli.run_function("softwareupdate.set_catalog", CATALOG) -def test_list_available(salt_call_cli, setup_teardown_vars): +def test_list_available(salt_call_cli): """ Test softwareupdate.list_available """ @@ -51,7 +51,7 @@ def test_list_available(salt_call_cli, setup_teardown_vars): assert isinstance(ret.data, dict) -def test_ignore(salt_call_cli, setup_teardown_vars): +def test_ignore(salt_call_cli): """ Test softwareupdate.ignore Test softwareupdate.list_ignored @@ -99,7 +99,7 @@ def test_schedule(salt_call_cli): assert not ret.data -def test_update(salt_call_cli, setup_teardown_vars): +def test_update(salt_call_cli): """ Test softwareupdate.update_all Test softwareupdate.update @@ -122,7 +122,7 @@ def test_update(salt_call_cli, setup_teardown_vars): assert "Update not available" in ret.data -def test_list_downloads(salt_call_cli, setup_teardown_vars): +def test_list_downloads(salt_call_cli): """ Test softwareupdate.list_downloads """ @@ -130,7 +130,7 @@ def test_list_downloads(salt_call_cli, setup_teardown_vars): assert isinstance(ret.data, list) -def test_download(salt_call_cli, setup_teardown_vars): +def test_download(salt_call_cli): """ Test softwareupdate.download @@ -142,7 +142,7 @@ def test_download(salt_call_cli, setup_teardown_vars): assert "Update not available" in ret.data -def test_download_all(salt_call_cli, setup_teardown_vars): +def test_download_all(salt_call_cli): """ Test softwareupdate.download_all """ @@ -150,7 +150,7 @@ def test_download_all(salt_call_cli, setup_teardown_vars): assert isinstance(ret.data, list) -def test_get_set_reset_catalog(salt_call_cli, setup_teardown_vars): +def test_get_set_reset_catalog(salt_call_cli): """ Test softwareupdate.download_all """ diff --git a/tests/pytests/integration/modules/test_mac_system.py b/tests/pytests/integration/modules/test_mac_system.py index 0ee2f8751c98..2cf9078c7308 100644 --- a/tests/pytests/integration/modules/test_mac_system.py +++ b/tests/pytests/integration/modules/test_mac_system.py @@ -20,8 +20,8 @@ ] -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(salt_call_cli): ret = salt_call_cli.run("service.enabled", "com.apple.atrun") ATRUN_ENABLED = ret.data diff --git a/tests/pytests/integration/modules/test_mac_timezone.py b/tests/pytests/integration/modules/test_mac_timezone.py index 23f83bc4a00c..c17070c8365f 100644 --- a/tests/pytests/integration/modules/test_mac_timezone.py +++ b/tests/pytests/integration/modules/test_mac_timezone.py @@ -23,8 +23,8 @@ ] -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(salt_call_cli): USE_NETWORK_TIME = salt_call_cli.run("timezone.get_using_network_time") TIME_SERVER = salt_call_cli.run("timezone.get_time_server") TIME_ZONE = salt_call_cli.run("timezone.get_zone") diff --git a/tests/pytests/integration/modules/test_mac_user.py b/tests/pytests/integration/modules/test_mac_user.py index 9add44141be8..4447cd8450d9 100644 --- a/tests/pytests/integration/modules/test_mac_user.py +++ b/tests/pytests/integration/modules/test_mac_user.py @@ -8,9 +8,6 @@ from saltfactories.utils import random_string import salt.utils.files -from salt.exceptions import CommandExecutionError - -# Create user strings for tests pytestmark = [ pytest.mark.slow_test, @@ -22,11 +19,6 @@ @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli): - ret = salt_call_cli.run("grains.item", "kernel") - os_grain = ret.data - if os_grain["kernel"] not in "Darwin": - pytest.skip("Test not applicable to '{kernel}' kernel".format(**os_grain)) - ADD_USER = random_string("RS-", lowercase=False) DEL_USER = random_string("RS-", lowercase=False) PRIMARY_GROUP_USER = random_string("RS-", lowercase=False) @@ -60,14 +52,10 @@ def test_mac_user_add(salt_call_cli, setup_teardown_vars): """ ADD_USER = setup_teardown_vars[0] - try: - salt_call_cli.run("user.add", ADD_USER) - ret = salt_call_cli.run("user.info", ADD_USER) - user_info = ret.data - assert ADD_USER == user_info["name"] - except CommandExecutionError: - salt_call_cli.run("user.delete", ADD_USER) - raise + salt_call_cli.run("user.add", ADD_USER) + ret = salt_call_cli.run("user.info", ADD_USER) + user_info = ret.data + assert ADD_USER == user_info["name"] @pytest.mark.slow_test @@ -101,17 +89,12 @@ def test_mac_user_primary_group(salt_call_cli, setup_teardown_vars): salt_call_cli.run("user.delete", PRIMARY_GROUP_USER) pytest.skip("Failed to create a user") - try: - # Test mac_user.primary_group - ret = salt_call_cli.run("user.primary_group", PRIMARY_GROUP_USER) - primary_group = ret.data - ret = salt_call_cli.run("user.info", PRIMARY_GROUP_USER) - uid_info = ret.data - assert primary_group in uid_info["groups"] - - except AssertionError: - salt_call_cli.run("user.delete", PRIMARY_GROUP_USER) - raise + # Test mac_user.primary_group + ret = salt_call_cli.run("user.primary_group", PRIMARY_GROUP_USER) + primary_group = ret.data + ret = salt_call_cli.run("user.info", PRIMARY_GROUP_USER) + uid_info = ret.data + assert primary_group in uid_info["groups"] @pytest.mark.slow_test @@ -127,49 +110,44 @@ def test_mac_user_changes(salt_call_cli, setup_teardown_vars): salt_call_cli.run("user.delete", CHANGE_USER) pytest.skip("Failed to create a user") - try: - # Test mac_user.chuid - salt_call_cli.run("user.chuid", CHANGE_USER, 4376) - ret = salt_call_cli.run("user.info", CHANGE_USER) - uid_info = ret.data - assert uid_info["uid"] == 4376 - - # Test mac_user.chgid - salt_call_cli.run("user.chgid", CHANGE_USER, 4376) - ret = salt_call_cli.run("user.info", CHANGE_USER) - gid_info = ret.data - assert gid_info["gid"] == 4376 - - # Test mac.user.chshell - salt_call_cli.run("user.chshell", CHANGE_USER, "/bin/zsh") - ret = salt_call_cli.run("user.info", CHANGE_USER) - shell_info = ret.data - assert shell_info["shell"] == "/bin/zsh" - - # Test mac_user.chhome - salt_call_cli.run("user.chhome", CHANGE_USER, "/Users/foo") - ret = salt_call_cli.run("user.info", CHANGE_USER) - home_info = ret.data - assert home_info["home"] == "/Users/foo" - - # Test mac_user.chfullname - salt_call_cli.run("user.chfullname", CHANGE_USER, "Foo Bar") - ret = salt_call_cli.run("user.info", CHANGE_USER) - fullname_info = ret.data - assert fullname_info["fullname"] == "Foo Bar" - - # Test mac_user.chgroups - ret = salt_call_cli.run("user.info", CHANGE_USER) - pre_info = ret.data["groups"] - expected = pre_info + ["wheel"] - salt_call_cli.run("user.chgroups", CHANGE_USER, "wheel") - ret = salt_call_cli.run("user.info", CHANGE_USER) - groups_info = ret.data - assert groups_info["groups"] == expected - - except AssertionError: - salt_call_cli.run("user.delete", CHANGE_USER) - raise + # Test mac_user.chuid + salt_call_cli.run("user.chuid", CHANGE_USER, 4376) + ret = salt_call_cli.run("user.info", CHANGE_USER) + uid_info = ret.data + assert uid_info["uid"] == 4376 + + # Test mac_user.chgid + salt_call_cli.run("user.chgid", CHANGE_USER, 4376) + ret = salt_call_cli.run("user.info", CHANGE_USER) + gid_info = ret.data + assert gid_info["gid"] == 4376 + + # Test mac.user.chshell + salt_call_cli.run("user.chshell", CHANGE_USER, "/bin/zsh") + ret = salt_call_cli.run("user.info", CHANGE_USER) + shell_info = ret.data + assert shell_info["shell"] == "/bin/zsh" + + # Test mac_user.chhome + salt_call_cli.run("user.chhome", CHANGE_USER, "/Users/foo") + ret = salt_call_cli.run("user.info", CHANGE_USER) + home_info = ret.data + assert home_info["home"] == "/Users/foo" + + # Test mac_user.chfullname + salt_call_cli.run("user.chfullname", CHANGE_USER, "Foo Bar") + ret = salt_call_cli.run("user.info", CHANGE_USER) + fullname_info = ret.data + assert fullname_info["fullname"] == "Foo Bar" + + # Test mac_user.chgroups + ret = salt_call_cli.run("user.info", CHANGE_USER) + pre_info = ret.data["groups"] + expected = pre_info + ["wheel"] + salt_call_cli.run("user.chgroups", CHANGE_USER, "wheel") + ret = salt_call_cli.run("user.info", CHANGE_USER) + groups_info = ret.data + assert groups_info["groups"] == expected @pytest.mark.slow_test diff --git a/tests/pytests/integration/modules/test_mac_xattr.py b/tests/pytests/integration/modules/test_mac_xattr.py index 5ac390f46589..7318ba22b9dd 100644 --- a/tests/pytests/integration/modules/test_mac_xattr.py +++ b/tests/pytests/integration/modules/test_mac_xattr.py @@ -2,8 +2,6 @@ integration tests for mac_xattr """ -import os - import pytest pytestmark = [ @@ -16,16 +14,16 @@ @pytest.fixture(scope="function") def setup_teardown_vars(salt_call_cli, tmp_path): - test_file = str(tmp_path / "xattr_test_file.txt") + test_file = tmp_path / "xattr_test_file.txt" no_file = str(tmp_path / "xattr_no_file.txt") - salt_call_cli.run("file.touch", test_file) + test_file.touch() try: - yield test_file, no_file + yield str(test_file), no_file finally: - if os.path.exists(test_file): - os.remove(test_file) + if test_file.exists(): + test_file.unlink() def test_list_no_xattr(salt_call_cli, setup_teardown_vars): From 47eed7aaf2d3aa089b66e0038f95e98ba6192bf2 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 20 Nov 2023 13:40:28 -0800 Subject: [PATCH 24/37] converting remain Mac integration tests to functional. --- .../modules/test_mac_assistive.py | 72 +++-- .../functional/modules/test_mac_desktop.py | 73 +++++ .../functional/modules/test_mac_group.py | 181 +++++++++++ .../modules/test_mac_keychain.py | 68 ++-- .../functional/modules/test_mac_portspkg.py | 106 ++++++ .../functional/modules/test_mac_power.py | 153 +++++++++ .../test_mac_power_restart_power_failure.py | 50 +++ .../test_mac_power_sleep_on_power_button.py | 49 +++ .../modules/test_mac_power_wake_on_modem.py | 48 +++ .../modules/test_mac_power_wake_on_net.py | 50 +++ .../functional/modules/test_mac_service.py | 238 ++++++++++++++ .../modules/test_mac_shadow.py | 83 ++--- .../modules/test_mac_softwareupdate.py | 178 +++++++++++ .../functional/modules/test_mac_system.py | 302 ++++++++++++++++++ .../functional/modules/test_mac_timezone.py | 225 +++++++++++++ .../modules/test_mac_user.py | 149 ++++----- .../functional/modules/test_mac_xattr.py | 184 +++++++++++ .../integration/modules/test_mac_desktop.py | 68 ---- .../integration/modules/test_mac_group.py | 186 ----------- .../integration/modules/test_mac_portspkg.py | 103 ------ .../integration/modules/test_mac_power.py | 148 --------- .../test_mac_power_restart_power_failure.py | 45 --- .../test_mac_power_sleep_on_power_button.py | 44 --- .../modules/test_mac_power_wake_on_modem.py | 43 --- .../modules/test_mac_power_wake_on_net.py | 45 --- .../integration/modules/test_mac_service.py | 235 -------------- .../modules/test_mac_softwareupdate.py | 176 ---------- .../integration/modules/test_mac_system.py | 298 ----------------- .../integration/modules/test_mac_timezone.py | 225 ------------- .../integration/modules/test_mac_xattr.py | 179 ----------- 30 files changed, 2023 insertions(+), 1981 deletions(-) rename tests/pytests/{integration => functional}/modules/test_mac_assistive.py (50%) create mode 100644 tests/pytests/functional/modules/test_mac_desktop.py create mode 100644 tests/pytests/functional/modules/test_mac_group.py rename tests/pytests/{integration => functional}/modules/test_mac_keychain.py (56%) create mode 100644 tests/pytests/functional/modules/test_mac_portspkg.py create mode 100644 tests/pytests/functional/modules/test_mac_power.py create mode 100644 tests/pytests/functional/modules/test_mac_power_restart_power_failure.py create mode 100644 tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py create mode 100644 tests/pytests/functional/modules/test_mac_power_wake_on_modem.py create mode 100644 tests/pytests/functional/modules/test_mac_power_wake_on_net.py create mode 100644 tests/pytests/functional/modules/test_mac_service.py rename tests/pytests/{integration => functional}/modules/test_mac_shadow.py (54%) create mode 100644 tests/pytests/functional/modules/test_mac_softwareupdate.py create mode 100644 tests/pytests/functional/modules/test_mac_system.py create mode 100644 tests/pytests/functional/modules/test_mac_timezone.py rename tests/pytests/{integration => functional}/modules/test_mac_user.py (52%) create mode 100644 tests/pytests/functional/modules/test_mac_xattr.py delete mode 100644 tests/pytests/integration/modules/test_mac_desktop.py delete mode 100644 tests/pytests/integration/modules/test_mac_group.py delete mode 100644 tests/pytests/integration/modules/test_mac_portspkg.py delete mode 100644 tests/pytests/integration/modules/test_mac_power.py delete mode 100644 tests/pytests/integration/modules/test_mac_power_restart_power_failure.py delete mode 100644 tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py delete mode 100644 tests/pytests/integration/modules/test_mac_power_wake_on_modem.py delete mode 100644 tests/pytests/integration/modules/test_mac_power_wake_on_net.py delete mode 100644 tests/pytests/integration/modules/test_mac_service.py delete mode 100644 tests/pytests/integration/modules/test_mac_softwareupdate.py delete mode 100644 tests/pytests/integration/modules/test_mac_system.py delete mode 100644 tests/pytests/integration/modules/test_mac_timezone.py delete mode 100644 tests/pytests/integration/modules/test_mac_xattr.py diff --git a/tests/pytests/integration/modules/test_mac_assistive.py b/tests/pytests/functional/modules/test_mac_assistive.py similarity index 50% rename from tests/pytests/integration/modules/test_mac_assistive.py rename to tests/pytests/functional/modules/test_mac_assistive.py index fbcb01b17a1b..ffbe703740af 100644 --- a/tests/pytests/integration/modules/test_mac_assistive.py +++ b/tests/pytests/functional/modules/test_mac_assistive.py @@ -12,87 +12,91 @@ ] +@pytest.fixture(scope="module") +def assistive(modules): + return modules.assistive + + @pytest.fixture(scope="function") def osa_script(): yield "/usr/bin/osascript" @pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(salt_call_cli, osa_script): - salt_call_cli.run("assistive.install", osa_script, True) +def _setup_teardown_vars(assistive, osa_script): + assistive.install(osa_script, True) try: yield finally: - ret = salt_call_cli.run("assistive.installed", osa_script) - osa_script_ret = ret.data + osa_script_ret = assistive.installed(osa_script) if osa_script_ret: - salt_call_cli.run("assistive.remove", osa_script) + assistive.remove(osa_script) smile_bundle = "com.smileonmymac.textexpander" - ret = salt_call_cli.run("assistive.installed", smile_bundle) - smile_bundle_present = ret.data + ret = assistive.installed(smile_bundle) + smile_bundle_present = ret if smile_bundle_present: - salt_call_cli.run("assistive.remove", smile_bundle) + assistive.remove(smile_bundle) @pytest.mark.slow_test -def test_install_and_remove(salt_call_cli, osa_script): +def test_install_and_remove(assistive, osa_script): """ Tests installing and removing a bundled ID or command to use assistive access. """ new_bundle = "com.smileonmymac.textexpander" - ret = salt_call_cli.run("assistive.install", new_bundle) - assert ret.data - ret = salt_call_cli.run("assistive.remove", new_bundle) - assert ret.data + ret = assistive.install(new_bundle) + assert ret + ret = assistive.remove(new_bundle) + assert ret @pytest.mark.slow_test -def test_installed(salt_call_cli, osa_script): +def test_installed(assistive, osa_script): """ Tests the True and False return of assistive.installed. """ # OSA script should have been installed in setUp function - ret = salt_call_cli.run("assistive.installed", osa_script) - assert ret.data + ret = assistive.installed(osa_script) + assert ret # Clean up install - salt_call_cli.run("assistive.remove", osa_script) + assistive.remove(osa_script) # Installed should now return False - ret = salt_call_cli.run("assistive.installed", osa_script) - assert not ret.data + ret = assistive.installed(osa_script) + assert not ret @pytest.mark.slow_test -def test_enable(salt_call_cli, osa_script): +def test_enable(assistive, osa_script): """ Tests setting the enabled status of a bundled ID or command. """ # OSA script should have been installed and enabled in setUp function # Now let's disable it, which should return True. - ret = salt_call_cli.run("assistive.enable", osa_script, False) - assert ret.data + ret = assistive.enable(osa_script, False) + assert ret # Double check the script was disabled, as intended. - ret = salt_call_cli.run("assistive.enabled", osa_script) - assert not ret.data + ret = assistive.enabled(osa_script) + assert not ret # Now re-enable - ret = salt_call_cli.run("assistive.enable", osa_script) - assert ret.data + ret = assistive.enable(osa_script) + assert ret # Double check the script was enabled, as intended. - ret = salt_call_cli.run("assistive.enabled", osa_script) - assert ret.data + ret = assistive.enabled(osa_script) + assert ret @pytest.mark.slow_test -def test_enabled(salt_call_cli, osa_script): +def test_enabled(assistive, osa_script): """ Tests if a bundled ID or command is listed in assistive access returns True. """ # OSA script should have been installed in setUp function, which sets # enabled to True by default. - ret = salt_call_cli.run("assistive.enabled", osa_script) - assert ret.data + ret = assistive.enabled(osa_script) + assert ret # Disable OSA Script - salt_call_cli.run("assistive.enable", osa_script, False) + assistive.enable(osa_script, False) # Assert against new disabled status - ret = salt_call_cli.run("assistive.enabled", osa_script) - assert not ret.data + ret = assistive.enabled(osa_script) + assert not ret diff --git a/tests/pytests/functional/modules/test_mac_desktop.py b/tests/pytests/functional/modules/test_mac_desktop.py new file mode 100644 index 000000000000..432b9c5708d9 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_desktop.py @@ -0,0 +1,73 @@ +""" +Integration tests for the mac_desktop execution module. +""" + +import pytest + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def desktop(modules): + return modules.desktop + + +def test_get_output_volume(desktop): + """ + Tests the return of get_output_volume. + """ + ret = desktop.get_output_volume() + assert ret is not None + + +def test_set_output_volume(desktop): + """ + Tests the return of set_output_volume. + """ + try: + ret = desktop.get_output_volume() + current_vol = ret + to_set = 10 + if current_vol == str(to_set): + to_set += 2 + ret = desktop.set_output_volume(str(to_set)) + new_vol = ret + ret = desktop.get_output_volume() + check_vol = ret + assert new_vol == check_vol + finally: + # Set volume back to what it was before + desktop.set_output_volume(current_vol) + + +def test_screensaver(desktop): + """ + Tests the return of the screensaver function. + """ + ret = desktop.screensaver() + if "does not exist" in ret: + pytest.skip("Skipping. Screensaver unavailable.") + assert ret + + +def test_lock(desktop): + """ + Tests the return of the lock function. + """ + ret = desktop.lock() + if "Unable to run" in ret: + pytest.skip("Skipping. Unable to lock screen.") + assert ret + + +def test_say(desktop): + """ + Tests the return of the say function. + """ + ret = desktop.say("hello", "world") + assert ret diff --git a/tests/pytests/functional/modules/test_mac_group.py b/tests/pytests/functional/modules/test_mac_group.py new file mode 100644 index 000000000000..291313942b98 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_group.py @@ -0,0 +1,181 @@ +""" + :codeauthor: Nicole Thomas +""" + +import pytest +from saltfactories.utils import random_string + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def group(modules): + return modules.group + + +# Create group name strings for tests +@pytest.fixture(scope="module") +def add_group(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def del_group(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def change_group(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def add_user(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module") +def rep_user_group(): + yield random_string("RS-", lowercase=False) + + +@pytest.fixture(scope="module", autouse=True) +def _setup_teardown_vars(group, add_group, change_group, del_group): + try: + yield + finally: + # Delete ADD_GROUP + add_info = group.info(add_group) + if add_info: + group.delete(add_group) + + # Delete DEL_GROUP if something failed + del_info = group.info(del_group) + if del_info: + group.delete(del_group) + + # Delete CHANGE_GROUP + change_info = group.info(change_group) + if change_info: + group.delete(change_group) + + +def test_mac_group_add(group, add_group): + """ + Tests the add group function + """ + group.add(add_group, 3456) + group_info = group.info(add_group) + assert group_info["name"] == add_group + + +def test_mac_group_delete(group, del_group): + """ + Tests the delete group function + """ + # Create a group to delete - If unsuccessful, skip the test + group_add_ret = group.add(del_group, 4567) + if group_add_ret is not True: + group.delete(del_group) + pytest.skip("Failed to create a group to delete") + + # Now try to delete the added group + ret = group.delete(del_group) + assert ret + + +def test_mac_group_chgid(group, change_group): + """ + Tests changing the group id + """ + # Create a group to delete - If unsuccessful, skip the test + ret = group.add(change_group, 5678) + if ret is not True: + group.delete(change_group) + pytest.skip("Failed to create a group to manipulate") + + group.chgid(change_group, 6789) + group_info = group.info(change_group) + assert group_info["gid"] == 6789 + + +def test_mac_adduser(group, add_group, add_user): + """ + Tests adding user to the group + """ + # Create a group to use for test - If unsuccessful, skip the test + ret = group.add(add_group, 5678) + if ret is not True: + group.delete(add_group) + pytest.skip("Failed to create a group to manipulate") + + group.adduser(add_group, add_user) + group_info = group.info(add_group) + assert add_user == "".join(group_info["members"]) + + +def test_mac_deluser(group, add_group, add_user): + """ + Test deleting user from a group + """ + # Create a group to use for test - If unsuccessful, skip the test + group_add_ret = group.add(add_group, 5678) + user_add_ret = group.adduser(add_group, add_user) + + if group_add_ret and user_add_ret is not True: + group.delete(add_group) + pytest.skip("Failed to create a group to manipulate") + + delusr = group.deluser(add_group, add_user) + assert delusr.data + + group_info = group.info(add_group) + assert add_user not in "".join(group_info["members"]) + + +def test_mac_members(group, add_group, add_user, rep_user_group): + """ + Test replacing members of a group + """ + group_add_ret = group.add(add_group, 5678) + user_add_ret = group.adduser(add_group, add_user) + + if group_add_ret and user_add_ret is not True: + group.delete(add_group) + pytest.skip( + "Failed to create the {} group or add user {} to group " + "to manipulate".format(add_group, add_user) + ) + + rep_group_mem = group.members(add_group, rep_user_group) + assert rep_group_mem + + # ensure new user is added to group and previous user is removed + group_info = group.info(add_group) + assert rep_user_group in str(group_info["members"]) + assert add_user not in str(group_info["members"]) + + +def test_mac_getent(group, add_group, add_user): + """ + Test returning info on all groups + """ + group_add_ret = group.add(add_group, 5678) + user_add_ret = group.adduser(add_group, add_user) + + if group_add_ret and user_add_ret is not True: + group.delete(add_group) + pytest.skip( + "Failed to create the {} group or add user {} to group " + "to manipulate".format(add_group, add_user) + ) + + getinfo = group.getent() + assert getinfo.data + assert add_group in str(getinfo) + assert add_user in str(getinfo) diff --git a/tests/pytests/integration/modules/test_mac_keychain.py b/tests/pytests/functional/modules/test_mac_keychain.py similarity index 56% rename from tests/pytests/integration/modules/test_mac_keychain.py rename to tests/pytests/functional/modules/test_mac_keychain.py index a19c843bb6fb..c4997d797c67 100644 --- a/tests/pytests/integration/modules/test_mac_keychain.py +++ b/tests/pytests/functional/modules/test_mac_keychain.py @@ -17,8 +17,18 @@ ] +@pytest.fixture(scope="module") +def cmd(modules): + return modules.cmd + + +@pytest.fixture(scope="module") +def keychain(modules): + return modules.keychain + + @pytest.fixture(scope="function", autouse=True) -def setup_teardown_vars(salt_call_cli, base_env_state_tree_root_dir): +def setup_teardown_vars(keychain, base_env_state_tree_root_dir): cert = os.path.join(RUNTIME_VARS.FILES, "file", "base", "certs", "salttest.p12") cert_alias = "Salt Test" passwd = "salttest" @@ -26,13 +36,12 @@ def setup_teardown_vars(salt_call_cli, base_env_state_tree_root_dir): try: yield cert, cert_alias, passwd finally: - ret = salt_call_cli.run("keychain.list_certs") - certs_list = ret.data + certs_list = keychain.list_certs() if cert_alias in certs_list: - salt_call_cli.run("keychain.uninstall", cert_alias) + keychain.uninstall(cert_alias) -def test_mac_keychain_install(salt_call_cli): +def test_mac_keychain_install(keychain, setup_teardown_vars): """ Tests that attempts to install a certificate """ @@ -41,18 +50,16 @@ def test_mac_keychain_install(salt_call_cli): cert_alias = setup_teardown_vars[1] passwd = setup_teardown_vars[2] - ret = salt_call_cli.run("keychain.install", cert, passwd) - install_cert = ret.data + install_cert = keychain.install(cert, passwd) assert install_cert assert install_cert == "1 identity imported." # check to ensure the cert was installed - ret = salt_call_cli.run("keychain.list_certs") - certs_list = ret.data + certs_list = keychain.list_certs() assert cert_alias in certs_list -def test_mac_keychain_uninstall(salt_call_cli): +def test_mac_keychain_uninstall(keychain, setup_teardown_vars): """ Tests that attempts to uninstall a certificate """ @@ -61,25 +68,23 @@ def test_mac_keychain_uninstall(salt_call_cli): cert_alias = setup_teardown_vars[1] passwd = setup_teardown_vars[2] - salt_call_cli.run("keychain.install", cert, passwd) - ret = salt_call_cli.run("keychain.list_certs") - certs_list = ret.data + keychain.install(cert, passwd) + certs_list = keychain.list_certs() if cert_alias not in certs_list: - salt_call_cli.run("keychain.uninstall", cert_alias) + keychain.uninstall(cert_alias) pytest.skip("Failed to install keychain") # uninstall cert - salt_call_cli.run("keychain.uninstall", cert_alias) - ret = salt_call_cli.run("keychain.list_certs") - certs_list = ret.data + keychain.uninstall(cert_alias) + certs_list = keychain.list_certs() # check to ensure the cert was uninstalled assert cert_alias not in str(certs_list) @pytest.mark.skip_if_binaries_missing("openssl") -def test_mac_keychain_get_friendly_name(salt_call_cli, shell): +def test_mac_keychain_get_friendly_name(keychain, shell): """ Test that attempts to get friendly name of a cert """ @@ -87,11 +92,10 @@ def test_mac_keychain_get_friendly_name(salt_call_cli, shell): cert_alias = setup_teardown_vars[1] passwd = setup_teardown_vars[2] - salt_call_cli.run("keychain.install", cert, passwd) - ret = salt_call_cli.run("keychain.list_certs") - certs_list = ret.data + keychain.install(cert, passwd) + certs_list = keychain.list_certs() if cert_alias not in certs_list: - salt_call_cli.run("keychain.uninstall", cert_alias) + keychain.uninstall(cert_alias) pytest.skip("Failed to install keychain") ret = shell.run("openssl", "version") @@ -100,32 +104,26 @@ def test_mac_keychain_get_friendly_name(salt_call_cli, shell): # openssl versions under 3.0.0 do not include legacy flag if salt.utils.versions.compare(ver1=openssl_version, oper="<", ver2="3.0.0"): - ret = salt_call_cli.run( - "keychain.get_friendly_name", cert, passwd, legacy=False - ) + get_name = keychain.get_friendly_name(cert, passwd, legacy=False) else: - ret = salt_call_cli.run("keychain.get_friendly_name", cert, passwd, legacy=True) + get_name = keychain.get_friendly_name(cert, passwd, legacy=True) - get_name = ret.data assert get_name == cert_alias -def test_mac_keychain_get_default_keychain(salt_call_cli): +def test_mac_keychain_get_default_keychain(keychain, cmd, setup_teardown_vars): """ Test that attempts to get the default keychain """ - ret = salt_call_cli.run("keychain.get_default_keychain") - salt_get_keychain = ret.data - ret = salt_call_cli.run("cmd.run", "security default-keychain -d user") - sys_get_keychain = ret.data + sys_get_keychain = keychain.get_default_keychain() + salt_get_keychain = cmd.run("security default-keychain -d user") assert salt_get_keychain == sys_get_keychain -def test_mac_keychain_list_certs(salt_call_cli): +def test_mac_keychain_list_certs(keychain, setup_teardown_vars): """ Test that attempts to list certs """ cert_default = "com.apple.systemdefault" - ret = salt_call_cli.run("keychain.list_certs") - certs = ret.data + certs = keychain.list_certs() assert cert_default in certs diff --git a/tests/pytests/functional/modules/test_mac_portspkg.py b/tests/pytests/functional/modules/test_mac_portspkg.py new file mode 100644 index 000000000000..bfeef1e87fb2 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_portspkg.py @@ -0,0 +1,106 @@ +""" +integration tests for mac_ports +""" + +import pytest + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.skip_if_binaries_missing("port"), +] + + +@pytest.fixture(scope="module") +def pkg(modules): + return modules.pkg + + +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(pkg): + AGREE_INSTALLED = False + try: + ret = pkg.list_pkgs() + AGREE_INSTALLED = "agree" in ret + pkg.refresh_db() + yield + finally: + if AGREE_INSTALLED: + pkg.remove("agree") + + +def test_list_pkgs(pkg): + """ + Test pkg.list_pkgs + """ + pkg.install("agree") + pkg_list_ret = pkg.list_pkgs() + assert isinstance(pkg_list_ret, dict) + assert "agree" in pkg_list_ret + + +def test_latest_version(pkg): + """ + Test pkg.latest_version + """ + pkg.install("agree") + result = pkg.latest_version("agree", refresh=False) + assert isinstance(result, dict) + assert "agree" in result.data + + +def test_remove(pkg): + """ + Test pkg.remove + """ + pkg.install("agree") + removed = pkg.remove("agree") + assert isinstance(removed, dict) + assert "agree" in removed + + +@pytest.mark.destructive_test +def test_install(pkg): + """ + Test pkg.install + """ + pkg.remove("agree") + installed = pkg.install("agree") + assert isinstance(installed, dict) + assert "agree" in installed + + +def test_list_upgrades(pkg): + """ + Test pkg.list_upgrades + """ + upgrade = pkg.list_upgrades(refresh=False) + assert isinstance(upgrade, dict) + + +def test_upgrade_available(pkg): + """ + Test pkg.upgrade_available + """ + pkg.install("agree") + upgrade_available = pkg.upgrade_available("agree", refresh=False) + assert not upgrade_available.data + + +def test_refresh_db(pkg): + """ + Test pkg.refresh_db + """ + refresh = pkg.refresh_db() + assert refresh + + +def test_upgrade(pkg): + """ + Test pkg.upgrade + """ + results = pkg.upgrade(refresh=False) + assert isinstance(results, dict) + assert results.data["result"] diff --git a/tests/pytests/functional/modules/test_mac_power.py b/tests/pytests/functional/modules/test_mac_power.py new file mode 100644 index 000000000000..b61b53d85ea9 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_power.py @@ -0,0 +1,153 @@ +""" +integration tests for mac_power +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def power(modules): + return modules.power + + +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(power): + computer_sleep = power.get_computer_sleep() + display_sleep = power.get_display_sleep() + hard_disk_sleep = power.get_harddisk_sleep() + try: + yield + finally: + power.set_computer_sleep(computer_sleep) + power.set_display_sleep(display_sleep) + power.set_harddisk_sleep(hard_disk_sleep) + + +def test_computer_sleep(power): + """ + Test power.get_computer_sleep + Test power.set_computer_sleep + """ + + # Normal Functionality + ret = power.set_computer_sleep(90) + assert ret + + ret = power.get_computer_sleep() + assert ret == "after 90 minutes" + + ret = power.set_computer_sleep("Off") + assert ret + + ret = power.get_computer_sleep() + assert ret == "Never" + + # Test invalid input + ret = power.set_computer_sleep("spongebob") + assert "Invalid String Value for Minutes" in ret + + ret = power.set_computer_sleep(0) + assert "Invalid Integer Value for Minutes" in ret + + ret = power.set_computer_sleep(181) + assert "Invalid Integer Value for Minutes" in ret + + ret = power.set_computer_sleep(True) + assert "Invalid Boolean Value for Minutes" in ret + + +def test_display_sleep(power): + """ + Test power.get_display_sleep + Test power.set_display_sleep + """ + + # Normal Functionality + ret = power.set_display_sleep(90) + assert ret + + ret = power.get_display_sleep() + assert ret == "after 90 minutes" + + ret = power.set_display_sleep("Off") + assert ret + + ret = power.get_display_sleep() + assert ret == "Never" + + # Test invalid input + ret = power.set_display_sleep("spongebob") + assert "Invalid String Value for Minutes" in ret + + ret = power.set_display_sleep(0) + assert "Invalid Integer Value for Minutes" in ret + + ret = power.set_display_sleep(181) + assert "Invalid Integer Value for Minutes" in ret + + ret = power.set_display_sleep(True) + assert "Invalid Boolean Value for Minutes" in ret + + +def test_harddisk_sleep(power): + """ + Test power.get_harddisk_sleep + Test power.set_harddisk_sleep + """ + + # Normal Functionality + ret = power.set_harddisk_sleep(90) + assert ret + + ret = power.get_harddisk_sleep() + assert ret == "after 90 minutes" + + ret = power.set_harddisk_sleep("Off") + assert ret + + ret = power.get_harddisk_sleep() + assert ret == "Never" + + # Test invalid input + ret = power.set_harddisk_sleep("spongebob") + assert "Invalid String Value for Minutes" in ret + + ret = power.set_harddisk_sleep(0) + assert "Invalid Integer Value for Minutes" in ret + + ret = power.set_harddisk_sleep(181) + assert "Invalid Integer Value for Minutes" in ret + + ret = power.set_harddisk_sleep(True) + assert "Invalid Boolean Value for Minutes" in ret + + +def test_restart_freeze(power): + """ + Test power.get_restart_freeze + Test power.set_restart_freeze + """ + # Normal Functionality + ret = power.set_restart_freeze("on") + assert ret + + ret = power.get_restart_freeze() + assert ret + + # This will return False because mac fails to actually make the change + ret = power.set_restart_freeze("off") + assert not ret + + # Even setting to off returns true, it actually is never set + # This is an apple bug + ret = power.get_restart_freeze() + assert ret diff --git a/tests/pytests/functional/modules/test_mac_power_restart_power_failure.py b/tests/pytests/functional/modules/test_mac_power_restart_power_failure.py new file mode 100644 index 000000000000..1016054e787e --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_power_restart_power_failure.py @@ -0,0 +1,50 @@ +""" +integration tests for mac_power +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def power(modules): + return modules.power + + +def test_restart_power_failure(power): + """ + Test power.get_restart_power_failure + Test power.set_restart_power_failure + """ + RESTART_POWER = None + + ret = power.get_restart_power_failure() + if isinstance(ret, bool): + RESTART_POWER = ret + + # If available on this system, test it + if RESTART_POWER is None: + # Check for not available + ret = power.get_restart_power_failure() + assert "Error" in ret + else: + ret = power.set_restart_power_failure("On") + assert ret + + ret = power.get_restart_power_failure() + assert ret + + ret = power.set_restart_power_failure("Off") + assert ret + + ret = power.get_restart_power_failure() + assert not ret + + power.set_sleep_on_power_button(RESTART_POWER) diff --git a/tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py b/tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py new file mode 100644 index 000000000000..19d2d878977c --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py @@ -0,0 +1,49 @@ +""" +integration tests for mac_power sleep_on_power_button +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def power(modules): + return modules.power + + +def test_sleep_on_power_button(power): + """ + Test power.get_sleep_on_power_button + Test power.set_sleep_on_power_button + """ + SLEEP_ON_BUTTON = None + + ret = power.get_sleep_on_power_button() + if isinstance(ret, bool): + SLEEP_ON_BUTTON = ret + + # If available on this system, test it + if SLEEP_ON_BUTTON is None: + # Check for not available + assert "Error" in ret + else: + ret = power.set_sleep_on_power_button("on") + assert ret + + ret = power.get_sleep_on_power_button() + assert ret + + ret = power.set_sleep_on_power_button("off") + assert ret + + ret = power.get_sleep_on_power_button() + assert not ret + + power.set_sleep_on_power_button(SLEEP_ON_BUTTON) diff --git a/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py b/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py new file mode 100644 index 000000000000..adebe40e2a1b --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py @@ -0,0 +1,48 @@ +""" +integration tests for mac_power wake_on_modem +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.skip_if_binaries_missing("systemsetup"), +] + + +@pytest.fixture(scope="module") +def power(modules): + return modules.power + + +def test_wake_on_modem(power): + """ + Test power.get_wake_on_modem + Test power.set_wake_on_modem + """ + WAKE_ON_MODEM = None + ret = power.get_wake_on_modem() + if isinstance(ret, bool): + WAKE_ON_MODEM = ret + + if WAKE_ON_MODEM is None: + # Check for not available + ret = power.get_wake_on_modem() + assert "Error" in ret + else: + ret = power.set_wake_on_modem("on") + assert ret + + ret = power.get_wake_on_modem() + assert ret + + ret = power.set_wake_on_modem("off") + assert ret + + ret = power.get_wake_on_modem() + assert not ret + + power.set_wake_on_modem(WAKE_ON_MODEM) diff --git a/tests/pytests/functional/modules/test_mac_power_wake_on_net.py b/tests/pytests/functional/modules/test_mac_power_wake_on_net.py new file mode 100644 index 000000000000..dc5f8aa40922 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_power_wake_on_net.py @@ -0,0 +1,50 @@ +""" +integration tests for mac_power wake_on_network +""" + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def power(modules): + return modules.power + + +def test_wake_on_network(power): + """ + Test power.get_wake_on_network + Test power.set_wake_on_network + """ + + WAKE_ON_NET = None + ret = power.get_wake_on_network() + if isinstance(ret, bool): + WAKE_ON_NET = ret + + # If available on this system, test it + if WAKE_ON_NET is None: + # Check for not available + ret = power.get_wake_on_network() + assert "Error" in ret + else: + ret = power.set_wake_on_network("on") + assert ret + + ret = power.get_wake_on_network() + assert ret + + ret = power.set_wake_on_network("off") + assert ret + + ret = power.get_wake_on_network() + assert not ret + + power.set_wake_on_network(WAKE_ON_NET) diff --git a/tests/pytests/functional/modules/test_mac_service.py b/tests/pytests/functional/modules/test_mac_service.py new file mode 100644 index 000000000000..7b26a98351c8 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_service.py @@ -0,0 +1,238 @@ +""" +integration tests for mac_service +""" + +import plistlib + +import pytest + +import salt.utils.files + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.skip_if_binaries_missing("launchctl", "plutil"), + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def service(modules): + return modules.service + + +@pytest.fixture(scope="function", autouse=True) +def service_name(sergice, service_name): + + service_name = "com.salt.integration.test" + service_path = "/Library/LaunchDaemons/com.salt.integration.test.plist" + + service_data = { + "KeepAlive": True, + "Label": service_name, + "ProgramArguments": ["/bin/sleep", "1000"], + "RunAtLoad": True, + } + with salt.utils.files.fopen(service_path, "wb") as fp: + plistlib.dump(service_data, fp) + service.enable(service_name) + service.start(service_name) + + try: + yield service_name + finally: + service.stop(service_name) + salt.utils.files.safe_rm(service_path) + + +def test_show(service, service_name): + """ + Test service.show + """ + # Existing Service + service_info = service.show(service_name) + assert isinstance(service_info, dict) + assert service_info.data["plist"]["Label"] == service_name + + # Missing Service + ret = service.show("spongebob") + assert "Service not found" in ret + + +def test_launchctl(service, service_name): + """ + Test service.launchctl + """ + # Expected Functionality + ret = service.launchctl("error", "bootstrap", 64) + assert ret + + ret = service.launchctl("error", "bootstrap", 64, return_stdout=True) + assert ret == "64: unknown error code" + + # Raise an error + ret = service.launchctl("error", "bootstrap") + assert "Failed to error service" in ret + + +def test_list(service, service_name): + """ + Test service.list + """ + # Expected Functionality + ret = service.list() + assert "PID" in ret + ret = service.list(service_name) + assert "{" in ret + + # Service not found + ret = service.list("spongebob") + assert "Service not found" in ret + + +def test_enable(service, service_name): + """ + Test service.enable + """ + ret = service.enable(service_name) + assert ret + + ret = service.enable("spongebob") + assert "Service not found" in ret + + +def test_disable(service, service_name): + """ + Test service.disable + """ + ret = service.disable(service_name) + assert ret + + ret = service.disable("spongebob") + assert "Service not found" in ret + + +def test_start(service, service_name): + """ + Test service.start + Test service.stop + Test service.status + """ + service.stop(service_name) + ret = service.start(service_name) + assert ret + + ret = service.start("spongebob") + assert "Service not found" in ret + + +def test_stop(service, service_name): + """ + Test service.stop + """ + ret = service.stop(service_name) + assert ret + + ret = service.stop("spongebob") + assert "Service not found" in ret + + +def test_status(service, service_name): + """ + Test service.status + """ + # A running service + service.start(service_name) + ret = service.status(service_name) + assert ret + + # A stopped service + service.stop(service_name) + ret = service.status(service_name) + assert not ret + + # Service not found + ret = service.status("spongebob") + assert not ret + + +def test_available(service, service_name): + """ + Test service.available + """ + ret = service.available(service_name) + assert ret + + ret = service.available("spongebob") + assert not ret + + +def test_missing(service, service_name): + """ + Test service.missing + """ + ret = service.missing(service_name) + assert not ret + + ret = service.missing("spongebob") + assert ret + + +def test_enabled(service, service_name): + """ + Test service.enabled + """ + service.disabled(service_name) + ret = service.enabled(service_name) + assert ret + + ret = service.enabled("spongebob") + assert "Service not found: spongebob" in ret + + +def test_disabled(service, service_name): + """ + Test service.disabled + """ + service.enabled(service_name) + service.start(service_name) + + ret = service.disabled(service_name) + assert not ret + + ret = service.disable(service_name) + assert ret + + ret = service.disabled(service_name) + assert ret + + ret = service.enable(service_name) + assert ret + + ret = service.disable("spongebob") + assert "Service not found: spongebob" in ret + + +def test_get_all(service, service_name): + """ + Test service.get_all + """ + services = service.get_all() + assert isinstance(services, list) + assert service_name in services.data + + +def test_get_enabled(service, service_name): + """ + Test service.get_enabled + """ + services = service.get_enabled() + assert isinstance(services, list) + assert service_name in services.data + + +def test_service_laoded(service, service_name): + """ + Test service.get_enabled + """ + ret = service.loaded(service_name) + assert ret diff --git a/tests/pytests/integration/modules/test_mac_shadow.py b/tests/pytests/functional/modules/test_mac_shadow.py similarity index 54% rename from tests/pytests/integration/modules/test_mac_shadow.py rename to tests/pytests/functional/modules/test_mac_shadow.py index 80ffe35d8e5d..f4c58ce05c81 100644 --- a/tests/pytests/integration/modules/test_mac_shadow.py +++ b/tests/pytests/functional/modules/test_mac_shadow.py @@ -17,6 +17,11 @@ ] +@pytest.fixture(scope="module") +def shadow(modules): + return modules.shadow + + @pytest.fixture(scope="function") def accounts(): with pytest.helpers.create_account(create_group=True) as _account: @@ -25,168 +30,168 @@ def accounts(): ) -def test_info(salt_call_cli, accounts): +def test_info(shadow, accounts): """ Test shadow.info """ # Correct Functionality - ret = salt_call_cli.run("shadow.info", accounts.created) - assert ret.data["name"] == accounts.created + ret = shadow.info(accounts.created) + assert ret["name"] == accounts.created # User does not exist - ret = salt_call_cli.run("shadow.info", accounts.not_created) - assert ret.data["name"] == "" + ret = shadow.info(accounts.not_created) + assert ret["name"] == "" -def test_get_account_created(salt_call_cli, accounts): +def test_get_account_created(shadow, accounts): """ Test shadow.get_account_created """ # Correct Functionality - text_date = salt_call_cli.run("shadow.get_account_created", accounts.created) + text_date = shadow.get_account_created(accounts.created) assert text_date.data != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) # User does not exist assert ( - salt_call_cli.run("shadow.get_account_created", accounts.not_created) + shadow.get_account_created(accounts.not_created) == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_last_change(salt_call_cli, accounts): +def test_get_last_change(shadow, accounts): """ Test shadow.get_last_change """ # Correct Functionality - text_date = salt_call_cli.run("shadow.get_last_change", accounts.created) + text_date = shadow.get_last_change(accounts.created) assert text_date != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) # User does not exist assert ( - salt_call_cli.run("shadow.get_last_change", accounts.not_created) + shadow.get_last_change(accounts.not_created) == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_login_failed_last(salt_call_cli, accounts): +def test_get_login_failed_last(shadow, accounts): """ Test shadow.get_login_failed_last """ # Correct Functionality - text_date = salt_call_cli.run("shadow.get_login_failed_last", accounts.created) + text_date = shadow.get_login_failed_last(accounts.created) assert text_date != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) # User does not exist assert ( - salt_call_cli.run("shadow.get_login_failed_last", accounts) + shadow.get_login_failed_last(accounts) == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_login_failed_count(salt_call_cli, accounts): +def test_get_login_failed_count(shadow, accounts): """ Test shadow.get_login_failed_count """ # Correct Functionality - assert salt_call_cli.run("shadow.get_login_failed_count", accounts.created) == "0" + assert shadow.get_login_failed_count(accounts.created) == "0" # User does not exist assert ( - salt_call_cli.run("shadow.get_login_failed_count", accounts.not_created) + shadow.get_login_failed_count(accounts.not_created) == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_set_maxdays(salt_call_cli, accounts): +def test_get_set_maxdays(shadow, accounts): """ Test shadow.get_maxdays Test shadow.set_maxdays """ # Correct Functionality - assert salt_call_cli.run("shadow.set_maxdays", accounts.created, 20) - assert salt_call_cli.run("shadow.get_maxdays", accounts.created) == 20 + assert shadow.set_maxdays(accounts.created, 20) + assert shadow.get_maxdays(accounts.created) == 20 # User does not exist assert ( - salt_call_cli.run("shadow.set_maxdays", accounts.not_created, 7) + shadow.set_maxdays(accounts.not_created, 7) == f"ERROR: User not found: {accounts.not_created}" ) assert ( - salt_call_cli.run("shadow.get_maxdays", accounts.not_created) + shadow.get_maxdays(accounts.not_created) == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_set_change(salt_call_cli, accounts): +def test_get_set_change(shadow, accounts): """ Test shadow.get_change Test shadow.set_change """ # Correct Functionality - assert salt_call_cli.run("shadow.set_change", accounts.created, "02/11/2011") - assert salt_call_cli.run("shadow.get_change", accounts.created) == "02/11/2011" + assert shadow.set_change(accounts.created, "02/11/2011") + assert shadow.get_change(accounts.created) == "02/11/2011" # User does not exist assert ( - salt_call_cli.run("shadow.set_change", accounts.not_created, "02/11/2012") + shadow.set_change(accounts.not_created, "02/11/2012") == f"ERROR: User not found: {accounts.not_created}" ) assert ( - salt_call_cli.run("shadow.get_change", accounts.not_created) + shadow.get_change(accounts.not_created) == f"ERROR: User not found: {accounts.not_created}" ) -def test_get_set_expire(salt_call_cli, accounts): +def test_get_set_expire(shadow, accounts): """ Test shadow.get_expire Test shadow.set_expire """ # Correct Functionality - assert salt_call_cli.run("shadow.set_expire", accounts.created, "02/11/2011") - assert salt_call_cli.run("shadow.get_expire", accounts.created) == "02/11/2011" + assert shadow.set_expire(accounts.created, "02/11/2011") + assert shadow.get_expire(accounts.created) == "02/11/2011" # User does not exist assert ( - salt_call_cli.run("shadow.set_expire", accounts.not_created, "02/11/2012") + shadow.set_expire(accounts.not_created, "02/11/2012") == f"ERROR: User not found: {accounts.not_created}" ) assert ( - salt_call_cli.run("shadow.get_expire", accounts.not_created) + shadow.get_expire(accounts.not_created) == f"ERROR: User not found: {accounts.not_created}" ) -def test_del_password(salt_call_cli, accounts): +def test_del_password(shadow, accounts): """ Test shadow.del_password """ # Correct Functionality - assert salt_call_cli.run("shadow.del_password", accounts.created) - assert salt_call_cli.run("shadow.info", accounts.created)["passwd"] == "*" + assert shadow.del_password(accounts.created) + assert shadow.info(accounts.created)["passwd"] == "*" # User does not exist assert ( - salt_call_cli.run("shadow.del_password", accounts.not_created) + shadow.del_password(accounts.not_created) == f"ERROR: User not found: {accounts.not_created}" ) -def test_set_password(salt_call_cli, accounts): +def test_set_password(shadow, accounts): """ Test shadow.set_password """ # Correct Functionality - assert salt_call_cli.run("shadow.set_password", accounts.created, "Pa$$W0rd") + assert shadow.set_password(accounts.created, "Pa$$W0rd") # User does not exist assert ( - salt_call_cli.run("shadow.set_password", accounts.not_created, "P@SSw0rd") + shadow.set_password(accounts.not_created, "P@SSw0rd") == f"ERROR: User not found: {accounts.not_created}" ) diff --git a/tests/pytests/functional/modules/test_mac_softwareupdate.py b/tests/pytests/functional/modules/test_mac_softwareupdate.py new file mode 100644 index 000000000000..87c245a532bc --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_softwareupdate.py @@ -0,0 +1,178 @@ +""" +integration tests for mac_softwareupdate +""" + +import pytest + +pytestmark = [ + pytest.mark.slow_test, + pytest.mark.skip_if_binaries_missing("softwareupdate"), + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.skip_initial_gh_actions_failure, +] + + +@pytest.fixture(scope="module") +def softwareupdate(modules): + return modules.softwareupdate + + +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(softwareupdate): + IGNORED_LIST = softwareupdate.list_ignored() + + SCHEDULE = softwareupdate.schedule() + + CATALOG = softwareupdate.get_catalog() + + try: + yield IGNORED_LIST, SCHEDULE, CATALOG + finally: + if IGNORED_LIST: + for item in IGNORED_LIST: + softwareupdate.ignore(item) + else: + softwareupdate.reset_ignored() + + softwareupdate.schedule(SCHEDULE) + + if CATALOG == "Default": + softwareupdate.reset_catalog() + else: + softwareupdate.set_catalog(CATALOG) + + +def test_list_available(softwareupdate): + """ + Test softwareupdate.list_available + """ + # Can't predict what will be returned, so can only test that the return + # is the correct type, dict + ret = softwareupdate.list_available() + assert isinstance(ret, dict) + + +def test_ignore(softwareupdate): + """ + Test softwareupdate.ignore + Test softwareupdate.list_ignored + Test softwareupdate.reset_ignored + """ + # Test reset_ignored + ret = softwareupdate.reset_ignored() + assert ret + + ret = softwareupdate.list_ignored() + assert ret == [] + + # Test ignore + ret = softwareupdate.ignore("spongebob") + assert ret + + ret = softwareupdate.ignore("squidward") + assert ret + + # Test list_ignored and verify ignore + ret = softwareupdate.list_ignored() + assert "spongebob" in ret + + ret = softwareupdate.list_ignored() + assert "squidward" in ret + + +def test_schedule(softwareupdate): + """ + Test softwareupdate.schedule_enable + Test softwareupdate.schedule_enabled + """ + # Test enable + ret = softwareupdate.schedule_enable(True) + assert ret + + ret = softwareupdate.schedule_enabled() + assert ret + + # Test disable in case it was already enabled + ret = softwareupdate.schedule_enable(False) + assert ret + + ret = softwareupdate.schedule_enabled() + assert not ret + + +def test_update(softwareupdate): + """ + Test softwareupdate.update_all + Test softwareupdate.update + Test softwareupdate.update_available + + Need to know the names of updates that are available to properly test + the update functions... + """ + # There's no way to know what the dictionary will contain, so all we can + # check is that the return is a dictionary + ret = softwareupdate.update_all() + assert isinstance(ret, dict) + + # Test update_available + ret = softwareupdate.update_available("spongebob") + assert not ret + + # Test update not available + ret = softwareupdate.update("spongebob") + assert "Update not available" in ret + + +def test_list_downloads(softwareupdate): + """ + Test softwareupdate.list_downloads + """ + ret = softwareupdate.list_downloads() + assert isinstance(ret, list) + + +def test_download(softwareupdate): + """ + Test softwareupdate.download + + Need to know the names of updates that are available to properly test + the download function + """ + # Test update not available + ret = softwareupdate.download("spongebob") + assert "Update not available" in ret + + +def test_download_all(softwareupdate): + """ + Test softwareupdate.download_all + """ + ret = softwareupdate.download_all() + assert isinstance(ret, list) + + +def test_get_set_reset_catalog(softwareupdate): + """ + Test softwareupdate.download_all + """ + # Reset the catalog + ret = softwareupdate.reset_catalog() + assert ret + + ret = softwareupdate.get_catalog() + assert ret == "Default" + + # Test setting and getting the catalog + ret = softwareupdate.set_catalog("spongebob") + assert ret + + ret = softwareupdate.get_catalog() + assert ret == "spongebob" + + # Test reset the catalog + ret = softwareupdate.reset_catalog() + assert ret + + assert softwareupdate.get_catalog() + assert ret == "Default" diff --git a/tests/pytests/functional/modules/test_mac_system.py b/tests/pytests/functional/modules/test_mac_system.py new file mode 100644 index 000000000000..97673a580e9b --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_system.py @@ -0,0 +1,302 @@ +""" +integration tests for mac_system +""" + +import logging + +import pytest +from saltfactories.utils import random_string + +log = logging.getLogger(__name__) + +pytestmark = [ + pytest.mark.flaky(max_runs=10), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, + pytest.mark.usefixtures("salt_sub_minion"), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.skip_initial_gh_actions_failure, +] + + +@pytest.fixture(scope="module") +def service(modules): + return modules.service + + +@pytest.fixture(scope="module") +def system(modules): + return modules.system + + +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(service, system): + ATRUN_ENABLED = service.enabled("com.apple.atrun") + + REMOTE_LOGIN_ENABLED = system.get_remote_login() + + REMOTE_EVENTS_ENABLED = system.get_remote_events() + + SUBNET_NAME = system.get_subnet_name() + + KEYBOARD_DISABLED = system.get_disable_keyboard_on_lock() + + try: + yield + finally: + if not ATRUN_ENABLED: + atrun = "/System/Library/LaunchDaemons/com.apple.atrun.plist" + service.stop(atrun) + + system.set_remote_login(REMOTE_LOGIN_ENABLED) + system.set_remote_events(REMOTE_EVENTS_ENABLED) + system.set_subnet_name(SUBNET_NAME) + system.set_disable_keyboard_on_lock(KEYBOARD_DISABLED) + + +def test_get_set_remote_login(system): + """ + Test system.get_remote_login + Test system.set_remote_login + """ + # Normal Functionality + ret = system.set_remote_login(True) + assert ret + + ret = system.get_remote_login() + assert ret + + ret = system.set_remote_login(False) + assert ret + + ret = system.get_remote_login() + assert not ret + + # Test valid input + ret = system.set_remote_login(True) + assert ret + + ret = system.set_remote_login(False) + assert ret + + ret = system.set_remote_login("yes") + assert ret + + ret = system.set_remote_login("no") + assert ret + + ret = system.set_remote_login("On") + assert ret + + ret = system.set_remote_login("Off") + assert ret + + ret = system.set_remote_login(1) + assert ret + + ret = system.set_remote_login(0) + assert ret + + # Test invalid input + ret = system.set_remote_login("spongebob") + assert "Invalid String Value for Enabled" in ret + + +def test_get_set_remote_events(system): + """ + Test system.get_remote_events + Test system.set_remote_events + """ + # Normal Functionality + ret = system.set_remote_events(True) + assert ret + + ret = system.get_remote_events() + assert ret + + ret = system.set_remote_events(False) + assert ret + + ret = not system.get_remote_events() + assert not ret + + # Test valid input + ret = system.set_remote_events(True) + assert ret + + ret = system.set_remote_events(False) + assert ret + + ret = system.set_remote_events("yes") + assert ret + + ret = system.set_remote_events("no") + assert ret + + ret = system.set_remote_events("On") + assert ret + + ret = system.set_remote_events("Off") + assert ret + + ret = system.set_remote_events(1) + assert ret + + ret = system.set_remote_events(0) + assert ret + + # Test invalid input + ret = system.set_remote_events("spongebob") + assert "Invalid String Value for Enabled" in ret + + +def test_get_set_subnet_name(system): + """ + Test system.get_subnet_name + Test system.set_subnet_name + """ + SET_SUBNET_NAME = random_string("RS-", lowercase=False) + + ret = system.set_subnet_name(SET_SUBNET_NAME) + assert ret + + ret = system.get_subnet_name() + assert ret == SET_SUBNET_NAME + + +def test_get_list_startup_disk(system): + """ + Test system.get_startup_disk + Test system.list_startup_disks + Don't know how to test system.set_startup_disk as there's usually only + one startup disk available on a system + """ + # Test list and get + ret = system.list_startup_disks() + assert isinstance(ret, list) + + startup_disk = system.get_startup_disk() + assert startup_disk in ret + + # Test passing set a bad disk + ret = system.set_startup_disk("spongebob") + assert "Invalid value passed for path." in ret + + +@pytest.mark.skip(reason="Skip this test until mac fixes it.") +def test_get_set_restart_delay(system): + """ + Test system.get_restart_delay + Test system.set_restart_delay + system.set_restart_delay does not work due to an apple bug, see docs + may need to disable this test as we can't control the delay value + """ + # Normal Functionality + ret = system.set_restart_delay(90) + assert ret + + ret = system.get_restart_delay() + assert ret == "90 seconds" + + # Pass set bad value for seconds + ret = system.set_restart_delay(70) + assert "Invalid value passed for seconds." in ret + + +def test_get_set_disable_keyboard_on_lock(system): + """ + Test system.get_disable_keyboard_on_lock + Test system.set_disable_keyboard_on_lock + """ + # Normal Functionality + ret = system.set_disable_keyboard_on_lock(True) + assert ret + + ret = system.get_disable_keyboard_on_lock() + assert ret + + ret = system.set_disable_keyboard_on_lock(False) + assert ret + + ret = system.get_disable_keyboard_on_lock() + assert not ret + + # Test valid input + ret = system.set_disable_keyboard_on_lock(True) + assert ret + + ret = system.set_disable_keyboard_on_lock(False) + assert ret + + ret = system.set_disable_keyboard_on_lock("yes") + assert ret + + ret = system.set_disable_keyboard_on_lock("no") + assert ret + + ret = system.set_disable_keyboard_on_lock("On") + assert ret + + ret = system.set_disable_keyboard_on_lock("Off") + assert ret + + ret = system.set_disable_keyboard_on_lock(1) + assert ret + + ret = system.set_disable_keyboard_on_lock(0) + assert ret + + # Test invalid input + ret = system.set_disable_keyboard_on_lock("spongebob") + assert "Invalid String Value for Enabled" in ret + + +@pytest.mark.skip(reason="Skip this test until mac fixes it.") +def test_get_set_boot_arch(system): + """ + Test system.get_boot_arch + Test system.set_boot_arch + system.set_boot_arch does not work due to an apple bug, see docs + may need to disable this test as we can't set the boot architecture + """ + # Normal Functionality + ret = system.set_boot_arch("i386") + assert ret + + ret = system.get_boot_arch() + assert ret == "i386" + + ret = system.set_boot_arch("default") + assert ret + + ret = system.get_boot_arch() + assert ret == "default" + + # Test invalid input + ret = system.set_boot_arch("spongebob") + assert "Invalid value passed for arch" in ret + + +# A similar test used to be skipped on py3 due to 'hanging', if we see +# something similar again we may want to skip this gain until we +# investigate +# @pytest.mark.skipif(salt.utils.platform.is_darwin() and six.PY3, reason='This test hangs on OS X on Py3. Skipping until #53566 is merged.') +@pytest.mark.destructive_test +def test_get_set_computer_name(system): + """ + Test system.get_computer_name + Test system.set_computer_name + """ + SET_COMPUTER_NAME = random_string("RS-", lowercase=False) + + COMPUTER_NAME = system.get_computer_name() + + log.debug("Set name is %s", SET_COMPUTER_NAME) + ret = system.set_computer_name(SET_COMPUTER_NAME) + assert ret + + ret = system.get_computer_name() + assert ret == SET_COMPUTER_NAME + + system.set_computer_name(COMPUTER_NAME) diff --git a/tests/pytests/functional/modules/test_mac_timezone.py b/tests/pytests/functional/modules/test_mac_timezone.py new file mode 100644 index 000000000000..57708f0c8ca8 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_timezone.py @@ -0,0 +1,225 @@ +""" +Integration tests for mac_timezone + +If using parallels, make sure Time sync is turned off. Otherwise, parallels will +keep changing your date/time settings while the tests are running. To turn off +Time sync do the following: + - Go to actions -> configure + - Select options at the top and 'More Options' on the left + - Set time to 'Do not sync' +""" + +import datetime + +import pytest + +pytestmark = [ + pytest.mark.flaky(max_runs=4), + pytest.mark.skip_if_binaries_missing("systemsetup"), + pytest.mark.slow_test, + pytest.mark.destructive_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def timezone(modules): + return modules.timezone + + +@pytest.fixture(scope="function", autouse=True) +def _setup_teardown_vars(timezone): + USE_NETWORK_TIME = timezone.get_using_network_time() + TIME_SERVER = timezone.get_time_server() + TIME_ZONE = timezone.get_zone() + CURRENT_DATE = timezone.get_date() + CURRENT_TIME = timezone.get_time() + + timezone.set_using_network_time(False) + timezone.set_zone("America/Denver") + + try: + yield + finally: + timezone.set_time_server(TIME_SERVER) + timezone.set_using_network_time(USE_NETWORK_TIME) + timezone.set_zone(TIME_ZONE) + if not USE_NETWORK_TIME: + timezone.set_date(CURRENT_DATE) + timezone.set_time(CURRENT_TIME) + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_date(timezone): + """ + Test timezone.get_date + Test timezone.set_date + """ + # Correct Functionality + ret = timezone.set_date("2/20/2011") + assert ret + ret = timezone.get_date() + assert ret == "2/20/2011" + + # Test bad date format + ret = timezone.set_date("13/12/2014") + assert ( + ret + == "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014" + ) + + +@pytest.mark.slow_test +def test_get_time(timezone): + """ + Test timezone.get_time + """ + text_time = timezone.get_time() + assert text_time != "Invalid Timestamp" + obj_date = datetime.datetime.strptime(text_time, "%H:%M:%S") + assert isinstance(obj_date, datetime.date) + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_set_time(timezone): + """ + Test timezone.set_time + """ + # Correct Functionality + ret = timezone.set_time("3:14") + assert ret + + # Test bad time format + ret = timezone.set_time("3:71") + assert ret == "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_zone(timezone): + """ + Test timezone.get_zone + Test timezone.set_zone + """ + # Correct Functionality + ret = timezone.set_zone("Pacific/Wake") + assert ret + assert ret == "Pacific/Wake" + + # Test bad time zone + ret = timezone.set_zone("spongebob") + assert ret == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_offset(timezone): + """ + Test timezone.get_offset + """ + ret = timezone.set_zone("Pacific/Wake") + assert ret + ret = timezone.get_offset() + assert isinstance(ret, str) + assert ret == "+1200" + + ret = timezone.set_zone("America/Los_Angeles") + assert ret + assert isinstance(ret, str) + assert ret == "-0700" + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_zonecode(timezone): + """ + Test timezone.get_zonecode + Test timezone.set_zonecode + """ + ret = timezone.set_zone("America/Los_Angeles") + assert ret + assert isinstance(ret, str) + assert ret == "PDT" + + ret = timezone.set_zone("Pacific/Wake") + assert ret + assert isinstance(ret, str) + assert ret == "WAKT" + + +@pytest.mark.slow_test +def test_list_zones(timezone): + """ + Test timezone.list_zones + """ + zones = timezone.list_zones() + assert isinstance(zones, list) + assert "America/Denver" in zones + assert "America/Los_Angeles" in zones + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_zone_compare(timezone): + """ + Test timezone.zone_compare + """ + ret = timezone.set_zone("America/Denver") + assert ret + ret = timezone.zone_compare("America/Denver") + assert ret + ret = timezone.zone_compare("Pacific/Wake") + assert not ret + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_using_network_time(timezone): + """ + Test timezone.get_using_network_time + Test timezone.set_using_network_time + """ + ret = timezone.set_using_network_time(True) + assert ret + + ret = timezone.get_using_network_time() + assert ret + + ret = timezone.set_using_network_time(False) + assert ret + + ret = timezone.get_using_network_time() + assert not ret + + +@pytest.mark.skip( + reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", +) +@pytest.mark.destructive_test +def test_get_set_time_server(timezone): + """ + Test timezone.get_time_server + Test timezone.set_time_server + """ + ret = timezone.set_time_server("spongebob.com") + assert ret + + ret = timezone.get_time_server() + assert ret == "spongebob.com" diff --git a/tests/pytests/integration/modules/test_mac_user.py b/tests/pytests/functional/modules/test_mac_user.py similarity index 52% rename from tests/pytests/integration/modules/test_mac_user.py rename to tests/pytests/functional/modules/test_mac_user.py index 4447cd8450d9..42cc0b4fc8d6 100644 --- a/tests/pytests/integration/modules/test_mac_user.py +++ b/tests/pytests/functional/modules/test_mac_user.py @@ -17,8 +17,13 @@ ] +@pytest.fixture(scope="module") +def user(modules): + return modules.user + + @pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli): +def setup_teardown_vars(user): ADD_USER = random_string("RS-", lowercase=False) DEL_USER = random_string("RS-", lowercase=False) PRIMARY_GROUP_USER = random_string("RS-", lowercase=False) @@ -28,145 +33,133 @@ def setup_teardown_vars(salt_call_cli): yield ADD_USER, DEL_USER, PRIMARY_GROUP_USER, CHANGE_USER finally: # Delete ADD_USER - ret = salt_call_cli.run("user.info", ADD_USER) - add_info = ret.data + add_info = user.info(ADD_USER) if add_info: - salt_call_cli.run("user.delete", ADD_USER) + user.delete(ADD_USER) # Delete DEL_USER if something failed - ret = salt_call_cli.run("user.info", DEL_USER) - del_info = ret.data + del_info = user.info(DEL_USER) if del_info: - salt_call_cli.run("user.delete", DEL_USER) + user.delete(DEL_USER) # Delete CHANGE_USER - ret = salt_call_cli.run("user.info", CHANGE_USER) - change_info = ret.data + change_info = user.info(CHANGE_USER) if change_info: - salt_call_cli.run("user.delete", CHANGE_USER) + user.delete(CHANGE_USER) -def test_mac_user_add(salt_call_cli, setup_teardown_vars): +def test_mac_user_add(user, setup_teardown_vars): """ Tests the add function """ ADD_USER = setup_teardown_vars[0] - salt_call_cli.run("user.add", ADD_USER) - ret = salt_call_cli.run("user.info", ADD_USER) - user_info = ret.data + user.add(ADD_USER) + user_info = user.info(ADD_USER) assert ADD_USER == user_info["name"] @pytest.mark.slow_test -def test_mac_user_delete(salt_call_cli, setup_teardown_vars): +def test_mac_user_delete(user, setup_teardown_vars): """ Tests the delete function """ DEL_USER = setup_teardown_vars[1] # Create a user to delete - If unsuccessful, skip the test - ret = salt_call_cli.run("user.add", DEL_USER) - if ret.data is not True: - salt_call_cli.run("user.delete", DEL_USER) + ret = user.add(DEL_USER) + if ret is not True: + user.delete(DEL_USER) pytest.skip("Failed to create a user to delete") # Now try to delete the added user - ret = salt_call_cli.run("user.delete", DEL_USER) - assert ret.data + ret = user.delete(DEL_USER) + assert ret @pytest.mark.slow_test -def test_mac_user_primary_group(salt_call_cli, setup_teardown_vars): +def test_mac_user_primary_group(user, setup_teardown_vars): """ Tests the primary_group function """ PRIMARY_GROUP_USER = setup_teardown_vars[2] # Create a user to test primary group function - ret = salt_call_cli.run("user.add", PRIMARY_GROUP_USER) - if ret.data is not True: - salt_call_cli.run("user.delete", PRIMARY_GROUP_USER) + ret = user.add(PRIMARY_GROUP_USER) + if ret is not True: + user.delete(PRIMARY_GROUP_USER) pytest.skip("Failed to create a user") # Test mac_user.primary_group - ret = salt_call_cli.run("user.primary_group", PRIMARY_GROUP_USER) - primary_group = ret.data - ret = salt_call_cli.run("user.info", PRIMARY_GROUP_USER) - uid_info = ret.data + primary_group = user.primary_group(PRIMARY_GROUP_USER) + uid_info = user.info(PRIMARY_GROUP_USER) assert primary_group in uid_info["groups"] @pytest.mark.slow_test -def test_mac_user_changes(salt_call_cli, setup_teardown_vars): +def test_mac_user_changes(user, setup_teardown_vars): """ Tests mac_user functions that change user properties """ CHANGE_USER = setup_teardown_vars[3] # Create a user to manipulate - if unsuccessful, skip the test - ret = salt_call_cli.run("user.add", CHANGE_USER) - if ret.data is not True: - salt_call_cli.run("user.delete", CHANGE_USER) + ret = user.add(CHANGE_USER) + if ret is not True: + user.delete(CHANGE_USER) pytest.skip("Failed to create a user") # Test mac_user.chuid - salt_call_cli.run("user.chuid", CHANGE_USER, 4376) - ret = salt_call_cli.run("user.info", CHANGE_USER) - uid_info = ret.data + user.chuid(CHANGE_USER, 4376) + uid_info = user.info(CHANGE_USER) assert uid_info["uid"] == 4376 # Test mac_user.chgid - salt_call_cli.run("user.chgid", CHANGE_USER, 4376) - ret = salt_call_cli.run("user.info", CHANGE_USER) - gid_info = ret.data + user.chgid(CHANGE_USER, 4376) + gid_info = user.info(CHANGE_USER) assert gid_info["gid"] == 4376 # Test mac.user.chshell - salt_call_cli.run("user.chshell", CHANGE_USER, "/bin/zsh") - ret = salt_call_cli.run("user.info", CHANGE_USER) - shell_info = ret.data + user.chshell(CHANGE_USER, "/bin/zsh") + shell_info = user.info(CHANGE_USER) assert shell_info["shell"] == "/bin/zsh" # Test mac_user.chhome - salt_call_cli.run("user.chhome", CHANGE_USER, "/Users/foo") - ret = salt_call_cli.run("user.info", CHANGE_USER) - home_info = ret.data + user.chhome(CHANGE_USER, "/Users/foo") + home_info = user.info(CHANGE_USER) assert home_info["home"] == "/Users/foo" # Test mac_user.chfullname - salt_call_cli.run("user.chfullname", CHANGE_USER, "Foo Bar") - ret = salt_call_cli.run("user.info", CHANGE_USER) - fullname_info = ret.data + user.chfullname(CHANGE_USER, "Foo Bar") + fullname_info = user.info(CHANGE_USER) assert fullname_info["fullname"] == "Foo Bar" # Test mac_user.chgroups - ret = salt_call_cli.run("user.info", CHANGE_USER) - pre_info = ret.data["groups"] + ret = user.info(CHANGE_USER) + pre_info = ret["groups"] expected = pre_info + ["wheel"] - salt_call_cli.run("user.chgroups", CHANGE_USER, "wheel") - ret = salt_call_cli.run("user.info", CHANGE_USER) - groups_info = ret.data + user.chgroups(CHANGE_USER, "wheel") + groups_info = user.info(CHANGE_USER) assert groups_info["groups"] == expected @pytest.mark.slow_test -def test_mac_user_enable_auto_login(salt_call_cli): +def test_mac_user_enable_auto_login(user): """ Tests mac_user functions that enable auto login """ # Make sure auto login is disabled before we start - if salt_call_cli.run("user.get_auto_login"): + if user.get_auto_login(): pytest.skip("Auto login already enabled") try: # Does enable return True - ret = salt_call_cli.run("user.enable_auto_login", ["Spongebob", "Squarepants"]) - assert ret.data + ret = user.enable_auto_login("Spongebob", "Squarepants") + assert ret # Did it set the user entry in the plist file - ret = salt_call_cli.run("user.get_auto_login") - assert ret.data == "Spongebob" + ret = user.get_auto_login() + assert ret == "Spongebob" # Did it generate the `/etc/kcpassword` file assert os.path.exists("/etc/kcpassword") @@ -178,11 +171,11 @@ def test_mac_user_enable_auto_login(salt_call_cli): assert test_data == file_data # Does disable return True - ret = salt_call_cli.run("user.disable_auto_login") - assert ret.data + ret = user.disable_auto_login() + assert ret # Does it remove the user entry in the plist file - ret = salt_call_cli.run("user.get_auto_login") + ret = user.get_auto_login() assert not ret # Is the `/etc/kcpassword` file removed @@ -190,51 +183,51 @@ def test_mac_user_enable_auto_login(salt_call_cli): finally: # Make sure auto_login is disabled - ret = salt_call_cli.run("user.disable_auto_login") - assert ret.data + ret = user.disable_auto_login() + assert ret # Make sure autologin is disabled - ret = salt_call_cli.run("user.get_auto_login") - if ret.data: + ret = user.get_auto_login() + if ret: raise Exception("Failed to disable auto login") @pytest.mark.slow_test -def test_mac_user_disable_auto_login(salt_call_cli): +def test_mac_user_disable_auto_login(user): """ Tests mac_user functions that disable auto login """ # Make sure auto login is enabled before we start # Is there an existing setting - if salt_call_cli.run("user.get_auto_login"): + if user.get_auto_login(): pytest.skip("Auto login already enabled") try: # Enable auto login for the test - salt_call_cli.run("user.enable_auto_login", ["Spongebob", "Squarepants"]) + user.enable_auto_login("Spongebob", "Squarepants") # Make sure auto login got set up - ret = salt_call_cli.run("user.get_auto_login") - if not ret.data == "Spongebob": + ret = user.get_auto_login() + if not ret == "Spongebob": raise Exception("Failed to enable auto login") # Does disable return True - ret = salt_call_cli.run("user.disable_auto_login") - assert ret.data + ret = user.disable_auto_login() + assert ret # Does it remove the user entry in the plist file - ret = salt_call_cli.run("user.get_auto_login") - assert not ret.data + ret = user.get_auto_login() + assert not ret # Is the `/etc/kcpassword` file removed assert not os.path.exists("/etc/kcpassword") finally: # Make sure auto login is disabled - ret = salt_call_cli.run("user.disable_auto_login") - assert ret.data + ret = user.disable_auto_login() + assert ret # Make sure auto login is disabled - ret = salt_call_cli.run("user.get_auto_login") - if ret.data: + ret = user.get_auto_login() + if ret: raise Exception("Failed to disable auto login") diff --git a/tests/pytests/functional/modules/test_mac_xattr.py b/tests/pytests/functional/modules/test_mac_xattr.py new file mode 100644 index 000000000000..94f1c87267e3 --- /dev/null +++ b/tests/pytests/functional/modules/test_mac_xattr.py @@ -0,0 +1,184 @@ +""" +integration tests for mac_xattr +""" + +import pytest + +pytestmark = [ + pytest.mark.skip_if_binaries_missing("xattr"), + pytest.mark.slow_test, + pytest.mark.skip_if_not_root, + pytest.mark.skip_unless_on_darwin, +] + + +@pytest.fixture(scope="module") +def xttr(modules): + return modules.xttr + + +@pytest.fixture(scope="function") +def setup_teardown_vars(salt_call_cli, tmp_path): + test_file = tmp_path / "xattr_test_file.txt" + no_file = str(tmp_path / "xattr_no_file.txt") + + test_file.touch() + + try: + yield str(test_file), no_file + finally: + if test_file.exists(): + test_file.unlink() + + +def test_list_no_xattr(xattr, setup_teardown_vars): + """ + Make sure there are no attributes + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + ret = xattr.clear(test_file) + assert ret + + # Test no attributes + ret = xattr.list(test_file) + assert ret == {} + + # Test file not found + ret = xattr.list(no_file) + assert f"File not found: {no_file}" in ret + + +def test_write(xattr, setup_teardown_vars): + """ + Write an attribute + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + ret = xattr.clear(test_file) + assert ret + + # Write some attributes + ret = xattr.write(test_file, "spongebob", "squarepants") + assert ret + + ret = xattr.write(test_file, "squidward", "plankton") + assert ret + + ret = xattr.write(test_file, "crabby", "patty") + assert ret + + # Test that they were actually added + ret = xattr.list(test_file) + assert ret == { + "spongebob": "squarepants", + "squidward": "plankton", + "crabby": "patty", + } + + # Test file not found + ret = xattr.write(no_file, "patrick", "jellyfish") + assert f"File not found: {no_file}" in ret + + +def test_read(xattr, setup_teardown_vars): + """ + Test xattr.read + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + ret = xattr.clear(test_file) + assert ret + + # Write an attribute + ret = xattr.write(test_file, "spongebob", "squarepants") + assert ret + + # Read the attribute + ret = xattr.read(test_file, "spongebob") + assert ret == "squarepants" + + # Test file not found + ret = xattr.read(no_file, "spongebob") + assert f"File not found: {no_file}" in ret + + # Test attribute not found + ret = xattr.read(test_file, "patrick") + assert "Attribute not found: patrick" in ret + + +def test_delete(xattr, setup_teardown_vars): + """ + Test xattr.delete + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + ret = xattr.clear(test_file) + assert ret + + # Write some attributes + ret = xattr.write(test_file, "spongebob", "squarepants") + assert ret + + ret = xattr.write(test_file, "squidward", "plankton") + assert ret + + ret = xattr.write(test_file, "crabby", "patty") + assert ret + + # Delete an attribute + ret = xattr.delete(test_file, "squidward") + assert ret + + # Make sure it was actually deleted + ret = xattr.list(test_file) + assert ret == { + "spongebob": "squarepants", + "crabby": "patty", + } + + # Test file not found + ret = xattr.delete(no_file, "spongebob") + assert f"File not found: {no_file}" in ret + + # Test attribute not found + ret = xattr.delete(test_file, "patrick") + assert "Attribute not found: patrick" in ret + + +def test_clear(xattr, setup_teardown_vars): + """ + Test xattr.clear + """ + test_file = setup_teardown_vars[0] + no_file = setup_teardown_vars[1] + + # Clear existing attributes + ret = xattr.clear(test_file) + assert ret + + # Write some attributes + ret = xattr.write(test_file, "spongebob", "squarepants") + assert ret + + ret = xattr.write(test_file, "squidward", "plankton") + assert ret + + ret = xattr.write(test_file, "crabby", "patty") + assert ret + + # Test Clear + ret = xattr.clear(test_file) + assert ret + + # Test file not found + ret = xattr.clear(no_file) + assert f"File not found: {no_file}" in ret diff --git a/tests/pytests/integration/modules/test_mac_desktop.py b/tests/pytests/integration/modules/test_mac_desktop.py deleted file mode 100644 index e420f50fb15c..000000000000 --- a/tests/pytests/integration/modules/test_mac_desktop.py +++ /dev/null @@ -1,68 +0,0 @@ -""" -Integration tests for the mac_desktop execution module. -""" - -import pytest - -pytestmark = [ - pytest.mark.slow_test, - pytest.mark.destructive_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -def test_get_output_volume(salt_call_cli): - """ - Tests the return of get_output_volume. - """ - ret = salt_call_cli.run("desktop.get_output_volume") - assert ret.data is not None - - -def test_set_output_volume(salt_call_cli): - """ - Tests the return of set_output_volume. - """ - try: - ret = salt_call_cli.run("desktop.get_output_volume") - current_vol = ret.data - to_set = 10 - if current_vol == str(to_set): - to_set += 2 - ret = salt_call_cli.run("desktop.set_output_volume", str(to_set)) - new_vol = ret.data - ret = salt_call_cli.run("desktop.get_output_volume") - check_vol = ret.data - assert new_vol == check_vol - finally: - # Set volume back to what it was before - salt_call_cli.run("desktop.set_output_volume", current_vol) - - -def test_screensaver(salt_call_cli): - """ - Tests the return of the screensaver function. - """ - ret = salt_call_cli.run("desktop.screensaver") - if "does not exist" in ret.stderr: - pytest.skip("Skipping. Screensaver unavailable.") - assert ret.data - - -def test_lock(salt_call_cli): - """ - Tests the return of the lock function. - """ - ret = salt_call_cli.run("desktop.lock") - if "Unable to run" in ret.stderr: - pytest.skip("Skipping. Unable to lock screen.") - assert ret.data - - -def test_say(salt_call_cli): - """ - Tests the return of the say function. - """ - ret = salt_call_cli.run("desktop.say", "hello", "world") - assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_group.py b/tests/pytests/integration/modules/test_mac_group.py deleted file mode 100644 index 02c6ad8be417..000000000000 --- a/tests/pytests/integration/modules/test_mac_group.py +++ /dev/null @@ -1,186 +0,0 @@ -""" - :codeauthor: Nicole Thomas -""" - -import pytest -from saltfactories.utils import random_string - -pytestmark = [ - pytest.mark.slow_test, - pytest.mark.destructive_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -# Create group name strings for tests -@pytest.fixture(scope="module") -def add_group(): - yield random_string("RS-", lowercase=False) - - -@pytest.fixture(scope="module") -def del_group(): - yield random_string("RS-", lowercase=False) - - -@pytest.fixture(scope="module") -def change_group(): - yield random_string("RS-", lowercase=False) - - -@pytest.fixture(scope="module") -def add_user(): - yield random_string("RS-", lowercase=False) - - -@pytest.fixture(scope="module") -def rep_user_group(): - yield random_string("RS-", lowercase=False) - - -@pytest.fixture(scope="module", autouse=True) -def _setup_teardown_vars(salt_call_cli, add_group, change_group, del_group): - try: - ret = salt_call_cli.run("grains.item", "kernel") - os_grain = ret.data - if os_grain["kernel"] not in "Darwin": - pytest.skip("Test not applicable to '{kernel}' kernel".format(**os_grain)) - yield - finally: - # Delete ADD_GROUP - ret = salt_call_cli.run("group.info", add_group) - add_info = ret.data - if add_info: - salt_call_cli.run("group.delete", add_group) - - # Delete DEL_GROUP if something failed - ret = salt_call_cli.run("group.info", del_group) - del_info = ret.data - if del_info: - salt_call_cli.run("group.delete", del_group) - - # Delete CHANGE_GROUP - ret = salt_call_cli.run("group.info", change_group) - change_info = ret.data - if change_info: - salt_call_cli.run("group.delete", change_group) - - -def test_mac_group_add(salt_call_cli, add_group): - """ - Tests the add group function - """ - salt_call_cli.run("group.add", add_group, 3456) - ret = salt_call_cli.run("group.info", add_group) - group_info = ret.data - assert group_info["name"] == add_group - - -def test_mac_group_delete(salt_call_cli, del_group): - """ - Tests the delete group function - """ - # Create a group to delete - If unsuccessful, skip the test - group_add_ret = salt_call_cli.run("group.add", del_group, 4567) - if group_add_ret.data is not True: - salt_call_cli.run("group.delete", del_group) - pytest.skip("Failed to create a group to delete") - - # Now try to delete the added group - ret = salt_call_cli.run("group.delete", del_group) - assert ret - - -def test_mac_group_chgid(salt_call_cli, change_group): - """ - Tests changing the group id - """ - # Create a group to delete - If unsuccessful, skip the test - ret = salt_call_cli.run("group.add", change_group, 5678) - if ret.data is not True: - salt_call_cli.run("group.delete", change_group) - pytest.skip("Failed to create a group to manipulate") - - salt_call_cli.run("group.chgid", change_group, 6789) - ret = salt_call_cli.run("group.info", change_group) - group_info = ret.data - assert group_info["gid"] == 6789 - - -def test_mac_adduser(salt_call_cli, add_group, add_user): - """ - Tests adding user to the group - """ - # Create a group to use for test - If unsuccessful, skip the test - ret = salt_call_cli.run("group.add", add_group, 5678) - if ret.data is not True: - salt_call_cli.run("group.delete", add_group) - pytest.skip("Failed to create a group to manipulate") - - salt_call_cli.run("group.adduser", add_group, add_user) - ret = salt_call_cli.run("group.info", add_group) - group_info = ret.data - assert add_user == "".join(group_info["members"]) - - -def test_mac_deluser(salt_call_cli, add_group, add_user): - """ - Test deleting user from a group - """ - # Create a group to use for test - If unsuccessful, skip the test - group_add_ret = salt_call_cli.run("group.add", add_group, 5678) - user_add_ret = salt_call_cli.run("group.adduser", add_group, add_user) - - if group_add_ret.data and user_add_ret is not True: - salt_call_cli.run("group.delete", add_group) - pytest.skip("Failed to create a group to manipulate") - - delusr = salt_call_cli.run("group.deluser", add_group, add_user) - assert delusr.data - - group_info = salt_call_cli.run("group.info", add_group) - assert add_user.data not in "".join(group_info["members"]) - - -def test_mac_members(salt_call_cli, add_group, add_user, rep_user_group): - """ - Test replacing members of a group - """ - group_add_ret = salt_call_cli.run("group.add", add_group, 5678) - user_add_ret = salt_call_cli.run("group.adduser", add_group, add_user) - - if group_add_ret.data and user_add_ret is not True: - salt_call_cli.run("group.delete", add_group) - pytest.skip( - "Failed to create the {} group or add user {} to group " - "to manipulate".format(add_group, add_user) - ) - - rep_group_mem = salt_call_cli.run("group.members", add_group, rep_user_group) - assert rep_group_mem.data - - # ensure new user is added to group and previous user is removed - group_info = salt_call_cli.run("group.info", [add_group]) - assert rep_user_group.data in str(group_info.data["members"]) - assert add_user not in str(group_info.data["members"]) - - -def test_mac_getent(salt_call_cli, add_group, add_user): - """ - Test returning info on all groups - """ - group_add_ret = salt_call_cli.run("group.add", add_group, 5678) - user_add_ret = salt_call_cli.run("group.adduser", add_group, add_user) - - if group_add_ret.data and user_add_ret is not True: - salt_call_cli.run("group.delete", add_group) - pytest.skip( - "Failed to create the {} group or add user {} to group " - "to manipulate".format(add_group, add_user) - ) - - getinfo = salt_call_cli.run("group.getent") - assert getinfo.data - assert add_group in str(getinfo.data) - assert add_user in str(getinfo.data) diff --git a/tests/pytests/integration/modules/test_mac_portspkg.py b/tests/pytests/integration/modules/test_mac_portspkg.py deleted file mode 100644 index feb82862c4bc..000000000000 --- a/tests/pytests/integration/modules/test_mac_portspkg.py +++ /dev/null @@ -1,103 +0,0 @@ -""" -integration tests for mac_ports -""" - -import pytest - -pytestmark = [ - pytest.mark.slow_test, - pytest.mark.destructive_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, - pytest.mark.skip_if_binaries_missing("port"), -] - - -@pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(salt_call_cli): - AGREE_INSTALLED = False - try: - ret = salt_call_cli.run("pkg.list_pkgs") - AGREE_INSTALLED = "agree" in ret.data - salt_call_cli.run("pkg.refresh_db") - yield - finally: - if AGREE_INSTALLED: - salt_call_cli.run("pkg.remove", "agree") - - -def test_list_pkgs(salt_call_cli): - """ - Test pkg.list_pkgs - """ - salt_call_cli.run("pkg.install", "agree") - pkg_list_ret = salt_call_cli.run("pkg.list_pkgs") - assert isinstance(pkg_list_ret.data, dict) - assert "agree" in pkg_list_ret.data - - -def test_latest_version(salt_call_cli): - """ - Test pkg.latest_version - """ - salt_call_cli.run("pkg.install", "agree") - result = salt_call_cli.run("pkg.latest_version", "agree", refresh=False) - assert isinstance(result.data, dict) - assert "agree" in result.data - - -def test_remove(salt_call_cli): - """ - Test pkg.remove - """ - salt_call_cli.run("pkg.install", "agree") - removed = salt_call_cli.run("pkg.remove", "agree") - assert isinstance(removed.data, dict) - assert "agree" in removed.data - - -@pytest.mark.destructive_test -def test_install(salt_call_cli): - """ - Test pkg.install - """ - salt_call_cli.run("pkg.remove", "agree") - installed = salt_call_cli.run("pkg.install", "agree") - assert isinstance(installed.data, dict) - assert "agree" in installed.data - - -def test_list_upgrades(salt_call_cli): - """ - Test pkg.list_upgrades - """ - upgrade = salt_call_cli.run("pkg.list_upgrades", refresh=False) - assert isinstance(upgrade.data, dict) - - -def test_upgrade_available(salt_call_cli): - """ - Test pkg.upgrade_available - """ - salt_call_cli.run("pkg.install", "agree") - upgrade_available = salt_call_cli.run( - "pkg.upgrade_available", "agree", refresh=False - ) - assert not upgrade_available.data - - -def test_refresh_db(salt_call_cli): - """ - Test pkg.refresh_db - """ - refresh = salt_call_cli.run("pkg.refresh_db") - assert refresh.data - - -def test_upgrade(salt_call_cli): - """ - Test pkg.upgrade - """ - results = salt_call_cli.run("pkg.upgrade", refresh=False) - assert isinstance(results.data, dict) - assert results.data["result"] diff --git a/tests/pytests/integration/modules/test_mac_power.py b/tests/pytests/integration/modules/test_mac_power.py deleted file mode 100644 index 4c6149d105c5..000000000000 --- a/tests/pytests/integration/modules/test_mac_power.py +++ /dev/null @@ -1,148 +0,0 @@ -""" -integration tests for mac_power -""" - -import pytest - -pytestmark = [ - pytest.mark.flaky(max_runs=10), - pytest.mark.skip_if_binaries_missing("systemsetup"), - pytest.mark.slow_test, - pytest.mark.destructive_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -@pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(salt_call_cli): - computer_sleep = salt_call_cli.run("power.get_computer_sleep") - display_sleep = salt_call_cli.run("power.get_display_sleep") - hard_disk_sleep = salt_call_cli.run("power.get_harddisk_sleep") - try: - yield - finally: - salt_call_cli.run("power.set_computer_sleep", computer_sleep) - salt_call_cli.run("power.set_display_sleep", display_sleep) - salt_call_cli.run("power.set_harddisk_sleep", hard_disk_sleep) - - -def test_computer_sleep(salt_call_cli): - """ - Test power.get_computer_sleep - Test power.set_computer_sleep - """ - - # Normal Functionality - ret = salt_call_cli.run("power.set_computer_sleep", 90) - assert ret.data - - ret = salt_call_cli.run("power.get_computer_sleep") - assert ret.data == "after 90 minutes" - - ret = salt_call_cli.run("power.set_computer_sleep", "Off") - assert ret.data - - ret = salt_call_cli.run("power.get_computer_sleep") - assert ret.data == "Never" - - # Test invalid input - ret = salt_call_cli.run("power.set_computer_sleep", "spongebob") - assert "Invalid String Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_computer_sleep", 0) - assert "Invalid Integer Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_computer_sleep", 181) - assert "Invalid Integer Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_computer_sleep", True) - assert "Invalid Boolean Value for Minutes" in ret.stderr - - -def test_display_sleep(salt_call_cli): - """ - Test power.get_display_sleep - Test power.set_display_sleep - """ - - # Normal Functionality - ret = salt_call_cli.run("power.set_display_sleep", 90) - assert ret.data - - ret = salt_call_cli.run("power.get_display_sleep") - assert ret.data == "after 90 minutes" - - ret = salt_call_cli.run("power.set_display_sleep", "Off") - assert ret.data - - ret = salt_call_cli.run("power.get_display_sleep") - assert ret.data == "Never" - - # Test invalid input - ret = salt_call_cli.run("power.set_display_sleep", "spongebob") - assert "Invalid String Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_display_sleep", 0) - assert "Invalid Integer Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_display_sleep", 181) - assert "Invalid Integer Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_display_sleep", True) - assert "Invalid Boolean Value for Minutes" in ret.stderr - - -def test_harddisk_sleep(salt_call_cli): - """ - Test power.get_harddisk_sleep - Test power.set_harddisk_sleep - """ - - # Normal Functionality - ret = salt_call_cli.run("power.set_harddisk_sleep", 90) - assert ret.data - - ret = salt_call_cli.run("power.get_harddisk_sleep") - assert ret.data == "after 90 minutes" - - ret = salt_call_cli.run("power.set_harddisk_sleep", "Off") - assert ret.data - - ret = salt_call_cli.run("power.get_harddisk_sleep") - assert ret.data == "Never" - - # Test invalid input - ret = salt_call_cli.run("power.set_harddisk_sleep", "spongebob") - assert "Invalid String Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_harddisk_sleep", 0) - assert "Invalid Integer Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_harddisk_sleep", 181) - assert "Invalid Integer Value for Minutes" in ret.stderr - - ret = salt_call_cli.run("power.set_harddisk_sleep", True) - assert "Invalid Boolean Value for Minutes" in ret.stderr - - -def test_restart_freeze(salt_call_cli): - """ - Test power.get_restart_freeze - Test power.set_restart_freeze - """ - # Normal Functionality - ret = salt_call_cli.run("power.set_restart_freeze", "on") - assert ret.data - - ret = salt_call_cli.run("power.get_restart_freeze") - assert ret.data - - # This will return False because mac fails to actually make the change - ret = salt_call_cli.run("power.set_restart_freeze", "off") - assert not ret.data - - # Even setting to off returns true, it actually is never set - # This is an apple bug - ret = salt_call_cli.run("power.get_restart_freeze") - assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py b/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py deleted file mode 100644 index aec2d90fd142..000000000000 --- a/tests/pytests/integration/modules/test_mac_power_restart_power_failure.py +++ /dev/null @@ -1,45 +0,0 @@ -""" -integration tests for mac_power -""" - -import pytest - -pytestmark = [ - pytest.mark.flaky(max_runs=10), - pytest.mark.skip_if_binaries_missing("systemsetup"), - pytest.mark.slow_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -def test_restart_power_failure(salt_call_cli): - """ - Test power.get_restart_power_failure - Test power.set_restart_power_failure - """ - RESTART_POWER = None - - ret = salt_call_cli.run("power.get_restart_power_failure") - if isinstance(ret.data, bool): - RESTART_POWER = ret.data - - # If available on this system, test it - if RESTART_POWER is None: - # Check for not available - ret = salt_call_cli.run("power.get_restart_power_failure") - assert "Error" in ret.data - else: - ret = salt_call_cli.run("power.set_restart_power_failure", "On") - assert ret.data - - ret = salt_call_cli.run("power.get_restart_power_failure") - assert ret.data - - ret = salt_call_cli.run("power.set_restart_power_failure", "Off") - assert ret.data - - ret = salt_call_cli.run("power.get_restart_power_failure") - assert not ret.data - - salt_call_cli.run("power.set_sleep_on_power_button", RESTART_POWER) diff --git a/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py b/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py deleted file mode 100644 index 1e6f71b3babb..000000000000 --- a/tests/pytests/integration/modules/test_mac_power_sleep_on_power_button.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -integration tests for mac_power sleep_on_power_button -""" - -import pytest - -pytestmark = [ - pytest.mark.flaky(max_runs=10), - pytest.mark.skip_if_binaries_missing("systemsetup"), - pytest.mark.slow_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -def test_sleep_on_power_button(salt_call_cli): - """ - Test power.get_sleep_on_power_button - Test power.set_sleep_on_power_button - """ - SLEEP_ON_BUTTON = None - - ret = salt_call_cli.run("power.get_sleep_on_power_button") - if isinstance(ret.data, bool): - SLEEP_ON_BUTTON = ret.data - - # If available on this system, test it - if SLEEP_ON_BUTTON is None: - # Check for not available - assert "Error" in ret.stderr - else: - ret = salt_call_cli.run("power.set_sleep_on_power_button", "on") - assert ret.data - - ret = salt_call_cli.run("power.get_sleep_on_power_button") - assert ret.data - - ret = salt_call_cli.run("power.set_sleep_on_power_button", "off") - assert ret.data - - ret = salt_call_cli.run("power.get_sleep_on_power_button") - assert not ret.data - - salt_call_cli.run("power.set_sleep_on_power_button", SLEEP_ON_BUTTON) diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py b/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py deleted file mode 100644 index 1fbb273eb8fc..000000000000 --- a/tests/pytests/integration/modules/test_mac_power_wake_on_modem.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -integration tests for mac_power wake_on_modem -""" - -import pytest - -pytestmark = [ - pytest.mark.flaky(max_runs=10), - pytest.mark.slow_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, - pytest.mark.skip_if_binaries_missing("systemsetup"), -] - - -def test_wake_on_modem(salt_call_cli): - """ - Test power.get_wake_on_modem - Test power.set_wake_on_modem - """ - WAKE_ON_MODEM = None - ret = salt_call_cli.run("power.get_wake_on_modem") - if isinstance(ret.data, bool): - WAKE_ON_MODEM = ret.data - - if WAKE_ON_MODEM is None: - # Check for not available - ret = salt_call_cli.run("power.get_wake_on_modem") - assert "Error" in ret.stderr - else: - ret = salt_call_cli.run("power.set_wake_on_modem", "on") - assert ret.data - - ret = salt_call_cli.run("power.get_wake_on_modem") - assert ret.data - - ret = salt_call_cli.run("power.set_wake_on_modem", "off") - assert ret.data - - ret = salt_call_cli.run("power.get_wake_on_modem") - assert not ret.data - - salt_call_cli.run("power.set_wake_on_modem", WAKE_ON_MODEM) diff --git a/tests/pytests/integration/modules/test_mac_power_wake_on_net.py b/tests/pytests/integration/modules/test_mac_power_wake_on_net.py deleted file mode 100644 index 15b26672c3c7..000000000000 --- a/tests/pytests/integration/modules/test_mac_power_wake_on_net.py +++ /dev/null @@ -1,45 +0,0 @@ -""" -integration tests for mac_power wake_on_network -""" - -import pytest - -pytestmark = [ - pytest.mark.flaky(max_runs=10), - pytest.mark.skip_if_binaries_missing("systemsetup"), - pytest.mark.slow_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -def test_wake_on_network(salt_call_cli): - """ - Test power.get_wake_on_network - Test power.set_wake_on_network - """ - - WAKE_ON_NET = None - ret = salt_call_cli.run("power.get_wake_on_network") - if isinstance(ret.data, bool): - WAKE_ON_NET = ret.data - - # If available on this system, test it - if WAKE_ON_NET is None: - # Check for not available - ret = salt_call_cli.run("power.get_wake_on_network") - assert "Error" in ret.stderr - else: - ret = salt_call_cli.run("power.set_wake_on_network", "on") - assert ret.data - - ret = salt_call_cli.run("power.get_wake_on_network") - assert ret.data - - ret = salt_call_cli.run("power.set_wake_on_network", "off") - assert ret.data - - ret = salt_call_cli.run("power.get_wake_on_network") - assert not ret.data - - salt_call_cli.run("power.set_wake_on_network", WAKE_ON_NET) diff --git a/tests/pytests/integration/modules/test_mac_service.py b/tests/pytests/integration/modules/test_mac_service.py deleted file mode 100644 index 13e45d5cef1c..000000000000 --- a/tests/pytests/integration/modules/test_mac_service.py +++ /dev/null @@ -1,235 +0,0 @@ -""" -integration tests for mac_service -""" - -import plistlib - -import pytest - -import salt.utils.files - -pytestmark = [ - pytest.mark.slow_test, - pytest.mark.skip_if_binaries_missing("launchctl", "plutil"), - pytest.mark.skip_unless_on_darwin, -] - - -@pytest.fixture(scope="function", autouse=True) -def service_name(salt_call_cli, service_name): - - service_name = "com.salt.integration.test" - service_path = "/Library/LaunchDaemons/com.salt.integration.test.plist" - - service_data = { - "KeepAlive": True, - "Label": service_name, - "ProgramArguments": ["/bin/sleep", "1000"], - "RunAtLoad": True, - } - with salt.utils.files.fopen(service_path, "wb") as fp: - plistlib.dump(service_data, fp) - salt_call_cli.run("service.enable", service_name) - salt_call_cli.run("service.start", service_name) - - try: - yield service_name - finally: - salt_call_cli.run("service.stop", service_name) - salt.utils.files.safe_rm(service_path) - - -def test_show(salt_call_cli, service_name): - """ - Test service.show - """ - # Existing Service - service_info = salt_call_cli.run("service.show", service_name) - assert isinstance(service_info.data, dict) - assert service_info.data["plist"]["Label"] == service_name - - # Missing Service - ret = salt_call_cli.run("service.show", "spongebob") - assert "Service not found" in ret.stderr - - -def test_launchctl(salt_call_cli, service_name): - """ - Test service.launchctl - """ - # Expected Functionality - ret = salt_call_cli.run("service.launchctl", "error", "bootstrap", 64) - assert ret.data - - ret = salt_call_cli.run( - "service.launchctl", "error", "bootstrap", 64, return_stdout=True - ) - assert ret.data == "64: unknown error code" - - # Raise an error - ret = salt_call_cli.run("service.launchctl", "error", "bootstrap") - assert "Failed to error service" in ret.stderr - - -def test_list(salt_call_cli, service_name): - """ - Test service.list - """ - # Expected Functionality - ret = salt_call_cli.run("service.list") - assert "PID" in ret.data - ret = salt_call_cli.run("service.list", service_name) - assert "{" in ret.data - - # Service not found - ret = salt_call_cli.run("service.list", "spongebob") - assert "Service not found" in ret.stderr - - -def test_enable(salt_call_cli, service_name): - """ - Test service.enable - """ - ret = salt_call_cli.run("service.enable", service_name) - assert ret.data - - ret = salt_call_cli.run("service.enable", "spongebob") - assert "Service not found" in ret.stderr - - -def test_disable(salt_call_cli, service_name): - """ - Test service.disable - """ - ret = salt_call_cli.run("service.disable", service_name) - assert ret.data - - ret = salt_call_cli.run("service.disable", "spongebob") - assert "Service not found" in ret.stderr - - -def test_start(salt_call_cli, service_name): - """ - Test service.start - Test service.stop - Test service.status - """ - salt_call_cli.run("service.stop", service_name) - ret = salt_call_cli.run("service.start", service_name) - assert ret.data - - ret = salt_call_cli.run("service.start", "spongebob") - assert "Service not found" in ret.stderr - - -def test_stop(salt_call_cli, service_name): - """ - Test service.stop - """ - ret = salt_call_cli.run("service.stop", service_name) - assert ret.data - - ret = salt_call_cli.run("service.stop", "spongebob") - assert "Service not found" in ret.stderr - - -def test_status(salt_call_cli, service_name): - """ - Test service.status - """ - # A running service - salt_call_cli.run("service.start", service_name) - ret = salt_call_cli.run("service.status", service_name) - assert ret.data - - # A stopped service - salt_call_cli.run("service.stop", service_name) - ret = salt_call_cli.run("service.status", service_name) - assert not ret.data - - # Service not found - ret = salt_call_cli.run("service.status", "spongebob") - assert not ret.data - - -def test_available(salt_call_cli, service_name): - """ - Test service.available - """ - ret = salt_call_cli.run("service.available", service_name) - assert ret.data - - ret = salt_call_cli.run("service.available", "spongebob") - assert not ret.data - - -def test_missing(salt_call_cli, service_name): - """ - Test service.missing - """ - ret = salt_call_cli.run("service.missing", service_name) - assert not ret.data - - ret = salt_call_cli.run("service.missing", "spongebob") - assert ret.data - - -def test_enabled(salt_call_cli, service_name): - """ - Test service.enabled - """ - salt_call_cli.run("service.disabled", service_name) - ret = salt_call_cli.run("service.enabled", service_name) - assert ret.data - - ret = salt_call_cli.run("service.enabled", "spongebob") - assert "Service not found: spongebob" in ret.stderr - - -def test_disabled(salt_call_cli, service_name): - """ - Test service.disabled - """ - salt_call_cli.run("service.enabled", service_name) - salt_call_cli.run("service.start", service_name) - - ret = salt_call_cli.run("service.disabled", service_name) - assert not ret.data - - ret = salt_call_cli.run("service.disable", service_name) - assert ret.data - - ret = salt_call_cli.run("service.disabled", service_name) - assert ret.data - - ret = salt_call_cli.run("service.enable", service_name) - assert ret.data - - ret = salt_call_cli.run("service.disable", "spongebob") - assert "Service not found: spongebob" in ret.stderr - - -def test_get_all(salt_call_cli, service_name): - """ - Test service.get_all - """ - services = salt_call_cli.run("service.get_all") - assert isinstance(services.data, list) - assert service_name in services.data - - -def test_get_enabled(salt_call_cli, service_name): - """ - Test service.get_enabled - """ - services = salt_call_cli.run("service.get_enabled") - assert isinstance(services.data, list) - assert service_name in services.data - - -def test_service_laoded(salt_call_cli, service_name): - """ - Test service.get_enabled - """ - ret = salt_call_cli.run("service.loaded", service_name) - assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_softwareupdate.py b/tests/pytests/integration/modules/test_mac_softwareupdate.py deleted file mode 100644 index b70297e9c03f..000000000000 --- a/tests/pytests/integration/modules/test_mac_softwareupdate.py +++ /dev/null @@ -1,176 +0,0 @@ -""" -integration tests for mac_softwareupdate -""" - -import pytest - -pytestmark = [ - pytest.mark.slow_test, - pytest.mark.skip_if_binaries_missing("softwareupdate"), - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, - pytest.mark.skip_initial_gh_actions_failure, -] - - -@pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(salt_call_cli): - ret = salt_call_cli.run("softwareupdate.list_ignored") - IGNORED_LIST = ret.data - - ret = salt_call_cli.run("softwareupdate.schedule") - SCHEDULE = ret.data - - ret = salt_call_cli.run("softwareupdate.get_catalog") - CATALOG = ret.data - - try: - yield IGNORED_LIST, SCHEDULE, CATALOG - finally: - if IGNORED_LIST: - for item in IGNORED_LIST: - salt_call_cli.run_function("softwareupdate.ignore", item) - else: - salt_call_cli.run_function("softwareupdate.reset_ignored") - - salt_call_cli.run_function("softwareupdate.schedule", SCHEDULE) - - if CATALOG == "Default": - salt_call_cli.run_function("softwareupdate.reset_catalog") - else: - salt_call_cli.run_function("softwareupdate.set_catalog", CATALOG) - - -def test_list_available(salt_call_cli): - """ - Test softwareupdate.list_available - """ - # Can't predict what will be returned, so can only test that the return - # is the correct type, dict - ret = salt_call_cli.run("softwareupdate.list_available") - assert isinstance(ret.data, dict) - - -def test_ignore(salt_call_cli): - """ - Test softwareupdate.ignore - Test softwareupdate.list_ignored - Test softwareupdate.reset_ignored - """ - # Test reset_ignored - ret = salt_call_cli.run("softwareupdate.reset_ignored") - assert ret.data - - ret = salt_call_cli.run("softwareupdate.list_ignored") == [] - assert ret.data - - # Test ignore - ret = salt_call_cli.run("softwareupdate.ignore", "spongebob") - assert ret.data - - ret = salt_call_cli.run("softwareupdate.ignore", "squidward") - assert ret.data - - # Test list_ignored and verify ignore - ret = salt_call_cli.run("softwareupdate.list_ignored") - assert "spongebob" in ret.data - - ret = salt_call_cli.run("softwareupdate.list_ignored") - assert "squidward" in ret.data - - -def test_schedule(salt_call_cli): - """ - Test softwareupdate.schedule_enable - Test softwareupdate.schedule_enabled - """ - # Test enable - ret = salt_call_cli.run("softwareupdate.schedule_enable", True) - assert ret.data - - ret = salt_call_cli.run("softwareupdate.schedule_enabled") - assert ret.data - - # Test disable in case it was already enabled - ret = salt_call_cli.run("softwareupdate.schedule_enable", False) - assert ret.data - - ret = salt_call_cli.run("softwareupdate.schedule_enabled") - assert not ret.data - - -def test_update(salt_call_cli): - """ - Test softwareupdate.update_all - Test softwareupdate.update - Test softwareupdate.update_available - - Need to know the names of updates that are available to properly test - the update functions... - """ - # There's no way to know what the dictionary will contain, so all we can - # check is that the return is a dictionary - ret = salt_call_cli.run("softwareupdate.update_all") - assert isinstance(ret, dict) - - # Test update_available - ret = salt_call_cli.run("softwareupdate.update_available", "spongebob") - assert not ret.data - - # Test update not available - ret = salt_call_cli.run("softwareupdate.update", "spongebob") - assert "Update not available" in ret.data - - -def test_list_downloads(salt_call_cli): - """ - Test softwareupdate.list_downloads - """ - ret = salt_call_cli.run("softwareupdate.list_downloads") - assert isinstance(ret.data, list) - - -def test_download(salt_call_cli): - """ - Test softwareupdate.download - - Need to know the names of updates that are available to properly test - the download function - """ - # Test update not available - ret = salt_call_cli.run("softwareupdate.download", ["spongebob"]) - assert "Update not available" in ret.data - - -def test_download_all(salt_call_cli): - """ - Test softwareupdate.download_all - """ - ret = salt_call_cli.run("softwareupdate.download_all") - assert isinstance(ret.data, list) - - -def test_get_set_reset_catalog(salt_call_cli): - """ - Test softwareupdate.download_all - """ - # Reset the catalog - ret = salt_call_cli.run("softwareupdate.reset_catalog") - assert ret.data - - ret = salt_call_cli.run("softwareupdate.get_catalog") - assert ret.data == "Default" - - # Test setting and getting the catalog - ret = salt_call_cli.run("softwareupdate.set_catalog", "spongebob") - assert ret.data - - ret = salt_call_cli.run("softwareupdate.get_catalog") == "spongebob" - assert ret.data - - # Test reset the catalog - ret = salt_call_cli.run("softwareupdate.reset_catalog") - assert ret.data - - assert salt_call_cli.run("softwareupdate.get_catalog") - assert ret.data == "Default" diff --git a/tests/pytests/integration/modules/test_mac_system.py b/tests/pytests/integration/modules/test_mac_system.py deleted file mode 100644 index 2cf9078c7308..000000000000 --- a/tests/pytests/integration/modules/test_mac_system.py +++ /dev/null @@ -1,298 +0,0 @@ -""" -integration tests for mac_system -""" - -import logging - -import pytest -from saltfactories.utils import random_string - -log = logging.getLogger(__name__) - -pytestmark = [ - pytest.mark.flaky(max_runs=10), - pytest.mark.slow_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, - pytest.mark.usefixtures("salt_sub_minion"), - pytest.mark.skip_if_binaries_missing("systemsetup"), - pytest.mark.skip_initial_gh_actions_failure, -] - - -@pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(salt_call_cli): - ret = salt_call_cli.run("service.enabled", "com.apple.atrun") - ATRUN_ENABLED = ret.data - - ret = salt_call_cli.run("system.get_remote_login") - REMOTE_LOGIN_ENABLED = ret.data - - ret = salt_call_cli.run("system.get_remote_events") - REMOTE_EVENTS_ENABLED = ret.data - - ret = salt_call_cli.run("system.get_subnet_name") - SUBNET_NAME = ret.data - - ret = salt_call_cli.run("system.get_disable_keyboard_on_lock") - KEYBOARD_DISABLED = ret.data - - try: - yield - finally: - if not ATRUN_ENABLED: - atrun = "/System/Library/LaunchDaemons/com.apple.atrun.plist" - salt_call_cli.run("service.stop", atrun) - - salt_call_cli.run("system.set_remote_login", REMOTE_LOGIN_ENABLED) - salt_call_cli.run("system.set_remote_events", REMOTE_EVENTS_ENABLED) - salt_call_cli.run("system.set_subnet_name", SUBNET_NAME) - salt_call_cli.run("system.set_disable_keyboard_on_lock", KEYBOARD_DISABLED) - - -def test_get_set_remote_login(salt_call_cli): - """ - Test system.get_remote_login - Test system.set_remote_login - """ - # Normal Functionality - ret = salt_call_cli.run("system.set_remote_login", True) - assert ret.data - - ret = salt_call_cli.run("system.get_remote_login") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", False) - assert ret.data - - ret = salt_call_cli.run("system.get_remote_login") - assert not ret.data - - # Test valid input - ret = salt_call_cli.run("system.set_remote_login", True) - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", False) - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", "yes") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", "no") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", "On") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", "Off") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", 1) - assert ret.data - - ret = salt_call_cli.run("system.set_remote_login", 0) - assert ret.data - - # Test invalid input - ret = salt_call_cli.run("system.set_remote_login", "spongebob") - assert "Invalid String Value for Enabled" in ret.stderr - - -def test_get_set_remote_events(salt_call_cli): - """ - Test system.get_remote_events - Test system.set_remote_events - """ - # Normal Functionality - ret = salt_call_cli.run("system.set_remote_events", True) - assert ret.data - - ret = salt_call_cli.run("system.get_remote_events") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", False) - assert ret.data - - ret = not salt_call_cli.run("system.get_remote_events") - assert not ret.data - - # Test valid input - ret = salt_call_cli.run("system.set_remote_events", True) - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", False) - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", "yes") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", "no") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", "On") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", "Off") - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", 1) - assert ret.data - - ret = salt_call_cli.run("system.set_remote_events", 0) - assert ret.data - - # Test invalid input - ret = salt_call_cli.run("system.set_remote_events", "spongebob") - assert "Invalid String Value for Enabled" in ret.stderr - - -def test_get_set_subnet_name(salt_call_cli): - """ - Test system.get_subnet_name - Test system.set_subnet_name - """ - SET_SUBNET_NAME = random_string("RS-", lowercase=False) - - ret = salt_call_cli.run("system.set_subnet_name", SET_SUBNET_NAME) - assert ret.data - - ret = salt_call_cli.run("system.get_subnet_name") - assert ret.data == SET_SUBNET_NAME - - -def test_get_list_startup_disk(salt_call_cli): - """ - Test system.get_startup_disk - Test system.list_startup_disks - Don't know how to test system.set_startup_disk as there's usually only - one startup disk available on a system - """ - # Test list and get - ret = salt_call_cli.run("system.list_startup_disks") - assert isinstance(ret.data, list) - - startup_disk = salt_call_cli.run("system.get_startup_disk") - assert startup_disk in ret - - # Test passing set a bad disk - ret = salt_call_cli.run("system.set_startup_disk", "spongebob") - assert "Invalid value passed for path." in ret.stderr - - -@pytest.mark.skip(reason="Skip this test until mac fixes it.") -def test_get_set_restart_delay(salt_call_cli): - """ - Test system.get_restart_delay - Test system.set_restart_delay - system.set_restart_delay does not work due to an apple bug, see docs - may need to disable this test as we can't control the delay value - """ - # Normal Functionality - ret = salt_call_cli.run("system.set_restart_delay", 90) - assert ret.data - - ret = salt_call_cli.run("system.get_restart_delay") - assert ret.data == "90 seconds" - - # Pass set bad value for seconds - ret = salt_call_cli.run("system.set_restart_delay", 70) - assert "Invalid value passed for seconds." in ret.stderr - - -def test_get_set_disable_keyboard_on_lock(salt_call_cli): - """ - Test system.get_disable_keyboard_on_lock - Test system.set_disable_keyboard_on_lock - """ - # Normal Functionality - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", True) - assert ret.data - - ret = salt_call_cli.run("system.get_disable_keyboard_on_lock") - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", False) - assert ret.data - - ret = not salt_call_cli.run("system.get_disable_keyboard_on_lock") - assert not ret.data - - # Test valid input - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", True) - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", False) - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "yes") - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "no") - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "On") - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "Off") - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", 1) - assert ret.data - - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", 0) - assert ret.data - - # Test invalid input - ret = salt_call_cli.run("system.set_disable_keyboard_on_lock", "spongebob") - assert "Invalid String Value for Enabled" in ret.stderr - - -@pytest.mark.skip(reason="Skip this test until mac fixes it.") -def test_get_set_boot_arch(salt_call_cli): - """ - Test system.get_boot_arch - Test system.set_boot_arch - system.set_boot_arch does not work due to an apple bug, see docs - may need to disable this test as we can't set the boot architecture - """ - # Normal Functionality - ret = salt_call_cli.run("system.set_boot_arch", "i386") - assert ret.data - - ret = salt_call_cli.run("system.get_boot_arch") == "i386" - assert ret.data - - ret = salt_call_cli.run("system.set_boot_arch", "default") - assert ret.data - - ret = salt_call_cli.run("system.get_boot_arch") == "default" - assert ret.data - - # Test invalid input - ret = salt_call_cli.run("system.set_boot_arch", "spongebob") - assert "Invalid value passed for arch" in ret.stderr - - -# A similar test used to be skipped on py3 due to 'hanging', if we see -# something similar again we may want to skip this gain until we -# investigate -# @pytest.mark.skipif(salt.utils.platform.is_darwin() and six.PY3, reason='This test hangs on OS X on Py3. Skipping until #53566 is merged.') -@pytest.mark.destructive_test -def test_get_set_computer_name(salt_call_cli): - """ - Test system.get_computer_name - Test system.set_computer_name - """ - SET_COMPUTER_NAME = random_string("RS-", lowercase=False) - - ret = salt_call_cli.run("system.get_computer_name") - COMPUTER_NAME = ret.data - - log.debug("Set name is %s", SET_COMPUTER_NAME) - assert salt_call_cli.run("system.set_computer_name", [SET_COMPUTER_NAME]) - assert ret.data - - ret = salt_call_cli.run("system.get_computer_name") - assert ret.data == SET_COMPUTER_NAME - - salt_call_cli.run("system.set_computer_name", COMPUTER_NAME) diff --git a/tests/pytests/integration/modules/test_mac_timezone.py b/tests/pytests/integration/modules/test_mac_timezone.py deleted file mode 100644 index c17070c8365f..000000000000 --- a/tests/pytests/integration/modules/test_mac_timezone.py +++ /dev/null @@ -1,225 +0,0 @@ -""" -Integration tests for mac_timezone - -If using parallels, make sure Time sync is turned off. Otherwise, parallels will -keep changing your date/time settings while the tests are running. To turn off -Time sync do the following: - - Go to actions -> configure - - Select options at the top and 'More Options' on the left - - Set time to 'Do not sync' -""" - -import datetime - -import pytest - -pytestmark = [ - pytest.mark.flaky(max_runs=4), - pytest.mark.skip_if_binaries_missing("systemsetup"), - pytest.mark.slow_test, - pytest.mark.destructive_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -@pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(salt_call_cli): - USE_NETWORK_TIME = salt_call_cli.run("timezone.get_using_network_time") - TIME_SERVER = salt_call_cli.run("timezone.get_time_server") - TIME_ZONE = salt_call_cli.run("timezone.get_zone") - CURRENT_DATE = salt_call_cli.run("timezone.get_date") - CURRENT_TIME = salt_call_cli.run("timezone.get_time") - - salt_call_cli.run("timezone.set_using_network_time", False) - salt_call_cli.run("timezone.set_zone", "America/Denver") - - try: - yield - finally: - salt_call_cli.run("timezone.set_time_server", TIME_SERVER) - salt_call_cli.run("timezone.set_using_network_time", USE_NETWORK_TIME) - salt_call_cli.run("timezone.set_zone", TIME_ZONE) - if not USE_NETWORK_TIME: - salt_call_cli.run("timezone.set_date", CURRENT_DATE) - salt_call_cli.run("timezone.set_time", CURRENT_TIME) - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_get_set_date(salt_call_cli): - """ - Test timezone.get_date - Test timezone.set_date - """ - # Correct Functionality - ret = salt_call_cli.run("timezone.set_date", "2/20/2011") - assert ret.data - ret = salt_call_cli.run("timezone.get_date") - assert ret.data == "2/20/2011" - - # Test bad date format - ret = salt_call_cli.run("timezone.set_date", "13/12/2014") - assert ( - ret.stderr - == "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014" - ) - - -@pytest.mark.slow_test -def test_get_time(salt_call_cli): - """ - Test timezone.get_time - """ - text_time = salt_call_cli.run("timezone.get_time") - assert text_time.data != "Invalid Timestamp" - obj_date = datetime.datetime.strptime(text_time.data, "%H:%M:%S") - assert isinstance(obj_date, datetime.date) - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_set_time(salt_call_cli): - """ - Test timezone.set_time - """ - # Correct Functionality - ret = salt_call_cli.run("timezone.set_time", "3:14") - assert ret.data - - # Test bad time format - ret = salt_call_cli.run("timezone.set_time", "3:71") - assert ( - ret.stderr - == "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" - ) - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_get_set_zone(salt_call_cli): - """ - Test timezone.get_zone - Test timezone.set_zone - """ - # Correct Functionality - ret = salt_call_cli.run("timezone.set_zone", "Pacific/Wake") - assert ret.data - assert ret.data == "Pacific/Wake" - - # Test bad time zone - ret = salt_call_cli.run("timezone.set_zone", "spongebob") - assert ( - ret.stderr == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" - ) - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_get_offset(salt_call_cli): - """ - Test timezone.get_offset - """ - ret = salt_call_cli.run("timezone.set_zone", "Pacific/Wake") - assert ret.data - ret = salt_call_cli.run("timezone.get_offset") - assert isinstance(ret.data, str) - assert ret.data == "+1200" - - ret = salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") - assert ret.data - assert isinstance(ret.data, str) - assert ret.data == "-0700" - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_get_set_zonecode(salt_call_cli): - """ - Test timezone.get_zonecode - Test timezone.set_zonecode - """ - ret = salt_call_cli.run("timezone.set_zone", "America/Los_Angeles") - assert ret.data - assert isinstance(ret.data, str) - assert ret.data == "PDT" - - ret = salt_call_cli.run("timezone.set_zone", "Pacific/Wake") - assert ret.data - assert isinstance(ret.data, str) - assert ret.data == "WAKT" - - -@pytest.mark.slow_test -def test_list_zones(salt_call_cli): - """ - Test timezone.list_zones - """ - zones = salt_call_cli.run("timezone.list_zones") - assert isinstance(zones.data, list) - assert "America/Denver" in zones.data - assert "America/Los_Angeles" in zones.data - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_zone_compare(salt_call_cli): - """ - Test timezone.zone_compare - """ - ret = salt_call_cli.run("timezone.set_zone", "America/Denver") - assert ret.data - ret = salt_call_cli.run("timezone.zone_compare", "America/Denver") - assert ret.data - ret = salt_call_cli.run("timezone.zone_compare", "Pacific/Wake") - assert not ret.data - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_get_set_using_network_time(salt_call_cli): - """ - Test timezone.get_using_network_time - Test timezone.set_using_network_time - """ - ret = salt_call_cli.run("timezone.set_using_network_time", True) - assert ret.data - - ret = salt_call_cli.run("timezone.get_using_network_time") - assert ret.data - - ret = salt_call_cli.run("timezone.set_using_network_time", False) - assert ret.data - - ret = salt_call_cli.run("timezone.get_using_network_time") - assert not ret.data - - -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) -@pytest.mark.destructive_test -def test_get_set_time_server(salt_call_cli): - """ - Test timezone.get_time_server - Test timezone.set_time_server - """ - ret = salt_call_cli.run("timezone.set_time_server", "spongebob.com") - assert ret.data - - ret = salt_call_cli.run("timezone.get_time_server") == "spongebob.com" - assert ret.data diff --git a/tests/pytests/integration/modules/test_mac_xattr.py b/tests/pytests/integration/modules/test_mac_xattr.py deleted file mode 100644 index 7318ba22b9dd..000000000000 --- a/tests/pytests/integration/modules/test_mac_xattr.py +++ /dev/null @@ -1,179 +0,0 @@ -""" -integration tests for mac_xattr -""" - -import pytest - -pytestmark = [ - pytest.mark.skip_if_binaries_missing("xattr"), - pytest.mark.slow_test, - pytest.mark.skip_if_not_root, - pytest.mark.skip_unless_on_darwin, -] - - -@pytest.fixture(scope="function") -def setup_teardown_vars(salt_call_cli, tmp_path): - test_file = tmp_path / "xattr_test_file.txt" - no_file = str(tmp_path / "xattr_no_file.txt") - - test_file.touch() - - try: - yield str(test_file), no_file - finally: - if test_file.exists(): - test_file.unlink() - - -def test_list_no_xattr(salt_call_cli, setup_teardown_vars): - """ - Make sure there are no attributes - """ - test_file = setup_teardown_vars[0] - no_file = setup_teardown_vars[1] - - # Clear existing attributes - ret = salt_call_cli.run("xattr.clear", test_file) - assert ret.data - - # Test no attributes - ret = salt_call_cli.run("xattr.list", test_file) - assert ret.data == {} - - # Test file not found - ret = salt_call_cli.run("xattr.list", no_file) - assert f"File not found: {no_file}" in ret.stderr - - -def test_write(salt_call_cli, setup_teardown_vars): - """ - Write an attribute - """ - test_file = setup_teardown_vars[0] - no_file = setup_teardown_vars[1] - - # Clear existing attributes - ret = salt_call_cli.run("xattr.clear", test_file) - assert ret.data - - # Write some attributes - ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") - assert ret.data - - ret = salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") - assert ret.data - - ret = salt_call_cli.run("xattr.write", test_file, "crabby", "patty") - assert ret.data - - # Test that they were actually added - ret = salt_call_cli.run("xattr.list", test_file) - assert ret.data == { - "spongebob": "squarepants", - "squidward": "plankton", - "crabby": "patty", - } - - # Test file not found - ret = salt_call_cli.run("xattr.write", no_file, "patrick", "jellyfish") - assert f"File not found: {no_file}" in ret.stderr - - -def test_read(salt_call_cli, setup_teardown_vars): - """ - Test xattr.read - """ - test_file = setup_teardown_vars[0] - no_file = setup_teardown_vars[1] - - # Clear existing attributes - ret = salt_call_cli.run("xattr.clear", test_file) - assert ret.data - - # Write an attribute - ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") - assert ret.data - - # Read the attribute - ret = salt_call_cli.run("xattr.read", test_file, "spongebob") - assert ret.data == "squarepants" - - # Test file not found - ret = salt_call_cli.run("xattr.read", no_file, "spongebob") - assert f"File not found: {no_file}" in ret.stderr - - # Test attribute not found - ret = salt_call_cli.run("xattr.read", test_file, "patrick") - assert "Attribute not found: patrick" in ret.stderr - - -def test_delete(salt_call_cli, setup_teardown_vars): - """ - Test xattr.delete - """ - test_file = setup_teardown_vars[0] - no_file = setup_teardown_vars[1] - - # Clear existing attributes - ret = salt_call_cli.run("xattr.clear", test_file) - assert ret.data - - # Write some attributes - ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") - assert ret.data - - ret = salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") - assert ret.data - - ret = salt_call_cli.run("xattr.write", test_file, "crabby", "patty") - assert ret.data - - # Delete an attribute - ret = salt_call_cli.run("xattr.delete", test_file, "squidward") - assert ret.data - - # Make sure it was actually deleted - ret = salt_call_cli.run("xattr.list", test_file) - assert ret.data == { - "spongebob": "squarepants", - "crabby": "patty", - } - - # Test file not found - ret = salt_call_cli.run("xattr.delete", no_file, "spongebob") - assert f"File not found: {no_file}" in ret.stderr - - # Test attribute not found - ret = salt_call_cli.run("xattr.delete", test_file, "patrick") - assert "Attribute not found: patrick" in ret.stderr - - -def test_clear(salt_call_cli, setup_teardown_vars): - """ - Test xattr.clear - """ - test_file = setup_teardown_vars[0] - no_file = setup_teardown_vars[1] - - # Clear existing attributes - ret = salt_call_cli.run("xattr.clear", test_file) - assert ret.data - - # Write some attributes - ret = salt_call_cli.run("xattr.write", test_file, "spongebob", "squarepants") - assert ret.data - - ret = salt_call_cli.run("xattr.write", test_file, "squidward", "plankton") - assert ret.data - - ret = salt_call_cli.run("xattr.write", test_file, "crabby", "patty") - assert ret.data - - # Test Clear - ret = salt_call_cli.run("xattr.clear", test_file) - assert ret.data - - # Test file not found - ret = salt_call_cli.run("xattr.clear", no_file) - assert f"File not found: {no_file}" in ret.stderr From 39712a8872a0026d533d143a50abd20a9290ef12 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 20 Nov 2023 14:33:03 -0800 Subject: [PATCH 25/37] fixing test_mac_group tests. --- .../pytests/functional/modules/test_mac_group.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_group.py b/tests/pytests/functional/modules/test_mac_group.py index 291313942b98..9f16b247d618 100644 --- a/tests/pytests/functional/modules/test_mac_group.py +++ b/tests/pytests/functional/modules/test_mac_group.py @@ -73,6 +73,8 @@ def test_mac_group_add(group, add_group): group_info = group.info(add_group) assert group_info["name"] == add_group + group.delete(add_group) + def test_mac_group_delete(group, del_group): """ @@ -103,6 +105,8 @@ def test_mac_group_chgid(group, change_group): group_info = group.info(change_group) assert group_info["gid"] == 6789 + group.delete(change_group) + def test_mac_adduser(group, add_group, add_user): """ @@ -118,6 +122,8 @@ def test_mac_adduser(group, add_group, add_user): group_info = group.info(add_group) assert add_user == "".join(group_info["members"]) + group.delete(add_group) + def test_mac_deluser(group, add_group, add_user): """ @@ -132,11 +138,13 @@ def test_mac_deluser(group, add_group, add_user): pytest.skip("Failed to create a group to manipulate") delusr = group.deluser(add_group, add_user) - assert delusr.data + assert delusr group_info = group.info(add_group) assert add_user not in "".join(group_info["members"]) + group.delete(add_group) + def test_mac_members(group, add_group, add_user, rep_user_group): """ @@ -160,6 +168,8 @@ def test_mac_members(group, add_group, add_user, rep_user_group): assert rep_user_group in str(group_info["members"]) assert add_user not in str(group_info["members"]) + group.delete(add_group) + def test_mac_getent(group, add_group, add_user): """ @@ -176,6 +186,8 @@ def test_mac_getent(group, add_group, add_user): ) getinfo = group.getent() - assert getinfo.data + assert getinfo assert add_group in str(getinfo) assert add_user in str(getinfo) + + group.delete(add_group) From 80ba0f655341301c62789c1f403d36f87e4b02a1 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 20 Nov 2023 15:35:52 -0800 Subject: [PATCH 26/37] fixing test_mac_desktop.py test_mac_keychain.py test_mac_power.py test_mac_power_wake_on_modem.py test_mac_service.py --- .../functional/modules/test_mac_desktop.py | 12 ++-- .../functional/modules/test_mac_keychain.py | 2 +- .../functional/modules/test_mac_power.py | 62 ++++++++++++------- .../modules/test_mac_power_wake_on_modem.py | 15 +++-- .../functional/modules/test_mac_service.py | 48 ++++++++------ 5 files changed, 85 insertions(+), 54 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_desktop.py b/tests/pytests/functional/modules/test_mac_desktop.py index 432b9c5708d9..1084ba55e98b 100644 --- a/tests/pytests/functional/modules/test_mac_desktop.py +++ b/tests/pytests/functional/modules/test_mac_desktop.py @@ -4,6 +4,8 @@ import pytest +from salt.exceptions import CommandExecutionError + pytestmark = [ pytest.mark.slow_test, pytest.mark.destructive_test, @@ -49,8 +51,9 @@ def test_screensaver(desktop): """ Tests the return of the screensaver function. """ - ret = desktop.screensaver() - if "does not exist" in ret: + try: + ret = desktop.screensaver() + except CommandExecutionError as exc: pytest.skip("Skipping. Screensaver unavailable.") assert ret @@ -59,8 +62,9 @@ def test_lock(desktop): """ Tests the return of the lock function. """ - ret = desktop.lock() - if "Unable to run" in ret: + try: + ret = desktop.lock() + except CommandExecutionError as exc: pytest.skip("Skipping. Unable to lock screen.") assert ret diff --git a/tests/pytests/functional/modules/test_mac_keychain.py b/tests/pytests/functional/modules/test_mac_keychain.py index c4997d797c67..eb67304487d2 100644 --- a/tests/pytests/functional/modules/test_mac_keychain.py +++ b/tests/pytests/functional/modules/test_mac_keychain.py @@ -84,7 +84,7 @@ def test_mac_keychain_uninstall(keychain, setup_teardown_vars): @pytest.mark.skip_if_binaries_missing("openssl") -def test_mac_keychain_get_friendly_name(keychain, shell): +def test_mac_keychain_get_friendly_name(keychain, shell, setup_teardown_vars): """ Test that attempts to get friendly name of a cert """ diff --git a/tests/pytests/functional/modules/test_mac_power.py b/tests/pytests/functional/modules/test_mac_power.py index b61b53d85ea9..1f714e5e5090 100644 --- a/tests/pytests/functional/modules/test_mac_power.py +++ b/tests/pytests/functional/modules/test_mac_power.py @@ -4,6 +4,8 @@ import pytest +from salt.exceptions import SaltInvocationError + pytestmark = [ pytest.mark.flaky(max_runs=10), pytest.mark.skip_if_binaries_missing("systemsetup"), @@ -52,17 +54,21 @@ def test_computer_sleep(power): assert ret == "Never" # Test invalid input - ret = power.set_computer_sleep("spongebob") - assert "Invalid String Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_computer_sleep("spongebob") + assert "Invalid String Value for Minutes" in str(exc.value) - ret = power.set_computer_sleep(0) - assert "Invalid Integer Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_computer_sleep(0) + assert "Invalid Integer Value for Minutes" in str(exc.value) - ret = power.set_computer_sleep(181) - assert "Invalid Integer Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_computer_sleep(181) + assert "Invalid Integer Value for Minutes" in str(exc.value) - ret = power.set_computer_sleep(True) - assert "Invalid Boolean Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_computer_sleep(True) + assert "Invalid Boolean Value for Minutes" in str(exc.value) def test_display_sleep(power): @@ -85,17 +91,21 @@ def test_display_sleep(power): assert ret == "Never" # Test invalid input - ret = power.set_display_sleep("spongebob") - assert "Invalid String Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_display_sleep("spongebob") + assert "Invalid String Value for Minutes" in str(exc.value) - ret = power.set_display_sleep(0) - assert "Invalid Integer Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_display_sleep(0) + assert "Invalid Integer Value for Minutes" in str(exc.value) - ret = power.set_display_sleep(181) - assert "Invalid Integer Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_display_sleep(181) + assert "Invalid Integer Value for Minutes" in str(exc.value) - ret = power.set_display_sleep(True) - assert "Invalid Boolean Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_display_sleep(True) + assert "Invalid Boolean Value for Minutes" in str(exc.value) def test_harddisk_sleep(power): @@ -118,17 +128,21 @@ def test_harddisk_sleep(power): assert ret == "Never" # Test invalid input - ret = power.set_harddisk_sleep("spongebob") - assert "Invalid String Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_harddisk_sleep("spongebob") + assert "Invalid String Value for Minutes" in str(exc.value) - ret = power.set_harddisk_sleep(0) - assert "Invalid Integer Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_harddisk_sleep(0) + assert "Invalid Integer Value for Minutes" in str(exc.value) - ret = power.set_harddisk_sleep(181) - assert "Invalid Integer Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_harddisk_sleep(181) + assert "Invalid Integer Value for Minutes" in str(exc.value) - ret = power.set_harddisk_sleep(True) - assert "Invalid Boolean Value for Minutes" in ret + with pytest.raises(SaltInvocationError) as exc: + power.set_harddisk_sleep(True) + assert "Invalid Boolean Value for Minutes" in str(exc.value) def test_restart_freeze(power): diff --git a/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py b/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py index adebe40e2a1b..b0db4e406bfb 100644 --- a/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py +++ b/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py @@ -4,6 +4,8 @@ import pytest +from salt.exceptions import CommandExecutionError + pytestmark = [ pytest.mark.flaky(max_runs=10), pytest.mark.slow_test, @@ -23,15 +25,16 @@ def test_wake_on_modem(power): Test power.get_wake_on_modem Test power.set_wake_on_modem """ - WAKE_ON_MODEM = None - ret = power.get_wake_on_modem() - if isinstance(ret, bool): - WAKE_ON_MODEM = ret + try: + ret = power.get_wake_on_modem() + if isinstance(ret, bool): + WAKE_ON_MODEM = ret + except CommandExecutionError as exc: + WAKE_ON_MODEM = None if WAKE_ON_MODEM is None: # Check for not available - ret = power.get_wake_on_modem() - assert "Error" in ret + pytest.skip("Skipping. wake_on_modem unavailable.") else: ret = power.set_wake_on_modem("on") assert ret diff --git a/tests/pytests/functional/modules/test_mac_service.py b/tests/pytests/functional/modules/test_mac_service.py index 7b26a98351c8..bcaa78bebcad 100644 --- a/tests/pytests/functional/modules/test_mac_service.py +++ b/tests/pytests/functional/modules/test_mac_service.py @@ -7,6 +7,7 @@ import pytest import salt.utils.files +from salt.exceptions import CommandExecutionError pytestmark = [ pytest.mark.slow_test, @@ -21,7 +22,7 @@ def service(modules): @pytest.fixture(scope="function", autouse=True) -def service_name(sergice, service_name): +def service_name(service, service_name): service_name = "com.salt.integration.test" service_path = "/Library/LaunchDaemons/com.salt.integration.test.plist" @@ -54,8 +55,9 @@ def test_show(service, service_name): assert service_info.data["plist"]["Label"] == service_name # Missing Service - ret = service.show("spongebob") - assert "Service not found" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.show("spongebob") + assert "Service not found" in str(exc.value) def test_launchctl(service, service_name): @@ -70,8 +72,9 @@ def test_launchctl(service, service_name): assert ret == "64: unknown error code" # Raise an error - ret = service.launchctl("error", "bootstrap") - assert "Failed to error service" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.launchctl("error", "bootstrap") + assert "Failed to error service" in str(exc.value) def test_list(service, service_name): @@ -85,8 +88,9 @@ def test_list(service, service_name): assert "{" in ret # Service not found - ret = service.list("spongebob") - assert "Service not found" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.list("spongebob") + assert "Service not found" in str(exc.value) def test_enable(service, service_name): @@ -96,8 +100,9 @@ def test_enable(service, service_name): ret = service.enable(service_name) assert ret - ret = service.enable("spongebob") - assert "Service not found" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.enable("spongebob") + assert "Service not found" in str(exc.value) def test_disable(service, service_name): @@ -107,8 +112,9 @@ def test_disable(service, service_name): ret = service.disable(service_name) assert ret - ret = service.disable("spongebob") - assert "Service not found" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.disable("spongebob") + assert "Service not found" in str(exc.value) def test_start(service, service_name): @@ -121,8 +127,9 @@ def test_start(service, service_name): ret = service.start(service_name) assert ret - ret = service.start("spongebob") - assert "Service not found" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.start("spongebob") + assert "Service not found" in str(exc.value) def test_stop(service, service_name): @@ -132,8 +139,9 @@ def test_stop(service, service_name): ret = service.stop(service_name) assert ret - ret = service.stop("spongebob") - assert "Service not found" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.stop("spongebob") + assert "Service not found" in str(exc.value) def test_status(service, service_name): @@ -185,8 +193,9 @@ def test_enabled(service, service_name): ret = service.enabled(service_name) assert ret - ret = service.enabled("spongebob") - assert "Service not found: spongebob" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.enabled("spongebob") + assert "Service not found: spongebob" in str(exc.value) def test_disabled(service, service_name): @@ -208,8 +217,9 @@ def test_disabled(service, service_name): ret = service.enable(service_name) assert ret - ret = service.disable("spongebob") - assert "Service not found: spongebob" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = service.disable("spongebob") + assert "Service not found: spongebob" in str(exc.value) def test_get_all(service, service_name): From 9fdd640436881e4ebe0ada4b16a389b5cbbb9f34 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 20 Nov 2023 15:58:47 -0800 Subject: [PATCH 27/37] fixes to test_mac_service.py --- .../pytests/functional/modules/test_mac_service.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_service.py b/tests/pytests/functional/modules/test_mac_service.py index bcaa78bebcad..3dcfce86396f 100644 --- a/tests/pytests/functional/modules/test_mac_service.py +++ b/tests/pytests/functional/modules/test_mac_service.py @@ -22,7 +22,7 @@ def service(modules): @pytest.fixture(scope="function", autouse=True) -def service_name(service, service_name): +def service_name(service): service_name = "com.salt.integration.test" service_path = "/Library/LaunchDaemons/com.salt.integration.test.plist" @@ -41,7 +41,11 @@ def service_name(service, service_name): try: yield service_name finally: - service.stop(service_name) + # Try to stop the service if it's running + try: + service.stop(service_name) + except CommandExecutionError: + pass salt.utils.files.safe_rm(service_path) @@ -52,7 +56,7 @@ def test_show(service, service_name): # Existing Service service_info = service.show(service_name) assert isinstance(service_info, dict) - assert service_info.data["plist"]["Label"] == service_name + assert service_info["plist"]["Label"] == service_name # Missing Service with pytest.raises(CommandExecutionError) as exc: @@ -228,7 +232,7 @@ def test_get_all(service, service_name): """ services = service.get_all() assert isinstance(services, list) - assert service_name in services.data + assert service_name in services def test_get_enabled(service, service_name): @@ -237,7 +241,7 @@ def test_get_enabled(service, service_name): """ services = service.get_enabled() assert isinstance(services, list) - assert service_name in services.data + assert service_name in services def test_service_laoded(service, service_name): From 24d56cc4547c42586b2af15662e5b3019bf31dd8 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 20 Nov 2023 16:20:37 -0800 Subject: [PATCH 28/37] removing __utils__ --- salt/modules/mac_system.py | 99 +++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/salt/modules/mac_system.py b/salt/modules/mac_system.py index 1dd0aa8ea29a..ad64bc6badc6 100644 --- a/salt/modules/mac_system.py +++ b/salt/modules/mac_system.py @@ -10,6 +10,7 @@ import getpass import shlex +import salt.utils.mac_utils import salt.utils.platform from salt.exceptions import CommandExecutionError, SaltInvocationError @@ -71,7 +72,7 @@ def _execute_command(cmd, at_time=None): Returns: bool """ if at_time: - cmd = "echo '{}' | at {}".format(cmd, shlex.quote(at_time)) + cmd = f"echo '{cmd}' | at {shlex.quote(at_time)}" return not bool(__salt__["cmd.retcode"](cmd, python_shell=True)) @@ -204,10 +205,10 @@ def get_remote_login(): salt '*' system.get_remote_login """ - ret = __utils__["mac_utils.execute_return_result"]("systemsetup -getremotelogin") + ret = salt.utils.mac_utils.execute_return_result("systemsetup -getremotelogin") - enabled = __utils__["mac_utils.validate_enabled"]( - __utils__["mac_utils.parse_return"](ret) + enabled = salt.utils.mac_utils.validate_enabled( + salt.utils.mac_utils.parse_return(ret) ) return enabled == "on" @@ -230,12 +231,12 @@ def set_remote_login(enable): salt '*' system.set_remote_login True """ - state = __utils__["mac_utils.validate_enabled"](enable) + state = salt.utils.mac_utils.validate_enabled(enable) - cmd = "systemsetup -f -setremotelogin {}".format(state) - __utils__["mac_utils.execute_return_success"](cmd) + cmd = f"systemsetup -f -setremotelogin {state}" + salt.utils.mac_utils.execute_return_success(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( state, get_remote_login, normalize_ret=True ) @@ -253,12 +254,12 @@ def get_remote_events(): salt '*' system.get_remote_events """ - ret = __utils__["mac_utils.execute_return_result"]( + ret = salt.utils.mac_utils.execute_return_result( "systemsetup -getremoteappleevents" ) - enabled = __utils__["mac_utils.validate_enabled"]( - __utils__["mac_utils.parse_return"](ret) + enabled = salt.utils.mac_utils.validate_enabled( + salt.utils.mac_utils.parse_return(ret) ) return enabled == "on" @@ -282,12 +283,12 @@ def set_remote_events(enable): salt '*' system.set_remote_events On """ - state = __utils__["mac_utils.validate_enabled"](enable) + state = salt.utils.mac_utils.validate_enabled(enable) - cmd = "systemsetup -setremoteappleevents {}".format(state) - __utils__["mac_utils.execute_return_success"](cmd) + cmd = f"systemsetup -setremoteappleevents {state}" + salt.utils.mac_utils.execute_return_success(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( state, get_remote_events, normalize_ret=True, @@ -307,9 +308,9 @@ def get_computer_name(): salt '*' system.get_computer_name """ - ret = __utils__["mac_utils.execute_return_result"]("scutil --get ComputerName") + ret = salt.utils.mac_utils.execute_return_result("scutil --get ComputerName") - return __utils__["mac_utils.parse_return"](ret) + return salt.utils.mac_utils.parse_return(ret) def set_computer_name(name): @@ -327,10 +328,10 @@ def set_computer_name(name): salt '*' system.set_computer_name "Mike's Mac" """ - cmd = 'scutil --set ComputerName "{}"'.format(name) - __utils__["mac_utils.execute_return_success"](cmd) + cmd = f'scutil --set ComputerName "{name}"' + salt.utils.mac_utils.execute_return_success(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( name, get_computer_name, ) @@ -349,11 +350,9 @@ def get_subnet_name(): salt '*' system.get_subnet_name """ - ret = __utils__["mac_utils.execute_return_result"]( - "systemsetup -getlocalsubnetname" - ) + ret = salt.utils.mac_utils.execute_return_result("systemsetup -getlocalsubnetname") - return __utils__["mac_utils.parse_return"](ret) + return salt.utils.mac_utils.parse_return(ret) def set_subnet_name(name): @@ -375,10 +374,10 @@ def set_subnet_name(name): The following will be set as 'Mikes-Mac' salt '*' system.set_subnet_name "Mike's Mac" """ - cmd = 'systemsetup -setlocalsubnetname "{}"'.format(name) - __utils__["mac_utils.execute_return_success"](cmd) + cmd = f'systemsetup -setlocalsubnetname "{name}"' + salt.utils.mac_utils.execute_return_success(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( name, get_subnet_name, ) @@ -397,9 +396,9 @@ def get_startup_disk(): salt '*' system.get_startup_disk """ - ret = __utils__["mac_utils.execute_return_result"]("systemsetup -getstartupdisk") + ret = salt.utils.mac_utils.execute_return_result("systemsetup -getstartupdisk") - return __utils__["mac_utils.parse_return"](ret) + return salt.utils.mac_utils.parse_return(ret) def list_startup_disks(): @@ -415,7 +414,7 @@ def list_startup_disks(): salt '*' system.list_startup_disks """ - ret = __utils__["mac_utils.execute_return_result"]("systemsetup -liststartupdisks") + ret = salt.utils.mac_utils.execute_return_result("systemsetup -liststartupdisks") return ret.splitlines() @@ -445,10 +444,10 @@ def set_startup_disk(path): ) raise SaltInvocationError(msg) - cmd = "systemsetup -setstartupdisk {}".format(path) - __utils__["mac_utils.execute_return_result"](cmd) + cmd = f"systemsetup -setstartupdisk {path}" + salt.utils.mac_utils.execute_return_result(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( path, get_startup_disk, ) @@ -469,11 +468,11 @@ def get_restart_delay(): salt '*' system.get_restart_delay """ - ret = __utils__["mac_utils.execute_return_result"]( + ret = salt.utils.mac_utils.execute_return_result( "systemsetup -getwaitforstartupafterpowerfailure" ) - return __utils__["mac_utils.parse_return"](ret) + return salt.utils.mac_utils.parse_return(ret) def set_restart_delay(seconds): @@ -512,10 +511,10 @@ def set_restart_delay(seconds): ) raise SaltInvocationError(msg) - cmd = "systemsetup -setwaitforstartupafterpowerfailure {}".format(seconds) - __utils__["mac_utils.execute_return_success"](cmd) + cmd = f"systemsetup -setwaitforstartupafterpowerfailure {seconds}" + salt.utils.mac_utils.execute_return_success(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( seconds, get_restart_delay, ) @@ -535,12 +534,12 @@ def get_disable_keyboard_on_lock(): salt '*' system.get_disable_keyboard_on_lock """ - ret = __utils__["mac_utils.execute_return_result"]( + ret = salt.utils.mac_utils.execute_return_result( "systemsetup -getdisablekeyboardwhenenclosurelockisengaged" ) - enabled = __utils__["mac_utils.validate_enabled"]( - __utils__["mac_utils.parse_return"](ret) + enabled = salt.utils.mac_utils.validate_enabled( + salt.utils.mac_utils.parse_return(ret) ) return enabled == "on" @@ -564,12 +563,12 @@ def set_disable_keyboard_on_lock(enable): salt '*' system.set_disable_keyboard_on_lock False """ - state = __utils__["mac_utils.validate_enabled"](enable) + state = salt.utils.mac_utils.validate_enabled(enable) - cmd = "systemsetup -setdisablekeyboardwhenenclosurelockisengaged {}".format(state) - __utils__["mac_utils.execute_return_success"](cmd) + cmd = f"systemsetup -setdisablekeyboardwhenenclosurelockisengaged {state}" + salt.utils.mac_utils.execute_return_success(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( state, get_disable_keyboard_on_lock, normalize_ret=True, @@ -589,11 +588,11 @@ def get_boot_arch(): salt '*' system.get_boot_arch """ - ret = __utils__["mac_utils.execute_return_result"]( + ret = salt.utils.mac_utils.execute_return_result( "systemsetup -getkernelbootarchitecturesetting" ) - arch = __utils__["mac_utils.parse_return"](ret) + arch = salt.utils.mac_utils.parse_return(ret) if "default" in arch: return "default" @@ -639,10 +638,10 @@ def set_boot_arch(arch="default"): ) raise SaltInvocationError(msg) - cmd = "systemsetup -setkernelbootarchitecture {}".format(arch) - __utils__["mac_utils.execute_return_success"](cmd) + cmd = f"systemsetup -setkernelbootarchitecture {arch}" + salt.utils.mac_utils.execute_return_success(cmd) - return __utils__["mac_utils.confirm_updated"]( + return salt.utils.mac_utils.confirm_updated( arch, get_boot_arch, ) From 975130b5623cc6dc0c57f7995d3edce013c4cd98 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 20 Nov 2023 17:49:58 -0800 Subject: [PATCH 29/37] fixses and a skip added to test_mac_shadow.py test_mac_softwareupdate.py --- tests/pytests/functional/modules/test_mac_shadow.py | 2 +- .../pytests/functional/modules/test_mac_softwareupdate.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_shadow.py b/tests/pytests/functional/modules/test_mac_shadow.py index f4c58ce05c81..41e0d16a4bf0 100644 --- a/tests/pytests/functional/modules/test_mac_shadow.py +++ b/tests/pytests/functional/modules/test_mac_shadow.py @@ -49,7 +49,7 @@ def test_get_account_created(shadow, accounts): """ # Correct Functionality text_date = shadow.get_account_created(accounts.created) - assert text_date.data != "Invalid Timestamp" + assert text_date != "Invalid Timestamp" obj_date = datetime.datetime.strptime(text_date, "%Y-%m-%d %H:%M:%S") assert isinstance(obj_date, datetime.date) diff --git a/tests/pytests/functional/modules/test_mac_softwareupdate.py b/tests/pytests/functional/modules/test_mac_softwareupdate.py index 87c245a532bc..c5295f308033 100644 --- a/tests/pytests/functional/modules/test_mac_softwareupdate.py +++ b/tests/pytests/functional/modules/test_mac_softwareupdate.py @@ -22,7 +22,7 @@ def softwareupdate(modules): def _setup_teardown_vars(softwareupdate): IGNORED_LIST = softwareupdate.list_ignored() - SCHEDULE = softwareupdate.schedule() + SCHEDULE = softwareupdate.schedule_enabled() CATALOG = softwareupdate.get_catalog() @@ -35,7 +35,7 @@ def _setup_teardown_vars(softwareupdate): else: softwareupdate.reset_ignored() - softwareupdate.schedule(SCHEDULE) + softwareupdate.schedule_enable(SCHEDULE) if CATALOG == "Default": softwareupdate.reset_catalog() @@ -53,6 +53,7 @@ def test_list_available(softwareupdate): assert isinstance(ret, dict) +@pytest.mark.skip(reason="Ignore removed from latest OS X.") def test_ignore(softwareupdate): """ Test softwareupdate.ignore @@ -95,7 +96,7 @@ def test_schedule(softwareupdate): # Test disable in case it was already enabled ret = softwareupdate.schedule_enable(False) - assert ret + assert not ret ret = softwareupdate.schedule_enabled() assert not ret From c061f15ca4cfd77f24131c7c246167557c3a9b7d Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 22 Nov 2023 12:21:49 -0800 Subject: [PATCH 30/37] more fixes related to migrating the mac tests over to functional tests --- .../functional/modules/test_mac_assistive.py | 9 ++- .../functional/modules/test_mac_brew_pkg.py | 7 +- .../functional/modules/test_mac_desktop.py | 9 +-- .../functional/modules/test_mac_power.py | 1 - .../test_mac_power_restart_power_failure.py | 1 - .../test_mac_power_sleep_on_power_button.py | 16 +++-- .../modules/test_mac_power_wake_on_modem.py | 1 - .../modules/test_mac_power_wake_on_net.py | 1 - .../functional/modules/test_mac_service.py | 8 +-- .../functional/modules/test_mac_shadow.py | 66 ++++++++----------- .../modules/test_mac_softwareupdate.py | 15 +++-- .../functional/modules/test_mac_system.py | 65 +++++++++++------- .../functional/modules/test_mac_timezone.py | 1 - .../functional/modules/test_mac_xattr.py | 41 +++++++----- 14 files changed, 130 insertions(+), 111 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_assistive.py b/tests/pytests/functional/modules/test_mac_assistive.py index ffbe703740af..32f7c0b00071 100644 --- a/tests/pytests/functional/modules/test_mac_assistive.py +++ b/tests/pytests/functional/modules/test_mac_assistive.py @@ -33,8 +33,7 @@ def _setup_teardown_vars(assistive, osa_script): assistive.remove(osa_script) smile_bundle = "com.smileonmymac.textexpander" - ret = assistive.installed(smile_bundle) - smile_bundle_present = ret + smile_bundle_present = assistive.installed(smile_bundle) if smile_bundle_present: assistive.remove(smile_bundle) @@ -56,7 +55,7 @@ def test_installed(assistive, osa_script): """ Tests the True and False return of assistive.installed. """ - # OSA script should have been installed in setUp function + # OSA script should have been installed in _setup_teardown_vars function ret = assistive.installed(osa_script) assert ret # Clean up install @@ -71,7 +70,7 @@ def test_enable(assistive, osa_script): """ Tests setting the enabled status of a bundled ID or command. """ - # OSA script should have been installed and enabled in setUp function + # OSA script should have been installed and enabled in _setup_teardown_vars function # Now let's disable it, which should return True. ret = assistive.enable(osa_script, False) assert ret @@ -91,7 +90,7 @@ def test_enabled(assistive, osa_script): """ Tests if a bundled ID or command is listed in assistive access returns True. """ - # OSA script should have been installed in setUp function, which sets + # OSA script should have been installed in _setup_teardown_vars function, which sets # enabled to True by default. ret = assistive.enabled(osa_script) assert ret diff --git a/tests/pytests/functional/modules/test_mac_brew_pkg.py b/tests/pytests/functional/modules/test_mac_brew_pkg.py index 47895f0476cc..2bcf84b48e04 100644 --- a/tests/pytests/functional/modules/test_mac_brew_pkg.py +++ b/tests/pytests/functional/modules/test_mac_brew_pkg.py @@ -13,15 +13,16 @@ pytest.mark.skip_if_binaries_missing("brew"), ] -# Brew doesn't support local package installation - So, let's -# Grab some small packages available online for brew - @pytest.fixture(scope="module") def pkg(modules): return modules.pkg +# Brew doesn't support local package installation - So, let's +# Grab some small packages available online for brew + + @pytest.fixture(scope="function") def add_pkg(): yield "algol68g" diff --git a/tests/pytests/functional/modules/test_mac_desktop.py b/tests/pytests/functional/modules/test_mac_desktop.py index 1084ba55e98b..7de6744adc06 100644 --- a/tests/pytests/functional/modules/test_mac_desktop.py +++ b/tests/pytests/functional/modules/test_mac_desktop.py @@ -31,16 +31,13 @@ def test_set_output_volume(desktop): """ Tests the return of set_output_volume. """ + current_vol = desktop.get_output_volume() try: - ret = desktop.get_output_volume() - current_vol = ret to_set = 10 if current_vol == str(to_set): to_set += 2 - ret = desktop.set_output_volume(str(to_set)) - new_vol = ret - ret = desktop.get_output_volume() - check_vol = ret + new_vol = desktop.set_output_volume(str(to_set)) + check_vol = desktop.get_output_volume() assert new_vol == check_vol finally: # Set volume back to what it was before diff --git a/tests/pytests/functional/modules/test_mac_power.py b/tests/pytests/functional/modules/test_mac_power.py index 1f714e5e5090..5600b2275692 100644 --- a/tests/pytests/functional/modules/test_mac_power.py +++ b/tests/pytests/functional/modules/test_mac_power.py @@ -7,7 +7,6 @@ from salt.exceptions import SaltInvocationError pytestmark = [ - pytest.mark.flaky(max_runs=10), pytest.mark.skip_if_binaries_missing("systemsetup"), pytest.mark.slow_test, pytest.mark.destructive_test, diff --git a/tests/pytests/functional/modules/test_mac_power_restart_power_failure.py b/tests/pytests/functional/modules/test_mac_power_restart_power_failure.py index 1016054e787e..e7196848dc44 100644 --- a/tests/pytests/functional/modules/test_mac_power_restart_power_failure.py +++ b/tests/pytests/functional/modules/test_mac_power_restart_power_failure.py @@ -5,7 +5,6 @@ import pytest pytestmark = [ - pytest.mark.flaky(max_runs=10), pytest.mark.skip_if_binaries_missing("systemsetup"), pytest.mark.slow_test, pytest.mark.skip_if_not_root, diff --git a/tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py b/tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py index 19d2d878977c..35b99e57804c 100644 --- a/tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py +++ b/tests/pytests/functional/modules/test_mac_power_sleep_on_power_button.py @@ -4,8 +4,9 @@ import pytest +from salt.exceptions import CommandExecutionError + pytestmark = [ - pytest.mark.flaky(max_runs=10), pytest.mark.skip_if_binaries_missing("systemsetup"), pytest.mark.slow_test, pytest.mark.skip_if_not_root, @@ -23,16 +24,17 @@ def test_sleep_on_power_button(power): Test power.get_sleep_on_power_button Test power.set_sleep_on_power_button """ - SLEEP_ON_BUTTON = None - - ret = power.get_sleep_on_power_button() - if isinstance(ret, bool): - SLEEP_ON_BUTTON = ret + try: + ret = power.get_sleep_on_power_button() + if isinstance(ret, bool): + SLEEP_ON_BUTTON = ret + except CommandExecutionError as exc: + SLEEP_ON_BUTTON = None # If available on this system, test it if SLEEP_ON_BUTTON is None: # Check for not available - assert "Error" in ret + pytest.skip("Skipping. sleep_on_power_button unavailable.") else: ret = power.set_sleep_on_power_button("on") assert ret diff --git a/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py b/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py index b0db4e406bfb..b6f759cb26d3 100644 --- a/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py +++ b/tests/pytests/functional/modules/test_mac_power_wake_on_modem.py @@ -7,7 +7,6 @@ from salt.exceptions import CommandExecutionError pytestmark = [ - pytest.mark.flaky(max_runs=10), pytest.mark.slow_test, pytest.mark.skip_if_not_root, pytest.mark.skip_unless_on_darwin, diff --git a/tests/pytests/functional/modules/test_mac_power_wake_on_net.py b/tests/pytests/functional/modules/test_mac_power_wake_on_net.py index dc5f8aa40922..a36bf695e990 100644 --- a/tests/pytests/functional/modules/test_mac_power_wake_on_net.py +++ b/tests/pytests/functional/modules/test_mac_power_wake_on_net.py @@ -5,7 +5,6 @@ import pytest pytestmark = [ - pytest.mark.flaky(max_runs=10), pytest.mark.skip_if_binaries_missing("systemsetup"), pytest.mark.slow_test, pytest.mark.skip_if_not_root, diff --git a/tests/pytests/functional/modules/test_mac_service.py b/tests/pytests/functional/modules/test_mac_service.py index 3dcfce86396f..0aa38a8ac8ea 100644 --- a/tests/pytests/functional/modules/test_mac_service.py +++ b/tests/pytests/functional/modules/test_mac_service.py @@ -147,13 +147,14 @@ def test_stop(service, service_name): ret = service.stop("spongebob") assert "Service not found" in str(exc.value) + service.start(service_name) + def test_status(service, service_name): """ Test service.status """ # A running service - service.start(service_name) ret = service.status(service_name) assert ret @@ -166,6 +167,8 @@ def test_status(service, service_name): ret = service.status("spongebob") assert not ret + service.start(service_name) + def test_available(service, service_name): """ @@ -206,9 +209,6 @@ def test_disabled(service, service_name): """ Test service.disabled """ - service.enabled(service_name) - service.start(service_name) - ret = service.disabled(service_name) assert not ret diff --git a/tests/pytests/functional/modules/test_mac_shadow.py b/tests/pytests/functional/modules/test_mac_shadow.py index 41e0d16a4bf0..f4fd783756fe 100644 --- a/tests/pytests/functional/modules/test_mac_shadow.py +++ b/tests/pytests/functional/modules/test_mac_shadow.py @@ -8,9 +8,10 @@ import pytest from saltfactories.utils import random_string +from salt.exceptions import CommandExecutionError + pytestmark = [ pytest.mark.skip_if_binaries_missing("dscl", "pwpolicy"), - pytest.mark.skip_initial_gh_actions_failure, pytest.mark.slow_test, pytest.mark.skip_if_not_root, pytest.mark.skip_unless_on_darwin, @@ -54,10 +55,9 @@ def test_get_account_created(shadow, accounts): assert isinstance(obj_date, datetime.date) # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.get_account_created(accounts.not_created) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_get_last_change(shadow, accounts): @@ -71,10 +71,9 @@ def test_get_last_change(shadow, accounts): assert isinstance(obj_date, datetime.date) # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.get_last_change(accounts.not_created) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_get_login_failed_last(shadow, accounts): @@ -88,10 +87,9 @@ def test_get_login_failed_last(shadow, accounts): assert isinstance(obj_date, datetime.date) # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.get_login_failed_last(accounts) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_get_login_failed_count(shadow, accounts): @@ -102,10 +100,9 @@ def test_get_login_failed_count(shadow, accounts): assert shadow.get_login_failed_count(accounts.created) == "0" # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.get_login_failed_count(accounts.not_created) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_get_set_maxdays(shadow, accounts): @@ -118,14 +115,13 @@ def test_get_set_maxdays(shadow, accounts): assert shadow.get_maxdays(accounts.created) == 20 # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.set_maxdays(accounts.not_created, 7) - == f"ERROR: User not found: {accounts.not_created}" - ) - assert ( + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) + + with pytest.raises(CommandExecutionError) as exc: shadow.get_maxdays(accounts.not_created) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_get_set_change(shadow, accounts): @@ -138,14 +134,13 @@ def test_get_set_change(shadow, accounts): assert shadow.get_change(accounts.created) == "02/11/2011" # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.set_change(accounts.not_created, "02/11/2012") - == f"ERROR: User not found: {accounts.not_created}" - ) - assert ( + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) + + with pytest.raises(CommandExecutionError) as exc: shadow.get_change(accounts.not_created) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_get_set_expire(shadow, accounts): @@ -158,14 +153,13 @@ def test_get_set_expire(shadow, accounts): assert shadow.get_expire(accounts.created) == "02/11/2011" # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.set_expire(accounts.not_created, "02/11/2012") - == f"ERROR: User not found: {accounts.not_created}" - ) - assert ( + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) + + with pytest.raises(CommandExecutionError) as exc: shadow.get_expire(accounts.not_created) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_del_password(shadow, accounts): @@ -177,10 +171,9 @@ def test_del_password(shadow, accounts): assert shadow.info(accounts.created)["passwd"] == "*" # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.del_password(accounts.not_created) - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) def test_set_password(shadow, accounts): @@ -191,7 +184,6 @@ def test_set_password(shadow, accounts): assert shadow.set_password(accounts.created, "Pa$$W0rd") # User does not exist - assert ( + with pytest.raises(CommandExecutionError) as exc: shadow.set_password(accounts.not_created, "P@SSw0rd") - == f"ERROR: User not found: {accounts.not_created}" - ) + assert f"ERROR: User not found: {accounts.not_created}" in str(exc.value) diff --git a/tests/pytests/functional/modules/test_mac_softwareupdate.py b/tests/pytests/functional/modules/test_mac_softwareupdate.py index c5295f308033..b4545252c989 100644 --- a/tests/pytests/functional/modules/test_mac_softwareupdate.py +++ b/tests/pytests/functional/modules/test_mac_softwareupdate.py @@ -4,12 +4,13 @@ import pytest +from salt.exceptions import SaltInvocationError + pytestmark = [ pytest.mark.slow_test, pytest.mark.skip_if_binaries_missing("softwareupdate"), pytest.mark.skip_if_not_root, pytest.mark.skip_unless_on_darwin, - pytest.mark.skip_initial_gh_actions_failure, ] @@ -82,6 +83,7 @@ def test_ignore(softwareupdate): assert "squidward" in ret +@pytest.mark.skip(reason="Ignore schedule support removed from latest OS X.") def test_schedule(softwareupdate): """ Test softwareupdate.schedule_enable @@ -121,8 +123,9 @@ def test_update(softwareupdate): assert not ret # Test update not available - ret = softwareupdate.update("spongebob") - assert "Update not available" in ret + with pytest.raises(SaltInvocationError) as exc: + ret = softwareupdate.update("spongebob") + assert "Update not available" in str(exc.value) def test_list_downloads(softwareupdate): @@ -141,8 +144,9 @@ def test_download(softwareupdate): the download function """ # Test update not available - ret = softwareupdate.download("spongebob") - assert "Update not available" in ret + with pytest.raises(SaltInvocationError) as exc: + softwareupdate.download("spongebob") + assert "Update not available" in str(exc.value) def test_download_all(softwareupdate): @@ -153,6 +157,7 @@ def test_download_all(softwareupdate): assert isinstance(ret, list) +@pytest.mark.skip(reason="Ignore catalog support removed from latest OS X.") def test_get_set_reset_catalog(softwareupdate): """ Test softwareupdate.download_all diff --git a/tests/pytests/functional/modules/test_mac_system.py b/tests/pytests/functional/modules/test_mac_system.py index 97673a580e9b..4570a01783b4 100644 --- a/tests/pytests/functional/modules/test_mac_system.py +++ b/tests/pytests/functional/modules/test_mac_system.py @@ -7,16 +7,15 @@ import pytest from saltfactories.utils import random_string +from salt.exceptions import CommandExecutionError, SaltInvocationError + log = logging.getLogger(__name__) pytestmark = [ - pytest.mark.flaky(max_runs=10), pytest.mark.slow_test, pytest.mark.skip_if_not_root, pytest.mark.skip_unless_on_darwin, - pytest.mark.usefixtures("salt_sub_minion"), pytest.mark.skip_if_binaries_missing("systemsetup"), - pytest.mark.skip_initial_gh_actions_failure, ] @@ -31,12 +30,14 @@ def system(modules): @pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(service, system): - ATRUN_ENABLED = service.enabled("com.apple.atrun") +def _setup_teardown_vars(service, system, grains): - REMOTE_LOGIN_ENABLED = system.get_remote_login() + ATRUN_ENABLED = service.enabled("com.apple.atrun") - REMOTE_EVENTS_ENABLED = system.get_remote_events() + if grains["osrelease_info"][0] < 13: + # Skipping this MacOSX 13+ until we can figure how to have full disk access enabled. + REMOTE_LOGIN_ENABLED = system.get_remote_login() + REMOTE_EVENTS_ENABLED = system.get_remote_events() SUBNET_NAME = system.get_subnet_name() @@ -49,17 +50,24 @@ def _setup_teardown_vars(service, system): atrun = "/System/Library/LaunchDaemons/com.apple.atrun.plist" service.stop(atrun) - system.set_remote_login(REMOTE_LOGIN_ENABLED) - system.set_remote_events(REMOTE_EVENTS_ENABLED) + if grains["osrelease_info"][0] < 13: + # Skipping this MacOSX 13+ until we can figure how to have full disk access enabled. + system.set_remote_login(REMOTE_LOGIN_ENABLED) + system.set_remote_events(REMOTE_EVENTS_ENABLED) system.set_subnet_name(SUBNET_NAME) system.set_disable_keyboard_on_lock(KEYBOARD_DISABLED) -def test_get_set_remote_login(system): +def test_get_set_remote_login(system, grains): """ Test system.get_remote_login Test system.set_remote_login """ + if grains["osrelease_info"][0] >= 13: + pytest.skip( + "Skipping this MacOSX 13+ until we can figure how to have full disk access enabled." + ) + # Normal Functionality ret = system.set_remote_login(True) assert ret @@ -99,15 +107,21 @@ def test_get_set_remote_login(system): assert ret # Test invalid input - ret = system.set_remote_login("spongebob") - assert "Invalid String Value for Enabled" in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_remote_login("spongebob") + assert "Invalid String Value for Enabled" in str(exc.value) -def test_get_set_remote_events(system): +def test_get_set_remote_events(system, grains): """ Test system.get_remote_events Test system.set_remote_events """ + if grains["osrelease_info"][0] >= 13: + pytest.skip( + "Skipping this MacOSX 13+ until we can figure how to have full disk access enabled." + ) + # Normal Functionality ret = system.set_remote_events(True) assert ret @@ -147,8 +161,9 @@ def test_get_set_remote_events(system): assert ret # Test invalid input - ret = system.set_remote_events("spongebob") - assert "Invalid String Value for Enabled" in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_remote_events("spongebob") + assert "Invalid String Value for Enabled" in str(exc.value) def test_get_set_subnet_name(system): @@ -180,8 +195,9 @@ def test_get_list_startup_disk(system): assert startup_disk in ret # Test passing set a bad disk - ret = system.set_startup_disk("spongebob") - assert "Invalid value passed for path." in ret + with pytest.raises(SaltInvocationError) as exc: + system.set_startup_disk("spongebob") + assert "Invalid value passed for path." in str(exc.value) @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -200,8 +216,9 @@ def test_get_set_restart_delay(system): assert ret == "90 seconds" # Pass set bad value for seconds - ret = system.set_restart_delay(70) - assert "Invalid value passed for seconds." in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_restart_delay(70) + assert "Invalid value passed for seconds." in str(exc.value) def test_get_set_disable_keyboard_on_lock(system): @@ -248,8 +265,9 @@ def test_get_set_disable_keyboard_on_lock(system): assert ret # Test invalid input - ret = system.set_disable_keyboard_on_lock("spongebob") - assert "Invalid String Value for Enabled" in ret + with pytest.raises(SaltInvocationError) as exc: + system.set_disable_keyboard_on_lock("spongebob") + assert "Invalid String Value for Enabled" in str(exc.value) @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -274,8 +292,9 @@ def test_get_set_boot_arch(system): assert ret == "default" # Test invalid input - ret = system.set_boot_arch("spongebob") - assert "Invalid value passed for arch" in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_boot_arch("spongebob") + assert "Invalid value passed for arch" in str(exc.value) # A similar test used to be skipped on py3 due to 'hanging', if we see diff --git a/tests/pytests/functional/modules/test_mac_timezone.py b/tests/pytests/functional/modules/test_mac_timezone.py index 57708f0c8ca8..40e1cb6803c0 100644 --- a/tests/pytests/functional/modules/test_mac_timezone.py +++ b/tests/pytests/functional/modules/test_mac_timezone.py @@ -14,7 +14,6 @@ import pytest pytestmark = [ - pytest.mark.flaky(max_runs=4), pytest.mark.skip_if_binaries_missing("systemsetup"), pytest.mark.slow_test, pytest.mark.destructive_test, diff --git a/tests/pytests/functional/modules/test_mac_xattr.py b/tests/pytests/functional/modules/test_mac_xattr.py index 94f1c87267e3..8dd72ac57709 100644 --- a/tests/pytests/functional/modules/test_mac_xattr.py +++ b/tests/pytests/functional/modules/test_mac_xattr.py @@ -4,6 +4,8 @@ import pytest +from salt.exceptions import CommandExecutionError + pytestmark = [ pytest.mark.skip_if_binaries_missing("xattr"), pytest.mark.slow_test, @@ -13,8 +15,8 @@ @pytest.fixture(scope="module") -def xttr(modules): - return modules.xttr +def xattr(modules): + return modules.xattr @pytest.fixture(scope="function") @@ -47,8 +49,9 @@ def test_list_no_xattr(xattr, setup_teardown_vars): assert ret == {} # Test file not found - ret = xattr.list(no_file) - assert f"File not found: {no_file}" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = xattr.list(no_file) + assert f"File not found: {no_file}" in str(exc.value) def test_write(xattr, setup_teardown_vars): @@ -81,8 +84,9 @@ def test_write(xattr, setup_teardown_vars): } # Test file not found - ret = xattr.write(no_file, "patrick", "jellyfish") - assert f"File not found: {no_file}" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = xattr.write(no_file, "patrick", "jellyfish") + assert f"File not found: {no_file}" in str(exc.value) def test_read(xattr, setup_teardown_vars): @@ -105,12 +109,14 @@ def test_read(xattr, setup_teardown_vars): assert ret == "squarepants" # Test file not found - ret = xattr.read(no_file, "spongebob") - assert f"File not found: {no_file}" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = xattr.read(no_file, "spongebob") + assert f"File not found: {no_file}" in str(exc.value) # Test attribute not found - ret = xattr.read(test_file, "patrick") - assert "Attribute not found: patrick" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = xattr.read(test_file, "patrick") + assert "Attribute not found: patrick" in str(exc.value) def test_delete(xattr, setup_teardown_vars): @@ -146,12 +152,14 @@ def test_delete(xattr, setup_teardown_vars): } # Test file not found - ret = xattr.delete(no_file, "spongebob") - assert f"File not found: {no_file}" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = xattr.delete(no_file, "spongebob") + assert f"File not found: {no_file}" in str(exc.value) # Test attribute not found - ret = xattr.delete(test_file, "patrick") - assert "Attribute not found: patrick" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = xattr.delete(test_file, "patrick") + assert "Attribute not found: patrick" in str(exc.value) def test_clear(xattr, setup_teardown_vars): @@ -180,5 +188,6 @@ def test_clear(xattr, setup_teardown_vars): assert ret # Test file not found - ret = xattr.clear(no_file) - assert f"File not found: {no_file}" in ret + with pytest.raises(CommandExecutionError) as exc: + ret = xattr.clear(no_file) + assert f"File not found: {no_file}" in str(exc.value) From 63d26164b4709d5574df112bf6ac08699d110eca Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 22 Nov 2023 21:02:59 +0000 Subject: [PATCH 31/37] Just run the required fixtures, for the tests needing them Signed-off-by: Pedro Algarvio --- .../functional/modules/test_mac_system.py | 145 ++++++++++-------- 1 file changed, 85 insertions(+), 60 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_system.py b/tests/pytests/functional/modules/test_mac_system.py index 4570a01783b4..e01e51b4dd36 100644 --- a/tests/pytests/functional/modules/test_mac_system.py +++ b/tests/pytests/functional/modules/test_mac_system.py @@ -7,8 +7,6 @@ import pytest from saltfactories.utils import random_string -from salt.exceptions import CommandExecutionError, SaltInvocationError - log = logging.getLogger(__name__) pytestmark = [ @@ -19,55 +17,89 @@ ] -@pytest.fixture(scope="module") +@pytest.fixture def service(modules): return modules.service -@pytest.fixture(scope="module") +@pytest.fixture def system(modules): return modules.system -@pytest.fixture(scope="function", autouse=True) -def _setup_teardown_vars(service, system, grains): +@pytest.fixture +def _remote_login_cleanup(system, grains): + if grains["osmajorrelease"] >= 13: + pytest.skip("SKipping until we figure out how to have full dist access") + + remote_login_enabled = system.get_remote_login() + try: + yield + finally: + if system.get_remote_login() != remote_login_enabled: + system.set_remote_login(remote_login_enabled) + + +@pytest.fixture +def _remote_events_cleanup(system, grains): + if grains["osmajorrelease"] >= 13: + pytest.skip("SKipping until we figure out how to have full dist access") + + remote_events_enabled = system.get_remote_events() + try: + yield + finally: + if system.get_remote_events() != remote_events_enabled: + system.set_remote_events(remote_events_enabled) + + +@pytest.fixture +def _subnet_cleanup(system): + subnet_name = system.get_subnet_name() + try: + yield + finally: + if system.get_subnet_name() != subnet_name: + system.set_subnet_name(subnet_name) - ATRUN_ENABLED = service.enabled("com.apple.atrun") - if grains["osrelease_info"][0] < 13: - # Skipping this MacOSX 13+ until we can figure how to have full disk access enabled. - REMOTE_LOGIN_ENABLED = system.get_remote_login() - REMOTE_EVENTS_ENABLED = system.get_remote_events() +@pytest.fixture +def _keyboard_cleanup(system): + keyboard_disabled = system.get_disable_keyboard_on_lock() + try: + yield + finally: + if system.get_disable_keyboard_on_lock() != keyboard_disabled: + system.set_disable_keyboard_on_lock(keyboard_disabled) - SUBNET_NAME = system.get_subnet_name() - KEYBOARD_DISABLED = system.get_disable_keyboard_on_lock() +@pytest.fixture +def _computer_name_cleanup(system): + computer_name = system.get_computer_name() + try: + yield + finally: + if system.get_computer_name() != computer_name: + system.set_computer_name(computer_name) + +@pytest.fixture(autouse=True) +def _setup_teardown_vars(service, system): + atrun_enabled = service.enabled("com.apple.atrun") try: yield finally: - if not ATRUN_ENABLED: + if not atrun_enabled: atrun = "/System/Library/LaunchDaemons/com.apple.atrun.plist" service.stop(atrun) - if grains["osrelease_info"][0] < 13: - # Skipping this MacOSX 13+ until we can figure how to have full disk access enabled. - system.set_remote_login(REMOTE_LOGIN_ENABLED) - system.set_remote_events(REMOTE_EVENTS_ENABLED) - system.set_subnet_name(SUBNET_NAME) - system.set_disable_keyboard_on_lock(KEYBOARD_DISABLED) - -def test_get_set_remote_login(system, grains): +@pytest.mark.usefixtures("_remote_login_cleanup") +def test_get_set_remote_login(system): """ Test system.get_remote_login Test system.set_remote_login """ - if grains["osrelease_info"][0] >= 13: - pytest.skip( - "Skipping this MacOSX 13+ until we can figure how to have full disk access enabled." - ) - # Normal Functionality ret = system.set_remote_login(True) assert ret @@ -107,21 +139,16 @@ def test_get_set_remote_login(system, grains): assert ret # Test invalid input - with pytest.raises(CommandExecutionError) as exc: - system.set_remote_login("spongebob") - assert "Invalid String Value for Enabled" in str(exc.value) + ret = system.set_remote_login("spongebob") + assert "Invalid String Value for Enabled" in ret -def test_get_set_remote_events(system, grains): +@pytest.mark.usefixtures("_remote_events_cleanup") +def test_get_set_remote_events(system): """ Test system.get_remote_events Test system.set_remote_events """ - if grains["osrelease_info"][0] >= 13: - pytest.skip( - "Skipping this MacOSX 13+ until we can figure how to have full disk access enabled." - ) - # Normal Functionality ret = system.set_remote_events(True) assert ret @@ -161,23 +188,23 @@ def test_get_set_remote_events(system, grains): assert ret # Test invalid input - with pytest.raises(CommandExecutionError) as exc: - system.set_remote_events("spongebob") - assert "Invalid String Value for Enabled" in str(exc.value) + ret = system.set_remote_events("spongebob") + assert "Invalid String Value for Enabled" in ret +@pytest.mark.usefixtures("_subnet_cleanup") def test_get_set_subnet_name(system): """ Test system.get_subnet_name Test system.set_subnet_name """ - SET_SUBNET_NAME = random_string("RS-", lowercase=False) + set_subnet_name = random_string("RS-", lowercase=False) - ret = system.set_subnet_name(SET_SUBNET_NAME) + ret = system.set_subnet_name(set_subnet_name) assert ret ret = system.get_subnet_name() - assert ret == SET_SUBNET_NAME + assert ret == set_subnet_name def test_get_list_startup_disk(system): @@ -195,9 +222,8 @@ def test_get_list_startup_disk(system): assert startup_disk in ret # Test passing set a bad disk - with pytest.raises(SaltInvocationError) as exc: - system.set_startup_disk("spongebob") - assert "Invalid value passed for path." in str(exc.value) + ret = system.set_startup_disk("spongebob") + assert "Invalid value passed for path." in ret @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -216,11 +242,11 @@ def test_get_set_restart_delay(system): assert ret == "90 seconds" # Pass set bad value for seconds - with pytest.raises(CommandExecutionError) as exc: - system.set_restart_delay(70) - assert "Invalid value passed for seconds." in str(exc.value) + ret = system.set_restart_delay(70) + assert "Invalid value passed for seconds." in ret +@pytest.mark.usefixtures("_keyboard_cleanup") def test_get_set_disable_keyboard_on_lock(system): """ Test system.get_disable_keyboard_on_lock @@ -265,9 +291,8 @@ def test_get_set_disable_keyboard_on_lock(system): assert ret # Test invalid input - with pytest.raises(SaltInvocationError) as exc: - system.set_disable_keyboard_on_lock("spongebob") - assert "Invalid String Value for Enabled" in str(exc.value) + ret = system.set_disable_keyboard_on_lock("spongebob") + assert "Invalid String Value for Enabled" in ret @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -292,9 +317,8 @@ def test_get_set_boot_arch(system): assert ret == "default" # Test invalid input - with pytest.raises(CommandExecutionError) as exc: - system.set_boot_arch("spongebob") - assert "Invalid value passed for arch" in str(exc.value) + ret = system.set_boot_arch("spongebob") + assert "Invalid value passed for arch" in ret # A similar test used to be skipped on py3 due to 'hanging', if we see @@ -302,20 +326,21 @@ def test_get_set_boot_arch(system): # investigate # @pytest.mark.skipif(salt.utils.platform.is_darwin() and six.PY3, reason='This test hangs on OS X on Py3. Skipping until #53566 is merged.') @pytest.mark.destructive_test +@pytest.mark.usefixtures("_computer_name_cleanup") def test_get_set_computer_name(system): """ Test system.get_computer_name Test system.set_computer_name """ - SET_COMPUTER_NAME = random_string("RS-", lowercase=False) + set_computer_name = random_string("RS-", lowercase=False) - COMPUTER_NAME = system.get_computer_name() + computer_name = system.get_computer_name() - log.debug("Set name is %s", SET_COMPUTER_NAME) - ret = system.set_computer_name(SET_COMPUTER_NAME) + log.debug("set name is %s", set_computer_name) + ret = system.set_computer_name(set_computer_name) assert ret ret = system.get_computer_name() - assert ret == SET_COMPUTER_NAME + assert ret == set_computer_name - system.set_computer_name(COMPUTER_NAME) + system.set_computer_name(computer_name) From fd75e4023a722b6f9372a4e769c2a398c791f0fd Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 22 Nov 2023 13:31:52 -0800 Subject: [PATCH 32/37] removing fixture from mac_assistant tests. --- tests/pytests/functional/modules/test_mac_assistive.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/pytests/functional/modules/test_mac_assistive.py b/tests/pytests/functional/modules/test_mac_assistive.py index 32f7c0b00071..64c5657525c7 100644 --- a/tests/pytests/functional/modules/test_mac_assistive.py +++ b/tests/pytests/functional/modules/test_mac_assistive.py @@ -7,7 +7,6 @@ pytestmark = [ pytest.mark.destructive_test, pytest.mark.skip_if_not_root, - pytest.mark.skip_initial_gh_actions_failure, pytest.mark.skip_unless_on_darwin, ] From 49cc7f513c7c6c22f4c9095a12e156973557bb02 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 22 Nov 2023 13:47:33 -0800 Subject: [PATCH 33/37] restore the pytest.raises calls to catch the exceptions. --- .../functional/modules/test_mac_system.py | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_system.py b/tests/pytests/functional/modules/test_mac_system.py index e01e51b4dd36..3858ccf01c91 100644 --- a/tests/pytests/functional/modules/test_mac_system.py +++ b/tests/pytests/functional/modules/test_mac_system.py @@ -7,6 +7,8 @@ import pytest from saltfactories.utils import random_string +from salt.exceptions import CommandExecutionError, SaltInvocationError + log = logging.getLogger(__name__) pytestmark = [ @@ -139,8 +141,9 @@ def test_get_set_remote_login(system): assert ret # Test invalid input - ret = system.set_remote_login("spongebob") - assert "Invalid String Value for Enabled" in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_remote_login("spongebob") + assert "Invalid String Value for Enabled" in str(exc.value) @pytest.mark.usefixtures("_remote_events_cleanup") @@ -188,8 +191,9 @@ def test_get_set_remote_events(system): assert ret # Test invalid input - ret = system.set_remote_events("spongebob") - assert "Invalid String Value for Enabled" in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_remote_events("spongebob") + assert "Invalid String Value for Enabled" in str(exc.value) @pytest.mark.usefixtures("_subnet_cleanup") @@ -222,8 +226,9 @@ def test_get_list_startup_disk(system): assert startup_disk in ret # Test passing set a bad disk - ret = system.set_startup_disk("spongebob") - assert "Invalid value passed for path." in ret + with pytest.raises(SaltInvocationError) as exc: + system.set_startup_disk("spongebob") + assert "Invalid value passed for path." in str(exc.value) @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -242,8 +247,9 @@ def test_get_set_restart_delay(system): assert ret == "90 seconds" # Pass set bad value for seconds - ret = system.set_restart_delay(70) - assert "Invalid value passed for seconds." in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_restart_delay(70) + assert "Invalid value passed for seconds." in str(exc.value) @pytest.mark.usefixtures("_keyboard_cleanup") @@ -291,8 +297,9 @@ def test_get_set_disable_keyboard_on_lock(system): assert ret # Test invalid input - ret = system.set_disable_keyboard_on_lock("spongebob") - assert "Invalid String Value for Enabled" in ret + with pytest.raises(SaltInvocationError) as exc: + system.set_disable_keyboard_on_lock("spongebob") + assert "Invalid String Value for Enabled" in str(exc.value) @pytest.mark.skip(reason="Skip this test until mac fixes it.") @@ -317,8 +324,9 @@ def test_get_set_boot_arch(system): assert ret == "default" # Test invalid input - ret = system.set_boot_arch("spongebob") - assert "Invalid value passed for arch" in ret + with pytest.raises(CommandExecutionError) as exc: + system.set_boot_arch("spongebob") + assert "Invalid value passed for arch" in str(exc.value) # A similar test used to be skipped on py3 due to 'hanging', if we see From 2193898376102180fd9b7b9474ebb66c153b4f58 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 22 Nov 2023 13:55:53 -0800 Subject: [PATCH 34/37] fixing setup fixture for test_mac_group to cleanup properly after each test --- tests/pytests/functional/modules/test_mac_group.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_group.py b/tests/pytests/functional/modules/test_mac_group.py index 9f16b247d618..e5f98f6e63d9 100644 --- a/tests/pytests/functional/modules/test_mac_group.py +++ b/tests/pytests/functional/modules/test_mac_group.py @@ -44,7 +44,7 @@ def rep_user_group(): yield random_string("RS-", lowercase=False) -@pytest.fixture(scope="module", autouse=True) +@pytest.fixture(autouse=True) def _setup_teardown_vars(group, add_group, change_group, del_group): try: yield @@ -73,8 +73,6 @@ def test_mac_group_add(group, add_group): group_info = group.info(add_group) assert group_info["name"] == add_group - group.delete(add_group) - def test_mac_group_delete(group, del_group): """ @@ -105,8 +103,6 @@ def test_mac_group_chgid(group, change_group): group_info = group.info(change_group) assert group_info["gid"] == 6789 - group.delete(change_group) - def test_mac_adduser(group, add_group, add_user): """ @@ -122,8 +118,6 @@ def test_mac_adduser(group, add_group, add_user): group_info = group.info(add_group) assert add_user == "".join(group_info["members"]) - group.delete(add_group) - def test_mac_deluser(group, add_group, add_user): """ @@ -143,8 +137,6 @@ def test_mac_deluser(group, add_group, add_user): group_info = group.info(add_group) assert add_user not in "".join(group_info["members"]) - group.delete(add_group) - def test_mac_members(group, add_group, add_user, rep_user_group): """ @@ -168,8 +160,6 @@ def test_mac_members(group, add_group, add_user, rep_user_group): assert rep_user_group in str(group_info["members"]) assert add_user not in str(group_info["members"]) - group.delete(add_group) - def test_mac_getent(group, add_group, add_user): """ @@ -189,5 +179,3 @@ def test_mac_getent(group, add_group, add_user): assert getinfo assert add_group in str(getinfo) assert add_user in str(getinfo) - - group.delete(add_group) From 3d375b7776289b24c07b76fcb6d1e066345f299b Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 22 Nov 2023 14:00:51 -0800 Subject: [PATCH 35/37] remove skip for timezone tests --- .../functional/modules/test_mac_timezone.py | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_timezone.py b/tests/pytests/functional/modules/test_mac_timezone.py index 40e1cb6803c0..4a9e6e38ee80 100644 --- a/tests/pytests/functional/modules/test_mac_timezone.py +++ b/tests/pytests/functional/modules/test_mac_timezone.py @@ -49,9 +49,6 @@ def _setup_teardown_vars(timezone): timezone.set_time(CURRENT_TIME) -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_get_set_date(timezone): """ @@ -100,9 +97,6 @@ def test_set_time(timezone): assert ret == "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_get_set_zone(timezone): """ @@ -119,9 +113,6 @@ def test_get_set_zone(timezone): assert ret == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_get_offset(timezone): """ @@ -139,9 +130,6 @@ def test_get_offset(timezone): assert ret == "-0700" -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_get_set_zonecode(timezone): """ @@ -170,9 +158,6 @@ def test_list_zones(timezone): assert "America/Los_Angeles" in zones -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_zone_compare(timezone): """ @@ -186,9 +171,6 @@ def test_zone_compare(timezone): assert not ret -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_get_set_using_network_time(timezone): """ @@ -208,9 +190,6 @@ def test_get_set_using_network_time(timezone): assert not ret -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_get_set_time_server(timezone): """ From 79da7dbc7bfabbd974da98687cfc9199c7e486d5 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 22 Nov 2023 15:18:20 -0800 Subject: [PATCH 36/37] unskips and fixes to test_mac_timezone.py --- .../functional/modules/test_mac_timezone.py | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/tests/pytests/functional/modules/test_mac_timezone.py b/tests/pytests/functional/modules/test_mac_timezone.py index 4a9e6e38ee80..251db5417323 100644 --- a/tests/pytests/functional/modules/test_mac_timezone.py +++ b/tests/pytests/functional/modules/test_mac_timezone.py @@ -13,6 +13,8 @@ import pytest +from salt.exceptions import SaltInvocationError + pytestmark = [ pytest.mark.skip_if_binaries_missing("systemsetup"), pytest.mark.slow_test, @@ -62,11 +64,12 @@ def test_get_set_date(timezone): assert ret == "2/20/2011" # Test bad date format - ret = timezone.set_date("13/12/2014") - assert ( - ret - == "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014" - ) + with pytest.raises(SaltInvocationError) as exc: + ret = timezone.set_date("13/12/2014") + assert ( + "ERROR executing 'timezone.set_date': Invalid Date/Time Format: 13/12/2014" + in str(exc.value) + ) @pytest.mark.slow_test @@ -80,9 +83,6 @@ def test_get_time(timezone): assert isinstance(obj_date, datetime.date) -@pytest.mark.skip( - reason="Skip until we can figure out why modifying the system clock causes ZMQ errors", -) @pytest.mark.destructive_test def test_set_time(timezone): """ @@ -93,8 +93,12 @@ def test_set_time(timezone): assert ret # Test bad time format - ret = timezone.set_time("3:71") - assert ret == "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" + with pytest.raises(SaltInvocationError) as exc: + ret = timezone.set_time("3:71") + assert ( + "ERROR executing 'timezone.set_time': Invalid Date/Time Format: 3:71" + in str(exc.value) + ) @pytest.mark.destructive_test @@ -106,11 +110,17 @@ def test_get_set_zone(timezone): # Correct Functionality ret = timezone.set_zone("Pacific/Wake") assert ret + + ret = timezone.get_zone() assert ret == "Pacific/Wake" # Test bad time zone - ret = timezone.set_zone("spongebob") - assert ret == "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" + with pytest.raises(SaltInvocationError) as exc: + ret = timezone.set_zone("spongebob") + assert ( + "ERROR executing 'timezone.set_zone': Invalid Timezone: spongebob" + in str(exc.value) + ) @pytest.mark.destructive_test @@ -126,8 +136,9 @@ def test_get_offset(timezone): ret = timezone.set_zone("America/Los_Angeles") assert ret + ret = timezone.get_offset() assert isinstance(ret, str) - assert ret == "-0700" + assert ret == "-0800" @pytest.mark.destructive_test @@ -138,13 +149,15 @@ def test_get_set_zonecode(timezone): """ ret = timezone.set_zone("America/Los_Angeles") assert ret + ret = timezone.get_zone() assert isinstance(ret, str) - assert ret == "PDT" + assert ret == "America/Los_Angeles" ret = timezone.set_zone("Pacific/Wake") assert ret + ret = timezone.get_zone() assert isinstance(ret, str) - assert ret == "WAKT" + assert ret == "Pacific/Wake" @pytest.mark.slow_test From bd076b9f7645d258d977d2ac486b58c7b8c5a4ba Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 22 Nov 2023 16:12:34 -0800 Subject: [PATCH 37/37] Adding a check to skip mac_assistive tests if the osa_script is unable to be installed. --- tests/pytests/functional/modules/test_mac_assistive.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/pytests/functional/modules/test_mac_assistive.py b/tests/pytests/functional/modules/test_mac_assistive.py index 64c5657525c7..1c5206ed04a6 100644 --- a/tests/pytests/functional/modules/test_mac_assistive.py +++ b/tests/pytests/functional/modules/test_mac_assistive.py @@ -4,6 +4,8 @@ import pytest +from salt.exceptions import CommandExecutionError + pytestmark = [ pytest.mark.destructive_test, pytest.mark.skip_if_not_root, @@ -23,7 +25,11 @@ def osa_script(): @pytest.fixture(scope="function", autouse=True) def _setup_teardown_vars(assistive, osa_script): - assistive.install(osa_script, True) + try: + ret = assistive.install(osa_script, True) + except CommandExecutionError as exc: + pytest.skip(f"Unable to install {osa_script} - {str(exc.value)}") + try: yield finally: