Skip to content

Commit

Permalink
Merge pull request saltstack#54162 from DSRCorporation/bugs/merge_for…
Browse files Browse the repository at this point in the history
…ward_tests_fixes

Merge forward tests fixes
  • Loading branch information
dwoz authored Aug 10, 2019
2 parents 4e500bf + 93467bb commit 354436d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
8 changes: 8 additions & 0 deletions salt/modules/rh_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,14 @@ def build_interface(iface, iface_type, enabled, **settings):
rh_major = '7'
else:
rh_major = '6'
elif __grains__['os'] == 'Amazon':
# TODO: Is there a better formula for this? -W. Werner, 2019-05-30
# If not, it will need to be updated whenever Amazon releases
# Amazon Linux 3
if __grains__['osmajorrelease'] == 2:
rh_major = '7'
else:
rh_major = '6'
else:
rh_major = __grains__['osrelease'][:1]

Expand Down
16 changes: 8 additions & 8 deletions tests/unit/modules/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,9 @@ def test_line_modecheck_failure(self):
:return:
'''
for mode, err_msg in [(None, 'How to process the file'), ('nonsense', 'Unknown mode')]:
with pytest.raises(CommandExecutionError) as cmd_err:
with pytest.raises(CommandExecutionError) as exc_info:
filemod.line('foo', mode=mode)
self.assertIn(err_msg, six.text_type(cmd_err))
self.assertIn(err_msg, six.text_type(exc_info.value))

@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
Expand All @@ -1140,10 +1140,10 @@ def test_line_no_content(self):
:return:
'''
for mode in ['insert', 'ensure', 'replace']:
with pytest.raises(CommandExecutionError) as cmd_err:
with pytest.raises(CommandExecutionError) as exc_info:
filemod.line('foo', mode=mode)
self.assertIn('Content can only be empty if mode is "delete"',
six.text_type(cmd_err))
six.text_type(exc_info.value))

@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
Expand All @@ -1155,10 +1155,10 @@ def test_line_insert_no_location_no_before_no_after(self):
'''
files_fopen = mock_open(read_data='test data')
with patch('salt.utils.files.fopen', files_fopen):
with pytest.raises(CommandExecutionError) as cmd_err:
with pytest.raises(CommandExecutionError) as exc_info:
filemod.line('foo', content='test content', mode='insert')
self.assertIn('"location" or "before/after"',
six.text_type(cmd_err))
six.text_type(exc_info.value))

def test_util_starts_till(self):
'''
Expand Down Expand Up @@ -1764,11 +1764,11 @@ def test_line_insert_ensure_beforeafter_rangelines(self):
with patch('salt.utils.files.fopen', files_fopen):
atomic_opener = mock_open()
with patch('salt.utils.atomicfile.atomic_open', atomic_opener):
with pytest.raises(CommandExecutionError) as cmd_err:
with pytest.raises(CommandExecutionError) as exc_info:
filemod.line('foo', content=cfg_content, after=_after, before=_before, mode='ensure')
self.assertIn(
'Found more than one line between boundaries "before" and "after"',
six.text_type(cmd_err))
six.text_type(exc_info))

@with_tempfile()
def test_line_delete(self, name):
Expand Down
28 changes: 14 additions & 14 deletions tests/unit/modules/test_localemod.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ def test_localectl_status_parser_no_systemd(self):
Test localectl status parser raises an exception if no systemd installed.
:return:
'''
with pytest.raises(CommandExecutionError) as err:
with pytest.raises(CommandExecutionError) as exc_info:
localemod._localectl_status()
assert 'Unable to find "localectl"' in six.text_type(err)
assert 'Unable to find "localectl"' in six.text_type(exc_info.value)
assert not localemod.log.debug.called

@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock(return_value=locale_ctl_out_empty)})
def test_localectl_status_parser_empty(self):
with pytest.raises(CommandExecutionError) as err:
with pytest.raises(CommandExecutionError) as exc_info:
localemod._localectl_status()
assert 'Unable to parse result of "localectl"' in six.text_type(err)
assert 'Unable to parse result of "localectl"' in six.text_type(exc_info.value)

@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock(return_value=locale_ctl_out_broken)})
def test_localectl_status_parser_broken(self):
with pytest.raises(CommandExecutionError) as err:
with pytest.raises(CommandExecutionError) as exc_info:
localemod._localectl_status()
assert 'Unable to parse result of "localectl"' in six.text_type(err)
assert 'Unable to parse result of "localectl"' in six.text_type(exc_info.value)

@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock(return_value=locale_ctl_out_structure)})
Expand Down Expand Up @@ -293,9 +293,9 @@ def test_get_locale_with_no_systemd_unknown(self):
Test getting current system locale with systemd and dbus available on Gentoo.
:return:
'''
with pytest.raises(CommandExecutionError) as err:
with pytest.raises(CommandExecutionError) as exc_info:
localemod.get_locale()
assert '"DrunkDragon" is unsupported' in six.text_type(err)
assert '"DrunkDragon" is unsupported' in six.text_type(exc_info.value)

@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Ubuntu', 'osmajorrelease': 42})
Expand Down Expand Up @@ -395,10 +395,10 @@ def test_set_locale_with_no_systemd_debian_no_update_locale(self):
:return:
'''
loc = 'de_DE.utf8'
with pytest.raises(CommandExecutionError) as err:
with pytest.raises(CommandExecutionError) as exc_info:
localemod.set_locale(loc)
assert not localemod._localectl_set.called
assert 'Cannot set locale: "update-locale" was not found.' in six.text_type(err)
assert 'Cannot set locale: "update-locale" was not found.' in six.text_type(exc_info.value)

@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Gentoo', 'osmajorrelease': 42})
Expand Down Expand Up @@ -467,9 +467,9 @@ def test_set_locale_with_no_systemd_unknown(self):
Test setting current system locale without systemd on unknown system.
:return:
'''
with pytest.raises(CommandExecutionError) as err:
with pytest.raises(CommandExecutionError) as exc_info:
localemod.set_locale('de_DE.utf8')
assert 'Unsupported platform' in six.text_type(err)
assert 'Unsupported platform' in six.text_type(exc_info.value)

@patch('salt.utils.locales.normalize_locale', MagicMock(return_value='en_US.UTF-8 UTF-8'))
@patch('salt.modules.localemod.__salt__', {'locale.list_avail': MagicMock(return_value=['A', 'B'])})
Expand Down Expand Up @@ -537,9 +537,9 @@ def test_gen_locale_suse_localedef_error_handling(self):
Tests the location where gen_locale is handling error while calling not installed localedef on Suse os-family.
:return:
'''
with pytest.raises(CommandExecutionError) as err:
with pytest.raises(CommandExecutionError) as exc_info:
localemod.gen_locale('de_DE.utf8')
assert 'Command "locale-gen" or "localedef" was not found on this system.' in six.text_type(err)
assert 'Command "locale-gen" or "localedef" was not found on this system.' in six.text_type(exc_info.value)

def test_gen_locale_debian(self):
'''
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/states/test_boto_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ class BotoVpcRouteTableTestCase(BotoVpcStateTestCaseBase, BotoVpcResourceTestCas
@mock_ec2_deprecated
def test_present_with_subnets(self):
vpc = self._create_vpc(name='test')
subnet1 = self._create_subnet(vpc_id=vpc.id, name='test1')
subnet2 = self._create_subnet(vpc_id=vpc.id, name='test2')
subnet1 = self._create_subnet(vpc_id=vpc.id, cidr_block='10.0.0.0/25', name='test1')
subnet2 = self._create_subnet(vpc_id=vpc.id, cidr_block='10.0.0.128/25', name='test2')

route_table_present_result = self.salt_states['boto_vpc.route_table_present'](
name='test', vpc_name='test', subnet_names=['test1'], subnet_ids=[subnet2.id])
Expand Down

0 comments on commit 354436d

Please sign in to comment.