def test_create(self):
        with settings(abort_on_prompts=True):
            project = 'dummy1'
            stackname = '%s--%s' % (project, self.environment)

            cfn.ensure_destroyed(stackname)
            self.stacknames.append(stackname)

            cfngen.generate_stack(project, stackname=stackname)
            bootstrap.create_stack(stackname)

            buildvars.switch_revision(stackname, 'master')
            buildvars.force(stackname, 'answer', 'forty-two')

            cfn.cmd(stackname, "ls -l /", username=BOOTSTRAP_USER, concurrency='parallel')
            cfn.cmd(stackname, "ls -l /", username=BOOTSTRAP_USER, concurrency='parallel', node=1)

            cfn.download_file(stackname, "/bin/ls", "ls", use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./ls"))

            cfn.download_file(stackname, "/bin/less", "venv/bin/", use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./venv/bin/less"))

            cfn.download_file(stackname, "/bin/pwd", "subfolder/pwd", use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./subfolder/pwd"))

            lifecycle.stop_if_running_for(stackname, minimum_minutes=60 * 24 * 365) # should exercise the code but do nothing, as this test's instance can't have been running for a year
Example #2
0
 def tear_down_stack(cls):
     try:
         if cls.reuse_existing_stack:
             json.dump(cls.state, open(cls.statefile, 'w'))
         if cls.cleanup:
             for stackname in cls.stacknames:
                 LOG.info("ensure_destroyed %s", stackname)
                 cfn.ensure_destroyed(stackname)
         # cls.rm_temp_dir()
         # cls.assertFalse(os.path.exists(cls.temp_dir), "failed to delete path %r in tearDown" % cls.temp_dir)
     except BaseException:
         # important, as anything in body will silently fail
         LOG.exception('uncaught error tearing down test class')
Example #3
0
 def tear_down_stack(cls):
     try:
         if cls.reuse_existing_stack:
             json.dump(cls.state, open(cls.statefile, 'w'))
         if cls.cleanup:
             for stackname in cls.stacknames:
                 LOG.info("ensure_destroyed %s", stackname)
                 cfn.ensure_destroyed(stackname)
         # cls.rm_temp_dir()
         # cls.assertFalse(os.path.exists(cls.temp_dir), "failed to delete path %r in tearDown" % cls.temp_dir)
     except BaseException:
         # important, as anything in body will silently fail
         LOG.exception('uncaught error tearing down test class')
Example #4
0
    def set_up_stack(cls, project, explicitly_start=False):
        switch_in_test_settings()

        # to re-use an existing stack, ensure cls.reuse_existing_stack is True
        # this will read the instance name from a temporary file (if it exists) and
        # look for that, creating it if doesn't exist yet
        # also ensure cls.cleanup is False so the instance isn't destroyed after tests complete
        cls.reuse_existing_stack = config.TWI_REUSE_STACK
        cls.cleanup = config.TWI_CLEANUP

        cls.stacknames = []
        cls.environment = generate_environment_name()
        # cls.temp_dir, cls.rm_temp_dir = utils.tempdir()

        # debugging only, where we keep an instance up between processes
        cls.state, cls.statefile = {}, '/tmp/.open-test-instances.txt'

        if cls.reuse_existing_stack and os.path.exists(cls.statefile):
            # evidence of a previous instance and we've been told to re-use old instances
            old_state = json.load(open(cls.statefile, 'r'))
            old_env = old_state.get('environment')

            # test if the old stack still exists ...
            if old_env and core.describe_stack(project + "--" + old_env,
                                               allow_missing=True):
                cls.state = old_state
                cls.environment = old_env
            else:
                # nope. old statefile is bogus, delete it
                os.unlink(cls.statefile)

        cls.state['environment'] = cls.environment  # will be saved later

        with settings(abort_on_prompts=True):
            cls.stackname = '%s--%s' % (project, cls.environment)
            cls.stacknames.append(cls.stackname)

            if cls.cleanup:
                LOG.info("ensure_destroyed %s", cls.stackname)
                cfn.ensure_destroyed(cls.stackname)

            cls.context, cls.cfn_template, _ = cfngen.generate_stack(
                project, stackname=cls.stackname)
            cls.region = cls.context['aws']['region']
            LOG.info("create_stack %s", cls.stackname)
            bootstrap.create_stack(cls.stackname)

            if explicitly_start:
                LOG.info("start %s", cls.stackname)
                lifecycle.start(cls.stackname)
Example #5
0
    def test_blue_green_operations(self):
        with settings(abort_on_prompts=True):
            project = 'project-with-cluster-integration-tests'
            stackname = '%s--%s' % (project, self.environment)

            cfn.ensure_destroyed(stackname)
            self.stacknames.append(stackname)
            cfngen.generate_stack(project, stackname=stackname)
            bootstrap.create_stack(stackname)

            output = cfn.cmd(stackname,
                             'ls -l /',
                             username=BOOTSTRAP_USER,
                             concurrency='blue-green')
            print output
Example #6
0
    def set_up_stack(cls, project, explicitly_start=False):
        switch_in_test_settings()

        # to re-use an existing stack, ensure cls.reuse_existing_stack is True
        # this will read the instance name from a temporary file (if it exists) and
        # look for that, creating it if doesn't exist yet
        # also ensure cls.cleanup is False so the instance isn't destroyed after tests complete
        cls.reuse_existing_stack = config.TWI_REUSE_STACK
        cls.cleanup = config.TWI_CLEANUP

        cls.stacknames = []
        cls.environment = generate_environment_name()
        # cls.temp_dir, cls.rm_temp_dir = utils.tempdir()

        # debugging only, where we keep an instance up between processes
        cls.state, cls.statefile = {}, '/tmp/.open-test-instances.txt'

        if cls.reuse_existing_stack and os.path.exists(cls.statefile):
            # evidence of a previous instance and we've been told to re-use old instances
            old_state = json.load(open(cls.statefile, 'r'))
            old_env = old_state.get('environment')

            # test if the old stack still exists ...
            if old_env and core.describe_stack(project + "--" + old_env, allow_missing=True):
                cls.state = old_state
                cls.environment = old_env
            else:
                # nope. old statefile is bogus, delete it
                os.unlink(cls.statefile)

        cls.state['environment'] = cls.environment # will be saved later

        with settings(abort_on_prompts=True):
            cls.stackname = '%s--%s' % (project, cls.environment)
            cls.stacknames.append(cls.stackname)

            if cls.cleanup:
                LOG.info("ensure_destroyed %s", cls.stackname)
                cfn.ensure_destroyed(cls.stackname)

            cls.context, cls.cfn_template, _ = cfngen.generate_stack(project, stackname=cls.stackname)
            cls.region = cls.context['aws']['region']
            LOG.info("create_stack %s", cls.stackname)
            bootstrap.create_stack(cls.stackname)

            if explicitly_start:
                LOG.info("start %s", cls.stackname)
                lifecycle.start(cls.stackname)
Example #7
0
    def test_create(self):
        with settings(abort_on_prompts=True):
            project = 'dummy1'
            stackname = '%s--%s' % (project, self.environment)

            cfn.ensure_destroyed(stackname)
            self.stacknames.append(stackname) # ensures stack is destroyed

            cfngen.generate_stack(project, stackname=stackname)
            bootstrap.create_stack(stackname)

            buildvars.switch_revision(stackname, 'master')
            buildvars.force(stackname, 'answer', 'forty-two')

            lifecycle.stop(stackname)
            lifecycle.start(stackname)
Example #8
0
    def test_create(self):
        with settings(abort_on_prompts=True):
            project = 'dummy1'
            stackname = '%s--%s' % (project, self.environment)

            cfn.ensure_destroyed(stackname)
            self.stacknames.append(stackname)

            cfngen.generate_stack(project, stackname=stackname)
            bootstrap.create_stack(stackname)

            buildvars.switch_revision(stackname, 'master')
            buildvars.force(stackname, 'answer', 'forty-two')

            cfn.cmd(stackname,
                    "ls -l /",
                    username=BOOTSTRAP_USER,
                    concurrency='parallel')
            cfn.cmd(stackname,
                    "ls -l /",
                    username=BOOTSTRAP_USER,
                    concurrency='parallel',
                    node=1)

            cfn.download_file(stackname,
                              "/bin/ls",
                              "ls",
                              use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./ls"))

            cfn.download_file(stackname,
                              "/bin/less",
                              "venv/bin/",
                              use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./venv/bin/less"))

            cfn.download_file(stackname,
                              "/bin/pwd",
                              "subfolder/pwd",
                              use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./subfolder/pwd"))

            lifecycle.stop_if_running_for(
                stackname, minimum_minutes=60 * 24 * 365
            )  # should exercise the code but do nothing, as this test's instance can't have been running for a year
    def tearDown(self):
        for stackname in self.stacknames:
            cfn.ensure_destroyed(stackname)

        tempfiles = [
            'ls',
            'venv/bin/less',
            'subfolder/pwd',
            'subfolder',
        ]
        for tf in tempfiles:
            path = os.path.join(PROJECT_DIR, tf)
            if os.path.isfile(path):
                os.unlink(path)
            elif os.path.isdir(path):
                # assumes dir is empty
                print('should be empty:', os.listdir(path))
                os.rmdir(path)
            self.assertFalse(os.path.exists(path), "failed to delete path %r in tearDown" % path)
Example #10
0
    def tearDown(self):
        for stackname in self.stacknames:
            cfn.ensure_destroyed(stackname)

        tempfiles = [
            'ls',
            'venv/bin/less',
            'subfolder/pwd',
            'subfolder',
        ]
        for tf in tempfiles:
            path = os.path.join(PROJECT_DIR, tf)
            if os.path.isfile(path):
                os.unlink(path)
            elif os.path.isdir(path):
                # assumes dir is empty
                print 'should be empty:', os.listdir(path)
                os.rmdir(path)
            self.assertFalse(os.path.exists(path),
                             "failed to delete path %r in tearDown" % path)
Example #11
0
    def test_create(self):
        with settings(abort_on_prompts=True):
            project = 'dummy1'
            stackname = '%s--%s' % (project, self.environment)

            cfn.ensure_destroyed(stackname)
            self.stacknames.append(stackname)

            cfngen.generate_stack(project, stackname=stackname)
            bootstrap.create_stack(stackname)

            buildvars.switch_revision(stackname, 'master')
            buildvars.force(stackname, 'answer', 'forty-two')

            lifecycle.stop(stackname)
            lifecycle.start(stackname)

            cfn.cmd(stackname,
                    "ls -l /",
                    username=BOOTSTRAP_USER,
                    concurrency='parallel')

            cfn.download_file(stackname,
                              "/bin/ls",
                              "ls",
                              use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./ls"))

            cfn.download_file(stackname,
                              "/bin/less",
                              "venv/bin/",
                              use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./venv/bin/less"))

            cfn.download_file(stackname,
                              "/bin/pwd",
                              "subfolder/pwd",
                              use_bootstrap_user="******")
            self.assertTrue(os.path.isfile("./subfolder/pwd"))
Example #12
0
 def tearDown(self):
     for stackname in self.stacknames:
         cfn.ensure_destroyed(stackname)