Exemplo n.º 1
0
class transition_spec(statement_spec):
    args = lambda s, self_type, self_name: {
        "days": sb.optional_spec(sb.integer_spec()),
        "date": capitalized_only_spec(),
        ("storage", "class"): sb.string_choice_spec(["GLACIER", "STANDARD_IA"])
    }
    required = ["storageclass"]
    conflicting = [('days', 'date')]
    validators = [validators.has_either(["days", "Days", "date", "Date"])]
    final_kls = lambda s, *args, **kwargs: LifecycleTransitionConfig(
        *args, **kwargs)
Exemplo n.º 2
0
class expiration_spec(statement_spec):
    args = lambda s, self_type, self_name: {
        "days":
        sb.optional_spec(sb.integer_spec()),
        "date":
        capitalized_only_spec(),
        (("sep", "_"), ("parts", ("expired", "object", "delete", "marker"))):
        sb.optional_spec(sb.boolean())
    }
    conflicting = [('days', 'date', 'expired_object_delete_marker')]
    validators = [
        validators.has_either([
            "days", "Days", "date", "Date", "expired_object_delete_marker",
            "ExpiredObjectDeleteMarker"
        ])
    ]
    final_kls = lambda s, *args, **kwargs: LifecycleExpirationConfig(
        *args, **kwargs)
Exemplo n.º 3
0
    it "uses validate if value is specified":
        result = mock.Mock(name="result")
        validate = mock.Mock(name="validate")
        validate.return_value = result

        validator = type("Validator", (Validator, ), {"validate": validate})()
        self.assertIs(validator.normalise(self.meta, self.val), result)
        validate.assert_called_once_with(self.meta, self.val)

describe TestCase, "has_either":
    before_each:
        self.meta = mock.Mock(name="meta")

    it "takes in choices":
        choices = mock.Mock(name="choices")
        validator = va.has_either(choices)
        self.assertIs(validator.choices, choices)

    it "complains if none of the values are satisfied":
        choices = ["one", "two"]
        with self.fuzzyAssertRaisesError(BadSpecValue, "Need to specify atleast one of the required keys", meta=self.meta, choices=choices):
            va.has_either(choices).normalise(self.meta, {})

        with self.fuzzyAssertRaisesError(BadSpecValue, "Need to specify atleast one of the required keys", meta=self.meta, choices=choices):
            va.has_either(choices).normalise(self.meta, {"one": NotSpecified})

    it "Lets the val through if it has atleast one choice":
        val = {"one": 1}
        self.assertEqual(va.has_either(["one", "two"]).normalise(self.meta, val), val)

describe TestCase, "has_only_one_of":
Exemplo n.º 4
0
    it "uses validate if value is specified":
        result = mock.Mock(name="result")
        validate = mock.Mock(name="validate")
        validate.return_value = result

        validator = type("Validator", (Validator, ), {"validate": validate})()
        self.assertIs(validator.normalise(self.meta, self.val), result)
        validate.assert_called_once_with(self.meta, self.val)

describe TestCase, "has_either":
    before_each:
        self.meta = mock.Mock(name="meta")

    it "takes in choices":
        choices = mock.Mock(name="choices")
        validator = va.has_either(choices)
        self.assertIs(validator.choices, choices)

    it "complains if none of the values are satisfied":
        choices = ["one", "two"]
        with self.fuzzyAssertRaisesError(BadSpecValue, "Need to specify atleast one of the required keys", meta=self.meta, choices=choices):
            va.has_either(choices).normalise(self.meta, {})

        with self.fuzzyAssertRaisesError(BadSpecValue, "Need to specify atleast one of the required keys", meta=self.meta, choices=choices):
            va.has_either(choices).normalise(self.meta, {"one": NotSpecified})

    it "Lets the val through if it has atleast one choice":
        val = {"one": 1}
        self.assertEqual(va.has_either(["one", "two"]).normalise(self.meta, val), val)

describe TestCase, "no_whitesapce":
Exemplo n.º 5
0
 def stack_spec(self):
     """Spec for each stack"""
     return create_spec(
         stack_objs.Stack,
         validators.deprecated_key(
             "url_checker", "Use ``confirm_deployment.url_checker1``"),
         validators.deprecated_key(
             "deploys_s3_path",
             "Use ``confirm_deployment.deploys_s3_path``"),
         validators.deprecated_key(
             "sns_confirmation",
             "Use ``confirm_deployment.sns_confirmation``"),
         validators.deprecated_key("autoscaling_group_id",
                                   "Use ``auto_scaling_group_name``"),
         validators.deprecated_key(
             "instance_count_limit",
             "Use ``scaling_options.instance_count_limit``"),
         bespin=any_spec(),
         name=formatted(defaulted(string_spec(), "{_key_name_1}"),
                        formatter=MergedOptionStringFormatter),
         key_name=formatted(overridden("{_key_name_1}"),
                            formatter=MergedOptionStringFormatter),
         stack_name=formatted(defaulted(string_spec(), "{_key_name_1}"),
                              formatter=MergedOptionStringFormatter),
         environment=formatted(overridden("{environment}"),
                               formatter=MergedOptionStringFormatter),
         env=listof(stack_specs.env_spec(),
                    expect=stack_objs.EnvironmentVariable),
         build_env=listof(stack_specs.env_spec(),
                          expect=stack_objs.EnvironmentVariable),
         stack_name_env=listof(stack_specs.env_spec(),
                               expect=stack_objs.EnvironmentVariable),
         tags=self.tags_spec,
         termination_protection=defaulted(boolean(), False),
         stack_json=valid_stack_json(
             default="{config_root}/{_key_name_1}.json"),
         stack_yaml=valid_stack_yaml(
             default="{config_root}/{_key_name_1}.yaml"),
         params_json=valid_params_json(
             default="{config_root}/{environment}/{_key_name_1}-params.json"
         ),
         params_yaml=valid_params_yaml(
             default="{config_root}/{environment}/{_key_name_1}-params.yaml"
         ),
         stack_policy=valid_policy_json(
             default="{config_root}/{_key_name_1}-policy.json"),
         role_name=formatted(string_spec(),
                             formatter=MergedOptionStringFormatter),
         build_first=listof(
             formatted(string_spec(),
                       formatter=MergedOptionStringFormatter)),
         build_after=listof(
             formatted(string_spec(),
                       formatter=MergedOptionStringFormatter)),
         build_timeout=defaulted(integer_spec(), 1200),
         ignore_deps=defaulted(boolean(), False),
         vars=delayed(
             dictof(string_spec(), stack_specs.var_spec(), nested=True)),
         skip_update_if_equivalent=listof(stack_specs.skipper_spec()),
         suspend_actions=defaulted(boolean(), False),
         auto_scaling_group_name=optional_spec(
             formatted(string_spec(),
                       formatter=MergedOptionStringFormatter)),
         artifact_retention_after_deployment=defaulted(boolean(), False),
         command=optional_spec(string_spec()),
         netscaler=optional_spec(self.netscaler_spec),
         notify_stackdriver=defaulted(boolean(), False),
         stackdriver=optional_spec(
             create_spec(
                 stack_objs.Stackdriver,
                 api_key=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 deployment_version=defaulted(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter),
                     "<version>"))),
         dns=optional_spec(
             stack_specs.dns_spec(
                 create_spec(
                     stack_objs.DNS,
                     vars=dictof(
                         string_spec(),
                         formatted(string_spec(),
                                   formatter=MergedOptionStringFormatter),
                         nested=True),
                     providers=dictof(string_spec(),
                                      stack_specs.dns_provider_spec()),
                     sites=delayed(
                         dictof(string_spec(),
                                stack_specs.dns_site_spec()))))),
         scaling_options=create_spec(
             ScalingOptions,
             highest_min=defaulted(integer_spec(), 2),
             instance_count_limit=defaulted(integer_spec(), 10)),
         artifacts=container_spec(
             artifact_objs.ArtifactCollection,
             dictof(
                 string_spec(),
                 create_spec(
                     artifact_objs.Artifact,
                     not_created_here=defaulted(boolean(), False),
                     compression_type=string_choice_spec(["gz", "xz"]),
                     history_length=integer_spec(),
                     cleanup_prefix=optional_spec(string_spec()),
                     upload_to=formatted(
                         string_spec(),
                         formatter=MergedOptionStringFormatter),
                     commands=listof(stack_specs.artifact_command_spec(),
                                     expect=artifact_objs.ArtifactCommand),
                     paths=listof(stack_specs.artifact_path_spec(),
                                  expect=artifact_objs.ArtifactPath),
                     files=listof(
                         create_spec(
                             artifact_objs.ArtifactFile,
                             validators.has_either(["content", "task"]),
                             content=optional_spec(
                                 formatted(
                                     string_spec(),
                                     formatter=MergedOptionStringFormatter)
                             ),
                             task=optional_spec(
                                 formatted(
                                     string_spec(),
                                     formatter=MergedOptionStringFormatter)
                             ),
                             path=formatted(
                                 string_spec(),
                                 formatter=MergedOptionStringFormatter),
                             task_runner=formatted(
                                 always_same_spec("{task_runner}"),
                                 formatter=MergedOptionStringFormatter)))))
         ),
         newrelic=optional_spec(
             create_spec(
                 stack_objs.NewRelic,
                 api_key=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 account_id=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 application_id=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 env=listof(stack_specs.env_spec(),
                            expect=stack_objs.EnvironmentVariable),
                 deployed_version=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)))),
         downtimer_options=optional_spec(
             dictof(
                 valid_string_spec(valid_alerting_system()),
                 create_spec(
                     stack_objs.DowntimerOptions,
                     hosts=listof(
                         formatted(
                             string_spec(),
                             formatter=MergedOptionStringFormatter))))),
         alerting_systems=optional_spec(
             dictof(string_spec(), self.alerting_system_spec)),
         ssh=optional_spec(
             create_spec(
                 stack_objs.SSH,
                 validators.deprecated_key(
                     "autoscaling_group_id",
                     "Use ``auto_scaling_group_name``"),
                 user=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion_user=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion_key_location=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 instance_key_location=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 address=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 instance=optional_spec(
                     listof(
                         formatted(string_spec(),
                                   formatter=MergedOptionStringFormatter))),
                 auto_scaling_group_name=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion_key_path=formatted(
                     defaulted(
                         string_spec(),
                         "{config_root}/{environment}/bastion_ssh_key.pem"),
                     formatter=MergedOptionStringFormatter),
                 instance_key_path=formatted(
                     defaulted(string_spec(),
                               "{config_root}/{environment}/ssh_key.pem"),
                     formatter=MergedOptionStringFormatter),
                 storage_type=formatted(
                     defaulted(string_choice_spec(["url", "rattic"]),
                               "url"),
                     formatter=MergedOptionStringFormatter),
                 storage_host=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)))),
         confirm_deployment=optional_spec(self.confirm_deployment_spec))
Exemplo n.º 6
0
    def stack_spec(self):
        """Spec for each stack"""
        return create_spec(stack_objs.Stack
            , validators.deprecated_key("url_checker", "Use ``confirm_deployment.url_checker1``")
            , validators.deprecated_key("deploys_s3_path", "Use ``confirm_deployment.deploys_s3_path``")
            , validators.deprecated_key("sns_confirmation", "Use ``confirm_deployment.sns_confirmation``")
            , validators.deprecated_key("autoscaling_group_id", "Use ``auto_scaling_group_name``")
            , validators.deprecated_key("instance_count_limit", "Use ``scaling_options.instance_count_limit``")

            , bespin = any_spec()

            , name = formatted(defaulted(string_spec(), "{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , key_name = formatted(overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , stack_name = formatted(defaulted(string_spec(), "{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , environment = formatted(overridden("{environment}"), formatter=MergedOptionStringFormatter)

            , env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)
            , build_env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)
            , stack_name_env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)

            , tags = dictionary_spec()

            , stack_json = valid_stack_json(default="{config_root}/{_key_name_1}.json")

            , params_json = valid_params_json(default="{config_root}/{environment}/{_key_name_1}-params.json")
            , params_yaml = valid_params_yaml(default="{config_root}/{environment}/{_key_name_1}-params.yaml")

            , build_first = listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , build_after = listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , build_timeout = defaulted(integer_spec(), 1200)
            , ignore_deps = defaulted(boolean(), False)

            , vars = dictof(string_spec(), stack_specs.var_spec(), nested=True)

            , skip_update_if_equivalent = listof(stack_specs.skipper_spec())

            , suspend_actions = defaulted(boolean(), False)
            , auto_scaling_group_name = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , artifact_retention_after_deployment = defaulted(boolean(), False)

            , command = optional_spec(string_spec())

            , netscaler = optional_spec(self.netscaler_spec)

            , dns = optional_spec(stack_specs.dns_spec(create_spec(stack_objs.DNS
                , vars = dictof(string_spec(), formatted(string_spec(), formatter=MergedOptionStringFormatter), nested=True)
                , providers = dictof(string_spec(), stack_specs.dns_provider_spec())
                , sites = delayed(dictof(string_spec(), stack_specs.dns_site_spec()))
                )))

            , scaling_options = create_spec(ScalingOptions
                , highest_min = defaulted(integer_spec(), 2)
                , instance_count_limit = defaulted(integer_spec(), 10)
                )

            , artifacts = container_spec(artifact_objs.ArtifactCollection, dictof(string_spec(), create_spec(artifact_objs.Artifact
                , not_created_here = defaulted(boolean(), False)
                , compression_type = string_choice_spec(["gz", "xz"])
                , history_length = integer_spec()
                , cleanup_prefix = optional_spec(string_spec())
                , upload_to = formatted(string_spec(), formatter=MergedOptionStringFormatter)
                , commands = listof(stack_specs.artifact_command_spec(), expect=artifact_objs.ArtifactCommand)
                , paths = listof(stack_specs.artifact_path_spec(), expect=artifact_objs.ArtifactPath)
                , files = listof(create_spec(artifact_objs.ArtifactFile, validators.has_either(["content", "task"])
                    , content = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                    , task = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                    , path = formatted(string_spec(), formatter=MergedOptionStringFormatter)
                    , task_runner = formatted(always_same_spec("{task_runner}"), formatter=MergedOptionStringFormatter)
                    ))
                )))

            , newrelic = optional_spec(create_spec(stack_objs.NewRelic
                , api_key = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , account_id = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , application_id = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))

                , env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)
                , deployed_version = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                ))

            , downtimer_options = optional_spec(dictof(valid_string_spec(valid_alerting_system())
                , create_spec(stack_objs.DowntimerOptions
                    , hosts = listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                    )
                ))

            , alerting_systems = optional_spec(dictof(string_spec(), self.alerting_system_spec))

            , ssh = optional_spec(create_spec(stack_objs.SSH
                , validators.deprecated_key("autoscaling_group_id", "Use ``auto_scaling_group_name``")

                , user = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , bastion = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , bastion_user = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , bastion_key_location = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , instance_key_location = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

                , address = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , instance = optional_spec(listof(formatted(string_spec(), formatter=MergedOptionStringFormatter)))
                , auto_scaling_group_name = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

                , bastion_key_path = formatted(defaulted(string_spec(), "{config_root}/{environment}/bastion_ssh_key.pem"), formatter=MergedOptionStringFormatter)
                , instance_key_path = formatted(defaulted(string_spec(), "{config_root}/{environment}/ssh_key.pem"), formatter=MergedOptionStringFormatter)

                , storage_type = formatted(defaulted(string_choice_spec(["url", "rattic"]), "url"), formatter=MergedOptionStringFormatter)
                , storage_host = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                ))

            , confirm_deployment = optional_spec(self.confirm_deployment_spec)
            )