38
41
'{}/staging/services.cfg'.format(workspace.repo_dir)))
39
42
# Verify that the configs were included in the deployer command.
40
43
expected_configs = (
41
'-c {configs_dir}/services.cfg '
42
'-c {configs_dir}/staging/services.cfg'.format(
44
'--config {configs_dir}/services.cfg '
45
'--config {configs_dir}/staging/services.cfg'.format(
43
46
configs_dir=workspace.repo_dir))
44
47
self.assertIn(expected_configs, command)
50
class SetPhaseTestCase(TestCase, MojoTestCaseMixin):
52
def write_config(self, path, **kwargs):
53
kwargs['templated'] = '{{ stage }}'
54
with open(path, 'w') as f:
55
conf = textwrap.dedent("""
62
f.write(conf.format(yaml.dump(kwargs)))
64
def test_set_phase_single_config(self):
65
phase = SetPhase(config='services.cfg')
66
workspace = self.create_workspace()
67
spec = self.create_spec(
68
path=workspace.spec_dir,
69
configs=['services.cfg'],
72
path = partial(os.path.join, spec.local_dir)
73
self.write_config(path('services.cfg'), conf='default')
75
with mock.patch('mojo.phase.Environment') as mock_env:
76
phase.run('unused', workspace, 'trusty', 'staging')
78
# Verify that the configs were both rendered.
79
self.assertTrue(os.path.exists(
80
'{}/services.cfg'.format(workspace.repo_dir)))
82
set_config = mock_env.connect.return_value.set_config
83
set_config.assert_called_once_with(
84
'service', {'conf': 'default', 'templated': 'staging'})
86
def test_set_phase_multi_config(self):
87
phase = SetPhase(config='services.cfg')
88
workspace = self.create_workspace()
89
spec = self.create_spec(
90
path=workspace.spec_dir,
91
configs=['staging/services.cfg', 'services.cfg'],
94
path = partial(os.path.join, spec.local_dir)
95
self.write_config(path('services.cfg'), conf='default')
96
self.write_config(path('staging/services.cfg'), conf='staging')
98
with mock.patch('mojo.phase.Environment') as mock_env:
99
phase.run('unused', workspace, 'trusty', 'staging')
101
# Verify that the configs were both rendered.
102
self.assertTrue(os.path.exists(
103
'{}/services.cfg'.format(workspace.repo_dir)))
105
self.assertTrue(os.path.exists(
106
'{}/staging/services.cfg'.format(workspace.repo_dir)))
108
set_config = mock_env.connect.return_value.set_config
109
set_config.assert_called_once_with(
110
'service', {'conf': 'staging', 'templated': 'staging'})
112
def test_set_phase_local_config(self):
113
phase = SetPhase(config='services.cfg', local='local.cfg')
114
workspace = self.create_workspace()
115
spec = self.create_spec(
116
path=workspace.spec_dir,
117
configs=['staging/services.cfg', 'services.cfg'],
120
path = partial(os.path.join, spec.local_dir)
121
self.write_config(path('services.cfg'), conf='default')
122
self.write_config(path('staging/services.cfg'), conf='staging')
124
os.path.join(workspace.local_dir, 'local.cfg'), conf='local')
126
with mock.patch('mojo.phase.Environment') as mock_env:
127
phase.run('unused', workspace, 'trusty', 'staging')
129
# Verify that the configs were both rendered.
130
self.assertTrue(os.path.exists(
131
'{}/services.cfg'.format(workspace.repo_dir)))
133
self.assertTrue(os.path.exists(
134
'{}/staging/services.cfg'.format(workspace.repo_dir)))
136
self.assertTrue(os.path.exists(
137
'{}/local.cfg'.format(workspace.repo_dir)))
139
set_config = mock_env.connect.return_value.set_config
140
set_config.assert_called_once_with(
141
'service', {'conf': 'local', 'templated': 'staging'})