def test_will_find_errors_in_all_environment(self): single_service_yaml = """ dev1: nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test aws_key_name: test services: [apache, my_app] type: phoenix.providers.aws_provider.AWSNodeDefinition invalid_node_provider: class_name: InvalidAWSNodeProvider dev2: invalid_nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test services: [apache, my_app] type: phoenix.providers.aws_provider.AWSNodeDefinition node_provider: class_name: FileBackedNodeProvider """ with self.assertRaisesRegexp(Exception, "Key 'nodes' not found for environment 'dev2',\nKey 'node_provider' not found for environment 'dev1'"): environment_definitions_from_yaml(single_service_yaml, service_definitions, 'test', all_credentials)
def test_should_add_service_lifecycle_hook_from_definition(self): yaml_string = """ prod: service_hooks: hello_world: - class_name: phoenix.hooks.elb_hook.ELBHook elb_name: hello_world_us_east_1_elb public_api_key: AKIAIGBFGAGVPGKLVX4Q private_api_key: NAOcwcX3an5hcyLCz3Y4xucwr4Fqxs9ijLn6biqk app_to_elb_ports: { 8080 : 80, 8081 : 81 } app_healthcheck_target: 'HTTP:8081/healthcheck' nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test aws_key_name : test services: [hello_world] security_groups: [ spicy-beef ] availability_zone: us-east-1a type: phoenix.providers.aws_provider.AWSNodeDefinition node_provider: class_name: AWSNodeProvider public_api_key: 123 private_api_key: 1234 """ env_definitions = environment_definitions_from_yaml(yaml_string, service_definitions, 'prod', all_credentials) self.assertEqual(1, len(env_definitions['prod'].service_lifecycle_hooks)) self.assertTrue(isinstance(env_definitions['prod'].service_lifecycle_hooks['hello_world'][0], ELBHook))
def test_will_throw_exception_if_node_provider_key_class_not_valid_for_environment(self): single_service_yaml = """ dev: nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test aws_key_name: test services: [mongo, hello_world] type: phoenix.providers.aws_provider.AWSNodeDefinition node_provider: class_name: InvalidAWSNodeProvider """ with self.assertRaisesRegexp(Exception, "Key 'node_provider' class_name 'InvalidAWSNodeProvider' is invalid for environment 'dev'"): environment_definitions_from_yaml(single_service_yaml, service_definitions, 'dev', all_credentials)
def test_should_return_correct_port_mappings(self): env_yaml_str = """ prod: service_hooks: hello_world: - class_name: phoenix.hooks.elb_hook.ELBHook elb_name: hello_world_us_east_1_elb public_api_key: AKIAIGBFGAGVPGKLVX4Q private_api_key: NAOcwcX3an5hcyLCz3Y4xucwr4Fqxs9ijLn6biqk app_to_elb_ports: { 8080 : 80, 8081 : 81 } app_healthcheck_target: 'HTTP:8081/healthcheck' nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test aws_key_name : test services: [hello_world] security_groups: [ spicy-beef ] availability_zone: us-east-1a type: phoenix.providers.aws_provider.AWSNodeDefinition node_provider: class_name: AWSNodeProvider public_api_key: 123 private_api_key: 1234 """ env_definitions = environment_definitions_from_yaml(env_yaml_str, self.service_definitions, 'prod', self.all_credentials) elb_connectivity_mappings = env_definitions['prod'].service_lifecycle_hooks['hello_world'][0].get_elb_mappings(self.service_definitions['hello_world'].configuration['connectivity']) self.assertEqual(2, len(elb_connectivity_mappings)) self.assertTrue((80, 8080, 'tcp') in elb_connectivity_mappings) self.assertTrue((81, 8081, 'tcp') in elb_connectivity_mappings)
def test_will_throw_exception_if_node_type_is_not_valid(self): env_yaml = """ dev: nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test services: [mongo, hello_world] type: phoenix.providers.aws_provider.InvalidAWSNodeDefinition node_provider: class_name: AWSNodeProvider public_api_key: AKIAIGBFGAGVPGKLVX4Q private_api_key: NAOcwcX3an5hcyLCz3Y4xucwr4Fqxs9ijLn6biqk """ with self.assertRaisesRegexp(Exception, "^Node type 'phoenix.providers.aws_provider.InvalidAWSNodeDefinition' is invalid for node number 1 in 'dev' environment$"): environment_definitions_from_yaml(env_yaml, service_definitions, 'dev', all_credentials)
def test_will_throw_exception_if_LXC_node_fails_validation(self): single_service_yaml = """ test: nodes: - invalid_template: ubuntu services: [hello_world] type: phoenix.providers.lxc_provider.LXCNodeDefinition node_provider: class_name: LXCNodeProvider host_name: ec2-184-72-150-211.compute-1.amazonaws.com admin_user: ubuntu credentials: test """ with self.assertRaisesRegexp(Exception, "^Key 'template' not set for LXC node definition number 1 in 'test' environment$"): environment_definitions_from_yaml(single_service_yaml, service_definitions, 'test', all_credentials)
def test_will_throw_exception_if_AWS_node_provider_is_not_setup_correctly(self): single_service_yaml = """ dev: nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test aws_key_name: test services: [apache, my_app] type: phoenix.providers.aws_provider.AWSNodeDefinition node_provider: class_name: AWSNodeProvider public_api_key: AKIAIGBFGAGVPGKLVX4Q private_api_key_WRONG: NAOcwcX3an5hcyLCz3Y4xucwr4Fqxs9ijLn6biqk """ with self.assertRaisesRegexp(Exception, "Key 'private_api_key' not found for AWS in 'dev' environment"): environment_definitions_from_yaml(single_service_yaml, service_definitions, 'test', all_credentials)
def test_will_throw_exception_if_node_provider_key_not_defined_for_environment(self): single_service_yaml = """ dev: nodes: - ami_id: ami-4dad7424 size: t1.micro credentials_name: test aws_key_name: test services: [mongo, hello_world] type: phoenix.providers.aws_provider.AWSNodeDefinition invalid_node_provider: class_name: AWSNodeProvider public_api_key: AKIAIGBFGAGVPGKLVX4Q private_api_key: NAOcwcX3an5hcyLCz3Y4xucwr4Fqxs9ijLn6biqk """ with self.assertRaisesRegexp(Exception, "Key 'node_provider' not found for environment 'dev'"): environment_definitions_from_yaml(single_service_yaml, service_definitions, 'dev', all_credentials)
def test_can_load_environment_from_yaml(self): single_service_yaml = """ dev: nodes: - role: test type: phoenix.providers.file_node_provider.FileBackedNodeDefinition services: [apache] node_provider: class_name : FileBackedNodeProvider """ environment_definitions = environment_definitions_from_yaml( single_service_yaml, service_definitions, 'dev', all_credentials) environment_definitions['dev'].launch() assert os.path.exists('./fake_nodes/fake_env.yml')