diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d171b0c7..36554620 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,4 @@ +3.1.3: Add account ID property to roles in precreate. 3.1.2: - RD-6237 Calculated drift in non-JSON serializable format 3.1.1: diff --git a/cloudify_aws/common/connection.py b/cloudify_aws/common/connection.py index 10fcf696..3f3ffa31 100644 --- a/cloudify_aws/common/connection.py +++ b/cloudify_aws/common/connection.py @@ -89,8 +89,11 @@ def __init__(self, node, aws_config=None): 'No plugin properties were provided. ' 'Defaulting client_config credentials.') + def get_sts_client(self, config): + return boto3.client("sts", **config) + def get_sts_credentials(self, role, config): - sts_client = boto3.client("sts", **config) + sts_client = self.get_sts_client(config) sts_credentials = sts_client.assume_role( RoleArn=role, @@ -103,6 +106,12 @@ def get_sts_credentials(self, role, config): "region_name": self.aws_config["region_name"] } + def get_account_id(self): + sts_client = self.get_sts_client(self.aws_config) + caller_id = sts_client.get_caller_identity() + if 'Account' in caller_id: + return caller_id['Account'] + def client(self, service_name): ''' Builds an AWS connection client diff --git a/cloudify_aws/common/tests/test_base.py b/cloudify_aws/common/tests/test_base.py index c8371b32..a7e597be 100644 --- a/cloudify_aws/common/tests/test_base.py +++ b/cloudify_aws/common/tests/test_base.py @@ -572,7 +572,10 @@ def _prepare_create_raises_UnknownServiceError( ) ) - fake_boto.assert_called_with(type_name, **CLIENT_CONFIG) + if type_name == 'iam': + return fake_boto + else: + fake_boto.assert_called_with(type_name, **CLIENT_CONFIG) def _create_common_relationships(self, node_id, diff --git a/cloudify_aws/common/tests/test_iface_requirement.py b/cloudify_aws/common/tests/test_iface_requirement.py index 5a12c4c1..0dd33640 100644 --- a/cloudify_aws/common/tests/test_iface_requirement.py +++ b/cloudify_aws/common/tests/test_iface_requirement.py @@ -212,6 +212,7 @@ def perform_operation(self, operation_callable, args, kwargs): @patch('cloudify_aws.common.decorators._wait_for_delete') @patch('cloudify_aws.common.AWSResourceBase.make_client_call') @patch('cloudify_aws.common.connection.Boto3Connection.client') + @patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') @patch('cloudify.context.CloudifyContext._verify_in_relationship_context') def test_iface_requirement(self, *_): plugin_yaml = self.get_plugin_yaml() diff --git a/cloudify_aws/iam/__init__.py b/cloudify_aws/iam/__init__.py index 9cb0cd01..9f62cf0f 100644 --- a/cloudify_aws/iam/__init__.py +++ b/cloudify_aws/iam/__init__.py @@ -31,6 +31,7 @@ def __init__(self, ctx_node, resource_id=None, client=None, logger=None): AWSResourceBase.__init__( self, client or Boto3Connection(ctx_node).client('iam'), resource_id=resource_id, logger=logger) + self.account_id = Boto3Connection(ctx_node).get_account_id() @property def properties(self): diff --git a/cloudify_aws/iam/resources/role.py b/cloudify_aws/iam/resources/role.py index 775b81bd..0ae4d17b 100644 --- a/cloudify_aws/iam/resources/role.py +++ b/cloudify_aws/iam/resources/role.py @@ -124,6 +124,12 @@ def validate_polices(policies, policies_from_properties): return policies +@decorators.aws_resource(IAMRole, RESOURCE_TYPE, waits_for_status=False) +@decorators.aws_params(RESOURCE_NAME) +def precreate(ctx, iface, **_): + ctx.instance.runtime_properties['account_id'] = iface.account_id + + @decorators.aws_resource(IAMRole, RESOURCE_TYPE, waits_for_status=False) @decorators.aws_params(RESOURCE_NAME) def create(ctx, iface, resource_config, params, **_): diff --git a/cloudify_aws/iam/tests/test_group.py b/cloudify_aws/iam/tests/test_group.py index 71eacabc..0057b70b 100644 --- a/cloudify_aws/iam/tests/test_group.py +++ b/cloudify_aws/iam/tests/test_group.py @@ -48,8 +48,14 @@ 'aws_resource_id': 'group_name_id', 'resource_config': {} } +ctx_node = MagicMock( + properties=NODE_PROPERTIES, + plugin=MagicMock(properties={}) +) +@patch('cloudify_aws.common.connection.ctx') +@patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') class TestIAMGroup(TestBase): def setUp(self): @@ -67,14 +73,15 @@ def tearDown(self): super(TestIAMGroup, self).tearDown() - def test_create_raises_UnknownServiceError(self): - self._prepare_create_raises_UnknownServiceError( + def test_create_raises_UnknownServiceError(self, *_): + fake_boto = self._prepare_create_raises_UnknownServiceError( type_hierarchy=GROUP_TH, type_name='iam', type_class=group ) + fake_boto.assert_called_with('iam') - def test_create(self): + def test_create(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES, @@ -94,7 +101,7 @@ def test_create(self): group.create(ctx=_ctx, resource_config=None, iface=None, params=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.create_group.assert_called_with( GroupName='group_name_id', Path='some_path' @@ -105,7 +112,7 @@ def test_create(self): RUNTIME_PROPERTIES_AFTER_CREATE ) - def test_delete(self): + def test_delete(self, *_): _ctx = self.get_mock_ctx( 'test_delete', test_properties=NODE_PROPERTIES, @@ -120,7 +127,7 @@ def test_delete(self): group.delete(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.delete_group.assert_called_with( GroupName='group_name_id' @@ -133,7 +140,7 @@ def test_delete(self): } ) - def test_attach_to_User(self): + def test_attach_to_User(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', GROUP_TH, @@ -161,7 +168,7 @@ def test_attach_to_User(self): } ) - def test_detach_from_User(self): + def test_detach_from_User(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_detach_from', GROUP_TH, @@ -191,7 +198,7 @@ def test_detach_from_User(self): } ) - def test_detach_from_Policy(self): + def test_detach_from_Policy(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_detach_from', GROUP_TH, @@ -219,7 +226,7 @@ def test_detach_from_Policy(self): } ) - def test_attach_to_Policy(self): + def test_attach_to_Policy(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', GROUP_TH, @@ -247,7 +254,7 @@ def test_attach_to_Policy(self): } ) - def test_IAMGroupClass_properties(self): + def test_IAMGroupClass_properties(self, *_): self.fake_client.get_group = MagicMock(return_value={ 'Group': { 'GroupName': "group_name_id", @@ -255,7 +262,7 @@ def test_IAMGroupClass_properties(self): } }) - test_instance = group.IAMGroup("ctx_node", resource_id='group_id', + test_instance = group.IAMGroup(ctx_node, resource_id='group_id', client=self.fake_client, logger=None) @@ -268,7 +275,7 @@ def test_IAMGroupClass_properties(self): GroupName='group_id' ) - def test_IAMGroupClass_status(self): + def test_IAMGroupClass_status(self, *_): self.fake_client.get_group = MagicMock(return_value={ 'Group': { 'GroupName': "group_name_id", @@ -276,7 +283,7 @@ def test_IAMGroupClass_status(self): } }) - test_instance = group.IAMGroup("ctx_node", resource_id='group_id', + test_instance = group.IAMGroup(ctx_node, resource_id='group_id', client=self.fake_client, logger=None) diff --git a/cloudify_aws/iam/tests/test_iambase.py b/cloudify_aws/iam/tests/test_iambase.py index bacbabe2..3031c9a8 100644 --- a/cloudify_aws/iam/tests/test_iambase.py +++ b/cloudify_aws/iam/tests/test_iambase.py @@ -14,18 +14,28 @@ # Standard imports import unittest +from mock import patch, MagicMock # Local imports -from cloudify_aws.common.tests.test_base import TestServiceBase from cloudify_aws.iam import IAMBase +from cloudify_aws.common.tests.test_base import TestServiceBase + +ctx_node = MagicMock( + properties={}, + plugin=MagicMock(properties={}) +) class TestIAMBase(TestServiceBase): - def setUp(self): + @patch('cloudify_aws.common.connection.ctx') + @patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') + def setUp(self, _, _ctx): + _ctx = MagicMock( # noqa + node=ctx_node, plugin=MagicMock(properties={})) super(TestIAMBase, self).setUp() - self.base = IAMBase("ctx_node", resource_id=True, - client=True, logger=None) + self.base = IAMBase( + ctx_node, resource_id=True, client=True, logger=None) if __name__ == '__main__': diff --git a/cloudify_aws/iam/tests/test_instance_profile.py b/cloudify_aws/iam/tests/test_instance_profile.py index 8da6bbe4..74bccde3 100644 --- a/cloudify_aws/iam/tests/test_instance_profile.py +++ b/cloudify_aws/iam/tests/test_instance_profile.py @@ -34,12 +34,20 @@ }, 'client_config': CLIENT_CONFIG } +ctx_node = MagicMock( + properties=NODE_PROPERTIES, + plugin=MagicMock(properties={}) +) class TestIAMInstanceProfile(TestBase): - def setUp(self): + @patch('cloudify_aws.common.connection.ctx') + @patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') + def setUp(self, _, _ctx): super(TestIAMInstanceProfile, self).setUp() + _ctx = MagicMock( # noqa + node=ctx_node, plugin=MagicMock(properties={})) self.fake_boto, self.fake_client = self.fake_boto_client('iam') @@ -47,7 +55,7 @@ def setUp(self): self.mock_patch.start() self.instance_profile = \ instance_profile.IAMInstanceProfile( - "ctx_node", + ctx_node, resource_id=True, client=MagicMock(), logger=None) @@ -89,7 +97,7 @@ def test_create(self): instance_profile.create(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('sts', **CLIENT_CONFIG) # This is just because I'm not interested in the content # of remote_configuration right now. @@ -124,7 +132,7 @@ def test_create_no_role(self): instance_profile.create(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('sts', **CLIENT_CONFIG) # This is just because I'm not interested in the content # of remote_configuration right now. @@ -152,7 +160,7 @@ def test_delete(self): instance_profile.delete(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('sts', **CLIENT_CONFIG) self.assertEqual(_ctx.instance.runtime_properties, {}) diff --git a/cloudify_aws/iam/tests/test_policy.py b/cloudify_aws/iam/tests/test_policy.py index ee4238d4..2a2f71d4 100644 --- a/cloudify_aws/iam/tests/test_policy.py +++ b/cloudify_aws/iam/tests/test_policy.py @@ -79,8 +79,14 @@ 'aws_resource_id': 'policy_name_id', 'resource_config': {} } +ctx_node = MagicMock( + properties=NODE_PROPERTIES, + plugin=MagicMock(properties={}) +) +@patch('cloudify_aws.common.connection.ctx') +@patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') class TestIAMPolicy(TestBase): def setUp(self): @@ -98,14 +104,15 @@ def tearDown(self): super(TestIAMPolicy, self).tearDown() - def test_create_raises_UnknownServiceError(self): - self._prepare_create_raises_UnknownServiceError( + def test_create_raises_UnknownServiceError(self, *_): + fake_boto = self._prepare_create_raises_UnknownServiceError( type_hierarchy=POLICY_TH, type_name='iam', type_class=policy ) + fake_boto.assert_called_with('iam') - def test_create(self): + def test_create(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES, @@ -124,14 +131,14 @@ def test_create(self): policy.create(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.assertEqual( _ctx.instance.runtime_properties, RUNTIME_PROPERTIES_AFTER_CREATE ) - def test_create_policy_str(self): + def test_create_policy_str(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES_POLICY_STR, @@ -150,7 +157,7 @@ def test_create_policy_str(self): policy.create(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.create_policy.assert_called_with( Description='Grants access to EC2 network components', @@ -164,7 +171,7 @@ def test_create_policy_str(self): RUNTIME_PROPERTIES_AFTER_CREATE ) - def test_delete(self): + def test_delete(self, *_): _ctx = self.get_mock_ctx( 'test_delete', test_properties=NODE_PROPERTIES, @@ -179,7 +186,7 @@ def test_delete(self): policy.delete(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.delete_policy.assert_called_with( PolicyArn='arn_id' @@ -192,7 +199,7 @@ def test_delete(self): } ) - def test_IAMPolicyClass_properties(self): + def test_IAMPolicyClass_properties(self, *_): self.fake_client.get_policy = MagicMock(return_value={ 'Policy': { 'PolicyName': 'policy_name_id', @@ -200,7 +207,7 @@ def test_IAMPolicyClass_properties(self): } }) - test_instance = policy.IAMPolicy("ctx_node", + test_instance = policy.IAMPolicy(ctx_node, resource_id='queue_id', client=self.fake_client, logger=None) @@ -214,7 +221,7 @@ def test_IAMPolicyClass_properties(self): PolicyArn='queue_id' ) - def test_IAMPolicyClass_status(self): + def test_IAMPolicyClass_status(self, *_): self.fake_client.get_policy = MagicMock(return_value={ 'Policy': { 'PolicyName': 'policy_name_id', @@ -222,7 +229,7 @@ def test_IAMPolicyClass_status(self): } }) - test_instance = policy.IAMPolicy("ctx_node", + test_instance = policy.IAMPolicy(ctx_node, resource_id='queue_id', client=self.fake_client, logger=None) diff --git a/cloudify_aws/iam/tests/test_role.py b/cloudify_aws/iam/tests/test_role.py index 3dcfe388..6c8a21e7 100644 --- a/cloudify_aws/iam/tests/test_role.py +++ b/cloudify_aws/iam/tests/test_role.py @@ -83,8 +83,14 @@ } } } +ctx_node = MagicMock( + properties=NODE_PROPERTIES, + plugin=MagicMock(properties={}) +) +@patch('cloudify_aws.common.connection.ctx') +@patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') class TestIAMRole(TestBase): def setUp(self): @@ -102,7 +108,7 @@ def tearDown(self): super(TestIAMRole, self).tearDown() - def test_create_raises_UnknownServiceError(self): + def test_create_raises_UnknownServiceError(self, *_): self._prepare_create_raises_UnknownServiceError( type_hierarchy=ROLE_TH, type_name='iam', @@ -145,9 +151,9 @@ def _prepare_create_raises_UnknownServiceError( ) ) - fake_boto.assert_called_with(type_name, **CLIENT_CONFIG) + fake_boto.assert_called_with(type_name) - def test_create(self): + def test_create(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES, @@ -172,7 +178,7 @@ def test_create(self): role.create(ctx=_ctx, resource_config=None, iface=None, params=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.create_role.assert_called_with( AssumeRolePolicyDocument=ASSUME_STR, @@ -187,7 +193,7 @@ def test_create(self): RUNTIME_PROPERTIES_AFTER_CREATE ) - def test_create_assume_str(self): + def test_create_assume_str(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES_ASSUME_STR, @@ -216,7 +222,7 @@ def test_create_assume_str(self): role.create(ctx=_ctx, resource_config=None, iface=mock_iface, params=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.create_role.assert_called_with( AssumeRolePolicyDocument=ASSUME_STR, @@ -229,7 +235,7 @@ def test_create_assume_str(self): RUNTIME_PROPERTIES_AFTER_CREATE ) - def test_delete(self): + def test_delete(self, *_): _ctx = self.get_mock_ctx( 'test_delete', test_properties=NODE_PROPERTIES, @@ -252,13 +258,13 @@ def test_delete(self): self.fake_client.get_role = MagicMock(return_value={}) role.delete(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.delete_role.assert_called_with( RoleName='role_name_id' ) - def test_IAMRoleClass_properties(self): + def test_IAMRoleClass_properties(self, *_): self.fake_client.get_role = MagicMock(return_value={ 'Role': { 'RoleName': "role_name_id", @@ -266,7 +272,7 @@ def test_IAMRoleClass_properties(self): } }) - test_instance = role.IAMRole("ctx_node", resource_id='role_id', + test_instance = role.IAMRole(ctx_node, resource_id='role_id', client=self.fake_client, logger=None) self.assertEqual(test_instance.properties, { @@ -278,7 +284,7 @@ def test_IAMRoleClass_properties(self): RoleName='role_id' ) - def test_IAMRoleClass_status(self): + def test_IAMRoleClass_status(self, *_): self.fake_client.get_role = MagicMock(return_value={ 'Role': { 'RoleName': "role_name_id", @@ -286,7 +292,7 @@ def test_IAMRoleClass_status(self): } }) - test_instance = role.IAMRole("ctx_node", resource_id='role_id', + test_instance = role.IAMRole(ctx_node, resource_id='role_id', client=self.fake_client, logger=None) self.assertEqual(test_instance.status, 'available') @@ -295,7 +301,7 @@ def test_IAMRoleClass_status(self): RoleName='role_id' ) - def test_attach_to(self): + def test_attach_to(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', ROLE_TH, @@ -323,7 +329,7 @@ def test_attach_to(self): } ) - def test_detach_from(self): + def test_detach_from(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_detach_from', ROLE_TH, diff --git a/cloudify_aws/iam/tests/test_role_policy.py b/cloudify_aws/iam/tests/test_role_policy.py index 3b198a2a..1ccc3170 100644 --- a/cloudify_aws/iam/tests/test_role_policy.py +++ b/cloudify_aws/iam/tests/test_role_policy.py @@ -16,7 +16,7 @@ import collections # Third party imports -from mock import patch +from mock import patch, MagicMock from cloudify.state import current_ctx @@ -46,6 +46,10 @@ }, 'client_config': CLIENT_CONFIG } +ctx_node = MagicMock( + properties=NODE_PROPERTIES, + plugin=MagicMock(properties={}) +) RUNTIME_PROPERTIES_AFTER_CREATE = { 'aws_resource_id': 'aws_resource', @@ -53,6 +57,8 @@ } +@patch('cloudify_aws.common.connection.ctx') +@patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') class TestIAMRolePolicy(TestBase): def setUp(self): @@ -70,44 +76,45 @@ def tearDown(self): super(TestIAMRolePolicy, self).tearDown() - def test_IAMRolePolicyClass_properties(self): + def test_IAMRolePolicyClass_properties(self, *_): test_instance = role_policy.IAMRolePolicy( - "ctx_node", resource_id='role_id', + ctx_node, resource_id='role_id', client=self.fake_client, logger=None) self.assertIsNone(test_instance.properties) - def test_IAMRolePolicyClass_status(self): + def test_IAMRolePolicyClass_status(self, *_): test_instance = role_policy.IAMRolePolicy( - "ctx_node", resource_id='role_id', + ctx_node, resource_id='role_id', client=self.fake_client, logger=None) self.assertIsNone(test_instance.status) - def test_IAMRolePolicyClass_create(self): + def test_IAMRolePolicyClass_create(self, *_): test_instance = role_policy.IAMRolePolicy( - "ctx_node", resource_id='role_id', + ctx_node, resource_id='role_id', client=self.fake_client, logger=None) self.fake_client.put_role_policy = self.mock_return({"c": "d"}) self.assertEqual(test_instance.create({"a": "b"}), {"c": "d"}) self.fake_client.put_role_policy.assert_called_with(a='b') - def test_IAMRolePolicyClass_delete(self): + def test_IAMRolePolicyClass_delete(self, *_): test_instance = role_policy.IAMRolePolicy( - "ctx_node", resource_id='role_id', + ctx_node, resource_id='role_id', client=self.fake_client, logger=None) self.fake_client.delete_role_policy = self.mock_return({"c": "d"}) self.assertEqual(test_instance.delete({"a": "b"}), {"c": "d"}) self.fake_client.delete_role_policy.assert_called_with(a='b') - def test_create_raises_UnknownServiceError(self): - self._prepare_create_raises_UnknownServiceError( + def test_create_raises_UnknownServiceError(self, *_): + fake_boto = self._prepare_create_raises_UnknownServiceError( type_hierarchy=ROLEPOLICY_TH, type_name='iam', type_class=role_policy ) + fake_boto.assert_called_with('iam') - def test_create(self): + def test_create(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES, @@ -132,7 +139,7 @@ def test_create(self): role_policy.create(ctx=_ctx, resource_config=None, iface=None, params=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.put_role_policy.assert_called_with( PolicyName='aws_resource', RoleName='subnet_id', @@ -144,7 +151,7 @@ def test_create(self): RUNTIME_PROPERTIES_AFTER_CREATE ) - def test_delete(self): + def test_delete(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES, @@ -170,7 +177,7 @@ def test_delete(self): role_policy.delete(ctx=_ctx, resource_config={}, iface=None, params=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.delete_role_policy.assert_called_with( PolicyName='aws_resource', RoleName='subnet_id') diff --git a/cloudify_aws/iam/tests/test_user.py b/cloudify_aws/iam/tests/test_user.py index 57b1b1f7..b85bd1ed 100644 --- a/cloudify_aws/iam/tests/test_user.py +++ b/cloudify_aws/iam/tests/test_user.py @@ -48,8 +48,14 @@ 'aws_resource_id': 'user_name_id', 'resource_config': {} } +ctx_node = MagicMock( + properties=NODE_PROPERTIES, + plugin=MagicMock(properties={}) +) +@patch('cloudify_aws.common.connection.ctx') +@patch('cloudify_aws.common.connection.Boto3Connection.get_account_id') class TestIAMUser(TestBase): def setUp(self): @@ -67,14 +73,15 @@ def tearDown(self): super(TestIAMUser, self).tearDown() - def test_create_raises_UnknownServiceError(self): - self._prepare_create_raises_UnknownServiceError( + def test_create_raises_UnknownServiceError(self, *_): + fake_boto = self._prepare_create_raises_UnknownServiceError( type_hierarchy=USER_TH, type_name='iam', type_class=user ) + fake_boto.assert_called_with('iam') - def test_create(self): + def test_create(self, *_): _ctx = self.get_mock_ctx( 'test_create', test_properties=NODE_PROPERTIES, @@ -93,7 +100,7 @@ def test_create(self): }) user.create(ctx=_ctx, resource_config=None, iface=None, params=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.create_user.assert_called_with( Path='user_path', UserName='user_name_id' @@ -104,7 +111,7 @@ def test_create(self): RUNTIME_PROPERTIES_AFTER_CREATE ) - def test_delete(self): + def test_delete(self, *_): _ctx = self.get_mock_ctx( 'test_delete', test_properties=NODE_PROPERTIES, @@ -119,7 +126,7 @@ def test_delete(self): user.delete(ctx=_ctx, resource_config=None, iface=None) - self.fake_boto.assert_called_with('iam', **CLIENT_CONFIG) + self.fake_boto.assert_called_with('iam') self.fake_client.delete_user.assert_called_with( UserName='user_name_id' @@ -132,7 +139,7 @@ def test_delete(self): } ) - def test_attach_to_Group(self): + def test_attach_to_Group(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', USER_TH, @@ -160,7 +167,7 @@ def test_attach_to_Group(self): } ) - def test_attach_to_AccessKey(self): + def test_attach_to_AccessKey(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', USER_TH, @@ -201,7 +208,7 @@ def test_attach_to_AccessKey(self): } ) - def test_attach_to_Policy(self): + def test_attach_to_Policy(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', USER_TH, @@ -229,7 +236,7 @@ def test_attach_to_Policy(self): } ) - def test_attach_to_LoginProfile_Create(self): + def test_attach_to_LoginProfile_Create(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', USER_TH, @@ -256,7 +263,7 @@ def test_attach_to_LoginProfile_Create(self): } ) - def test_attach_to_LoginProfile_Update(self): + def test_attach_to_LoginProfile_Update(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_attach_to', USER_TH, @@ -287,7 +294,7 @@ def test_attach_to_LoginProfile_Update(self): } ) - def test_detach_from_Group(self): + def test_detach_from_Group(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_detach_from', USER_TH, @@ -317,7 +324,7 @@ def test_detach_from_Group(self): } ) - def test_detach_from_AccessKey(self): + def test_detach_from_AccessKey(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_detach_from', USER_TH, @@ -345,7 +352,7 @@ def test_detach_from_AccessKey(self): } ) - def test_detach_from_Policy(self): + def test_detach_from_Policy(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_detach_from', USER_TH, @@ -373,7 +380,7 @@ def test_detach_from_Policy(self): } ) - def test_detach_from_LoginProfile(self): + def test_detach_from_LoginProfile(self, *_): _source_ctx, _target_ctx, _ctx = self._create_common_relationships( 'test_detach_from', USER_TH, @@ -400,7 +407,7 @@ def test_detach_from_LoginProfile(self): } ) - def test_IAMUserClass_properties(self): + def test_IAMUserClass_properties(self, *_): self.fake_client.get_user = MagicMock(return_value={ 'User': { 'UserName': 'user_name_id', @@ -408,7 +415,7 @@ def test_IAMUserClass_properties(self): } }) - test_instance = user.IAMUser("ctx_node", resource_id='user_id', + test_instance = user.IAMUser(ctx_node, resource_id='user_id', client=self.fake_client, logger=None) self.assertEqual(test_instance.properties, { @@ -420,7 +427,7 @@ def test_IAMUserClass_properties(self): UserName='user_id' ) - def test_IAMUserClass_status(self): + def test_IAMUserClass_status(self, *_): self.fake_client.get_user = MagicMock(return_value={ 'User': { 'UserName': 'user_name_id', @@ -428,7 +435,7 @@ def test_IAMUserClass_status(self): } }) - test_instance = user.IAMUser("ctx_node", resource_id='user_id', + test_instance = user.IAMUser(ctx_node, resource_id='user_id', client=self.fake_client, logger=None) self.assertEqual(test_instance.status, 'available') diff --git a/plugin.yaml b/plugin.yaml index 9bd9b6bd..201de77e 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -2,7 +2,7 @@ plugins: aws: executor: central_deployment_agent package_name: cloudify-aws-plugin - package_version: '3.1.2' + package_version: '3.1.3' data_types: @@ -1645,6 +1645,9 @@ node_types: required: false interfaces: cloudify.interfaces.lifecycle: + precreate: + implementation: aws.cloudify_aws.iam.resources.role.precreate + inputs: *operation_inputs create: implementation: aws.cloudify_aws.iam.resources.role.create inputs: *operation_inputs diff --git a/plugin_1_4.yaml b/plugin_1_4.yaml index 9e2cbf1b..606d00e4 100644 --- a/plugin_1_4.yaml +++ b/plugin_1_4.yaml @@ -2,7 +2,7 @@ plugins: aws: executor: central_deployment_agent package_name: cloudify-aws-plugin - package_version: '3.1.2' + package_version: '3.1.3' data_types: @@ -1678,6 +1678,9 @@ node_types: required: false interfaces: cloudify.interfaces.lifecycle: + precreate: + implementation: aws.cloudify_aws.iam.resources.role.precreate + inputs: *operation_inputs create: implementation: aws.cloudify_aws.iam.resources.role.create inputs: *operation_inputs diff --git a/plugin_1_5.yaml b/plugin_1_5.yaml index f5e5d851..2ad141c6 100644 --- a/plugin_1_5.yaml +++ b/plugin_1_5.yaml @@ -2,7 +2,7 @@ plugins: aws: executor: central_deployment_agent package_name: cloudify-aws-plugin - package_version: '3.1.2' + package_version: '3.1.3' properties_description: | Manage AWS resources. Credentials documentation: https://docs.cloudify.co/latest/working_with/official_plugins/infrastructure/aws/#authentication-with-aws. @@ -1733,6 +1733,9 @@ node_types: required: false interfaces: cloudify.interfaces.lifecycle: + precreate: + implementation: aws.cloudify_aws.iam.resources.role.precreate + inputs: *operation_inputs create: implementation: aws.cloudify_aws.iam.resources.role.create inputs: *operation_inputs diff --git a/v2_plugin.yaml b/v2_plugin.yaml index c3ea4136..d4f311f7 100644 --- a/v2_plugin.yaml +++ b/v2_plugin.yaml @@ -2,7 +2,7 @@ plugins: aws: executor: central_deployment_agent package_name: cloudify-aws-plugin - package_version: '3.1.2' + package_version: '3.1.3' data_types: @@ -1679,6 +1679,9 @@ node_types: required: false interfaces: cloudify.interfaces.lifecycle: + precreate: + implementation: aws.cloudify_aws.iam.resources.role.precreate + inputs: *operation_inputs create: implementation: aws.cloudify_aws.iam.resources.role.create inputs: *operation_inputs