Esempio n. 1
0
    def test_setup(self):

        test_descriptor = {
            "tests": [{
                "name": "my-custom",
                "description": ["custom test driver will be ignored"],
                "setup": "yac/tests/test/lib/setup_cleanup.py",
                "target": "https://www.google.com/",
                "driver": "yac/tests/lib/custom_test_pass.py"
            }]
        }

        params = Params({})

        tests = IntegrationTests(test_descriptor)

        err = tests.run(params,
                        context="",
                        test_names=["my-custom"],
                        setup_only=True)

        # test that the setup was called and set a param
        my_setup_param = params.get('setup-param')

        self.assertTrue(my_setup_param == 'setup-value')
        self.assertTrue(not err)
Esempio n. 2
0
    def test_kvp_params(self):

        kvps = "joe:blue,jan:green"

        params = Params({})
        params.load_kvps(kvps)

        self.assertTrue(params.get("jan") == 'green')
        self.assertTrue(params.get("joe") == 'blue')
Esempio n. 3
0
    def test_no_yac_fxn(self):
        # test when a dictionary references a non-existant yac-fxn

        params = {
            "service-alias": {
                "type": "string",
                "value": "myservice"
            },
            "env": {
                "type": "string",
                "value": "dev"
            }
        }

        test_dict1 = {
            "myparam": {
                "comment": "testing",
                "value": {
                    "yac-calc":
                    ["yac/tests/intrinsics/vectors/nonexistant.py"]
                }
            }
        }

        test_dict2 = {
            "myparam": {
                "comment": "testing",
                "value": {
                    "yac-calc": ["no-existant-stock"]
                }
            }
        }

        # run test
        error_received1 = False
        try:
            updated_dict1 = apply_intrinsics(test_dict1, Params(params))
        except IntrinsicsError as e:
            error_received1 = True

        error_received2 = False
        try:
            updated_dict2 = apply_intrinsics(test_dict2, Params(params))
        except IntrinsicsError as e:
            error_received2 = True

        self.assertTrue(error_received1)
        self.assertTrue(error_received2)
Esempio n. 4
0
    def test_dir_non_existent(self):

        cwd = os.getcwd()
        temp_test_dir = "yac/tests/stacks/aws/vectors/deploy"
        svc_file_path = os.path.join(cwd, temp_test_dir)
        service_parmeters = {
            "render-me": {
                "value": "baby!"
            },
            "service-alias": {
                "value": "testing"
            }
        }
        serialize_boot_files = {
            "directories": [{
                "src":
                "i_do_not_exist",
                "dest":
                "/tmp/stacks/aws/vectors/deploy/rendered/sample_dir"
            }]
        }

        boot_files = BootFiles(serialize_boot_files)

        error_thrown = False
        try:
            boot_files.deploy(Params(service_parmeters),
                              context="",
                              dry_run_bool=False)

        except TemplateError as e:
            # this is the expected condition
            error_thrown = True

        self.assertTrue(error_thrown)
Esempio n. 5
0
    def test_map(self):

        params = {
            "user-name": {
                "value": "henry-grantham"
            },
            "neighborhood-map": {
                "lookup": "user-name",
                "value": {
                    "tom-jackson": "phinney",
                    "henry-grantham": "capital-hill"
                }
            }
        }

        test_dict = {
            "InstancePort": {
                "Ref": "WebServerPort"
            },
            "LoadBalancerName": {
                "yac-ref": "neighborhood-map"
            }
        }

        # run test
        updated_dict = apply_intrinsics(test_dict, Params(params))

        updated_dict_str = json.dumps(updated_dict)

        print(updated_dict_str)

        ref_check = "capital-hill" in updated_dict_str

        self.assertTrue(ref_check)
Esempio n. 6
0
    def test_map_name_error(self):

        params = {
            "user-name": {
                "value": "henry-grantham"
            },
            "neighborhood-map": {
                "lookup": "user-name",
                "value": {
                    "tom-jackson": "phinney",
                    "henry-grantham": "capital-hill"
                }
            }
        }

        test_dict = {
            "InstancePort": {
                "Ref": "WebServerPort"
            },
            "LoadBalancerName": {
                "yac-ref": "neighborhood-maps"
            }
        }

        # verify we get an error
        error_received = False
        try:
            updated_dict = apply_intrinsics(test_dict, Params(params))
        except IntrinsicsError as e:
            error_received = True

        self.assertTrue(error_received)
Esempio n. 7
0
    def test_conditional_miss2(self):

        serialized_input = {
            "key": "alias",
            "title": "Alias",
            "type": "string",
            "help": "Name of alias to assign this custom dev stack",
            "required": True,
            "conditions": {
                "kvps": "env:dev,date:today"
            }
        }

        inputs = Input(serialized_input)

        params = Params({"env": {"value": "dev"}})

        # inject an invalid response followed by a valid response
        sys.stdin = io.StringIO("my-stack")

        value, user_prompted = inputs.process(params)

        # test that the user was not prompted and that no value was returned
        self.assertTrue(not user_prompted)
        self.assertTrue(not value)
Esempio n. 8
0
    def test_dir_template(self):
        # test rendering templates in a directory

        test_dir = 'yac/tests/template/vectors/sample_dir'

        test_file1 = '/tmp/sample_file1.txt'
        test_file2 = '/tmp/sample_file2.tmp'
        test_file3 = '/tmp/sub_dir/sample_file3.txt'
        test_file4 = '/tmp/sample_binary.xls'

        test_variables = {
            "user-fname": {
                "value": "Tom"
            },
            "user-lname": {
                "value": "Jaxon"
            }
        }

        # run test
        apply_templates_in_dir(test_dir, Params(test_variables), "/tmp")

        self.assertTrue('Tom Jaxon' in open(test_file1).read())

        self.assertTrue('Tom Jaxon' in open(test_file2).read())

        self.assertTrue('Tom Jaxon' in open(test_file3).read())

        # test to see if binary file copies to destination properly
        self.assertTrue(os.path.exists(test_file4))
Esempio n. 9
0
    def test_reference_error(self): 
        
        params = {
            "suffix" : {
              "type" : "string",
              "value": ""
            },
            "s3_path": {
               "type" : "boolean",
                "value": "/sets/jira/dev"           
            }
        }

        test_dict = {
            "volumesFrom": {
                "comment": "testing",
                "value": {"yac-ref": "suffi"}
            }
        }

        error_received=False
        try:
            updated_dict = apply_intrinsics(test_dict, Params(params))
        except IntrinsicsError as e:
            error_received = True
            print(json.dumps(test_dict,indent=2))
        
        self.assertTrue(error_received)        
Esempio n. 10
0
    def test_stemplate(self):

        test_file = 'yac/tests/template/vectors/sample_map_file.txt'

        test_variables = {
            "user-name": {
                "value": "henry-grantham"
            },
            "neighborhood-map": {
                "lookup": "user-name",
                "value": {
                    "tom-jackson": "phinney",
                    "henry-grantham": "capital-hill"
                }
            }
        }

        # read file into string
        file_contents = get_file_contents(test_file)

        # run test
        updated_file_contents = apply_stemplate(file_contents,
                                                Params(test_variables))

        # test that the correct neighborhood got rendered into the file contents
        render_check = "capital-hill" in updated_file_contents

        self.assertTrue(render_check)
Esempio n. 11
0
    def test_custom_select(self):

        test_descriptor = {
            "tests": [{
                "name": "my-custom-1",
                "description": ["a custom test driver"],
                "target": "https://www.google.com/",
                "driver": "yac/tests/test/lib/custom_test_fail.py"
            }, {
                "name": "my-custom-2",
                "description": ["a custom test driver"],
                "target": "https://www.google.com/",
                "driver": "yac/tests/test/lib/custom_test_pass.py"
            }]
        }

        tests = IntegrationTests(test_descriptor)

        tests.run(Params({}), "", test_names=["my-custom-1", "my-custom-2"])

        test_results = tests.get_results()

        # test that the pass count is 1 and passing tests includes
        # the requested test
        self.assertTrue(len(test_results.get_passing_tests()) == 1)
        self.assertTrue('my-custom-2' in test_results.get_passing_tests())
Esempio n. 12
0
    def test_files(self):

        temp_test_dir = "yac/tests/stacks/aws/vectors/deploy"
        service_parmeters = {"render-me": {"value": "baby!"},
                             "servicefile-path": {"value": temp_test_dir},
                             "service-alias": {"value": "testing"}}
        serialize_boot_files = {
            "files": [
            {
                "src":  "deploy_for_boot.txt",
                "dest": "/tmp/stacks/aws/vectors/deploy/rendered/deploy_for_boot.txt"
            }
            ]
        }

        boot_files = BootFiles(serialize_boot_files)

        try:
            boot_files.deploy(Params(service_parmeters),context="")

        except FileError as e:
            print(e.msg)

        # read file contents from destination file
        file_contents = get_file_contents(serialize_boot_files['files'][0]['dest'])

        # clean up
        shutil.rmtree("/tmp/stacks/aws/vectors/deploy/rendered")

        self.assertTrue(file_contents == "render my params, then deploy me %s"%(service_parmeters["render-me"]["value"]))
Esempio n. 13
0
    def test_group(self):

        test_descriptor = {
            "test-groups": [{
                "name":
                "group-1",
                "target":
                "https://www.google.com/",
                "tests": [{
                    "name": "my-custom-1",
                    "description": ["a custom test driver"],
                    "target": "https://www.google.com/",
                    "driver": "yac/tests/test/lib/custom_test_pass.py"
                }, {
                    "name": "my-custom-2",
                    "description": ["a custom test driver"],
                    "target": "https://www.google.com/",
                    "driver": "yac/tests/test/lib/custom_test_pass.py"
                }]
            }]
        }

        tests = IntegrationTests(test_descriptor)

        tests.run(Params({}), context="", group_names=["group-1"])

        test_results = tests.get_results()

        # test that all pass
        self.assertTrue(len(test_results.get_passing_tests()) == 2)
Esempio n. 14
0
    def test_yac_fxn(self):

        params = {
            "service-alias": {
                "type": "string",
                "value": "myservice"
            },
            "env": {
                "type": "string",
                "value": "dev"
            }
        }

        test_dict = {
            "myparam": {
                "comment": "testing",
                "value": {
                    "yac-fxn": "yac/tests/intrinsics/vectors/fxn.py"
                }
            }
        }

        # run test
        updated_dict = apply_intrinsics(test_dict, Params(params))

        # test that the value is populated per the value returned by fxn.py
        fxn_check = updated_dict['myparam']['value'] == "myservice"

        self.assertTrue(fxn_check)
Esempio n. 15
0
    def test_null_join(self): 
        
        params = {
            "suffix" : {
              "type" : "string",
              "value": ""
            },
            "s3_path": {
               "type" : "boolean",
                "value": "/sets/jira/dev"           
            }
        }

        test_dict = {
            "volumesFrom": {
                "comment": "testing",
                "value": {"yac-join" : [ "/", [ 
                         {"yac-ref": "s3_path"},
                         {"yac-ref": "suffix"},
                          "backups.json" ]]}
            }
        }

        # run test
        updated_dict = apply_intrinsics(test_dict, Params(params))

        join_check = updated_dict['volumesFrom']['value'] == "/sets/jira/dev/backups.json"

        self.assertTrue(join_check)  
Esempio n. 16
0
    def test_group_test_misselect(self):

        test_descriptor = {
            "test-groups": [{
                "name":
                "group-1",
                "target":
                "https://www.google.com/",
                "tests": [{
                    "name": "my-custom-1",
                    "description": ["a custom test driver"],
                    "target": "https://www.google.com/",
                    "driver": "yac/tests/test/lib/custom_test_pass.py"
                }, {
                    "name": "my-custom-2",
                    "description": ["a custom test driver"],
                    "target": "https://www.google.com/",
                    "driver": "yac/tests/test/lib/custom_test_pass.py"
                }]
            }]
        }

        tests = IntegrationTests(test_descriptor)

        err = tests.run(Params({}),
                        context="",
                        group_names=["group-1:my-custom-na"])

        test_results = tests.get_results()

        # test that the pass count is 0 and that an error was returned
        self.assertTrue(len(test_results.get_passing_tests()) == 0)
        print(err)
        self.assertTrue(err)
Esempio n. 17
0
    def test_stack(self):

        serialized_stack = {
            "type":
            "kubernetes",
            "deployments": [{
                "apiVersion": "apps/v1",
                "kind": "Deployment",
                "spec": {
                    "replicas": 2,
                    "template": {
                        "spec": {
                            "resources": {
                                "requests": {
                                    "memory": "129M",
                                    "cpu": 3
                                },
                                "limits": {
                                    "memory": "250M",
                                    "cpu": 4
                                }
                            }
                        }
                    }
                }
            }]
        }

        stack = K8sStack(serialized_stack)

        stack.cost(Params({}))

        self.assertTrue(stack)
Esempio n. 18
0
def get_params_from_file(cache_full_path):

    # sneak a peak at file before deleting
    with open(cache_full_path) as file_arg_fp:
        file_contents = file_arg_fp.read()

    return Params(json.loads(file_contents))
Esempio n. 19
0
    def test_via_custom_convention_temp(self):

        params = {
            "service-alias": {
                "comment": "my service alias",
                "value": "jira"
            },
            "env": {
                "comment": "environment",
                "value": "dev"
            },
            "naming-convention": {
                "comment": "my custom naming convention",
                "value": {
                    "param-keys": ['service-alias','env'],
                    "delimitter_fake": "-"
                }
            }
          }

        validation_errors = False

        try:
            resource_name = get_resource_name(Params(params), "elb")

        except ValidationError as e:
            validation_errors = True


        self.assertTrue(validation_errors)
Esempio n. 20
0
    def test_naming_convention(self):

        params = {
            "service-alias": {
                "value": "jira"
            },
            "env": {
                "value": "prod"
            },
            "naming-convention": {
                "comment":
                "name resources using the alias followed by the environment",
                "value": {
                    "param-keys": ['service-alias', 'env'],
                    "delimiter": "."
                }
            }
        }

        test_dict = {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Name": {
                "yac-name": "asg"
            }
        }

        updated_dict = apply_intrinsics(test_dict, Params(params))

        name_check = updated_dict['Name'] == 'jira.prod.asg'

        self.assertTrue(name_check)
Esempio n. 21
0
    def test_params(self):

        test_parameters = {
            "ssl-cert" : {
              "value": "godzilla",
              "comment": ""
            },
            "s3_path": {
              "value": "/sets/jira/dev",
              "comment": ""
            }
        }

        # run test
        params = Params(test_parameters)

        self.assertTrue(params.get("ssl-cert") == "godzilla")
Esempio n. 22
0
    def test_boot(self):

        # run test
        boot_list,err = do_calc(["yac/tests/stacks/aws/vectors/boot_simple.sh"],Params({}))

        len_check = len(boot_list)==20

        self.assertTrue(len_check)
Esempio n. 23
0
    def test_map(self):

        test_parameters = {
            "user-name": {
                "value": "tom-johnson"
            },
            "neighborhood-map": {
                "lookup": "user-name",
                "value": {
                    "tom-johnson": "phinney",
                    "henry-grantham": "queen-ann-hill"
                }
            }
        }

        params = Params(test_parameters)

        self.assertTrue(params.get("neighborhood-map") == "phinney")
Esempio n. 24
0
    def test_secrets(self):

        my_secrets = {
            "param-key-1": {
                "comment": "branch 1, child 1, entry 1",
                "source": "keepass",
                "lookup": {
                    "path": "Branch 1/B1-C1/B1-C1-E1",
                    "field": "password"
                }
            },
            "param-key-2": {
                "comment": "branch 2, child 2, entry 1",
                "source": "keepass",
                "lookup": {
                    "path": "Branch 2/B2-C2/B2-C2-E1",
                    "field": "password"
                }
            }
        }

        secrets_vaults = [{
            "type": "keepass",
            "name": "keepass",
            "configs": {
                "vault-path": "yac/tests/vault/vectors/test_vault.kdbx",
                "vault-pwd-path": TestCase.pwd_path
            }
        }]

        params = Params({})

        vaults = SecretVaults(secrets_vaults)

        secrets = Secrets(my_secrets)

        secrets.load(params, vaults)

        print(secrets.get_errors())

        both_loaded = (params.get("param-key-1") == 'b1-c1-e1-secret'
                       and params.get("param-key-2") == 'b2-c2-e1-secret')

        self.assertTrue(both_loaded)
Esempio n. 25
0
    def test_stranger(self):

        string_w_variables = 'Simons says {{yac-calc:["yac/tests/template/vectors/say_hello.py"]}}'

        # run test
        string_w_variables = apply_stemplate(string_w_variables, Params({}))

        # test that "Hello stranger" got rendered into the string contents
        render_check = "hello stranger" in string_w_variables

        self.assertTrue(render_check)
Esempio n. 26
0
    def test_bad_calculator(self):

        string_w_variables = 'Simons says {{yac-calc: ["nonexistent.py"]}}'

        err = ""
        try:
            string_w_variables = apply_stemplate(string_w_variables, Params({}))
        except TemplateError as e:
            err = e

        self.assertTrue(err)
Esempio n. 27
0
    def test_yac_version(self): 
        
        test_parameters = {
            "yac-version" : {
              "value": "2.0"
            }
        }

        ami_id = do_calc([],Params(test_parameters))

        self.assertTrue(ami_id) 
Esempio n. 28
0
    def test_schema_good(self):

        serialized_obj = {
          "type": "gcp-cloudmanager",
          "Resources": {}
        }

        # test that no schema validation errors are raised
        stack = GCPStack(serialized_obj)

        err = stack.build(Params({}))

        self.assertTrue(not err)
Esempio n. 29
0
    def test_map_miss(self):

        # user-name doesn't match any of the map keys

        test_parameters = {
            "user-name": {
                "value": "tom-johnsons"
            },
            "neighborhood-map": {
                "lookup": "user-name",
                "value": {
                    "tom-johnson": "phinney",
                    "henry-grantham": "queen-ann-hill"
                }
            }
        }

        params = Params(test_parameters)

        value = params.get("neighborhood-map", "m.i.a")

        self.assertTrue(value == "m.i.a")
Esempio n. 30
0
    def test_run_task(self):

        tasks = Tasks(TestCase.serialized_tasks)

        restore_task = tasks.get('restore')

        # inject an response to input prompt
        sys.stdin = io.StringIO("dev")

        params = Params({})
        err = restore_task.run(params)

        self.assertTrue(err == "")