desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Perform some tests around creation of the given grants'
def _addGrantRoutine(self, grant, user, db, grant_option=False, escape=True, **kwargs):
ret = self.run_function('mysql.grant_add', grant=grant, database=db, user=user, grant_option=grant_option, escape=escape, **kwargs) self.assertEqual(True, ret, "Calling grant_add on user '{0}' and grants '{1}' did not return True: {2}".format(user, grant, repr(ret))) ret ...
'Test user grant methods'
@destructiveTest def testGrants(self):
self._addGrantRoutine(grant='SELECT, INSERT,UPDATE, CREATE', user=self.users['user1']['name'], db=(self.testdb1 + '.*'), grant_option=True, escape=True, connection_user=self.user, connection_pass=self.password) self._addGrantRoutine(grant='INSERT, SELECT', user=self.users['user1']['name'], db=((self.te...
'Sets up the test requirements'
def setUp(self):
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))
'Tests that writes and reads macdefaults'
def test_macdefaults_write_read(self):
write_domain = self.run_function('macdefaults.write', [DEFAULT_DOMAIN, DEFAULT_KEY, DEFAULT_VALUE]) self.assertTrue(write_domain) read_domain = self.run_function('macdefaults.read', [DEFAULT_DOMAIN, DEFAULT_KEY]) self.assertTrue(read_domain) self.assertEqual(read_domain, DEFAULT_VALUE)
'Get current settings'
def setUp(self):
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(MacSoftwareUpdateModuleTest, self).setUp()
'Reset to original settings'
def tearDown(self):
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_funct...
'Test softwareupdate.list_available'
def test_list_available(self):
self.assertIsInstance(self.run_function('softwareupdate.list_available'), dict)
'Test softwareupdate.ignore Test softwareupdate.list_ignored Test softwareupdate.reset_ignored'
@destructiveTest def test_ignore(self):
self.assertTrue(self.run_function('softwareupdate.reset_ignored')) self.assertEqual(self.run_function('softwareupdate.list_ignored'), []) self.assertTrue(self.run_function('softwareupdate.ignore', ['spongebob'])) self.assertTrue(self.run_function('softwareupdate.ignore', ['squidward'])) self.assertI...
'Test softwareupdate.schedule_enable Test softwareupdate.schedule_enabled'
@destructiveTest def test_schedule(self):
self.assertTrue(self.run_function('softwareupdate.schedule_enable', [True])) self.assertTrue(self.run_function('softwareupdate.schedule_enabled')) self.assertTrue(self.run_function('softwareupdate.schedule_enable', [False])) self.assertFalse(self.run_function('softwareupdate.schedule_enabled'))
'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...'
@destructiveTest def test_update(self):
self.assertIsInstance(self.run_function('softwareupdate.update_all'), dict) self.assertFalse(self.run_function('softwareupdate.update_available', ['spongebob'])) self.assertIn('Update not available', self.run_function('softwareupdate.update', ['spongebob']))
'Test softwareupdate.list_downloads'
def test_list_downloads(self):
self.assertIsInstance(self.run_function('softwareupdate.list_downloads'), list)
'Test softwareupdate.download Need to know the names of updates that are available to properly test the download function'
@destructiveTest def test_download(self):
self.assertIn('Update not available', self.run_function('softwareupdate.download', ['spongebob']))
'Test softwareupdate.download_all'
@destructiveTest def test_download_all(self):
self.assertIsInstance(self.run_function('softwareupdate.download_all'), list)
'Test softwareupdate.download_all'
@destructiveTest def test_get_set_reset_catalog(self):
self.assertTrue(self.run_function('softwareupdate.reset_catalog')) self.assertEqual(self.run_function('softwareupdate.get_catalog'), 'Default') self.assertTrue(self.run_function('softwareupdate.set_catalog', ['spongebob'])) self.assertEqual(self.run_function('softwareupdate.get_catalog'), 'spongebob') ...
'Get current settings'
def setUp(self):
super(GroupModuleTest, self).setUp() self._user = self.__random_string() self._user1 = self.__random_string() self._no_user = self.__random_string() self._group = self.__random_string() self._no_group = self.__random_string() self._gid = 64989 self._new_gid = 64998 os_grain = self.ru...
'Reset to original settings'
@destructiveTest def tearDown(self):
self.run_function('user.delete', [self._user]) self.run_function('user.delete', [self._user1]) self.run_function('group.delete', [self._group])
'Generates a random names'
def __random_string(self, size=6):
return ('tg-' + ''.join((random.choice((string.ascii_lowercase + string.digits)) for x in range(size))))
'Test the add group function'
@destructiveTest def test_add(self):
self.assertTrue(self.run_function('group.add', [self._group, self._gid])) group_info = self.run_function('group.info', [self._group]) self.assertEqual(group_info['name'], self._group) self.assertEqual(group_info['gid'], self._gid) self.assertFalse(self.run_function('group.add', [self._group, self._g...
'Test the delete group function'
@destructiveTest def test_delete(self):
self.assertTrue(self.run_function('group.add', [self._group])) self.assertTrue(self.run_function('group.delete', [self._group])) self.assertFalse(self.run_function('group.delete', [self._no_group]))
'Test the info group function'
@destructiveTest def test_info(self):
self.run_function('group.add', [self._group, self._gid]) self.run_function('user.add', [self._user]) self.run_function('group.adduser', [self._group, self._user]) group_info = self.run_function('group.info', [self._group]) self.assertEqual(group_info['name'], self._group) self.assertEqual(group_...
'Test the change gid function'
@destructiveTest def test_chgid(self):
self.run_function('group.add', [self._group, self._gid]) self.assertTrue(self.run_function('group.chgid', [self._group, self._new_gid])) group_info = self.run_function('group.info', [self._group]) self.assertEqual(group_info['gid'], self._new_gid)
'Test the add user to group function'
@destructiveTest def test_adduser(self):
self.run_function('group.add', [self._group, self._gid]) self.run_function('user.add', [self._user]) self.assertTrue(self.run_function('group.adduser', [self._group, self._user])) group_info = self.run_function('group.info', [self._group]) self.assertIn(self._user, group_info['members']) self.as...
'Test the delete user from group function'
@destructiveTest def test_deluser(self):
self.run_function('group.add', [self._group, self._gid]) self.run_function('user.add', [self._user]) self.run_function('group.adduser', [self._group, self._user]) self.assertTrue(self.run_function('group.deluser', [self._group, self._user])) group_info = self.run_function('group.info', [self._group]...
'Test the members function'
@destructiveTest def test_members(self):
self.run_function('group.add', [self._group, self._gid]) self.run_function('user.add', [self._user]) self.run_function('user.add', [self._user1]) m = '{0},{1}'.format(self._user, self._user1) self.assertTrue(self.run_function('group.members', [self._group, m])) group_info = self.run_function('gr...
'Test the getent function'
@destructiveTest def test_getent(self):
self.run_function('group.add', [self._group, self._gid]) self.run_function('user.add', [self._user]) self.run_function('group.adduser', [self._group, self._user]) ginfo = self.run_function('user.getent') self.assertIn(self._group, str(ginfo)) self.assertIn(self._user, str(ginfo)) self.assert...
'test key.finger to ensure we receive a valid fingerprint'
def test_key_finger(self):
out = self.run_function('key.finger') match = re.match('([0-9a-z]{2}:){15,}[0-9a-z]{2}$', out) self.assertTrue(match)
'test key.finger_master to ensure we receive a valid fingerprint'
def test_key_finger_master(self):
out = self.run_function('key.finger_master') match = re.match('([0-9a-z]{2}:){15,}[0-9a-z]{2}$', out) self.assertTrue(match)
'Sets up test requirements.'
def setUp(self):
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))
'Tests the return of get_output_volume.'
def test_get_output_volume(self):
ret = self.run_function('desktop.get_output_volume') self.assertIsNotNone(ret)
'Tests the return of set_output_volume.'
def test_set_output_volume(self):
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) ...
'Tests the return of the screensaver function.'
def test_screensaver(self):
self.assertTrue(self.run_function('desktop.screensaver'))
'Tests the return of the lock function.'
def test_lock(self):
self.assertTrue(self.run_function('desktop.lock'))
'Tests the return of the say function.'
def test_say(self):
self.assertTrue(self.run_function('desktop.say', ['hello', 'world']))
'Tests the primary_group function'
def test_user_primary_group(self):
name = 'saltyuser' if (self.run_function('user.add', [name]) is not True): self.run_function('user.delete', [name]) self.skipTest('Failed to create a user') try: primary_group = self.run_function('user.primary_group', [name]) uid_info = self.run_function('user.inf...
'Test adding a user'
def test_add_user(self):
user_name = self.__random_string() try: if (self.run_function('user.add', [user_name]) is False): self.run_function('user.delete', [user_name, True, True]) self.skipTest('Failed to create user') user_list = self.run_function('user.list_users') self.assert...
'Test adding a user'
def test_add_group(self):
group_name = self.__random_string() try: if (self.run_function('group.add', [group_name]) is False): self.run_function('group.delete', [group_name, True, True]) self.skipTest('Failed to create group') group_list = self.run_function('group.list_groups') se...
'Test adding a user to a group'
def test_add_user_to_group(self):
group_name = self.__random_string() user_name = self.__random_string() try: if (self.run_function('group.add', [group_name])['result'] is not True): self.run_function('group.delete', [group_name, True, True]) self.skipTest('Failed to create group') if (self.r...
'Get current settings'
def setUp(self):
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.COMPUTER_NAME = self.run_function('system.get_computer_name') self.S...
'Reset to original settings'
def tearDown(self):
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...
'Test system.get_remote_login Test system.set_remote_login'
@destructiveTest def test_get_set_remote_login(self):
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')) self.assertTrue(self.run_function(...
'Test system.get_remote_events Test system.set_remote_events'
@destructiveTest def test_get_set_remote_events(self):
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')) self.assertTrue(self.run_funct...
'Test system.get_computer_name Test system.set_computer_name'
@destructiveTest def test_get_set_computer_name(self):
self.assertTrue(self.run_function('system.set_computer_name', [SET_COMPUTER_NAME])) self.assertEqual(self.run_function('system.get_computer_name'), SET_COMPUTER_NAME)
'Test system.get_subnet_name Test system.set_subnet_name'
@destructiveTest def test_get_set_subnet_name(self):
self.assertTrue(self.run_function('system.set_subnet_name', [SET_SUBNET_NAME])) self.assertEqual(self.run_function('system.get_subnet_name'), SET_SUBNET_NAME)
'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'
def test_get_list_startup_disk(self):
ret = self.run_function('system.list_startup_disks') self.assertIsInstance(ret, list) self.assertIn(self.run_function('system.get_startup_disk'), ret) self.assertIn('Invalid value passed for path.', self.run_function('system.set_startup_disk', ['spongebob']))
'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'
@skipIf(True, 'Skip this test until mac fixes it.') def test_get_set_restart_delay(self):
self.assertTrue(self.run_function('system.set_restart_delay', [90])) self.assertEqual(self.run_function('system.get_restart_delay'), '90 seconds') self.assertIn('Invalid value passed for seconds.', self.run_function('system.set_restart_delay', [70]))
'Test system.get_disable_keyboard_on_lock Test system.set_disable_keyboard_on_lock'
def test_get_set_disable_keyboard_on_lock(self):
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_o...
'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'
@skipIf(True, 'Skip this test until mac fixes it.') def test_get_set_boot_arch(self):
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') self.assertIn('Inval...
'Set up Linux test environment'
def setUp(self):
ret_grain = self.run_function('grains.item', ['kernel']) if ('Linux' not in ret_grain['kernel']): self.skipTest('For Linux only') super(TimezoneLinuxModuleTest, self).setUp()
'Set up Solaris test environment'
def setUp(self):
ret_grain = self.run_function('grains.item', ['os_family']) if ('Solaris' not in ret_grain['os_family']): self.skipTest('For Solaris only') super(TimezoneSolarisModuleTest, self).setUp()
'pillar.data'
def test_data(self):
grains = self.run_function('grains.items') pillar = self.run_function('pillar.data') self.assertEqual(pillar['os'], grains['os']) self.assertEqual(pillar['monty'], 'python') if (grains['os'] == 'Fedora'): self.assertEqual(pillar['class'], 'redhat') else: self.assertEqual(pillar['...
'pillar[\'master\'][\'file_roots\'] is overwritten by the master in order to use the fileclient interface to read the pillar files. We should restore the actual file_roots when we send the pillar back to the minion.'
def test_issue_5449_report_actual_file_roots_in_pillar(self):
self.assertIn(TMP_STATE_TREE, self.run_function('pillar.data')['master']['file_roots']['base'])
'pillar.data for ext_pillar cmd.yaml'
def test_ext_cmd_yaml(self):
self.assertEqual(self.run_function('pillar.data')['ext_spam'], 'eggs')
'Test to ensure we get expected output from pillar.items'
def test_pillar_items(self):
get_items = self.run_function('pillar.items') self.assertDictContainsSubset({'monty': 'python'}, get_items) self.assertDictContainsSubset({'knights': ['Lancelot', 'Galahad', 'Bedevere', 'Robin']}, get_items)
'Test git.add with a directory'
def test_add_dir(self):
newdir = 'quux' newdir_path = os.path.join(self.repo, newdir) _makedirs(newdir_path) files = [os.path.join(newdir_path, x) for x in self.files] files_relpath = [os.path.join(newdir, x) for x in self.files] for path in files: with salt.utils.files.fopen(path, 'w') as fp_: fp_....
'Test git.add with a file'
def test_add_file(self):
filename = 'quux' file_path = os.path.join(self.repo, filename) with salt.utils.files.fopen(file_path, 'w') as fp_: fp_.write((('This is a test file named ' + filename) + '.\n')) ret = self.run_function('git.add', [self.repo, filename]) self.assertEqual(ret, "add '{0}'"....
'Test git.archive'
def test_archive(self):
tar_archive = os.path.join(TMP, 'test_archive.tar.gz') self.assertTrue(self.run_function('git.archive', [self.repo, tar_archive], prefix='foo/')) self.assertTrue(tarfile.is_tarfile(tar_archive)) with closing(tarfile.open(tar_archive, 'r')) as tar_obj: self.assertEqual(tar_obj.getnames(), ['foo',...
'Test git.archive on a subdir, giving only a partial copy of the repo in the resulting archive'
def test_archive_subdir(self):
tar_archive = os.path.join(TMP, 'test_archive.tar.gz') self.assertTrue(self.run_function('git.archive', [os.path.join(self.repo, 'qux'), tar_archive], prefix='foo/')) self.assertTrue(tarfile.is_tarfile(tar_archive)) with closing(tarfile.open(tar_archive, 'r')) as tar_obj: self.assertEqual(tar_ob...
'Test creating, renaming, and deleting a branch using git.branch'
def test_branch(self):
renamed_branch = 'ihavebeenrenamed' self.assertTrue(self.run_function('git.branch', [self.repo, self.branches[1]])) self.assertTrue(self.run_function('git.branch', [self.repo, renamed_branch], opts=('-m ' + self.branches[1]))) self.assertTrue(self.run_function('git.branch', [self.repo, renamed_branch...
'Test checking out a new branch and then checking out master again'
def test_checkout(self):
new_branch = 'iamanothernewbranch' self.assertEqual(self.run_function('git.checkout', [self.repo, 'HEAD'], opts=('-b ' + new_branch)), (("Switched to a new branch '" + new_branch) + "'")) self.assertTrue(("Switched to branch 'master'" in self.run_function('git.checkout', [self.rep...
'Test git.checkout without a rev, both with -b in opts and without'
def test_checkout_no_rev(self):
new_branch = 'iamanothernewbranch' self.assertEqual(self.run_function('git.checkout', [self.repo], rev=None, opts=('-b ' + new_branch)), (("Switched to a new branch '" + new_branch) + "'")) self.assertTrue(("'rev' argument is required unless -b or -B in opts" in ...
'Test cloning an existing repo'
def test_clone(self):
clone_parent_dir = tempfile.mkdtemp(dir=TMP) self.assertTrue(self.run_function('git.clone', [clone_parent_dir, self.repo])) shutil.rmtree(clone_parent_dir, True)
'Test cloning an existing repo with an alternate name for the repo dir'
def test_clone_with_alternate_name(self):
clone_parent_dir = tempfile.mkdtemp(dir=TMP) clone_name = os.path.basename(self.repo) self.assertTrue(self.run_function('git.clone', [clone_parent_dir, self.repo], name=clone_name)) shutil.rmtree(clone_parent_dir, True)
'Test git.commit two ways: 1) First using git.add, then git.commit 2) Using git.commit with the \'filename\' argument to skip staging'
def test_commit(self):
filename = 'foo' commit_re_prefix = '^\\[master [0-9a-f]+\\] ' with salt.utils.files.fopen(os.path.join(self.repo, filename), 'a') as fp_: fp_.write('Added a line\n') self.run_function('git.add', [self.repo, filename]) commit_msg = ('Add a line to ' + filename) re...
'Test setting, getting, and unsetting config values WARNING: This test will modify and completely remove a config section \'foo\', both in the repo created in setUp() and in the user\'s global .gitconfig.'
def test_config(self):
def _clear_config(): cmds = (['git', 'config', '--remove-section', 'foo'], ['git', 'config', '--global', '--remove-section', 'foo']) for cmd in cmds: with salt.utils.files.fopen(os.devnull, 'w') as devnull: try: subprocess.check_call(cmd, stderr=devnul...
'Test git.current_branch'
def test_current_branch(self):
self.assertEqual(self.run_function('git.current_branch', [self.repo]), 'master')
'Test git.describe'
def test_describe(self):
self.assertEqual(self.run_function('git.describe', [self.repo]), self.tags[0])
'Use git.init to init a new repo'
def test_init(self):
new_repo = tempfile.mkdtemp(dir=TMP) if salt.utils.platform.is_windows(): new_repo = new_repo.replace('\\', '/') tmp_dir = os.path.basename(new_repo) git_ret = self.run_function('git.init', [new_repo]).lower() self.assertIn('Initialized empty Git repository in'.lower(...
'Test git.list_branches'
def test_list_branches(self):
self.assertEqual(self.run_function('git.list_branches', [self.repo]), sorted(self.branches))
'Test git.list_tags'
def test_list_tags(self):
self.assertEqual(self.run_function('git.list_tags', [self.repo]), sorted(self.tags))
'Test git.merge # TODO: Test more than just a fast-forward merge'
def test_merge(self):
ret = self.run_function('git.merge', [self.repo], rev=self.branches[1]) self.assertTrue(('Fast-forward' in ret.splitlines()))
'Test git.merge_base, git.merge_tree and git.revision TODO: Test all of the arguments'
def test_merge_base_and_tree(self):
head_rev = self.run_function('git.revision', [self.repo], rev='HEAD') self.assertTrue((len(head_rev) == 40)) second_rev = self.run_function('git.revision', [self.repo], rev=self.branches[1]) self.assertTrue((len(second_rev) == 40)) self.assertEqual(self.run_function('git.merge_base', [self.repo], re...
'Test git.rebase'
def test_rebase(self):
file_path = os.path.join(self.repo, self.files[1]) with salt.utils.files.fopen(file_path, 'a') as fp_: fp_.write('Added a line\n') self.assertTrue(('ERROR' not in self.run_function('git.commit', [self.repo, ('Added a line to ' + self.files[1])], filename=self.files[1]))) self.a...
'Test setting a remote (git.remote_set), and getting a remote (git.remote_get and git.remotes) TODO: Properly mock fetching a remote (git.fetch), and build out more robust testing that confirms that the https auth bits work.'
def test_remotes(self):
remotes = {'first': {'fetch': '/dev/null', 'push': '/dev/null'}, 'second': {'fetch': '/dev/null', 'push': '/dev/stdout'}} self.assertEqual(self.run_function('git.remote_set', [self.repo, remotes['first']['fetch']], remote='first'), remotes['first']) self.assertEqual(self.run_function('git.remote_set', [self...
'Test git.reset TODO: Test more than just a hard reset'
def test_reset(self):
self.assertTrue(('ERROR' not in self.run_function('git.checkout', [self.repo], rev=self.branches[1]))) self.run_function('git.reset', [self.repo], opts='--hard HEAD~1') head_rev = self.run_function('git.revision', [self.repo], rev='HEAD') self.assertTrue((len(head_rev) == 40)) master_rev = self.r...
'Test git.rev_parse'
def test_rev_parse(self):
self.assertEqual(self.run_function('git.rev_parse', [self.repo, 'HEAD'], opts='--abbrev-ref'), 'master')
'Test git.rm'
def test_rm(self):
single_file = self.files[0] entire_dir = self.dirs[1] self.assertEqual(self.run_function('git.rm', [self.repo, single_file]), (("rm '" + single_file) + "'")) expected = '\n'.join(sorted([(("rm '" + os.path.join(entire_dir, x)) + "'") for x in self.files])) if salt.utils.platform.is_windows(): ...
'Test git.stash # TODO: test more stash actions'
def test_stash(self):
file_path = os.path.join(self.repo, self.files[0]) with salt.utils.files.fopen(file_path, 'a') as fp_: fp_.write('Temp change to be stashed') self.assertTrue(('ERROR' not in self.run_function('git.stash', [self.repo]))) ret = self.run_function('git.stash', [self.repo], action='list')...
'Test git.status'
def test_status(self):
changes = {'modified': ['foo'], 'new': ['thisisdefinitelyanewfile'], 'deleted': ['bar'], 'untracked': ['thisisalsoanewfile']} for filename in changes['modified']: with salt.utils.files.fopen(os.path.join(self.repo, filename), 'a') as fp_: fp_.write('Added a line\n') for filename in...
'Test git.symbolic_ref'
def test_symbolic_ref(self):
self.assertEqual(self.run_function('git.symbolic_ref', [self.repo, 'HEAD'], opts='--quiet'), 'refs/heads/master')
'This tests git.worktree_add, git.is_worktree, git.worktree_rm, and git.worktree_prune. Tests for \'git worktree list\' are covered in tests.unit.modules.git_test.'
@skipIf((not _worktrees_supported()), 'Git 2.5 or newer required for worktree support') def test_worktree_add_rm(self):
if (_git_version() >= LooseVersion('2.6.0')): worktree_add_prefix = 'Preparing ' else: worktree_add_prefix = 'Enter ' worktree_path = tempfile.mkdtemp(dir=TMP) worktree_basename = os.path.basename(worktree_path) worktree_path2 = tempfile.mkdtemp(dir=TMP) if salt.utils.platf...
'Helper function to check if two datetime objects are close enough to the same time.'
def _same_times(self, t1, t2, seconds_diff=30):
return (abs((t1 - t2)) < datetime.timedelta(seconds=seconds_diff))
'Some builds of hwclock don\'t include the `--compare` function needed to test hw/sw clock synchronization. Returns false on systems where it\'s not present so that we can skip the comparison portion of the test.'
def _hwclock_has_compare(self):
res = self.run_function('cmd.run_all', cmd='hwclock -h') return ((res['retcode'] == 0) and (res['stdout'].find('--compare') > 0))
'Check that hw and sw clocks are sync\'d.'
def _test_hwclock_sync(self):
if (not self.run_function('system.has_settable_hwclock')): return None if (not self._hwclock_has_compare()): return None class CompareTimeout(BaseException, ): pass def _alrm_handler(sig, frame): log.warning('hwclock --compare failed to produce output af...
'Test we are able to get the correct time'
def test_get_system_date_time(self):
t1 = datetime.datetime.now() res = self.run_function('system.get_system_date_time') t2 = datetime.datetime.strptime(res, self.fmt_str) msg = 'Difference in times is too large. Now: {0} Fake: {1}'.format(t1, t2) self.assertTrue(self._same_times(t1, t2, seconds_diff=2), msg=...
'Test we are able to get the correct time with utc'
def test_get_system_date_time_utc(self):
t1 = datetime.datetime.utcnow() res = self.run_function('system.get_system_date_time', utc_offset='+0000') t2 = datetime.datetime.strptime(res, self.fmt_str) msg = 'Difference in times is too large. Now: {0} Fake: {1}'.format(t1, t2) self.assertTrue(self._same_times(t1, t2...
'Test changing the system clock. We are only able to set it up to a resolution of a second so this test may appear to run in negative time.'
@destructiveTest @skip_if_not_root def test_set_system_date_time(self):
self._save_time() cmp_time = (datetime.datetime.now() - datetime.timedelta(days=7)) result = self._set_time(cmp_time) time_now = datetime.datetime.now() msg = 'Difference in times is too large. Now: {0} Fake: {1}'.format(time_now, cmp_time) self.assertTrue((result and ...
'Test changing the system clock. We are only able to set it up to a resolution of a second so this test may appear to run in negative time.'
@destructiveTest @skip_if_not_root def test_set_system_date_time_utc(self):
self._save_time() cmp_time = (datetime.datetime.utcnow() - datetime.timedelta(days=7)) result = self._set_time(cmp_time, offset='+0000') time_now = datetime.datetime.utcnow() msg = 'Difference in times is too large. Now: {0} Fake: {1}'.format(time_now, cmp_time) self.a...
'Test changing the system clock. We are only able to set it up to a resolution of a second so this test may appear to run in negative time.'
@destructiveTest @skip_if_not_root def test_set_system_date_time_utcoffset_east(self):
self._save_time() cmp_time = (datetime.datetime.utcnow() - datetime.timedelta(days=7)) time_to_set = (cmp_time - datetime.timedelta(seconds=25200)) result = self._set_time(time_to_set, offset='-0700') time_now = datetime.datetime.utcnow() msg = 'Difference in times is too large. ...
'Test changing the system clock. We are only able to set it up to a resolution of a second so this test may appear to run in negative time.'
@destructiveTest @skip_if_not_root def test_set_system_date_time_utcoffset_west(self):
self._save_time() cmp_time = (datetime.datetime.utcnow() - datetime.timedelta(days=7)) time_to_set = (cmp_time + datetime.timedelta(seconds=7200)) result = self._set_time(time_to_set, offset='+0200') time_now = datetime.datetime.utcnow() msg = 'Difference in times is too large. ...
'Test setting the system time without adjusting the date.'
@destructiveTest @skip_if_not_root def test_set_system_time(self):
cmp_time = datetime.datetime.now().replace(hour=10, minute=5, second=0) self._save_time() result = self.run_function('system.set_system_time', ['10:05:00']) time_now = datetime.datetime.now() msg = 'Difference in times is too large. Now: {0} Fake: {1}'.format(time_now, cmp...
'Test setting the system date without adjusting the time.'
@destructiveTest @skip_if_not_root def test_set_system_date(self):
cmp_time = (datetime.datetime.now() - datetime.timedelta(days=7)) self._save_time() result = self.run_function('system.set_system_date', [cmp_time.strftime('%Y-%m-%d')]) time_now = datetime.datetime.now() msg = 'Difference in times is too large. Now: {0} Fake: {1}'.format(...
'Test getting the system hostname'
@skip_if_not_root def test_get_computer_desc(self):
res = self.run_function('system.get_computer_desc') hostname_cmd = salt.utils.path.which('hostnamectl') if hostname_cmd: desc = self.run_function('cmd.run', ['hostnamectl status --pretty']) self.assertEqual(res, desc) elif (not os.path.isfile('/etc/machine-info')): self.ass...
'Test setting the system hostname'
@destructiveTest @skip_if_not_root def test_set_computer_desc(self):
self._save_machine_info() desc = 'test' ret = self.run_function('system.set_computer_desc', [desc]) computer_desc = self.run_function('system.get_computer_desc') self.assertTrue(ret) self.assertIn(desc, computer_desc)
'Verify platform has a settable hardware clock, if possible.'
@skip_if_not_root def test_has_hwclock(self):
if (self.run_function('grains.get', ['os_family']) == 'NILinuxRT'): self.assertTrue(self.run_function('system._has_settable_hwclock')) self.assertTrue(self._hwclock_has_compare())
'Checks to see if a download error looks transitory'
def _check_download_error(self, ret):
return any(((w in ret) for w in ['URLError', 'Download error']))
'isolate regex for extracting `successful install` message from pip'
def pip_successful_install(self, target, expect=('flake8', 'pep8')):
expect = set(expect) expect_str = '|'.join(expect) success = re.search('^.*Successfully installed\\s([^\\n]+)(?:Clean.*)?', target, (re.M | re.S)) success_for = (re.findall('({0})(?:-(?:[\\d\\.-]))?'.format(expect_str), success.groups()[0]) if success else []) return expect.issubset(set(success_f...
'Test adding and deleting a beacon'
def test_add_and_delete(self):
_add = self.run_function('beacons.add', ['ps', [{'apache2': 'stopped'}]]) self.assertTrue(_add['result']) _save = self.run_function('beacons.save') self.assertTrue(_save['result']) _delete = self.run_function('beacons.delete', ['ps']) self.assertTrue(_delete['result']) self.run_function('bea...
'Test disabling beacons'
def test_disable(self):
_list = self.run_function('beacons.list', return_yaml=False) self.assertIn('ps', _list) ret = self.run_function('beacons.disable') self.assertTrue(ret['result']) _list = self.run_function('beacons.list', return_yaml=False) self.assertFalse(_list['enabled']) ret = self.run_function('beacons.d...
'Test enabling beacons'
def test_enable(self):
_list = self.run_function('beacons.list', return_yaml=False) self.assertIn('ps', _list) ret = self.run_function('beacons.enable') self.assertTrue(ret['result']) _list = self.run_function('beacons.list', return_yaml=False) self.assertTrue(_list['enabled'])
'Test enabled specific beacon'
@skipIf(True, 'Skip until https://github.com/saltstack/salt/issues/31516 problems are resolved.') def test_enabled_beacons(self):
ret = self.run_function('beacons.enable_beacon', ['ps']) self.assertTrue(ret['result']) _list = self.run_function('beacons.list', return_yaml=False) self.assertTrue(_list['ps']['enabled'])