def test_create(self):
        ctx = self.ctx
        config = {BUCKET: 'bucket', POLICY: 'policy'}
        iface = MagicMock()
        iface.create = self.mock_return('location')
        bucket_policy.create(ctx, iface, config)
        self.assertEqual(ctx.instance.runtime_properties[POLICY], 'policy')

        config = {BUCKET: 'bucket', POLICY: ['policy']}
        iface = MagicMock()
        iface.create = self.mock_return('location')
        bucket_policy.create(ctx, iface, config)
        self.assertEqual(ctx.instance.runtime_properties[POLICY], '["policy"]')

        config = {POLICY: 'policy'}
        ctx_target = self.get_mock_relationship_ctx(
            "bucket",
            test_target=self.get_mock_ctx("Bucket",
                                          {},
                                          {EXTERNAL_RESOURCE_ID: 'ext_id'}))
        iface = MagicMock()
        iface.create = self.mock_return('location')
        with patch(PATCH_PREFIX + 'utils') as utils:
            utils.find_rel_by_node_type = self.mock_return(ctx_target)
            utils.clean_params = self.mock_return({POLICY: 'policy'})
            bucket_policy.create(ctx, iface, config)
            self.assertEqual(ctx.instance.runtime_properties[BUCKET],
                             'ext_id')
            self.assertEqual(ctx.instance.runtime_properties[POLICY],
                             'policy')
Пример #2
0
    def test_create(self):
        ctx = self.get_mock_ctx("Backet")
        config = {BUCKET: 'bucket', POLICY: 'policy'}
        iface = MagicMock()
        iface.create = self.mock_return('location')
        bucket_policy.create(ctx, iface, config)
        self.assertEqual(ctx.instance.runtime_properties[POLICY], 'policy')

        config = {BUCKET: 'bucket', POLICY: ['policy']}
        iface = MagicMock()
        iface.create = self.mock_return('location')
        bucket_policy.create(ctx, iface, config)
        self.assertEqual(ctx.instance.runtime_properties[POLICY], '["policy"]')

        config = {POLICY: 'policy'}
        ctx_target = self.get_mock_relationship_ctx(
            "bucket",
            test_target=self.get_mock_ctx("Backet", {},
                                          {EXTERNAL_RESOURCE_ID: 'ext_id'}))
        iface = MagicMock()
        iface.create = self.mock_return('location')
        with patch(PATCH_PREFIX + 'utils') as utils:
            utils.find_rel_by_node_type = self.mock_return(ctx_target)
            bucket_policy.create(ctx, iface, config)
            self.assertEqual(ctx.instance.runtime_properties[BUCKET], 'ext_id')
            self.assertEqual(ctx.instance.runtime_properties[POLICY], 'policy')
Пример #3
0
    def test_create(self):
        ctx = self._get_ctx()
        with patch(PATCH_PREFIX + 'utils') as utils:
            iface = MagicMock()
            iface.create = MagicMock(
                return_value={'Statement': {
                    'Sid': 'res_id'
                }})
            iface.resource_id = 'test_id'
            permission.create(ctx, iface, {})
            self.assertEqual(1, utils.update_resource_id.call_count)
            self.assertEqual(1, utils.update_resource_arn.call_count)

        with patch(PATCH_PREFIX + 'utils') as utils:
            iface = MagicMock()
            iface.create = MagicMock(
                return_value={'Statement': {
                    'Sid': 'res_id'
                }})
            iface.resource_id = None
            ctx.instance.runtime_properties['resource_config'].update(
                {'StatementId': 'test_id'})
            permission.create(ctx, iface, {})
            self.assertEqual(1, utils.update_resource_id.call_count)
            self.assertEqual(1, utils.update_resource_arn.call_count)
    def _prepere_mocks(self):
        logger = MagicMock()
        api_configuration = MagicMock()

        mock_api = MagicMock()

        client_api = MagicMock()

        def del_func(body, name, first):
            return (body, name, first)

        def read_func(name, first):
            return (name, first)

        def create_func(body, first):
            mock = MagicMock()
            mock.to_dict = MagicMock(return_value={
                'body': body,
                'first': first
            })
            return mock

        client_api.delete = del_func
        client_api.read = read_func
        client_api.create = create_func

        mock_api.api_client_version = MagicMock(return_value=client_api)
        mock_api.api_payload_version = MagicMock(
            return_value={'payload_param': 'payload_value'})

        api_configuration.prepare_api = MagicMock(return_value=mock_api)

        operation_mock = MagicMock()
        operation_mock.execute = MagicMock(side_effect=ApiException())

        mappingMock = MagicMock()

        mappingMock.create = MagicMock()
        mappingMock.create.payload = 'api_payload_version'
        mappingMock.create.api = 'api_client_version'
        mappingMock.create.method = 'create'

        mappingMock.read = MagicMock()
        mappingMock.read.api = 'api_client_version'
        mappingMock.read.method = 'read'

        mappingMock.delete = MagicMock()
        mappingMock.delete.api = 'api_client_version'
        mappingMock.delete.method = 'delete'

        return CloudifyKubernetesClient(logger, api_configuration), mappingMock
 def test_create(self):
     ctx = self.get_mock_ctx("Backet")
     config = {RESOURCE_NAME: 'bucket'}
     iface = MagicMock()
     iface.create = self.mock_return({LOCATION: 'location'})
     bucket.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(ctx.instance.runtime_properties[LOCATION], 'location')
    def test_create(self):
        bucket_object_request = {
            'Body': 'test/path/test-object.txt',
            'Key': 'test-object.txt'
        }
        config = self.resource_config['resource_config']['kwargs']
        config.update(**bucket_object_request)

        iface = MagicMock()
        iface.create = self.mock_return(None)

        download_file_mock = MagicMock()
        _, file_path = tempfile.mkstemp()
        download_file_mock.return_value = file_path
        bucket_object.download_resource_file = download_file_mock

        bucket_object.create(ctx=self.ctx,
                             iface=iface,
                             resource_config=config)

        self.assertEqual(
            self.ctx.instance.runtime_properties[BUCKET], 'test_bucket')

        self.assertEqual(
            self.ctx.instance.runtime_properties[EXTERNAL_RESOURCE_ID],
            'test-object.txt')
    def test_create(self):
        ctx = self.get_mock_ctx("EBSVolume")
        config = \
            {
                'AvailabilityZone': 'aq-testzone-1a',
                'Size': 6,
                'Tags':
                    [
                        {
                            'Key': 'test-tag-key-1',
                            'Value': 'test-tag-value-1',
                        },
                        {
                            'Key': 'test-tag-key-2',
                            'Value': 'test-tag-value-2',
                        }

                    ],
                'VolumeId': 'test_volume_id',
            }
        self.ebs_volume.resource_id = config[VOLUME_ID]
        iface = MagicMock()
        iface.create = self.mock_return(config)
        ebs.create(ctx=ctx, iface=iface, resource_config=config)
        self.assertEqual(self.ebs_volume.resource_id, 'test_volume_id')
Пример #8
0
    def test_create(self):
        ctx = self.get_mock_ctx("EBSVolume", {'client_config': {
            'region_name': 'aq-testzone-1'
        }})
        config = \
            {
                'AvailabilityZone': 'aq-testzone-1a',
                'Size': 6,
                'Tags':
                    [
                        {
                            'Key': 'test-tag-key-1',
                            'Value': 'test-tag-value-1',
                        },
                        {
                            'Key': 'test-tag-key-2',
                            'Value': 'test-tag-value-2',
                        }

                    ],
                'VolumeId': 'test_volume_id',
            }
        self.ebs_volume.resource_id = config[VOLUME_ID]
        iface = MagicMock()
        iface.create = self.mock_return(config)
        ebs.create(ctx=ctx, iface=iface, resource_config=config)
        self.assertEqual(self.ebs_volume.resource_id, 'test_volume_id')
Пример #9
0
    def test_create(self):
        ctx = self.get_mock_ctx("Cluster")
        config = {cluster.CLUSTER_RESOURCE_NAME: 'test_cluster_name'}
        iface = MagicMock()
        response = \
            {
                cluster.CLUSTER: {
                    'clusterArn': 'test_cluster_arn',
                    'clusterName': 'test_cluster_name',
                    'status': 'test_cluster_status',
                    'registeredContainerInstancesCount': 1,
                    'runningTasksCount': 1,
                    'pendingTasksCount': 1,
                    'activeServicesCount': 1,
                    'statistics': [
                        {
                            'name': 'test_statistics_name',
                            'value': 'test_statistics_name'
                        },
                    ]
                }
            }

        iface.create = self.mock_return(response)
        cluster.create(ctx, iface, config)
        self.assertEqual(
            ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID],
            'test_cluster_name')
    def test_create_use_allocated_no_allocated(self):
        value = {
            ADDRESSES: [{
                NETWORKINTERFACE_ID: 'test_name',
                'AssociationId': 'test_name',
                'AllocationId': 'test_name',
            }, {
                NETWORKINTERFACE_ID: 'test_name2',
                'AssociationId': 'test_name2',
                'AllocationId': 'test_name2'
            }]
        }

        self.elasticip.client = self.make_client_function('describe_addresses',
                                                          return_value=value)

        test_node_props = {'use_unassociated_addresses': True}
        ctx = self.get_mock_ctx("PublicIp", test_properties=test_node_props)
        config = {
            ELASTICIP_ID: 'elasticip',
            INSTANCE_ID: 'instance',
            'AllocationId': 'elasticip'
        }
        self.elasticip.resource_id = config[ELASTICIP_ID]
        iface = MagicMock()
        iface.create = self.mock_return(config)
        iface.list = self.mock_return(value[ADDRESSES])
        elasticip.create(ctx=ctx, iface=iface, resource_config=config)
        self.assertEqual(self.elasticip.resource_id, 'elasticip')
        self.assertEqual(ctx.instance.runtime_properties.get('allocation_id'),
                         'elasticip')
    def test_create(self):
        iface = MagicMock()
        ctx = self.get_mock_ctx("EC2VpcPeering")
        config = \
            {
                'DryRun': True,
                'PeerVpcId': 'peer_vpc_id_test',
                'VpcId': 'vpc_id_test',
                'PeerRegion': 'peer_region_test'
            }

        response = \
            {
                vpc_peering.VPC_PEERING_CONNECTION: {
                    'AccepterVpcInfo': {
                        'CidrBlock': 'cidr_block_test',
                        'Ipv6CidrBlockSet': [
                            {
                                'Ipv6CidrBlock': 'ip_6_cidr_block_test'
                            },
                        ],
                        'CidrBlockSet': [
                            {
                                'CidrBlock': 'cidr_block_test'
                            },
                        ],
                        'OwnerId': 'owner_id_test',
                        'VpcId': 'vpc_id_test',
                        'Region': 'region_test'
                    },
                    'RequesterVpcInfo': {
                        'CidrBlock': 'cidr_block_test',
                        'Ipv6CidrBlockSet': [
                            {
                                'Ipv6CidrBlock': 'ip_6_cidr_block_test'
                            },
                        ],
                        'CidrBlockSet': [
                            {
                                'CidrBlock': 'cidr_block_test'
                            },
                        ],
                        'OwnerId': 'owner_id_test',
                        'VpcId': 'vpc_id_test',
                        'Region': 'region_test'
                    },
                    'Status': {
                        'Code': 'test_status_code',
                        'Message': 'test_status_message'
                    },
                    'VpcPeeringConnectionId': 'test_peering_connection_id'
                },
            }

        ctx.instance.runtime_properties['resource_config'] = config
        iface.create = self.mock_return(response)
        vpc_peering.create(ctx=ctx, iface=iface, resource_config=config)
        self.assertEqual(
            ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID],
            'test_peering_connection_id')
Пример #12
0
 def get_mock_rest_client(self):
     mock_node = MagicMock(node_id='foo', type_hierarchy=discover.GCP_TYPE)
     mock_node.id = mock_node.node_id
     mock_node.properties = {
         'client_config': {},
         'resource_config': {},
         'zones': []
     }
     nodes_list = [mock_node]
     mock_nodes_client = MagicMock()
     mock_nodes_client.list = MagicMock(return_value=nodes_list)
     mock_instance = MagicMock(node_id='foo', state='started')
     mock_instance.node = mock_node
     mock_instance.node_id = mock_node.node_id
     mock_instance.runtime_properties = {}
     instances_list = [mock_instance]
     mock_instances_client = MagicMock()
     mock_instances_client.list = MagicMock(return_value=instances_list)
     mock_deployments_client = MagicMock()
     mock_deployments_client.create = MagicMock()
     mock_deployments_client.get.return_value = None
     mock_deployment_groups_client = MagicMock()
     mock_deployment_groups_client.put = MagicMock()
     mock_rest_client = MagicMock()
     mock_rest_client.nodes = mock_nodes_client
     mock_rest_client.node_instances = mock_instances_client
     mock_rest_client.deployments = mock_deployments_client
     mock_rest_client.deployment_groups = mock_deployment_groups_client
     return mock_rest_client
 def test_create(self):
     ctx = self.get_mock_ctx("VpnGateway")
     config = {VPNGATEWAY_ID: 'vpn gateway'}
     self.vpn_gateway.resource_id = config[VPNGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'VpnGateway': config})
     vpn_gateway.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.vpn_gateway.resource_id, 'vpn gateway')
Пример #14
0
 def test_create(self):
     ctx = self.get_mock_ctx(DHCPOPTIONS)
     config = {DHCPOPTIONS_ID: 'dhcp'}
     self.dhcp.resource_id = config[DHCPOPTIONS_ID]
     iface = MagicMock()
     iface.create = self.mock_return({DHCPOPTIONS: config})
     dhcp.create(ctx, iface, config)
     self.assertEqual(self.dhcp.resource_id, 'dhcp')
Пример #15
0
 def test_prepare(self):
     ctx = self.get_mock_ctx("Image")
     config = {IMAGE_ID: 'image', OWNERS: 'owner'}
     iface = MagicMock()
     iface.create = self.mock_return(config)
     image.prepare(ctx, iface, config)
     self.assertEqual(ctx.instance.runtime_properties['resource_config'],
                      config)
Пример #16
0
 def test_create(self):
     ctx = self.get_mock_ctx("Vpc")
     config = {VPC_ID: 'vpc', CIDR_BLOCK: 'cidr_block'}
     self.vpc.resource_id = config[VPC_ID]
     iface = MagicMock()
     iface.create = self.mock_return({VPC: config})
     vpc.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.vpc.resource_id, 'vpc')
 def test_create(self):
     ctx = self.get_mock_ctx("NetworkAcl")
     config = {NETWORKACL_ID: 'network acl', VPC_ID: 'vpc'}
     self.networkacl.resource_id = config[NETWORKACL_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkAcl': config})
     networkacl.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.networkacl.resource_id, 'network acl')
Пример #18
0
 def test_create(self):
     ctx = self.get_mock_ctx("PublicIp")
     config = {ELASTICIP_ID: 'elasticip', INSTANCE_ID: 'instance'}
     self.elasticip.resource_id = config[ELASTICIP_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     elasticip.create(ctx, iface, config)
     self.assertEqual(self.elasticip.resource_id, 'elasticip')
Пример #19
0
 def test_create(self):
     ctx = self.get_mock_ctx("NetworkInterface")
     config = {NETWORKINTERFACE_ID: 'eni', SUBNET_ID: 'subnet'}
     self.eni.resource_id = config[NETWORKINTERFACE_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkInterface': config})
     eni.create(ctx, iface, config)
     self.assertEqual(self.eni.resource_id, 'eni')
 def test_prepare(self):
     ctx = self.get_mock_ctx("Image")
     config = {IMAGE_ID: 'image', OWNERS: 'owner'}
     iface = MagicMock()
     iface.create = self.mock_return(config)
     image.prepare(ctx, iface, config)
     self.assertEqual(ctx.instance.runtime_properties['resource_config'],
                      config)
Пример #21
0
 def test_create(self):
     ctx = self.get_mock_ctx("InternetGateway")
     config = {INTERNETGATEWAY_ID: 'internet gateway'}
     self.internet_gateway.resource_id = config[INTERNETGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     internet_gateway.create(ctx, iface, config)
     self.assertEqual(self.internet_gateway.resource_id, 'internet gateway')
 def test_create(self):
     ctx = self.get_mock_ctx("Subnet")
     config = {SUBNET_ID: 'subnet', CIDR_BLOCK: 'cidr_block', VPC_ID: 'vpc'}
     self.subnet.resource_id = config[SUBNET_ID]
     iface = MagicMock()
     iface.create = self.mock_return({SUBNET: config})
     subnet.create(ctx, iface, config)
     self.assertEqual(self.subnet.resource_id, 'subnet')
 def test_prepare(self):
     ctx = self.get_mock_ctx("Subnet")
     config = {SUBNET_ID: 'subnet', CIDR_BLOCK: 'cidr_block'}
     iface = MagicMock()
     iface.create = self.mock_return(config)
     subnet.prepare(ctx, iface, config)
     self.assertEqual(ctx.instance.runtime_properties['resource_config'],
                      config)
Пример #24
0
 def test_create(self):
     ctx = self.get_mock_ctx("RouteTable")
     config = {ROUTETABLE_ID: 'route table', VPC_ID: 'vpc'}
     self.routetable.resource_id = config[ROUTETABLE_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     routetable.create(ctx, iface, config)
     self.assertEqual(self.routetable.resource_id, 'route table')
Пример #25
0
 def test_create(self):
     ctx = self.get_mock_ctx("CustomerGateway")
     config = {CUSTOMERGATEWAY_ID: 'customer gateway'}
     self.customer_gateway.resource_id = config[CUSTOMERGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     customer_gateway.create(ctx, iface, config)
     self.assertEqual(self.customer_gateway.resource_id, 'customer gateway')
Пример #26
0
 def test_prepare(self):
     ctx = self.get_mock_ctx("Vpc")
     config = {VPC_ID: 'vpc', CIDR_BLOCK: 'cidr_block'}
     iface = MagicMock()
     iface.create = self.mock_return(config)
     vpc.prepare(ctx, iface, config)
     self.assertEqual(ctx.instance.runtime_properties['resource_config'],
                      config)
 def test_create(self):
     ctx = self.get_mock_ctx("PublicIp")
     config = {ELASTICIP_ID: 'elasticip', INSTANCE_ID: 'instance'}
     self.elasticip.resource_id = config[ELASTICIP_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     elasticip.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.elasticip.resource_id,
                      'elasticip')
 def test_create(self):
     ctx = self.get_mock_ctx("VpnGateway")
     config = {VPNGATEWAY_ID: 'vpn gateway'}
     self.vpn_gateway.resource_id = config[VPNGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'VpnGateway': config})
     vpn_gateway.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.vpn_gateway.resource_id,
                      'vpn gateway')
 def test_create(self):
     ctx = self.get_mock_ctx("CustomerGateway")
     config = {CUSTOMERGATEWAY_ID: 'customer gateway'}
     self.customer_gateway.resource_id = config[CUSTOMERGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'CustomerGateway': config})
     customer_gateway.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.customer_gateway.resource_id,
                      'customer gateway')
 def test_create(self):
     ctx = self.get_mock_ctx("NetworkAcl")
     config = {NETWORKACL_ID: 'network acl', VPC_ID: 'vpc'}
     self.networkacl.resource_id = config[NETWORKACL_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkAcl': config})
     networkacl.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.networkacl.resource_id,
                      'network acl')
Пример #31
0
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("RouteTable", type_hierarchy=[VPC_TYPE])
     config = {}
     self.routetable.resource_id = 'routetable'
     iface = MagicMock()
     iface.create = self.mock_return(config)
     with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):
         routetable.create(ctx, iface, config)
         self.assertEqual(self.routetable.resource_id, 'routetable')
Пример #32
0
 def test_create(self):
     ctx = self.get_mock_ctx("Vpc")
     config = {VPC_ID: 'vpc', CIDR_BLOCK: 'cidr_block'}
     self.vpc.resource_id = config[VPC_ID]
     iface = MagicMock()
     iface.create = self.mock_return({VPC: config})
     vpc.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.vpc.resource_id,
                      'vpc')
 def test_create(self):
     ctx = self.get_mock_ctx("InternetGateway")
     config = {INTERNETGATEWAY_ID: 'internet gateway'}
     self.internet_gateway.resource_id = config[INTERNETGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'InternetGateway': config})
     internet_gateway.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.internet_gateway.resource_id,
                      'internet gateway')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("NetworkAcl", type_hierarchy=[NETWORKACL_TYPE])
     config = {}
     self.networkaclentry.resource_id = 'network acl'
     iface = MagicMock()
     iface.create = self.mock_return(config)
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         networkaclentry.create(ctx, iface, config)
         self.assertEqual(self.networkaclentry.resource_id, 'network acl')
 def test_create(self):
     ctx = self._get_ctx()
     resource_config = {'config': None}
     iface = MagicMock()
     iface.create = self.mock_return({'HostedZone': {'Id': 'id'}})
     hosted_zone.create(ctx, iface, resource_config)
     rprop = ctx.instance.runtime_properties
     self.assertEqual(rprop[constants.EXTERNAL_RESOURCE_ID], 'id')
     self.assertEqual(rprop[constants.EXTERNAL_RESOURCE_ARN], 'id')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("Subnet", type_hierarchy=[VPC_TYPE])
     config = {SUBNET_ID: 'subnet', CIDR_BLOCK: 'cidr_block'}
     self.subnet.resource_id = config[SUBNET_ID]
     iface = MagicMock()
     iface.create = self.mock_return({SUBNET: config})
     with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):
         subnet.create(ctx, iface, config)
         self.assertEqual(self.subnet.resource_id, 'subnet')
Пример #37
0
 def test_create(self):
     ctx = self.get_mock_ctx("NetworkInterface")
     config = {NETWORKINTERFACE_ID: 'eni', SUBNET_ID: 'subnet'}
     self.eni.resource_id = config[NETWORKINTERFACE_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkInterface': config})
     eni.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.eni.resource_id,
                      'eni')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("NetworkAcl", type_hierarchy=[VPC_TYPE])
     config = {}
     self.networkacl.resource_id = 'networkacl'
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkAcl': config})
     with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):
         networkacl.create(ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.networkacl.resource_id, 'networkacl')
 def test_create(self):
     ctx = self._get_ctx()
     resource_config = {'config': None}
     iface = MagicMock()
     iface.create = self.mock_return({'HostedZone': {'Id': 'id'}})
     hosted_zone.create(ctx, iface, resource_config)
     rprop = ctx.instance.runtime_properties
     self.assertEqual(rprop[constants.EXTERNAL_RESOURCE_ID], 'id')
     self.assertEqual(rprop[constants.EXTERNAL_RESOURCE_ARN], 'id')
 def test_create(self):
     ctx = self.get_mock_ctx(DHCPOPTIONS)
     config = {DHCPOPTIONS_ID: 'dhcp'}
     self.dhcp.resource_id = config[DHCPOPTIONS_ID]
     iface = MagicMock()
     iface.create = self.mock_return({DHCPOPTIONS: config})
     dhcp.create(ctx, iface, config)
     self.assertEqual(self.dhcp.resource_id,
                      'dhcp')
Пример #41
0
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("NetworkInterface",
                             type_hierarchy=[SUBNET_TYPE])
     config = {NETWORKINTERFACE_ID: 'eni'}
     self.eni.resource_id = config[NETWORKINTERFACE_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkInterface': config})
     with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):
         eni.create(ctx, iface, config)
         self.assertEqual(self.eni.resource_id, 'eni')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("NatGateway",
                             type_hierarchy=[SUBNET_TYPE, ELASTICIP_TYPE])
     config = {NATGATEWAY_ID: 'nat_gateway'}
     self.nat_gateway.resource_id = config[NATGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NatGateway': config})
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         nat_gateway.create(ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.nat_gateway.resource_id, 'nat_gateway')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("Subnet", type_hierarchy=[VPC_TYPE])
     config = {SUBNET_ID: 'subnet', CIDR_BLOCK: 'cidr_block'}
     self.subnet.resource_id = config[SUBNET_ID]
     iface = MagicMock()
     iface.create = self.mock_return({SUBNET: config})
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         subnet.create(ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.subnet.resource_id,
                          'subnet')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("NetworkAcl", type_hierarchy=[VPC_TYPE])
     config = {}
     self.networkacl.resource_id = 'networkacl'
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkAcl': config})
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         networkacl.create(ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.networkacl.resource_id,
                          'networkacl')
 def test_create(self):
     ctx = self.get_mock_ctx("Subnet")
     config = {SUBNET_ID: 'subnet', CIDR_BLOCK: 'cidr_block',
               VPC_ID: 'vpc'}
     self.subnet.resource_id = config[SUBNET_ID]
     iface = MagicMock()
     iface.create = self.mock_return({SUBNET: config})
     subnet.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.subnet.resource_id,
                      'subnet')
 def test_create(self):
     ctx = self.get_mock_ctx("NATGateway")
     config = {NATGATEWAY_ID: 'nat_gateway', SUBNET_ID: 'subnet_id',
               ALLOCATION_ID: 'allocation_id'}
     self.nat_gateway.resource_id = config[NATGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NatGateway': config})
     nat_gateway.create(ctx=ctx, iface=iface, resource_config=config)
     self.assertEqual(self.nat_gateway.resource_id,
                      'nat_gateway')
Пример #47
0
 def test_create(self):
     ctx = self.get_mock_ctx("NATGateway")
     config = {NATGATEWAY_ID: 'nat_gateway', SUBNET_ID: 'subnet_id',
               ALLOCATION_ID: 'allocation_id'}
     self.nat_gateway.resource_id = config[NATGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     nat_gateway.create(ctx, iface, config)
     self.assertEqual(self.nat_gateway.resource_id,
                      'nat_gateway')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("NatGateway", type_hierarchy=[SUBNET_TYPE,
                                                           ELASTICIP_TYPE])
     config = {NATGATEWAY_ID: 'nat_gateway'}
     self.nat_gateway.resource_id = config[NATGATEWAY_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NatGateway': config})
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         nat_gateway.create(ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.nat_gateway.resource_id,
                          'nat_gateway')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("PublicIp",
                             type_hierarchy=[INSTANCE_TYPE_DEPRECATED])
     config = {ELASTICIP_ID: 'elasticip'}
     self.elasticip.resource_id = config[ELASTICIP_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         elasticip.create(ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.elasticip.resource_id,
                          'elasticip')
Пример #50
0
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("NetworkInterface",
                             type_hierarchy=[SUBNET_TYPE])
     config = {NETWORKINTERFACE_ID: 'eni'}
     self.eni.resource_id = config[NETWORKINTERFACE_ID]
     iface = MagicMock()
     iface.create = self.mock_return({'NetworkInterface': config})
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         eni.create(ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.eni.resource_id,
                          'eni')
 def test_create_with_relationships(self):
     ctx = self.get_mock_ctx("CustomerGateway",
                             type_hierarchy=[ELASTICIP_TYPE])
     config = {'Type': 'type'}
     self.customer_gateway.resource_id = config['Type']
     iface = MagicMock()
     iface.create = self.mock_return({'CustomerGateway': config})
     with patch('cloudify_aws.common.utils.find_rel_by_node_type'):
         customer_gateway.create(
             ctx=ctx, iface=iface, resource_config=config)
         self.assertEqual(self.customer_gateway.resource_id,
                          'type')
Пример #52
0
 def test_create_wth_modify(self):
     ctx = self.get_mock_ctx("NetworkInterface")
     config = {NETWORKINTERFACE_ID: 'eni', SUBNET_ID: 'subnet'}
     self.eni.resource_id = config[NETWORKINTERFACE_ID]
     iface = MagicMock()
     modify_args = {'SourceDestCheck': {'Value': True}}
     iface.create = self.mock_return({'NetworkInterface': config})
     eni.create(
         ctx=ctx, iface=iface, resource_config=config,
         modify_network_interface_attribute_args=modify_args)
     self.assertEqual(self.eni.resource_id,
                      'eni')
    def test_create(self):
        ctx = self._get_ctx()
        with patch(PATCH_PREFIX + 'utils') as utils:
            iface = MagicMock()
            iface.create = MagicMock(
                return_value={'Statement': {'Sid': 'res_id'}})
            iface.resource_id = 'test_id'
            permission.create(ctx, iface, {})
            self.assertEqual(1, utils.update_resource_id.call_count)
            self.assertEqual(1, utils.update_resource_arn.call_count)

        with patch(PATCH_PREFIX + 'utils') as utils:
            iface = MagicMock()
            iface.create = MagicMock(
                return_value={'Statement': {'Sid': 'res_id'}})
            iface.resource_id = None
            ctx.instance.runtime_properties['resource_config'].update(
                {'StatementId': 'test_id'})
            permission.create(ctx, iface, {})
            self.assertEqual(1, utils.update_resource_id.call_count)
            self.assertEqual(1, utils.update_resource_arn.call_count)
 def test_prepare_assoc(self):
     ctx = self._get_relationship_context()
     ctx.source.instance.runtime_properties['resource_config'] = {'VPC': {}}
     iface = MagicMock()
     iface.create = self.mock_return(('res_id', 'res_arn'))
     with patch(PATCH_PREFIX + 'utils') as utils:
         utils.is_node_type = self.mock_return(True)
         utils.get_resource_id = self.mock_return('res_id')
         record_set.prepare_assoc(ctx)
         rprop = ctx.source.instance.runtime_properties['resource_config']
         self.assertEqual(
             rprop['HostedZoneId'],
             'res_id')
Пример #55
0
  def test_create_transaction_id(self):
    project_id = 'guestbook'
    project_node = '/appscale/apps/{}'.format(project_id)

    zk_client = MagicMock()
    tx_manager = ProjectTransactionManager(project_id, zk_client)

    # Ensure the first created node is ignored.
    created_nodes = ['{}/txids/tx0000000000'.format(project_node),
                     '{}/txids/tx0000000001'.format(project_node)]
    zk_client.create = MagicMock(side_effect=created_nodes)
    self.assertEqual(tx_manager.create_transaction_id(xg=False), 1)
    calls = [
      call('{}/txids/tx'.format(project_node), value=ANY, sequence=True),
      call('{}/txids/tx'.format(project_node), value=ANY, sequence=True)]
    zk_client.create.assert_has_calls(calls)

    # Ensure the manual offset works.
    tx_manager._txid_manual_offset = 10
    created_nodes = ['{}/txids/tx0000000015'.format(project_node)]
    zk_client.create = MagicMock(side_effect=created_nodes)
    self.assertEqual(tx_manager.create_transaction_id(xg=False), 25)
    calls = [
      call('{}/txids/tx'.format(project_node), value=ANY, sequence=True)]
    zk_client.create.assert_has_calls(calls)
    tx_manager._txid_manual_offset = 0

    # Ensure the automatic rollover works.
    created_nodes = ['{}/txids/tx-2147483647'.format(project_node),
                     '{}/txids2'.format(project_node),
                     '{}/txids2/tx0000000000'.format(project_node)]
    zk_client.create = MagicMock(side_effect=created_nodes)
    zk_client.get_children = MagicMock(return_value=['txids', 'txids2'])
    self.assertEqual(tx_manager.create_transaction_id(xg=False), 2147483648)
    calls = [
      call('{}/txids/tx'.format(project_node), value=ANY, sequence=True),
      call('{}/txids2'.format(project_node)),
      call('{}/txids2/tx'.format(project_node), value=ANY, sequence=True)]
    zk_client.create.assert_has_calls(calls)
Пример #56
0
 def test_create(self):
     ctx = self.get_mock_ctx("EBSVolumeAttachment")
     config = \
         {
             'Device': 'test_device',
             'InstanceId': 'test_instance_id',
             'VolumeId': 'test_volume_id',
         }
     self.ebs_volume_attachment.resource_id = config[VOLUME_ID]
     iface = MagicMock()
     iface.create = self.mock_return(config)
     ebs.attach(ctx, iface, config)
     self.assertEqual(self.ebs_volume_attachment.resource_id,
                      'test_volume_id')
 def test_create(self):
     ctx = self.get_mock_ctx(
         "EC2Instances",
         test_properties={'os_family': 'linux'},
         type_hierarchy=['cloudify.nodes.Root', 'cloudify.nodes.Compute'])
     current_ctx.set(ctx=ctx)
     params = {'ImageId': 'test image', 'InstanceType': 'test type'}
     self.instances.resource_id = 'test_name'
     iface = MagicMock()
     value = {INSTANCES: [{INSTANCE_ID: 'test_name'}]}
     iface.create = self.mock_return(value)
     instances.create(ctx=ctx, iface=iface, resource_config=params)
     self.assertEqual(self.instances.resource_id,
                      'test_name')
    def test_create(self):
        iface = MagicMock()
        ctx = self.get_mock_ctx("EC2VPNConnectionRoute")

        config = \
            {
                'DestinationCidrBlock': 'destination_cidr_block',
                'VpnConnectionId': 'vpn_connection_id_test',
            }
        response = None
        iface.create = self.mock_return(response)
        vpn_connection_route.create(ctx, iface, config)
        self.assertEqual(
            ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID],
            'vpn_connection_id_test'
        )
 def test_prepare_assoc(self):
     ctx = self._get_relationship_context()
     ctx.source.instance.runtime_properties['resource_config'] = {'VPC': {}}
     resource_config = {'config': None}
     iface = MagicMock()
     iface.create = self.mock_return(('res_id', 'res_arn'))
     with patch(PATCH_PREFIX + 'utils') as utils, \
             patch(PATCH_PREFIX + 'detect_vpc_region',
                   self.mock_return('vpc_region')), \
             patch(PATCH_PREFIX + 'Boto3Connection'):
         utils.is_node_type = self.mock_return(True)
         utils.get_resource_id = self.mock_return('res_id')
         hosted_zone.prepare_assoc(ctx, iface, resource_config)
         rprop = ctx.source.instance.runtime_properties
         self.assertEqual(
             rprop['resource_config']['VPC'],
             {'VPCId': 'res_id', 'VPCRegion': 'vpc_region'})