0003-hobo_deploy-do-not-recall-import_template-when-it-pr.patch
hobo/agent/common/management/commands/hobo_deploy.py | ||
---|---|---|
195 | 195 |
if 'import_template' in get_commands() and me.get('template_name'): |
196 | 196 |
execute_from_command_line([sys.argv[0], 'tenant_command', |
197 | 197 |
'import_template', me['template_name'], |
198 |
'--domain', tenant.domain_url]) |
|
198 |
'--domain', tenant.domain_url, |
|
199 |
'--if-empty']) |
hobo/agent/common/management/commands/import_template.py | ||
---|---|---|
30 | 30 |
def add_arguments(self, parser): |
31 | 31 |
parser.add_argument('template_name', type=str) |
32 | 32 |
parser.add_argument('--basepath', type=str) |
33 |
parser.add_argument('--if-empty', action='store_true', default=False, |
|
34 |
help='Import only if passerelle is empty') |
|
33 | 35 | |
34 | 36 |
def handle(self, *args, **kwargs): |
35 | 37 |
app_name = settings.PROJECT_NAME |
38 |
if_empty = kwargs.get('if_empty') |
|
36 | 39 |
basepath = kwargs.get('basepath') or '/var/lib/%s/skeletons' % app_name |
37 | 40 |
template = '%s/%s.json' % (basepath, kwargs.get('template_name')) |
38 | 41 | |
... | ... | |
40 | 43 |
if not os.path.exists(template): |
41 | 44 |
raise UnknownTemplateError('unknown template (%r)' % template) |
42 | 45 |
else: |
43 |
call_command('import_site', template) |
|
46 |
call_command('import_site', template, if_empty=if_empty) |
tests/test_hobo_deploy.py | ||
---|---|---|
401 | 401 |
command.configure_template(ENVIRONMENT, tenant) |
402 | 402 |
assert mocked_execute_from_command_line.mock_calls == [ |
403 | 403 |
call(['.../manage.py', 'tenant_command', 'import_template', 'my_template', |
404 |
'--domain', 'combo.dev.publik.love'])] |
|
404 |
'--domain', 'combo.dev.publik.love', '--if-empty'])]
|
|
405 | 405 | |
406 | 406 |
# no template_name entry provided |
407 | 407 |
mocked_execute_from_command_line.reset_mock() |
tests/test_import_template.py | ||
---|---|---|
21 | 21 |
# simulate: |
22 | 22 |
# $ XXX-manage import-template import_me |
23 | 23 |
command = Command() |
24 |
with override_settings(PROJECT_NAME='bobo'):
|
|
24 |
with override_settings(PROJECT_NAME='hobo'):
|
|
25 | 25 |
command.handle(template_name='import_me') |
26 | 26 | |
27 | 27 |
# assert 'import_site' command is run |
28 | 28 |
assert mocked_call_command.mock_calls == [ |
29 |
mock.call('import_site', '/var/lib/bobo/skeletons/import_me.json')] |
|
29 |
mock.call('import_site', '/var/lib/hobo/skeletons/import_me.json', |
|
30 |
if_empty=None)] |
|
31 | ||
32 |
# set if-empty flag |
|
33 |
mocked_call_command.reset_mock() |
|
34 |
kwargs = {'if_empty': True} |
|
35 |
with override_settings(PROJECT_NAME='hobo'): |
|
36 |
command.handle(template_name='import_me', **kwargs) |
|
37 |
assert mocked_call_command.mock_calls == [ |
|
38 |
mock.call('import_site', '/var/lib/hobo/skeletons/import_me.json', |
|
39 |
if_empty=True)] |
|
40 | ||
30 | 41 | |
31 | 42 |
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists') |
32 | 43 |
@mock.patch('hobo.agent.common.management.commands.import_template.call_command') |
... | ... | |
45 | 56 | |
46 | 57 |
# assert 'import_site' command is run |
47 | 58 |
assert mocked_call_command.mock_calls == [ |
48 |
mock.call('import_site', '/tmp/import_me.json')] |
|
59 |
mock.call('import_site', '/tmp/import_me.json', if_empty=None)]
|
|
49 | 60 | |
50 | 61 | |
51 | 62 |
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists') |
tests_schemas/test_hobo_deploy.py | ||
---|---|---|
33 | 33 |
assert mocked_execute_from_command_line.mock_calls == [ |
34 | 34 |
mock.call(['.../manage.py', 'tenant_command', |
35 | 35 |
'import_template', 'import_me', |
36 |
'--domain', 'chrono.dev.publik.love'])] |
|
36 |
'--domain', 'chrono.dev.publik.love', '--if-empty'])]
|
|
37 | 37 | |
38 | 38 | |
39 | 39 |
def test_deploy_on_common_agent(db): |
tests_schemas/test_import_template.py | ||
---|---|---|
14 | 14 |
check this call result in '$ passerelle-manage import_site my-template' |
15 | 15 |
""" |
16 | 16 |
command = load_command_class('hobo.agent.common', 'import_template') |
17 |
kwargs = {'if_empty': False} |
|
17 | 18 | |
18 | 19 |
mocked_get_commands.return_value = ['import_site'] |
19 | 20 |
template_path = os.path.join(str(tmpdir), 'my-template.json') |
20 | 21 |
with open(template_path, 'w') as handler: |
21 | 22 |
handler.write('...') |
22 | 23 | |
23 |
command.handle(basepath=str(tmpdir), template_name='my-template') |
|
24 |
assert mocked_call_command.mock_calls == [mock.call('import_site', template_path)] |
|
24 |
command.handle(basepath=str(tmpdir), template_name='my-template', **kwargs) |
|
25 |
assert mocked_call_command.mock_calls == [ |
|
26 |
mock.call('import_site', template_path, if_empty=False)] |
|
25 | 27 | |
26 | 28 | |
27 | 29 |
@mock.patch('hobo.agent.common.management.commands.import_template.call_command') |
... | ... | |
32 | 34 |
only check we reach the hobo.agent.common's code here |
33 | 35 |
""" |
34 | 36 |
command = load_command_class('hobo.agent.combo', 'import_template') |
37 |
kwargs = {'if_empty': False} |
|
35 | 38 | |
36 | 39 |
mocked_get_commands.return_value = ['import_site'] |
37 | 40 |
template_path = os.path.join(str(tmpdir), 'my-template.json') |
38 | 41 |
with open(template_path, 'w') as handler: |
39 | 42 |
handler.write('...') |
40 | 43 | |
41 |
command.handle(basepath=str(tmpdir), template_name='my-template') |
|
42 |
assert mocked_call_command.mock_calls == [mock.call('import_site', template_path)] |
|
44 |
command.handle(basepath=str(tmpdir), template_name='my-template', **kwargs) |
|
45 |
assert mocked_call_command.mock_calls == [ |
|
46 |
mock.call('import_site', template_path, if_empty=False)] |
|
43 |
- |