示例#1
0
    def test_absent(self):
        '''
        Test to ensure the IAM role is deleted.
        '''
        name = 'myrole'

        ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}

        mock = MagicMock(
            side_effect=[['mypolicy'], ['mypolicy'], False, True, False, False,
                         True, False, False, False, True])
        mock_bool = MagicMock(return_value=False)
        mock_lst = MagicMock(return_value=[])
        with patch.dict(
                boto_iam_role.__salt__, {
                    'boto_iam.list_role_policies': mock,
                    'boto_iam.delete_role_policy': mock_bool,
                    'boto_iam.profile_associated': mock,
                    'boto_iam.disassociate_profile_from_role': mock_bool,
                    'boto_iam.instance_profile_exists': mock,
                    'boto_iam.list_attached_role_policies': mock_lst,
                    'boto_iam.delete_instance_profile': mock_bool,
                    'boto_iam.role_exists': mock,
                    'boto_iam.delete_role': mock_bool
                }):
            with patch.dict(boto_iam_role.__opts__, {'test': False}):
                comt = (' Failed to add policy mypolicy to role myrole')
                ret.update({
                    'comment': comt,
                    'changes': {
                        'new': {
                            'policies': ['mypolicy']
                        },
                        'old': {
                            'policies': ['mypolicy']
                        }
                    }
                })
                self.assertDictEqual(boto_iam_role.absent(name), ret)

                comt = (
                    ' No policies in role myrole.'
                    ' No attached policies in role myrole. Failed to disassociate '
                    'myrole instance profile from myrole role.')
                ret.update({'comment': comt, 'changes': {}})
                self.assertDictEqual(boto_iam_role.absent(name), ret)

                comt = (' No policies in role myrole.'
                        ' No attached policies in role myrole. '
                        ' Failed to delete myrole instance profile.')
                ret.update({'comment': comt, 'changes': {}})
                self.assertDictEqual(boto_iam_role.absent(name), ret)

                comt = (
                    ' No policies in role myrole.'
                    ' No attached policies in role myrole.  myrole instance profile '
                    'does not exist. Failed to delete myrole iam role.')
                ret.update({'comment': comt, 'changes': {}})
                self.assertDictEqual(boto_iam_role.absent(name), ret)
示例#2
0
    def test_absent(self):
        '''
        Test to ensure the IAM role is deleted.
        '''
        name = 'myrole'

        ret = {'name': name,
               'result': False,
               'changes': {},
               'comment': ''}

        mock = MagicMock(side_effect=[['mypolicy'], ['mypolicy'], False, True,
                                      False, False, True, False, False, False,
                                      True])
        mock_bool = MagicMock(return_value=False)
        mock_lst = MagicMock(return_value=[])
        with patch.dict(boto_iam_role.__salt__,
                        {'boto_iam.list_role_policies': mock,
                         'boto_iam.delete_role_policy': mock_bool,
                         'boto_iam.profile_associated': mock,
                         'boto_iam.disassociate_profile_from_role': mock_bool,
                         'boto_iam.instance_profile_exists': mock,
                         'boto_iam.list_attached_role_policies': mock_lst,
                         'boto_iam.delete_instance_profile': mock_bool,
                         'boto_iam.role_exists': mock,
                         'boto_iam.delete_role': mock_bool}):
            with patch.dict(boto_iam_role.__opts__, {'test': False}):
                comt = (' Failed to add policy mypolicy to role myrole')
                ret.update({'comment': comt,
                            'changes': {'new': {'policies': ['mypolicy']},
                                        'old': {'policies': ['mypolicy']}}})
                self.assertDictEqual(boto_iam_role.absent(name), ret)

                comt = (' No policies in role myrole.'
                        ' No attached policies in role myrole. Failed to disassociate '
                        'myrole instance profile from myrole role.')
                ret.update({'comment': comt, 'changes': {}})
                self.assertDictEqual(boto_iam_role.absent(name), ret)

                comt = (' No policies in role myrole.'
                        ' No attached policies in role myrole. '
                        ' Failed to delete myrole instance profile.')
                ret.update({'comment': comt, 'changes': {}})
                self.assertDictEqual(boto_iam_role.absent(name), ret)

                comt = (' No policies in role myrole.'
                        ' No attached policies in role myrole.  myrole instance profile '
                        'does not exist. Failed to delete myrole iam role.')
                ret.update({'comment': comt, 'changes': {}})
                self.assertDictEqual(boto_iam_role.absent(name), ret)
def test_absent():
    """
    Test to ensure the IAM role is deleted.
    """
    name = "myrole"

    ret = {"name": name, "result": False, "changes": {}, "comment": ""}

    mock = MagicMock(side_effect=[
        ["mypolicy"],
        ["mypolicy"],
        False,
        True,
        False,
        False,
        True,
        False,
        False,
        False,
        True,
    ])
    mock_bool = MagicMock(return_value=False)
    mock_lst = MagicMock(return_value=[])
    with patch.dict(
            boto_iam_role.__salt__,
        {
            "boto_iam.list_role_policies": mock,
            "boto_iam.delete_role_policy": mock_bool,
            "boto_iam.profile_associated": mock,
            "boto_iam.disassociate_profile_from_role": mock_bool,
            "boto_iam.instance_profile_exists": mock,
            "boto_iam.list_attached_role_policies": mock_lst,
            "boto_iam.delete_instance_profile": mock_bool,
            "boto_iam.role_exists": mock,
            "boto_iam.delete_role": mock_bool,
        },
    ):
        with patch.dict(boto_iam_role.__opts__, {"test": False}):
            comt = " Failed to add policy mypolicy to role myrole"
            ret.update({
                "comment": comt,
                "changes": {
                    "new": {
                        "policies": ["mypolicy"]
                    },
                    "old": {
                        "policies": ["mypolicy"]
                    },
                },
            })
            assert boto_iam_role.absent(name) == ret

            comt = (
                " No policies in role myrole."
                " No attached policies in role myrole. Failed to disassociate "
                "myrole instance profile from myrole role.")
            ret.update({"comment": comt, "changes": {}})
            assert boto_iam_role.absent(name) == ret

            comt = (" No policies in role myrole."
                    " No attached policies in role myrole. "
                    " Failed to delete myrole instance profile.")
            ret.update({"comment": comt, "changes": {}})
            assert boto_iam_role.absent(name) == ret

            comt = (
                " No policies in role myrole."
                " No attached policies in role myrole.  myrole instance profile "
                "does not exist. Failed to delete myrole iam role.")
            ret.update({"comment": comt, "changes": {}})
            assert boto_iam_role.absent(name) == ret