import os
import unittest

import mock
from argparse import ArgumentTypeError

from tests.mock_data import *
import maccli.parser_cli
import maccli.dao.inheritance


class ServiceInheritanceTestCase(unittest.TestCase):

    def setUp(self):
        if os.path.exists(os.getcwd() + "/mock"):
            maccli.pwd = os.getcwd() + "/mock"
        else:
            maccli.pwd = os.getcwd() + "/tests/mock"

    def test_basic_inheritance(self):
        expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced Application'), ('name', 'demo'), ('version', '1.0'), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n'), ('environment', [OrderedDict([('DB_IP', '127.0.0.1')]), OrderedDict([('APP_BRANCH', 'master')])])]))]))])), ('infrastructures', OrderedDict([('image_base_inf', OrderedDict([('name', 'app'), ('provider', 'amazon'), ('location', 'us-east-1'), ('hardware', 't1.micro'), ('role', 'app'), ('release', 'ubuntu'), ('amount', 1)])), ('build_lb_inf', OrderedDict([('resource', 'build_lb')])), ('create_image_inf', OrderedDict([('resource', 'create_image')])), ('create_launch_configuration_inf', OrderedDict([('resource', 'create_launch_configuration')])), ('create_autoscale_group_inf', OrderedDict([('resource', 'create_autoscale_group')]))])), ('actions', {'get_id': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/instance-id')]), 'get_security_groups': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/security-groups')]), 'get_availability_zone': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')])}), ('resources', {'build_lb': OrderedDict([('create bash', 'aws elb create-load-balancer --load-balancer-name my-load-balancer --listeners Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80 --region infrastructure.image_base_inf.location --availability-zones role.app.get_availability_zone')]), 'create_autoscale_group': OrderedDict([('create bash', 'aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-lb-asg --launch-configuration-name my-lc --availability-zones role.app.get_availability_zone --load-balancer-names my-load-balancer --max-size 5 --min-size 1 --desired-capacity 2 --region infrastructure.image_base_inf.location')]), 'create_launch_configuration': OrderedDict([('create bash', 'aws autoscaling create-launch-configuration --launch-configuration-name my-lc --image-id resource.create_image_inf.json.ImageId --instance-type infrastructure.image_base_inf.hardware --security-groups role.app.get_security_groups --region infrastructure.image_base_inf.location')]), 'create_image': OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name DemoApplication3 --description MyDemoApplication --region infrastructure.image_base_inf.location')])})])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_BASIC_INHERITANCE, [])
        self.assertEquals(actual, expected)

    def test_single_inheritance(self):
        maccli.logging.basicConfig(level=maccli.logging.DEBUG)
        expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced Application'), ('name', 'demo'), ('version', '1.0'), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n'), ('environment', [OrderedDict([('DB_IP', '127.0.0.1')]), OrderedDict([('APP_BRANCH', 'master')])])]))]))])), ('infrastructures', OrderedDict([('image_base_inf', OrderedDict([('name', 'app'), ('provider', 'amazon'), ('location', 'us-east-1'), ('hardware', 't1.micro'), ('role', 'app'), ('release', 'ubuntu'), ('amount', 1)])), ('create_image_inf', {'resource': 'create_image'}), ('build_lb_inf', OrderedDict([('resource', 'build_lb')])), ('create_launch_configuration_inf', OrderedDict([('resource', 'create_launch_configuration')])), ('create_autoscale_group_inf', OrderedDict([('resource', 'create_autoscale_group')]))])), ('actions', {'get_id': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/instance-id')]), 'get_security_groups': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/security-groups')]), 'get_availability_zone': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')])}), ('resources', {'build_lb': OrderedDict([('create bash', 'aws elb create-load-balancer --load-balancer-name my-load-balancer --listeners Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80 --region infrastructure.image_base_inf.location --availability-zones role.app.get_availability_zone')]), 'create_autoscale_group': OrderedDict([('create bash', 'aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-lb-asg --launch-configuration-name my-lc --availability-zones role.app.get_availability_zone --load-balancer-names my-load-balancer --max-size 5 --min-size 1 --desired-capacity 2 --region infrastructure.image_base_inf.location')]), 'create_launch_configuration': OrderedDict([('create bash', 'aws autoscaling create-launch-configuration --launch-configuration-name my-lc --image-id resource.create_image_inf.json.ImageId --instance-type infrastructure.image_base_inf.hardware --security-groups role.app.get_security_groups --region infrastructure.image_base_inf.location')]), 'create_image': OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name DemoApplication3 --description MyDemoApplication --region infrastructure.image_base_inf.location')])})])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_SINGLE_INHERITANCE, [])
        self.assertEquals(actual, expected)

    def test_some_infrastructure_default_values(self):
        maccli.logging.basicConfig(level=maccli.logging.DEBUG)
        expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced Application'), ('name', 'demo'), ('version', '1.0'), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n'), ('environment', [OrderedDict([('DB_IP', '127.0.0.1')]), OrderedDict([('APP_BRANCH', 'master')])])]))]))])), ('infrastructures', OrderedDict([('image_base_inf', OrderedDict([('location', 'us-east-1'), ('hardware', 't1.micro'), ('role', 'app'), ('release', 'ubuntu'), ('amount', 1), ('name', 'app'), ('provider', 'amazon')])), ('create_image_inf', {'resource': 'create_image'}), ('build_lb_inf', OrderedDict([('resource', 'build_lb')])), ('create_launch_configuration_inf', OrderedDict([('resource', 'create_launch_configuration')])), ('create_autoscale_group_inf', OrderedDict([('resource', 'create_autoscale_group')]))])), ('actions', {'get_id': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/instance-id')]), 'get_security_groups': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/security-groups')]), 'get_availability_zone': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')])}), ('resources', {'build_lb': OrderedDict([('create bash', 'aws elb create-load-balancer --load-balancer-name my-load-balancer --listeners Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80 --region infrastructure.image_base_inf.location --availability-zones role.app.get_availability_zone')]), 'create_autoscale_group': OrderedDict([('create bash', 'aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-lb-asg --launch-configuration-name my-lc --availability-zones role.app.get_availability_zone --load-balancer-names my-load-balancer --max-size 5 --min-size 1 --desired-capacity 2 --region infrastructure.image_base_inf.location')]), 'create_launch_configuration': OrderedDict([('create bash', 'aws autoscaling create-launch-configuration --launch-configuration-name my-lc --image-id resource.create_image_inf.json.ImageId --instance-type infrastructure.image_base_inf.hardware --security-groups role.app.get_security_groups --region infrastructure.image_base_inf.location')]), 'create_image': OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name DemoApplication3 --description MyDemoApplication --region infrastructure.image_base_inf.location')])})])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_SOME_VALUES_INHERITANCE, [])
        self.assertEquals(actual, expected)

    def test_override_infrastructure_default_values(self):
        maccli.logging.basicConfig(level=maccli.logging.DEBUG)
        expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced Application'), ('name', 'demo'), ('version', '1.0'), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n'), ('environment', [OrderedDict([('DB_IP', '127.0.0.1')]), OrderedDict([('APP_BRANCH', 'master')])])]))]))])), ('infrastructures', OrderedDict([('image_base_inf', OrderedDict([('name', 'override'), ('location', 'us-east-1'), ('hardware', 't1.micro'), ('role', 'app'), ('release', 'ubuntu'), ('amount', 1), ('provider', 'amazon')])), ('create_image_inf', {'resource': 'create_image'}), ('build_lb_inf', OrderedDict([('resource', 'build_lb')])), ('create_launch_configuration_inf', OrderedDict([('resource', 'create_launch_configuration')])), ('create_autoscale_group_inf', OrderedDict([('resource', 'create_autoscale_group')]))])), ('actions', {'get_id': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/instance-id')]), 'get_security_groups': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/security-groups')]), 'get_availability_zone': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')])}), ('resources', {'build_lb': OrderedDict([('create bash', 'aws elb create-load-balancer --load-balancer-name my-load-balancer --listeners Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80 --region infrastructure.image_base_inf.location --availability-zones role.app.get_availability_zone')]), 'create_autoscale_group': OrderedDict([('create bash', 'aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-lb-asg --launch-configuration-name my-lc --availability-zones role.app.get_availability_zone --load-balancer-names my-load-balancer --max-size 5 --min-size 1 --desired-capacity 2 --region infrastructure.image_base_inf.location')]), 'create_launch_configuration': OrderedDict([('create bash', 'aws autoscaling create-launch-configuration --launch-configuration-name my-lc --image-id resource.create_image_inf.json.ImageId --instance-type infrastructure.image_base_inf.hardware --security-groups role.app.get_security_groups --region infrastructure.image_base_inf.location')]), 'create_image': OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name DemoApplication3 --description MyDemoApplication --region infrastructure.image_base_inf.location')])})])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_OVERRIDE_VALUES_INHERITANCE, [])
        self.assertEquals(actual, expected)

    def test_override_action(self):
        maccli.logging.basicConfig(level=maccli.logging.DEBUG)
        expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced Application'), ('name', 'demo'), ('version', '1.0'), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n'), ('environment', [OrderedDict([('DB_IP', '127.0.0.1')]), OrderedDict([('APP_BRANCH', 'master')])])]))]))])), ('actions', OrderedDict([('get_id', OrderedDict([('ssh', 'overrided action')])), ('get_availability_zone', OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')])), ('get_security_groups', OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/security-groups')]))])), ('infrastructures', OrderedDict([('image_base_inf', OrderedDict([('name', 'override'), ('location', 'us-east-1'), ('hardware', 't1.micro'), ('role', 'app'), ('release', 'ubuntu'), ('amount', 1), ('provider', 'amazon')])), ('create_image_inf', {'resource': 'create_image'}), ('build_lb_inf', OrderedDict([('resource', 'build_lb')])), ('create_launch_configuration_inf', OrderedDict([('resource', 'create_launch_configuration')])), ('create_autoscale_group_inf', OrderedDict([('resource', 'create_autoscale_group')]))])), ('resources', {'build_lb': OrderedDict([('create bash', 'aws elb create-load-balancer --load-balancer-name my-load-balancer --listeners Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80 --region infrastructure.image_base_inf.location --availability-zones role.app.get_availability_zone')]), 'create_autoscale_group': OrderedDict([('create bash', 'aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-lb-asg --launch-configuration-name my-lc --availability-zones role.app.get_availability_zone --load-balancer-names my-load-balancer --max-size 5 --min-size 1 --desired-capacity 2 --region infrastructure.image_base_inf.location')]), 'create_launch_configuration': OrderedDict([('create bash', 'aws autoscaling create-launch-configuration --launch-configuration-name my-lc --image-id resource.create_image_inf.json.ImageId --instance-type infrastructure.image_base_inf.hardware --security-groups role.app.get_security_groups --region infrastructure.image_base_inf.location')]), 'create_image': OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name DemoApplication3 --description MyDemoApplication --region infrastructure.image_base_inf.location')])})])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_OVERRIDE_ACTION, [])
        self.assertEquals(actual, expected)

    def test_override_resource(self):
        maccli.logging.basicConfig(level=maccli.logging.DEBUG)
        expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced Application'), ('name', 'demo'), ('version', '1.0'), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n'), ('environment', [OrderedDict([('DB_IP', '127.0.0.1')]), OrderedDict([('APP_BRANCH', 'master')])])]))]))])), ('resources', OrderedDict([('build_lb', OrderedDict([('create bash', 'overrided resource')])), ('create_image', OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name DemoApplication3 --description MyDemoApplication --region infrastructure.image_base_inf.location')])), ('create_launch_configuration', OrderedDict([('create bash', 'aws autoscaling create-launch-configuration --launch-configuration-name my-lc --image-id resource.create_image_inf.json.ImageId --instance-type infrastructure.image_base_inf.hardware --security-groups role.app.get_security_groups --region infrastructure.image_base_inf.location')])), ('create_autoscale_group', OrderedDict([('create bash', 'aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-lb-asg --launch-configuration-name my-lc --availability-zones role.app.get_availability_zone --load-balancer-names my-load-balancer --max-size 5 --min-size 1 --desired-capacity 2 --region infrastructure.image_base_inf.location')]))])), ('infrastructures', OrderedDict([('image_base_inf', OrderedDict([('name', 'override'), ('location', 'us-east-1'), ('hardware', 't1.micro'), ('role', 'app'), ('release', 'ubuntu'), ('amount', 1), ('provider', 'amazon')])), ('create_image_inf', {'resource': 'create_image'}), ('build_lb_inf', OrderedDict([('resource', 'build_lb')])), ('create_launch_configuration_inf', OrderedDict([('resource', 'create_launch_configuration')])), ('create_autoscale_group_inf', OrderedDict([('resource', 'create_autoscale_group')]))])), ('actions', {'get_id': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/instance-id')]), 'get_security_groups': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/security-groups')]), 'get_availability_zone': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')])})])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_OVERRIDE_RESOURCE, [])
        self.assertEquals(actual, expected)

    def test_override_params(self):
        maccli.logging.basicConfig(level=maccli.logging.DEBUG)
        expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced Application'), ('name', 'demo'), ('version', '1.0'), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n'), ('environment', [OrderedDict([('DB_IP', '127.0.0.1')]), OrderedDict([('APP_BRANCH', 'master')])])]))]))])), ('infrastructures', OrderedDict([('create_image_inf', OrderedDict([('params', OrderedDict([('param1', 9), ('param2', 2), ('param3', 3)])), ('resource', 'create_image')]))])), ('actions', {}), ('resources', {'create_image': OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name DemoApplication3 --description MyDemoApplication --region infrastructure.image_base_inf.location')])})])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_OVERRIDE_PARAMS, [])
        self.assertEquals(actual, expected)

    # def test_override_params_1(self):
    #     maccli.logging.basicConfig(level=maccli.logging.DEBUG)
    #     expected = OrderedDict([('mac', '1.0.0'), ('description', 'Scaled and Load-Balanced nginx'), ('name', 'demo'), ('version', 3), ('roles', OrderedDict([('app', OrderedDict([('instance create', OrderedDict([('bootstrap bash', 'sudo apt-get update\nsudo apt-get install nginx -y\n')]))]))])), ('infrastructures', OrderedDict([('image_base_inf', OrderedDict([('name', 'app'), ('provider', 'amazon'), ('location', 'us-east-1'), ('hardware', 't1.micro'), ('role', 'app'), ('release', 'ubuntu:trusty'), ('amount', 1)])), ('build_lb_inf', {'params': OrderedDict([('listeners', 'Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80'), ('region', 'us-east-1')]), 'resource': 'build_lb'}), ('register_lb_inf', {'params': OrderedDict([('load-balancer-name', 'lb-demo-3'), ('instances', 'role.app.get_id'), ('region', 'us-east-1')]), 'resource': 'register_lb'}), ('create_image_inf', {'ready': 'role.app', 'params': OrderedDict([('region', 'us-east-1')]), 'resource': 'create_image'}), ('create_launch_configuration_inf', {'params': OrderedDict([('region', 'us-east-1')]), 'resource': 'create_launch_configuration'}), ('create_autoscale_group_inf', OrderedDict([('params', OrderedDict([('max-size', 5), ('min-size', 1), ('desired-capacity', 1), ('region', 'us-east-1')])), ('resource', 'create_autoscale_group')])), ('policy_up_inf', OrderedDict([('resource', 'scale_policy'), ('params', OrderedDict([('policy-name', 'ac-up-policy-demo-3'), ('auto-scaling-group-name', 'asg-demo-3'), ('scaling-adjustment', '2'), ('region', 'us-east-1')]))])), ('policy_down_inf', OrderedDict([('resource', 'scale_policy'), ('params', OrderedDict([('policy-name', 'ac-down-policy-demo-3'), ('auto-scaling-group-name', 'asg-demo-3'), ('scaling-adjustment', '-1'), ('region', 'us-east-1')]))])), ('cloudwatch_add_capacity_inf', OrderedDict([('resource', 'cloudwatch'), ('params', OrderedDict([('alarm-name', 'add-capacity-policy-up-demo-3'), ('threshold', '10'), ('comparison-operator', 'GreaterThanOrEqualToThreshold'), ('evaluation-periods', '2'), ('alarm-actions', 'resource.policy_up_inf.json.PolicyARN'), ('region', 'us-east-1')]))])), ('cloudwatch_remove_capacity_inf', OrderedDict([('resource', 'cloudwatch'), ('params', OrderedDict([('alarm-name', 'remove-capacity-policy-down-demo-3'), ('threshold', '3'), ('comparison-operator', 'LessThanOrEqualToThreshold'), ('evaluation-periods', '45'), ('alarm-actions', 'resource.policy_down_inf.json.PolicyARN'), ('region', 'us-east-1')]))]))])), ('actions', {'get_id': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/instance-id')]), 'get_security_groups': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/security-groups')]), 'get_availability_zone': OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')])}), ('resources', {'register_lb': OrderedDict([('create bash', 'aws elb register-instances-with-load-balancer --load-balancer-name infrastructure.param.load-balancer-name --instances infrastructure.param.instances --region infrastructure.param.region')]), 'build_lb': OrderedDict([('create bash', 'aws elb create-load-balancer --load-balancer-name lb-demo-3 --listeners infrastructure.param.listeners --region infrastructure.param.region --availability-zones role.app.get_availability_zone'), ('destroy bash', 'aws elb delete-load-balancer --load-balancer-name lb-demo-3 --region infrastructure.param.region')]), 'create_autoscale_group': OrderedDict([('create bash', 'aws autoscaling create-auto-scaling-group --auto-scaling-group-name asg-demo-3 --launch-configuration-name lc-demo-3 --availability-zones role.app.get_availability_zone --load-balancer-names lb-demo-3 --max-size infrastructure.param.max-size --min-size infrastructure.param.min-size --desired-capacity infrastructure.param.desired-capacity --region infrastructure.param.region'), ('destroy bash', '#!/bin/sh\naws autoscaling update-auto-scaling-group --auto-scaling-group-name asg-demo-3 --min-size 0 --max-size 0 --desired-capacity 0 --region us-east-1\nINSTANCES=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names asg-demo-3 --query "AutoScalingGroups[0].Instances[*].InstanceId" --output text --region infrastructure.image_base_inf.location )\nif [ ! -z "$INSTANCES" ]\nthen\n      aws ec2 wait instance-terminated --instance-ids $INSTANCES --region infrastructure.param.region\nfi\nsleep 10\naws autoscaling delete-auto-scaling-group --auto-scaling-group-name asg-demo-3 --force-delete --region infrastructure.param.region\n')]), 'create_launch_configuration': OrderedDict([('create bash', 'aws autoscaling create-launch-configuration --launch-configuration-name lc-demo-3 --image-id resource.create_image_inf.json.ImageId --instance-type infrastructure.image_base_inf.hardware --security-groups role.app.get_security_groups --region infrastructure.param.region'), ('destroy bash', 'aws autoscaling delete-launch-configuration --launch-configuration-name lc-demo-3 --region infrastructure.param.region')]), 'scale_policy': OrderedDict([('create bash', 'aws autoscaling put-scaling-policy --policy-name infrastructure.param.policy-name --auto-scaling-group-name asg-demo-3 --scaling-adjustment infrastructure.param.scaling-adjustment --adjustment-type ChangeInCapacity --cooldown 300 --region infrastructure.param.region')]), 'create_image': OrderedDict([('create bash', 'aws ec2 create-image --instance-id infrastructure.image_base_inf.get_id --name img-demo-3 --description img-demo-3 --region infrastructure.param.region'), ('destroy bash', 'aws ec2 deregister-image --image-id resource.create_image_inf.json.ImageId --region infrastructure.param.region')]), 'cloudwatch': OrderedDict([('create bash', 'aws cloudwatch put-metric-alarm --alarm-name infrastructure.param.alarm-name --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 60 --threshold infrastructure.param.threshold --comparison-operator infrastructure.param.comparison-operator --dimensions "Name=AutoScalingGroupName,Value=asg-demo-3" --evaluation-periods infrastructure.param.evaluation-periods --alarm-actions infrastructure.param.alarm-actions --region infrastructure.param.region'), ('destroy bash', 'aws cloudwatch delete-alarms --alarm-name infrastructure.param.alarm-name --region infrastructure.param.region')])})])
    #     actual = maccli.dao.inheritance.resolve_inheritance(MOCK_OVERRIDE_PARAMS_1, ['INF_NAME=demo', 'INF_VERSION=3', 'AWS_REGION=us-east-1'])
    #     self.assertEquals(actual, expected)

    def test_roles_environment_no_dash(self):
        expected = OrderedDict([('mac', '0.9.19'), ('description', 'Wordpress Containers'), ('name', 'application_1'), ('version', 1.0), ('actions', OrderedDict([('get_id', OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/instance-id')])), ('get_availability_zone', OrderedDict([('ssh', 'wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone')]))])), ('roles', OrderedDict([('wordpress_template', OrderedDict([('instance create', OrderedDict([('branch', 'master'), ('configuration', 'app'), ('environment', OrderedDict([('RDS_FQDN', 'rds-demo.cbhgwxgu29ez.us-east-1.rds.amazonaws.com'), ('RDS_USER', 'myuser'), ('RDS_PASS', 'mysecretpass'), ('WORDPRESS_VERSION', '4.3.1-apache')]))]))]))])), ('infrastructures', OrderedDict([('wordpress_server', OrderedDict([('deployment', 'testing'), ('hardware', 't2.micro'), ('location', 'us-east-1'), ('name', 'wordpress'), ('provider', 'amazon'), ('release', 'any'), ('role', 'wordpress_template'), ('lifespan', 600), ('amount', 1)]))]))])
        actual = maccli.dao.inheritance.resolve_inheritance(MOCK_MACFILE_PARAMS_ROLES_ENVIRONMENT_NO_DASH, [])
        self.assertEquals(actual, expected)
