2017-02-20 21:21:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Libs
|
|
|
|
from salt.cloud.clouds import ec2
|
|
|
|
from salt.exceptions import SaltCloudSystemExit
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
2017-09-08 21:36:52 +00:00
|
|
|
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, PropertyMock
|
2017-02-20 21:21:05 +00:00
|
|
|
|
2017-02-23 00:02:21 +00:00
|
|
|
|
2017-02-20 21:21:05 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-09-08 21:36:52 +00:00
|
|
|
class EC2TestCase(TestCase):
|
2017-02-20 21:21:05 +00:00
|
|
|
'''
|
|
|
|
Unit TestCase for salt.cloud.clouds.ec2 module.
|
|
|
|
'''
|
2017-02-19 15:35:30 +00:00
|
|
|
|
2017-02-20 21:21:05 +00:00
|
|
|
def test__validate_key_path_and_mode(self):
|
2017-09-08 21:36:52 +00:00
|
|
|
|
|
|
|
# Key file exists
|
|
|
|
with patch('os.path.exists', return_value=True):
|
|
|
|
with patch('os.stat') as patched_stat:
|
|
|
|
|
|
|
|
type(patched_stat.return_value).st_mode = PropertyMock(return_value=0o644)
|
|
|
|
self.assertRaises(
|
|
|
|
SaltCloudSystemExit, ec2._validate_key_path_and_mode, 'key_file')
|
|
|
|
|
|
|
|
type(patched_stat.return_value).st_mode = PropertyMock(return_value=0o600)
|
|
|
|
self.assertTrue(ec2._validate_key_path_and_mode('key_file'))
|
|
|
|
|
|
|
|
type(patched_stat.return_value).st_mode = PropertyMock(return_value=0o400)
|
|
|
|
self.assertTrue(ec2._validate_key_path_and_mode('key_file'))
|
|
|
|
|
|
|
|
# Key file does not exist
|
|
|
|
with patch('os.path.exists', return_value=False):
|
|
|
|
self.assertRaises(
|
|
|
|
SaltCloudSystemExit, ec2._validate_key_path_and_mode, 'key_file')
|