def overrided_run_instance(**_):
  if 'parameters' in ctx.node.properties and 'placement' in ctx.node.properties['parameters']:
    if ('scale' in ctx.workflow_id):
      # Ignore the placement property when scale
      ctx.instance.runtime_properties['placement'] = None
    else:
      _set_placement_for_instance()
  run_instances(**_)
    def test_run_instances_clean(self):
        """ this tests that the instance create function
        adds the runtime_properties
        """

        ctx = self.mock_ctx('test_run_instances_clean')
        current_ctx.set(ctx=ctx)
        instance.run_instances(ctx=ctx)
        self.assertIn('aws_resource_id',
                      ctx.instance.runtime_properties.keys())
    def test_run_instances_clean(self):
        """ this tests that the instance create function
        adds the runtime_properties
        """

        ctx = self.mock_ctx('test_run_instances_clean')
        current_ctx.set(ctx=ctx)
        instance.run_instances(ctx=ctx)
        self.assertIn('aws_resource_id',
                      ctx.instance.runtime_properties.keys())
    def test_run_instances_external_resource(self):
        """ this tests that the instance create function adds
        the runtime_properties
        """
        ctx = self.mock_ctx('test_run_instances_external_resource')
        current_ctx.set(ctx=ctx)

        ec2_client = connection.EC2ConnectionClient().client()
        reservation = ec2_client.run_instances(
            TEST_AMI_IMAGE_ID, instance_type=TEST_INSTANCE_TYPE)
        instance_id = reservation.instances[0].id
        ctx.node.properties['use_external_resource'] = True
        ctx.node.properties['resource_id'] = instance_id
        instance.run_instances(ctx=ctx)
        self.assertIn('aws_resource_id',
                      ctx.instance.runtime_properties.keys())
    def test_run_instances_external_resource(self):
        """ this tests that the instance create function adds
        the runtime_properties
        """
        ctx = self.mock_ctx('test_run_instances_external_resource')
        current_ctx.set(ctx=ctx)

        ec2_client = connection.EC2ConnectionClient().client()
        reservation = ec2_client.run_instances(
            TEST_AMI_IMAGE_ID, instance_type=TEST_INSTANCE_TYPE)
        instance_id = reservation.instances[0].id
        ctx.node.properties['use_external_resource'] = True
        ctx.node.properties['resource_id'] = instance_id
        instance.run_instances(ctx=ctx)
        self.assertIn('aws_resource_id',
                      ctx.instance.runtime_properties.keys())
    def test_run_instances_provider_context_good_subnet(self):
        """ this tests that the instance create function
        adds the runtime_properties
        """

        vpc = self.create_vpc_client().create_vpc('10.10.10.0/16')
        subnet = self.create_vpc_client().create_subnet(
            vpc.id, '10.10.10.0/24',
            availability_zone=TEST_AVAILABILITY_ZONE)
        ctx = self.mock_ctx('test_run_instances_provider_context_good_subnet')
        ctx.provider_context['resources'] = {
            constants.VPC: {
                'id': vpc.id,
                'external_resource': True
            },
            constants.SUBNET: {
                'id': subnet.id,
                'external_resource': True
            },
            constants.AGENTS_AWS_INSTANCE_PARAMETERS: {
                'placement': TEST_AVAILABILITY_ZONE
            }
        }
        current_ctx.set(ctx=ctx)
        instance.run_instances(ctx=ctx)
        self.assertIn('aws_resource_id',
                      ctx.instance.runtime_properties.keys())
        self.assertIn('subnet_id',
                      ctx.instance.runtime_properties.keys())
        self.assertEquals(subnet.id,
                          ctx.instance.runtime_properties['subnet_id'])
        self.assertIn('vpc_id',
                      ctx.instance.runtime_properties.keys())
        self.assertEquals(vpc.id,
                          ctx.instance.runtime_properties['vpc_id'])
        self.assertIn('placement',
                      ctx.instance.runtime_properties.keys())
        self.assertEquals(TEST_AVAILABILITY_ZONE,
                          ctx.instance.runtime_properties['placement'])