本文整理匯總了Python中webhook2lambda2sqs.terraform_runner.TerraformRunner類的典型用法代碼示例。如果您正苦於以下問題:Python TerraformRunner類的具體用法?Python TerraformRunner怎麽用?Python TerraformRunner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TerraformRunner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_apply_stream
def test_apply_stream(self):
def se_exc(*args, **kwargs):
raise Exception('foo')
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform-bin')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._set_remote' % pb, autospec=True) as mock_set:
with patch('%s._run_tf' % pb, autospec=True) as mock_run:
with patch('%s._taint_deployment' % pb,
autospec=True) as mock_taint:
mock_run.return_value = 'output'
mock_taint.side_effect = se_exc
with patch('%s._show_outputs' % pb,
autospec=True) as mock_show:
cls.apply(stream=True)
assert mock_set.mock_calls == [call(cls, stream=True)]
assert mock_run.mock_calls == [
call(cls, 'apply', cmd_args=['-input=false', '-refresh=true', '.'],
stream=True)
]
assert mock_logger.mock_calls == [
call.warning('Running terraform apply: %s',
'-input=false -refresh=true .'),
call.warning("Terraform apply finished successfully.")
]
assert mock_show.mock_calls == [call(cls)]
assert mock_taint.mock_calls == [call(cls, stream=True)]
示例2: get_base_url
def get_base_url(config, args):
"""
Get the API base url. Try Terraform state first, then
:py:class:`~.AWSInfo`.
:param config: configuration
:type config: :py:class:`~.Config`
:param args: command line arguments
:type args: :py:class:`argparse.Namespace`
:return: API base URL
:rtype: str
"""
try:
logger.debug('Trying to get Terraform base_url output')
runner = TerraformRunner(config, args.tf_path)
outputs = runner._get_outputs()
base_url = outputs['base_url']
logger.debug("Terraform base_url output: '%s'", base_url)
except Exception:
logger.info('Unable to find API base_url from Terraform state; '
'querying AWS.', exc_info=1)
aws = AWSInfo(config)
base_url = aws.get_api_base_url()
logger.debug("AWS api_base_url: '%s'", base_url)
if not base_url.endswith('/'):
base_url += '/'
return base_url
示例3: test_apply
def test_apply(self):
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform-bin')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._set_remote' % pb, autospec=True) as mock_set:
with patch('%s._setup_tf' % pb, autospec=True) as mock_setup:
with patch('%s._run_tf' % pb, autospec=True) as mock_run:
with patch('%s._taint_deployment' % pb,
autospec=True) as mock_taint:
mock_run.return_value = 'output'
with patch('%s._show_outputs' % pb,
autospec=True) as mock_show:
cls.apply()
assert mock_setup.mock_calls == [call(cls, stream=False)]
assert mock_set.mock_calls == []
assert mock_run.mock_calls == [
call(cls, 'apply', cmd_args=['-input=false', '-refresh=true', '.'],
stream=False)
]
assert mock_logger.mock_calls == [
call.warning('Running terraform apply: %s',
'-input=false -refresh=true .'),
call.warning("Terraform apply finished successfully:\n%s", 'output')
]
assert mock_show.mock_calls == [call(cls)]
assert mock_taint.mock_calls == [call(cls, stream=False)]
示例4: get_base_url
def get_base_url(dir_path):
"""
get the base url to the API
"""
os.chdir(dir_path)
conf = Config(os.path.join(dir_path, 'config.json'))
tf_runner = TerraformRunner(conf, 'terraform')
outs = tf_runner._get_outputs()
return outs['base_url']
示例5: test_show_outputs
def test_show_outputs(self, capsys):
outs = {'a': 'b', 'foo': 'bar'}
with patch('%s._get_outputs' % pb, autospec=True) as mock_get:
mock_get.return_value = outs
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform-bin')
cls._show_outputs()
assert mock_get.mock_calls == [call(cls)]
out, err = capsys.readouterr()
assert err == ''
assert out == "\n\n=> Terraform Outputs:\na = b\nfoo = bar\n"
示例6: test_setup_tf_pre090
def test_setup_tf_pre090(self):
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform')
cls.tf_version = (0, 7, 2)
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._set_remote' % pb, autospec=True) as mock_set_rmt:
with patch('%s._run_tf' % pb, autospec=True) as mock_run:
mock_run.return_value = ('myoutput', 0)
cls._setup_tf()
assert mock_set_rmt.mock_calls == [call(cls, stream=False)]
assert mock_run.mock_calls == []
assert mock_logger.mock_calls == []
示例7: test_run_tf
def test_run_tf(self):
expected_args = 'terraform plan config foo bar'
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s.run_cmd' % pbm, autospec=True) as mock_run:
mock_run.return_value = ('myoutput', 0)
cls._run_tf('plan', cmd_args=['config', 'foo', 'bar'])
assert mock_run.mock_calls == [
call(expected_args, stream=False)
]
assert mock_logger.mock_calls == [
call.info('Running terraform command: %s', expected_args)
]
示例8: test_set_remote_none
def test_set_remote_none(self):
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), '/path/to/terraform')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._args_for_remote' % pb, autospec=True) as mock_args:
with patch('%s.run_cmd' % pbm, autospec=True) as mock_run:
mock_args.return_value = None
cls._set_remote()
assert mock_args.mock_calls == [call(cls)]
assert mock_run.mock_calls == []
assert mock_logger.mock_calls == [
call.debug('_args_for_remote() returned None; not configuring '
'terraform remote')
]
示例9: test_args_for_remote
def test_args_for_remote(self):
conf = self.mock_config(conf={
'terraform_remote_state': {
'backend': 'consul',
'config': {
'path': 'consul/path',
'address': 'foo:1234'
}
}
})
with patch('%s._validate' % pb):
cls = TerraformRunner(conf, 'tfpath')
assert cls._args_for_remote() == [
'-backend=consul',
'-backend-config="address=foo:1234"',
'-backend-config="path=consul/path"'
]
示例10: main
def main(args=None):
"""
Main entry point
"""
# parse args
if args is None:
args = parse_args(sys.argv[1:])
# dump example config if that action
if args.action == 'example-config':
conf, doc = Config.example_config()
print(conf)
sys.stderr.write(doc + "\n")
return
# set logging level
if args.verbose > 1:
set_log_debug()
elif args.verbose == 1:
set_log_info()
# get our config
config = Config(args.config)
if args.action == 'logs':
aws = AWSInfo(config)
aws.show_cloudwatch_logs(count=args.log_count)
return
if args.action == 'queuepeek':
aws = AWSInfo(config)
aws.show_queue(name=args.queue_name, delete=args.queue_delete,
count=args.msg_count)
return
if args.action == 'test':
run_test(config, args)
return
# if generate or genapply, generate the configs
if args.action == 'generate' or args.action == 'genapply':
func_gen = LambdaFuncGenerator(config)
func_src = func_gen.generate()
# @TODO: also write func_source to disk
tf_gen = TerraformGenerator(config)
tf_gen.generate(func_src)
# if only generate, exit now
if args.action == 'generate':
return
# else setup a Terraform action
runner = TerraformRunner(config, args.tf_path)
# run the terraform action
if args.action == 'apply' or args.action == 'genapply':
runner.apply(args.stream_tf)
elif args.action == 'plan':
runner.plan(args.stream_tf)
else: # destroy
runner.destroy(args.stream_tf)
示例11: test_destroy_stream
def test_destroy_stream(self):
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform-bin')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._set_remote' % pb, autospec=True) as mock_set:
with patch('%s._run_tf' % pb, autospec=True) as mock_run:
mock_run.return_value = 'output'
cls.destroy(stream=True)
assert mock_set.mock_calls == [call(cls, stream=True)]
assert mock_run.mock_calls == [
call(cls, 'destroy', cmd_args=['-refresh=true', '-force', '.'],
stream=True)
]
assert mock_logger.mock_calls == [
call.warning('Running terraform destroy: %s',
'-refresh=true -force .'),
call.warning("Terraform destroy finished successfully.")
]
示例12: test_plan
def test_plan(self):
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform-bin')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._set_remote' % pb, autospec=True) as mock_set:
with patch('%s._run_tf' % pb, autospec=True) as mock_run:
mock_run.return_value = 'output'
cls.plan()
assert mock_set.mock_calls == [call(cls, stream=False)]
assert mock_run.mock_calls == [
call(cls, 'plan', cmd_args=['-input=false', '-refresh=true', '.'],
stream=False)
]
assert mock_logger.mock_calls == [
call.warning('Running terraform plan: %s',
'-input=false -refresh=true .'),
call.warning("Terraform plan finished successfully:\n%s", 'output')
]
示例13: test_set_remote
def test_set_remote(self):
expected_args = ['config', 'foo', 'bar']
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._args_for_remote' % pb, autospec=True) as mock_args:
with patch('%s._run_tf' % pb, autospec=True) as mock_run:
mock_args.return_value = ['foo', 'bar']
mock_run.return_value = ('myoutput', 0)
cls._set_remote()
assert mock_args.mock_calls == [call(cls)]
assert mock_run.mock_calls == [
call(cls, 'remote', cmd_args=expected_args, stream=False)
]
assert mock_logger.mock_calls == [
call.warning('Setting terraform remote config: %s', 'foo bar'),
call.info('Terraform remote configured.')
]
示例14: test_taint_deployment_stream
def test_taint_deployment_stream(self):
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform-bin')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._set_remote' % pb, autospec=True) as mock_set:
with patch('%s._run_tf' % pb, autospec=True) as mock_run:
mock_run.return_value = 'output'
cls._taint_deployment(stream=True)
assert mock_set.mock_calls == []
assert mock_run.mock_calls == [
call(cls, 'taint', cmd_args=['aws_api_gateway_deployment.depl'],
stream=True)
]
assert mock_logger.mock_calls == [
call.warning('Running terraform taint: %s as workaround for '
'<https://github.com/hashicorp/terraform/issues/6613>',
'aws_api_gateway_deployment.depl'),
call.warning("Terraform taint finished successfully.")
]
示例15: test_run_tf_fail
def test_run_tf_fail(self):
expected_args = 'terraform-bin plan config foo bar'
with patch('%s._validate' % pb):
cls = TerraformRunner(self.mock_config(), 'terraform-bin')
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s.run_cmd' % pbm, autospec=True) as mock_run:
mock_run.return_value = ('myoutput', 5)
with pytest.raises(Exception) as excinfo:
cls._run_tf('plan', cmd_args=['config', 'foo', 'bar'],
stream=True)
assert exc_msg(excinfo.value) == 'terraform plan failed'
assert mock_run.mock_calls == [
call(expected_args, stream=True)
]
assert mock_logger.mock_calls == [
call.info('Running terraform command: %s', expected_args),
call.critical('Terraform command (%s) failed with exit code '
'%d:\n%s', expected_args, 5, 'myoutput')
]