34
24
parser.add_argument('bundle_path',
35
25
help='URL or path to a bundle')
36
26
add_basic_testing_arguments(parser)
37
parser.add_argument('--allow-native-deploy', action='store_true',
38
help='Let juju 2 use native bundle deploying.')
39
parser.add_argument('--bundle-verification-script',
40
help='Script to verify the bundle.')
41
27
parser.add_argument('--bundle-name', default=None,
42
28
help='Name of the bundle to deploy.')
43
29
parser.add_argument('--health-cmd', default=None,
44
30
help='A binary for checking the health of the'
45
31
' deployed bundle.')
46
parser.add_argument('--upgrade-condition', action='append', default=None,
47
help='unit_name:<conditions>'
48
' One or more of the following conditions to apply'
49
' to the given unit_name: clock_skew.')
50
parser.add_argument('--agent-timeout', type=int, default=1200,
51
help='The time to wait for agents to start')
52
parser.add_argument('--workload-timeout', type=int, default=1800,
53
help='The time to wait for workloads to active')
54
args = parser.parse_args(argv)
55
if args.allow_native_deploy and args.bundle_name:
56
parser.error('cannot supply bundle name with native juju deploying')
60
def check_health(cmd_path, env_name='', environ=None):
32
return parser.parse_args(argv)
35
def check_health(cmd_path, env_name=''):
61
36
"""Run the health checker command and raise on error."""
63
38
cmd = (cmd_path, env_name)
64
logging.info('Calling {}'.format(cmd))
66
logging.info('PATH: {}'.format(environ.get('PATH')))
67
logging.info('JUJU_HOME: {}'.format(environ.get('JUJU_HOME')))
68
with scoped_environ(environ):
69
sub_output = subprocess.check_output(cmd)
39
logging.debug('Calling {}'.format(cmd))
40
sub_output = subprocess.check_output(cmd)
70
41
logging.info('Health check output: {}'.format(sub_output))
71
42
except OSError as e:
83
CLOCK_SKEW_SCRIPT = """
86
sudo date --set @$future
90
def apply_condition(client, condition):
91
"""Apply an adverse condition to the given unit."""
92
unit, action = condition.split(':', 1)
93
logging.info('Applying {} to unit {}'.format(action, unit))
94
remote = remote_from_unit(client, unit)
95
if not remote.is_windows():
96
if action == 'clock_skew':
97
result = remote.run(CLOCK_SKEW_SCRIPT)
98
logging.info('Clock on {} set to: {}'.format(unit, result))
100
raise ErrUnitCondition("%s: Unknown condition type." % action)
103
def assess_deployer(args, client, agent_timeout, workload_timeout):
104
"""Run juju-deployer, based on command line configuration values."""
105
if args.allow_native_deploy:
106
client.deploy_bundle(args.bundle_path)
107
client.wait_for_started(timeout=agent_timeout)
109
client.deployer(args.bundle_path, args.bundle_name)
110
client.wait_for_workloads(timeout=workload_timeout)
112
environ = client._shell_environ()
113
check_health(args.health_cmd, args.temp_env_name, environ)
116
if args.upgrade_condition:
117
for condition in args.upgrade_condition:
118
apply_condition(client, condition)
119
assess_upgrade(client, args.juju_bin)
120
client.wait_for_workloads()
122
environ = client._shell_environ()
123
check_health(args.health_cmd, args.temp_env_name, environ)
54
def run_deployer(argv=None):
127
55
args = parse_args(argv)
128
56
configure_logging(args.verbose)
57
env = SimpleEnvironment.from_config(args.env)
129
58
start_juju_path = None if args.upgrade else args.juju_bin
130
client = client_from_config(args.env, start_juju_path, debug=args.debug,
131
soft_deadline=args.deadline)
59
client = EnvJujuClient.by_version(env, start_juju_path, debug=args.debug)
132
60
with boot_context(args.temp_env_name, client, None, [], args.series,
133
61
args.agent_url, args.agent_stream, args.logs,
134
args.keep_env, upload_tools=args.upload_tools,
137
args, client, args.agent_timeout, args.workload_timeout)
138
if args.bundle_verification_script:
139
client_ser = pickle.dumps(client)
140
logging.info('Calling bundle verification script {}'.format(
141
args.bundle_verification_script))
142
run_command([args.bundle_verification_script, client_ser])
62
args.keep_env, False, region=args.region):
63
client.deployer(args.bundle_path, args.bundle_name)
65
check_health(args.health_cmd, args.temp_env_name)
67
client.juju('status', ())
68
assess_upgrade(client, args.juju_bin)
70
check_health(args.health_cmd, args.temp_env_name)
146
71
if __name__ == '__main__':