"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/integration/modules/test_grains.py" between
salt-2019.2.0.tar.gz and salt-2019.2.1.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

test_grains.py  (salt-2019.2.0):test_grains.py  (salt-2019.2.1)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' '''
Test the grains module Test the grains module
''' '''
# Import python libs # Import python libs
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import logging import logging
import os import os
import time import time
import pprint
# Import Salt Testing libs # Import Salt Testing libs
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.unit import skipIf from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest, flaky from tests.support.helpers import flaky
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class TestModulesGrains(ModuleCase): class TestModulesGrains(ModuleCase):
''' '''
Test the grains module Test the grains module
''' '''
def test_items(self): def test_items(self):
''' '''
grains.items grains.items
skipping to change at line 146 skipping to change at line 147
grains = ['num_cpus', 'mem_total', 'num_gpus', 'uid'] grains = ['num_cpus', 'mem_total', 'num_gpus', 'uid']
os = self.run_function('grains.get', ['os']) os = self.run_function('grains.get', ['os'])
for grain in grains: for grain in grains:
get_grain = self.run_function('grains.get', [grain]) get_grain = self.run_function('grains.get', [grain])
if os == 'Windows' and grain in ['uid']: if os == 'Windows' and grain in ['uid']:
self.assertEqual(get_grain, '') self.assertEqual(get_grain, '')
continue continue
self.assertIsInstance( self.assertIsInstance(
get_grain, int, msg='grain: {0} is not an int or empty'.format(g rain)) get_grain, int, msg='grain: {0} is not an int or empty'.format(g rain))
@destructiveTest
class GrainsAppendTestCase(ModuleCase): class GrainsAppendTestCase(ModuleCase):
''' '''
Tests written specifically for the grains.append function. Tests written specifically for the grains.append function.
''' '''
GRAIN_KEY = 'salttesting-grain-key' GRAIN_KEY = 'salttesting-grain-key'
GRAIN_VAL = 'my-grain-val' GRAIN_VAL = 'my-grain-val'
def tearDown(self): def setUp(self):
# Start off with an empty list
self.run_function('grains.setval', [self.GRAIN_KEY, []]) self.run_function('grains.setval', [self.GRAIN_KEY, []])
self.addCleanup(self.run_function, 'grains.setval', [self.GRAIN_KEY, []] )
def test_grains_append(self): def test_grains_append(self):
''' '''
Tests the return of a simple grains.append call. Tests the return of a simple grains.append call.
''' '''
ret = self.run_function('grains.append', [self.GRAIN_KEY, self.GRAIN_VAL ]) ret = self.run_function('grains.append', [self.GRAIN_KEY, self.GRAIN_VAL ])
self.assertEqual(ret[self.GRAIN_KEY], [self.GRAIN_VAL]) self.assertEqual(ret[self.GRAIN_KEY], [self.GRAIN_VAL])
def test_grains_append_val_already_present(self): def test_grains_append_val_already_present(self):
''' '''
skipping to change at line 189 skipping to change at line 191
time.sleep(5) time.sleep(5)
ret = self.run_function('grains.append', [self.GRAIN_KEY, self.GRAIN _VAL]) ret = self.run_function('grains.append', [self.GRAIN_KEY, self.GRAIN _VAL])
assert msg == ret assert msg == ret
@flaky @flaky
def test_grains_append_val_is_list(self): def test_grains_append_val_is_list(self):
''' '''
Tests the return of a grains.append call when val is passed in as a list . Tests the return of a grains.append call when val is passed in as a list .
''' '''
# Start off with an empty list, don't know if the flaky decorator runs t
he setUp function or not...
self.run_function('grains.setval', [self.GRAIN_KEY, []])
second_grain = self.GRAIN_VAL + '-2' second_grain = self.GRAIN_VAL + '-2'
ret = self.run_function('grains.append', [self.GRAIN_KEY, [self.GRAIN_VA L, second_grain]]) ret = self.run_function('grains.append', [self.GRAIN_KEY, [self.GRAIN_VA L, second_grain]])
self.assertEqual(ret[self.GRAIN_KEY], [self.GRAIN_VAL, second_grain]) self.assertEqual(ret[self.GRAIN_KEY], [self.GRAIN_VAL, second_grain])
def test_grains_append_call_twice(self): def test_grains_append_call_twice(self):
''' '''
Tests the return of a grains.append call when the value is already prese nt Tests the return of a grains.append call when the value is already prese nt
but also ensure the grain is not listed twice. but also ensure the grain is not listed twice.
''' '''
# First, add the test grain. # First, add the test grain.
self.run_function('grains.append', [self.GRAIN_KEY, self.GRAIN_VAL]) append_1 = self.run_function('grains.append', [self.GRAIN_KEY, self.GRAI N_VAL])
# Call the function again, which results in a string message, as tested in # Call the function again, which results in a string message, as tested in
# test_grains_append_val_already_present above. # test_grains_append_val_already_present above.
self.run_function('grains.append', [self.GRAIN_KEY, self.GRAIN_VAL]) append_2 = self.run_function('grains.append', [self.GRAIN_KEY, self.GRAI N_VAL])
# Now make sure the grain doesn't show up twice. # Now make sure the grain doesn't show up twice.
grains = self.run_function('grains.items') grains = self.run_function('grains.items')
count = 0 count = 0
for grain in grains: for grain in grains:
if grain == self.GRAIN_KEY: if grain == self.GRAIN_KEY:
count += 1 count += 1
# We should only have hit the grain key once. # We should only have hit the grain key once.
self.assertEqual(count, 1) self.assertEqual(
count,
1,
msg='Count did not match({}!=1) while looking for key \'{}\'.\nFirst
append return:\n{}\nSecond append return:\n{}'.format(
count,
self.GRAIN_KEY,
pprint.pformat(append_1),
pprint.pformat(append_2)
)
)
 End of changes. 9 change blocks. 
5 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)