class CloudFormationTemplateURLTests(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument('--template_urls', dest='template_urls',
                                 help='comma separated list of template_urls',
                                 default=None)
        self.parser.add_argument('--timeout', dest='timeout',
                                 help='number of seconds to wait for stacks to complete',
                                 default=300)
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        self.show_args()
        self.template_urls = self.args.template_urls.split(',')
        self.timeout = int(self.args.timeout)
        # Setup basic eutester object
        if self.args.region:
            self.tester = CFNops(credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath, config_file=self.args.config,
                                  password=self.args.password)
        # Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.stacks = []

    def Stack_Template_URL_Test(self):
        for url in self.template_urls:
            # get template name from URL, remove file extension and any "-"
            template = os.path.splitext(url.rsplit('/', 1)[1])[0].replace("-", "")
            self.stack_name = template + str(os.urandom(8).encode('hex'))
            self.stacks.append(self.stack_name)
            self.template_parameters = [('KeyName', self.keypair.name), ('ImageId', self.tester.get_emi().id)]
            self.tester.create_stack(stack_name=self.stack_name,
                                     template_body=None,
                                     template_url=url,
                                     parameters=self.template_parameters)

            def stack_completed():
                stack_status = False
                if len(self.tester.cloudformation.describe_stack_events(self.stack_name)) > 0:
                    stack_info = self.tester.cloudformation.describe_stack_events(self.stack_name)
                    for inf in stack_info:
                        if (inf.logical_resource_id == self.stack_name) and (inf.resource_status == "CREATE_COMPLETE"):
                            self.debug("Stack Logical Resource: " + inf.logical_resource_id)
                            self.debug("Stack Resource Status: " + inf.resource_status)
                            stack_status = True
                return stack_status
            self.tester.wait_for_result(stack_completed, True, timeout=self.timeout)

    def clean_method(self):
        self.tester.cleanup_artifacts()
        for stack in self.stacks:
            self.tester.delete_stack(stack)
Ejemplo n.º 2
0
class CloudFormations(EutesterTestCase):
    def __init__(self, extra_args= None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = CFNops( credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops( credpath=self.args.credpath, config_file=self.args.config,password=self.args.password)
        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

    def InstanceVolumeTemplate(self):
        self.stack_name = "volumeTest{0}".format(int(time.time()))
        template = Template()
        keyname_param = template.add_parameter(Parameter("KeyName", Description="Name of an existing EC2 KeyPair "
                                                                                "to enable SSH access to the instance",
                                                         Type="String",))
        template.add_mapping('RegionMap', {"": {"AMI": self.tester.get_emi().id}})
        for i in xrange(2):
            ec2_instance = template.add_resource(ec2.Instance("Instance{0}".format(i),
                                                              ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
                                                              InstanceType="t1.micro", KeyName=Ref(keyname_param),
                                                              SecurityGroups=[self.group.name], UserData=Base64("80")))
            vol = template.add_resource(ec2.Volume("Volume{0}".format(i), Size="8",
                                                   AvailabilityZone=GetAtt("Instance{0}".format(i), "AvailabilityZone")))
            mount = template.add_resource(ec2.VolumeAttachment("MountPt{0}".format(i), InstanceId=Ref("Instance{0}".format(i)),
                                                               VolumeId=Ref("Volume{0}".format(i)), Device="/dev/vdc"))
        stack = self.tester.create_stack(self.stack_name, template.to_json(), parameters=[("KeyName",self.keypair.name)])
        def stack_completed():
            return self.tester.cloudformation.describe_stacks(self.stack_name).status == "CREATE_COMPLETE"
        self.tester.wait_for_result(stack_completed, True, timeout=600)
        self.tester.delete_stack(self.stack_name)

    def clean_method(self):
        self.tester.cleanup_artifacts()
class CloudFormationTemplateURLTests(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument('--template_urls',
                                 dest='template_urls',
                                 help='comma separated list of template_urls',
                                 default=None)
        self.parser.add_argument(
            '--timeout',
            dest='timeout',
            help='number of seconds to wait for stacks to complete',
            default=300)
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        self.show_args()
        self.template_urls = self.args.template_urls.split(',')
        self.timeout = int(self.args.timeout)
        # Setup basic eutester object
        if self.args.region:
            self.tester = CFNops(credpath=self.args.credpath,
                                 region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)
        # Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.stacks = []

    def Stack_Template_URL_Test(self):
        for url in self.template_urls:
            # get template name from URL, remove file extension and any "-"
            template = os.path.splitext(url.rsplit('/',
                                                   1)[1])[0].replace("-", "")
            self.stack_name = template + str(os.urandom(8).encode('hex'))
            self.stacks.append(self.stack_name)
            self.template_parameters = [('KeyName', self.keypair.name),
                                        ('ImageId', self.tester.get_emi().id)]
            self.tester.create_stack(stack_name=self.stack_name,
                                     template_body=None,
                                     template_url=url,
                                     parameters=self.template_parameters)

            def stack_completed():
                stack_status = False
                if len(
                        self.tester.cloudformation.describe_stack_events(
                            self.stack_name)) > 0:
                    stack_info = self.tester.cloudformation.describe_stack_events(
                        self.stack_name)
                    for inf in stack_info:
                        if (inf.logical_resource_id
                                == self.stack_name) and (inf.resource_status
                                                         == "CREATE_COMPLETE"):
                            self.debug("Stack Logical Resource: " +
                                       inf.logical_resource_id)
                            self.debug("Stack Resource Status: " +
                                       inf.resource_status)
                            stack_status = True
                return stack_status

            self.tester.wait_for_result(stack_completed,
                                        True,
                                        timeout=self.timeout)

    def clean_method(self):
        self.tester.cleanup_artifacts()
        for stack in self.stacks:
            self.tester.delete_stack(stack)
Ejemplo n.º 4
0
class CloudFormations(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = CFNops(credpath=self.args.credpath,
                                 region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)
        self.group = self.tester.add_group(group_name="group-" +
                                           str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name,
                                            port=-1,
                                            protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

    def InstanceVolumeTemplate(self):
        self.stack_name = "volumeTest{0}".format(int(time.time()))
        template = Template()
        keyname_param = template.add_parameter(
            Parameter(
                "KeyName",
                Description="Name of an existing EC2 KeyPair "
                "to enable SSH access to the instance",
                Type="String",
            ))
        template.add_mapping('RegionMap',
                             {"": {
                                 "AMI": self.tester.get_emi().id
                             }})
        for i in xrange(2):
            ec2_instance = template.add_resource(
                ec2.Instance("Instance{0}".format(i),
                             ImageId=FindInMap("RegionMap", Ref("AWS::Region"),
                                               "AMI"),
                             InstanceType="t1.micro",
                             KeyName=Ref(keyname_param),
                             SecurityGroups=[self.group.name],
                             UserData=Base64("80")))
            vol = template.add_resource(
                ec2.Volume("Volume{0}".format(i),
                           Size="8",
                           AvailabilityZone=GetAtt("Instance{0}".format(i),
                                                   "AvailabilityZone")))
            mount = template.add_resource(
                ec2.VolumeAttachment("MountPt{0}".format(i),
                                     InstanceId=Ref("Instance{0}".format(i)),
                                     VolumeId=Ref("Volume{0}".format(i)),
                                     Device="/dev/vdc"))
        stack = self.tester.create_stack(self.stack_name,
                                         template.to_json(),
                                         parameters=[("KeyName",
                                                      self.keypair.name)])

        def stack_completed():
            return self.tester.cloudformation.describe_stacks(
                self.stack_name).status == "CREATE_COMPLETE"

        self.tester.wait_for_result(stack_completed, True, timeout=600)
        self.tester.delete_stack(self.stack_name)

    def clean_method(self):
        self.tester.cleanup_artifacts()