Esempio n. 1
0
    def test_events(self):
        create_stack('tank', 'never', self.template_body, self.mock_client)

        # use incorrect name
        r = self.runner.invoke(cli, ['stack', 'events', 'booty'])
        self.assertEqual(-1, r.exit_code)
        self.assertEqual(0, len(r.output))
Esempio n. 2
0
    def off_test_list_filter_miss(self):
        '''filtering not working for mock'''
        create_stack('tank', 'never', self.template_body, self.mock_client)
        create_stack('beef', 'canoe', self.template_body, self.mock_client)

        r = self.runner.invoke(cli, ['stack', 'list', '-f', 'DELETE_COMPLETE'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertEqual(1, len(statuses))
Esempio n. 3
0
    def test_list_filter_hit(self):
        create_stack('tank', 'never', self.template_body, self.mock_client)
        create_stack('beef', 'canoe', self.template_body, self.mock_client)

        r = self.runner.invoke(cli, ['stack', 'list', '-f', 'CREATE_COMPLETE'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertEqual(2, len(statuses))
        self.assertTrue(statuses[0].startswith('tank'))
        self.assertTrue(statuses[1].startswith('beef'))
Esempio n. 4
0
    def test_list(self):
        # first created these stacks in setUp, but didn't carry over
        # "create" two stacks
        create_stack('tank', 'never', self.template_body, self.mock_client)
        create_stack('beef', 'canoe', self.template_body, self.mock_client)

        r = self.runner.invoke(cli, ['stack', 'list'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertEqual(2, len(statuses))
        self.assertTrue(statuses[0].startswith('tank'))
        self.assertTrue(statuses[1].startswith('beef'))
Esempio n. 5
0
    def test_list_long(self):
        create_stack('tank', 'never', self.template_body, self.mock_client)
        create_stack('beef', 'canoe', self.template_body, self.mock_client)

        r = self.runner.invoke(cli, ['stack', 'list', '-l'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertEqual(6, len(statuses))
        self.assertTrue(statuses[0].startswith('tank'))
        self.assertTrue('Id' in statuses[1])
        self.assertTrue('Created' in statuses[2])
        self.assertTrue(statuses[3].startswith('beef'))
        self.assertTrue('Id' in statuses[4])
        self.assertTrue('Created' in statuses[5])
Esempio n. 6
0
    def test_delete(self):
        # first created these stacks in setUp, but didn't carry over
        # "create" two stacks
        create_stack('tank', 'never', self.template_body, self.mock_client)
        create_stack('beef', 'canoe', self.template_body, self.mock_client)

        # use incorrect name
        r = self.runner.invoke(cli, ['stack', 'delete', 'booty'])

        # check that both are still there
        r = self.runner.invoke(cli, ['stack', 'list'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertEqual(2, len(statuses))
        self.assertTrue(statuses[0].startswith('tank'))
        self.assertTrue(statuses[1].startswith('beef'))

        # use correct name
        r = self.runner.invoke(cli, ['stack', 'delete', 'beef'])

        # check that both are still there
        r = self.runner.invoke(cli, ['stack', 'list'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertEqual(1, len(statuses))
        self.assertTrue(statuses[0].startswith('tank'))

        # try it again
        r = self.runner.invoke(cli, ['stack', 'delete', 'beef'])

        # check that both are still there
        r = self.runner.invoke(cli, ['stack', 'list'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertEqual(1, len(statuses))
        self.assertTrue(statuses[0].startswith('tank'))
        self.assertTrue('beef' not in r.output)

        # remove last one
        r = self.runner.invoke(cli, ['stack', 'delete', 'tank'])

        # check it
        r = self.runner.invoke(cli, ['stack', 'list'])
        self.assertEqual(0, r.exit_code)
        statuses = r.output.strip().split('\n')
        self.assertTrue('tank' not in r.output)
Esempio n. 7
0
os.environ['AWS_SHARED_CREDENTIALS_FILE'] = p.credential_name

os.environ['AWS_PROFILE'] = p.credential_name
os.environ['AWS_DEFAULT_REGION'] = p.location

s3 = boto3.resource('s3')
try:
    s3.create_bucket(Bucket=p.data_bucket, CreateBucketConfiguration={'LocationConstraint': p.location})
except ClientError:
    print("Data Bucket Already Created")
u.upload_object(p.data_bucket, p.template_name, p.template_name)
u.upload_zip_object(p.data_bucket, 'lambda_function.py', 'lambda_function.zip', 'lambda_function.zip')
client = boto3.client('cloudformation')
status = u.stack_status(p.stack_name)
if status == 'ROLLBACK_COMPLETE' or status == 'ROLLBACK_FAILED' or status == 'UPDATE_ROLLBACK_COMPLETE' or status == \
        'DELETE_FAILED':
    u.delete_object(p.names["source_bucket"])
    u.delete_object(p.names["dest_bucket"])
    client.delete_stack(StackName=p.stack_name)
    while u.stack_status('stack') == 'DELETE_IN_PROGRESS':
        time.sleep(1)
    print("stack deleted")
    u.create_stack(p.stack_name, p.names["template_url"], p.names["source_bucket"], p.names["dest_bucket"])
    print("stack created")
elif status == 'CREATE_COMPLETE' or status == 'UPDATE_COMPLETE' :
    u.update_stack(p.stack_name, p.names["template_url"], p.names["source_bucket"], p.names["dest_bucket"])
    print("stack updated")
else:
    u.create_stack(p.stack_name, p.names["template_url"], p.names["source_bucket"], p.names["dest_bucket"])
    print("stack created")